|
|
@@ -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);
|
|
|
}
|
|
|
|