SiMzService.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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 lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.stereotype.Service;
  9. import thyyxxk.webserver.config.exception.ExceptionEnum;
  10. import thyyxxk.webserver.constants.Capacity;
  11. import thyyxxk.webserver.constants.sidicts.Insutype;
  12. import thyyxxk.webserver.constants.sidicts.MdtrtCertType;
  13. import thyyxxk.webserver.constants.sidicts.MedType;
  14. import thyyxxk.webserver.constants.sidicts.SiFunction;
  15. import thyyxxk.webserver.dao.his.medicalinsurance.SiMzDao;
  16. import thyyxxk.webserver.entity.ResultVo;
  17. import thyyxxk.webserver.entity.markmtfees.*;
  18. import thyyxxk.webserver.entity.medicalinsurance.manage.clinicinfo.RevokeRegRequest;
  19. import thyyxxk.webserver.entity.medicalinsurance.outpatient.*;
  20. import thyyxxk.webserver.entity.medicalinsurance.query.InsuInfo;
  21. import thyyxxk.webserver.entity.medicalinsurance.query.PsnBaseInfo;
  22. import thyyxxk.webserver.entity.medicalinsurance.query.QryPsnBsInfo;
  23. import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo;
  24. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.FundDetail;
  25. import thyyxxk.webserver.service.externalhttp.SiMzSrvc;
  26. import thyyxxk.webserver.service.externalhttp.ThmzSystem;
  27. import thyyxxk.webserver.utils.*;
  28. import java.math.BigDecimal;
  29. import java.math.RoundingMode;
  30. import java.util.*;
  31. /**
  32. * @description: 门诊医保交易
  33. * @author: DingJie
  34. * @create: 2021-05-28 16:11:19
  35. **/
  36. @Slf4j
  37. @Service
  38. public class SiMzService {
  39. private final SiMzDao dao;
  40. private final ExecService exec;
  41. private final ThmzSystem thmz;
  42. private final SiMzSrvc mzSrvc;
  43. private final SiQueryService qryService;
  44. private static final String RESULT_CODE = "infcode";
  45. private static final String OUTPUT = "output";
  46. @Value("${si-mz-fee-url}")
  47. private String siMzFeeUrl;
  48. @Value("${thmz-api-url}")
  49. private String thmzApiUrl;
  50. @Autowired
  51. public SiMzService(SiMzDao dao, ExecService exec, ThmzSystem thmz, SiMzSrvc mzSrvc, SiQueryService qryService) {
  52. this.dao = dao;
  53. this.exec = exec;
  54. this.thmz = thmz;
  55. this.mzSrvc = mzSrvc;
  56. this.qryService = qryService;
  57. }
  58. public ResultVo<String> outpatientRegistration(MzPatientInfo p) {
  59. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  60. return mzSrvc.outpatientRegistration(siMzFeeUrl, p);
  61. }
  62. public ResultVo<String> revokeOutpatientRegistration(MzPatientInfo p) {
  63. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  64. return mzSrvc.revokeOutpatientRegistration(siMzFeeUrl, p);
  65. }
  66. public ResultVo<String> executeOutpatientRegRevoke(RevokeRegRequest request) {
  67. request.setStaffId(TokenUtil.getInstance().getTokenUserId());
  68. return mzSrvc.executeOutpatientRegRevoke(siMzFeeUrl, request);
  69. }
  70. public ResultVo<List<Map<String, Object>>> getMzReceipts(MzPatientInfo p) {
  71. String patNo = p.getPatNo();
  72. JSONObject queryMzChargeListParam = new JSONObject();
  73. queryMzChargeListParam.put("patCardType", 21);
  74. queryMzChargeListParam.put("patCardNo", patNo);
  75. queryMzChargeListParam.put("hisOrdNum", "");
  76. queryMzChargeListParam.put("ybRequest", 1);
  77. Map<String, Object> mzChargeListMap = thmz.getMzChargeDetailForUnPaid(thmzApiUrl, queryMzChargeListParam);
  78. if (null == mzChargeListMap) {
  79. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  80. }
  81. if (0 != (int) mzChargeListMap.get("resultCode")) {
  82. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, mzChargeListMap.get("resultMessage").toString());
  83. }
  84. List<Map<String, Object>> finalResult = new ArrayList<>();
  85. List<Map<String, String>> mzChargeList = FilterUtil.cast(mzChargeListMap.get("data"));
  86. for (Map<String, String> item : mzChargeList) {
  87. String hisOrdNum = item.get("hisOrdNum");
  88. if (null != hisOrdNum) {
  89. String[] hisOrdNumParts = hisOrdNum.split("_");
  90. int tempTimes = Integer.parseInt(hisOrdNumParts[1]);
  91. MzVisit mzVisit = dao.selectMzVisit(patNo, tempTimes);
  92. if (null == mzVisit) {
  93. continue;
  94. }
  95. mzVisit.setReceiptNo(Integer.parseInt(hisOrdNumParts[2]));
  96. mzVisit.setTableClinicReceiptNo(0);
  97. Map<String, Object> childResult = new HashMap<>(Capacity.FIVE);
  98. childResult.put("times", tempTimes);
  99. childResult.put("mzVisit", mzVisit);
  100. JSONObject queryMzChargeDetailParam = new JSONObject();
  101. queryMzChargeDetailParam.put("patientId", patNo);
  102. queryMzChargeDetailParam.put("times", tempTimes);
  103. queryMzChargeDetailParam.put("receiptNo", hisOrdNumParts[2]);
  104. Map<String, Object> mzChargeDetailMap = thmz.unPaidToFullChargeDetail(thmzApiUrl, queryMzChargeDetailParam);
  105. if (null != mzChargeDetailMap && 0 == (int) mzChargeDetailMap.get("resultCode")) {
  106. List<Map<String, Object>> mzChargeDetailList = FilterUtil.cast(mzChargeDetailMap.get("data"));
  107. mzChargeDetailList.removeIf(detail -> "TC".equals(detail.get("billItemCode")) ||
  108. !"5".equals(detail.get("payMark")) || "BILL99".equals(detail.get("chargeItemCode")) ||
  109. "四舍五入".equals(detail.get("tcName")));
  110. if (mzChargeDetailList.isEmpty()) {
  111. continue;
  112. }
  113. Map<Integer, List<MzReceipt>> orderReceiptsMap = new HashMap<>(Capacity.DEFAULT);
  114. String doctorName = dao.selectDoctorName(mzChargeDetailList.get(0).get("doctorCode").toString());
  115. mzChargeDetailList.forEach(detail -> {
  116. MzReceipt receipt = fillMzReceipt(detail);
  117. receipt.setPatientId(patNo);
  118. receipt.setTimes(tempTimes);
  119. receipt.setDoctorName(doctorName);
  120. if (!orderReceiptsMap.containsKey(receipt.getOrderNo())) {
  121. List<MzReceipt> list = new ArrayList<>();
  122. list.add(receipt);
  123. orderReceiptsMap.put(receipt.getOrderNo(), list);
  124. } else {
  125. orderReceiptsMap.get(receipt.getOrderNo()).add(receipt);
  126. }
  127. });
  128. List<OrderNo> orderNos = getOrderNos(patNo, tempTimes, mzVisit.getReceiptNo(), orderReceiptsMap);
  129. childResult.put("orderNos", orderNos);
  130. childResult.put("mzReceipts", orderReceiptsMap);
  131. childResult.put("zgmztczf", mzSrvc.getZgmztczf(mzVisit).getData());
  132. finalResult.add(childResult);
  133. }
  134. }
  135. }
  136. return ResultVoUtil.success(finalResult);
  137. }
  138. public ResultVo<List<MzDepositFile>> getHistoryMzReceipts(String patNo, String start, String end) {
  139. List<MzDepositFile> mzChargeList = dao.selectMzDepositFiles(patNo, start, end);
  140. if (null == mzChargeList || mzChargeList.isEmpty()) {
  141. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到历史处方!");
  142. }
  143. for (MzDepositFile depositFile : mzChargeList) {
  144. MzVisit mzVisit = new MzVisit();
  145. mzVisit.setPatientId(patNo);
  146. mzVisit.setTimes(depositFile.getTimes());
  147. mzVisit.setReceiptNo(depositFile.getReceiptNo());
  148. depositFile.setZgmztczf(mzSrvc.getZgmztczf(mzVisit).getData());
  149. }
  150. return ResultVoUtil.success(mzChargeList);
  151. }
  152. public ResultVo<Map<String, Object>> getHistoryReceiptDetail(MzDepositFile mzDepositFile) {
  153. MzVisit mzVisit = dao.selectMzVisit(mzDepositFile.getPatNo(), mzDepositFile.getTimes());
  154. List<MzReceipt> mzReceipts = dao.selectMzCharge(mzDepositFile.getPatNo(),
  155. mzDepositFile.getTimes(), mzDepositFile.getReceiptNo());
  156. mzReceipts.forEach(itm -> itm.setChecked(StringUtil.notBlank(itm.getNationalCode())));
  157. Map<String, Object> map = new HashMap<>();
  158. map.put("mzVisit", mzVisit);
  159. map.put("mzReceipts", mzReceipts);
  160. return ResultVoUtil.success(map);
  161. }
  162. private MzReceipt fillMzReceipt(Map<String, Object> detail) {
  163. MzReceipt receipt = new MzReceipt();
  164. receipt.setReceiptNo((int) detail.get("receiptNo"));
  165. receipt.setOrderNo((int) detail.get("orderNo"));
  166. receipt.setItemNo((int) detail.get("itemNo"));
  167. receipt.setDrugName(detail.get("tcName").toString());
  168. receipt.setChargeItemCode(detail.get("chargeItemCode").toString());
  169. receipt.setPriceTime(DateUtil.formatPriceTime(detail.get("priceTime").toString()));
  170. receipt.setUnitPrice(new BigDecimal(detail.get("unitPrice").toString()).setScale(4, RoundingMode.HALF_UP));
  171. receipt.setQuantity(Double.valueOf(detail.get("quantity").toString()));
  172. receipt.setDrugWin((int) detail.get("drugWin"));
  173. receipt.setDoctorCode(detail.get("doctorCode").toString());
  174. receipt.setGroupNo(detail.get("groupNo").toString());
  175. receipt.setChargeDate(detail.get("priceTime").toString().split("\\+")[0].replace("T", " "));
  176. receipt.setBillItemCode(detail.get("billItemCode").toString());
  177. receipt.setChargeBillCode(detail.get("chargeBillCode").toString());
  178. String table = receipt.getGroupNo().trim().equals("00") ? "zd_charge_item" : "yp_zd_dict";
  179. receipt.setNationalCode(dao.selectNationalCode(receipt.getChargeItemCode(), table));
  180. receipt.setChecked(StringUtil.notBlank(receipt.getNationalCode()));
  181. if (null != detail.get("serialNo")) {
  182. receipt.setSerialNo(detail.get("serialNo").toString());
  183. }
  184. if (null != detail.get("instructionText")) {
  185. receipt.setInstructionText(detail.get("instructionText").toString());
  186. }
  187. if (null != detail.get("specification")) {
  188. receipt.setSpecification(detail.get("specification").toString());
  189. }
  190. if (null != detail.get("frequency")) {
  191. receipt.setFrequency(detail.get("frequency").toString());
  192. }
  193. if (null != detail.get("drugQuan")) {
  194. receipt.setDrugQuan(Double.valueOf(detail.get("drugQuan").toString()));
  195. }
  196. if (null != detail.get("orderDays")) {
  197. receipt.setOrderDays((Integer) detail.get("orderDays"));
  198. }
  199. // groupNo:00-项目;其他-药品
  200. if ("00".equals(receipt.getGroupNo())) {
  201. receipt.setDrugUnit(dao.selectXmChargeUnit(receipt.getChargeItemCode()));
  202. } else {
  203. if (null != detail.get("serial")) {
  204. receipt.setSerial(detail.get("serial").toString());
  205. receipt.setSpecification(dao.selectSpecification(receipt.getChargeItemCode(), receipt.getSerial()));
  206. }
  207. if (null != detail.get("supplyCode")) {
  208. receipt.setSupplyCode(dao.selectSupplyName(detail.get("supplyCode").toString()));
  209. }
  210. if (null != detail.get("drugUnit")) {
  211. receipt.setDrugUnit(dao.selectDrugUnit(detail.get("drugUnit").toString()));
  212. }
  213. }
  214. return receipt;
  215. }
  216. private List<OrderNo> getOrderNos(String patientId, int times, int receiptNo, Map<Integer, List<MzReceipt>> orderReceiptsMap) {
  217. List<OrderNo> orderNos = new ArrayList<>();
  218. for (Map.Entry<Integer, List<MzReceipt>> entry : orderReceiptsMap.entrySet()) {
  219. OrderNo orderNo = new OrderNo();
  220. orderNo.setPatientId(patientId);
  221. orderNo.setTimes(times);
  222. orderNo.setReceiptNo(entry.getValue().get(0).getReceiptNo());
  223. orderNo.setOrderNo(entry.getKey());
  224. BigDecimal total = new BigDecimal("0.00");
  225. for (MzReceipt receipt : entry.getValue()) {
  226. total = total.add(receipt.getChargeFee());
  227. }
  228. orderNo.setTotalFee(total);
  229. int count = dao.selectFeeCount(patientId, times, receiptNo, entry.getKey());
  230. orderNo.setStatus(count > 0);
  231. orderNos.add(orderNo);
  232. }
  233. return orderNos;
  234. }
  235. public ResultVo<String> insertSiMzFees(List<MzReceipt> receipts) {
  236. receipts.removeIf(item -> !item.getChecked() || item.getChargeItemCode().equals("019110")
  237. || item.getChargeItemCode().equals("019180"));
  238. if (receipts.isEmpty()) {
  239. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "患者没有可以报销的项目!");
  240. }
  241. receipts.forEach(dao::insertBatchedMtFeeInfo);
  242. return ResultVoUtil.success();
  243. }
  244. public ResultVo<String> insertSiMzFeesForSupplement(List<MzReceipt> receipts) {
  245. receipts.removeIf(item -> !item.getChecked() || item.getChargeItemCode().equals("019110")
  246. || item.getChargeItemCode().equals("019180"));
  247. if (receipts.isEmpty()) {
  248. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "患者没有可以报销的项目!");
  249. }
  250. MzReceipt receipt = receipts.get(0);
  251. List<Integer> receiptNos = dao.selectGeneratedReceiptNos(receipt.getPatientId(), receipt.getTimes());
  252. for (int receiptNo : receiptNos) {
  253. if (dao.isReceiptPayed(receipt.getPatientId(), receipt.getTimes(), receiptNo) == 0) {
  254. dao.deleteCertainReceipt(receipt.getPatientId(), receipt.getTimes(), receiptNo);
  255. }
  256. }
  257. receipts.forEach(dao::insertBatchedMtFeeInfo);
  258. return ResultVoUtil.success();
  259. }
  260. public ResultVo<String> deleteMzReceipt(OrderNo param) {
  261. dao.deleteMzReceipt(param);
  262. return ResultVoUtil.success();
  263. }
  264. public ResultVo<String> deleteAllMzReceipts(MzPatientInfo p) {
  265. if (null == p.getTimes()) {
  266. p.setTimes(dao.selectMaxTimes(p.getPatNo()));
  267. }
  268. log.info("【操作员:{}】删除所有门特处方:门诊号:{},门诊次数:{}",
  269. TokenUtil.getInstance().getTokenUserId(), p.getPatNo(), p.getTimes());
  270. dao.deleteAllReceipts(p.getPatNo(), p.getTimes());
  271. return ResultVoUtil.success("删除成功。");
  272. }
  273. public ResultVo<SiPatInfo> uploadOutpatientFeeDetails(SpcChrDiseAcct p) {
  274. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  275. return mzSrvc.uploadOutpatientFeeDetails(siMzFeeUrl, p);
  276. }
  277. public ResultVo<String> revokeOutpatientFeeDetails(MzPatientInfo p) {
  278. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  279. return mzSrvc.revokeOutpatientFeeDetails(siMzFeeUrl, p);
  280. }
  281. public ResultVo<FundDetail> outpatientPreSettlement(MzPatientInfo p) {
  282. if (null == p.getStaffId()) {
  283. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  284. }
  285. return mzSrvc.outpatientPreSettlement(siMzFeeUrl, p);
  286. }
  287. public ResultVo<FundDetail> outpatientSettlement(MzPatientInfo p) {
  288. if (null == p.getStaffId()) {
  289. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  290. }
  291. return mzSrvc.outpatientSettlement(siMzFeeUrl, p);
  292. }
  293. public ResultVo<FundDetail> revokeOutpatientSettlement(MzPatientInfo p) {
  294. if (null == p.getStaffId()) {
  295. p.setStaffId(TokenUtil.getInstance().getTokenUserId());
  296. }
  297. return mzSrvc.revokeOutpatientSettlement(siMzFeeUrl, p);
  298. }
  299. public void insertSiPatInfo(MzPatientInfo mz) {
  300. int count = dao.selectSiMzInfoCount(mz.getPatNo(), -1);
  301. if (count == 0) {
  302. PsnBaseInfo patinfo = dao.selectPsnBaseinfo(mz.getPatNo(), mz.getTimes());
  303. if (null != patinfo) {
  304. patinfo.setTimes(-1);
  305. dao.insertSiMzInfoPsnNo(patinfo);
  306. }
  307. }
  308. }
  309. public ResultVo<String> saveSiMzDiags(List<SiMzDiag> diags) {
  310. if (ListUtil.isBlank(diags)) {
  311. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有要保存的诊断!");
  312. }
  313. SiMzDiag diag = diags.get(0);
  314. dao.deleteMzDiags(diag.getPatNo(), diag.getTimes());
  315. String staffId = TokenUtil.getInstance().getTokenUserId();
  316. for (SiMzDiag itm : diags) {
  317. itm.setRealOpter(staffId);
  318. dao.insertNewMzDiag(itm);
  319. }
  320. return ResultVoUtil.success("门诊诊断保存成功。");
  321. }
  322. public ResultVo<List<SpcChrDiseAcct>> fetchSpcSlwinfo(String socialNo) {
  323. if (StringUtil.isBlank(socialNo)) {
  324. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者身份证号不能为空,请补充!");
  325. }
  326. JSONObject input = exec.makeTradeHeader(SiFunction.OBTAIN_BASIC_PERSON_INFO);
  327. JSONObject data = new JSONObject();
  328. data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  329. data.put("psn_cert_type", "01");
  330. data.put("mdtrt_cert_no", socialNo);
  331. data.put("certno", socialNo);
  332. input.getJSONObject("input").put("data", data);
  333. JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO);
  334. if (null == result) {
  335. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  336. }
  337. if (null == result.getInteger(RESULT_CODE)) {
  338. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
  339. }
  340. if (result.getIntValue(RESULT_CODE) == 0) {
  341. JSONObject output = result.getJSONObject(OUTPUT);
  342. JSONObject baseinfo = output.getJSONObject("baseinfo");
  343. String psnNo = baseinfo.getString("psn_no");
  344. JSONArray insuinfo = output.getJSONArray("insuinfo");
  345. Date now = new Date();
  346. List<SpcChrDiseAcct> list = new ArrayList<>();
  347. for (int i = 0; i < insuinfo.size(); i++) {
  348. JSONObject item = insuinfo.getJSONObject(i);
  349. String admdvs = item.getString("insuplc_admdvs");
  350. input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION, admdvs);
  351. data = new JSONObject();
  352. data.put("psn_no", psnNo);
  353. input.getJSONObject("input").put("data", data);
  354. result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION);
  355. if (null == result) {
  356. continue;
  357. }
  358. if (null == result.getInteger(RESULT_CODE)) {
  359. continue;
  360. }
  361. if (result.getIntValue(RESULT_CODE) == 0) {
  362. output = result.getJSONObject(OUTPUT);
  363. JSONArray details = output.getJSONArray("feedetail");
  364. if (null == details || details.isEmpty()) {
  365. continue;
  366. }
  367. for (int j = 0; j < details.size(); j++) {
  368. JSONObject detail = details.getJSONObject(j);
  369. SpcChrDiseAcct spcChrDiseAcct = JSONObject.parseObject(detail.toJSONString(), SpcChrDiseAcct.class);
  370. if (now.before(spcChrDiseAcct.getEnddate())) {
  371. list.add(spcChrDiseAcct);
  372. }
  373. }
  374. if (!list.isEmpty()) {
  375. return ResultVoUtil.success(list);
  376. }
  377. }
  378. }
  379. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
  380. }
  381. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
  382. }
  383. public Map<String, Object> queryInsuinfo(SiMzBusinessParams param) {
  384. Map<String, Object> result = new HashMap<>();
  385. QryPsnBsInfo mzptnt = new QryPsnBsInfo();
  386. mzptnt.setStaffId(param.getStaffId());
  387. mzptnt.setPatNo(param.getPatientId());
  388. mzptnt.setMedType(MedType.GENERAL_CLINIC.getCode());
  389. mzptnt.setOnlyQry(1);
  390. mzptnt.setTimes(-1);
  391. if (StringUtil.notBlank(param.getAdmdvs())) {
  392. mzptnt.setAdmdvs(param.getAdmdvs());
  393. mzptnt.setSocialNo(param.getSocialNo());
  394. }
  395. ResultVo<PsnBaseInfo> baseInfo = qryService.obtainBasicPersonInfo(mzptnt);
  396. if (null == baseInfo) {
  397. result.put("code", -2);
  398. result.put("msg", "网络异常。");
  399. return result;
  400. }
  401. if (baseInfo.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  402. result.put("code", -2);
  403. result.put("msg", baseInfo.getMessage());
  404. return result;
  405. }
  406. // 如果有职工保险,就入库
  407. PsnBaseInfo psninfo = baseInfo.getData();
  408. InsuInfo insuInfo = getEmployeeInsuInfo(psninfo.getInsuinfo());
  409. if (null == insuInfo) {
  410. result.put("code", -1);
  411. result.put("msg", "患者没有职工医保,如需报销请走医保科流程。");
  412. return result;
  413. }
  414. if (!isInsuplcAdmdvsEligible(insuInfo.getInsuplcAdmdvs())) {
  415. result.put("code", -1);
  416. result.put("msg", "患者参保地不满足门诊统筹要求。");
  417. return result;
  418. }
  419. psninfo.setInsutype(insuInfo.getInsutype());
  420. int count = dao.selectSiMzInfoCount(mzptnt.getPatNo(), mzptnt.getTimes());
  421. if (count == 0) {
  422. psninfo.setMedType(MedType.GENERAL_CLINIC.getCode());
  423. psninfo.setInsuplc(insuInfo.getInsuplcAdmdvs());
  424. psninfo.setPsnType(insuInfo.getPsnType());
  425. psninfo.setEmpName(insuInfo.getEmpName());
  426. psninfo.setBalc(insuInfo.getBalc());
  427. dao.insertSiMzInfoPsnNo(psninfo);
  428. } else {
  429. dao.updateSiZyInfoPsnNo(mzptnt.getPatNo(), mzptnt.getTimes(), psninfo.getInsutype(), insuInfo.getBalc());
  430. }
  431. result.put("code", 0);
  432. result.put("expContentRequired", expContentRequired(insuInfo.getInsuplcAdmdvs()));
  433. result.put("msg", "查询参保信息成功。");
  434. return result;
  435. }
  436. private InsuInfo getEmployeeInsuInfo(List<InsuInfo> list) {
  437. for (InsuInfo info : list) {
  438. Insutype insutype = Insutype.get(info.getInsutype());
  439. if (null == insutype) {
  440. continue;
  441. }
  442. if (insutype == Insutype.BASIC_MEDICAL_INSURANCE_FOR_EMPLOYEES) {
  443. return info;
  444. }
  445. }
  446. return null;
  447. }
  448. private InsuInfo getValidInsuInfo(List<InsuInfo> list) {
  449. for (InsuInfo info : list) {
  450. Insutype insutype = Insutype.get(info.getInsutype());
  451. if (null == insutype) {
  452. continue;
  453. }
  454. if (insutype == Insutype.BASIC_MEDICAL_INSURANCE_FOR_EMPLOYEES ||
  455. insutype == Insutype.BASIC_MEDICAL_INSURANCE_FOR_RURAL_RESIDENTS) {
  456. return info;
  457. }
  458. }
  459. return null;
  460. }
  461. private boolean isInsuplcAdmdvsEligible(String insuplc) {
  462. return !insuplc.startsWith("4304") && !insuplc.startsWith("4307");
  463. }
  464. private int expContentRequired(String insuplc) {
  465. return (insuplc.startsWith("4301") || insuplc.equals("439900")) ? 0 : 1;
  466. }
  467. public ResultVo<FundDetail> directRegistration(SiMzBusinessParams param) {
  468. return mzSrvc.directRegistration(siMzFeeUrl, param);
  469. }
  470. public ResultVo<FundDetail> mzgjAfterModifyReceipt(SiMzBusinessParams param) {
  471. PsnBaseInfo psnBaseInfo = dao.selectLatestPsnInfo(param.getPatientId());
  472. if (null == psnBaseInfo) {
  473. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "无法办理,没有找到参保信息。");
  474. }
  475. if (!Objects.equals(psnBaseInfo.getTimes(), param.getTimes())) {
  476. int count = dao.selectSiMzInfoCount(param.getPatientId(), param.getTimes());
  477. if (count == 0) {
  478. psnBaseInfo.setTimes(param.getTimes());
  479. dao.insertSiMzInfoPsnNo(psnBaseInfo);
  480. }
  481. }
  482. return mzSrvc.directRegistration(siMzFeeUrl, param);
  483. }
  484. public ResultVo<Integer> isPatientDuringSiSettle(String patientId) {
  485. return mzSrvc.isPatientDuringSiSettle(siMzFeeUrl, patientId);
  486. }
  487. public ResultVo<String> queryModifyPermission(MzPatientInfo info) {
  488. String setlStaff = dao.selectSetlStaff(info.getPatNo(), info.getTimes());
  489. if (StrUtil.isEmpty(setlStaff)) {
  490. return ResultVoUtil.success("OK");
  491. }
  492. if (Objects.equals(info.getStaffId(), setlStaff)) {
  493. return ResultVoUtil.success("OK");
  494. }
  495. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "DENIED");
  496. }
  497. public Map<String, Object> modifyFundPayAmount(ModifyFundAmt amt) {
  498. amt.fixNullVal();
  499. Integer res = dao.modifyFundAmt(amt);
  500. Map<String, Object> resultMap = new HashMap<>();
  501. if (null != res && res > 0) {
  502. resultMap.put("code", 0);
  503. resultMap.put("msg", "更新成功,有" + res + "条数据受影响。");
  504. } else {
  505. resultMap.put("code", -1);
  506. resultMap.put("msg", "更新失败,有0条数据受影响。");
  507. }
  508. log.info("THMZ修改报销数据:\n参数:{}\n结果:{}", amt, resultMap);
  509. return resultMap;
  510. }
  511. }