InspectionsService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. package thyyxxk.wxservice_server.service;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.dom4j.Document;
  4. import org.dom4j.DocumentException;
  5. import org.dom4j.DocumentHelper;
  6. import org.dom4j.Element;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.stereotype.Service;
  10. import org.springframework.web.client.RestTemplate;
  11. import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
  12. import thyyxxk.wxservice_server.dao.InspectionsDao;
  13. import thyyxxk.wxservice_server.entity.ResultVo;
  14. import thyyxxk.wxservice_server.entity.hrgresponse.HrgCommonResponse;
  15. import thyyxxk.wxservice_server.entity.inspections.CheckExamParam;
  16. import thyyxxk.wxservice_server.entity.inspections.ExamIndexResult;
  17. import thyyxxk.wxservice_server.entity.inspections.HshjPatient;
  18. import thyyxxk.wxservice_server.entity.inspections.QueryReportDetail;
  19. import thyyxxk.wxservice_server.entity.inspections.detail.*;
  20. import thyyxxk.wxservice_server.utils.*;
  21. import java.text.SimpleDateFormat;
  22. import java.util.*;
  23. /**
  24. * @author light
  25. */
  26. @Slf4j
  27. @Service
  28. public class InspectionsService {
  29. private final InspectionsDao dao;
  30. private final SoapInvokeService invokeService;
  31. @Value("${hrgApiUrl}")
  32. private String hrgApiUrl;
  33. @Autowired
  34. public InspectionsService(InspectionsDao dao, SoapInvokeService invokeService) {
  35. this.dao = dao;
  36. this.invokeService = invokeService;
  37. }
  38. public ResultVo<List<ExamIndexResult>> getExamIndex(CheckExamParam param) {
  39. String sendHead0 = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + param.getPatientId() + "</PTNT_NO>";
  40. String sendHead1 = null;
  41. String sendHead2 = null;
  42. String sendHead3 = null;
  43. RestTemplate restTemplate = new RestTemplate();
  44. String url = hrgApiUrl + "/getParentIdByPatientId?patientId=" + param.getPatientId();
  45. HrgCommonResponse response = restTemplate.getForObject(url, HrgCommonResponse.class);
  46. if (null != response && response.getCode() == 0) {
  47. List<Map<String, String>> list = CastUtil.cast(response.getData());
  48. sendHead1 = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + list.get(0).get("parentPatientId") + "</PTNT_NO>";
  49. }
  50. final String tjNo = dao.selectTjNo(param.getPatientId());
  51. final String inpatientNo = dao.selectInpatientNo(param.getPatientId());
  52. if (StringUtil.notBlank(tjNo)) {
  53. sendHead2 = "<message><PTNT_NO>" + tjNo + "</PTNT_NO>";
  54. }
  55. if (StringUtil.notBlank(inpatientNo)) {
  56. sendHead3 = "<message><PATIENT_TYPE>1</PATIENT_TYPE><PTNT_NO>" + inpatientNo + "</PTNT_NO>";
  57. }
  58. String sendEnd = "<START_TIME>" + param.getStart() + "</START_TIME><END_TIME>" + param.getEnd() + "</END_TIME></message>";
  59. String send0 = sendHead0 + sendEnd;
  60. String xml0 = invokeService.invokeRemoteMethod("GetLabReportIndex", send0);
  61. List<ExamIndexResult> list0 = invokeService.analyzeExamIndex(xml0);
  62. if (null != sendHead1) {
  63. String send1 = sendHead1 + sendEnd;
  64. String xml1 = invokeService.invokeRemoteMethod("GetLabReportIndex", send1);
  65. List<ExamIndexResult> list1 = invokeService.analyzeExamIndex(xml1);
  66. list0.addAll(list1);
  67. }
  68. if (null != sendHead2) {
  69. String send2 = sendHead2 + sendEnd;
  70. String xml2 = invokeService.invokeRemoteMethod("GetLabReportIndex", send2);
  71. List<ExamIndexResult> list2 = invokeService.analyzeExamIndex(xml2);
  72. list0.addAll(list2);
  73. }
  74. if (null != sendHead3) {
  75. String send3 = sendHead3 + sendEnd;
  76. String xml3 = invokeService.invokeRemoteMethod("GetLabReportIndex", send3);
  77. List<ExamIndexResult> list3 = invokeService.analyzeExamIndex(xml3);
  78. list0.addAll(list3);
  79. }
  80. return ResultVoUtil.success(list0);
  81. }
  82. public ResultVo<List<ExamIndexResult>> checkCovidExamIndexBySocialNo(String socialNo) {
  83. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  84. Date date = new Date();
  85. String start = df.format(date.getTime() - 15L * 24 * 60 * 60 * 1000);
  86. String end = df.format(date);
  87. String xmlEnd = "<START_TIME>" + start + "</START_TIME><END_TIME>" + end + "</END_TIME></message>";
  88. List<String> mzNos = dao.selectMzNos(socialNo);
  89. List<HshjPatient> hshjNos = null;
  90. if (null != mzNos && mzNos.size() > 0) {
  91. RestTemplate restTemplate = new RestTemplate();
  92. hshjNos = new ArrayList<>();
  93. for (String mzNo : mzNos) {
  94. String url = hrgApiUrl + "/getParentIdByPatientId?patientId=" + mzNo;
  95. HrgCommonResponse response = restTemplate.getForObject(url, HrgCommonResponse.class);
  96. if (null != response && response.getCode() == 0) {
  97. String patName = dao.selectPatName(mzNo);
  98. List<Map<String, String>> list = CastUtil.cast(response.getData());
  99. for (Map<String, String> item : list) {
  100. Date startDate = DateUtil.parseDatetime(start + " 00:00:00");
  101. Date itemDate = DateUtil.parseDatetime(item.get("createDate"));
  102. if (null != startDate && null != itemDate) {
  103. if (startDate.before(itemDate)) {
  104. hshjNos.add(new HshjPatient(patName, mzNo, item.get("parentPatientId")));
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. List<ExamIndexResult> results = new ArrayList<>();
  112. if (null != mzNos && mzNos.size() > 0) {
  113. for (String mzNo : mzNos) {
  114. String mzHead = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + mzNo + "</PTNT_NO>";
  115. String xml = invokeService.invokeRemoteMethod("GetLabReportIndex", mzHead+xmlEnd);
  116. List<ExamIndexResult> list = invokeService.analyzeExamIndex(xml);
  117. for (ExamIndexResult index : list) {
  118. if (BooleanUtil.isCovidExam(index.getAPLY_CTNT())) {
  119. results.add(index);
  120. }
  121. }
  122. }
  123. }
  124. if (null != hshjNos && hshjNos.size() > 0) {
  125. for (HshjPatient hshj : hshjNos) {
  126. String hshjHead = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + hshj.getParentId() + "</PTNT_NO>";
  127. String xml = invokeService.invokeRemoteMethod("GetLabReportIndex", hshjHead+xmlEnd);
  128. List<ExamIndexResult> list = invokeService.analyzeExamIndex(xml);
  129. for (ExamIndexResult index : list) {
  130. if (BooleanUtil.isCovidExam(index.getAPLY_CTNT())) {
  131. index.setPTNT_ID(hshj.getPatientId());
  132. index.setIC_CARD(hshj.getPatientId());
  133. index.setPTNT_NAME(hshj.getName());
  134. results.add(index);
  135. }
  136. }
  137. }
  138. }
  139. return ResultVoUtil.success(results);
  140. }
  141. public ResultVo<ExamDetailResult> checkExamDetail(QueryReportDetail param) {
  142. if (StringUtil.isBlank(param.getOrderId())) {
  143. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "报告ID不能为空!");
  144. }
  145. String send = "<message><ORDR_ID>" + param.getOrderId() + "</ORDR_ID></message>";
  146. String xml = invokeService.invokeRemoteMethod("GetLabReport", send);
  147. Element retEle = null;
  148. try {
  149. Document document = DocumentHelper.parseText(xml);
  150. Element root = document.getRootElement();
  151. retEle = root.element("return");
  152. } catch (DocumentException e) {
  153. e.printStackTrace();
  154. }
  155. if (retEle == null) {
  156. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结果集为空!");
  157. }
  158. ExamDetailResult detail = new ExamDetailResult();
  159. String code = retEle.elementTextTrim("Code");
  160. if ("0".equals(code)) {
  161. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, retEle.elementTextTrim("ErrorMsg"));
  162. }
  163. Element reportListEle = retEle.element("Result").element("ReportList");
  164. ReportHeader header = new ReportHeader();
  165. detail.setReportHeader((ReportHeader) invokeService.reflect(header, reportListEle.element("ReportHeader")));
  166. List<ReportItem> reportItems = new ArrayList<>();
  167. List<Element> reportItemElements = reportListEle.elements("ReportItem");
  168. reportItemElements.forEach(reportItemElement -> {
  169. ReportItem reportItem = new ReportItem();
  170. invokeService.reflect(reportItem, reportItemElement);
  171. List<Element> bacteriaResultElements = reportItemElement.elements("BacteriaResult");
  172. if (bacteriaResultElements.size() > 0) {
  173. List<BacteriaResult> bacteriaResults = new ArrayList<>();
  174. bacteriaResultElements.forEach(bacterialResultElement -> {
  175. BacteriaResult bacteriaResult = new BacteriaResult();
  176. invokeService.reflect(bacteriaResult, bacterialResultElement);
  177. List<Element> antibioticResultElements = bacterialResultElement.elements("AntibioticResult");
  178. if (antibioticResultElements.size() > 0) {
  179. List<AntibioticResult> antibioticResults = new ArrayList<>();
  180. antibioticResultElements.forEach(antibioticResultElement -> {
  181. AntibioticResult antibioticResult = new AntibioticResult();
  182. antibioticResults.add((AntibioticResult) invokeService.reflect(antibioticResult, antibioticResultElement));
  183. });
  184. bacteriaResult.setAntibioticResults(antibioticResults);
  185. }
  186. if (StringUtil.notBlank(bacteriaResult.getBAC_ID())) {
  187. bacteriaResults.add(bacteriaResult);
  188. }
  189. });
  190. reportItem.setBacteriaResults(bacteriaResults);
  191. }
  192. if (StringUtil.notBlank(reportItem.getITM_VALUE()) || StringUtil.notBlank(reportItem.getITM_STR_VALUE())
  193. || reportItem.getBacteriaResults().size() > 0) {
  194. reportItems.add(reportItem);
  195. }
  196. });
  197. if (detail.getReportHeader().getPTNT_NAME().startsWith("核酸混检")) {
  198. HshjPatient patient = dao.selectPatientBriefInfo(param.getPatNo());
  199. detail.getReportHeader().setPTNT_NAME(patient.getName());
  200. detail.getReportHeader().setPTNT_SEX(patient.getGender());
  201. detail.getReportHeader().setPTNT_AGE(patient.getAge());
  202. }
  203. detail.setReportItems(reportItems);
  204. return ResultVoUtil.success(detail);
  205. }
  206. }