123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- package thyyxxk.wxservice_server.service;
- import lombok.extern.slf4j.Slf4j;
- import org.dom4j.Document;
- import org.dom4j.DocumentException;
- import org.dom4j.DocumentHelper;
- import org.dom4j.Element;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.web.client.RestTemplate;
- import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
- import thyyxxk.wxservice_server.dao.InspectionsDao;
- import thyyxxk.wxservice_server.entity.ResultVo;
- import thyyxxk.wxservice_server.entity.hrgresponse.HrgCommonResponse;
- import thyyxxk.wxservice_server.entity.inspections.CheckExamParam;
- import thyyxxk.wxservice_server.entity.inspections.ExamIndexResult;
- import thyyxxk.wxservice_server.entity.inspections.HshjPatient;
- import thyyxxk.wxservice_server.entity.inspections.QueryReportDetail;
- import thyyxxk.wxservice_server.entity.inspections.detail.*;
- import thyyxxk.wxservice_server.utils.*;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * @author light
- */
- @Slf4j
- @Service
- public class InspectionsService {
- private final InspectionsDao dao;
- private final SoapInvokeService invokeService;
- @Value("${hrgApiUrl}")
- private String hrgApiUrl;
- @Autowired
- public InspectionsService(InspectionsDao dao, SoapInvokeService invokeService) {
- this.dao = dao;
- this.invokeService = invokeService;
- }
- public ResultVo<List<ExamIndexResult>> getExamIndex(CheckExamParam param) {
- String sendHead0 = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + param.getPatientId() + "</PTNT_NO>";
- String sendHead1 = null;
- String sendHead2 = null;
- String sendHead3 = null;
- RestTemplate restTemplate = new RestTemplate();
- String url = hrgApiUrl + "/getParentIdByPatientId?patientId=" + param.getPatientId();
- HrgCommonResponse response = restTemplate.getForObject(url, HrgCommonResponse.class);
- if (null != response && response.getCode() == 0) {
- List<Map<String, String>> list = CastUtil.cast(response.getData());
- sendHead1 = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + list.get(0).get("parentPatientId") + "</PTNT_NO>";
- }
- final String tjNo = dao.selectTjNo(param.getPatientId());
- final String inpatientNo = dao.selectInpatientNo(param.getPatientId());
- if (StringUtil.notBlank(tjNo)) {
- sendHead2 = "<message><PTNT_NO>" + tjNo + "</PTNT_NO>";
- }
- if (StringUtil.notBlank(inpatientNo)) {
- sendHead3 = "<message><PATIENT_TYPE>1</PATIENT_TYPE><PTNT_NO>" + inpatientNo + "</PTNT_NO>";
- }
- String sendEnd = "<START_TIME>" + param.getStart() + "</START_TIME><END_TIME>" + param.getEnd() + "</END_TIME></message>";
- String send0 = sendHead0 + sendEnd;
- String xml0 = invokeService.invokeRemoteMethod("GetLabReportIndex", send0);
- List<ExamIndexResult> list0 = invokeService.analyzeExamIndex(xml0);
- if (null != sendHead1) {
- String send1 = sendHead1 + sendEnd;
- String xml1 = invokeService.invokeRemoteMethod("GetLabReportIndex", send1);
- List<ExamIndexResult> list1 = invokeService.analyzeExamIndex(xml1);
- list0.addAll(list1);
- }
- if (null != sendHead2) {
- String send2 = sendHead2 + sendEnd;
- String xml2 = invokeService.invokeRemoteMethod("GetLabReportIndex", send2);
- List<ExamIndexResult> list2 = invokeService.analyzeExamIndex(xml2);
- list0.addAll(list2);
- }
- if (null != sendHead3) {
- String send3 = sendHead3 + sendEnd;
- String xml3 = invokeService.invokeRemoteMethod("GetLabReportIndex", send3);
- List<ExamIndexResult> list3 = invokeService.analyzeExamIndex(xml3);
- list0.addAll(list3);
- }
- return ResultVoUtil.success(list0);
- }
- public ResultVo<List<ExamIndexResult>> checkCovidExamIndexBySocialNo(String socialNo) {
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
- Date date = new Date();
- String start = df.format(date.getTime() - 15L * 24 * 60 * 60 * 1000);
- String end = df.format(date);
- String xmlEnd = "<START_TIME>" + start + "</START_TIME><END_TIME>" + end + "</END_TIME></message>";
- List<String> mzNos = dao.selectMzNos(socialNo);
- List<HshjPatient> hshjNos = null;
- if (null != mzNos && mzNos.size() > 0) {
- RestTemplate restTemplate = new RestTemplate();
- hshjNos = new ArrayList<>();
- for (String mzNo : mzNos) {
- String url = hrgApiUrl + "/getParentIdByPatientId?patientId=" + mzNo;
- HrgCommonResponse response = restTemplate.getForObject(url, HrgCommonResponse.class);
- if (null != response && response.getCode() == 0) {
- String patName = dao.selectPatName(mzNo);
- List<Map<String, String>> list = CastUtil.cast(response.getData());
- for (Map<String, String> item : list) {
- Date startDate = DateUtil.parseDatetime(start + " 00:00:00");
- Date itemDate = DateUtil.parseDatetime(item.get("createDate"));
- if (null != startDate && null != itemDate) {
- if (startDate.before(itemDate)) {
- hshjNos.add(new HshjPatient(patName, mzNo, item.get("parentPatientId")));
- }
- }
- }
- }
- }
- }
- List<ExamIndexResult> results = new ArrayList<>();
- if (null != mzNos && mzNos.size() > 0) {
- for (String mzNo : mzNos) {
- String mzHead = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + mzNo + "</PTNT_NO>";
- String xml = invokeService.invokeRemoteMethod("GetLabReportIndex", mzHead+xmlEnd);
- List<ExamIndexResult> list = invokeService.analyzeExamIndex(xml);
- for (ExamIndexResult index : list) {
- if (BooleanUtil.isCovidExam(index.getAPLY_CTNT())) {
- results.add(index);
- }
- }
- }
- }
- if (null != hshjNos && hshjNos.size() > 0) {
- for (HshjPatient hshj : hshjNos) {
- String hshjHead = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + hshj.getParentId() + "</PTNT_NO>";
- String xml = invokeService.invokeRemoteMethod("GetLabReportIndex", hshjHead+xmlEnd);
- List<ExamIndexResult> list = invokeService.analyzeExamIndex(xml);
- for (ExamIndexResult index : list) {
- if (BooleanUtil.isCovidExam(index.getAPLY_CTNT())) {
- index.setPTNT_ID(hshj.getPatientId());
- index.setIC_CARD(hshj.getPatientId());
- index.setPTNT_NAME(hshj.getName());
- results.add(index);
- }
- }
- }
- }
- return ResultVoUtil.success(results);
- }
- public ResultVo<ExamDetailResult> checkExamDetail(QueryReportDetail param) {
- if (StringUtil.isBlank(param.getOrderId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "报告ID不能为空!");
- }
- String send = "<message><ORDR_ID>" + param.getOrderId() + "</ORDR_ID></message>";
- String xml = invokeService.invokeRemoteMethod("GetLabReport", send);
- Element retEle = null;
- try {
- Document document = DocumentHelper.parseText(xml);
- Element root = document.getRootElement();
- retEle = root.element("return");
- } catch (DocumentException e) {
- e.printStackTrace();
- }
- if (retEle == null) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结果集为空!");
- }
- ExamDetailResult detail = new ExamDetailResult();
- String code = retEle.elementTextTrim("Code");
- if ("0".equals(code)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, retEle.elementTextTrim("ErrorMsg"));
- }
- Element reportListEle = retEle.element("Result").element("ReportList");
- ReportHeader header = new ReportHeader();
- detail.setReportHeader((ReportHeader) invokeService.reflect(header, reportListEle.element("ReportHeader")));
- List<ReportItem> reportItems = new ArrayList<>();
- List<Element> reportItemElements = reportListEle.elements("ReportItem");
- reportItemElements.forEach(reportItemElement -> {
- ReportItem reportItem = new ReportItem();
- invokeService.reflect(reportItem, reportItemElement);
- List<Element> bacteriaResultElements = reportItemElement.elements("BacteriaResult");
- if (bacteriaResultElements.size() > 0) {
- List<BacteriaResult> bacteriaResults = new ArrayList<>();
- bacteriaResultElements.forEach(bacterialResultElement -> {
- BacteriaResult bacteriaResult = new BacteriaResult();
- invokeService.reflect(bacteriaResult, bacterialResultElement);
- List<Element> antibioticResultElements = bacterialResultElement.elements("AntibioticResult");
- if (antibioticResultElements.size() > 0) {
- List<AntibioticResult> antibioticResults = new ArrayList<>();
- antibioticResultElements.forEach(antibioticResultElement -> {
- AntibioticResult antibioticResult = new AntibioticResult();
- antibioticResults.add((AntibioticResult) invokeService.reflect(antibioticResult, antibioticResultElement));
- });
- bacteriaResult.setAntibioticResults(antibioticResults);
- }
- if (StringUtil.notBlank(bacteriaResult.getBAC_ID())) {
- bacteriaResults.add(bacteriaResult);
- }
- });
- reportItem.setBacteriaResults(bacteriaResults);
- }
- if (StringUtil.notBlank(reportItem.getITM_VALUE()) || StringUtil.notBlank(reportItem.getITM_STR_VALUE())
- || reportItem.getBacteriaResults().size() > 0) {
- reportItems.add(reportItem);
- }
- });
- if (detail.getReportHeader().getPTNT_NAME().startsWith("核酸混检")) {
- HshjPatient patient = dao.selectPatientBriefInfo(param.getPatNo());
- detail.getReportHeader().setPTNT_NAME(patient.getName());
- detail.getReportHeader().setPTNT_SEX(patient.getGender());
- detail.getReportHeader().setPTNT_AGE(patient.getAge());
- }
- detail.setReportItems(reportItems);
- return ResultVoUtil.success(detail);
- }
- }
|