xiaochan 2 роки тому
батько
коміт
99a03956a1

+ 4 - 1
src/main/java/thyyxxk/webserver/config/exception/ExceptionEnum.java

@@ -42,7 +42,10 @@ public enum ExceptionEnum {
     PRE_DISCHARGE_ERROR(4002, "出院预审有可疑数据。"),
     SERVER_IS_UPDATE(5001, "服务器正在升级,请稍后在试一下。"),
     ERROR_MESSAGE(6001, "前端是返回成功的"),
-    ERROR_MESSAGE_BOX(6002, "数据错误");
+    ERROR_MESSAGE_BOX(6002, "数据错误"),
+    // 电子病历保存错误信息
+    EMR_SAVE(7001, "保存失败"),
+    EMR_EXTRACT_OBJECTS(7002, "提取数据元失败,但病历已保存。");
 
     private final int code;
     private String message;

+ 39 - 24
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/emr/EmrServer.java

@@ -9,6 +9,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.ListUtils;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
@@ -35,7 +36,6 @@ import thyyxxk.webserver.service.externalhttp.emr.EmrEditor;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
 import thyyxxk.webserver.utils.*;
 
-import javax.websocket.Session;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -208,29 +208,38 @@ public class EmrServer {
         // 获取 需要提取的数据元
         List<String> strings = JSON.parseArray(emrDataExtract.getDataExtract(), String.class);
         // 获取前端传入的数据元
+        Map<String, Object> extractedData = getStringObjectMap(param, strings);
+        EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(param.getPatNo(), param.getTimes());
+        if (emrDataElement == null) {
+            // 创建的病历可以解锁了
+            dao.insertDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(extractedData));
+        } else {
+            JSONObject jsonObject = JSONObject.parseObject(emrDataElement.getDataElement());
+            jsonObject.putAll(extractedData);
+            dao.updatePatientDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(jsonObject));
+        }
+        return extractedData;
+    }
+
+    @NotNull
+    private static Map<String, Object> getStringObjectMap(EmrPatientData param, List<String> strings) {
         JSONObject elementData = param.getEmrDataElement();
         // 提取到的数据
         Map<String, Object> extractedData = new HashMap<>(strings.size());
         for (String el : strings) {
             if (elementData.containsKey(el)) {
-                JSONObject item = elementData.getJSONObject(el);
+                JSONObject item;
+                try {
+                    item = elementData.getJSONObject(el);
+                } catch (Exception ignore) {
+                    throw new RuntimeException("数据元提取失败,但病历保存成功。数据元名称:【" + el + "】,粘贴时请使用(文本粘贴)。");
+                }
                 Object value = item.get("value");
                 if (value != null) {
                     extractedData.put(el, value);
                 }
             }
         }
-        EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(param.getPatNo(), param.getTimes());
-        if (emrDataElement == null) {
-            // 创建的病历可以解锁了
-            dao.insertDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(extractedData));
-        } else {
-            JSONObject jsonObject = JSONObject.parseObject(emrDataElement.getDataElement());
-//            log.info("患者原来的数据:{}", jsonObject);
-            jsonObject.putAll(extractedData);
-            dao.updatePatientDataSource(param.getPatNo(), param.getTimes(), JSON.toJSONString(jsonObject));
-        }
-//        log.info("提取到的数据:{}", JSON.toJSONString(extractedData));
         return extractedData;
     }
 
@@ -247,12 +256,12 @@ public class EmrServer {
         try {
             emr.saveDocument(saveJson);
         } catch (Exception e) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "病历保存错误,请重试!" + e.getMessage());
+            return ResultVoUtil.fail(ExceptionEnum.EMR_SAVE, "病历保存错误,请重试!" + e.getMessage());
         }
 
         param.setCreateId(TokenUtil.getInstance().getTokenUserId());
         Integer isUpdated = dao.whetherThereIsAMedicalRecord(param.getEmrDocumentId());
-        Map<String, Object> extractedData = extractDataElement(param);
+
         if (isUpdated != null) {
             dao.updateCreatedTemplate(param);
             insertAFragmentOfTheCourseOfTheDisease(isUpdated, param.getFragment());
@@ -268,6 +277,15 @@ public class EmrServer {
             dao.emrInsertForTheFirstTime(param);
             insertAFragmentOfTheCourseOfTheDisease(param.getId(), param.getFragment());
         }
+
+        Map<String, Object> extractedData;
+        try {
+            extractedData = extractDataElement(param);
+        } catch (Exception e) {
+            return ResultVoUtil.fail(ExceptionEnum.EMR_EXTRACT_OBJECTS, e.getMessage());
+        }
+
+
         return ResultVoUtil.success(extractedData);
     }
 
@@ -296,21 +314,12 @@ public class EmrServer {
      * @return 删除电子病历的同时需要删除, 提取到的数据源.
      */
     public ResultVo<List<String>> deletePatientEmrByDocumentId(String documentId) {
-
-        try {
-            emr.deleteEmr(documentId);
-        } catch (Exception e) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除电子病历失败,请重试!" + e.getMessage());
-        }
-
-
         EmrPatientData patientData = dao.getCategoryCodeByDocumentId(documentId);
         EmrDataExtract emrDataExtract = dao.extractDataSource(patientData.getEmrCategoryCode());
         List<String> strings = new ArrayList<>();
         if (emrDataExtract != null) {
             // 获取 需要提取的数据元
             strings = JSON.parseArray(emrDataExtract.getDataExtract(), String.class);
-//            log.info("需要提取的数据:{}", strings);
             // 获取到已经提取的数据
             EmrDataElement emrDataElement = dao.obtainPatientSOriginalData(patientData.getPatNo(), patientData.getTimes());
             // 转 json
@@ -324,6 +333,12 @@ public class EmrServer {
         }
         // 删除病历
         dao.deletePatientEmrByDocumentId(documentId, TokenUtil.getInstance().getTokenUserId());
+
+        try {
+            emr.deleteEmr(documentId);
+        } catch (Exception e) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除电子病历失败,请重试!" + e.getMessage());
+        }
         return ResultVoUtil.success(strings);
     }