CaseFrontSheetService.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. package thyyxxk.webserver.service.casefrontsheet;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.scheduling.annotation.Scheduled;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.transaction.annotation.Transactional;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.sidicts.Insutype;
  10. import thyyxxk.webserver.constants.sidicts.MedType;
  11. import thyyxxk.webserver.dao.his.LoginDao;
  12. import thyyxxk.webserver.dao.his.casefrontsheet.BasSelectOverviewDao;
  13. import thyyxxk.webserver.dao.his.casefrontsheet.CaseFrontSheetDao;
  14. import thyyxxk.webserver.dao.his.casefrontsheet.SheetCreatedDao;
  15. import thyyxxk.webserver.entity.ResultVo;
  16. import thyyxxk.webserver.entity.casefrontsheet.*;
  17. import thyyxxk.webserver.entity.dictionary.PureCodeName;
  18. import thyyxxk.webserver.service.externalhttp.PowersiSrvc;
  19. import thyyxxk.webserver.service.redislike.RedisLikeService;
  20. import thyyxxk.webserver.utils.*;
  21. import java.lang.reflect.Field;
  22. import java.util.*;
  23. import java.util.concurrent.ConcurrentHashMap;
  24. @Slf4j
  25. @Service
  26. public class CaseFrontSheetService {
  27. private static ConcurrentHashMap<String, List<PureCodeName>> allDictionary;
  28. private final CaseFrontSheetDao dao;
  29. private final SheetCreatedDao createdDao;
  30. private final BasSelectOverviewDao basDao;
  31. private final LoginDao userDao;
  32. private final PowersiSrvc srvc;
  33. private final RedisLikeService redis;
  34. public CaseFrontSheetService(SheetCreatedDao createdDao, CaseFrontSheetDao dao,
  35. BasSelectOverviewDao basDao, LoginDao userDao, PowersiSrvc srvc, RedisLikeService redis) {
  36. this.dao = dao;
  37. this.createdDao = createdDao;
  38. this.basDao = basDao;
  39. this.userDao = userDao;
  40. this.srvc = srvc;
  41. this.redis = redis;
  42. if (allDictionary == null) {
  43. allDictionary = new ConcurrentHashMap<>();
  44. }
  45. }
  46. public ResultVo<Map<String, List<PureCodeName>>> getAllDictionary() {
  47. if (allDictionary.isEmpty()) {
  48. allDictionary.put("getMarriageCode", createdDao.getMarriageCode());
  49. allDictionary.put("getSexCode", createdDao.getSexCode());
  50. allDictionary.put("getAdmissWay", createdDao.getAdmissWay());
  51. allDictionary.put("getBloodType", createdDao.getBloodType());
  52. allDictionary.put("getAnaesthesia", createdDao.getAnaesthesia());
  53. allDictionary.put("getOperateScale", createdDao.getOperateScale());
  54. allDictionary.put("getAdmissStatus", createdDao.getAdmissStatus());
  55. allDictionary.put("getDisAdmissStatus", createdDao.getDisAdmissStatus());
  56. allDictionary.put("getCutHealGrade", createdDao.getCutHealGrade());
  57. allDictionary.put("getDisdiagStatus", createdDao.getDisdiagStatus());
  58. allDictionary.put("getHbsag", createdDao.getHbsag());
  59. allDictionary.put("getDiagConform", createdDao.getDiagConform());
  60. allDictionary.put("getDisdiagType", createdDao.getDisdiagType());
  61. allDictionary.put("getPatientStatus", createdDao.getPatientStatus());
  62. allDictionary.put("getQualityLevel", createdDao.getQualityLevel());
  63. allDictionary.put("getZyDismissWay", createdDao.getZyDismissWay());
  64. allDictionary.put("getTumorLevelT", createdDao.getTumorLevelT());
  65. allDictionary.put("getTumorLevelN", createdDao.getTumorLevelN());
  66. allDictionary.put("getTumorLevelM", createdDao.getTumorLevelM());
  67. allDictionary.put("getTumorLevel", createdDao.getTumorLevel());
  68. allDictionary.put("getRelations", createdDao.getRelations());
  69. List<PureCodeName> temp = new ArrayList<>();
  70. temp.add(new PureCodeName());
  71. temp.addAll(createdDao.getStatutoryEpidemic());
  72. allDictionary.put("getStatutoryEpidemic", temp);
  73. allDictionary.put("getClinicalPathwayManagement", createdDao.getClinicalPathwayManagement());
  74. allDictionary.put("getDrgsManagement", createdDao.getDrgsManagement());
  75. allDictionary.put("getCaseClassification", createdDao.getCaseClassification());
  76. allDictionary.put("getOccupation", createdDao.getOccupation());
  77. allDictionary.put("getCountry", createdDao.getCountry());
  78. allDictionary.put("getNation", createdDao.getNation());
  79. allDictionary.put("getPayMethod", createdDao.getPayMethod());
  80. }
  81. return ResultVoUtil.success(allDictionary);
  82. }
  83. public ResultVo<String> resetDictionary() {
  84. allDictionary.clear();
  85. return ResultVoUtil.success();
  86. }
  87. @Scheduled(cron = "0 0 3 * * ?")
  88. public void refreshDictionary() {
  89. resetDictionary();
  90. }
  91. public ResultVo<List<PureCodeName>> getUserWards() {
  92. String code = TokenUtil.getTokenUserId();
  93. List<Integer> roles = createdDao.selectUserRoles(code);
  94. List<PureCodeName> list;
  95. if (roles.contains(7) || roles.contains(1)) {
  96. list = createdDao.getAllWards();
  97. } else {
  98. list = createdDao.getUserWards(code);
  99. }
  100. list.removeIf(Objects::isNull);
  101. return ResultVoUtil.success(list);
  102. }
  103. public ResultVo<List<PureCodeName>> getAllWards() {
  104. return ResultVoUtil.success(createdDao.getAllWards());
  105. }
  106. public ResultVo<List<SheetOverview>> getPatientOverview(String ward) {
  107. return ResultVoUtil.success(dao.getPatientOverview(ward));
  108. }
  109. public ResultVo<List<SheetOverview>> getOutPatient(GetOutSheet param) {
  110. param.setEnd(param.getEnd() + " 23:59:59");
  111. if (StringUtil.isBlank(param.getWard())) {
  112. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择科室!");
  113. }
  114. return ResultVoUtil.success(dao.getOutPatients(param));
  115. }
  116. /**
  117. * 查询病案首页汇总
  118. *
  119. * @param param 查询的条件
  120. * @return 返回数据
  121. */
  122. public ResultVo<GetBasOverviewRet> getOutPatientForBas(GetOutSheet param) {
  123. GetBasOverviewRet ret = new GetBasOverviewRet();
  124. if (StringUtil.notBlank(param.getWard())) {
  125. int cd = dao.getCDBlfxCount(param.getWard());
  126. int all = dao.getAllDisPatientCount(param.getWard());
  127. if (cd == 0 || all == 0) {
  128. ret.setCdPercentage("0.00%");
  129. } else {
  130. ret.setCdPercentage(DecimalUtil.getPercent(cd, all));
  131. }
  132. }
  133. if (StringUtil.notBlank(param.getStart())) {
  134. param.setStart(param.getStart() + " 00:00:00");
  135. }
  136. if (StringUtil.notBlank(param.getEnd())) {
  137. param.setEnd(param.getEnd() + " 23:59:59");
  138. }
  139. List<SheetOverview> list;
  140. if (StringUtil.notBlank(param.getBah())) {
  141. if (param.getFileStatus() == 0) {
  142. list = basDao.selectPatientsForBasByBah(param);
  143. if (list.isEmpty()) {
  144. list = basDao.selectSignApply(param.getBah(), param.getFileStatus());
  145. if (list.isEmpty()) {
  146. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有找到此患者的未归档病案。");
  147. }
  148. }
  149. } else {
  150. list = basDao.selectPatientsFromSignedBase(param);
  151. if (list.isEmpty()) {
  152. return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有找到此患者的已归档病案。");
  153. }
  154. }
  155. if (param.getLateFlag() != 3) {
  156. list.removeIf(item -> !item.getLateFlag().equals(param.getLateFlag()));
  157. }
  158. ret.setList(list);
  159. return ResultVoUtil.success(ret);
  160. }
  161. if (StringUtil.notBlank(param.getWard())) {
  162. if (param.getFileStatus() == 0) {
  163. list = basDao.selectPatientsForBasByWard(param);
  164. } else {
  165. list = basDao.selectPatientsForBasByWard2(param);
  166. }
  167. if (param.getLateFlag() != 3) {
  168. list.removeIf(item -> !item.getLateFlag().equals(param.getLateFlag()));
  169. }
  170. ret.setList(list);
  171. return ResultVoUtil.success(ret);
  172. }
  173. if (param.getFileStatus() == 0) {
  174. list = basDao.selectPatientsForBasByFileStatus(param);
  175. } else {
  176. list = basDao.selectPatientsForBasByFileStatus2(param);
  177. }
  178. if (param.getLateFlag() != 3) {
  179. list.removeIf(item -> !item.getLateFlag().equals(param.getLateFlag()));
  180. }
  181. ret.setList(list);
  182. return ResultVoUtil.success(ret);
  183. }
  184. public ResultVo<CaseFrontsheetMain> getPatientInfo(SheetOverview overview) {
  185. CaseFrontsheetMain sheet;
  186. String bah = overview.getBah();
  187. Integer times = overview.getTimes();
  188. int fileStatus = overview.getFileStatus();
  189. if (fileStatus == 1) {
  190. sheet = dao.selectSignedSheetMain(bah, times);
  191. if (null != sheet) {
  192. sheet.setDisdiagList(getSheetDisDiags(bah, times, fileStatus));
  193. sheet.setSurgeryList(getSheetSurgeries(bah, times, fileStatus));
  194. return ResultVoUtil.success(sheet);
  195. }
  196. }
  197. int flag = overview.getInOutFlag();
  198. if (flag == 2) {
  199. flag = dao.selectActCount(bah, times) > 0 ? 1 : 2;
  200. }
  201. sheet = dao.getAPatientMi(bah);
  202. sheet.setAge(DateUtil.calculateAge(sheet.getBirthDate()));
  203. CaseFrontsheetMain sheet1 = dao.getZyLedgerFile(bah, times);
  204. CaseFrontsheetMain sheet2 = flag == 1 ? dao.getZyActPatient("zy_actpatient", "yz_act_order", bah, times) :
  205. dao.getZyActPatient("zy_inactpatient", "yz_inact_order", bah, times);
  206. if (null == sheet2) {
  207. sheet2 = flag == 1 ? dao.getZyActPatient("zy_inactpatient", "yz_inact_order", bah, times) :
  208. dao.getZyActPatient("zy_actpatient", "yz_act_order", bah, times);
  209. }
  210. if (StringUtil.isBlank(sheet2.getMedType())) {
  211. String injurySerialNo = dao.selectInjurySerialNo(bah, times);
  212. if (StringUtil.notBlank(injurySerialNo)) {
  213. sheet2.setMedType("42");
  214. }
  215. }
  216. sheet2.setMedTypeName(MedType.getName(sheet2.getMedType()));
  217. sheet2.setInsutype(Insutype.getName(sheet2.getInsutype()));
  218. final int hasInfant = dao.getInfant(bah, times);
  219. sheet2.setHasInfant(String.valueOf(hasInfant));
  220. if (null == sheet2.getDismissDate()) {
  221. final Date dismissDate = flag == 1 ?
  222. dao.getDismissDateFromYzActOrder("yz_inact_order", bah, times)
  223. : dao.getDismissDateFromYzActOrder("yz_act_order", bah, times);
  224. sheet2.setDismissDate(dismissDate);
  225. }
  226. CaseFrontsheetMain sheet3 = dao.getBatjBa1(bah, times);
  227. if (sheet3 == null) {
  228. if (dao.isBatjBa1Exist(bah, times) == 0) {
  229. dao.createBatjBa1(bah, times, sheet.getName(), sheet2.getAdmissDate(),
  230. sheet2.getAdmissDept(), sheet2.getAdmissWard());
  231. log.info("insert batjBa1>>> " + bah + ", " + times);
  232. }
  233. }
  234. CaseFrontsheetMain sheet4 = flag == 1 ? dao.getBatjBa2ForInPatient(bah, times) :
  235. dao.getBatjBa2ForOutPatient(bah, times);
  236. if (sheet4 == null) {
  237. if (dao.isBatjBa2Exist(bah, times) == 0) {
  238. dao.createBatjBa2(bah, times);
  239. log.info("insert batjBa2>>> " + bah + ", " + times);
  240. }
  241. }
  242. mergeObject(sheet1, sheet);
  243. mergeObject(sheet2, sheet);
  244. mergeObject(sheet3, sheet);
  245. mergeObject(sheet4, sheet);
  246. if (dao.getDismissOrder(bah, times) > 0) {
  247. sheet.setZyDismissWay("0");
  248. }
  249. if (dao.getDeathOrder(bah, times) > 0) {
  250. sheet.setZyDismissWay("4");
  251. }
  252. Integer days = DateUtil.daysBetween(sheet.getDismissDate(), sheet.getAdmissDate());
  253. if (0 == days) {
  254. days = 1;
  255. }
  256. sheet.setAdmissDays(String.valueOf(days));
  257. if (null == sheet.getQualityControlDate()) {
  258. sheet.setQualityControlDate(new Date());
  259. }
  260. sheet.setDisdiagList(getSheetDisDiags(bah, times, fileStatus));
  261. sheet.setSurgeryList(getSheetSurgeries(bah, times, fileStatus));
  262. return ResultVoUtil.success(sheet);
  263. }
  264. private List<CaseFrontsheetDisdiag> getSheetDisDiags(String bah, int times, int status) {
  265. List<CaseFrontsheetDisdiag> disdiags = status == 1 ?
  266. dao.selectSignedSheetDiags(bah, times) : dao.getDisdiags(bah, times);
  267. if (disdiags == null) {
  268. disdiags = new ArrayList<>();
  269. }
  270. while (disdiags.size() < 27) {
  271. disdiags.add(new CaseFrontsheetDisdiag());
  272. }
  273. return disdiags;
  274. }
  275. private List<CaseFrontsheetSurgery> getSheetSurgeries(String bah, int times, int status) {
  276. List<CaseFrontsheetSurgery> surgeries = status == 1 ?
  277. dao.selectSignedSheetSurgeries(bah, times) : dao.getSurgeries(bah, times);
  278. if (surgeries == null) {
  279. surgeries = new ArrayList<>();
  280. }
  281. while (surgeries.size() < 5) {
  282. surgeries.add(new CaseFrontsheetSurgery());
  283. }
  284. return surgeries;
  285. }
  286. private void mergeObject(CaseFrontsheetMain origin, CaseFrontsheetMain destination) {
  287. if (origin == null || destination == null) {
  288. return;
  289. }
  290. Field[] fields = destination.getClass().getDeclaredFields();
  291. for (Field field : fields) {
  292. try {
  293. field.setAccessible(true);
  294. Object valueD = field.get(origin);
  295. Object valueO = field.get(destination);
  296. if (null == valueO) {
  297. field.set(destination, valueD);
  298. }
  299. field.setAccessible(false);
  300. } catch (Exception e) {
  301. log.error("合并实体类出错", e);
  302. }
  303. }
  304. }
  305. private ResultVo<List<PureCodeName>> saveSheet(CaseFrontsheetMain sheet) {
  306. String bah = sheet.getBah();
  307. int times = sheet.getAdmissTimes();
  308. dao.updateAPatientMi(sheet);
  309. dao.updateZyActPatient(bah, times, sheet.getAutopsy(), sheet.getDiagConform1(),
  310. sheet.getDiagConform2(), sheet.getDiagConform3(), sheet.getDiagConform4(),
  311. sheet.getDiagConform5(), sheet.getHasSurgery(), sheet.getPathologicDiagStr(),
  312. sheet.getPathologicDiagCode(), sheet.getClinicDiagCode(), sheet.getClinicDiagStr());
  313. dao.updateZyInActPatient(bah, times, sheet.getAutopsy(), sheet.getDiagConform1(), sheet.getDiagConform2(),
  314. sheet.getDiagConform3(), sheet.getDiagConform4(), sheet.getDiagConform5(), sheet.getHasSurgery(),
  315. sheet.getPathologicDiagStr(), sheet.getPathologicDiagCode(), sheet.getClinicDiagCode(), sheet.getClinicDiagStr());
  316. dao.updateBatjBa1(sheet);
  317. dao.updateBatjBa2(sheet);
  318. dao.deleteOldDisdiag(bah, times);
  319. if (!sheet.getDisdiagList().isEmpty()) {
  320. List<CaseFrontsheetDisdiag> diags = sheet.getDisdiagList();
  321. for (int i = 0; i < diags.size(); i++) {
  322. CaseFrontsheetDisdiag item = diags.get(i);
  323. if (StringUtil.isBlank(item.getCode())) {
  324. break;
  325. }
  326. item.setNo(i + 1);
  327. item.setBah(bah);
  328. item.setTimes(times);
  329. dao.writeNewDisdiag(item);
  330. }
  331. }
  332. dao.deleteOldSurgeryRecord(bah, times);
  333. if (!sheet.getSurgeryList().isEmpty()) {
  334. List<CaseFrontsheetSurgery> surgeries = sheet.getSurgeryList();
  335. for (int i = 0; i < surgeries.size(); i++) {
  336. CaseFrontsheetSurgery item = surgeries.get(i);
  337. if (StringUtil.isBlank(item.getCode())) {
  338. break;
  339. }
  340. if (null == item.getDate()) {
  341. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "手术日期不能为空!");
  342. }
  343. item.setNo(i + 1);
  344. item.setBah(bah);
  345. item.setTimes(times);
  346. dao.writeNewZySurgeryRecord(item);
  347. }
  348. }
  349. return ResultVoUtil.success();
  350. }
  351. public ResultVo<List<PureCodeName>> signApply(CaseFrontsheetMain sheet) {
  352. Integer status = dao.getSignApplyStatus(sheet.getBah(), sheet.getAdmissTimes());
  353. if (null == status) {
  354. List<PureCodeName> message = VerifyCaseFrontSheet.getInstance().printVerify(sheet);
  355. if (message.isEmpty()) {
  356. dao.insertNewSignApply(sheet.getBah(), sheet.getAdmissTimes(),
  357. sheet.getName(), sheet.getSex(), TokenUtil.getTokenUserId());
  358. return ResultVoUtil.success();
  359. }
  360. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "校验未通过。", message);
  361. }
  362. if (status == 0) {
  363. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "此病案已提交过归档申请,请耐心等待病案室签收。");
  364. }
  365. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "此病案已签收,无法继续申请。");
  366. }
  367. private ResultVo<List<PureCodeName>> archiveSheet(CaseFrontsheetMain sheet) {
  368. String staff = TokenUtil.getTokenUserId();
  369. if (userDao.getUserRoles(staff).contains(7)) {
  370. String bah = sheet.getBah();
  371. int times = sheet.getAdmissTimes();
  372. if (isLateSubmit(sheet.getDismissDate()) > 8) {
  373. sheet.setLateFlag(1);
  374. } else {
  375. sheet.setLateFlag(0);
  376. }
  377. //插入数据 SignDate 签收日期 在点击签收后 向数据库中插入
  378. sheet.setSignDate(new Date());
  379. sheet.setFileStatus(1);
  380. //判断是否已经插入过了
  381. Integer fileStatus = dao.selectFileStatus(sheet.getBah(), sheet.getAdmissTimes());
  382. if (null != fileStatus && fileStatus == 1) {
  383. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请勿重复签收 ( ˉ ⌓ ˉ ๑)");
  384. }
  385. //在t_case_frontsheet_main表中插入 主体的内容
  386. dao.insert(sheet);
  387. //循环插主要的诊断
  388. for (CaseFrontsheetDisdiag caseFrontsheetDisdiag : sheet.getDisdiagList()) {
  389. caseFrontsheetDisdiag.setBah(sheet.getBah());
  390. caseFrontsheetDisdiag.setTimes(sheet.getAdmissTimes());
  391. if (caseFrontsheetDisdiag.getNo() != null) {
  392. createdDao.insert(caseFrontsheetDisdiag);
  393. }
  394. }
  395. //循环插入做过的手术
  396. for (CaseFrontsheetSurgery caseFrontsheetSurgery : sheet.getSurgeryList()) {
  397. caseFrontsheetSurgery.setBah(sheet.getBah());
  398. caseFrontsheetSurgery.setTimes(sheet.getAdmissTimes());
  399. if (caseFrontsheetSurgery.getNo() != null) {
  400. basDao.insert(caseFrontsheetSurgery);
  401. }
  402. }
  403. basDao.updateActFileStatus(bah, times, 1);
  404. dao.updateSignApply(bah, times, staff);
  405. return ResultVoUtil.success();
  406. }
  407. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有签收首页的权限。");
  408. }
  409. @Transactional(rollbackFor = Exception.class)
  410. public synchronized ResultVo<String> unArchiveSheet(OpCaseFrontsheet param) {
  411. CaseFrontsheetMain sheet = param.getSheet();
  412. if (sheet.getFileStatus() == 0) {
  413. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未签收的病案首页无需解除签收!");
  414. }
  415. Map<String, Object> map = new HashMap<>();
  416. map.put("bah", sheet.getBah());
  417. map.put("admiss_times", sheet.getAdmissTimes());
  418. dao.deleteByMap(map);
  419. map.put("times", map.remove("admiss_times"));
  420. createdDao.deleteByMap(map);
  421. basDao.deleteByMap(map);
  422. log.info("解除签收状态, 操作员:{} >>> 住院号:{}, 住院次数:{}",
  423. param.getStaffId(), sheet.getBah(), sheet.getAdmissTimes());
  424. basDao.updateActFileStatus(sheet.getBah(), sheet.getAdmissTimes(), 0);
  425. dao.writeBaOpLog(param.getOpType(), param.getStaffId(), sheet.getBah(), sheet.getAdmissTimes());
  426. log.info("写入病案操作日志, 操作员:{} >>> 住院号:{}, 住院次数:{}, 操作编码:{}",
  427. param.getStaffId(), sheet.getBah(), sheet.getAdmissTimes(), param.getOpType());
  428. return ResultVoUtil.success("已成功解除签收。");
  429. }
  430. private JSONObject qualityControl(CaseFrontsheetMain sheet) {
  431. JSONObject obj = new JSONObject();
  432. obj.put("functionId", "100138");
  433. JSONObject baseinfo = new JSONObject();
  434. baseinfo.put("name", sheet.getName());
  435. baseinfo.put("age", sheet.getAge());
  436. baseinfo.put("sex_id", sheet.getSex());
  437. String agedays = sheet.getAgeDays();
  438. if (null != agedays && agedays.equals("-")) {
  439. agedays = "";
  440. }
  441. baseinfo.put("nwb_age", agedays);
  442. baseinfo.put("out_hosp_id", FilterUtil.filterDismissWay(sheet.getZyDismissWay()));
  443. baseinfo.put("is_autopsy_id", sheet.getAutopsy());
  444. JSONObject inputParam = new JSONObject();
  445. inputParam.put("baseInfo", baseinfo);
  446. JSONArray hsptzdDagnsInfo = new JSONArray();
  447. for (CaseFrontsheetDisdiag diag : sheet.getDisdiagList()) {
  448. if (null == diag.getNo()) {
  449. break;
  450. }
  451. JSONObject itm = new JSONObject();
  452. itm.put("icd_code", diag.getCode());
  453. itm.put("dagns_type", diag.getNo() == 1 ? 1 : 2);
  454. itm.put("disease_name", diag.getName());
  455. itm.put("order", diag.getNo());
  456. hsptzdDagnsInfo.add(itm);
  457. }
  458. inputParam.put("hsptzdDagnsInfo", hsptzdDagnsInfo);
  459. JSONArray hsptzdOprtInfo = new JSONArray();
  460. for (CaseFrontsheetSurgery surgery : sheet.getSurgeryList()) {
  461. if (null == surgery.getNo()) {
  462. break;
  463. }
  464. JSONObject itm = new JSONObject();
  465. itm.put("oprt_code", surgery.getCode());
  466. itm.put("oprt_name", surgery.getName());
  467. itm.put("oprt_type", surgery.getNo() == 1 ? 1 : 2);
  468. itm.put("order", surgery.getNo());
  469. hsptzdOprtInfo.add(itm);
  470. }
  471. inputParam.put("hsptzdOprtInfo", hsptzdOprtInfo);
  472. obj.put("inputParam", inputParam);
  473. try {
  474. JSONObject result = srvc.setlQualityControl(obj);
  475. log.info("病案质控接口:\n参数:{}\n结果:{}", obj, result);
  476. return result;
  477. } catch (Exception e) {
  478. log.error("创智诊断校验访问失败:http://172.16.32.183:8917/mmg-transceiver/interfaceFactory/call");
  479. return null;
  480. }
  481. }
  482. public ResultVo<Map<String, List<PureCodeName>>> infoVerification(OpCaseFrontsheet param) {
  483. CaseFrontsheetMain sheet = param.getSheet();
  484. if (sheet.getFileStatus() == 2) {
  485. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "已最终归档病案首页无法打印!");
  486. }
  487. ResultVo<List<PureCodeName>> save = saveSheet(param.getSheet());
  488. if (save.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  489. Map<String, List<PureCodeName>> map = new HashMap<>();
  490. map.put("force", save.getData());
  491. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "校验未通过。", map);
  492. }
  493. List<PureCodeName> force = VerifyCaseFrontSheet.getInstance().printVerify(sheet);
  494. List<PureCodeName> advice = new ArrayList<>();
  495. JSONObject powersi = qualityControl(sheet);
  496. if (null != powersi) {
  497. JSONObject responseEntity = powersi.getJSONObject("responseEntity");
  498. if (null != responseEntity) {
  499. JSONArray retarr = responseEntity.getJSONArray("newSettleMemInfo");
  500. if (null != retarr && retarr.size() > 0) {
  501. for (int i = 0; i < retarr.size(); i++) {
  502. advice.add(new PureCodeName("", retarr.getJSONObject(i).getString("result_msg")));
  503. }
  504. }
  505. }
  506. }
  507. if (force.isEmpty()) {
  508. saveSheet(sheet);
  509. if (advice.isEmpty()) {
  510. return ResultVoUtil.success();
  511. }
  512. }
  513. Map<String, List<PureCodeName>> map = new HashMap<>();
  514. map.put("force", force);
  515. map.put("advice", advice);
  516. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "校验未通过。", map);
  517. }
  518. public ResultVo<List<PureCodeName>> saveVerify(OpCaseFrontsheet info) {
  519. CaseFrontsheetMain sheet = info.getSheet();
  520. if (sheet.getFileStatus() == 1 && !userDao.getUserRoles(TokenUtil.getTokenUserId()).contains(7)) {
  521. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "已签收的病案首页无法保存,如需保存,请联系病案室对此病案解除签收。");
  522. }
  523. if (sheet.getFileStatus() == 2) {
  524. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "已打印的病案首页无法再次保存!");
  525. }
  526. int optype = info.getOpType();
  527. List<PureCodeName> message = optype == 1 ? VerifyCaseFrontSheet.getInstance().saveVerify(sheet) :
  528. VerifyCaseFrontSheet.getInstance().printVerify(sheet);
  529. if (message.isEmpty()) {
  530. final String bah = sheet.getBah();
  531. final int times = sheet.getAdmissTimes();
  532. dao.writeBaOpLog(optype, info.getStaffId(), bah, times);
  533. return optype == 1 ? saveSheet(sheet) : archiveSheet(sheet);
  534. } else {
  535. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "校验未通过。", message);
  536. }
  537. }
  538. public ResultVo<List<YiBaoDisdiag>> getYbDiags(String bah, int times) {
  539. List<YiBaoDisdiag> diags = dao.getYbDiags(bah, times);
  540. return ResultVoUtil.success(diags);
  541. }
  542. @Transactional
  543. public ResultVo<String> saveYbDiags(SaveYbDiagParam param) {
  544. dao.deleteOldYbDiag(param.getBah(), param.getTimes());
  545. List<String> diagCodes = new ArrayList<>();
  546. for (int i = 0; i < param.getYbDiags().size(); i++) {
  547. YiBaoDisdiag diag = param.getYbDiags().get(i);
  548. if (StringUtil.isBlank(diag.getCode())) {
  549. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【诊断序号:" + diag.getNo() + "】诊断编码不能为空!");
  550. }
  551. if (StringUtil.isBlank(diag.getName())) {
  552. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【诊断序号:" + diag.getNo() + "】诊断名称不能为空!");
  553. }
  554. if (StringUtil.isBlank(diag.getCyzg())) {
  555. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【诊断序号:" + diag.getNo() + "】出院转归不能为空!");
  556. }
  557. if (null == diag.getSiDiagType()) {
  558. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【诊断序号:" + diag.getNo() + "】诊断类别不能为空!");
  559. }
  560. if (diagCodes.contains(diag.getCode())) {
  561. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【诊断编码:" + diag.getCode() + "】请勿填入重复的诊断!");
  562. }
  563. diagCodes.add(diag.getCode());
  564. diag.setNo(i + 1);
  565. diag.setBah(param.getBah());
  566. diag.setTimes(param.getTimes());
  567. dao.insertNewYbDiag(diag);
  568. }
  569. return ResultVoUtil.success();
  570. }
  571. @Transactional(rollbackFor = Exception.class)
  572. public ResultVo<String> lendOut(OpCaseFrontsheet param) {
  573. CaseFrontsheetMain sheet = param.getSheet();
  574. if (sheet.getFileStatus() == 0) {
  575. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未签收的病案不可借阅!");
  576. }
  577. if (sheet.getLendFlag() == 1) {
  578. BorrowBase info = dao.getBorrowInfo(sheet.getBah(), sheet.getAdmissTimes());
  579. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该病案已于:" +
  580. DateUtil.formatDatetime(info.getBorrowDate()) + " 借阅给【" + info.getBorrowName() + "】。");
  581. }
  582. if (null == sheet.getBorrowDate() || null == sheet.getBorrowId()) {
  583. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "借阅人和借阅时间不可为空!");
  584. }
  585. log.info("借阅> 时间:{},借阅人:{},操作员:{},病案号:{},住院次数:{}",
  586. sheet.getBorrowDate(), sheet.getBorrowId(), param.getStaffId(), sheet.getBah(), sheet.getAdmissTimes());
  587. dao.lendZyOut(sheet.getBah(), sheet.getAdmissTimes());
  588. dao.lendZyInOut(sheet.getBah(), sheet.getAdmissTimes());
  589. dao.writeLendOutLog(param.getStaffId(), sheet.getBah(), sheet.getAdmissTimes(),
  590. sheet.getBorrowId(), sheet.getBorrowDate());
  591. return ResultVoUtil.success();
  592. }
  593. @Transactional(rollbackFor = Exception.class)
  594. public ResultVo<String> lendBack(OpCaseFrontsheet param) {
  595. CaseFrontsheetMain sheet = param.getSheet();
  596. if (sheet.getLendFlag() != 1) {
  597. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未借阅的病案无需收回!");
  598. }
  599. BorrowBase info = dao.getBorrowInfo(sheet.getBah(), sheet.getAdmissTimes());
  600. dao.lendZyBack(sheet.getBah(), sheet.getAdmissTimes());
  601. dao.lendZyInBack(sheet.getBah(), sheet.getAdmissTimes());
  602. dao.writeLendBackLog(param.getStaffId(), sheet.getBah(), sheet.getAdmissTimes(),
  603. info.getBorrowId(), info.getBorrowDate());
  604. return ResultVoUtil.success();
  605. }
  606. public ResultVo<List<SheetOverview>> advanceSearch(AdvanceSearchParam param) {
  607. return ResultVoUtil.success(dao.advanceSearch(param));
  608. }
  609. public ResultVo<String> fetchSsfz(String code, String bah, Integer times) {
  610. DisefamilyGrade disefamilyGrade = dao.selectDisefamilyGrade(code);
  611. if (null == disefamilyGrade) {
  612. return ResultVoUtil.success("无对照的病种。");
  613. }
  614. boolean hasModified = dao.selectModified(bah, times) > 0;
  615. List<String> surgeries = hasModified ? dao.selectPatientSurgeryCodes(bah, times, "batj_ba4_modify")
  616. : dao.selectPatientSurgeryCodes(bah, times, "batj_ba4");
  617. if (ListUtil.isBlank(surgeries)) {
  618. return ResultVoUtil.success("有对照的非手术分值:" + disefamilyGrade.getNoneOprnGrade());
  619. }
  620. List<OprnDisefamilyGrade> oprnGrades = dao.selectOperationDisefamilies(disefamilyGrade.getDisefamilyCode());
  621. int ssfz = 0;
  622. for (OprnDisefamilyGrade oprn : oprnGrades) {
  623. if (surgeries.contains(oprn.getOprnCode())) {
  624. if (oprn.getOprnGrade() > ssfz) {
  625. ssfz = oprn.getOprnGrade();
  626. }
  627. }
  628. }
  629. if (ssfz != 0) {
  630. return ResultVoUtil.success("有对照的手术分值:" + ssfz);
  631. }
  632. return ResultVoUtil.success("有对照的非手术分值:" + disefamilyGrade.getNoneOprnGrade());
  633. }
  634. private int isLateSubmit(Date dismissDate) {
  635. long days = (System.currentTimeMillis() - dismissDate.getTime()) / 1000 / (3600 * 24);
  636. return (int) days;
  637. }
  638. public ResultVo<List<DismissCount>> analyzeDismissCount(GetDisCount param) {
  639. String begntime = param.getMonth() + "-01 00:00:00.000";
  640. String endtime = DateUtil.getMonthEndtime(param.getMonth());
  641. int type = param.getType();
  642. List<DismissCount> list;
  643. if (type == 1) {
  644. List<TempDismissCount> templist = dao.selectDismissCount(begntime, endtime);
  645. Map<String, DismissCount> map = new HashMap<>();
  646. for (TempDismissCount item : templist) {
  647. if (map.containsKey(item.getDeptCode())) {
  648. DismissCount count = map.get(item.getDeptCode());
  649. count.setDismissCount(count.getDismissCount() + item.getDismissCount());
  650. if (item.getFileStatus() == 1) {
  651. count.setSignedCount(count.getSignedCount() + item.getDismissCount());
  652. } else {
  653. count.setUnsignCount(count.getUnsignCount() + item.getDismissCount());
  654. }
  655. } else {
  656. DismissCount dismissCount = new DismissCount();
  657. dismissCount.setDeptName(redis.getDeptName(item.getDeptCode()));
  658. dismissCount.setDismissCount(item.getDismissCount());
  659. if (item.getFileStatus() == 1) {
  660. dismissCount.setSignedCount(item.getDismissCount());
  661. dismissCount.setUnsignCount(0);
  662. } else {
  663. dismissCount.setUnsignCount(item.getDismissCount());
  664. dismissCount.setSignedCount(0);
  665. }
  666. map.put(item.getDeptCode(), dismissCount);
  667. }
  668. }
  669. list = new ArrayList<>();
  670. for (Map.Entry<String, DismissCount> entry : map.entrySet()) {
  671. list.add(entry.getValue());
  672. }
  673. } else {
  674. list = dao.selectDismissDetailCount(begntime, endtime, param.getDept());
  675. if (type == 3) {
  676. list.removeIf(item -> item.getDeadOrder() == 0);
  677. }
  678. for (DismissCount item : list) {
  679. if (StringUtil.equalsIgnoreNull(item.getZkWard(), item.getAdmissDept())) {
  680. item.setZkWard(null);
  681. }
  682. item.setDisDept(redis.getDeptName(item.getDisDept()));
  683. item.setBlfx(filterBlfx(item.getBlfx()));
  684. item.setAdmissDept(redis.getDeptName(item.getAdmissDept()));
  685. item.setZkWard(redis.getDeptName(item.getZkWard()));
  686. item.setKzr(redis.getEmployeeName(item.getKzr()));
  687. item.setZzys(redis.getEmployeeName(item.getZzys()));
  688. item.setZyys(redis.getEmployeeName(item.getZyys()));
  689. item.setFdcrb(filterFdcrb(item.getFdcrb()));
  690. }
  691. }
  692. return ResultVoUtil.success(list);
  693. }
  694. private String filterBlfx(String val) {
  695. switch (val) {
  696. case "1":
  697. return "A";
  698. case "2":
  699. return "B";
  700. case "3":
  701. return "C";
  702. case "4":
  703. return "D";
  704. default:
  705. return "";
  706. }
  707. }
  708. private String filterFdcrb(String val) {
  709. switch (val) {
  710. case "1":
  711. return "甲类";
  712. case "2":
  713. return "乙类";
  714. case "3":
  715. return "丙类";
  716. default:
  717. return "";
  718. }
  719. }
  720. public void increaseDiagWeight(String code) {
  721. dao.increaseDiagWeight(code);
  722. }
  723. }