Explorar el Código

dpcc定时任务

lighter hace 4 meses
padre
commit
4341e71838

+ 5 - 0
pom.xml

@@ -75,6 +75,11 @@
             <groupId>com.microsoft.sqlserver</groupId>
             <artifactId>mssql-jdbc</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
+        </dependency>
+
     </dependencies>
 
     <dependencyManagement>

+ 0 - 1
thyy-beinhospital/HELP.md

@@ -1 +0,0 @@
-# 住院服务

+ 0 - 7
thyy-emr-query/pom.xml

@@ -49,13 +49,6 @@
             <groupId>org.thyy.business</groupId>
             <artifactId>thyy-utils</artifactId>
         </dependency>
-
-
-        <dependency>
-            <groupId>com.baomidou</groupId>
-            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>

+ 5 - 0
thyy-scheduled/pom.xml

@@ -21,6 +21,11 @@
             <groupId>org.thyy.business</groupId>
             <artifactId>thyy-utils</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.thyy</groupId>
+            <artifactId>thyy-thirdpart-api</artifactId>
+            <version>${thyy-thirdpart-api}</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 66 - 0
thyy-scheduled/src/main/java/org/thyy/scheduled/dao/DpccDao.java

@@ -0,0 +1,66 @@
+package org.thyy.scheduled.dao;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.thyy.scheduled.entity.dpcc.MedicalPrescription;
+import org.thyy.scheduled.entity.dpcc.Patient;
+
+import java.util.List;
+
+@Mapper
+public interface DpccDao {
+    @Select("select " +
+            "rtrim(a.inpatient_no) as patNo,a.admiss_times as times, " +
+            "rtrim(b.social_no) as idCard,source='2' " +
+            "from zy_actpatient a,a_patient_mi b where a.zk_ward='1020700' " +
+            "and a.dpcc_upload_flag=0 and a.inpatient_no=b.inpatient_no")
+    List<Patient> getInpatientList();
+
+    @Select("select " +
+            "rtrim(a.patient_id) as patNo,a.times," +
+            "rtrim(b.social_no) as idCard,source='1' " +
+            "from mz_visit_table a,mz_patient_mi b where a.visit_dept_code='1020700' " +
+            "and a.dpcc_upload_flag=0 and datediff(day,a.visit_date,getdate())=0 " +
+            "and a.patient_id=b.patient_id")
+    List<Patient> getOutpatientList();
+
+    @Select("select " +
+            "patientNo=rtrim(b.inpatient_no), " +
+            "prescriptionNo=cast(cast (order_no as decimal) as varchar), " +
+            "hisDrugCode=rtrim(charge_code_mx), " +
+            "hisDrugName=(select top 1 rtrim(d.name) from yp_zd_dict d where d.code=a.charge_code_mx), " +
+            "hisDrugFrequencyCode=rtrim(b.frequ_code), " +
+            "hisDrugFrequencyName=rtrim(b.frequ_code), " +
+            "hisDrugUnit=(select rtrim(d.name) from yp_zd_unit d where d.code=b.dose_unit), " +
+            "hisDrugUsage=(select rtrim(d.supply_name) from yz_supply_type d where d.supply_code=b.supply_code), " +
+            "hisDrugDosage=b.dose, " +
+            "prescriptionTime=convert(varchar(19),a.charge_date,21), " +
+            "uniqueIndex=rtrim(b.inpatient_no)+'_'+cast(a.admiss_times as varchar)+'_'+cast(detail_sn as varchar), " +
+            "source='2',oecPrdesc=N'医嘱用药',isCydy='0' " +
+            "from zy_detail_charge a,yz_act_order b " +
+            "where a.inpatient_no=#{patNo} and a.admiss_times=#{times} " +
+            "and a.charge_code in ('BILL01','BILL02','BILL28') " +
+            "and a.charge_date<=getdate()" +
+            "and datediff(minute,a.charge_date,getdate())<=180 " +
+            "and a.order_no=b.act_order_no")
+    List<MedicalPrescription> getInpatientDrugs(Patient patient);
+
+    @Select("select " +
+            "patientNo=rtrim(a.patient_id), " +
+            "prescriptionNo=rtrim(a.patient_id) + '_' + cast(a.times as varchar) + '_1', " +
+            "hisDrugCode=rtrim(a.charge_item_code), " +
+            "hisDrugName=(select top 1 rtrim(d.name) from yp_zd_dict d where d.code=a.charge_item_code), " +
+            "hisDrugFrequencyCode=rtrim(a.frequency), " +
+            "hisDrugFrequencyName=rtrim(a.frequency), " +
+            "hisDrugUnit=(select rtrim(d.name) from yp_zd_unit d where d.code=a.drug_unit), " +
+            "hisDrugUsage=(select rtrim(d.supply_name) from yz_supply_type d where d.supply_code=a.supply_code), " +
+            "hisDrugDosage=a.quantity, " +
+            "prescriptionTime=convert(varchar(19),a.charge_date,21), " +
+            "uniqueIndex=rtrim(a.patient_id)+'_'+cast(a.times as varchar)+'_'+cast(receipt_no as varchar) " +
+            "+'_'+cast(a.order_no as varchar)+'_'+cast(item_no as varchar), " +
+            "source='1' " +
+            "from mz_charge_detail a " +
+            "where a.patient_id=#{patNo} and a.times=#{times} " +
+            "and a.group_no!='00' and a.pay_mark!='5' ")
+    List<MedicalPrescription> getOutpatientDrugs(Patient patient);
+}

+ 2 - 1
thyy-scheduled/src/main/java/org/thyy/scheduled/entity/dpcc/ReportIndexInquiry.java

@@ -1,10 +1,11 @@
 package org.thyy.scheduled.entity.dpcc;
 
 import lombok.Data;
+import org.thyy.thirdpartapi.inspection.config.PatientNumType;
 
 @Data
 public class ReportIndexInquiry {
-    private String patType;
+    private PatientNumType patType;
     private String reportCategory;
     private String patNo;
     private String socialNo;

+ 58 - 42
thyy-scheduled/src/main/java/org/thyy/scheduled/service/DpccHttp.java

@@ -11,11 +11,19 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 import org.thyy.scheduled.config.constant.Dpcc;
+import org.thyy.scheduled.dao.DpccDao;
 import org.thyy.scheduled.entity.dpcc.MedicalCheckResult;
 import org.thyy.scheduled.entity.dpcc.MedicalPrescription;
 import org.thyy.scheduled.entity.dpcc.Patient;
 import org.thyy.scheduled.entity.dpcc.ReportIndexInquiry;
 import org.thyy.scheduled.utils.AccessTokenUtil;
+import org.thyy.thirdpartapi.inspection.config.PatientNumType;
+import org.thyy.thirdpartapi.inspection.inspectionImpl.ThyyInspectionImpl;
+import org.thyy.thirdpartapi.inspection.request.jy.JyIndexRequest;
+import org.thyy.thirdpartapi.inspection.response.jy.JyDetailItem;
+import org.thyy.thirdpartapi.inspection.response.jy.JyDetailOrder;
+import org.thyy.thirdpartapi.inspection.response.jy.JyDetailResponse;
+import org.thyy.thirdpartapi.inspection.response.jy.JyIndexResponse;
 import org.thyy.utils.exception.BizException;
 import org.thyy.utils.exception.ExceptionEnum;
 
@@ -31,12 +39,16 @@ import java.util.List;
 @Service
 public class DpccHttp {
     private final Dpcc dpcc;
+    private final DpccDao dao;
     private final RestTemplate restTemplate;
+    private final ThyyInspectionImpl inspectionImpl;
 
     @Autowired
-    public DpccHttp(Dpcc dpcc, RestTemplate restTemplate) {
+    public DpccHttp(Dpcc dpcc, DpccDao dao, RestTemplate restTemplate, ThyyInspectionImpl inspectionImpl) {
         this.dpcc = dpcc;
+        this.dao = dao;
         this.restTemplate = restTemplate;
+        this.inspectionImpl = inspectionImpl;
     }
 
     public void getToken() {
@@ -93,7 +105,6 @@ public class DpccHttp {
     }
 
 
-
     private ReportIndexInquiry getReportIndexInquiry() {
         String now = DateUtil.formatDate(new Date());
         String start = now + " 00:00:00";
@@ -105,34 +116,36 @@ public class DpccHttp {
         return inquiry;
     }
 
-    private void uploadInpatientCheck(List<Patient> inpatientList, ReportIndexInquiry inquiry) throws Exception {
-        inquiry.setPatType("InPatient");
+    private void uploadInpatientCheck(List<Patient> inpatientList, ReportIndexInquiry inquiry) {
+        inquiry.setPatType(PatientNumType.InPatient);
         for (Patient inpatient : inpatientList) {
             queryCheckAndUpload(inquiry, inpatient);
         }
     }
 
-    private void uploadOutpatientCheck(List<Patient> outpatientList, ReportIndexInquiry inquiry) throws Exception {
-        inquiry.setPatType("OutPatient");
+    private void uploadOutpatientCheck(List<Patient> outpatientList, ReportIndexInquiry inquiry) {
+        inquiry.setPatType(PatientNumType.OutPatient);
         for (Patient outpatient : outpatientList) {
             queryCheckAndUpload(inquiry, outpatient);
         }
     }
 
-    private List<ExamIndexResponse> getExamIndex(ReportIndexInquiry inquiry) {
-        ExamIndexRequest request = new ExamIndexRequest.Builder()
+    private List<JyIndexResponse> getJyIndex(ReportIndexInquiry inquiry) {
+        JyIndexRequest request = new JyIndexRequest.Builder()
                 .patientNumType(inquiry.getPatType()).patientNum(inquiry.getPatNo())
                 .startDate(inquiry.getReqStartTime()).endDate(inquiry.getReqEndTime()).build();
-        ExamReportService examReportService = new ExamReportService();
-        return examReportService.queryExamIndex(request);
+        JSONObject json = JSONObject.from(request);
+        return inspectionImpl.queryExamIndex(json);
     }
 
-    private ExamDetailResponse getExamDetail(String reportId) {
-        ExamReportService examReportService = new ExamReportService();
-        return examReportService.queryExamDetail(reportId);
+    private JyDetailResponse getJyDetail(String reportId) {
+        JSONObject json = new JSONObject();
+        json.put("reportId", reportId);
+        json.put("responseMode", "Json");
+        return inspectionImpl.queryExamDetail(json);
     }
 
-    private boolean reportTimeValid(ExamDetailOrder order) {
+    private boolean reportTimeValid(JyDetailOrder order) {
         Date auditTime = DateUtil.parse(order.getAudtTime());
         if (null == auditTime) {
             return false;
@@ -142,19 +155,19 @@ public class DpccHttp {
         return diff / 1000 / 60 / 60 <= 72;
     }
 
-    private void queryCheckAndUpload(ReportIndexInquiry inquiry, Patient patient) throws Exception {
+    private void queryCheckAndUpload(ReportIndexInquiry inquiry, Patient patient) {
         List<MedicalCheckResult> checkResultBatches = new ArrayList<>();
         inquiry.setPatNo(patient.getPatNo());
-        List<ExamIndexResponse> indexList = getExamIndex(inquiry);
-        for (ExamIndexResponse index : indexList) {
-            ExamDetailResponse detail = getExamDetail(index.getReportId());
+        List<JyIndexResponse> indexList = getJyIndex(inquiry);
+        for (JyIndexResponse index : indexList) {
+            JyDetailResponse detail = getJyDetail(index.getReportId());
             if (reportTimeValid(detail.getOrder())) {
                 patient.setReportId(index.getReportId());
                 patient.setInspectTime(detail.getOrder().getInspectTime());
                 if (StrUtil.isBlank(patient.getInspectTime())) {
                     patient.setInspectTime(detail.getOrder().getAudtTime());
                 }
-                for (ExamDetailItem item : detail.getItems()) {
+                for (JyDetailItem item : detail.getItems()) {
                     if (StrUtil.isBlank(item.getItmUnit())) {
                         continue;
                     }
@@ -173,7 +186,7 @@ public class DpccHttp {
         }
     }
 
-    private MedicalCheckResult getMedicalCheckResult(Patient patient, ExamDetailItem item) {
+    private MedicalCheckResult getMedicalCheckResult(Patient patient, JyDetailItem item) {
         MedicalCheckResult checkResult = new MedicalCheckResult();
         checkResult.setSource(patient.getSource());
         checkResult.setIdCard(patient.getIdCard());
@@ -191,7 +204,7 @@ public class DpccHttp {
         return checkResult;
     }
 
-    private void uploadInpatientDrug(List<Patient> inpatientList) throws Exception {
+    private void uploadInpatientDrug(List<Patient> inpatientList) {
         List<MedicalPrescription> drugBatches = new ArrayList<>();
         for (Patient inpatient : inpatientList) {
             String patNo = inpatient.getPatNo();
@@ -210,7 +223,7 @@ public class DpccHttp {
         }
     }
 
-    private void uploadOutpatientDrug(List<Patient> outpatientList) throws Exception {
+    private void uploadOutpatientDrug(List<Patient> outpatientList) {
         for (Patient outpatient : outpatientList) {
             String patNo = outpatient.getPatNo();
             int times = outpatient.getTimes();
@@ -231,20 +244,17 @@ public class DpccHttp {
     }
 
     private void executeUploadChecks(List<MedicalCheckResult> checkBatches,
-                                     String patNo, int times) throws Exception {
+                                     String patNo, int times) {
         String json = JSON.toJSONString(checkBatches);
         log.info("DPCC上传检验:{}, {}", patNo, times);
         uploadToSino(encrypt(json), Type.CHECK);
     }
 
     private void executeUploadDrugs(List<MedicalPrescription> drugBatches,
-                                    String patNo, int times) throws Exception {
+                                    String patNo, int times) {
         String json = JSON.toJSONString(drugBatches);
         log.info("DPCC上传药品:{}, {}", patNo, times);
-        int res = uploadToSino(encrypt(json), Type.DRUG);
-        if (res == 200 && times != -1) {
-            dao.updateDpccFlag(patNo, times);
-        }
+        uploadToSino(encrypt(json), Type.DRUG);
     }
 
     private int uploadToSino(String encrypt, Type type) {
@@ -271,25 +281,31 @@ public class DpccHttp {
         DRUG,
     }
     
-    
-
-    private String encrypt(String plainText) throws Exception {
+    private String encrypt(String plainText) {
         byte[] keyBytes = dpcc.getEncryptKey().getBytes(StandardCharsets.UTF_8);
         SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
-        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
-        cipher.init(Cipher.ENCRYPT_MODE, keySpec);
-        byte[] plainTextBytes = plainText.getBytes(StandardCharsets.UTF_8);
-        byte[] cipherTextBytes = cipher.doFinal(plainTextBytes);
-        return Base64.getEncoder().encodeToString(cipherTextBytes);
+        try {
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.ENCRYPT_MODE, keySpec);
+            byte[] plainTextBytes = plainText.getBytes(StandardCharsets.UTF_8);
+            byte[] cipherTextBytes = cipher.doFinal(plainTextBytes);
+            return Base64.getEncoder().encodeToString(cipherTextBytes);
+        } catch (Exception e) {
+            throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
+        }
     }
 
-    private String decrypt(String cipherTextBase64) throws Exception {
+    private String decrypt(String cipherTextBase64) {
         byte[] keyBytes = dpcc.getEncryptKey().getBytes(StandardCharsets.UTF_8);
         SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
-        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
-        cipher.init(Cipher.DECRYPT_MODE, keySpec);
-        byte[] cipherTextBytes = Base64.getDecoder().decode(cipherTextBase64);
-        byte[] plainTextBytes = cipher.doFinal(cipherTextBytes);
-        return new String(plainTextBytes, StandardCharsets.UTF_8);
+        try {
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, keySpec);
+            byte[] cipherTextBytes = Base64.getDecoder().decode(cipherTextBase64);
+            byte[] plainTextBytes = cipher.doFinal(cipherTextBytes);
+            return new String(plainTextBytes, StandardCharsets.UTF_8);
+        } catch (Exception e) {
+            throw new BizException(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
+        }
     }
 }

+ 1 - 1
thyy-thirdpart-api/src/main/java/org/thyy/thirdpartapi/inspection/inspectionImpl/ThyyInspectionImpl.java

@@ -30,7 +30,7 @@ public class ThyyInspectionImpl implements InspectionInterface {
     @Override
     public void init(InspectionApi inspectionApi, InspectionApi.Config config) {
         this.api = config.getJy();
-        log.info("检验检查模块初始化: {}", api);
+        log.info("检验检查模块初始化完成");
     }
 
     @Override

+ 54 - 0
thyy-thirdpart-api/src/main/java/org/thyy/thirdpartapi/inspection/request/jy/JyIndexRequest.java

@@ -39,4 +39,58 @@ public class JyIndexRequest {
      * 查询截止日期: yyyy-MM-dd
      * */
     private String endDate;
+
+    public JyIndexRequest() {}
+
+    public JyIndexRequest(String cardType, String cardNo, PatientNumType patientNumType, String patientNum, String startDate, String endDate) {
+        this.cardType = cardType;
+        this.cardNo = cardNo;
+        this.patientNumType = patientNumType;
+        this.patientNum = patientNum;
+        this.startDate = startDate;
+        this.endDate = endDate;
+    }
+
+    public static class Builder {
+        private String cardType = "Undefine";
+        private String cardNo = "";
+        private PatientNumType patientNumType;
+        private String patientNum;
+        private String startDate;
+        private String endDate;
+
+        public Builder cardType(String cardType) {
+            this.cardType = cardType;
+            return this;
+        }
+
+        public Builder cardNo(String cardNo) {
+            this.cardNo = cardNo;
+            return this;
+        }
+
+        public Builder patientNumType(PatientNumType patientNumType) {
+            this.patientNumType = patientNumType;
+            return this;
+        }
+
+        public Builder patientNum(String patientNum) {
+            this.patientNum = patientNum;
+            return this;
+        }
+
+        public Builder startDate(String startDate) {
+            this.startDate = startDate;
+            return this;
+        }
+
+        public Builder endDate(String endDate) {
+            this.endDate = endDate;
+            return this;
+        }
+
+        public JyIndexRequest build() {
+            return new JyIndexRequest(cardType, cardNo, patientNumType, patientNum, startDate, endDate);
+        }
+    }
 }