SiMzFeeService.java 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. package thyyxxk.simzfeeoprnsystm.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import thyyxxk.simzfeeoprnsystm.dao.SiLogDao;
  6. import thyyxxk.simzfeeoprnsystm.dao.SiMzDao;
  7. import thyyxxk.simzfeeoprnsystm.dao.SiSetldetailDao;
  8. import thyyxxk.simzfeeoprnsystm.dao.SiSetlinfoDao;
  9. import thyyxxk.simzfeeoprnsystm.dicts.*;
  10. import thyyxxk.simzfeeoprnsystm.external.WebHisService;
  11. import thyyxxk.simzfeeoprnsystm.pojo.*;
  12. import thyyxxk.simzfeeoprnsystm.pojo.ResultVo;
  13. import thyyxxk.simzfeeoprnsystm.pojo.SiPatInfo;
  14. import thyyxxk.simzfeeoprnsystm.utils.*;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import java.math.BigDecimal;
  19. import java.math.RoundingMode;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.Objects;
  24. import java.util.concurrent.TimeUnit;
  25. @Slf4j
  26. @Service
  27. public class SiMzFeeService {
  28. private final SiMzDao mzDao;
  29. private final SiSetlinfoDao setlinfoDao;
  30. private final SiSetldetailDao setldetailDao;
  31. private final ExecService exec;
  32. private final WebHisService webHisService;
  33. private final MariadbService mariadbService;
  34. private static final String RESULT_CODE = "infcode";
  35. private static final String ERROR_MESSAGE = "err_msg";
  36. private static final String OUTPUT = "output";
  37. private final SiLogDao logDao;
  38. @Value("${web-his-url}")
  39. private String webHisUrl;
  40. @Value("${thmz-url}")
  41. private String thmzUrl;
  42. @Autowired
  43. public SiMzFeeService(SiMzDao mzDao, SiSetlinfoDao setlinfoDao,
  44. SiSetldetailDao setldetailDao, ExecService exec,
  45. WebHisService webHisService, MariadbService mariadbService,
  46. SiLogDao logDao) {
  47. this.mzDao = mzDao;
  48. this.setlinfoDao = setlinfoDao;
  49. this.setldetailDao = setldetailDao;
  50. this.exec = exec;
  51. this.webHisService = webHisService;
  52. this.mariadbService = mariadbService;
  53. this.logDao = logDao;
  54. }
  55. public ResultVo<String> outpatientRegistration(MzPatientInfo p) {
  56. Regstrtn regstrtn = mzDao.selectRegstrtn(p.getPatNo(), p.getTimes());
  57. if (null == regstrtn) {
  58. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "mz_visit_table患者信息为空,请联系医生重开处方。");
  59. }
  60. ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
  61. if (readCardBizType != ReadCardBizType.REGISTRATION && !p.getInsuplcAdmdvs().startsWith("43")) {
  62. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "省外异地的患者请读社保卡或医保电子凭证登记!");
  63. }
  64. if (StringUtil.notBlank(p.getMedType())) {
  65. mzDao.updateMedtype(p.getMedType(), p.getPatNo(), p.getTimes());
  66. }
  67. if (readCardBizType == ReadCardBizType.REGISTRATION) {
  68. MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
  69. regstrtn.setMdtrtCertType(mdtrtCertType.getCode());
  70. if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) {
  71. String[] out = p.getReadCardResult().split("\\|");
  72. regstrtn.setMdtrtCertNo(out[2]);
  73. regstrtn.setCardSn(out[3]);
  74. } else if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) {
  75. JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
  76. regstrtn.setMdtrtCertNo(qrinfo.getString("ecToken"));
  77. }
  78. }
  79. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_REGISTRATION,
  80. p.getInsuplcAdmdvs(), p.getStaffId());
  81. regstrtn.setInsutype(p.getInsutype());
  82. regstrtn.setPsnType(p.getPsnType());
  83. regstrtn.setIptOtpNo(p.getPatNo());
  84. String ref = JSONObject.toJSONStringWithDateFormat(regstrtn, "yyyy-MM-dd HH:mm:ss");
  85. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  86. JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_REGISTRATION);
  87. log.info("【操作员:{}】,门诊挂号:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  88. Integer infcode = result.getInteger(RESULT_CODE);
  89. logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, regstrtn.getPsnNo()));
  90. if (infcode == 0) {
  91. JSONObject output = result.getJSONObject(OUTPUT).getJSONObject("data");
  92. p.setMdtrtId(output.getString("mdtrt_id"));
  93. p.setVisitDate(regstrtn.getBegntime());
  94. mzDao.afterRegistrtn(p);
  95. return ResultVoUtil.success("挂号成功。");
  96. }
  97. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  98. }
  99. public ResultVo<String> revokeOutpatientRegistration(MzPatientInfo p) {
  100. if (null == p.getTimes()) {
  101. p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
  102. }
  103. SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes());
  104. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  105. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保挂号信息。");
  106. }
  107. RevokeRegRequest request = new RevokeRegRequest();
  108. request.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs()); ;
  109. request.setStaffId(p.getStaffId());
  110. request.setPsnNo(siPatInfo.getPsnNo());
  111. request.setMdtrtId(siPatInfo.getMdtrtId());
  112. request.setPatNo(p.getPatNo());
  113. request.setTimes(p.getTimes());
  114. return executeOutpatientRegRevoke(request);
  115. }
  116. public ResultVo<String> executeOutpatientRegRevoke(RevokeRegRequest request) {
  117. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_REGISTRATION,
  118. request.getInsuplcAdmdvs(), request.getStaffId());
  119. JSONObject data = new JSONObject();
  120. data.put("psn_no", request.getPsnNo());
  121. data.put("mdtrt_id", request.getMdtrtId());
  122. data.put("ipt_otp_no", request.getPatNo());
  123. input.getJSONObject("input").put("data", data);
  124. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_REGISTRATION);
  125. log.info("【操作员:{}】,取消门诊挂号:\n参数:{},\n结果:{}", request.getStaffId(), input, result);
  126. Integer infcode = result.getInteger(RESULT_CODE);
  127. logDao.insert(new SiLog(input, result, request.getPatNo(), request.getTimes(), infcode, request.getPsnNo()));
  128. if (infcode == 0) {
  129. mzDao.clearMdtrtIdForMz(request.getPatNo(), request.getTimes(), null);
  130. return ResultVoUtil.success("取消门诊挂号成功。");
  131. }
  132. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  133. }
  134. private ResultVo<String> uploadOutpatientInfo(SpcChrDiseAcct spcChrDiseAcct, SiPatInfo siPatInfo) {
  135. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_INFO,
  136. siPatInfo.getInsuplcAdmdvs(), spcChrDiseAcct.getStaffId());
  137. JSONObject mdtrtinfo = new JSONObject();
  138. List<Diagnoses> diagnosesList = new ArrayList<>();
  139. String icdCodeNew = mzDao.selectIcdCodeNew(siPatInfo.getPatNo(), siPatInfo.getTimes());
  140. if (StringUtil.isBlank(icdCodeNew)) {
  141. diagnosesList = mzDao.selectMzDiags(siPatInfo.getPatNo(), siPatInfo.getTimes());
  142. if (null == diagnosesList || diagnosesList.isEmpty()) {
  143. log.info("【{}】 上传就诊信息失败,门诊诊断为空。", siPatInfo.getPatNo());
  144. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的门诊诊断为空,请联系医生填写。");
  145. }
  146. } else {
  147. Diagnoses base = mzDao.selectDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes());
  148. String[] icds = icdCodeNew.split(",");
  149. for (int i = 0; i < icds.length; i++) {
  150. String icd = icds[i];
  151. String icdTextNew = mzDao.selectIcdTextNew(icd);
  152. Diagnoses diag = new Diagnoses();
  153. diag.setDiagCode(icd);
  154. diag.setDiagName(icdTextNew);
  155. diag.setDiagSrtNo(i + 1);
  156. diag.setDiagType("1");
  157. diag.setValiFlag("1");
  158. diag.setDiagDept(base.getDiagDept());
  159. diag.setDiagTime(base.getDiagTime());
  160. diag.setDiseDorNo(base.getDiseDorNo());
  161. diag.setDiseDorName(base.getDiseDorName());
  162. diagnosesList.add(diag);
  163. }
  164. }
  165. if (siPatInfo.getMedType().equals("14") || siPatInfo.getMedType().equals("51")) {
  166. if (StringUtil.isBlank(spcChrDiseAcct.getOpspDiseCode())) {
  167. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "生育门诊与慢特病门诊的病种不能为空 !");
  168. }
  169. }
  170. mdtrtinfo.put("mdtrt_id", siPatInfo.getMdtrtId());
  171. mdtrtinfo.put("psn_no", siPatInfo.getPsnNo());
  172. mdtrtinfo.put("med_type", siPatInfo.getMedType());
  173. mdtrtinfo.put("begntime", DateUtil.formatDatetime(siPatInfo.getVisitDatetime()));
  174. mdtrtinfo.put("main_cond_dscr", spcChrDiseAcct.getOpspDiseName());
  175. mdtrtinfo.put("dise_codg", spcChrDiseAcct.getOpspDiseCode());
  176. mdtrtinfo.put("dise_name", spcChrDiseAcct.getOpspDiseName());
  177. mdtrtinfo.put("birctrl_type", "");
  178. mdtrtinfo.put("birctrl_matn_date", "");
  179. mdtrtinfo.put("exp_content", spcChrDiseAcct.getExpContent());
  180. String ref = JSONObject.toJSONString(diagnosesList);
  181. input.getJSONObject("input").put("mdtrtinfo", mdtrtinfo);
  182. input.getJSONObject("input").put("diseinfo", JSONArray.parse(ref));
  183. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_OUTPATIENT_INFO);
  184. log.info("【操作员:{}】门诊就诊信息上传:\n参数:{},\n结果:{}", spcChrDiseAcct.getStaffId(), input, result);
  185. Integer infcode = result.getInteger(RESULT_CODE);
  186. logDao.insert(new SiLog(input, result, siPatInfo.getPatNo(), siPatInfo.getTimes(), infcode, siPatInfo.getPsnNo()));
  187. if (result.getIntValue(RESULT_CODE) == 0) {
  188. Diagnoses main = diagnosesList.get(0);
  189. mzDao.updatePatDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes(), main.getDiagCode(), main.getDiagName());
  190. return ResultVoUtil.success("门诊就诊信息上传成功。");
  191. }
  192. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  193. }
  194. public ResultVo<SiPatInfo> uploadOutpatientFeeDetails(SpcChrDiseAcct p) {
  195. String patNo = p.getPatNo();
  196. if (null == p.getTimes()) {
  197. p.setTimes(mzDao.selectMaxTimes(patNo));
  198. }
  199. SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(patNo, p.getTimes());
  200. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  201. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo +
  202. "】未找到此患者的医保挂号信息,请核实。");
  203. }
  204. setlinfoDao.deletePreSettleInfo(patNo, p.getTimes());
  205. if (!p.getFromDirectReg()) {
  206. ResultVo<String> uplRes = uploadOutpatientInfo(p, siPatInfo);
  207. if (null != uplRes && uplRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  208. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, uplRes.getMessage());
  209. }
  210. }
  211. List<FeeDetail> feeDetails = mzDao.selectOutpatientFees(patNo, p.getTimes());
  212. if (null == feeDetails || feeDetails.isEmpty()) {
  213. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有需要上传的费用。");
  214. }
  215. MzVisit mzVisit = mzDao.selectMzVisitInfo(patNo, p.getTimes());
  216. if (null == mzVisit || StringUtil.isBlank(mzVisit.getVisitDeptCode())) {
  217. log.info("【{},{}】就诊科室没有匹配医保码,无法使用门诊统筹。", patNo, p.getTimes());
  218. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "就诊科室没有匹配医保码,无法使用门诊统筹。");
  219. }
  220. String batchNo = patNo + "_" + p.getTimes();
  221. feeDetails.forEach(item -> {
  222. item.setMdtrtId(siPatInfo.getMdtrtId());
  223. item.setPsnNo(siPatInfo.getPsnNo());
  224. item.setChrgBchno(batchNo);
  225. item.setRxCircFlag(YesOrNo.NO.getCodeStr());
  226. item.setHospApprFlag(YesOrNo.YES.getCodeStr());
  227. item.setBilgDeptCodg(mzVisit.getVisitDeptCode());
  228. item.setBilgDeptName(mzVisit.getVisitDeptName());
  229. if (siPatInfo.getMedType().equals("51")) {
  230. item.setMatnFeeFlag("1");
  231. }
  232. });
  233. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS,
  234. siPatInfo.getInsuplcAdmdvs(), p.getStaffId());
  235. String ref = JSONArray.toJSONStringWithDateFormat(feeDetails, "yyyy-MM-dd HH:mm:ss");
  236. JSONArray feedetail = JSONArray.parseArray(ref);
  237. input.getJSONObject("input").put("feedetail", feedetail);
  238. JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS);
  239. log.info("【操作员:{}】门诊费用明细信息上传:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  240. Integer infcode = result.getInteger(RESULT_CODE);
  241. logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo()));
  242. if (infcode == 0) {
  243. JSONArray feeRes = result.getJSONObject(OUTPUT).getJSONArray("result");
  244. double fulamtOwnpayAmt = 0d;
  245. double overlmtAmt = 0d;
  246. double preselfpayAmt = 0d;
  247. double inscpScpAmt = 0d;
  248. for (int i = 0; i < feeRes.size(); i++) {
  249. JSONObject fee = feeRes.getJSONObject(i);
  250. fulamtOwnpayAmt += fee.getDoubleValue("fulamt_ownpay_amt");
  251. overlmtAmt += fee.getDoubleValue("overlmt_amt");
  252. preselfpayAmt += fee.getDoubleValue("preselfpay_amt");
  253. inscpScpAmt += fee.getDoubleValue("inscp_scp_amt");
  254. String detlSn = fee.getString("feedetl_sn");
  255. String chrgLv = fee.getString("chrgitm_lv");
  256. String chrgType = fee.getString("med_chrgitm_type");
  257. String[] sns = detlSn.split("_");
  258. int times = Integer.parseInt(sns[1]);
  259. int recNo = Integer.parseInt(sns[2]);
  260. int odrNo = Integer.parseInt(sns[3]);
  261. int itmNo = Integer.parseInt(sns[4]);
  262. mzDao.afterUploadFees(patNo, times, recNo, odrNo, itmNo, chrgLv, chrgType);
  263. }
  264. siPatInfo.setFulamtOwnpayAmt(fulamtOwnpayAmt);
  265. siPatInfo.setOverlmtAmt(overlmtAmt);
  266. siPatInfo.setPreselfpayAmt(preselfpayAmt);
  267. siPatInfo.setInscpScpAmt(inscpScpAmt);
  268. mzDao.updateSortOfAmt(siPatInfo);
  269. return ResultVoUtil.success(siPatInfo);
  270. }
  271. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  272. }
  273. public ResultVo<String> revokeOutpatientFeeDetails(MzPatientInfo p) {
  274. if (null == p.getTimes()) {
  275. p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
  276. }
  277. SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes());
  278. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  279. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的医保挂号信息!");
  280. }
  281. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS,
  282. siPatInfo.getInsuplcAdmdvs(), p.getStaffId());
  283. JSONObject data = new JSONObject();
  284. data.put("mdtrt_id", siPatInfo.getMdtrtId());
  285. data.put("psn_no", siPatInfo.getPsnNo());
  286. data.put("chrg_bchno", "0000");
  287. input.getJSONObject("input").put("data", data);
  288. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS);
  289. log.info("【操作员:{}】门诊费用明细信息撤销,参数:{},结果:{}", p.getStaffId(), input, result);
  290. Integer infcode = result.getInteger(RESULT_CODE);
  291. logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo()));
  292. if (infcode == 0) {
  293. mzDao.afterRevokeFees(p.getPatNo(), p.getTimes());
  294. return ResultVoUtil.success("门诊费用明细信息撤销成功。");
  295. }
  296. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  297. }
  298. public ResultVo<FundDetail> outpatientPreSettlement(MzPatientInfo p) {
  299. while (MzgjUtil.inProcessing(p.getPatNo())) {
  300. try {
  301. TimeUnit.SECONDS.sleep(1);
  302. } catch (InterruptedException e) {
  303. throw new RuntimeException(e);
  304. }
  305. }
  306. if (null == p.getTimes()) {
  307. p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
  308. }
  309. ResultVo<FundDetail> setlfund = getFundDetailByPatientInfo(p.getPatNo(), p.getTimes(), false);
  310. if (setlfund != null) {
  311. return setlfund;
  312. }
  313. MzPreSetlmt mzPreSetlmt = mzDao.selectPreSetlmt(p.getPatNo(), p.getTimes());
  314. if (null == mzPreSetlmt || null == mzPreSetlmt.getMedfeeSumamt()) {
  315. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者没有已上传的费用。");
  316. }
  317. ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
  318. if (readCardBizType == ReadCardBizType.SETTLEMENT) {
  319. MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
  320. mzPreSetlmt.setMdtrtCertType(mdtrtCertType.getCode());
  321. if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) {
  322. String[] out = p.getReadCardResult().split("\\|");
  323. mzPreSetlmt.setMdtrtCertNo(out[2]);
  324. mzPreSetlmt.setCardSn(out[3]);
  325. } else if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) {
  326. JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
  327. if (!p.getSocialNo().trim().equals(qrinfo.getString("idNo").trim())) {
  328. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。");
  329. }
  330. mzPreSetlmt.setMdtrtCertNo(qrinfo.getString("ecToken"));
  331. }
  332. }
  333. mzPreSetlmt.setMedfeeSumamt(mzPreSetlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP));
  334. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_PRE_SETTLEMENT,
  335. mzPreSetlmt.getInsuplcAdmdvs(), p.getStaffId());
  336. mzPreSetlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  337. mzPreSetlmt.setAcctUsedFlag(p.getAcctUsedFlag());
  338. mzPreSetlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes());
  339. mzPreSetlmt.setExpContent(p.getExpContent());
  340. String ref = JSONObject.toJSONString(mzPreSetlmt);
  341. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  342. JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_PRE_SETTLEMENT);
  343. log.info("【操作员:{}】门诊预结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  344. Integer infcode = result.getInteger(RESULT_CODE);
  345. logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, mzPreSetlmt.getPsnNo()));
  346. if (infcode == 0) {
  347. JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  348. FundDetail fundDetail = new FundDetail();
  349. fundDetail.setTotalCost(setlinfo.getString("medfee_sumamt"));
  350. fundDetail.setFundPay(setlinfo.getString("fund_pay_sumamt"));
  351. fundDetail.setCashPay(setlinfo.getString("psn_cash_pay"));
  352. fundDetail.setAcctPay(setlinfo.getString("acct_pay"));
  353. fundDetail.setSelfPay(setlinfo.getString("psn_part_amt"));
  354. fundDetail.setCardType(getCardType(mzPreSetlmt.getInsuplcAdmdvs()));
  355. if (p.needSavePreSettleResult()) {
  356. setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
  357. SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
  358. setlEntity.setPatNo(p.getPatNo());
  359. setlEntity.setTimes(p.getTimes());
  360. setlEntity.setLedgerSn(0);
  361. setlEntity.setStaffId(p.getStaffId());
  362. setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
  363. setlEntity.setInsuplcAdmdvs(mzPreSetlmt.getInsuplcAdmdvs());
  364. setlinfoDao.insertPreSettleInfo(setlEntity);
  365. }
  366. return ResultVoUtil.success(fundDetail);
  367. }
  368. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  369. }
  370. private ResultVo<FundDetail> getFundDetailByPatientInfo(String patientId, int times, boolean realSettle) {
  371. SiSetlinfo sisetlinfo = mzDao.selectSettledInfo(patientId, times, 0);
  372. if (!realSettle && null == sisetlinfo) {
  373. sisetlinfo = setlinfoDao.selectPresettleInfo(patientId, times);
  374. }
  375. if (null != sisetlinfo) {
  376. return getFundDetailFromSetlinfo(sisetlinfo);
  377. }
  378. return null;
  379. }
  380. private ResultVo<FundDetail> getFundDetailFromSetlinfo(SiSetlinfo setlinfo) {
  381. FundDetail fundDetail = new FundDetail();
  382. fundDetail.setCardType(getCardType(setlinfo.getInsuplcAdmdvs()));
  383. fundDetail.setTotalCost(String.valueOf(setlinfo.getMedfeeSumamt()));
  384. fundDetail.setFundPay(String.valueOf(setlinfo.getFundPaySumamt()));
  385. fundDetail.setCashPay(String.valueOf(setlinfo.getPsnCashPay()));
  386. fundDetail.setAcctPay(String.valueOf(setlinfo.getAcctPay()));
  387. fundDetail.setSelfPay(String.valueOf(setlinfo.getPsnPartAmt()));
  388. if (setlinfo.getRevoked() == 1) {
  389. fundDetail.reverseAll();
  390. }
  391. fundDetail.setSetlinfo(setlinfo);
  392. return ResultVoUtil.success(fundDetail);
  393. }
  394. private Integer getCardType(String insplc) {
  395. if (insplc.startsWith("4301")) {
  396. return 1;
  397. } else if (insplc.equals("439900")) {
  398. return 2;
  399. }
  400. return 3;
  401. }
  402. public ResultVo<FundDetail> outpatientSettlement(MzPatientInfo p) {
  403. ResultVo<FundDetail> setlfund = getFundDetailByPatientInfo(p.getPatNo(), p.getTimes(), true);
  404. if (setlfund != null) {
  405. return setlfund;
  406. }
  407. Setlmt setlmt = mzDao.selectSetlmt(p.getPatNo(), p.getTimes());
  408. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_SETTLEMENT,
  409. setlmt.getInsuplcAdmdvs(), p.getStaffId());
  410. ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
  411. if (readCardBizType == ReadCardBizType.SETTLEMENT) {
  412. MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
  413. setlmt.setMdtrtCertType(mdtrtCertType.getCode());
  414. if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) {
  415. String[] out = p.getReadCardResult().split("\\|");
  416. setlmt.setMdtrtCertNo(out[2]);
  417. setlmt.setCardSn(out[3]);
  418. } else if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) {
  419. JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
  420. if (!p.getSocialNo().trim().equals(qrinfo.getString("idNo").trim())) {
  421. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。");
  422. }
  423. setlmt.setMdtrtCertNo(qrinfo.getString("ecToken"));
  424. }
  425. }
  426. setlmt.setMedfeeSumamt(setlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP));
  427. setlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  428. setlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes());
  429. setlmt.setAcctUsedFlag(p.getAcctUsedFlag());
  430. setlmt.setInvono(SnowFlakeId.getInstance().nextId());
  431. setlmt.setExpContent(p.getExpContent());
  432. String ref = JSONObject.toJSONString(setlmt);
  433. input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  434. JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_SETTLEMENT);
  435. log.info("【操作员:{}】门诊结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  436. Integer infcode = result.getInteger(RESULT_CODE);
  437. logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, setlmt.getPsnNo()));
  438. if (infcode == 0) {
  439. JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  440. SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
  441. setlEntity.setPatNo(p.getPatNo());
  442. setlEntity.setTimes(p.getTimes());
  443. setlEntity.setLedgerSn(0);
  444. setlEntity.setStaffId(p.getStaffId());
  445. setlEntity.setRevoked(YesOrNo.NO.getCode());
  446. setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
  447. setlEntity.setInsuplcAdmdvs(setlmt.getInsuplcAdmdvs());
  448. setlEntity.setBegntime(mzDao.selectBegntime(p.getPatNo(), p.getTimes()));
  449. setlEntity.setEndtime(setlEntity.getSetlTime());
  450. setlEntity.setMzSaved(p.getSaved());
  451. BigDecimal hospitalPart = BigDecimal.ZERO;
  452. JSONArray setldetail = result.getJSONObject(OUTPUT).getJSONArray("setldetail");
  453. for (int i = 0; i < setldetail.size(); i++) {
  454. SiSetldetail setldetailEntity = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(),
  455. SiSetldetail.class);
  456. setldetailEntity.setPatNo(p.getPatNo());
  457. setldetailEntity.setTimes(p.getTimes());
  458. setldetailEntity.setLedgerSn(0);
  459. if (setldetailEntity.getFundPayType().equals("999996") || setldetailEntity.getSetlProcInfo().equals("999996")) {
  460. hospitalPart = hospitalPart.add(BigDecimal.valueOf(setldetailEntity.getFundPayamt()));
  461. }
  462. setldetailDao.insert(setldetailEntity);
  463. }
  464. setlEntity.setHospPartAmt(hospitalPart.doubleValue());
  465. setlinfoDao.insert(setlEntity);
  466. setlinfoDao.updateSiZyInfoSetlId(p.getPatNo(), p.getTimes(), 0, setlEntity.getSetlId(),
  467. setlEntity.getMedinsSetlId(), input.getString("msgid"));
  468. webHisService.saveCumInfo(webHisUrl, setlEntity);
  469. if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(setlEntity.getPsnCashPay())) == 0) {
  470. ResultVo<String> mzChargeResponse = mzChargeFee(p.getPatNo(), p.getTimes(),
  471. String.valueOf(setlEntity.getMedfeeSumamt()));
  472. if (mzChargeResponse.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  473. revokeOutpatientSettlementForTask(setlEntity);
  474. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, mzChargeResponse.getMessage());
  475. }
  476. }
  477. setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
  478. return getFundDetailFromSetlinfo(setlEntity);
  479. }
  480. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  481. }
  482. public ResultVo<FundDetail> revokeOutpatientSettlement(MzPatientInfo p) {
  483. log.info("请求撤销门诊医保结算:{}", JSONObject.toJSON(p));
  484. if (null == p.getTimes()) {
  485. p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
  486. }
  487. SiSetlinfo setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 0);
  488. if (null == setlinfo) {
  489. if (p.needRevokeRegistration()) {
  490. deletePresettleInfo(p);
  491. }
  492. setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 1);
  493. if (null == setlinfo) {
  494. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的已结算数据。");
  495. }
  496. return getFundDetailFromSetlinfo(setlinfo);
  497. }
  498. String staffDept = mzDao.selectStaffDepartment(p.getStaffId());
  499. if (!Objects.equals(staffDept, "3020100") &&
  500. !Objects.equals(staffDept, "3060000") &&
  501. !Objects.equals(staffDept, "3100000")) {
  502. if (!Objects.equals(p.getStaffId(), setlinfo.getStaffId())) {
  503. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "您没有权限撤销本条医保业务,请到收费窗口退处方,或者联系医保科处理。");
  504. }
  505. }
  506. if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(setlinfo.getPsnCashPay())) == 0
  507. && !Objects.equals(staffDept, "3060000")) {
  508. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "本次结算【个人现金支付为0】,请到收费窗口做退费操作。");
  509. }
  510. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT,
  511. mzDao.selectAdmdvs(setlinfo.getPatNo(), setlinfo.getTimes(), setlinfo.getLedgerSn()), p.getStaffId());
  512. JSONObject data = new JSONObject();
  513. data.put("setl_id", setlinfo.getSetlId());
  514. data.put("mdtrt_id", setlinfo.getMdtrtId());
  515. data.put("psn_no", setlinfo.getPsnNo());
  516. input.getJSONObject("input").put("data", data);
  517. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_SETTLEMENT);
  518. log.info("【操作员:{}】门诊结算撤销:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  519. Integer infcode = result.getInteger(RESULT_CODE);
  520. logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, setlinfo.getPsnNo()));
  521. if (infcode == 0) {
  522. afterRevokeSetl(p.getPatNo(), p.getTimes(), input.getString("msgid"));
  523. if (p.needRevokeRegistration()) {
  524. deletePresettleInfo(p);
  525. }
  526. return getFundDetailFromSetlinfo(setlinfo);
  527. }
  528. if (p.needRevokeRegistration()) {
  529. deletePresettleInfo(p);
  530. }
  531. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  532. }
  533. public void revokeOutpatientSettlementForTask(SiSetlinfo setlinfo) {
  534. JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT,
  535. mzDao.selectAdmdvs(setlinfo.getPatNo(), setlinfo.getTimes(), setlinfo.getLedgerSn()), "99999");
  536. JSONObject data = new JSONObject();
  537. data.put("setl_id", setlinfo.getSetlId());
  538. data.put("mdtrt_id", setlinfo.getMdtrtId());
  539. data.put("psn_no", setlinfo.getPsnNo());
  540. input.getJSONObject("input").put("data", data);
  541. JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_SETTLEMENT);
  542. log.info("【操作员:99999】门诊结算撤销:\n参数:{},\n结果:{}", input, result);
  543. Integer infcode = result.getInteger(RESULT_CODE);
  544. logDao.insert(new SiLog(input, result, setlinfo.getPatNo(), setlinfo.getTimes(), infcode, setlinfo.getPsnNo()));
  545. if (null != infcode && infcode == 0) {
  546. afterRevokeSetl(setlinfo.getPatNo(), setlinfo.getTimes(), input.getString("msgid"));
  547. MzPatientInfo mzPatientInfo = new MzPatientInfo();
  548. mzPatientInfo.setPatNo(setlinfo.getPatNo());
  549. mzPatientInfo.setTimes(setlinfo.getTimes());
  550. mzPatientInfo.setStaffId("99999");
  551. revokeOutpatientFeeDetails(mzPatientInfo);
  552. revokeOutpatientRegistration(mzPatientInfo);
  553. }
  554. }
  555. public void afterRevokeSetl(String patNo, int times, String msgId) {
  556. try {
  557. mzDao.deleteSetlInfo(patNo, times);
  558. mzDao.deleteSetlDetail(patNo, times);
  559. mzDao.updateRvkSetlMsgid(patNo, times, msgId);
  560. setlinfoDao.deletePreSettleInfo(patNo, times);
  561. } catch (Exception e) {
  562. String sql1 = String.format("update t_si_setlinfo set revoked=1,mz_saved=0 where pat_no='%s' and times=%d;\n", patNo, times);
  563. String sql2 = String.format("delete from t_si_setldetail where pat_no='%s' and times=%d;\n", patNo, times);
  564. String sql3 = String.format("update t_si_pat_info set rvk_setl_msgid='%s' where pat_no='%s' and times=%d;",
  565. msgId, patNo, times);
  566. String sql = sql1 + sql2 + sql3;
  567. mariadbService.insertNewRecord(sql);
  568. }
  569. }
  570. public ResultVo<FundDetail> directRegistration(DirectionRegParam param) {
  571. log.info("门诊共济:{}", param);
  572. if (MzgjUtil.inProcessing(param.getPatientId())) {
  573. log.info("【{}】此患者上一次的共济流程尚未结束,请稍后再试。", param.getPatientId());
  574. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者上一次的共济流程尚未结束,请稍后再试。");
  575. }
  576. ResultVo<FundDetail> setlfund = getFundDetailByPatientInfo(param.getPatientId(), param.getTimes(), false);
  577. if (setlfund != null) {
  578. return setlfund;
  579. }
  580. MzgjUtil.addProcess(param.getPatientId());
  581. try {
  582. return executeMzgj(param);
  583. } catch (Exception e) {
  584. log.error("门诊共济出错:", e);
  585. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
  586. } finally {
  587. MzgjUtil.finishProcessing(param.getPatientId());
  588. }
  589. }
  590. private ResultVo<FundDetail> executeMzgj(DirectionRegParam param) {
  591. if (mzDao.selectExistCount(param.getPatientId(), param.getTimes()) == 0) {
  592. int update = mzDao.updateMzTimes(param.getPatientId(), param.getTimes());
  593. if (update == 0) {
  594. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
  595. "[t_si_pat_info]不存在患者[" + param.getPatientId()
  596. + "]第[" + param.getTimes() + "]次的就诊信息,请重新查询。");
  597. }
  598. }
  599. mzDao.deleteTempPatinfo(param.getPatientId(), param.getTimes());
  600. MzPatientInfo mzptnt = new MzPatientInfo();
  601. mzptnt.setStaffId(param.getStaffId());
  602. mzptnt.setPatNo(param.getPatientId());
  603. mzptnt.setTimes(param.getTimes());
  604. mzptnt.setMedType("11");
  605. mzptnt.setAcctUsedFlag(String.valueOf(param.getAcctUsedFlag()));
  606. SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes());
  607. mzptnt.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs());
  608. mzptnt.setInsutype(siPatInfo.getInsutype());
  609. mzptnt.setPsnType(siPatInfo.getPsnType());
  610. mzptnt.setName(siPatInfo.getPsnName());
  611. mzptnt.setSocialNo(siPatInfo.getCertno());
  612. if (StringUtil.notBlank(param.getReadCardResult())) {
  613. MdtrtCertType mdtrtCertType = MdtrtCertType.get(param.getReadCardType());
  614. mzptnt.setMdtrtCertType(mdtrtCertType.getLabel());
  615. mzptnt.setReadCardBizType(ReadCardBizType.REGISTRATION.getCode());
  616. mzptnt.setReadCardResult(param.getReadCardResult());
  617. if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) {
  618. JSONObject obj = JSONObject.parseObject(param.getReadCardResult());
  619. String admdvs = obj.getString("insuOrg");
  620. if (StringUtil.isBlank(mzptnt.getInsuplcAdmdvs())) {
  621. mzptnt.setInsuplcAdmdvs(admdvs);
  622. }
  623. }
  624. }
  625. ResultVo<String> regres = outpatientRegistration(mzptnt);
  626. if (regres.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  627. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, regres.getMessage());
  628. }
  629. // 挂号登记成功后上传就诊信息
  630. siPatInfo = mzDao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes());
  631. siPatInfo.setFromDirectReg(true);
  632. SpcChrDiseAcct spcChrDiseAcct = new SpcChrDiseAcct();
  633. spcChrDiseAcct.setStaffId(param.getStaffId());
  634. spcChrDiseAcct.setExpContent(param.getExpContent());
  635. ResultVo<String> upldMdtrtRes = uploadOutpatientInfo(spcChrDiseAcct, siPatInfo);
  636. if (upldMdtrtRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  637. revokeOutpatientRegistration(mzptnt);
  638. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldMdtrtRes.getMessage());
  639. }
  640. // 上传就诊信息成功后生成门诊医保费用
  641. ResultVo<List<Map<String, Object>>> getMzRcptRes = webHisService.getMzReceipts(webHisUrl, mzptnt);
  642. if (null == getMzRcptRes) {
  643. revokeOutpatientRegistration(mzptnt);
  644. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  645. }
  646. if (getMzRcptRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  647. revokeOutpatientRegistration(mzptnt);
  648. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, getMzRcptRes.getMessage());
  649. }
  650. List<MzReceipt> mzReceipts = new ArrayList<>();
  651. for (Map<String, Object> item : getMzRcptRes.getData()) {
  652. int times = (int) item.get("times");
  653. if (times != mzptnt.getTimes()) {
  654. continue;
  655. }
  656. mzDao.deleteAllReceipts(param.getPatientId(), times);
  657. Map<Integer, List<MzReceipt>> orderReceiptsMap = FilterUtil.cast(item.get("mzReceipts"));
  658. for (Map.Entry<Integer, List<MzReceipt>> entry : orderReceiptsMap.entrySet()) {
  659. mzReceipts.addAll(entry.getValue());
  660. }
  661. }
  662. if (mzReceipts.isEmpty()) {
  663. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有可以上传到医保的费用。");
  664. }
  665. ResultVo<String> insertSiMzFeeRes = webHisService.insertSiMzFees(webHisUrl, mzReceipts);
  666. if (insertSiMzFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  667. revokeOutpatientRegistration(mzptnt);
  668. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, insertSiMzFeeRes.getMessage());
  669. }
  670. // 生成费用成功后上传到医保
  671. spcChrDiseAcct.setStaffId(param.getStaffId());
  672. spcChrDiseAcct.setPatNo(mzptnt.getPatNo());
  673. spcChrDiseAcct.setTimes(mzptnt.getTimes());
  674. spcChrDiseAcct.setFromDirectReg(true);
  675. ResultVo<SiPatInfo> upldFeeRes = uploadOutpatientFeeDetails(spcChrDiseAcct);
  676. if (upldFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  677. revokeOutpatientRegistration(mzptnt);
  678. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldFeeRes.getMessage());
  679. }
  680. // 上传完成之后试算并返回试算结果
  681. mzptnt.setReadCardBizType(ReadCardBizType.SETTLEMENT.getCode());
  682. // mzptnt.setSavePreSettleResult(true);
  683. // return outpatientPreSettlement(mzptnt);
  684. return outpatientSettlement(mzptnt);
  685. }
  686. private ResultVo<String> mzChargeFee(String patientId, int times, String totalFee) {
  687. JSONObject params = new JSONObject();
  688. params.put("patientId", patientId);
  689. params.put("times", times);
  690. params.put("totalFee", totalFee);
  691. int tryTimes = 1;
  692. JSONObject response = webHisService.mzChargeFee(thmzUrl, params);
  693. log.info("第{}次保存处方:\n参数:{}\n结果:{}", tryTimes, params, response);
  694. while (0 != response.getInteger("code") && tryTimes < 5
  695. && !response.getString("message").contains("已经收费")) {
  696. try {
  697. tryTimes += 1;
  698. response = webHisService.mzChargeFee(thmzUrl, params);
  699. log.info("第{}次保存处方:\n参数:{}\n结果:{}", tryTimes, params, response);
  700. TimeUnit.SECONDS.sleep(Math.min(tryTimes, 3));
  701. } catch (Exception e) {
  702. log.error("TIMEUNIT SLEEP ERROR", e);
  703. }
  704. }
  705. if (0 != response.getInteger("code") && !response.getString("message").contains("已经收费")) {
  706. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "自动保存处方失败,将为您撤销门诊医保业务。");
  707. }
  708. return ResultVoUtil.success();
  709. }
  710. public ResultVo<Integer> isPatientDuringSiSettle(String patientId) {
  711. int result = MzgjUtil.inProcessing(patientId) ? 1 : 0;
  712. return ResultVoUtil.success(result);
  713. }
  714. public void deletePresettleInfo(MzPatientInfo p) {
  715. int res = setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
  716. if (res == 1) {
  717. revokeOutpatientFeeDetails(p);
  718. revokeOutpatientRegistration(p);
  719. }
  720. }
  721. }