Browse Source

完成血糖查询和修改

xiaochan 2 years ago
parent
commit
7214f088fa

+ 44 - 0
src/main/java/thyyxxk/webserver/controller/examinations/BloodSugarQueryController.java

@@ -0,0 +1,44 @@
+package thyyxxk.webserver.controller.examinations;
+
+import org.springframework.web.bind.annotation.*;
+import thyyxxk.webserver.dao.his.examinations.BloodSugarQueryDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.examinations.BloodSugar.BgNursingTestSync;
+import thyyxxk.webserver.service.examinations.BloodSugarQueryServer;
+import thyyxxk.webserver.utils.ResultVoUtil;
+
+import java.util.Map;
+
+/**
+ * @author Administrator
+ */
+@RestController
+@RequestMapping("/bloodSugar")
+public class BloodSugarQueryController {
+
+    private final BloodSugarQueryServer server;
+
+    private final BloodSugarQueryDao dao;
+
+    public BloodSugarQueryController(BloodSugarQueryServer server, BloodSugarQueryDao dao) {
+        this.server = server;
+        this.dao = dao;
+    }
+
+
+    @GetMapping("/getThePatienMaxHospitalizationTimes")
+    public ResultVo<Integer> getPatientNoTimes(@RequestParam("patNo") String patNo) {
+        return ResultVoUtil.success(dao.getPatientTimes(patNo));
+    }
+
+    @GetMapping("/getPatientLoodSugar")
+    public ResultVo<Map<String, Object>> getPatientLoodSugar(@RequestParam("patNo") String patNo,
+                                                             @RequestParam("times") Integer times) {
+        return server.getPatientLoodSugar(patNo, times);
+    }
+
+    @PostMapping("/modifyPatientBloodGlucoseInfo")
+    public ResultVo<String> modifyPatientBloodGlucoseInfo(@RequestBody BgNursingTestSync param) {
+        return server.modifyPatientBloodGlucoseInfo(param);
+    }
+}

+ 79 - 0
src/main/java/thyyxxk/webserver/dao/his/examinations/BloodSugarQueryDao.java

@@ -0,0 +1,79 @@
+package thyyxxk.webserver.dao.his.examinations;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import thyyxxk.webserver.entity.examinations.BloodSugar.BgNursingTestSync;
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
+
+import java.util.List;
+
+@Mapper
+public interface BloodSugarQueryDao {
+
+
+    @Select("select bed_no, " +
+            "       rtrim(a.name) name, " +
+            "       birth_date, " +
+            "       a.inpatient_no, " +
+            "       admiss_date " +
+            "from ${tableName} a, " +
+            "     a_patient_mi b " +
+            "where a.inpatient_no = b.inpatient_no " +
+            "  and a.inpatient_no = #{patNo} " +
+            "and a.admiss_times = #{times}")
+    Patient getPatientInfo(@Param("tableName") String tableName,
+                           @Param("patNo") String patNo,
+                           @Param("times") Integer times);
+
+
+    @Select("select id,\n" +
+            "       inpatient_no,\n" +
+            "       admiss_times,\n" +
+            "       nurse_id,\n" +
+            "       nurse_id_name = (select rtrim(name) from a_employee_mi where code = nurse_id)," +
+            "       test_time,\n" +
+            "       bed_no,\n" +
+            "       timecode_id,\n" +
+            "       timecode_name,\n" +
+            "       test_result,\n" +
+            "       result_unit\n" +
+            "from bg_nursing_test_sync\n" +
+            "where inpatient_no = #{patNo}" +
+            " and admiss_times = #{times}" +
+            " and timecode_name = N'随机血糖'")
+    List<BgNursingTestSync> getPatientLoodSugarRandom(@Param("patNo") String patNo,
+                                                      @Param("times") Integer times);
+
+    @Select("select id,\n" +
+            "       inpatient_no,\n" +
+            "       admiss_times,\n" +
+            "       nurse_id,\n" +
+            "       nurse_id_name = (select rtrim(name) from a_employee_mi where code = nurse_id)," +
+            "       test_time,\n" +
+            "       bed_no,\n" +
+            "       timecode_id,\n" +
+            "       timecode_name,\n" +
+            "       test_result,\n" +
+            "       result_unit\n" +
+            "from bg_nursing_test_sync\n" +
+            "where inpatient_no = #{patNo}" +
+            " and admiss_times = #{times}")
+    List<BgNursingTestSync> getPatientLoodSugar(@Param("patNo") String patNo,
+                                                @Param("times") Integer times);
+
+
+    @Select("select admiss_times " +
+            "from zy_actpatient " +
+            "where inpatient_no = #{patNo} ")
+    Integer getPatientTimes(@Param("patNo") String patNo);
+
+    @Update("update bg_nursing_test_sync\n" +
+            "set nurse_id  = #{nurseId},\n" +
+            "    test_time = #{testTime},\n" +
+            "    test_result = #{testResult} \n" +
+            "where id = #{id}")
+    void modifyPatientBloodGlucoseInfo(BgNursingTestSync param);
+
+}

+ 77 - 0
src/main/java/thyyxxk/webserver/entity/examinations/BloodSugar/BgNursingTestSync.java

@@ -0,0 +1,77 @@
+package thyyxxk.webserver.entity.examinations.BloodSugar;
+
+import lombok.Data;
+import thyyxxk.webserver.utils.DateUtil;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author 肖蟾
+ */
+@Data
+public class BgNursingTestSync implements Serializable {
+
+    private static final long serialVersionUID = 6832316864133680831L;
+
+    /**
+     * id
+     */
+    private Integer id;
+
+    /**
+     * 患者住院号
+     */
+    private String inpatientNo;
+
+    /**
+     * 住院次数
+     */
+    private Integer admissTimes;
+
+    /**
+     * 护理ID
+     */
+    private String nurseId;
+    private String nurseIdName;
+
+    /**
+     * 测试时间
+     */
+    private Date testTime;
+
+
+    public String getFormatTestTime() {
+        if (testTime == null) {
+            return null;
+        } else {
+            return DateUtil.formatDatetime(testTime, "HH:mm");
+        }
+    }
+
+    /**
+     * 床位号
+     */
+    private String bedNo;
+
+    /**
+     * 时间代码
+     */
+    private String timecodeId;
+
+    /**
+     * 时间代码名称
+     */
+    private String timecodeName;
+
+    /**
+     * 结果
+     */
+    private String testResult;
+
+    /**
+     * 结果单位
+     */
+    private String resultUnit;
+
+}

+ 11 - 0
src/main/java/thyyxxk/webserver/entity/examinations/BloodSugar/PackagedBloodGlucoseData.java

@@ -0,0 +1,11 @@
+package thyyxxk.webserver.entity.examinations.BloodSugar;
+
+import lombok.Data;
+
+import java.util.Map;
+
+@Data
+public class PackagedBloodGlucoseData {
+    private String date;
+    Map<String, BgNursingTestSync> data;
+}

+ 118 - 0
src/main/java/thyyxxk/webserver/service/examinations/BloodSugarQueryServer.java

@@ -0,0 +1,118 @@
+package thyyxxk.webserver.service.examinations;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.constants.Capacity;
+import thyyxxk.webserver.dao.his.examinations.BloodSugarQueryDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.examinations.BloodSugar.BgNursingTestSync;
+import thyyxxk.webserver.entity.examinations.BloodSugar.PackagedBloodGlucoseData;
+import thyyxxk.webserver.entity.inpatient.patient.Patient;
+import thyyxxk.webserver.utils.DateUtil;
+import thyyxxk.webserver.utils.ListUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class BloodSugarQueryServer {
+
+    private final BloodSugarQueryDao dao;
+
+    public BloodSugarQueryServer(BloodSugarQueryDao dao) {
+        this.dao = dao;
+    }
+
+
+    public ResultVo<Map<String, Object>> getPatientLoodSugar(String panNo, Integer times) {
+        Patient patient = dao.getPatientInfo("zy_actpatient", panNo, times);
+        if (patient == null) {
+            patient = dao.getPatientInfo("zy_inactpatient", panNo, times);
+        }
+        if (patient == null) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到患者信息");
+        }
+
+        if (patient.getBirthDate() != null && patient.getAdmissDate() != null) {
+            patient.setAge(DateUtil.calculateAge(DateUtil.parse(patient.getBirthDate()), patient.getAdmissDate()));
+        }
+
+        Map<String, Object> returnValue = new HashMap<>(Capacity.TWO);
+        returnValue.put("patientInfo", patient);
+
+        List<BgNursingTestSync> list = dao.getPatientLoodSugar(panNo, times);
+
+        if (ListUtil.isBlank(list)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到该患者的血糖信息。");
+        }
+
+        Map<String, List<BgNursingTestSync>> map = list.stream().collect(
+                Collectors.groupingBy(item -> DateUtil.formatDatetime(item.getTestTime(), DateUtil.DATE))
+        );
+
+        List<PackagedBloodGlucoseData> data = new ArrayList<>();
+
+        for (Map.Entry<String, List<BgNursingTestSync>> entrySet : map.entrySet()) {
+            Map<String, Integer> a = new HashMap<>();
+            // "空腹", "早餐后", "中餐前", "中餐后", "晚餐前", "晚餐后", "零点", "三点"
+            a.put("空腹", 0);
+            a.put("早餐后", 0);
+            a.put("中餐前", 0);
+            a.put("中餐后", 0);
+            a.put("晚餐前", 0);
+            a.put("晚餐后", 0);
+            a.put("零点", 0);
+            a.put("三点", 0);
+            a.put("随机血糖", 0);
+
+            List<PackagedBloodGlucoseData> row = new ArrayList<>();
+
+            for (BgNursingTestSync item : entrySet.getValue()) {
+                Integer timecodeNameIndex = a.get(item.getTimecodeName());
+                int rowSize = timecodeNameIndex + 1;
+                a.replace(item.getTimecodeName(), rowSize);
+
+                String name = item.getTimecodeName();
+
+                if ("随机血糖".equals(item.getTimecodeName())) {
+
+                    if (timecodeNameIndex >= 3) {
+                        name = item.getTimecodeName() + ((timecodeNameIndex % 3) + 1);
+                        timecodeNameIndex = timecodeNameIndex / 3;
+                        rowSize = timecodeNameIndex + 1;
+                    } else {
+                        name += (timecodeNameIndex + 1);
+                        timecodeNameIndex = 0;
+                        rowSize = 1;
+                    }
+                }
+                if (rowSize > row.size()) {
+                    PackagedBloodGlucoseData temp = new PackagedBloodGlucoseData();
+                    temp.setDate(entrySet.getKey());
+                    temp.setData(new HashMap<>());
+                    row.add(temp);
+                }
+                row.get(timecodeNameIndex).getData().put(name, item);
+            }
+            data.addAll(row);
+        }
+
+        returnValue.put("bloodSugarData", data);
+
+
+        return ResultVoUtil.success(returnValue);
+    }
+
+    public ResultVo<String> modifyPatientBloodGlucoseInfo(BgNursingTestSync param) {
+        if (param.getId() == null) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "血糖id 为空");
+        }
+        dao.modifyPatientBloodGlucoseInfo(param);
+        return ResultVoUtil.success();
+    }
+
+
+}