|
@@ -0,0 +1,284 @@
|
|
|
+package com.wdklian.ncs.ms.ccey.service;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.wdklian.ncs.ms.ccey.config.CCEYConfig;
|
|
|
+import com.wdklian.ncs.ms.ccey.model.*;
|
|
|
+import com.wdklian.ncs.ms.common.entity.open.dos.DoctorAdviceDO;
|
|
|
+import com.wdklian.ncs.ms.common.entity.open.dos.PatientDO;
|
|
|
+import com.wdklian.ncs.ms.common.entity.system.dos.ShopDO;
|
|
|
+import com.wdklian.ncs.ms.common.enums.ShopTypeEnum;
|
|
|
+import com.wdklian.ncs.ms.feignclient.entrace.EntraceDoctorAdviceFeignClient;
|
|
|
+import com.wdklian.ncs.ms.feignclient.entrace.EntracePatientFeignClient;
|
|
|
+import com.wdklian.ncs.ms.feignclient.open.DoctorAdviceFeignClient;
|
|
|
+import com.wdklian.ncs.ms.feignclient.open.PatientFeignClient;
|
|
|
+import com.wdklian.ncs.ms.feignclient.system.CustomerFeignClient;
|
|
|
+import com.wdklian.ncs.ms.feignclient.system.ShopFeignClient;
|
|
|
+import com.wdklian.ncs.ms.framework.config.TaskSchedule;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.Trigger;
|
|
|
+import org.springframework.scheduling.support.CronTrigger;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import springfox.documentation.spring.web.json.Json;
|
|
|
+
|
|
|
+import javax.xml.bind.JAXBContext;
|
|
|
+import javax.xml.bind.JAXBException;
|
|
|
+import javax.xml.bind.Marshaller;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author z
|
|
|
+ * @title
|
|
|
+ * @projectName ncs-ms
|
|
|
+ * @date 2024/3/29 15:32
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CCEYMainDataQueryService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CCEYConfig cceyConfig;
|
|
|
+ @Autowired
|
|
|
+ private TaskSchedule taskSchedule; //任务调度器
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CCEYCustomerInfoService cceyCustomerInfoService;
|
|
|
+ @Autowired
|
|
|
+ private CCEYCustomerAdviceService cceyCustomerAdviceService;
|
|
|
+ @Autowired
|
|
|
+ private CCEYCustomerNursingService cceyCustomerNursingService;
|
|
|
+ @Autowired
|
|
|
+ private EntracePatientFeignClient entracePatientFeignClient;
|
|
|
+ @Autowired
|
|
|
+ private EntraceDoctorAdviceFeignClient entraceDoctorAdviceFeignClient;
|
|
|
+ @Autowired
|
|
|
+ private CustomerFeignClient customerFeignClient;
|
|
|
+ @Autowired
|
|
|
+ private DoctorAdviceFeignClient doctorAdviceFeignClient;
|
|
|
+ @Autowired
|
|
|
+ private ShopFeignClient shopFeignClient;
|
|
|
+
|
|
|
+ public void scheduleMainDataSyncTask() {
|
|
|
+ Runnable syncMainDataRunnable = () -> {
|
|
|
+ log.info("开始执行同步任务");
|
|
|
+ // 同步用户信息
|
|
|
+ try {
|
|
|
+ List<ShopDO> shops = this.shopFeignClient.listShopByType(ShopTypeEnum.PART.value()).getData();
|
|
|
+ if (shops.isEmpty()) {
|
|
|
+ log.info("未找到科室,任务结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ shops = shops.stream().filter(p -> p.getHisCode() != null && !p.getHisCode().equals("")).collect(Collectors.toList());
|
|
|
+ if (shops.isEmpty()) {
|
|
|
+ log.info("未找到带有 his_code 的科室,任务结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.syncMain(shops);
|
|
|
+
|
|
|
+ } catch (JAXBException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ new Thread(syncMainDataRunnable).start();
|
|
|
+ Trigger triggerPatient = triggerContext -> new CronTrigger(cceyConfig.getSyncPeriod()).nextExecutionTime(triggerContext);
|
|
|
+ this.taskSchedule.scheduleTask("SYNC_CCEY_MAIN_DATA", syncMainDataRunnable, triggerPatient);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void syncMain(List<ShopDO> shops) throws JAXBException {
|
|
|
+ List<PatientDO> patients = new ArrayList<>();
|
|
|
+ List<DoctorAdviceDO> advices = new ArrayList<>();
|
|
|
+ List<PatientDO> patientsByShop = new ArrayList<>();
|
|
|
+ List<DoctorAdviceDO> advicesByPatient = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ String jsonStr = "";
|
|
|
+ for (ShopDO shopDO : shops) {
|
|
|
+ log.info("目前同步科室的键值 ===================> " + shopDO.getHisCode());
|
|
|
+ patientsByShop = this.cceyCustomerInfoService.CCEYCustomerInfo(shopDO.getHisCode());
|
|
|
+ if (!patientsByShop.isEmpty()) {
|
|
|
+ patients.addAll(patientsByShop);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!patients.isEmpty()) {
|
|
|
+ try {
|
|
|
+ this.entracePatientFeignClient.syncPatientNoBack(patients);
|
|
|
+// jsonStr = mapper.writeValueAsString(patients);
|
|
|
+// log.info(jsonStr);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ log.info("同步患者数据");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.info("没有需要同步的患者数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PatientDO patientDO : patients) {
|
|
|
+ advicesByPatient = this.cceyCustomerAdviceService.CCEYCustomerAdvice(patientDO.getName(), patientDO.getPartKeyval(), patientDO.getKeyval());
|
|
|
+ if (!advicesByPatient.isEmpty()) {
|
|
|
+ advices.addAll(advicesByPatient);
|
|
|
+ }
|
|
|
+
|
|
|
+ advicesByPatient = this.cceyCustomerNursingService.CCEYCustomerNursing(patientDO.getName(), patientDO.getPartKeyval(), patientDO.getKeyval());
|
|
|
+ if (!advicesByPatient.isEmpty()) {
|
|
|
+ advices.addAll(advicesByPatient);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!advices.isEmpty()) {
|
|
|
+ try {
|
|
|
+ this.entraceDoctorAdviceFeignClient.syncDoctorAdviceNoBack(advices);
|
|
|
+// jsonStr = mapper.writeValueAsString(patients);
|
|
|
+// log.info(jsonStr);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ log.info("同步医嘱数据");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ log.info("没有需要同步医嘱数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) throws JAXBException {
|
|
|
+ String requestXML = "";
|
|
|
+ CCEYRequestBody requestBody = new CCEYRequestBody();
|
|
|
+ requestBody.setTranCode("CP0001");
|
|
|
+ requestBody.setStartTime("2022-08-11");
|
|
|
+ requestBody.setEndTime("2022-08-11");
|
|
|
+ requestBody.setBrzyid("1");
|
|
|
+ requestBody.setDqks("1");
|
|
|
+
|
|
|
+ JAXBContext jaxbContext = JAXBContext.newInstance(CCEYRequestBody.class);
|
|
|
+ Marshaller marshaller = jaxbContext.createMarshaller();
|
|
|
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
|
|
+ marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
|
|
+
|
|
|
+ StringWriter writer = new StringWriter();
|
|
|
+ marshaller.marshal(requestBody, writer);
|
|
|
+
|
|
|
+ requestXML = writer.toString();
|
|
|
+ String cdataWrappedRequestXML = "<![CDATA[" + requestXML + "]]>";
|
|
|
+ System.out.println(cdataWrappedRequestXML);
|
|
|
+// System.out.println(requestXML);
|
|
|
+ System.out.println("================================================");
|
|
|
+//
|
|
|
+// CCEYSOAPEnvelope envelope = new CCEYSOAPEnvelope();
|
|
|
+// CCEYSOAPBody body = new CCEYSOAPBody();
|
|
|
+// CCEYQuery query = new CCEYQuery();
|
|
|
+// CCEYQueryRequest request = new CCEYQueryRequest();
|
|
|
+// request.setRequest(requestXML);
|
|
|
+// query.setQuery(request);
|
|
|
+// body.setQuery(query);
|
|
|
+// envelope.setBody(body);
|
|
|
+//
|
|
|
+// JAXBContext jaxbContext2 = JAXBContext.newInstance(CCEYSOAPEnvelope.class);
|
|
|
+// Marshaller marshaller2 = jaxbContext2.createMarshaller();
|
|
|
+// marshaller2.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
|
|
+// marshaller2.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
|
|
|
+//
|
|
|
+// StringWriter writer2 = new StringWriter();
|
|
|
+// marshaller2.marshal(envelope, writer2);
|
|
|
+//
|
|
|
+// System.out.println(writer2.toString());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:djh=\"http://www.djhealthunion.com/\">\n" +
|
|
|
+ " <soapenv:Header/>\n" +
|
|
|
+ " <soapenv:Body>\n" +
|
|
|
+ " <djh:Query>\n" +
|
|
|
+ " <!--Optional:-->\n" +
|
|
|
+ " <djh:query>\n" +
|
|
|
+ " <djh:request>\n" +
|
|
|
+ " <![CDATA[\n" +
|
|
|
+ requestXML+
|
|
|
+ " ]]>\n" +
|
|
|
+ " </djh:request>\n" +
|
|
|
+ " </djh:query>\n" +
|
|
|
+ " </djh:Query>\n" +
|
|
|
+ " </soapenv:Body>\n" +
|
|
|
+ "</soapenv:Envelope> ";
|
|
|
+ System.out.println(xml);
|
|
|
+
|
|
|
+// String xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
|
|
|
+// " <soapenv:Body>\n" +
|
|
|
+// " <djh:QueryResponse xmlns:djh=\"http://www.djhealthunion.com/\">\n" +
|
|
|
+// " <djh:response><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
|
|
+// "<Response>\n" +
|
|
|
+// " <TranCode>CW1011</TranCode>\n" +
|
|
|
+// " <ResultCode>0</ResultCode>\n" +
|
|
|
+// " <ErrorMsg/>\n" +
|
|
|
+// " <Items>\n" +
|
|
|
+// " <Item>\n" +
|
|
|
+// " <PATIENT_ID>101493391</PATIENT_ID>\n" +
|
|
|
+// " <BED_NO>K06</BED_NO>\n" +
|
|
|
+// " <INP_NO>01491520</INP_NO>\n" +
|
|
|
+// " <IN_FQCY>3</IN_FQCY>\n" +
|
|
|
+// " <DEPT_ID>01541</DEPT_ID>\n" +
|
|
|
+// " <NURSE_UNIT_CODE>174</NURSE_UNIT_CODE>\n" +
|
|
|
+// " <PATIENT_NAME>吴春宇</PATIENT_NAME>\n" +
|
|
|
+// " <PATIENT_SEX>男</PATIENT_SEX>\n" +
|
|
|
+// " <PATIENT_BIRTHDAY>1963-03-20</PATIENT_BIRTHDAY>\n" +
|
|
|
+// " <CHARGE_TYPE>国家省医保</CHARGE_TYPE>\n" +
|
|
|
+// " <IN_TIME>2022-08-11</IN_TIME>\n" +
|
|
|
+// " <TRANSFE_IN>2022-08-11</TRANSFE_IN>\n" +
|
|
|
+// " <ZHUZHIYSXM>贾晓晶</ZHUZHIYSXM>\n" +
|
|
|
+// " </Item>\n" +
|
|
|
+// " <Item>\n" +
|
|
|
+// " ...\n" +
|
|
|
+// " </Item>\n" +
|
|
|
+// " </Items>\n" +
|
|
|
+// "</Response>]]></djh:response>\n" +
|
|
|
+// " </djh:QueryResponse>\n" +
|
|
|
+// " </soapenv:Body>\n" +
|
|
|
+// "</soapenv:Envelope> ";
|
|
|
+//
|
|
|
+//
|
|
|
+// // 创建 JAXB 上下文
|
|
|
+// JAXBContext jaxbContext = JAXBContext.newInstance(CCEYSOAPEnvelope.class);
|
|
|
+//
|
|
|
+// // 创建 Unmarshaller 实例
|
|
|
+// Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
|
|
+//
|
|
|
+// // 将 XML 字符串转换为 Java 对象
|
|
|
+// CCEYSOAPEnvelope envelope = (CCEYSOAPEnvelope) unmarshaller.unmarshal(new StringReader(xml));
|
|
|
+//
|
|
|
+// // 从 SOAPEnvelope 获取 Response 对象
|
|
|
+// CCEYQueryResponse queryResponse = envelope.getBody().getQueryResponse();
|
|
|
+// String responseXml = queryResponse.getResponse();
|
|
|
+//
|
|
|
+// // 再次使用 JAXB 解析嵌套的 XML
|
|
|
+// JAXBContext responseContext = JAXBContext.newInstance(CCEYResponseInfo.class);
|
|
|
+// Unmarshaller responseUnmarshaller = responseContext.createUnmarshaller();
|
|
|
+// CCEYResponseInfo cceyResponse = (CCEYResponseInfo) responseUnmarshaller.unmarshal(new StringReader(responseXml));
|
|
|
+//
|
|
|
+// if (cceyResponse != null) {
|
|
|
+// // 输出解析结果
|
|
|
+// System.out.println("TranCode: " + cceyResponse.getTranCode());
|
|
|
+// System.out.println("ResultCode: " + cceyResponse.getResultCode());
|
|
|
+// for (CCEYCustomerInfoItem item : cceyResponse.getCCEYCustomerInfoItems()) {
|
|
|
+// System.out.println("Patient ID: " + item.getPatientId());
|
|
|
+// System.out.println("Bed No: " + item.getBedNo());
|
|
|
+// // 输出其他字段...
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+}
|