SiMzService.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. package thyyxxk.webserver.service.medicalinsurance;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.web.client.RestTemplate;
  8. import thyyxxk.webserver.config.exception.ExceptionEnum;
  9. import thyyxxk.webserver.constants.Capacity;
  10. import thyyxxk.webserver.dao.his.medicalinsurance.SiMzDao;
  11. import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao;
  12. import thyyxxk.webserver.entity.ResultVo;
  13. import thyyxxk.webserver.entity.markmtfees.*;
  14. import thyyxxk.webserver.entity.medicalinsurance.outpatient.*;
  15. import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo;
  16. import thyyxxk.webserver.entity.medicalinsurance.setlinfo.FundDetail;
  17. import thyyxxk.webserver.utils.*;
  18. import java.math.BigDecimal;
  19. import java.math.RoundingMode;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * @description: 门诊医保交易
  26. * @author: DingJie
  27. * @create: 2021-05-28 16:11:19
  28. **/
  29. @Slf4j
  30. @Service
  31. public class SiMzService {
  32. private final SiMzDao dao;
  33. private final SiQueryDao queryDao;
  34. @Value("${hrg-api-url}")
  35. private String hrgApiUrl;
  36. @Value("${si-fee-url}")
  37. private String siFeeUrl;
  38. @Autowired
  39. public SiMzService(SiMzDao dao, SiQueryDao queryDao) {
  40. this.dao = dao;
  41. this.queryDao = queryDao;
  42. }
  43. public ResultVo<String> outpatientRegistration(MzPatientInfo p) {
  44. p.setStaffId(TokenUtil.getTokenUserId());
  45. RestTemplate restTemplate = new RestTemplate();
  46. return restTemplate.postForObject(siFeeUrl + "/mzFee/outpatientRegistration", p, ResultVo.class);
  47. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_REGISTRATION, p.getInsuplcAdmdvs());
  48. // Regstrtn regstrtn = dao.selectRegstrtn(p.getPatNo(), p.getTimes());
  49. // if (null == regstrtn) {
  50. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "mz_visit_table患者信息为空,请联系医生重开处方。");
  51. // }
  52. // regstrtn.setInsutype(p.getInsutype());
  53. // regstrtn.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  54. // regstrtn.setPsnType(p.getPsnType());
  55. // regstrtn.setIptOtpNo(p.getPatNo());
  56. // String ref = JSONObject.toJSONStringWithDateFormat(regstrtn, "yyyy-MM-dd HH:mm:ss");
  57. // input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  58. // JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_REGISTRATION);
  59. // log.info("【操作员:{}】,门诊挂号:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  60. // if (null == result) {
  61. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  62. // }
  63. // if (null == result.getInteger(RESULT_CODE)) {
  64. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  65. // }
  66. // if (result.getIntValue(RESULT_CODE) == 0) {
  67. // JSONObject output = result.getJSONObject(OUTPUT).getJSONObject("data");
  68. // p.setMdtrtId(output.getString("mdtrt_id"));
  69. // p.setVisitDate(regstrtn.getBegntime());
  70. // dao.afterRegistrtn(p);
  71. // return ResultVoUtil.success("挂号成功。");
  72. // }
  73. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  74. }
  75. public ResultVo<String> revokeOutpatientRegistration(MzPatientInfo p) {
  76. p.setStaffId(TokenUtil.getTokenUserId());
  77. RestTemplate restTemplate = new RestTemplate();
  78. return restTemplate.postForObject(siFeeUrl + "/mzFee/revokeOutpatientRegistration", p, ResultVo.class);
  79. // if (null == p.getTimes()) {
  80. // p.setTimes(dao.selectMaxTimes(p.getPatNo()));
  81. // }
  82. // SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes());
  83. // if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  84. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保挂号信息。");
  85. // }
  86. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_REGISTRATION, siPatInfo.getInsuplcAdmdvs());
  87. // JSONObject data = new JSONObject();
  88. // data.put("psn_no", siPatInfo.getPsnNo());
  89. // data.put("mdtrt_id", siPatInfo.getMdtrtId());
  90. // data.put("ipt_otp_no", p.getPatNo());
  91. // input.getJSONObject("input").put("data", data);
  92. // JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_REGISTRATION);
  93. // log.info("【操作员:{}】,取消门诊挂号:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  94. // if (null == result) {
  95. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  96. // }
  97. // if (null == result.getInteger(RESULT_CODE)) {
  98. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  99. // }
  100. // if (result.getIntValue(RESULT_CODE) == 0) {
  101. // queryDao.clearMdtrtIdForMz(p.getPatNo(), p.getTimes(), null);
  102. // return ResultVoUtil.success("取消门诊挂号成功。");
  103. // }
  104. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  105. }
  106. public ResultVo<List<Map<String, Object>>> getMzReceipts(MzPatientInfo p) {
  107. String patNo = p.getPatNo();
  108. if (null == p.getTimes()) {
  109. p.setTimes(dao.selectMaxTimes(patNo));
  110. }
  111. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(patNo, p.getTimes());
  112. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  113. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo + "】未找到此患者的医保挂号信息,请核实。");
  114. }
  115. JSONObject queryMzChargeListParam = new JSONObject();
  116. queryMzChargeListParam.put("patCardType", 21);
  117. queryMzChargeListParam.put("patCardNo", patNo);
  118. queryMzChargeListParam.put("hisOrdNum", "");
  119. RestTemplate template = new RestTemplate();
  120. Map<String, Object> mzChargeListMap = template.postForObject(hrgApiUrl + "/getMzChargeDetailForUnPaid", queryMzChargeListParam, Map.class);
  121. if (null == mzChargeListMap) {
  122. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  123. }
  124. if (0 != (int) mzChargeListMap.get("resultCode")) {
  125. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, mzChargeListMap.get("resultMessage").toString());
  126. }
  127. List<Map<String, Object>> finalResult = new ArrayList<>();
  128. List<Map<String, String>> mzChargeList = FilterUtil.cast(mzChargeListMap.get("data"));
  129. for (Map<String, String> item : mzChargeList) {
  130. String hisOrdNum = item.get("hisOrdNum");
  131. if (null != hisOrdNum) {
  132. String[] hisOrdNumParts = hisOrdNum.split("_");
  133. int tempTimes = Integer.parseInt(hisOrdNumParts[1]);
  134. MzVisit mzVisit = dao.selectMzVisit(patNo, tempTimes);
  135. if (null == mzVisit) {
  136. continue;
  137. }
  138. Map<String, Object> childResult = new HashMap<>(Capacity.FIVE);
  139. childResult.put("times", tempTimes);
  140. childResult.put("mzPatient", siPatInfo);
  141. childResult.put("mzVisit", mzVisit);
  142. JSONObject queryMzChargeDetailParam = new JSONObject();
  143. queryMzChargeDetailParam.put("patientId", patNo);
  144. queryMzChargeDetailParam.put("times", tempTimes);
  145. queryMzChargeDetailParam.put("receiptNo", hisOrdNumParts[2]);
  146. mzVisit.setReceiptNo(Integer.parseInt(hisOrdNumParts[2]));
  147. Map<String, Object> mzChargeDetailMap = template.postForObject(hrgApiUrl + "/unPaidToFullChargeDetail",
  148. queryMzChargeDetailParam, Map.class);
  149. if (null != mzChargeDetailMap && 0 == (int) mzChargeDetailMap.get("resultCode")) {
  150. List<Map<String, Object>> mzChargeDetailList = FilterUtil.cast(mzChargeDetailMap.get("data"));
  151. mzChargeDetailList.removeIf(detail -> "TC".equals(detail.get("billItemCode")) ||
  152. !"5".equals(detail.get("payMark")) || "BILL99".equals(detail.get("chargeItemCode")) ||
  153. "四舍五入".equals(detail.get("tcName")));
  154. if (mzChargeDetailList.isEmpty()) {
  155. continue;
  156. }
  157. Map<Integer, List<MzReceipt>> orderReceiptsMap = new HashMap<>(Capacity.DEFAULT);
  158. String doctorName = dao.selectDoctorName(mzChargeDetailList.get(0).get("doctorCode").toString());
  159. mzChargeDetailList.forEach(detail -> {
  160. MzReceipt receipt = fillMzReceipt(detail);
  161. receipt.setPatientId(patNo);
  162. receipt.setTimes(tempTimes);
  163. receipt.setDoctorName(doctorName);
  164. if (!orderReceiptsMap.containsKey(receipt.getOrderNo())) {
  165. List<MzReceipt> list = new ArrayList<>();
  166. list.add(receipt);
  167. orderReceiptsMap.put(receipt.getOrderNo(), list);
  168. } else {
  169. orderReceiptsMap.get(receipt.getOrderNo()).add(receipt);
  170. }
  171. });
  172. List<OrderNo> orderNos = getOrderNos(patNo, tempTimes, mzVisit.getReceiptNo(), orderReceiptsMap);
  173. childResult.put("orderNos", orderNos);
  174. childResult.put("mzReceipts", orderReceiptsMap);
  175. finalResult.add(childResult);
  176. }
  177. }
  178. }
  179. return ResultVoUtil.success(finalResult);
  180. }
  181. public ResultVo<List<MzDepositFile>> getHistoryMzReceipts(String patNo) {
  182. List<MzDepositFile> mzChargeList = dao.selectMzDepositFiles(patNo);
  183. if (null == mzChargeList || mzChargeList.isEmpty()) {
  184. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到历史处方!");
  185. }
  186. return ResultVoUtil.success(mzChargeList);
  187. }
  188. public ResultVo<List<MzReceipt>> getHistoryReceiptDetail(MzDepositFile mzDepositFile) {
  189. List<MzReceipt> mzReceipts = dao.selectMzCharge(mzDepositFile.getPatNo(),
  190. mzDepositFile.getTimes(), mzDepositFile.getReceiptNo());
  191. mzReceipts.forEach(itm -> itm.setChecked(true));
  192. return ResultVoUtil.success(mzReceipts);
  193. }
  194. private MzReceipt fillMzReceipt(Map<String, Object> detail) {
  195. MzReceipt receipt = new MzReceipt();
  196. receipt.setChecked(true);
  197. receipt.setReceiptNo((int) detail.get("receiptNo"));
  198. receipt.setOrderNo((int) detail.get("orderNo"));
  199. receipt.setItemNo((int) detail.get("itemNo"));
  200. receipt.setDrugName(detail.get("tcName").toString());
  201. receipt.setChargeItemCode(detail.get("chargeItemCode").toString());
  202. receipt.setPriceTime(DateUtil.formatPriceTime(detail.get("priceTime").toString()));
  203. receipt.setUnitPrice(new BigDecimal(detail.get("unitPrice").toString()).setScale(4, RoundingMode.HALF_UP));
  204. receipt.setQuantity((double) detail.get("quantity"));
  205. receipt.setDrugWin((int) detail.get("drugWin"));
  206. receipt.setDoctorCode(detail.get("doctorCode").toString());
  207. receipt.setSerialNo(detail.get("serialNo").toString());
  208. receipt.setGroupNo(detail.get("groupNo").toString());
  209. receipt.setBillItemCode(detail.get("billItemCode").toString());
  210. receipt.setChargeBillCode(detail.get("chargeBillCode").toString());
  211. if (null != detail.get("instructionText")) {
  212. receipt.setInstructionText(detail.get("instructionText").toString());
  213. }
  214. if (null != detail.get("specification")) {
  215. receipt.setSpecification(detail.get("specification").toString());
  216. }
  217. if (null != detail.get("frequency")) {
  218. receipt.setFrequency(detail.get("frequency").toString());
  219. }
  220. if (null != detail.get("drugQuan")) {
  221. receipt.setDrugQuan((Double) detail.get("drugQuan"));
  222. }
  223. if (null != detail.get("orderDays")) {
  224. receipt.setOrderDays((Integer) detail.get("orderDays"));
  225. }
  226. // groupNo:00-项目;其他-药品
  227. if ("00".equals(receipt.getGroupNo())) {
  228. receipt.setDrugUnit(dao.selectXmChargeUnit(receipt.getChargeItemCode()));
  229. } else {
  230. if (null != detail.get("serial")) {
  231. receipt.setSerial(detail.get("serial").toString());
  232. receipt.setSpecification(dao.selectSpecification(receipt.getChargeItemCode(), receipt.getSerial()));
  233. }
  234. if (null != detail.get("supplyCode")) {
  235. receipt.setSupplyCode(dao.selectSupplyName(detail.get("supplyCode").toString()));
  236. }
  237. if (null != detail.get("drugUnit")) {
  238. receipt.setDrugUnit(dao.selectDrugUnit(detail.get("drugUnit").toString()));
  239. }
  240. }
  241. return receipt;
  242. }
  243. private List<OrderNo> getOrderNos(String patientId, int times, int receiptNo, Map<Integer, List<MzReceipt>> orderReceiptsMap) {
  244. List<OrderNo> orderNos = new ArrayList<>();
  245. for (Map.Entry<Integer, List<MzReceipt>> entry : orderReceiptsMap.entrySet()) {
  246. OrderNo orderNo = new OrderNo();
  247. orderNo.setPatientId(patientId);
  248. orderNo.setTimes(times);
  249. orderNo.setReceiptNo(entry.getValue().get(0).getReceiptNo());
  250. orderNo.setOrderNo(entry.getKey());
  251. BigDecimal total = new BigDecimal("0.00");
  252. for (MzReceipt receipt : entry.getValue()) {
  253. total = total.add(receipt.getChargeFee());
  254. }
  255. orderNo.setTotalFee(total);
  256. int count = dao.selectFeeCount(patientId, times, receiptNo, entry.getKey());
  257. orderNo.setStatus(count > 0);
  258. orderNos.add(orderNo);
  259. }
  260. return orderNos;
  261. }
  262. public ResultVo<String> insertSiMzFees(List<MzReceipt> receipts) {
  263. MzReceipt receipt = receipts.get(0);
  264. SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(receipt.getPatientId(), receipt.getTimes());
  265. if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  266. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + receipt.getPatientId() +
  267. "】未找到此患者的医保挂号信息,请核实。");
  268. }
  269. int count = dao.selectFeeCount(receipt.getPatientId(), receipt.getTimes(),
  270. receipt.getReceiptNo(), receipt.getOrderNo());
  271. if (count > 0) {
  272. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该处方已生成过门特费用,请勿重复操作。");
  273. }
  274. dao.insertMzChargeYb(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(),
  275. receipt.getOrderNo(), siPatInfo.getInsutype(), siPatInfo.getMedType());
  276. receipts.forEach(item -> {
  277. if (item.getChecked()) {
  278. dao.insertBatchedMtFeeInfo(item);
  279. }
  280. });
  281. return ResultVoUtil.success();
  282. }
  283. public ResultVo<String> deleteMzReceipt(OrderNo param) {
  284. dao.deleteMzReceipt(param);
  285. return ResultVoUtil.success();
  286. }
  287. public ResultVo<String> deleteAllMzReceipts(MzPatientInfo p) {
  288. if (null == p.getTimes()) {
  289. p.setTimes(dao.selectMaxTimes(p.getPatNo()));
  290. }
  291. log.info("【操作员:{}】删除所有门特处方:门诊号:{},门诊次数:{}", TokenUtil.getTokenUserId(), p.getPatNo(), p.getTimes());
  292. dao.deleteAllReceipts(p.getPatNo(), p.getTimes());
  293. return ResultVoUtil.success("删除成功。");
  294. }
  295. // private ResultVo<String> uploadOutpatientInfo(SpcChrDiseAcct p, SiPatInfo siPatInfo) {
  296. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_INFO, siPatInfo.getInsuplcAdmdvs());
  297. // JSONObject mdtrtinfo = new JSONObject();
  298. // Diseinfo diag = dao.selectDiseinfo(p.getPatNo(), p.getTimes());
  299. // if (StringUtil.notBlank(p.getOpspDiseCode())) {
  300. // diag.setDiagCode(p.getOpspDiseCode());
  301. // diag.setDiagName(p.getOpspDiseName());
  302. // }
  303. // if (StringUtil.isBlank(diag.getDiagCode())) {
  304. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的门诊诊断为空,请联系医生填写!");
  305. // }
  306. // dao.updatePatDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes(), diag.getDiagCode(), diag.getDiagName());
  307. // mdtrtinfo.put("mdtrt_id", siPatInfo.getMdtrtId());
  308. // mdtrtinfo.put("psn_no", siPatInfo.getPsnNo());
  309. // mdtrtinfo.put("med_type", siPatInfo.getMedType());
  310. // mdtrtinfo.put("begntime", DateUtil.formatDatetime(siPatInfo.getVisitDatetime()));
  311. // mdtrtinfo.put("main_cond_dscr", p.getOpspDiseName());
  312. // mdtrtinfo.put("dise_codg", p.getOpspDiseCode());
  313. // mdtrtinfo.put("dise_name", p.getOpspDiseName());
  314. // mdtrtinfo.put("birctrl_type", "");
  315. // mdtrtinfo.put("birctrl_matn_date", "");
  316. // List<Diseinfo> diseinfo = new ArrayList<>();
  317. // diseinfo.add(diag);
  318. // String ref = JSONObject.toJSONString(diseinfo);
  319. // input.getJSONObject("input").put("mdtrtinfo", mdtrtinfo);
  320. // input.getJSONObject("input").put("diseinfo", JSONArray.parse(ref));
  321. // JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_OUTPATIENT_INFO);
  322. // log.info("【操作员:{}】门诊就诊信息上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  323. // return SiUtil.makeReturnWithoutOutput(result, "门诊就诊信息上传成功。");
  324. // }
  325. public ResultVo<SiPatInfo> uploadOutpatientFeeDetails(SpcChrDiseAcct p) {
  326. p.setStaffId(TokenUtil.getTokenUserId());
  327. RestTemplate restTemplate = new RestTemplate();
  328. return restTemplate.postForObject(siFeeUrl + "/mzFee/uploadOutpatientFeeDetails", p, ResultVo.class);
  329. // String patNo = p.getPatNo();
  330. // if (null == p.getTimes()) {
  331. // p.setTimes(dao.selectMaxTimes(patNo));
  332. // }
  333. // SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(patNo, p.getTimes());
  334. // if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  335. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo +
  336. // "】未找到此患者的医保挂号信息,请核实。");
  337. // }
  338. // ResultVo<String> uplRes = uploadOutpatientInfo(p, siPatInfo);
  339. // if (null != uplRes && uplRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
  340. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, uplRes.getMessage());
  341. // }
  342. // List<FeeDetail> feeDetails = dao.selectOutpatientFees(patNo, p.getTimes());
  343. // if (null == feeDetails || feeDetails.isEmpty()) {
  344. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有需要上传的费用。");
  345. // }
  346. // String batchNo = patNo + "_" + p.getTimes();
  347. // feeDetails.forEach(item -> {
  348. // item.setMdtrtId(siPatInfo.getMdtrtId());
  349. // item.setPsnNo(siPatInfo.getPsnNo());
  350. // item.setChrgBchno(batchNo);
  351. // item.setRxCircFlag(YesOrNo.NO.getCodeStr());
  352. // item.setHospApprFlag(YesOrNo.YES.getCodeStr());
  353. // });
  354. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs());
  355. // String ref = JSONArray.toJSONString(feeDetails);
  356. // JSONArray feedetail = JSONArray.parseArray(ref);
  357. // input.getJSONObject("input").put("feedetail", feedetail);
  358. // JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS);
  359. // log.info("【操作员:{}】门诊费用明细信息上传:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
  360. // if (null == result) {
  361. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  362. // }
  363. // if (null == result.getInteger(RESULT_CODE)) {
  364. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  365. // }
  366. // if (result.getIntValue(RESULT_CODE) == 0) {
  367. // JSONArray feeRes = result.getJSONObject(OUTPUT).getJSONArray("result");
  368. // double fulamtOwnpayAmt = 0d;
  369. // double overlmtAmt = 0d;
  370. // double preselfpayAmt = 0d;
  371. // double inscpScpAmt = 0d;
  372. // for (int i = 0; i < feeRes.size(); i++) {
  373. // JSONObject fee = feeRes.getJSONObject(i);
  374. // fulamtOwnpayAmt += fee.getDoubleValue("fulamt_ownpay_amt");
  375. // overlmtAmt += fee.getDoubleValue("overlmt_amt");
  376. // preselfpayAmt += fee.getDoubleValue("preselfpay_amt");
  377. // inscpScpAmt += fee.getDoubleValue("inscp_scp_amt");
  378. //
  379. // String detlSn = fee.getString("feedetl_sn");
  380. // String chrgLv = fee.getString("chrgitm_lv");
  381. // String chrgType = fee.getString("med_chrgitm_type");
  382. // String[] sns = detlSn.split("_");
  383. // int times = Integer.parseInt(sns[1]);
  384. // int recNo = Integer.parseInt(sns[2]);
  385. // int odrNo = Integer.parseInt(sns[3]);
  386. // int itmNo = Integer.parseInt(sns[4]);
  387. // dao.afterUploadFees(patNo, times, recNo, odrNo, itmNo, chrgLv, chrgType);
  388. // }
  389. // siPatInfo.setFulamtOwnpayAmt(fulamtOwnpayAmt);
  390. // siPatInfo.setOverlmtAmt(overlmtAmt);
  391. // siPatInfo.setPreselfpayAmt(preselfpayAmt);
  392. // siPatInfo.setInscpScpAmt(inscpScpAmt);
  393. // dao.updateSortOfAmt(siPatInfo);
  394. // return ResultVoUtil.success(siPatInfo);
  395. // }
  396. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  397. }
  398. public ResultVo<String> revokeOutpatientFeeDetails(MzPatientInfo p) {
  399. p.setStaffId(TokenUtil.getTokenUserId());
  400. RestTemplate restTemplate = new RestTemplate();
  401. return restTemplate.postForObject(siFeeUrl + "/mzFee/revokeOutpatientFeeDetails", p, ResultVo.class);
  402. // if (null == p.getTimes()) {
  403. // p.setTimes(dao.selectMaxTimes(p.getPatNo()));
  404. // }
  405. // SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes());
  406. // log.info("patNo: {}, times: {}, sipatinfo: {}", p.getPatNo(), p.getTimes(), siPatInfo);
  407. // if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
  408. // return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的医保挂号信息!");
  409. // }
  410. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs());
  411. // JSONObject data = new JSONObject();
  412. // data.put("mdtrt_id", siPatInfo.getMdtrtId());
  413. // data.put("psn_no", siPatInfo.getPsnNo());
  414. // data.put("chrg_bchno", "0000");
  415. // input.getJSONObject("input").put("data", data);
  416. // JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS);
  417. // log.info("【操作员:{}】门诊费用明细信息撤销,参数:{},结果:{}", TokenUtil.getTokenUserId(), input, result);
  418. // if (null == result) {
  419. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  420. // }
  421. // if (null == result.getInteger(RESULT_CODE)) {
  422. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  423. // }
  424. // if (result.getIntValue(RESULT_CODE) == 0) {
  425. // dao.afterRevokeFees(p.getPatNo(), p.getTimes());
  426. // return ResultVoUtil.success("门诊费用明细信息撤销成功。");
  427. // }
  428. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  429. }
  430. public ResultVo<FundDetail> outpatientPreSettlement(MzPatientInfo p) {
  431. if (null == p.getStaffId()) {
  432. p.setStaffId(TokenUtil.getTokenUserId());
  433. }
  434. RestTemplate restTemplate = new RestTemplate();
  435. return restTemplate.postForObject(siFeeUrl + "/mzFee/outpatientPreSettlement", p, ResultVo.class);
  436. // if (null == p.getTimes()) {
  437. // p.setTimes(dao.selectMaxTimes(p.getPatNo()));
  438. // }
  439. // ResultVo<FundDetail> fundDetail1 = getFundDetailResultVo(p);
  440. // if (fundDetail1 != null) return fundDetail1;
  441. // PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getPatNo(), p.getTimes());
  442. // preSetlmt.setMedfeeSumamt(preSetlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP));
  443. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_PRE_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
  444. // preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  445. // preSetlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  446. // preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
  447. // preSetlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes());
  448. // String ref = JSONObject.toJSONString(preSetlmt);
  449. // input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  450. // JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_PRE_SETTLEMENT);
  451. // log.info("【操作员:{}】门诊预结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  452. // if (null == result) {
  453. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  454. // }
  455. // if (null == result.getInteger(RESULT_CODE)) {
  456. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  457. // }
  458. // if (result.getIntValue(RESULT_CODE) == 0) {
  459. // int mtPartCount = dao.selectMtPartCount(p.getPatNo(), p.getTimes());
  460. // if (mtPartCount == 0) {
  461. // CssybApplyInfo applyInfo = new CssybApplyInfo();
  462. // applyInfo.setPatientId(p.getPatNo());
  463. // applyInfo.setTimes(p.getTimes());
  464. // applyInfo.setHicNo(preSetlmt.getPsnNo());
  465. // applyInfo.setBizType(preSetlmt.getMedType());
  466. // applyInfo.setIcdCode("");
  467. // applyInfo.setIcdName("");
  468. // applyInfo.setMzSerialNo(preSetlmt.getMdtrtId());
  469. // dao.insertMtPartInfo(applyInfo);
  470. // }
  471. // JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  472. // FundDetail fundDetail = new FundDetail();
  473. // fundDetail.setTotalCost(setlinfo.getString("medfee_sumamt"));
  474. // fundDetail.setFundPay(setlinfo.getString("fund_pay_sumamt"));
  475. // fundDetail.setCashPay(setlinfo.getString("psn_cash_pay"));
  476. // fundDetail.setAcctPay(setlinfo.getString("acct_pay"));
  477. // fundDetail.setSelfPay(setlinfo.getString("psn_part_amt"));
  478. // return ResultVoUtil.success(fundDetail);
  479. // }
  480. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  481. }
  482. // private ResultVo<FundDetail> getFundDetailResultVo(MzPatientInfo p) {
  483. // SiSetlinfo sisetl = dao.selectSettledInfo(p.getPatNo(), p.getTimes());
  484. // if (null != sisetl && null != sisetl.getSetlId()) {
  485. // FundDetail fundDetail = new FundDetail();
  486. // fundDetail.setTotalCost(String.valueOf(sisetl.getMedfeeSumamt()));
  487. // fundDetail.setFundPay(String.valueOf(sisetl.getFundPaySumamt()));
  488. // fundDetail.setCashPay(String.valueOf(sisetl.getPsnCashPay()));
  489. // fundDetail.setAcctPay(String.valueOf(sisetl.getAcctPay()));
  490. // fundDetail.setSelfPay(String.valueOf(sisetl.getPsnPartAmt()));
  491. // return ResultVoUtil.success(fundDetail);
  492. // }
  493. // if (null == p.getStaffId()) {
  494. // p.setStaffId(TokenUtil.getTokenUserId());
  495. // }
  496. // return null;
  497. // }
  498. public ResultVo<FundDetail> outpatientSettlement(MzPatientInfo p) {
  499. if (null == p.getStaffId()) {
  500. p.setStaffId(TokenUtil.getTokenUserId());
  501. }
  502. RestTemplate restTemplate = new RestTemplate();
  503. return restTemplate.postForObject(siFeeUrl + "/mzFee/outpatientSettlement", p, ResultVo.class);
  504. // ResultVo<FundDetail> fundDetail1 = getFundDetailResultVo(p);
  505. // if (fundDetail1 != null) return fundDetail1;
  506. // Setlmt setlmt = dao.selectSetlmt(p.getPatNo(), p.getTimes());
  507. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_SETTLEMENT, setlmt.getInsuplcAdmdvs());
  508. // setlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
  509. // setlmt.setMedfeeSumamt(setlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP));
  510. // setlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode());
  511. // setlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes());
  512. // setlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
  513. // setlmt.setInvono(SnowFlakeId.instance().nextId());
  514. // String ref = JSONObject.toJSONString(setlmt);
  515. // input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
  516. // JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_SETTLEMENT);
  517. // log.info("【操作员:{}】门诊结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  518. // if (null == result) {
  519. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "与医保中心的连接出现网络异常!");
  520. // }
  521. // if (null == result.getInteger(RESULT_CODE)) {
  522. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  523. // }
  524. // if (result.getIntValue(RESULT_CODE) == 0) {
  525. // JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
  526. // SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
  527. // setlEntity.setPatNo(p.getPatNo());
  528. // setlEntity.setTimes(p.getTimes());
  529. // setlEntity.setLedgerSn(0);
  530. // setlEntity.setStaffId(p.getStaffId());
  531. // setlEntity.setRevoked(YesOrNo.NO.getCode());
  532. // setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
  533. // setlinfoDao.insert(setlEntity);
  534. // setlinfoDao.updateSiZyInfoSetlId(p.getPatNo(), p.getTimes(), 0, setlEntity.getSetlId(),
  535. // setlEntity.getMedinsSetlId(), input.getString("msgid"));
  536. // JSONArray setldetail = result.getJSONObject(OUTPUT).getJSONArray("setldetail");
  537. // for (int i = 0; i < setldetail.size(); i++) {
  538. // SiSetldetail setldetailEntity = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class);
  539. // setldetailEntity.setPatNo(p.getPatNo());
  540. // setldetailEntity.setTimes(p.getTimes());
  541. // setldetailEntity.setLedgerSn(0);
  542. // setldetailDao.insert(setldetailEntity);
  543. // }
  544. // FundDetail fundDetail = new FundDetail();
  545. // fundDetail.setTotalCost(String.valueOf(setlEntity.getMedfeeSumamt()));
  546. // fundDetail.setFundPay(String.valueOf(setlEntity.getFundPaySumamt()));
  547. // fundDetail.setCashPay(String.valueOf(setlEntity.getPsnCashPay()));
  548. // fundDetail.setAcctPay(String.valueOf(setlEntity.getAcctPay()));
  549. // fundDetail.setSelfPay(String.valueOf(setlEntity.getPsnPartAmt()));
  550. // return ResultVoUtil.success(fundDetail);
  551. // }
  552. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  553. }
  554. public ResultVo<String> revokeOutpatientSettlement(MzPatientInfo p) {
  555. if (null == p.getStaffId()) {
  556. p.setStaffId(TokenUtil.getTokenUserId());
  557. }
  558. RestTemplate restTemplate = new RestTemplate();
  559. return restTemplate.postForObject(siFeeUrl + "/mzFee/revokeOutpatientSettlement", p, ResultVo.class);
  560. // if (null == p.getTimes()) {
  561. // p.setTimes(dao.selectMaxTimes(p.getPatNo()));
  562. // }
  563. // if (null == p.getStaffId()) {
  564. // p.setStaffId(TokenUtil.getTokenUserId());
  565. // }
  566. // QueryWrapper<SiSetlinfo> wrapper = new QueryWrapper<>();
  567. // wrapper.eq("pat_no", p.getPatNo());
  568. // wrapper.eq("times", p.getTimes());
  569. // wrapper.eq("revoked", 0);
  570. // SiSetlinfo setlinfo = setlinfoDao.selectOne(wrapper);
  571. // if (null == setlinfo) {
  572. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的结算信息。");
  573. // }
  574. // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT,
  575. // dao.selectAdmdvs(setlinfo.getPatNo(), setlinfo.getTimes(), setlinfo.getLedgerSn()));
  576. // JSONObject data = new JSONObject();
  577. // data.put("setl_id", setlinfo.getSetlId());
  578. // data.put("mdtrt_id", setlinfo.getMdtrtId());
  579. // data.put("psn_no", setlinfo.getPsnNo());
  580. // input.getJSONObject("input").put("data", data);
  581. // JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_SETTLEMENT);
  582. // log.info("【操作员:{}】门诊结算撤销:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
  583. // if (null == result) {
  584. // return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  585. // }
  586. // if (null == result.getInteger(RESULT_CODE)) {
  587. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  588. // }
  589. // if (result.getIntValue(RESULT_CODE) == 0) {
  590. // dao.deleteSetlInfo(p.getPatNo(), p.getTimes());
  591. // dao.deleteSetlDetail(p.getPatNo(), p.getTimes());
  592. // dao.updateRvkSetlMsgid(p.getPatNo(), p.getTimes(), input.getString("msgid"));
  593. // return ResultVoUtil.success("门诊结算撤销成功。");
  594. // }
  595. // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  596. }
  597. }