SiZyService.java 41 KB

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