SiManageService.java 37 KB

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