Quellcode durchsuchen

修改质控完成时间改成可选区间,医嘱分类(分为长嘱和临嘱)

ligao vor 6 Monaten
Ursprung
Commit
ba78156f3e

+ 3 - 2
ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/controller/chat/PatientDataController.java

@@ -74,12 +74,13 @@ public class PatientDataController {
             @RequestParam(required = false) String admissionDept,
             @RequestParam(required = false) String status,
             @RequestParam(required = false) String attendingDoctor,
-            @RequestParam(required = false) String admissionDate,
+            @RequestParam(required = false) String qcStartDate,
+            @RequestParam(required = false) String qcEndDate,
             @RequestParam(required = false) String viewed
     ) {
         Long userId = LoginHelper.getUserId();
         return patientRecordService.patientRecordList(pageQuery, recordId, admissionNo, patientName,
-                admissionDept, status, attendingDoctor, admissionDate, viewed, userId);
+                admissionDept, status, attendingDoctor, qcStartDate, qcEndDate, viewed, userId);
     }
 
     /**

+ 2 - 1
ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/PatientRecordService.java

@@ -21,7 +21,8 @@ public interface PatientRecordService {
             String admissionDept,
             String status,
             String attendingDoctor,
-            String admissionDate,
+            String qcStartDate,
+            String qcEndDate,
             String viewed,
             Long userId
     );

+ 81 - 8
ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/PatientRecordServiceImpl.java

@@ -465,7 +465,8 @@ public class PatientRecordServiceImpl implements PatientRecordService {
             String admissionDept,
             String status,
             String attendingDoctor,
-            String admissionDate,
+            String qcStartDate,
+            String qcEndDate,
             String viewed,
             Long userId
     ) {
@@ -496,11 +497,18 @@ public class PatientRecordServiceImpl implements PatientRecordService {
         if (attendingDoctor != null && !attendingDoctor.isEmpty()) {
             lqw.like(PatientRecord::getAttendingDoctor, attendingDoctor);
         }
-        if (admissionDate != null && !admissionDate.isEmpty()) {
-            // 将用户选择的日期转成开始和结束时间,根据质控结束时间进行搜索
-            String startTime = admissionDate + " 00:00:00";
-            String endTime = admissionDate + " 23:59:59";
-            lqw.exists("SELECT 1 FROM medical_record_result mrr WHERE mrr.patient_record_id = patient_record.id AND mrr.qc_end_time >= '" + startTime + "' AND mrr.qc_end_time <= '" + endTime + "'");
+        // 质控完成时间范围查询(>=开始时间,<=结束时间)
+        if ((qcStartDate != null && !qcStartDate.isEmpty()) || (qcEndDate != null && !qcEndDate.isEmpty())) {
+            StringBuilder existsSql = new StringBuilder("SELECT 1 FROM medical_record_result mrr WHERE mrr.patient_record_id = patient_record.id");
+            if (qcStartDate != null && !qcStartDate.isEmpty()) {
+                String startTime = qcStartDate + " 00:00:00";
+                existsSql.append(" AND mrr.qc_end_time >= '").append(startTime).append("'");
+            }
+            if (qcEndDate != null && !qcEndDate.isEmpty()) {
+                String endTime = qcEndDate + " 23:59:59";
+                existsSql.append(" AND mrr.qc_end_time <= '").append(endTime).append("'");
+            }
+            lqw.exists(existsSql.toString());
         }
 
         Set<String> viewedRecordIds = new HashSet<>();
@@ -674,8 +682,8 @@ public class PatientRecordServiceImpl implements PatientRecordService {
             case "抢救记录":
             case "手术记录":
             case "医嘱记录":
-                // 这些类型是数组,需要逐条拆分
-                formattedContent.append(formatMedicalRecords(content));
+                // 医嘱记录需要按类型排序:先长期医嘱,后临时医嘱
+                formattedContent.append(formatOrdersWithTypeSort(content));
                 break;
 
             case "知情同意书":
@@ -746,6 +754,71 @@ public class PatientRecordServiceImpl implements PatientRecordService {
         return formattedContent.toString().trim();
     }
 
+    /**
+     * 医嘱记录格式化并排序:先长期医嘱,后临时医嘱
+     */
+    private String formatOrdersWithTypeSort(String content) {
+        StringBuilder formattedContent = new StringBuilder();
+
+        try {
+            List<String> records = objectMapper.readValue(content, List.class);
+            if (records == null || records.isEmpty()) {
+                return "";
+            }
+
+            List<String> processedRecords = records.stream()
+                    .filter(record -> record != null && !record.trim().isEmpty())
+                    .collect(Collectors.toList());
+
+            // 按医嘱类型排序:长期医嘱在前,临时医嘱在后
+            if (processedRecords.size() > 1) {
+                processedRecords.sort((r1, r2) -> {
+                    String type1 = extractOrderType(r1);
+                    String type2 = extractOrderType(r2);
+                    
+                    // 长期医嘱优先级为0,临时医嘱优先级为1
+                    int priority1 = "长期医嘱".equals(type1) ? 0 : 1;
+                    int priority2 = "长期医嘱".equals(type2) ? 0 : 1;
+                    
+                    // 先按类型排序(长期在前)
+                    int typeCompare = Integer.compare(priority1, priority2);
+                    if (typeCompare != 0) {
+                        return typeCompare;
+                    }
+                    
+                    // 同类型内保持原有顺序(或可以按时间排序)
+                    return 0;
+                });
+            }
+
+            for (String record : processedRecords) {
+                formattedContent.append(record.trim()).append("\n\n");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "解析记录失败";
+        }
+
+        return formattedContent.toString().trim();
+    }
+
+    /**
+     * 从医嘱格式化字符串中提取类型(类型:xxx)
+     * 格式示例:xxx(类型:临时医嘱,状态:...)
+     */
+    private String extractOrderType(String orderStr) {
+        if (orderStr == null || orderStr.isEmpty()) {
+            return "";
+        }
+        // 匹配 "类型:xxx,"
+        Pattern pattern = Pattern.compile("类型:([^,]+)");
+        Matcher matcher = pattern.matcher(orderStr);
+        if (matcher.find()) {
+            return matcher.group(1).trim();
+        }
+        return "";
+    }
+
     private LocalDateTime extractRecordDateTime(String record) {
         if (record == null) {
             return null;