MarkMtFeesService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. package thyyxxk.webserver.service.markmtfees;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.web.client.RestTemplate;
  7. import thyyxxk.webserver.config.exception.ExceptionEnum;
  8. import thyyxxk.webserver.constants.Capacity;
  9. import thyyxxk.webserver.constants.ResponceType;
  10. import thyyxxk.webserver.dao.his.markmtfees.MarkMtFeesDao;
  11. import thyyxxk.webserver.pojo.ResultVo;
  12. import thyyxxk.webserver.pojo.markmtfees.*;
  13. import thyyxxk.webserver.utils.*;
  14. import java.math.BigDecimal;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @author dj
  21. */
  22. @Slf4j
  23. @Service
  24. public class MarkMtFeesService {
  25. private final MarkMtFeesDao dao;
  26. @Autowired
  27. public MarkMtFeesService(MarkMtFeesDao dao) {
  28. this.dao = dao;
  29. }
  30. public ResultVo<Map<String, Object>> queryMtPersonInfo(QueryMtInfoParam param) {
  31. log.info("查询门特身份:{}", param);
  32. String patientId = param.getPatientId();
  33. if (StringUtil.isBlank(patientId)) {
  34. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请输入正确的门诊id号!");
  35. }
  36. patientId = patientId.trim();
  37. if (StringUtil.notBlank(param.getPhoneNo())) {
  38. dao.updatePhoneNo(patientId, param.getPhoneNo());
  39. }
  40. if (StringUtil.notBlank(param.getIdCard())) {
  41. dao.updateSocialNo(patientId, param.getIdCard());
  42. }
  43. Integer times = dao.selectMaxTimes(patientId);
  44. if (null == times || times == 0) {
  45. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到些患者的就诊信息,请检查!");
  46. }
  47. if (StringUtil.isBlank(param.getIdCard())) {
  48. param.setIdCard(dao.selectSocialNoByPatientId(patientId));
  49. }
  50. if (!IdCardUtil.isValidatedIdCard(param.getIdCard())) {
  51. return ResultVoUtil.fail(ExceptionEnum.SLIGHTLY_ERROR, "应医保局要求,门诊特殊病患者的身份证不能为空,请补充。");
  52. }
  53. if (StringUtil.isBlank(param.getPhoneNo())) {
  54. param.setPhoneNo(dao.selectPhoneNo(patientId));
  55. }
  56. if (StringUtil.isBlank(param.getPhoneNo())) {
  57. return ResultVoUtil.fail(ExceptionEnum.SLIGHTLY_ERROR, "应医保局要求,门诊特殊病患者的联系电话不能为空,请补充。");
  58. }
  59. Map<String, Object> data = new HashMap<>(Capacity.THREE);
  60. data.put("patientId", patientId);
  61. data.put("times", times);
  62. int mtCount;
  63. if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) {
  64. mtCount = dao.selectCountMtPartInfo(patientId, times);
  65. } else {
  66. mtCount = dao.selectCountMtPartInfoForSyb(patientId, times, param.getBizType());
  67. }
  68. if (mtCount > 0) {
  69. return ResultVoUtil.success(data);
  70. }
  71. param.setStaffId(TokenUtil.getTokenUserId());
  72. RestTemplate template = new RestTemplate();
  73. Object mapRet;
  74. if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) {
  75. param.setBizType("13");
  76. mapRet = template.postForObject(YbLinksUtil.normalLinks.get("hnsybMtInfo"), param, Object.class);
  77. } else {
  78. mapRet = template.postForObject(YbLinksUtil.normalLinks.get("cssybReadMzPatient"), param, Object.class);
  79. }
  80. if (null == mapRet) {
  81. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "服务器内部错误,查询门特身份信息失败。");
  82. }
  83. Map<String, Object> map = FilterUtil.cast(mapRet);
  84. if (ExceptionEnum.SUCCESS.getCode() != (int) map.get("code")) {
  85. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("message").toString());
  86. }
  87. if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) {
  88. Map<String, Object> hnsybRet = FilterUtil.cast(map.get("data"));
  89. List<Map<String, String>> spinfos = FilterUtil.cast(hnsybRet.get("spinfo"));
  90. Map<String, String> spinfo = spinfos.get(0);
  91. String icd = spinfo.get("icd");
  92. String serialApply = spinfo.get("serial_apply");
  93. spinfos = FilterUtil.cast(hnsybRet.get("personinfo"));
  94. String balance = spinfos.get(0).get("last_balance");
  95. dao.insertHnsybMtPartInfo(patientId, times, icd, balance, serialApply);
  96. return ResultVoUtil.success(data);
  97. }
  98. data.put("list", map.get("data"));
  99. return ResultVoUtil.success(data);
  100. }
  101. public ResultVo<String> confirmCssybMtApplyInfo(CssybApplyInfo param) {
  102. int mtCount = dao.selectCountMtPartInfoForSyb(param.getPatientId(), param.getTimes(), param.getBizType());
  103. if (mtCount > 0) {
  104. return ResultVoUtil.success();
  105. }
  106. dao.clearMtPartInfo(param.getPatientId(), param.getTimes());
  107. param.setMzSerialNo(SnowFlakeId.instance().nextId());
  108. dao.insertCssybMtPartInfo(param);
  109. return ResultVoUtil.success();
  110. }
  111. public ResultVo<Map<String, Object>> getMtReceipts(String patientId, Integer times) {
  112. Map<String, Object> map = new HashMap<>(Capacity.FOUR);
  113. List<MzPatient> mzPatients = dao.selectMzPatient(patientId, times);
  114. if (null == mzPatients || mzPatients.isEmpty()) {
  115. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patientId + ",就诊次数:" +
  116. times + "】未找到此患者的本次就诊信息,请核实。");
  117. }
  118. MzVisit mzVisit = dao.selectMzVisit(patientId, times);
  119. if (null == mzVisit) {
  120. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patientId + ",就诊次数:" +
  121. times + "】未找到此患者的本次就诊信息,请核实。");
  122. }
  123. map.put("mzPatient", mzPatients.get(0));
  124. map.put("mzVisit", mzVisit);
  125. List<MzReceipt> mzReceipts = dao.selectMzReceipts(patientId, times, mzVisit.getReceiptNo());
  126. mzReceipts.removeIf(item -> "TC".equals(item.getBillItemCode()) || item.getPayMark() != 5 || "BILL99".equals(item.getChargeItemCode()));
  127. Map<Integer, List<MzReceipt>> temp = new HashMap<>(Capacity.DEFAULT);
  128. mzReceipts.forEach(item -> {
  129. item.setChecked(true);
  130. if (!temp.containsKey(item.getOrderNo())) {
  131. List<MzReceipt> list = new ArrayList<>();
  132. list.add(item);
  133. temp.put(item.getOrderNo(), list);
  134. } else {
  135. temp.get(item.getOrderNo()).add(item);
  136. }
  137. });
  138. List<OrderNo> orderNos = new ArrayList<>();
  139. for (Map.Entry<Integer, List<MzReceipt>> entry : temp.entrySet()) {
  140. OrderNo orderNo = new OrderNo();
  141. orderNo.setPatientId(patientId);
  142. orderNo.setTimes(times);
  143. orderNo.setReceiptNo(mzVisit.getReceiptNo());
  144. orderNo.setOrderNo(entry.getKey());
  145. BigDecimal total = new BigDecimal("0.00");
  146. for (MzReceipt item : entry.getValue()) {
  147. total = total.add(item.getChargeFee());
  148. }
  149. orderNo.setTotalFee(total);
  150. int count = dao.selectFeeCount(patientId, times, mzVisit.getReceiptNo(), entry.getKey());
  151. orderNo.setStatus(count > 0);
  152. orderNos.add(orderNo);
  153. }
  154. map.put("orderNos", orderNos);
  155. map.put("mzReceipts", temp);
  156. return ResultVoUtil.success(map);
  157. }
  158. public ResultVo<String> insertMtFees(MarkMtFeeParam param) {
  159. if (param.getResponceType().equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
  160. param.setYbType("13");
  161. }
  162. MzReceipt receipt = param.getReceipts().get(0);
  163. int count = dao.selectFeeCount(receipt.getPatientId(), receipt.getTimes(),
  164. receipt.getReceiptNo(), receipt.getOrderNo());
  165. if (count > 0) {
  166. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该处方已生成过门特费用,请勿重复操作。");
  167. }
  168. dao.insertMzChargeYb(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(),
  169. receipt.getOrderNo(), param.getResponceType(), param.getYbType());
  170. param.getReceipts().forEach(item -> {
  171. if (item.getChecked()) {
  172. dao.insertBatchedMtFeeInfo(item);
  173. }
  174. });
  175. return ResultVoUtil.success();
  176. }
  177. public ResultVo<String> deleteMtFees(OrderNo param) {
  178. dao.deleteMtFees(param);
  179. return ResultVoUtil.success();
  180. }
  181. public ResultVo<Object> cssybMtPreCal(String patientId, Integer times) {
  182. JSONObject param = new JSONObject();
  183. param.put("patientId", patientId);
  184. param.put("times", times);
  185. param.put("staffId", TokenUtil.getTokenUserId());
  186. log.info("市门特试算:{}", param);
  187. RestTemplate template = new RestTemplate();
  188. Object mapRet = template.postForObject(YbLinksUtil.normalLinks.get("cssybMtPreCal"), param, Object.class);
  189. log.info("市门特试算结果:{}", mapRet);
  190. if (null == mapRet) {
  191. return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "服务器内部错误,门特费用试算失败。");
  192. }
  193. Map<String, Object> map = FilterUtil.cast(mapRet);
  194. if (ExceptionEnum.SUCCESS.getCode() != (int) map.get("code")) {
  195. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("message").toString());
  196. }
  197. return ResultVoUtil.success(map.get("data"));
  198. }
  199. public Map<String, Object> uploadMtFees(UploadMtFeeParam param) {
  200. log.info("上传省门特费用:{}", param);
  201. Map<String, Object> resultMap = new HashMap<>(Capacity.TWO);
  202. String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes());
  203. if (null == responceType) {
  204. resultMap.put("code", -1);
  205. resultMap.put("msg", "未查询到此人的门特身份记录。");
  206. return resultMap;
  207. }
  208. String urlHead = YbLinksUtil.normalLinks.get("mtBase");
  209. String urlEnd;
  210. if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
  211. urlEnd = ":2000/shengyb/mt/uploadFees";
  212. } else {
  213. urlEnd = ":1000/mzsyb/mzCalculate";
  214. }
  215. String url = urlHead + urlEnd;
  216. RestTemplate restTemplate = new RestTemplate();
  217. Object templateRet = restTemplate.postForObject(url, param, Object.class);
  218. log.info("上传省门特费用结果:{}", templateRet);
  219. return FilterUtil.cast(templateRet);
  220. }
  221. public Map<String, Object> retractMtFees(UploadMtFeeParam param) {
  222. log.info("撤销门特费用:{}", param);
  223. Map<String, Object> resultMap = new HashMap<>(Capacity.TWO);
  224. String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes());
  225. if (null == responceType) {
  226. resultMap.put("code", -1);
  227. resultMap.put("msg", "未查询到此人的门特身份记录。");
  228. return resultMap;
  229. }
  230. String urlHead = YbLinksUtil.normalLinks.get("mtBase");
  231. String urlEnd;
  232. if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
  233. urlEnd = ":2000/shengyb/mt/retractFees";
  234. } else {
  235. urlEnd = ":1000/mzsyb/mzCancelCalculate";
  236. }
  237. String url = urlHead + urlEnd;
  238. RestTemplate restTemplate = new RestTemplate();
  239. Object templateRet = restTemplate.postForObject(url, param, Object.class);
  240. return FilterUtil.cast(templateRet);
  241. }
  242. public Map<String, Object> calculateMtFees(UploadMtFeeParam param) {
  243. log.info("结算门特费用:{}", param);
  244. Map<String, Object> resultMap = new HashMap<>(Capacity.TWO);
  245. String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes());
  246. if (null == responceType) {
  247. resultMap.put("code", -1);
  248. resultMap.put("msg", "未查询到此人的门特身份记录。");
  249. return resultMap;
  250. }
  251. String urlHead = YbLinksUtil.normalLinks.get("mtBase");
  252. String urlEnd;
  253. if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
  254. urlEnd = ":2000/shengyb/mt/calculateCost";
  255. } else {
  256. urlEnd = ":1000/mzsyb/mzCalculate";
  257. }
  258. String url = urlHead + urlEnd;
  259. RestTemplate restTemplate = new RestTemplate();
  260. Object templateRet = restTemplate.postForObject(url, param, Object.class);
  261. log.info("结算门特费用结果:{}", templateRet);
  262. return FilterUtil.cast(templateRet);
  263. }
  264. }