Browse Source

优化代码

lighter 2 years ago
parent
commit
dadee654aa

+ 1 - 1
src/main/java/thyyxxk/wxservice_server/dao/HomePageDao.java

@@ -18,6 +18,6 @@ public interface HomePageDao {
             "deptName=(select rtrim(name) from zd_unit_code with(nolock) where code=dept_code), " +
             "doctorTitle=(select rtrim(name) from zd_emp_title with(nolock) where code=emp_tit_code), " +
             "portrait,introduction from a_employee_mi with(nolock) where wx_homepage_flag=1 and " +
-            "isnull(del_flag,0)!=1 order by wx_homepage_order")
+            "isnull(del_flag,0)!=1 and introduction is not null order by wx_homepage_order")
     List<DoctorInfo> selectHomePageDoctors();
 }

+ 3 - 0
src/main/java/thyyxxk/wxservice_server/entity/inspections/HshjPatient.java

@@ -2,6 +2,9 @@ package thyyxxk.wxservice_server.entity.inspections;
 
 import lombok.Data;
 
+/**
+ * 核酸混检患者
+ * */
 @Data
 public class HshjPatient {
     private String name;

+ 11 - 12
src/main/java/thyyxxk/wxservice_server/service/Covid19AssessmentService.java

@@ -41,26 +41,25 @@ public class Covid19AssessmentService {
         log.info("提交新冠感染流行病史问卷:{}", covidQuestionnaire);
         if (null == covidQuestionnaire.getPatientId()) {
             final String patientId = dao.selectPatientId(covidQuestionnaire.getIdcard());
-            log.info("根据身份证获取病人id: {}, {}", covidQuestionnaire.getIdcard(), patientId);
-            if (null == patientId) {
-                covidQuestionnaire.setPatientId("");
-            } else {
-                covidQuestionnaire.setPatientId(patientId);
-            }
+            covidQuestionnaire.setPatientId(null == patientId ? "" : patientId);
         }
         Integer dateDiff = dao.selectDateDiff(covidQuestionnaire.getPatientId());
         if (null == dateDiff || dateDiff > 0) {
             dao.insertNewCovid19Assessment(covidQuestionnaire);
-            if (covidQuestionnaire.getTemperature() == 2 ||
-                    covidQuestionnaire.getItem1() != 14 ||
-                    covidQuestionnaire.getItem2() != 24 ||
-                    covidQuestionnaire.getItem3() != 32 ||
-                    covidQuestionnaire.getItem4() != 42 ||
-                    covidQuestionnaire.getItem6() != 61) {
+            if (invalidCovidQuestionnaire(covidQuestionnaire)) {
                 return ResultVoUtil.success("您新型冠状病毒感染流行病学史问卷未通过,请挂发热门诊。");
             }
             return ResultVoUtil.success();
         }
         return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "您今天已提交过此问卷,请明天再试。");
     }
+
+    private Boolean invalidCovidQuestionnaire(CovidQuestionnaire questionnaire) {
+        return questionnaire.getTemperature() == 2 ||
+                questionnaire.getItem1() != 14 ||
+                questionnaire.getItem2() != 24 ||
+                questionnaire.getItem3() != 32 ||
+                questionnaire.getItem4() != 42 ||
+                questionnaire.getItem6() != 61;
+    }
 }

+ 0 - 3
src/main/java/thyyxxk/wxservice_server/service/HomePageService.java

@@ -35,9 +35,6 @@ public class HomePageService {
         List<DoctorInfo> originList = dao.selectHomePageDoctors();
         List<DoctorInfo> tempList = new ArrayList<>();
         for (DoctorInfo doctor : originList) {
-            if (StringUtil.isBlank(doctor.getIntroduction())) {
-                continue;
-            }
             tempList.add(doctor);
             if (tempList.size() == 3) {
                 HOME_PAGE_DOCTORS.add(tempList);

+ 58 - 52
src/main/java/thyyxxk/wxservice_server/service/IdCardAnalyzeService.java

@@ -34,7 +34,6 @@ public class IdCardAnalyzeService {
     private static final String APP_ID = "23575691";
     private static final String API_KEY = "vORX44kXQ4EyecWmDKCMwzoT";
     private static final String SECRET_KEY = "oDTPg0yC2a6hDhe63o5TgzuQMpZbkRDp";
-
     private final PatientCardsDao cardsDao;
     private final PushWxMessageService pushWxMessageService;
     private final RedisLikeService redis;
@@ -64,45 +63,50 @@ public class IdCardAnalyzeService {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "解析身份证服务出现异常,预计明日恢复,请手动输入您的信息。");
         }
         if (1 == res.getInt("idcard_number_type")) {
-            IdCardAnalyzeResult idCard = new IdCardAnalyzeResult();
-            JSONObject result = res.getJSONObject("words_result");
-            String socialNo = result.getJSONObject("公民身份号码").getString("words");
-            idCard.setName(result.getJSONObject("姓名").getString("words"));
-            idCard.setSocialNo(socialNo);
-            idCard.setSex(DateUtil.calculateSex(socialNo));
-            String districtCode = idCard.getSocialNo().substring(0, 6);
-            String districtName = redis.getRegionName(districtCode);
-            if (null != districtName) {
-                idCard.setDistrict(districtCode);
-                String cityCode = redis.getRegionParentCode(districtCode);
-                idCard.setCity(cityCode);
-                String cityName = redis.getRegionName(cityCode);
-                String provinceCode = redis.getRegionParentCode(cityCode);
-                idCard.setProvince(provinceCode);
-                String provinceName = redis.getRegionName(provinceCode);
-                idCard.setAddress(provinceName + "/" + cityName + "/" + districtName);
-                String longStreet = result.getJSONObject("住址").getString("words");
-                String[] shortStreets = longStreet.split(districtName);
-                if (shortStreets.length > 1) {
-                    idCard.setStreet(shortStreets[1]);
-                }
-            }
-            return ResultVoUtil.success(idCard);
+            return ResultVoUtil.success(readIdCardInfoFromAipOcr(res));
         }
         return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请上传正确的身份证图像!");
     }
 
+    private IdCardAnalyzeResult readIdCardInfoFromAipOcr(JSONObject res) {
+        IdCardAnalyzeResult idCard = new IdCardAnalyzeResult();
+        JSONObject result = res.getJSONObject("words_result");
+        String socialNo = result.getJSONObject("公民身份号码").getString("words");
+        idCard.setName(result.getJSONObject("姓名").getString("words"));
+        idCard.setSocialNo(socialNo);
+        idCard.setSex(DateUtil.calculateSex(socialNo));
+        String rawAddress = result.getJSONObject("住址").getString("words");
+        analyseStandardIdCardAddress(idCard, rawAddress);
+        return idCard;
+    }
+
+    private void analyseStandardIdCardAddress(IdCardAnalyzeResult idCard, String rawAddress) {
+        String districtCode = idCard.getSocialNo().substring(0, 6);
+        String districtName = redis.getRegionName(districtCode);
+        if (null != districtName) {
+            idCard.setDistrict(districtCode);
+            String cityCode = redis.getRegionParentCode(districtCode);
+            idCard.setCity(cityCode);
+            String cityName = redis.getRegionName(cityCode);
+            String provinceCode = redis.getRegionParentCode(cityCode);
+            idCard.setProvince(provinceCode);
+            String provinceName = redis.getRegionName(provinceCode);
+            idCard.setAddress(provinceName + "/" + cityName + "/" + districtName);
+            String[] shortStreets = rawAddress.split(districtName);
+            if (shortStreets.length > 1) {
+                idCard.setStreet(shortStreets[1]);
+            }
+        }
+    }
+
     public ResultVo<HashMap<String, Object>> readInput(IdCardAnalyzeResult param) throws Exception {
         if (StringUtil.isBlank(param.getSocialNo())) {
-            String birth = DateUtil.matchDate(param.getBirthday(), "yyyyMMdd");
-            if (null == birth) {
+            param.setBirthday(DateUtil.matchDate(param.getBirthday(), "yyyyMMdd"));
+            if (null == param.getBirthday()) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "儿童出生日期格式错误,请检查!(例:20180601)");
             }
-            param.setBirthday(birth);
-        } else {
-            if (!IdCardUtil.isValidatedIdCard(param.getSocialNo())) {
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "身份证不合法,请检查。");
-            }
+        } else if (!IdCardUtil.isValidatedIdCard(param.getSocialNo())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "身份证不合法,请检查。");
         }
         param.setIsDefault(param.getRelation() == 1 ? 1 :0);
         RestTemplate template = new RestTemplate();
@@ -120,26 +124,7 @@ public class IdCardAnalyzeService {
                 return bindExistCard(param);
             }
         }
-        CreatCardParam card = new CreatCardParam();
-        card.setPatName(param.getName());
-        card.setPatIdType(1);
-        card.setPatIdNo(param.getSocialNo());
-        card.setPatMobile(param.getPhone());
-        card.setPatAge(DateUtil.calculateAge(param.getSocialNo(), param.getBirthday()));
-        if (StringUtil.isBlank(param.getSocialNo())) {
-            card.setPatSex(param.getSex());
-        } else {
-            card.setPatSex(DateUtil.calculateSex(param.getSocialNo()));
-        }
-        card.setPatBirth(DateUtil.formatBirthday(param.getSocialNo(), param.getBirthday()));
-        card.setPatType(calculatePatType(card.getPatAge()));
-        card.setGuardName(param.getGuardName());
-        card.setGuardIdType(1);
-        card.setGuardIdNo(param.getGuardIdNo());
-        String provinceName = redis.getRegionName(param.getProvince());
-        String cityName = redis.getRegionName(param.getCity());
-        String districtName = redis.getRegionName(param.getDistrict());
-        card.setPatAddress(provinceName + cityName + districtName + param.getStreet());
+        CreatCardParam card = makeCreateCardParam(param);
         CreateCardResponse hrgResponse = template.postForObject(hrgApiUrl + "/savePatientInfo", card, CreateCardResponse.class);
         log.info("首诊患者建档:\n参数:{},\n结果:{}", card, hrgResponse);
         if (null == hrgResponse) {
@@ -153,6 +138,27 @@ public class IdCardAnalyzeService {
         return bindExistCard(param);
     }
 
+    private CreatCardParam makeCreateCardParam(IdCardAnalyzeResult idCard) throws Exception {
+        CreatCardParam card = new CreatCardParam();
+        card.setPatName(idCard.getName());
+        card.setPatIdType(1);
+        card.setPatIdNo(idCard.getSocialNo());
+        card.setPatMobile(idCard.getPhone());
+        card.setPatAge(DateUtil.calculateAge(idCard.getSocialNo(), idCard.getBirthday()));
+        card.setPatSex(StringUtil.isBlank(idCard.getSocialNo()) ? idCard.getSex() :
+                DateUtil.calculateSex(idCard.getSocialNo()));
+        card.setPatBirth(DateUtil.formatBirthday(idCard.getSocialNo(), idCard.getBirthday()));
+        card.setPatType(calculatePatType(card.getPatAge()));
+        card.setGuardName(idCard.getGuardName());
+        card.setGuardIdType(1);
+        card.setGuardIdNo(idCard.getGuardIdNo());
+        String provinceName = redis.getRegionName(idCard.getProvince());
+        String cityName = redis.getRegionName(idCard.getCity());
+        String districtName = redis.getRegionName(idCard.getDistrict());
+        card.setPatAddress(provinceName + cityName + districtName + idCard.getStreet());
+        return card;
+    }
+
     private Integer calculatePatType(Integer age) {
         if (null == age) {
             return 2;

+ 74 - 79
src/main/java/thyyxxk/wxservice_server/service/InspectionsService.java

@@ -20,6 +20,7 @@ import thyyxxk.wxservice_server.entity.inspections.QueryReportDetail;
 import thyyxxk.wxservice_server.entity.inspections.detail.*;
 import thyyxxk.wxservice_server.utils.*;
 
+import java.awt.geom.RectangularShape;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -41,108 +42,100 @@ public class InspectionsService {
     }
 
     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;
+        String firstHead = "<message><PATIENT_TYPE>0</PATIENT_TYPE><PTNT_NO>" + param.getPatientId() + "</PTNT_NO>";
+        String[] sendHeads = new String[]{firstHead, null, null, 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>";
+            sendHeads[1] = "<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>";
+            sendHeads[2] = "<message><PTNT_NO>" + tjNo + "</PTNT_NO>";
         }
         if (StringUtil.notBlank(inpatientNo)) {
-            sendHead3 = "<message><PATIENT_TYPE>1</PATIENT_TYPE><PTNT_NO>" + inpatientNo + "</PTNT_NO>";
+            sendHeads[3] = "<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);
+        List<ExamIndexResult> list = new ArrayList<>();
+        for (String sendHead : sendHeads) {
+            if (null != sendHead) {
+                String sendXml = sendHead + sendEnd;
+                String resXml = invokeService.invokeRemoteMethod("GetLabReportIndex", sendXml);
+                list.addAll(invokeService.analyzeExamIndex(resXml));
+            }
         }
-        return ResultVoUtil.success(list0);
+        return ResultVoUtil.success(list);
     }
 
     public ResultVo<List<ExamIndexResult>> checkCovidExamIndexBySocialNo(String socialNo) {
-        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         Date date = new Date();
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
         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<HshjPatient> hshjNos = getCovidMultipleExamNo(mzNos, start);
+        List<ExamIndexResult> results = getSingleCovidExamResult(mzNos, xmlEnd);
+        results.addAll(getMultipleExamResult(hshjNos, xmlEnd));
+        return ResultVoUtil.success(results);
+    }
+
+    private List<HshjPatient> getCovidMultipleExamNo(List<String> mzNos, String start) {
+        List<HshjPatient> hshjNos = new ArrayList<>();
+        RestTemplate restTemplate = new RestTemplate();
+        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 && startDate.before(itemDate)) {
+                        hshjNos.add(new HshjPatient(patName, mzNo, item.get("parentPatientId")));
                     }
                 }
             }
         }
+        return hshjNos;
+    }
+
+    private List<ExamIndexResult> getSingleCovidExamResult(List<String> mzNos, String xmlEnd) {
         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);
-                    }
+        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 results;
+    }
+
+    private List<ExamIndexResult> getMultipleExamResult(List<HshjPatient> hshjNos, String xmlEnd) {
+        List<ExamIndexResult> results = new ArrayList<>();
+        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);
+        return results;
     }
 
     public ResultVo<ExamDetailResult> checkExamDetail(QueryReportDetail param) {
@@ -151,15 +144,8 @@ public class InspectionsService {
         }
         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) {
+        Element retEle = getResultElement(xml);
+        if (null == retEle) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结果集为空!");
         }
         ExamDetailResult detail = new ExamDetailResult();
@@ -211,5 +197,14 @@ public class InspectionsService {
         return ResultVoUtil.success(detail);
     }
 
-
+    private Element getResultElement(String xml) {
+        try {
+            Document document = DocumentHelper.parseText(xml);
+            Element root = document.getRootElement();
+            return root.element("return");
+        } catch (DocumentException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
 }

+ 0 - 1
src/main/java/thyyxxk/wxservice_server/service/OrderCovidExamService.java

@@ -28,7 +28,6 @@ import java.util.Map;
 @Service
 public class OrderCovidExamService {
     private final AppointmentDao dao;
-
     private final MultipleExamTimeLimit timeLimit = new MultipleExamTimeLimit();
     private final SimpleDateFormat timeLimitFormat = new SimpleDateFormat("HHmm");