SiZyService.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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.sidicts.*;
  10. import thyyxxk.webserver.constants.YesOrNo;
  11. import thyyxxk.webserver.dao.his.medicalinsurance.*;
  12. import thyyxxk.webserver.entity.ResultVo;
  13. import thyyxxk.webserver.entity.dictionary.PureCodeName;
  14. import thyyxxk.webserver.entity.medicalinsurance.inpatient.*;
  15. import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo;
  16. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail;
  17. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
  18. import thyyxxk.webserver.entity.yibao.dismiss.YbSettleFee;
  19. import thyyxxk.webserver.entity.yibao.patient.Overview;
  20. import thyyxxk.webserver.service.externalhttp.SiZySrvc;
  21. import thyyxxk.webserver.service.yibao.DismissService;
  22. import thyyxxk.webserver.utils.*;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Date;
  25. import java.util.List;
  26. /**
  27. * @description: 住院医保交易
  28. * @author: DingJie
  29. * @create: 2021-05-14 16:28:16
  30. * <p>
  31. * 联通云:
  32. * http://10.136.68.156:20005/isp-api/powercsb/1101
  33. * api_access_key=FqSRO1tkKe4PTsZS8mJkN3zs12U6Zkkwez6Qhy
  34. * api_secreKey=SKklCVOoGDag5ys4zkSE2qHYo8iU4FsG7DNyJQYI
  35. * <p>
  36. * 省政府二院:
  37. * http://10.90.0.11:8081/isp-api/powercsb/1101
  38. * api_access_key=sJAXxQd10aQLWZFAMH3PT9pHCGGqXPzz4Hv4Ei
  39. * api_secreKey=SK1BtAloxIaQUgv9m0gjqrQJ0NJikkPPUTlRGOzp
  40. **/
  41. @Slf4j
  42. @Service
  43. public class SiZyService {
  44. private static final String RESULT_CODE = "infcode";
  45. private static final String ERROR_MESSAGE = "err_msg";
  46. private static final String OUTPUT = "output";
  47. private final SiZyDao dao;
  48. private final SiQueryDao qrydao;
  49. private final SiSetlinfoDao setlinfodao;
  50. private final SiSetldetailDao setldetldao;
  51. private final SiChargeTempDao chrgtmpdao;
  52. private final ExecService exec;
  53. private final DismissService dismissService;
  54. private final SiZySrvc zySrvc;
  55. @Autowired
  56. public SiZyService(SiZyDao dao, SiQueryDao qrydao, SiSetlinfoDao setlinfoDao,
  57. SiSetldetailDao setldetldao, SiChargeTempDao chrgtmpdao, ExecService exec,
  58. DismissService dismissService, SiZySrvc zySrvc) {
  59. this.dao = dao;
  60. this.qrydao = qrydao;
  61. this.setlinfodao = setlinfoDao;
  62. this.setldetldao = setldetldao;
  63. this.chrgtmpdao = chrgtmpdao;
  64. this.exec = exec;
  65. this.dismissService = dismissService;
  66. this.zySrvc = zySrvc;
  67. }
  68. public ResultVo<String> admissRegister(ZyPatientInfo p) {
  69. if (p.getInsuplcAdmdvs().equals("430182")) {
  70. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "宁乡患者无法在我院办理住院业务。");
  71. }
  72. AdmMdtrtinfo admMdtrtinfo = dao.selectAdmMdtrtinfo(p.getInpatientNo(), p.getLedgerSn());
  73. if (null == admMdtrtinfo) {
  74. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的参保信息!");
  75. }
  76. if (StringUtil.isBlank(admMdtrtinfo.getChfpdrName())) {
  77. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "管床医生不能为空!");
  78. }
  79. List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
  80. if (null == admDiseinfos || admDiseinfos.isEmpty()) {
  81. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
  82. }
  83. admMdtrtinfo.setInsutype(p.getInsutype());
  84. admMdtrtinfo.setAdmDiagDscr(admDiseinfos.get(0).getDiagName());
  85. admMdtrtinfo.setDscgMaindiagCode(admDiseinfos.get(0).getDiagCode());
  86. admMdtrtinfo.setDscgMaindiagName(admDiseinfos.get(0).getDiagName());
  87. admMdtrtinfo.setDiseCodg(admDiseinfos.get(0).getDiagCode());
  88. admMdtrtinfo.setDiseName(admDiseinfos.get(0).getDiagName());
  89. admMdtrtinfo.setMatnType(p.getMatnType());
  90. admMdtrtinfo.setLatechbFlag(p.getLatechbFlag());
  91. admMdtrtinfo.setPretFlag(p.getPretFlag());
  92. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.ADMISSION_REGISTRATION, p.getInsuplcAdmdvs());
  93. String ref = JSONObject.toJSONStringWithDateFormat(admMdtrtinfo, "yyyy-MM-dd HH:mm:ss");
  94. input.getJSONObject("input").put("mdtrtinfo", JSONObject.parseObject(ref));
  95. String diseRef = JSONArray.toJSONStringWithDateFormat(admDiseinfos, "yyyy-MM-dd HH:mm:ss");
  96. input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
  97. JSONObject result = exec.executeTrade(input, SiFunction.ADMISSION_REGISTRATION);
  98. log.info("【操作员:{}】,医保入院登记:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  99. if (null == result) {
  100. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  101. }
  102. if (null == result.getInteger(RESULT_CODE)) {
  103. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  104. }
  105. if (result.getIntValue(RESULT_CODE) == 0) {
  106. JSONObject output = result.getJSONObject(OUTPUT);
  107. String mdtrtId = output.getJSONObject("result").getString("mdtrt_id");
  108. p.setMdtrtId(mdtrtId);
  109. p.setAdmRegMsgid(input.getString("msgid"));
  110. dao.afterAdmissRegister(p);
  111. return ResultVoUtil.success("入院登记成功,就诊号为:" + mdtrtId);
  112. }
  113. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  114. }
  115. public ResultVo<String> modifyAdmissionInfo(ZyPatientInfo p) {
  116. PureCodeName codeName = dao.selectMdtrtId(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  117. if (null == codeName || StringUtil.isBlank(codeName.getName())) {
  118. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保不在院!");
  119. }
  120. List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
  121. if (null == admDiseinfos || admDiseinfos.isEmpty()) {
  122. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
  123. }
  124. admDiseinfos.forEach(item -> item.setMdtrtId(codeName.getName()));
  125. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.MODIFY_ADMISSION_INFO, codeName.getCode());
  126. JSONObject adminfo = new JSONObject();
  127. adminfo.put("mdtrt_id", codeName.getName());
  128. adminfo.put("psn_no", p.getPsnNo());
  129. adminfo.put("begntime", DateUtil.formatDatetime(p.getAdmissDate()));
  130. adminfo.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  131. adminfo.put("med_type", p.getMedType());
  132. adminfo.put("ipt_otp_no", p.getInpatientNo());
  133. adminfo.put("atddr_no", p.getReferPhysician());
  134. adminfo.put("chfpdr_name", p.getReferPhysicianName());
  135. adminfo.put("adm_diag_dscr", admDiseinfos.get(0).getDiagCode());
  136. adminfo.put("adm_dept_codg", p.getSmallDept());
  137. adminfo.put("adm_dept_name", p.getSmallDeptName());
  138. adminfo.put("adm_bed", p.getBedNo());
  139. adminfo.put("dscg_maindiag_code", admDiseinfos.get(0).getDiagCode());
  140. adminfo.put("dscg_maindiag_name", admDiseinfos.get(0).getDiagName());
  141. input.getJSONObject("input").put("adminfo", adminfo);
  142. String diseRef = JSONArray.toJSONStringWithDateFormat(admDiseinfos, "yyyy-MM-dd HH:mm:ss");
  143. input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
  144. JSONObject result = exec.executeTrade(input, SiFunction.MODIFY_ADMISSION_INFO);
  145. log.info("【操作员:{}】,入院信息变更:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  146. return SiUtil.makeReturnWithoutOutput(result, "变更住院信息成功。");
  147. }
  148. public ResultVo<String> revokeAdmission(ZyPatientInfo p) {
  149. SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  150. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  151. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  152. }
  153. revokeUploadFees(p);
  154. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_ADMISSION, siPatInfo.getInsuplcAdmdvs());
  155. JSONObject data = new JSONObject();
  156. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  157. data.put("psn_no", siPatInfo.getPsnNo());
  158. input.getJSONObject("input").put("data", data);
  159. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_ADMISSION);
  160. log.info("【操作员:{}】,取消入院登记:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  161. if (null == result) {
  162. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  163. }
  164. if (null == result.getInteger(RESULT_CODE)) {
  165. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  166. }
  167. if (result.getIntValue(RESULT_CODE) == 0) {
  168. qrydao.clearMdtrtIdForZy(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(), null);
  169. return ResultVoUtil.success("取消入院登记成功。");
  170. }
  171. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  172. }
  173. public ResultVo<String> uploadFeeDetail(Overview o) {
  174. o.setStaffId(TokenUtil.getTokenUserId());
  175. return zySrvc.uploadFeeDetail(o);
  176. }
  177. public ResultVo<String> hospitalizationPreSettlement(ZyPatientInfo p) {
  178. PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
  179. p.getLedgerSn(), DateUtil.getTodayEndTime());
  180. if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
  181. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  182. }
  183. preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  184. preSetlmt.setPsnSetlway(p.getDbg() ? PsnSetlWay.SETTLE_BY_QUOTA.getCode() : PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  185. preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
  186. preSetlmt.setMidSetlFlag(YesOrNo.NO.getCodeStr());
  187. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.HOSPITALIZATION_PRE_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
  188. String ref = JSONObject.toJSONString(preSetlmt);
  189. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  190. JSONObject result = exec.executeTrade(input, SiFunction.HOSPITALIZATION_PRE_SETTLEMENT);
  191. log.info("预结算:\n参数:{},\n结果:{}", input, result);
  192. if (null == result) {
  193. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  194. }
  195. if (null == result.getInteger(RESULT_CODE)) {
  196. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  197. }
  198. if (result.getIntValue(RESULT_CODE) == 0) {
  199. JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  200. String fundPay = setlinfo.getString("fund_pay_sumamt");
  201. if (DecimalUtil.compare(fundPay, p.getTotalCharge()) == 1) {
  202. fundPay = p.getTotalCharge();
  203. }
  204. dao.updateFundPay(fundPay, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  205. String message = "患者【" + p.getName() + "】院内总费用与医保中心总费用一致,医保报销金额为:¥ " + fundPay + "。";
  206. return ResultVoUtil.success(message);
  207. }
  208. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  209. }
  210. public ResultVo<String> revokeUploadFees(ZyPatientInfo p) {
  211. SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  212. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  213. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  214. }
  215. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs());
  216. JSONArray data = new JSONArray();
  217. if (null == p.getDetailSns() || p.getDetailSns().isEmpty()) {
  218. JSONObject item = new JSONObject();
  219. item.put("feedetl_sn", "0000");
  220. item.put("mdtrt_id", siPatInfo.getMdtrtId());
  221. item.put("psn_no", siPatInfo.getPsnNo());
  222. data.add(item);
  223. } else {
  224. p.getDetailSns().forEach(detailSn -> {
  225. JSONObject item = new JSONObject();
  226. item.put("feedetl_sn", detailSn);
  227. item.put("mdtrt_id", siPatInfo.getMdtrtId());
  228. item.put("psn_no", siPatInfo.getPsnNo());
  229. data.add(item);
  230. });
  231. }
  232. input.getJSONObject("input").put("data", data);
  233. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS);
  234. log.info("【操作员:{}】撤销已上传的费用:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  235. if (null == result) {
  236. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  237. }
  238. if (null == result.getInteger(RESULT_CODE)) {
  239. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  240. }
  241. if (result.getIntValue(RESULT_CODE) == 0) {
  242. QueryWrapper<SiChargeTemp> wrapper = new QueryWrapper<>();
  243. wrapper.eq("pat_no", p.getInpatientNo());
  244. wrapper.eq("times", p.getAdmissTimes());
  245. wrapper.eq("ledger_sn", p.getLedgerSn());
  246. if (null == p.getDetailSns() || p.getDetailSns().isEmpty()) {
  247. dao.revokeAllUploadFee(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  248. chrgtmpdao.delete(wrapper);
  249. } else {
  250. wrapper.in("detail_sn", p.getDetailSns());
  251. chrgtmpdao.delete(wrapper);
  252. dao.revokePartUploadFee(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), p.getDetailSns());
  253. }
  254. return ResultVoUtil.success("撤销费用上传成功。");
  255. }
  256. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  257. }
  258. public ResultVo<String> dischargeProcessing(ZyPatientInfo p) {
  259. List<Date> dscgDates = dao.selectDscgDate(p.getInpatientNo(), p.getAdmissTimes());
  260. if (null == dscgDates || dscgDates.isEmpty()) {
  261. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有出院医嘱,请检查!");
  262. }
  263. if (dscgDates.size() > 1) {
  264. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者的出院医嘱不止1条,请检查!");
  265. }
  266. if (null == p.getLedgerSn()) {
  267. p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
  268. }
  269. Dscginfo dscginfo = dao.selectDscginfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  270. if (null == dscginfo || StringUtil.isBlank(dscginfo.getMdtrtId())) {
  271. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  272. }
  273. List<SetlDiseinfo> setlDises = dao.selectSetlDises(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  274. if (null == setlDises || setlDises.isEmpty()) {
  275. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保出院诊断不能为空,请联系医生在病案首页填写。");
  276. }
  277. if (null == p.getStaffId()) {
  278. p.setStaffId(TokenUtil.getTokenUserId());
  279. }
  280. dscginfo.setDiseCodg(setlDises.get(0).getDiagCode());
  281. dscginfo.setDiseName(setlDises.get(0).getDiagName());
  282. dscginfo.setDscgWay(DscgWay.ORDER_TO_LEAVE_HOSPITAL.getCode());
  283. String ref = JSONObject.toJSONString(dscginfo);
  284. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.DISCHARGE_PROCESSING,
  285. dao.selectAdmdvs(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn()));
  286. input.getJSONObject("input").put("dscginfo", JSONObject.parseObject(ref));
  287. String diseRef = JSONArray.toJSONString(setlDises);
  288. input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
  289. JSONObject result = exec.executeTrade(input, SiFunction.DISCHARGE_PROCESSING);
  290. log.info("【操作员:{}】,医保出院办理:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  291. if (null == result) {
  292. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  293. }
  294. if (null == result.getInteger(RESULT_CODE)) {
  295. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  296. }
  297. if (result.getIntValue(RESULT_CODE) == 0) {
  298. return inpatientSettlement(p);
  299. }
  300. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  301. }
  302. public ResultVo<String> revokeDischarge(ZyPatientInfo p) {
  303. SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  304. if (null == siPatInfo) {
  305. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保出院信息,无法撤销出院!");
  306. }
  307. p.setMdtrtId(siPatInfo.getMdtrtId());
  308. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_DISCHARGE, siPatInfo.getInsuplcAdmdvs());
  309. JSONObject data = new JSONObject();
  310. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  311. data.put("psn_no", siPatInfo.getPsnNo());
  312. input.getJSONObject("input").put("data", data);
  313. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_DISCHARGE);
  314. log.info("【操作员:{}】取消医保出院办理:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  315. if (null == result) {
  316. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  317. }
  318. if (null == result.getInteger(RESULT_CODE)) {
  319. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  320. }
  321. if (result.getIntValue(RESULT_CODE) == 0) {
  322. dao.deleteSetlInfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  323. dao.deleteSetlDetail(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  324. transbackTables(p);
  325. return ResultVoUtil.success("取消医保出院办理成功。");
  326. }
  327. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  328. }
  329. private ResultVo<String> inpatientSettlement(ZyPatientInfo p) {
  330. PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
  331. p.getLedgerSn(), "2099-12-31 23:59:59.999");
  332. if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
  333. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
  334. }
  335. preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  336. preSetlmt.setPsnSetlway(p.getDbg() ? PsnSetlWay.SETTLE_BY_QUOTA.getCode() : PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  337. preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
  338. preSetlmt.setMidSetlFlag(YesOrNo.NO.getCodeStr());
  339. preSetlmt.setInvono(SnowFlakeId.instance().nextId());
  340. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.HOSPITALIZATION_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
  341. String ref = JSONObject.toJSONString(preSetlmt);
  342. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  343. JSONObject result = exec.executeTrade(input, SiFunction.HOSPITALIZATION_SETTLEMENT);
  344. log.info("【操作员:{}】,医保出院结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  345. if (null == result) {
  346. revokeDischarge(p);
  347. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  348. }
  349. if (null == result.getInteger(RESULT_CODE)) {
  350. revokeDischarge(p);
  351. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  352. }
  353. if (result.getIntValue(RESULT_CODE) == 0) {
  354. JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  355. SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
  356. setlEntity.setPatNo(p.getInpatientNo());
  357. setlEntity.setTimes(p.getAdmissTimes());
  358. setlEntity.setLedgerSn(p.getLedgerSn());
  359. setlEntity.setStaffId(TokenUtil.getTokenUserId());
  360. setlEntity.setRevoked(YesOrNo.NO.getCode());
  361. setlEntity.setSetlType(ClrType.INPATIENT.getCode());
  362. setlinfodao.insert(setlEntity);
  363. setlinfodao.updateSiZyInfoSetlId(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(),
  364. setlEntity.getSetlId(), setlEntity.getMedinsSetlId(), input.getString("msgid"));
  365. JSONArray setldetail = result.getJSONObject(OUTPUT).getJSONArray("setldetail");
  366. for (int i = 0; i < setldetail.size(); i++) {
  367. SiSetldetail setldetailEntity = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class);
  368. setldetailEntity.setPatNo(p.getInpatientNo());
  369. setldetailEntity.setTimes(p.getAdmissTimes());
  370. setldetailEntity.setLedgerSn(p.getLedgerSn());
  371. setldetldao.insert(setldetailEntity);
  372. }
  373. // todo 结算,需要改造,慢慢删除responceType字段
  374. YbSettleFee settleFee = new YbSettleFee();
  375. if (p.getDismissFlag() == 2) {
  376. settleFee.setZjdzDatetime(p.getMidSetlDate());
  377. }
  378. settleFee.setResponceType("03");
  379. settleFee.setFlag(p.getDismissFlag());
  380. settleFee.setStaffId(TokenUtil.getTokenUserId());
  381. settleFee.setInpatientNo(p.getInpatientNo());
  382. settleFee.setAdmissTimes(p.getAdmissTimes());
  383. settleFee.setBedNo(p.getBedNo());
  384. settleFee.setWardCode(p.getAdmissWard());
  385. settleFee.setDeptCode(p.getAdmissDept());
  386. settleFee.setTotalCost(setlinfo.getString("medfee_sumamt"));
  387. settleFee.setTczf(setlinfo.getString("fund_pay_sumamt"));
  388. settleFee.setHospitalPay(setlinfo.getString("hosp_part_amt"));
  389. settleFee.setGrzhzf(setlinfo.getString("acct_pay"));
  390. settleFee.setDbzf(setlinfo.getString("hifmi_pay"));
  391. settleFee.setXjzf(setlinfo.getString("psn_part_amt"));
  392. settleFee.setTable(p.getTable());
  393. return dismissService.doDismiss(settleFee);
  394. }
  395. revokeDischarge(p);
  396. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  397. }
  398. public ResultVo<String> revokeSettlement(ZyPatientInfo p) {
  399. SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  400. if (null == p.getStaffId()) {
  401. p.setStaffId(TokenUtil.getTokenUserId());
  402. }
  403. if (null == p.getLedgerSn()) {
  404. p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
  405. }
  406. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getSetlId())) {
  407. return revokeDischarge(p);
  408. }
  409. p.setMdtrtId(siPatInfo.getMdtrtId());
  410. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_SETTLEMENT, siPatInfo.getInsuplcAdmdvs());
  411. JSONObject data = new JSONObject();
  412. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  413. data.put("setl_id", siPatInfo.getSetlId());
  414. data.put("psn_no", siPatInfo.getPsnNo());
  415. input.getJSONObject("input").put("data", data);
  416. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_SETTLEMENT);
  417. log.info("【操作员:{}】取消医保结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  418. if (null == result) {
  419. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  420. }
  421. if (null == result.getInteger(RESULT_CODE)) {
  422. return revokeDischarge(p);
  423. }
  424. if (result.getIntValue(RESULT_CODE) == 0) {
  425. dao.updateRvkSetlMsgid(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), input.getString("msgid"));
  426. transbackTables(p);
  427. }
  428. return revokeDischarge(p);
  429. }
  430. private void transbackTables(ZyPatientInfo p) {
  431. dao.deleteSiSetlFeeDetl(p.getMdtrtId());
  432. dao.deleteZyLedgerFileYb(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  433. dao.deleteZyReceipt(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  434. dao.updateSettleType(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  435. dao.updateChargeStatus(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
  436. }
  437. }