SiZyService.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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.beans.factory.annotation.Value;
  8. import org.springframework.stereotype.Service;
  9. import thyyxxk.webserver.config.exception.ExceptionEnum;
  10. import thyyxxk.webserver.constants.sidicts.*;
  11. import thyyxxk.webserver.constants.YesOrNo;
  12. import thyyxxk.webserver.dao.his.inpatient.PatientDao;
  13. import thyyxxk.webserver.dao.his.medicalinsurance.*;
  14. import thyyxxk.webserver.entity.ResultVo;
  15. import thyyxxk.webserver.entity.inpatient.patient.NotUploadedFee;
  16. import thyyxxk.webserver.entity.medicalinsurance.log.SiLog;
  17. import thyyxxk.webserver.entity.medicalinsurance.inpatient.*;
  18. import thyyxxk.webserver.entity.medicalinsurance.manage.InsSetlDetlChkRslt;
  19. import thyyxxk.webserver.entity.medicalinsurance.manage.InstStlLdgChk;
  20. import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo;
  21. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail;
  22. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
  23. import thyyxxk.webserver.entity.inpatient.dismiss.MedinsSettleFee;
  24. import thyyxxk.webserver.entity.inpatient.patient.Overview;
  25. import thyyxxk.webserver.service.externalhttp.SiZySrvc;
  26. import thyyxxk.webserver.service.inpatient.DismissService;
  27. import thyyxxk.webserver.utils.*;
  28. import java.math.BigDecimal;
  29. import java.util.*;
  30. /**
  31. * @description: 住院医保交易
  32. * @author: DingJie
  33. * @create: 2021-05-14 16:28:16
  34. **/
  35. @Slf4j
  36. @Service
  37. public class SiZyService {
  38. private static final String RESULT_CODE = "infcode";
  39. private static final String ERROR_MESSAGE = "err_msg";
  40. private static final String OUTPUT = "output";
  41. private final SiZyDao dao;
  42. private final PatientDao patientDao;
  43. private final SiQueryService queryService;
  44. private final SiQueryDao queryDao;
  45. private final SiSetlinfoDao setlinfodao;
  46. private final SiSetldetailDao setldetldao;
  47. private final SiChargeTempDao chrgtmpdao;
  48. private final SiLogDao logDao;
  49. private final ExecService exec;
  50. private final DismissService dismissService;
  51. private final SiZySrvc zySrvc;
  52. private final SiManageService manageService;
  53. @Value("${si-zy-fee-url}")
  54. private String siZyFeeUrl;
  55. @Autowired
  56. public SiZyService(SiZyDao dao, PatientDao patientDao, SiQueryService queryService, SiQueryDao queryDao, SiSetlinfoDao setlinfoDao,
  57. SiSetldetailDao setldetldao, SiChargeTempDao chrgtmpdao, SiLogDao logDao, ExecService exec,
  58. DismissService dismissService, SiZySrvc zySrvc, SiManageService manageService) {
  59. this.dao = dao;
  60. this.patientDao = patientDao;
  61. this.queryService = queryService;
  62. this.queryDao = queryDao;
  63. this.setlinfodao = setlinfoDao;
  64. this.setldetldao = setldetldao;
  65. this.chrgtmpdao = chrgtmpdao;
  66. this.logDao = logDao;
  67. this.exec = exec;
  68. this.dismissService = dismissService;
  69. this.zySrvc = zySrvc;
  70. this.manageService = manageService;
  71. }
  72. public ResultVo<String> admissRegister(ZyPatientInfo p) {
  73. AdmMdtrtinfo admMdtrtinfo = dao.selectAdmMdtrtinfo(p.getInpatientNo(), p.getLedgerSn());
  74. if (null == admMdtrtinfo) {
  75. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的参保信息!");
  76. }
  77. Date setlEndTime = dao.selectSetlEndTime(p.getInpatientNo(), p.getAdmissTimes());
  78. if (null != setlEndTime && setlEndTime.after(admMdtrtinfo.getBegntime())) {
  79. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者有 " +
  80. DateUtil.formatDatetime(setlEndTime, "yyyy-MM-dd") + " 的医保结算条目,不可重复登记。");
  81. }
  82. if (StringUtil.isBlank(admMdtrtinfo.getChfpdrName())) {
  83. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "管床医生不能为空!");
  84. }
  85. List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
  86. if (null == admDiseinfos || admDiseinfos.isEmpty()) {
  87. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
  88. }
  89. admDiseinfos.forEach(item -> {
  90. item.setDiseDorNo(admMdtrtinfo.getAtddrNo());
  91. item.setDiseDorName(admMdtrtinfo.getChfpdrName());
  92. });
  93. ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
  94. if (readCardBizType != ReadCardBizType.ADMISSION && !p.getInsuplcAdmdvs().startsWith("43")) {
  95. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "省外异地的患者请读社保卡登记!");
  96. }
  97. if (readCardBizType == ReadCardBizType.ADMISSION) {
  98. MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
  99. admMdtrtinfo.setMdtrtCertType(mdtrtCertType.getCode());
  100. if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) {
  101. String[] out = p.getReadCardResult().split("\\|");
  102. if (!p.getName().trim().equals(out[4].trim())) {
  103. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "社保卡姓名与HIS姓名不一致,请确认是否人证相符。");
  104. }
  105. admMdtrtinfo.setMdtrtCertNo(out[2]);
  106. admMdtrtinfo.setCardSn(out[3]);
  107. } else if (mdtrtCertType.getCode().equals(MdtrtCertType.MEDICAL_INSURANCE_ELECTRONIC_VOUCHER.getCode())) {
  108. JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
  109. if (!p.getName().trim().equals(qrinfo.getString("userName").trim())) {
  110. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证姓名与HIS姓名不一致,请确认是否人证相符。");
  111. }
  112. if (!p.getSocialNo().trim().equals(qrinfo.getString("idNo").trim())) {
  113. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。");
  114. }
  115. admMdtrtinfo.setMdtrtCertNo(qrinfo.getString("ecToken"));
  116. }
  117. }
  118. if (StringUtil.isBlank(admMdtrtinfo.getDiseCodg())) {
  119. admMdtrtinfo.setDiseCodg(admDiseinfos.get(0).getDiagCode());
  120. admMdtrtinfo.setDiseName(admDiseinfos.get(0).getDiagName());
  121. }
  122. admMdtrtinfo.setInsutype(p.getInsutype());
  123. admMdtrtinfo.setAdmDiagDscr(admDiseinfos.get(0).getDiagName());
  124. admMdtrtinfo.setDscgMaindiagCode(admDiseinfos.get(0).getDiagCode());
  125. admMdtrtinfo.setDscgMaindiagName(admDiseinfos.get(0).getDiagName());
  126. admMdtrtinfo.setMatnType(p.getMatnType());
  127. admMdtrtinfo.setLatechbFlag(p.getLatechbFlag());
  128. admMdtrtinfo.setPretFlag(p.getPretFlag());
  129. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.ADMISSION_REGISTRATION, p.getInsuplcAdmdvs());
  130. String ref = JSONObject.toJSONStringWithDateFormat(admMdtrtinfo, "yyyy-MM-dd HH:mm:ss");
  131. input.getJSONObject("input").put("mdtrtinfo", JSONObject.parseObject(ref));
  132. String diseRef = JSONArray.toJSONStringWithDateFormat(admDiseinfos, "yyyy-MM-dd HH:mm:ss");
  133. input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
  134. JSONObject result = exec.executeTrade(input, SiFunction.ADMISSION_REGISTRATION);
  135. log.info("【操作员:{}】,医保入院登记:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  136. if (null == result) {
  137. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  138. }
  139. Integer infcode = result.getInteger(RESULT_CODE);
  140. if (null == infcode) {
  141. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  142. }
  143. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, admMdtrtinfo.getPsnNo()));
  144. if (result.getIntValue(RESULT_CODE) == 0) {
  145. JSONObject output = result.getJSONObject(OUTPUT);
  146. String mdtrtId = output.getJSONObject("result").getString("mdtrt_id");
  147. p.setMdtrtId(mdtrtId);
  148. p.setAdmRegMsgid(input.getString("msgid"));
  149. dao.afterAdmissRegister(p);
  150. String restype = dao.selectResponceType(admMdtrtinfo.getMedType());
  151. dao.updateResponceType(restype, admMdtrtinfo.getMedType(), p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  152. return ResultVoUtil.success("入院登记成功,就诊号为:" + mdtrtId);
  153. }
  154. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  155. }
  156. public ResultVo<String> modifyAdmissionInfo(ZyPatientInfo p) {
  157. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  158. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  159. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保不在院!");
  160. }
  161. List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
  162. if (null == admDiseinfos || admDiseinfos.isEmpty()) {
  163. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
  164. }
  165. admDiseinfos.forEach(item -> item.setMdtrtId(siPatInfo.getMdtrtId()));
  166. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.MODIFY_ADMISSION_INFO, siPatInfo.getInsuplcAdmdvs());
  167. JSONObject adminfo = new JSONObject();
  168. adminfo.put("mdtrt_id", siPatInfo.getMdtrtId());
  169. adminfo.put("psn_no", siPatInfo.getPsnNo());
  170. adminfo.put("begntime", DateUtil.formatDatetime(p.getYbRegisterDate()));
  171. adminfo.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  172. adminfo.put("med_type", siPatInfo.getMedType());
  173. adminfo.put("ipt_otp_no", p.getInpatientNo());
  174. adminfo.put("atddr_no", p.getReferPhysician());
  175. adminfo.put("chfpdr_name", p.getReferPhysicianName());
  176. adminfo.put("adm_diag_dscr", admDiseinfos.get(0).getDiagCode());
  177. adminfo.put("adm_dept_codg", p.getSmallDept());
  178. adminfo.put("adm_dept_name", p.getSmallDeptName());
  179. adminfo.put("adm_bed", p.getBedNo());
  180. adminfo.put("dscg_maindiag_code", admDiseinfos.get(0).getDiagCode());
  181. adminfo.put("dscg_maindiag_name", admDiseinfos.get(0).getDiagName());
  182. input.getJSONObject("input").put("adminfo", adminfo);
  183. String diseRef = JSONArray.toJSONStringWithDateFormat(admDiseinfos, "yyyy-MM-dd HH:mm:ss");
  184. input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
  185. JSONObject result = exec.executeTrade(input, SiFunction.MODIFY_ADMISSION_INFO);
  186. log.info("【操作员:{}】,入院信息变更:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  187. Integer infcode = result.getInteger(RESULT_CODE);
  188. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, siPatInfo.getPsnNo()));
  189. return SiUtil.makeReturnWithoutOutput(result, "变更住院信息成功。");
  190. }
  191. public ResultVo<String> revokeAdmission(ZyPatientInfo p) {
  192. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  193. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  194. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  195. }
  196. revokeUploadFees(p);
  197. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_ADMISSION, siPatInfo.getInsuplcAdmdvs());
  198. JSONObject data = new JSONObject();
  199. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  200. data.put("psn_no", siPatInfo.getPsnNo());
  201. input.getJSONObject("input").put("data", data);
  202. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_ADMISSION);
  203. log.info("【操作员:{}】,取消入院登记:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  204. if (null == result) {
  205. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  206. }
  207. Integer infcode = result.getInteger(RESULT_CODE);
  208. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, siPatInfo.getPsnNo()));
  209. if (null == infcode) {
  210. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  211. }
  212. if (infcode == 0) {
  213. queryDao.clearMdtrtIdForZy(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(), null);
  214. dao.updateResponceType("01", null, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  215. return ResultVoUtil.success("取消入院登记成功。");
  216. }
  217. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  218. }
  219. public ResultVo<String> uploadFeeDetail(Overview o) {
  220. o.setStaffId(TokenUtil.getTokenUserId());
  221. return zySrvc.uploadFeeDetail(siZyFeeUrl, o);
  222. }
  223. public ResultVo<String> multipleUpload(List<Overview> overviews) {
  224. for (Overview o : overviews) {
  225. if (o.getStatus() == 0) {
  226. String message = String.format("【%s床,%s,%s】未进行医保登记,无法进行费用上传。",
  227. o.getBedNo(), o.getInpatientNo(), o.getName());
  228. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, message);
  229. }
  230. if (invalidMultipleUploadPatient(o.getMedType())) {
  231. String message = String.format("【%s床,%s,%s】是工伤患者,不支持批量上传。",
  232. o.getBedNo(), o.getInpatientNo(), o.getName());
  233. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, message);
  234. }
  235. o.setStaffId(TokenUtil.getTokenUserId());
  236. }
  237. return zySrvc.uploadMultiplePatientFees(siZyFeeUrl, overviews);
  238. }
  239. private boolean invalidMultipleUploadPatient(String medtype) {
  240. MedType medType = MedType.get(medtype);
  241. return null == medType || medType == MedType.INJURY_HOSPITALIZATION || medType == MedType.SELF_PAY;
  242. }
  243. public ResultVo<String> hospitalizationPreSettlement(ZyPatientInfo p) {
  244. PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
  245. p.getLedgerSn(), DateUtil.getTodayEndTime());
  246. if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
  247. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  248. }
  249. preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  250. preSetlmt.setPsnSetlway(p.getDbg() ? PsnSetlWay.SETTLE_BY_QUOTA.getCode() : PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  251. preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
  252. preSetlmt.setMidSetlFlag(YesOrNo.NO.getCodeStr());
  253. preSetlmt.setMdtrtareaAdmvs(SiUtil.getInstitutionArea(preSetlmt.getInsuplcAdmdvs()));
  254. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.HOSPITALIZATION_PRE_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
  255. String ref = JSONObject.toJSONString(preSetlmt);
  256. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  257. JSONObject result = exec.executeTrade(input, SiFunction.HOSPITALIZATION_PRE_SETTLEMENT);
  258. log.info("预结算:\n参数:{},\n结果:{}", input, result);
  259. if (null == result) {
  260. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  261. }
  262. Integer infcode = result.getInteger(RESULT_CODE);
  263. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, preSetlmt.getPsnNo()));
  264. if (null == infcode) {
  265. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  266. }
  267. if (infcode == 0) {
  268. JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  269. String fundPay = setlinfo.getString("fund_pay_sumamt");
  270. dao.updateFundPay(fundPay, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  271. patientDao.recountDeposit(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  272. patientDao.updateBalance(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  273. String balance = patientDao.selectLedgerBalance(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  274. if (StringUtil.isBlank(balance)) {
  275. balance = "0";
  276. }
  277. patientDao.updateZyActPatientBalance(p.getInpatientNo(), balance);
  278. String message = "患者【" + p.getName() + "】院内总费用与医保中心总费用一致,医保报销金额为:¥ " + fundPay + "。";
  279. return ResultVoUtil.success(message);
  280. }
  281. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  282. }
  283. public ResultVo<String> revokeUploadFees(ZyPatientInfo p) {
  284. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  285. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  286. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  287. }
  288. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs());
  289. JSONArray data = new JSONArray();
  290. if (null == p.getDetailSns() || p.getDetailSns().isEmpty()) {
  291. JSONObject item = new JSONObject();
  292. item.put("feedetl_sn", "0000");
  293. item.put("mdtrt_id", siPatInfo.getMdtrtId());
  294. item.put("psn_no", siPatInfo.getPsnNo());
  295. data.add(item);
  296. } else {
  297. p.getDetailSns().forEach(detailSn -> {
  298. JSONObject item = new JSONObject();
  299. item.put("feedetl_sn", detailSn);
  300. item.put("mdtrt_id", siPatInfo.getMdtrtId());
  301. item.put("psn_no", siPatInfo.getPsnNo());
  302. data.add(item);
  303. });
  304. }
  305. input.getJSONObject("input").put("data", data);
  306. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS);
  307. log.info("【操作员:{}】撤销已上传的费用:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  308. if (null == result) {
  309. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  310. }
  311. Integer infcode = result.getInteger(RESULT_CODE);
  312. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, siPatInfo.getPsnNo()));
  313. if (null == infcode) {
  314. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  315. }
  316. if (infcode == 0) {
  317. QueryWrapper<SiChargeTemp> wrapper = new QueryWrapper<>();
  318. wrapper.eq("pat_no", p.getInpatientNo());
  319. wrapper.eq("times", p.getAdmissTimes());
  320. wrapper.eq("ledger_sn", p.getLedgerSn());
  321. if (null == p.getDetailSns() || p.getDetailSns().isEmpty()) {
  322. dao.revokeAllUploadFee(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  323. dao.resetFundpayAmt(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  324. chrgtmpdao.delete(wrapper);
  325. } else {
  326. wrapper.in("feedetl_sn", p.getDetailSns());
  327. chrgtmpdao.delete(wrapper);
  328. dao.revokePartUploadFee(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), p.getDetailSns());
  329. }
  330. return ResultVoUtil.success("撤销费用上传成功。");
  331. }
  332. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  333. }
  334. public ResultVo<String> pairNegativeFee(NotUploadedFee fee) {
  335. if (null == fee.getOriDetailSn()) {
  336. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先处理违规退费。");
  337. }
  338. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(fee.getPatNo(), fee.getTimes(), fee.getLedgerSn());
  339. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS,
  340. siPatInfo.getInsuplcAdmdvs());
  341. JSONArray data = new JSONArray();
  342. JSONObject item = new JSONObject();
  343. item.put("feedetl_sn", fee.getOriDetailSn());
  344. item.put("mdtrt_id", siPatInfo.getMdtrtId());
  345. item.put("psn_no", siPatInfo.getPsnNo());
  346. data.add(item);
  347. input.getJSONObject("input").put("data", data);
  348. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS);
  349. log.info("【操作员:{}】退费处理:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  350. if (null == result) {
  351. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  352. }
  353. Integer infcode = result.getInteger(RESULT_CODE);
  354. logDao.insert(new SiLog(input, result, fee.getPatNo(), fee.getTimes(), fee.getLedgerSn(), infcode, siPatInfo.getPsnNo()));
  355. if (null == infcode) {
  356. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  357. }
  358. if (infcode == 0) {
  359. QueryWrapper<SiChargeTemp> wrapper = new QueryWrapper<>();
  360. wrapper.eq("pat_no", fee.getPatNo());
  361. wrapper.eq("times", fee.getTimes());
  362. wrapper.eq("ledger_sn", fee.getLedgerSn());
  363. wrapper.eq("feedetl_sn", fee.getOriDetailSn());
  364. chrgtmpdao.delete(wrapper);
  365. dao.updateYbTransFlagInPair(fee.getPatNo(), fee.getTimes(), fee.getDetailSn(), fee.getOriDetailSn());
  366. }
  367. return ResultVoUtil.success("退费处理成功。");
  368. }
  369. public ResultVo<String> revokeSingleCharge(String patNo, int times, int ledgerSn, int detailSn) {
  370. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(patNo, times, ledgerSn);
  371. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS,
  372. siPatInfo.getInsuplcAdmdvs());
  373. JSONArray data = new JSONArray();
  374. JSONObject item = new JSONObject();
  375. item.put("feedetl_sn", detailSn);
  376. item.put("mdtrt_id", siPatInfo.getMdtrtId());
  377. item.put("psn_no", siPatInfo.getPsnNo());
  378. data.add(item);
  379. input.getJSONObject("input").put("data", data);
  380. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS);
  381. log.info("【操作员:{}】退费处理:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  382. if (null == result) {
  383. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  384. }
  385. Integer infcode = result.getInteger(RESULT_CODE);
  386. logDao.insert(new SiLog(input, result, patNo, times, ledgerSn, infcode, siPatInfo.getPsnNo()));
  387. if (null == infcode) {
  388. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  389. }
  390. if (infcode == 0) {
  391. QueryWrapper<SiChargeTemp> wrapper = new QueryWrapper<>();
  392. wrapper.eq("pat_no", patNo);
  393. wrapper.eq("times", times);
  394. wrapper.eq("ledger_sn", ledgerSn);
  395. wrapper.eq("feedetl_sn", detailSn);
  396. chrgtmpdao.delete(wrapper);
  397. dao.updateSingleYbTransFlag(patNo, times, detailSn);
  398. }
  399. return ResultVoUtil.success("处理成功。");
  400. }
  401. public ResultVo<String> dischargeProcessing(ZyPatientInfo p) {
  402. if (null == p.getLedgerSn()) {
  403. p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
  404. }
  405. Dscginfo dscginfo;
  406. if (p.getMidSetl()) {
  407. dscginfo = dao.selectDscginfoForMidSetl(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  408. dscginfo.setEndtime(p.getZjdzDatetime());
  409. } else {
  410. dscginfo = dao.selectDscginfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  411. }
  412. if (null == dscginfo || StringUtil.isBlank(dscginfo.getMdtrtId())) {
  413. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  414. }
  415. List<SetlDiseinfo> setlDises = dao.selectSetlDises(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  416. if (null == setlDises || setlDises.isEmpty()) {
  417. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保出院诊断不能为空,请联系医生在病案首页填写。");
  418. }
  419. if (null == p.getStaffId()) {
  420. p.setStaffId(TokenUtil.getTokenUserId());
  421. }
  422. // if (p.getAge() >= 7 && p.getAge() < 70) {
  423. // ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
  424. // if (readCardBizType != ReadCardBizType.SETTLEMENT) {
  425. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请先读卡再做出院结算。");
  426. // }
  427. // }
  428. dscginfo.setDiseCodg(setlDises.get(0).getDiagCode());
  429. dscginfo.setDiseName(setlDises.get(0).getDiagName());
  430. dscginfo.setDscgWay(DscgWay.ORDER_TO_LEAVE_HOSPITAL.getCode());
  431. String ref = JSONObject.toJSONStringWithDateFormat(dscginfo, "yyyy-MM-dd HH:mm:ss");
  432. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.DISCHARGE_PROCESSING,
  433. dao.selectAdmdvs(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn()));
  434. input.getJSONObject("input").put("dscginfo", JSONObject.parseObject(ref));
  435. String diseRef = JSONArray.toJSONStringWithDateFormat(setlDises, "yyyy-MM-dd HH:mm:ss");
  436. input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
  437. JSONObject result = exec.executeTrade(input, SiFunction.DISCHARGE_PROCESSING);
  438. log.info("【操作员:{}】,医保出院办理:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  439. if (null == result) {
  440. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  441. }
  442. Integer infcode = result.getInteger(RESULT_CODE);
  443. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, dscginfo.getPsnNo()));
  444. if (null == infcode) {
  445. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  446. }
  447. if (infcode == 0) {
  448. p.setDismissDate(dscginfo.getEndtime());
  449. return inpatientSettlement(p);
  450. }
  451. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  452. }
  453. public ResultVo<String> revokeDischarge(ZyPatientInfo p) {
  454. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  455. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  456. transbackTables(p);
  457. return ResultVoUtil.success("取消出院办理成功。");
  458. }
  459. p.setMdtrtId(siPatInfo.getMdtrtId());
  460. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_DISCHARGE, siPatInfo.getInsuplcAdmdvs());
  461. JSONObject data = new JSONObject();
  462. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  463. data.put("psn_no", siPatInfo.getPsnNo());
  464. input.getJSONObject("input").put("data", data);
  465. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_DISCHARGE);
  466. log.info("【操作员:{}】取消医保出院办理:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  467. if (null == result) {
  468. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  469. }
  470. Integer infcode = result.getInteger(RESULT_CODE);
  471. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, siPatInfo.getPsnNo()));
  472. if (null == infcode) {
  473. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  474. }
  475. if (infcode == 0) {
  476. dao.deleteSetlInfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  477. dao.deleteSetlDetail(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  478. transbackTables(p);
  479. return ResultVoUtil.success("取消医保出院办理成功。");
  480. }
  481. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  482. }
  483. private ResultVo<String> inpatientSettlement(ZyPatientInfo p) {
  484. PreSetlmt preSetlmt;
  485. Date begntime = p.getYbRegisterDate();
  486. if (null == begntime) {
  487. begntime = dismissService.getBegntime(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), "zy_actpatient");
  488. }
  489. if (p.getMidSetl()) {
  490. preSetlmt = dao.selectPreSetlmtForMidSetl(p.getInpatientNo(), p.getAdmissTimes(),
  491. p.getLedgerSn(), begntime, p.getZjdzDatetime());
  492. } else {
  493. preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
  494. p.getLedgerSn(), "2999-12-31 23:59:59.999");
  495. }
  496. if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
  497. revokeDischarge(p);
  498. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  499. }
  500. ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
  501. if (readCardBizType == ReadCardBizType.SETTLEMENT) {
  502. MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
  503. preSetlmt.setMdtrtCertType(mdtrtCertType.getCode());
  504. if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) {
  505. String[] out = p.getReadCardResult().split("\\|");
  506. if (!p.getName().trim().equals(out[4].trim())) {
  507. revokeDischarge(p);
  508. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "社保卡姓名与HIS姓名不一致,请确认是否人证相符。");
  509. }
  510. preSetlmt.setMdtrtCertNo(out[2]);
  511. preSetlmt.setCardSn(out[3]);
  512. } else if (mdtrtCertType.getCode().equals(MdtrtCertType.MEDICAL_INSURANCE_ELECTRONIC_VOUCHER.getCode())) {
  513. JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
  514. if (!p.getName().trim().equals(qrinfo.getString("userName").trim())) {
  515. revokeDischarge(p);
  516. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证姓名与HIS姓名不一致,请确认是否人证相符。");
  517. }
  518. if (!p.getSocialNo().trim().equals(qrinfo.getString("idNo").trim())) {
  519. revokeDischarge(p);
  520. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。");
  521. }
  522. preSetlmt.setMdtrtCertNo(qrinfo.getString("ecToken"));
  523. }
  524. }
  525. preSetlmt.setPsnSetlway(p.getDbg() ? PsnSetlWay.SETTLE_BY_QUOTA.getCode() : PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  526. preSetlmt.setAcctUsedFlag(p.getAcctUsedFlag());
  527. preSetlmt.setMidSetlFlag(YesOrNo.NO.getCodeStr());
  528. preSetlmt.setInvono(SnowFlakeId.instance().nextId());
  529. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.HOSPITALIZATION_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
  530. String ref = JSONObject.toJSONString(preSetlmt);
  531. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  532. JSONObject result = exec.executeTrade(input, SiFunction.HOSPITALIZATION_SETTLEMENT);
  533. log.info("【操作员:{}】,医保出院结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  534. if (null == result) {
  535. revokeDischarge(p);
  536. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  537. }
  538. Integer infcode = result.getInteger(RESULT_CODE);
  539. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, preSetlmt.getPsnNo()));
  540. if (null == infcode) {
  541. revokeDischarge(p);
  542. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  543. }
  544. if (infcode == 0) {
  545. JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  546. SiSetlinfo setlinfoEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
  547. setlinfoEntity.setPatNo(p.getInpatientNo());
  548. setlinfoEntity.setTimes(p.getAdmissTimes());
  549. setlinfoEntity.setLedgerSn(p.getLedgerSn());
  550. setlinfoEntity.setStaffId(TokenUtil.getTokenUserId());
  551. setlinfoEntity.setRevoked(YesOrNo.NO.getCode());
  552. setlinfoEntity.setSetlType(ClrType.INPATIENT.getCode());
  553. setlinfoEntity.setInsuplcAdmdvs(preSetlmt.getInsuplcAdmdvs());
  554. setlinfoEntity.setBegntime(begntime);
  555. setlinfoEntity.setEndtime(p.getDismissDate());
  556. setlinfoEntity.setHiPaymtd(CommonUtil.calcHiPaymtd(setlinfoEntity.getInsuplcAdmdvs(),setlinfoEntity.getMedType(),setlinfoEntity.getInsutype(),setlinfoEntity.getSetlTime()));
  557. setlinfoEntity.setMedinsType(MedInsTypeUtil.getMedInsType(setlinfoEntity));
  558. JSONArray setldetail = result.getJSONObject(OUTPUT).getJSONArray("setldetail");
  559. BigDecimal hospitalPart = BigDecimal.ZERO;
  560. for (int i = 0; i < setldetail.size(); i++) {
  561. SiSetldetail setldetailEntity = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class);
  562. setldetailEntity.setPatNo(p.getInpatientNo());
  563. setldetailEntity.setTimes(p.getAdmissTimes());
  564. setldetailEntity.setLedgerSn(p.getLedgerSn());
  565. if (setldetailEntity.getFundPayType().equals("999996") || setldetailEntity.getSetlProcInfo().equals("999996")) {
  566. hospitalPart = hospitalPart.add(setldetailEntity.getFundPayamt());
  567. }
  568. setldetldao.insert(setldetailEntity);
  569. }
  570. setlinfoEntity.setHospPartAmt(hospitalPart.doubleValue());
  571. setlinfodao.insert(setlinfoEntity);
  572. setlinfodao.updateSiZyInfoSetlId(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(),
  573. setlinfoEntity.getSetlId(), setlinfoEntity.getMedinsSetlId(), input.getString("msgid"));
  574. setlinfodao.updateApplySettled(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), YesOrNo.YES.getCode());
  575. // 跨省异地数据不参与对账,对总账时无需统计进去。
  576. if (setlinfoEntity.getFundPaySumamt() > 0 && setlinfoEntity.getInsuplcAdmdvs().startsWith("43")) {
  577. InstStlLdgChk ldgChk = new InstStlLdgChk();
  578. ldgChk.setInsutype(setlinfoEntity.getInsutype());
  579. ldgChk.setClrType(setlinfoEntity.getClrType());
  580. ldgChk.setSetlOptins(setlinfoEntity.getClrOptins());
  581. ldgChk.setStmtBegndate(setlinfoEntity.getSetlTime());
  582. ldgChk.setStmtEnddate(setlinfoEntity.getSetlTime());
  583. ResultVo<String> totalLedgerCheck = manageService.institutionSettlementLedgerCheck(ldgChk);
  584. if (totalLedgerCheck.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  585. InstStlLdgChk detlChk = new InstStlLdgChk();
  586. detlChk.setSetlOptins(ldgChk.getSetlOptins());
  587. detlChk.setStmtBegndate(ldgChk.getStmtBegndate());
  588. detlChk.setStmtEnddate(ldgChk.getStmtEnddate());
  589. detlChk.setClrType(ldgChk.getClrType());
  590. detlChk.setRefdSetlFlag(YesOrNo.NO.getCodeStr());
  591. ResultVo<List<InsSetlDetlChkRslt>> detailLedgerCheck = manageService.institutionSettlementDetailCheck(detlChk);
  592. if (detailLedgerCheck.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  593. revokeSettlement(p);
  594. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, detailLedgerCheck.getMessage());
  595. }
  596. for (InsSetlDetlChkRslt insSetlDetlChkRslt : detailLedgerCheck.getData()) {
  597. if (Objects.equals(insSetlDetlChkRslt.getSetlId(), setlinfoEntity.getSetlId())) {
  598. if (!Objects.equals(insSetlDetlChkRslt.getStmtRslt(), "0")) {
  599. revokeSettlement(p);
  600. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, insSetlDetlChkRslt.getMemo());
  601. }
  602. break;
  603. }
  604. }
  605. }
  606. }
  607. queryService.saveCumInfo(setlinfoEntity);
  608. MedinsSettleFee settleFee = new MedinsSettleFee();
  609. if (p.getMidSetl()) {
  610. settleFee.setZjdzDatetime(p.getZjdzDatetime());
  611. }
  612. settleFee.setMidSetl(p.getMidSetl());
  613. settleFee.setStaffId(TokenUtil.getTokenUserId());
  614. settleFee.setInpatientNo(p.getInpatientNo());
  615. settleFee.setAdmissTimes(p.getAdmissTimes());
  616. settleFee.setBedNo(p.getBedNo());
  617. settleFee.setWardCode(p.getAdmissWard());
  618. settleFee.setDeptCode(p.getAdmissDept());
  619. settleFee.setTotalCost(setlinfo.getString("medfee_sumamt"));
  620. settleFee.setTczf(setlinfo.getString("fund_pay_sumamt"));
  621. settleFee.setHospitalPay(setlinfo.getString("hosp_part_amt"));
  622. settleFee.setGrzhzf(setlinfo.getString("acct_pay"));
  623. settleFee.setDbzf(setlinfo.getString("hifmi_pay"));
  624. settleFee.setXjzf(setlinfo.getString("psn_cash_pay"));
  625. settleFee.setTable(p.getTable());
  626. return dismissService.executeDischarging(settleFee);
  627. }
  628. revokeDischarge(p);
  629. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  630. }
  631. public ResultVo<String> revokeSettlement(ZyPatientInfo p) {
  632. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  633. if (null == p.getStaffId()) {
  634. p.setStaffId(TokenUtil.getTokenUserId());
  635. }
  636. if (null == p.getLedgerSn()) {
  637. p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
  638. }
  639. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getSetlId())) {
  640. return revokeDischarge(p);
  641. }
  642. p.setMdtrtId(siPatInfo.getMdtrtId());
  643. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_SETTLEMENT, siPatInfo.getInsuplcAdmdvs());
  644. JSONObject data = new JSONObject();
  645. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  646. data.put("setl_id", siPatInfo.getSetlId());
  647. data.put("psn_no", siPatInfo.getPsnNo());
  648. input.getJSONObject("input").put("data", data);
  649. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_SETTLEMENT);
  650. log.info("【操作员:{}】取消医保结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  651. if (null == result) {
  652. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  653. }
  654. Integer infcode = result.getInteger(RESULT_CODE);
  655. logDao.insert(new SiLog(input, result, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), infcode, siPatInfo.getPsnNo()));
  656. if (null == infcode) {
  657. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  658. }
  659. String errMsg = null;
  660. if (infcode != 0) {
  661. errMsg = result.getString("err_msg");
  662. }
  663. ResultVo<String> rvkDischrgRslt = revokeDischarge(p);
  664. if (rvkDischrgRslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  665. dao.updateRvkSetlMsgid(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), input.getString("msgid"));
  666. setlinfodao.updateApplySettled(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), YesOrNo.NO.getCode());
  667. transbackTables(p);
  668. return rvkDischrgRslt;
  669. }
  670. return null == errMsg ? rvkDischrgRslt : ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, errMsg);
  671. }
  672. private void transbackTables(ZyPatientInfo p) {
  673. dao.deleteSiSetlFeeDetl(p.getMdtrtId());
  674. dao.deleteZyLedgerFileYb(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  675. dao.deleteZyReceipt(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  676. dao.updateSettleType(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  677. dao.updateChargeStatus(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  678. }
  679. }