Browse Source

完成医院患者的人员分布

xiaochan 2 years ago
parent
commit
4b72291191

+ 25 - 2
src/main/java/thyyxxk/webserver/controller/reports/PatientDistributionAddressController.java

@@ -1,17 +1,26 @@
 package thyyxxk.webserver.controller.reports;
 
+import org.apache.ibatis.annotations.Param;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.inpatient.patient.Patient;
 import thyyxxk.webserver.service.reports.PatientDistributionAddressServer;
+import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
 
 import java.util.List;
 
 @RestController
 @RequestMapping("/PatientDistributionAddress")
 public class PatientDistributionAddressController {
+    private final Integer BE_HOSPITALIZED = 1;
+    private final Integer 门诊 = 2;
+
+    private final Integer 在院 = 1;
+    private final Integer LEAVE_HOSPITAL = 2;
 
     private final PatientDistributionAddressServer server;
 
@@ -20,8 +29,22 @@ public class PatientDistributionAddressController {
     }
 
     @GetMapping("/patientAddress")
-    public ResultVo<List<Patient>> patientAddress() {
-        return server.patientAddress();
+    public ResultVo<List<Patient>> patientAddress(@Param("patientType") Integer patientType,
+                                                  @Param("inHospital") Integer inHospital,
+                                                  @Param("startTime") String startTime,
+                                                  @Param("endTime") String endTime) {
+        if (patientType.equals(BE_HOSPITALIZED)) {
+            if (StringUtil.isBlank(startTime) && inHospital.equals(LEAVE_HOSPITAL)) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出院患者必须选择时间范围");
+            }
+            return server.inpatientLocation(inHospital.equals(LEAVE_HOSPITAL) ? "zy_inactpatient" : "zy_actpatient", startTime, endTime);
+        } else {
+            if (StringUtil.isBlank(startTime)) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "门诊患者请选择时间范围");
+            }
+            return server.mzLocation(startTime, endTime);
+        }
+
     }
 
 

+ 37 - 9
src/main/java/thyyxxk/webserver/dao/his/reports/PatientDistributionAddressDao.java

@@ -1,5 +1,7 @@
 package thyyxxk.webserver.dao.his.reports;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -15,13 +17,29 @@ public interface PatientDistributionAddressDao {
     // district_code = (select name from t_region where code = district_code),
     // a_patient_mi 省市区
 
-    @Select("select inpatient_no, " +
+    @Select("select a.inpatient_no, " +
+            "       home_street, " +
             "       latitude, " +
-            "       longitude,  " +
-            "       addr_transed_flag " +
-            "from a_patient_mi " +
-            "where addr_transed_flag = 0")
-    List<Patient> inpatientAddress();
+            "       longitude," +
+            "       a.name " +
+            "from a_patient_mi a," +
+            "     ${tableName} b " +
+            "where addr_transed_flag = 0 and a.inpatient_no = b.inpatient_no " +
+            "and ${ew.sqlSegment} ")
+    List<Patient> inpatientAddress(@Param("tableName") String tableName,
+                                   @Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);
+
+
+    @Select("select latitude,\n" +
+            "       longitude,\n" +
+            "       name,\n" +
+            "       rtrim(patient_id) as inpatient_no\n" +
+            "from mz_patient_mi\n" +
+            "where addr_transed_flag = 0\n" +
+            "  and lv_date >= #{startTime}\n" +
+            "  and lv_date <= #{endTime} ")
+    List<Patient> mzAddress(@Param("startTime") String startTime,
+                            @Param("endTime") String endTime);
 
 
     @Select("select top 5000 inpatient_no," +
@@ -33,15 +51,25 @@ public interface PatientDistributionAddressDao {
     List<Patient> timedTaskPatientData();
 
 
+    @Select("select top 5000 patient_id as inpatient_no,\n" +
+            "                adress     as home_street\n" +
+            "from mz_patient_mi\n" +
+            "where nullif(adress, '') is not null\n" +
+            "order by patient_id desc")
+    List<Patient> mzTimedTaskPatientData();
+
+
     @Update("<script>" +
             "<foreach collection=\"list\" item=\"item\" index=\"index\" open=\"\" close=\"\" separator=\";\">" +
-            "update a_patient_mi " +
+            "update ${tableName} " +
             "set latitude = #{item.latitude,jdbcType=REAL}," +
             "    longitude = #{item.longitude,jdbcType=REAL}, " +
             "    addr_transed_flag = #{item.addrTransedFlag,jdbcType=INTEGER}  " +
-            "where inpatient_no = #{item.inpatientNo} " +
+            "where ${patNo} = #{item.inpatientNo} " +
             "</foreach>" +
             "</script>")
-    void updatePatientAddress(@Param("list") List<Patient> patients);
+    void updatePatientAddress(@Param("list") List<Patient> patients,
+                              @Param("tableName") String tableName,
+                              @Param("patNo") String panNo);
 
 }

+ 5 - 0
src/main/java/thyyxxk/webserver/entity/inpatient/patient/Patient.java

@@ -3,6 +3,7 @@ package thyyxxk.webserver.entity.inpatient.patient;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
+import thyyxxk.webserver.utils.StringUtil;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -128,6 +129,10 @@ public class Patient {
         }
     }
 
+    public String getPatNo() {
+        return StringUtil.isBlank(inpatientNo) ? inpatientNo : inpatientNo.trim();
+    }
+
     public Boolean getMidSetl() {
         return null != midSetl && midSetl;
     }

+ 18 - 25
src/main/java/thyyxxk/webserver/service/reports/PatientDistributionAddressServer.java

@@ -1,5 +1,6 @@
 package thyyxxk.webserver.service.reports;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
@@ -8,6 +9,7 @@ import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.inpatient.patient.Patient;
 import thyyxxk.webserver.utils.ListUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
 
 import java.util.List;
 
@@ -21,37 +23,28 @@ public class PatientDistributionAddressServer {
         this.dao = dao;
     }
 
-    public ResultVo<List<Patient>> patientAddress() {
+    public ResultVo<List<Patient>> inpatientLocation(String tableName, String startTime, String endTime) {
 
-        List<Patient> list = dao.inpatientAddress();
+        QueryWrapper<?> qw = new QueryWrapper<>();
+        qw.eq("1", 1);
 
+        if (StringUtil.notBlank(startTime) && "zy_inactpatient".equals(tableName)) {
+            qw.ge("b.dis_date", startTime);
+            qw.le("b.dis_date", endTime);
+        }
+
+        return adderss(dao.inpatientAddress(tableName, qw));
+    }
+
+    public ResultVo<List<Patient>> mzLocation(String startTime, String endTime) {
+        return adderss(dao.mzAddress(startTime, endTime));
+    }
+
+    private ResultVo<List<Patient>> adderss(List<Patient> list) {
         if (ListUtil.isBlank(list)) {
             return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
         }
         return ResultVoUtil.success(list);
-
-
-//        Map<String, BaiduMap> latitudeAndLongitude = new HashMap<>();
-//
-//        for (Patient patient : list) {
-//            BaiduMap baiduMap = new BaiduMap();
-//            String lat = patient.getLatitude().toPlainString();
-//            String lng = patient.getLongitude().toPlainString();
-//            baiduMap.setLat(patient.getLatitude());
-//            baiduMap.setLng(patient.getLongitude());
-//
-//            String key = lat + "_" + lng;
-//
-//            if (latitudeAndLongitude.containsKey(key)) {
-//                BaiduMap temp = latitudeAndLongitude.get(key);
-//                temp.setCount(temp.getCount() + 1);
-//            } else {
-//                baiduMap.setCount(1);
-//                latitudeAndLongitude.put(key, baiduMap);
-//            }
-//        }
-//
-//        return ResultVoUtil.success(latitudeAndLongitude);
     }