SiManageService.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package thyyxxk.webserver.service.medicalinsurance;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.Capacity;
  10. import thyyxxk.webserver.constants.YesOrNo;
  11. import thyyxxk.webserver.constants.frntsheet.CaseClassification;
  12. import thyyxxk.webserver.constants.sidicts.*;
  13. import thyyxxk.webserver.dao.his.medicalinsurance.SiLogDao;
  14. import thyyxxk.webserver.dao.his.medicalinsurance.SiManageDao;
  15. import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao;
  16. import thyyxxk.webserver.entity.ResultVo;
  17. import thyyxxk.webserver.entity.dictionary.PureCodeName;
  18. import thyyxxk.webserver.entity.medicalinsurance.log.SiLog;
  19. import thyyxxk.webserver.entity.medicalinsurance.manage.*;
  20. import thyyxxk.webserver.entity.medicalinsurance.manage.clinicinfo.*;
  21. import thyyxxk.webserver.entity.medicalinsurance.manage.deptmanage.DeptInfo;
  22. import thyyxxk.webserver.entity.medicalinsurance.manage.deptmanage.DeptInfoQuery;
  23. import thyyxxk.webserver.entity.medicalinsurance.manage.deptmanage.MedStaffQuery;
  24. import thyyxxk.webserver.entity.medicalinsurance.manage.detailanalyse.*;
  25. import thyyxxk.webserver.entity.medicalinsurance.manage.examination.BilgItemInfo;
  26. import thyyxxk.webserver.entity.medicalinsurance.manage.frontsheet.Baseinfo;
  27. import thyyxxk.webserver.entity.medicalinsurance.manage.frontsheet.Diseinfo;
  28. import thyyxxk.webserver.entity.medicalinsurance.manage.frontsheet.Icuinfo;
  29. import thyyxxk.webserver.entity.medicalinsurance.manage.frontsheet.Oprninfo;
  30. import thyyxxk.webserver.entity.medicalinsurance.manage.goods.*;
  31. import thyyxxk.webserver.entity.medicalinsurance.manage.orderinfo.ActOrder;
  32. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
  33. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SlctSetlPrm;
  34. import thyyxxk.webserver.service.redislike.RedisLikeService;
  35. import thyyxxk.webserver.utils.*;
  36. import java.io.IOException;
  37. import java.math.BigDecimal;
  38. import java.nio.file.Files;
  39. import java.nio.file.Paths;
  40. import java.util.*;
  41. /**
  42. * @description: 医保管理服务,包涵项目对照等
  43. * @author: DingJie
  44. * @create: 2021/6/2914:44
  45. */
  46. @Service
  47. @Slf4j
  48. public class SiManageService {
  49. private static final String RESULT_CODE = "infcode";
  50. private static final String ERROR_MESSAGE = "err_msg";
  51. private static final String OUTPUT = "output";
  52. private final ExecService exec;
  53. private final SiUploadService upldServcie;
  54. private final SiDownloadService dldService;
  55. private final SiManageDao dao;
  56. private final SiSetlinfoDao setlinfoDao;
  57. private final SiLogDao logDao;
  58. private final RedisLikeService redis;
  59. @Autowired
  60. public SiManageService(ExecService exec, SiUploadService upldServcie,
  61. SiDownloadService dldService, SiManageDao dao, SiSetlinfoDao setlinfoDao, SiLogDao logDao, RedisLikeService redis) {
  62. this.exec = exec;
  63. this.upldServcie = upldServcie;
  64. this.dldService = dldService;
  65. this.dao = dao;
  66. this.setlinfoDao = setlinfoDao;
  67. this.logDao = logDao;
  68. this.redis = redis;
  69. }
  70. public ResultVo<String> uploadCatalogueContrast(CatalogueContrast prm) {
  71. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_CATALOGUE_CONTRAST);
  72. JSONArray data = new JSONArray();
  73. setListType(prm);
  74. List<String> codes = new ArrayList<>();
  75. prm.getList().forEach(item -> {
  76. codes.add(item.getCode());
  77. JSONObject catalogue = new JSONObject();
  78. catalogue.put("fixmedins_hilist_id", item.getCode());
  79. catalogue.put("fixmedins_hilist_name", item.getName());
  80. catalogue.put("list_type", prm.getListType());
  81. catalogue.put("med_list_codg", item.getNationalCode());
  82. catalogue.put("begndate", DateUtil.formatDatetime(prm.getBeginDate()));
  83. catalogue.put("enddate", DateUtil.formatDatetime(prm.getEndDate()));
  84. data.add(catalogue);
  85. });
  86. input.getJSONObject("input").put("data", data);
  87. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_CATALOGUE_CONTRAST);
  88. log.info("【操作员:{}】,上传目录对照:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  89. if (null == result) {
  90. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  91. }
  92. Integer infcode = result.getInteger(RESULT_CODE);
  93. logDao.insert(new SiLog(input, result, null, null, null, infcode, null));
  94. if (null == infcode) {
  95. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  96. }
  97. if (infcode == 0) {
  98. dao.updateUploadedFlag(prm.getTable(), YesOrNo.YES.getCode(), codes);
  99. return ResultVoUtil.success("上传目录对照成功。");
  100. }
  101. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  102. }
  103. public ResultVo<String> revokeCatalogueContrast(CatalogueContrast prm) {
  104. setListType(prm);
  105. JSONObject input = exec.makeTradeHeader(SiFunction.REVOKE_CATALOGUE_CONTRAST);
  106. JSONObject data = new JSONObject();
  107. data.put("fixmedins_code", SiUtil.INSTITUTION_ID);
  108. data.put("fixmedins_hilist_id", prm.getChargeCode());
  109. data.put("list_type", prm.getListType());
  110. data.put("med_list_codg", prm.getNationalCode());
  111. input.getJSONObject("input").put("data", data);
  112. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_CATALOGUE_CONTRAST);
  113. log.info("【操作员:{}】,撤销目录:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  114. if (null == result) {
  115. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  116. }
  117. Integer infcode = result.getInteger(RESULT_CODE);
  118. logDao.insert(new SiLog(input, result, null, null, null, infcode, null));
  119. if (null == infcode) {
  120. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  121. }
  122. if (infcode == 0) {
  123. dao.updateUploadedFlag2(prm.getTable(), prm.getChargeCode());
  124. return ResultVoUtil.success("撤销目录对照成功。");
  125. }
  126. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  127. }
  128. private void setListType(CatalogueContrast prm) {
  129. String table = "yp_zd_dict";
  130. switch (prm.getType()) {
  131. case 1:
  132. prm.setListType(ListType.WEST_PATENT.getCode());
  133. break;
  134. case 2:
  135. prm.setListType(ListType.HERBAL.getCode());
  136. break;
  137. case 3:
  138. prm.setListType(ListType.SERVICE.getCode());
  139. table = "zd_charge_item";
  140. break;
  141. case 4:
  142. prm.setListType(ListType.SUPPLY.getCode());
  143. table = "zd_charge_item";
  144. break;
  145. }
  146. prm.setTable(table);
  147. }
  148. public ResultVo<String> autoRecoveryTrade(AtoRcvTrd atoRcvTrd) {
  149. Integer recoveryTradePermission = dao.recoveryTradePermission(TokenUtil.getTokenUserId());
  150. if (null == recoveryTradePermission || recoveryTradePermission == 0) {
  151. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您没有冲正交易的权限!");
  152. }
  153. JSONObject input = exec.makeTradeHeader(SiFunction.AUTO_RECOVERY_TRADE);
  154. String ref = JSONObject.toJSONString(atoRcvTrd);
  155. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  156. JSONObject result = exec.executeTrade(input, SiFunction.AUTO_RECOVERY_TRADE);
  157. log.info("【操作员:{}】,冲正交易:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  158. Integer infcode = result.getInteger(RESULT_CODE);
  159. logDao.insert(new SiLog(input, result, null, null, null, infcode, atoRcvTrd.getPsnNo()));
  160. return SiUtil.makeReturnWithoutOutput(result, "冲正成功。");
  161. }
  162. public ResultVo<String> institutionSettlementLedgerCheck(InstStlLdgChk instStlLdgChk) {
  163. String startdate = DateUtil.getDayStartTime(instStlLdgChk.getStmtBegndate());
  164. String enddate = DateUtil.getDayEndTime(instStlLdgChk.getStmtEnddate());
  165. List<InstSetlLdgChkBrf> brfs = dao.selectSetlChkBrfsWithInsutype(instStlLdgChk.getClrType(), instStlLdgChk.getInsutype(),
  166. instStlLdgChk.getSetlOptins(), startdate, enddate);
  167. BigDecimal medfeesum = new BigDecimal("0");
  168. BigDecimal acctpaysum = new BigDecimal("0");
  169. BigDecimal fundpaysum = new BigDecimal("0");
  170. for (InstSetlLdgChkBrf brf : brfs) {
  171. medfeesum = DecimalUtil.add(medfeesum, brf.getMedfeeSumamt());
  172. acctpaysum = DecimalUtil.add(acctpaysum, brf.getAcctPay());
  173. fundpaysum = DecimalUtil.add(fundpaysum, brf.getFundPaySumamt());
  174. if (null != brf.getHospPay()) {
  175. fundpaysum = DecimalUtil.minus(fundpaysum, brf.getHospPay());
  176. }
  177. }
  178. instStlLdgChk.setMedfeeSumamt(medfeesum);
  179. instStlLdgChk.setAcctPay(acctpaysum);
  180. instStlLdgChk.setFundPaySumamt(fundpaysum);
  181. instStlLdgChk.setFixmedinsSetlCnt(brfs.size());
  182. JSONObject input = exec.makeTradeHeader(SiFunction.INSTITUTION_SETTLEMENT_LEDGER_CHECK);
  183. String ref = JSONObject.toJSONStringWithDateFormat(instStlLdgChk, "yyyy-MM-dd");
  184. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  185. JSONObject result = exec.executeTrade(input, SiFunction.INSTITUTION_SETTLEMENT_LEDGER_CHECK);
  186. log.info("【操作员:{}】,医药机构费用结算对总账:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  187. if (null == result) {
  188. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  189. }
  190. if (null == result.getInteger(RESULT_CODE)) {
  191. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  192. }
  193. if (result.getIntValue(RESULT_CODE) == 0) {
  194. JSONObject output = result.getJSONObject(OUTPUT);
  195. JSONObject info = output.getJSONObject("stmtinfo");
  196. String setlOptins = info.getString("setl_optins");
  197. Admdvs admdvs = Admdvs.get(setlOptins);
  198. String optins;
  199. if (null == admdvs) {
  200. optins = redis.getRegionName(setlOptins);
  201. } else {
  202. optins = admdvs.getName();
  203. }
  204. String rslt;
  205. if (info.getString("stmt_rslt").equals(StmtRslt.CORRECT.getCode())) {
  206. rslt = StmtRslt.CORRECT.getName();
  207. } else {
  208. rslt = StmtRslt.WRONG.getName();
  209. }
  210. String dscr = info.getString("stmt_rslt_dscr");
  211. if (StringUtil.isBlank(dscr)) {
  212. dscr = "结算笔数:" + brfs.size() +
  213. ",医疗费总额:" + medfeesum + ",基金支付总额:" + fundpaysum;
  214. }
  215. String data = "【清算机构:" + optins + "】对账结果:" + rslt + "。对账结果说明:" + dscr;
  216. if (rslt.equals(StmtRslt.CORRECT.getName())) {
  217. return ResultVoUtil.success(data);
  218. }
  219. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, data);
  220. }
  221. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  222. }
  223. public ResultVo<List<InsSetlDetlChkRslt>> institutionSettlementDetailCheck(InsSetlDetlChk insSetlDetlChk) {
  224. String snowId = SnowFlakeId.instance().nextId();
  225. String filename = snowId + ".txt";
  226. StringBuilder fsIn = new StringBuilder();
  227. String startdate = DateUtil.getDayStartTime(insSetlDetlChk.getStmtBegndate());
  228. String enddate = DateUtil.getDayEndTime(insSetlDetlChk.getStmtEnddate());
  229. List<InstSetlLdgChkBrf> brfs = dao.selectSetlChkBrfs(insSetlDetlChk.getClrType(),
  230. insSetlDetlChk.getSetlOptins(), startdate, enddate);
  231. BigDecimal medfeesum = new BigDecimal("0");
  232. BigDecimal psnCashPay = new BigDecimal("0");
  233. BigDecimal fundpaysum = new BigDecimal("0");
  234. for (InstSetlLdgChkBrf brf : brfs) {
  235. medfeesum = DecimalUtil.add(medfeesum, brf.getMedfeeSumamt());
  236. psnCashPay = DecimalUtil.add(psnCashPay, brf.getPsnCashPay());
  237. fundpaysum = DecimalUtil.add(fundpaysum, brf.getFundPaySumamt());
  238. if (null != brf.getHospPay()) {
  239. fundpaysum = DecimalUtil.minus(fundpaysum, brf.getHospPay());
  240. brf.setFundPaySumamt(DecimalUtil.minus(brf.getFundPaySumamt(), brf.getHospPay()));
  241. }
  242. }
  243. insSetlDetlChk.setMedfeeSumamt(medfeesum);
  244. insSetlDetlChk.setCashPayamt(psnCashPay);
  245. insSetlDetlChk.setFundPaySumamt(fundpaysum);
  246. insSetlDetlChk.setFixmedinsSetlCnt(brfs.size());
  247. for (InstSetlLdgChkBrf item : brfs) {
  248. fsIn.append(item.getSetlId()).append("\t")
  249. .append(item.getMdtrtId()).append("\t")
  250. .append(item.getPsnNo()).append("\t")
  251. .append(item.getMedfeeSumamt()).append("\t")
  252. .append(item.getFundPaySumamt()).append("\t")
  253. .append(item.getAcctPay()).append("\t")
  254. .append(insSetlDetlChk.getRefdSetlFlag()).append("\n");
  255. }
  256. try {
  257. Files.write(Paths.get(filename), fsIn.toString().getBytes());
  258. String zipFile = ZipUtil.zip(filename);
  259. ZipUtil.deleteFile(filename);
  260. String fsUploadIn = "{\"filename\": \"" + filename + ".zip\", \"fixmedins_code\": \"" +
  261. SiUtil.INSTITUTION_ID + "\", \"in\": " + Arrays.toString(ZipUtil.zipFileToBytes(zipFile)) + "}";
  262. ResultVo<String> uplRes = upldServcie.uploadFile(JSONObject.parseObject(fsUploadIn), filename);
  263. ZipUtil.deleteFile(zipFile);
  264. if (uplRes.getCode().equals(ExceptionEnum.SUCCESS.getCode())) {
  265. insSetlDetlChk.setFileQuryNo(uplRes.getData());
  266. }
  267. } catch (IOException e) {
  268. log.error("医药机构费用结算对明细账出错", e);
  269. }
  270. JSONObject input = exec.makeTradeHeader(SiFunction.INSTITUTION_SETTLEMENT_DETAIL_CHECK);
  271. String ref = JSONObject.toJSONStringWithDateFormat(insSetlDetlChk, "yyyy-MM-dd");
  272. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  273. JSONObject result = exec.executeTrade(input, SiFunction.INSTITUTION_SETTLEMENT_DETAIL_CHECK);
  274. log.info("【操作员:{}】,医药机构费用结算对明细账:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  275. if (null == result) {
  276. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  277. }
  278. if (null == result.getInteger(RESULT_CODE)) {
  279. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  280. }
  281. if (result.getIntValue(RESULT_CODE) == 0) {
  282. JSONObject output = result.getJSONObject(OUTPUT);
  283. JSONObject fileinfo = output.getJSONObject("fileinfo");
  284. String filePath = dldService.downloadFile(fileinfo.getString("file_qury_no"), fileinfo.getString("filename"));
  285. Queue<String> queue = SiUtil.readTxtFile(filePath);
  286. if (null == queue || queue.size() == 0) {
  287. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未能成功获取到对账结果。");
  288. }
  289. List<InsSetlDetlChkRslt> list = new ArrayList<>();
  290. while (queue.size() > 0) {
  291. String item = queue.poll();
  292. String[] arr = item.split("\t");
  293. InsSetlDetlChkRslt rslt = new InsSetlDetlChkRslt(arr);
  294. list.add(rslt);
  295. }
  296. return ResultVoUtil.success(list);
  297. }
  298. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  299. }
  300. public ResultVo<Map<String, Object>> selectSetlinfos(SlctSetlPrm prm) {
  301. QueryWrapper<SiSetlinfo> wrapper = new QueryWrapper<>();
  302. if (StringUtil.notBlank(prm.getInsutype())) {
  303. wrapper.eq("insutype", prm.getInsutype());
  304. }
  305. String begndate = DateUtil.formatDatetime(prm.getStmtBegndate(), "yyyy-MM-dd") + " 00:00:00";
  306. String enddate = DateUtil.formatDatetime(prm.getStmtEnddate(), "yyyy-MM-dd") + " 23:59:59";
  307. wrapper.eq("setl_type", prm.getClrType());
  308. wrapper.eq("revoked", YesOrNo.NO.getCode());
  309. wrapper.apply("fund_pay_sumamt!=0");
  310. wrapper.apply("setl_time>='" + begndate + "'");
  311. wrapper.apply("setl_time<='" + enddate + "'");
  312. wrapper.apply("(insuplc_admdvs='439900' or insuplc_admdvs like '4301%') ");
  313. List<SiSetlinfo> list = setlinfoDao.selectList(wrapper);
  314. if (null == list || list.isEmpty()) {
  315. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到符合条件的数据。");
  316. }
  317. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  318. Map<String, String> optinsMap = new HashMap<>();
  319. List<PureCodeName> optinList = new ArrayList<>();
  320. list.forEach(item -> {
  321. Admdvs admdvs = Admdvs.get(item.getClrOptins());
  322. if (null == admdvs) {
  323. item.setClrOptinsName(redis.getRegionName(item.getClrOptins()));
  324. } else {
  325. item.setClrOptinsName(admdvs.getName());
  326. }
  327. if (!optinsMap.containsKey(item.getClrOptins())) {
  328. optinsMap.put(item.getClrOptins(), item.getClrOptinsName());
  329. }
  330. FilterUtil.filterCodeToName(item);
  331. });
  332. map.put("list", list);
  333. for (Map.Entry<String, String> entry : optinsMap.entrySet()) {
  334. optinList.add(new PureCodeName(entry.getKey(), entry.getValue()));
  335. }
  336. map.put("optins", optinList);
  337. return ResultVoUtil.success(map);
  338. }
  339. public ResultVo<String> detailAnalyse(String patNo, int times, int ledger, int type) {
  340. SiFunction function = type == 1 ? SiFunction.ITEMIZED_REVIEW_ANALYSIS_SERVICES_BEFORE
  341. : SiFunction.ITEMIZED_REVIEW_ANALYSIS_SERVICES_MIDDLE;
  342. String logpart = type == 1 ? "明细审核事前分析" : "明细审核事中分析";
  343. JSONObject input = exec.makeTradeHeader(function);
  344. MainPart mainPart = new MainPart();
  345. mainPart.setSyscode("csthyy");
  346. mainPart.setTaskId(SnowFlakeId.instance().nextId());
  347. mainPart.setTrigScen("1");
  348. PatientDtos patientDtos = dao.selectPatientDto(patNo, times);
  349. FsiEncounterDtos fsiEncounterDtos = dao.selectFsiEncounterDto(patNo, times);
  350. fsiEncounterDtos.setAdmDeptName(redis.getDeptName(fsiEncounterDtos.getAdmDeptCodg()));
  351. fsiEncounterDtos.setDscgDeptCodg(fsiEncounterDtos.getAdmDeptCodg());
  352. fsiEncounterDtos.setDscgDeptName(fsiEncounterDtos.getAdmDeptName());
  353. List<FsiDiagnoseDtos> fsiDiagnoseDtos = dao.selectFsiDiagnoseDtos(patNo, times);
  354. fsiEncounterDtos.setFsiDiagnoseDtos(fsiDiagnoseDtos);
  355. String setlId = dao.selectSetlId(patNo, times);
  356. List<FsiOrderDtos> tempFsiOrderDtos = dao.selectFsiOrderDtos(patNo, times, setlId);
  357. Map<String, Integer> distinctOrderMap = new HashMap<>();
  358. List<FsiOrderDtos> fsiOrderDtos = new ArrayList<>();
  359. tempFsiOrderDtos.forEach(item -> {
  360. if (!distinctOrderMap.containsKey(item.getRxId())) {
  361. distinctOrderMap.put(item.getRxId(), 1);
  362. item.setDrordDrProfttl(DrordDrProfttl.getCodeByHisCode(item.getDrordDrProfttl()));
  363. fsiOrderDtos.add(item);
  364. }
  365. });
  366. fsiEncounterDtos.setFsiOrderDtos(fsiOrderDtos);
  367. patientDtos.setFsiEncounterDtos(fsiEncounterDtos);
  368. FsiHisDataDto fsiHisDataDto = new FsiHisDataDto();
  369. mainPart.setPatientDtos(patientDtos);
  370. // mainPart.setFsiHisDataDto(fsiHisDataDto);
  371. String ref = JSONObject.toJSONStringWithDateFormat(mainPart, "yyyy-MM-dd HH:mm:ss");
  372. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  373. JSONObject result = exec.executeTrade(input, function);
  374. log.info("【操作员:{}】,{}:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), logpart, input, result);
  375. Integer infcode = result.getInteger(RESULT_CODE);
  376. logDao.insert(new SiLog(input, result, patNo, times, ledger, infcode, "psn_no"));
  377. return SiUtil.makeReturnWithoutOutput(result, "分析结果。");
  378. }
  379. public ResultVo<String> deptInfoUpload(DeptInfo deptInfo) {
  380. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_DEPARTMENT_INFO);
  381. String ref = JSONObject.toJSONStringWithDateFormat(deptInfo, "yyyy-MM-dd HH:mm:ss");
  382. input.getJSONObject("input").put("deptinfo", JSONObject.parseObject(ref));
  383. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_DEPARTMENT_INFO);
  384. log.info("【操作员:{}】,科室信息上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  385. Integer infcode = result.getInteger(RESULT_CODE);
  386. logDao.insert(new SiLog(input, result, null, null, null, infcode, null));
  387. return SiUtil.makeReturnWithoutOutput(result, "科室信息上传成功。");
  388. }
  389. public ResultVo<String> deptInfoBatchUpload(List<DeptInfo> deptInfos) {
  390. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_DEPARTMENT_INFO_IN_BATCH);
  391. String ref = JSONArray.toJSONStringWithDateFormat(deptInfos, "yyyy-MM-dd HH:mm:ss");
  392. input.getJSONObject("input").put("deptinfo", JSONArray.parseArray(ref));
  393. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_DEPARTMENT_INFO_IN_BATCH);
  394. log.info("【操作员:{}】,科室信息批量上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  395. Integer infcode = result.getInteger(RESULT_CODE);
  396. logDao.insert(new SiLog(input, result, null, null, null, infcode, null));
  397. return SiUtil.makeReturnWithoutOutput(result, "科室信息批量上传成功。");
  398. }
  399. public ResultVo<String> deptInfoModify(DeptInfo deptInfo) {
  400. JSONObject input = exec.makeTradeHeader(SiFunction.MODIFY_DEPARTMENT_INFO);
  401. String ref = JSONObject.toJSONStringWithDateFormat(deptInfo, "yyyy-MM-dd HH:mm:ss");
  402. input.getJSONObject("input").put("deptinfo", JSONObject.parseObject(ref));
  403. JSONObject result = exec.executeTrade(input, SiFunction.MODIFY_DEPARTMENT_INFO);
  404. log.info("【操作员:{}】,科室信息变更:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  405. Integer infcode = result.getInteger(RESULT_CODE);
  406. logDao.insert(new SiLog(input, result, null, null, null, infcode, null));
  407. return SiUtil.makeReturnWithoutOutput(result, "科室信息变更成功。");
  408. }
  409. public ResultVo<String> deptInfoDelete(DeptInfo deptInfo) {
  410. JSONObject input = exec.makeTradeHeader(SiFunction.REVOKE_DEPARTMENT_INFO);
  411. JSONObject data = new JSONObject();
  412. data.put("hosp_dept_codg", deptInfo.getHospDeptCodg());
  413. data.put("hosp_dept_name", deptInfo.getHospDeptName());
  414. data.put("begntime", DateUtil.formatDatetime(deptInfo.getBegntime(), "yyyy-MM-dd"));
  415. input.getJSONObject("input").put("data", data);
  416. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_DEPARTMENT_INFO);
  417. log.info("【操作员:{}】,科室信息撤销:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  418. Integer infcode = result.getInteger(RESULT_CODE);
  419. logDao.insert(new SiLog(input, result, null, null, null, infcode, null));
  420. return SiUtil.makeReturnWithoutOutput(result, "科室信息撤销成功。");
  421. }
  422. public ResultVo<JSONObject> queryDeptInfo(DeptInfoQuery query) {
  423. JSONObject input = exec.makeTradeHeader(SiFunction.QUERY_DEPARTMENT_INFO);
  424. query.setInfno(SiFunction.QUERY_DEPARTMENT_INFO.getCode());
  425. query.setMsgid(input.getString("msgid"));
  426. query.setInfTime(input.getString("inf_time"));
  427. query.setFixmedinsCode(SiUtil.INSTITUTION_ID);
  428. query.setFixmedinsName(SiUtil.INSTITUTION_NAME);
  429. query.setSignNo(input.getString("sign_no"));
  430. query.setInfver(SiUtil.API_VERSION);
  431. String ref = JSONObject.toJSONString(query);
  432. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  433. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_DEPARTMENT_INFO);
  434. log.info("【操作员:{}】,科室信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  435. Integer infcode = result.getInteger(RESULT_CODE);
  436. if (null == infcode) {
  437. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  438. }
  439. if (infcode == 0) {
  440. return ResultVoUtil.success(result.getJSONObject(OUTPUT));
  441. }
  442. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  443. }
  444. // 接口存在问题
  445. public ResultVo<JSONObject> queryMedStaffInfo(MedStaffQuery query) {
  446. String ref = JSONObject.toJSONString(query);
  447. JSONObject input = exec.makeTradeHeader(SiFunction.QUERY_MEDICAL_STAFF_INFO);
  448. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  449. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_MEDICAL_STAFF_INFO);
  450. log.info("【操作员:{}】,医执人员信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  451. Integer infcode = result.getInteger(RESULT_CODE);
  452. if (null == infcode) {
  453. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  454. }
  455. if (infcode == 0) {
  456. return ResultVoUtil.success(result.getJSONObject(OUTPUT));
  457. }
  458. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  459. }
  460. public ResultVo<JSONObject> queryExaminationExInfo(BilgItemInfo bilgItemInfo) {
  461. String ref = JSONObject.toJSONString(bilgItemInfo);
  462. JSONObject input = exec.makeTradeHeader(SiFunction.QUERY_MUTUAL_ACCREDIT_INFO);
  463. input.getJSONObject("input").put("bilgiteminfo", JSONObject.parseObject(ref));
  464. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_MUTUAL_ACCREDIT_INFO);
  465. log.info("【操作员:{}】,项目互认信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  466. Integer infcode = result.getInteger(RESULT_CODE);
  467. if (null == infcode) {
  468. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  469. }
  470. if (infcode == 0) {
  471. return ResultVoUtil.success(result.getJSONObject(OUTPUT));
  472. }
  473. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  474. }
  475. public ResultVo<JSONObject> queryExaminationDetail(String psnNo, String reportNo) {
  476. JSONObject input = exec.makeTradeHeader(SiFunction.QUERY_DIAGNOSIS_REPORT_DETAIL);
  477. JSONObject rptdetailinfo = new JSONObject();
  478. rptdetailinfo.put("psn_no", psnNo);
  479. rptdetailinfo.put("rpotc_no", reportNo);
  480. rptdetailinfo.put("fixmedins_code", SiUtil.INSTITUTION_ID);
  481. input.getJSONObject("input").put("rptdetailinfo", rptdetailinfo);
  482. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_DIAGNOSIS_REPORT_DETAIL);
  483. log.info("【操作员:{}】,报告明细信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  484. Integer infcode = result.getInteger(RESULT_CODE);
  485. if (null == infcode) {
  486. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  487. }
  488. if (infcode == 0) {
  489. return ResultVoUtil.success(result.getJSONObject(OUTPUT));
  490. }
  491. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  492. }
  493. public ResultVo<String> uploadInvinfo(InvinfoUpload invinfo) {
  494. String ref = JSONObject.toJSONStringWithDateFormat(invinfo, "yyyy-MM-dd");
  495. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_COMMODITY_INVENTORY);
  496. input.getJSONObject("input").put("invinfo", JSONObject.parseObject(ref));
  497. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_COMMODITY_INVENTORY);
  498. log.info("【操作员:{}】,商品盘存上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  499. return SiUtil.makeReturnWithoutOutput(result, "商品盘存上传成功。");
  500. }
  501. public ResultVo<String> modifyInvinfo(InvinfoModify invinfo) {
  502. String ref = JSONObject.toJSONStringWithDateFormat(invinfo, "yyyy-MM-dd HH:mm:ss");
  503. JSONObject input = exec.makeTradeHeader(SiFunction.CHANGE_COMMODITY_INVENTORY);
  504. input.getJSONObject("input").put("invinfo", JSONObject.parseObject(ref));
  505. JSONObject result = exec.executeTrade(input, SiFunction.CHANGE_COMMODITY_INVENTORY);
  506. log.info("【操作员:{}】,商品盘存修改:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  507. return SiUtil.makeReturnWithoutOutput(result, "商品盘存修改成功。");
  508. }
  509. public ResultVo<String> purchaseGoods(PurcinfoBought purcinfo) {
  510. String ref = JSONObject.toJSONString(purcinfo);
  511. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_COMMODITY_PURCHASE);
  512. input.getJSONObject("input").put("purcinfo", JSONObject.parseObject(ref));
  513. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_COMMODITY_PURCHASE);
  514. log.info("【操作员:{}】,商品采购上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  515. return SiUtil.makeReturnWithoutOutput(result, "商品采购上传成功。");
  516. }
  517. public ResultVo<String> returnGoods(PurcinfoBought purcinfo) {
  518. String ref = JSONObject.toJSONString(purcinfo);
  519. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_COMMODITY_PURCHASE_RETURN);
  520. input.getJSONObject("input").put("purcinfo", JSONObject.parseObject(ref));
  521. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_COMMODITY_PURCHASE_RETURN);
  522. log.info("【操作员:{}】,商品采购退货:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  523. return SiUtil.makeReturnWithoutOutput(result, "商品采购退货成功。");
  524. }
  525. public ResultVo<String> saleGoods(SelinfoSold selinfo) {
  526. String ref = JSONObject.toJSONString(selinfo);
  527. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_COMMODITY_SALES);
  528. input.getJSONObject("input").put("selinfo", JSONObject.parseObject(ref));
  529. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_COMMODITY_SALES);
  530. log.info("【操作员:{}】,商品销售上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  531. return SiUtil.makeReturnWithoutOutput(result, "商品销售上传成功。");
  532. }
  533. public ResultVo<String> returnSales(SelinfoReturn selinfo) {
  534. String ref = JSONObject.toJSONString(selinfo);
  535. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_COMMODITY_SALES_RETURN);
  536. input.getJSONObject("input").put("selinfo", JSONObject.parseObject(ref));
  537. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_COMMODITY_SALES_RETURN);
  538. log.info("【操作员:{}】,商品销售退货:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  539. return SiUtil.makeReturnWithoutOutput(result, "商品销售退货成功。");
  540. }
  541. public ResultVo<String> deleteGoods(String fixmedinsBchno, int type) {
  542. JSONObject input = exec.makeTradeHeader(SiFunction.DELETE_COMMODITY_INFO);
  543. JSONObject data = new JSONObject();
  544. data.put("fixmedins_bchno", fixmedinsBchno);
  545. data.put("inv_data_type", type); // 1-盘存信息;2-库存变更信息;3-采购信息;4-销售信息
  546. input.getJSONObject("input").put("data", data);
  547. JSONObject result = exec.executeTrade(input, SiFunction.DELETE_COMMODITY_INFO);
  548. log.info("【操作员:{}】,商品删除:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  549. return SiUtil.makeReturnWithoutOutput(result, "商品删除成功。");
  550. }
  551. public ResultVo<String> modifySetllistState(String psnNo, String setlId, int type) {
  552. JSONObject input = exec.makeTradeHeader(SiFunction.MODIFY_SI_SETTLE_STATE);
  553. JSONObject data = new JSONObject();
  554. data.put("psn_no", psnNo);
  555. data.put("setl_id", setlId);
  556. data.put("stas_type", type); // 0未提交,1已提交
  557. input.getJSONObject("input").put("data", data);
  558. JSONObject result = exec.executeTrade(input, SiFunction.MODIFY_SI_SETTLE_STATE);
  559. log.info("【操作员:{}】,结算清单状态修改:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  560. return SiUtil.makeReturnWithoutOutput(result, "结算清单状态修改成功。");
  561. }
  562. public ResultVo<JSONObject> querySetllistInfo(String psnNo, String setlId) {
  563. JSONObject input = exec.makeTradeHeader(SiFunction.QUERY_SI_SETTLE_INFO);
  564. JSONObject data = new JSONObject();
  565. data.put("psn_no", psnNo);
  566. data.put("setl_id", setlId);
  567. input.getJSONObject("input").put("data", data);
  568. JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SI_SETTLE_INFO);
  569. log.info("【操作员:{}】,结算清单信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  570. Integer infcode = result.getInteger(RESULT_CODE);
  571. if (null == infcode) {
  572. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  573. }
  574. if (infcode == 0) {
  575. return ResultVoUtil.success(result.getJSONObject(OUTPUT));
  576. }
  577. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  578. }
  579. public ResultVo<String> uploadFrontSheet(String patNo, int times) {
  580. Baseinfo baseinfo = dao.selectFrontSheetBaseInfo(patNo, times);
  581. baseinfo.setCtd(CaseClassification.getWjwCodeByHisCode(baseinfo.getCtd()));
  582. List<Diseinfo> diseinfos = dao.selectYbDisdiags(patNo, times);
  583. if (null == diseinfos || diseinfos.isEmpty()) {
  584. diseinfos = dao.selectFrontSheetDiseInfo(patNo, times);
  585. }
  586. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_FRONT_SHEET_INFO);
  587. String base = JSONObject.toJSONStringWithDateFormat(baseinfo, "yyyy-MM-dd");
  588. String dise = JSONArray.toJSONString(diseinfos);
  589. List<Icuinfo> icuinfos = new ArrayList<>();
  590. Icuinfo icuinfo = new Icuinfo();
  591. icuinfo.setValiFlag("0");
  592. icuinfo.setIptMedcasHmpgSn(diseinfos.get(0).getIptMedcasHmpgSn());
  593. icuinfo.setMdtrtSn(diseinfos.get(0).getMdtrtSn());
  594. icuinfos.add(icuinfo);
  595. String icu = JSONArray.toJSONString(icuinfos);
  596. List<Oprninfo> oprninfos = new ArrayList<>();
  597. Oprninfo oprninfo = new Oprninfo();
  598. oprninfo.setValiFlag("0");
  599. oprninfo.setIptMedcasHmpgSn(diseinfos.get(0).getIptMedcasHmpgSn());
  600. oprninfo.setMdtrtSn(diseinfos.get(0).getMdtrtSn());
  601. oprninfos.add(oprninfo);
  602. String oprn = JSONArray.toJSONString(oprninfos);
  603. input.getJSONObject("input").put("baseinfo", JSONObject.parseObject(base));
  604. input.getJSONObject("input").put("diseinfo", JSONArray.parseArray(dise));
  605. input.getJSONObject("input").put("oprninfo", JSONArray.parseArray(oprn));
  606. input.getJSONObject("input").put("icuinfo", JSONArray.parseArray(icu));
  607. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_FRONT_SHEET_INFO);
  608. log.info("【操作员:{}】,病案首页信息上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  609. return SiUtil.makeReturnWithoutOutput(result, "病案首页信息上传成功。");
  610. }
  611. public ResultVo<String> uploadActOrder(String patNo, int times) {
  612. List<ActOrder> actOrders = dao.selectActOrders(patNo, times);
  613. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_ACT_ORDER);
  614. String ref = JSONArray.toJSONStringWithDateFormat(actOrders, "yyyy-MM-dd HH:mm:ss");
  615. input.getJSONObject("input").put("data", JSONArray.parseArray(ref));
  616. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_ACT_ORDER);
  617. log.info("【操作员:{}】,医嘱记录上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  618. return SiUtil.makeReturnWithoutOutput(result, "医嘱记录上传成功。");
  619. }
  620. public ResultVo<String> uploadClinicRecord(String patNo, int times) {
  621. ClinicRegistration clinicRegistration = dao.selectClinicRegistration(patNo, times);
  622. List<ClinicDiseinfo> diseinfos = dao.selectClinicDiseinfo(patNo, times);
  623. List<ClinicRxinfo> rxinfos = dao.selectClinicRxinfo(patNo, times);
  624. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_CLINIC_RECORD);
  625. String rgstinfo = JSONObject.toJSONStringWithDateFormat(clinicRegistration, "yyyy-MM-dd HH:mm:ss");
  626. input.getJSONObject("input").put("rgstinfo", JSONObject.parseObject(rgstinfo));
  627. input.getJSONObject("input").put("caseinfo", new JSONArray());
  628. String diseinfo = JSONArray.toJSONString(diseinfos);
  629. input.getJSONObject("input").put("diseinfo", JSONArray.parseArray(diseinfo));
  630. String rxinfo = JSONArray.toJSONStringWithDateFormat(rxinfos, "yyyy-MM-dd HH:mm:ss");
  631. input.getJSONObject("input").put("rxinfo", JSONArray.parseArray(rxinfo));
  632. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_CLINIC_RECORD);
  633. log.info("【操作员:{}】,门急诊诊疗记录上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  634. return SiUtil.makeReturnWithoutOutput(result, "门急诊诊疗记录上传成功。");
  635. }
  636. public ResultVo<String> uploadEmergencyRecord(String patNo, int times) {
  637. List<EmergencyOprninfo> oprninfos = dao.selectEmergencyOprninfos(patNo, times);
  638. List<EmergencyRescueinfo> rescueinfos = new ArrayList<>();
  639. String oprninfo = JSONArray.toJSONString(oprninfos);
  640. String rescueinfo = JSONArray.toJSONString(rescueinfos);
  641. JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_EMERGENCY_RECORD);
  642. input.getJSONObject("input").put("oprninfo", JSONArray.parseArray(oprninfo));
  643. input.getJSONObject("input").put("rescinfo", JSONArray.parseArray(rescueinfo));
  644. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_EMERGENCY_RECORD);
  645. log.info("【操作员:{}】,急诊留观手术及抢救信息上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  646. return SiUtil.makeReturnWithoutOutput(result, "急诊留观手术及抢救信息上传成功。");
  647. }
  648. }