|
|
|
@ -2,26 +2,24 @@ package com.supervision.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.manage.pojo.vo.MedicalRecInfoVO;
|
|
|
|
|
import com.supervision.manage.pojo.vo.MedicalRecManageVO;
|
|
|
|
|
import com.supervision.manage.pojo.vo.MedicalRecQaVO;
|
|
|
|
|
import com.supervision.model.*;
|
|
|
|
|
import com.supervision.service.AskPatientAnswerService;
|
|
|
|
|
import com.supervision.service.*;
|
|
|
|
|
import com.supervision.vo.manage.MedicalRecPageResVO;
|
|
|
|
|
import com.supervision.manage.service.MedicalRecManageService;
|
|
|
|
|
import com.supervision.service.DiseaseService;
|
|
|
|
|
import com.supervision.service.MedicalRecService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@ -36,6 +34,12 @@ public class MedicalRecManageServiceImpl implements MedicalRecManageService {
|
|
|
|
|
|
|
|
|
|
private final AskPatientAnswerService askPatientAnswerService;
|
|
|
|
|
|
|
|
|
|
private final PatientService patientService;
|
|
|
|
|
|
|
|
|
|
private final AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
|
|
|
|
|
|
|
|
|
|
private final CommonDicService commonDicService;
|
|
|
|
|
|
|
|
|
|
public List<Disease> queryDiseaseListByKeyWord(String keyword) {
|
|
|
|
|
// 注意,这里不支持查询复杂疾病,如果需要支持复杂疾病,这里需要单独进行改造
|
|
|
|
|
return diseaseService.lambdaQuery().eq(Disease::getDiseaseType, 0).like(Disease::getDiseaseName, keyword).list();
|
|
|
|
@ -61,16 +65,19 @@ public class MedicalRecManageServiceImpl implements MedicalRecManageService {
|
|
|
|
|
medicalRec.insert();
|
|
|
|
|
// 这里生成一个新的编号(首先去数据库里面查询编号,然后用最大的编号+1)(可能存在并发修改导致编码重复问题,不是重点,等有问题再说)
|
|
|
|
|
medicalRecService.updateMedicalRecNo("QL", "男".equals(patient.getGender()) ? "M" : "F", medicalRec.getId());
|
|
|
|
|
// 然后保存病历编码
|
|
|
|
|
List<AskPatientAnswer> qaList = reqVO.getQaList();
|
|
|
|
|
for (AskPatientAnswer askPatientAnswer : qaList) {
|
|
|
|
|
if (StrUtil.isBlank(askPatientAnswer.getLibraryQuestionId())) {
|
|
|
|
|
// 然后保存病历对应的问题
|
|
|
|
|
List<MedicalRecQaVO> qaList = reqVO.getQaList();
|
|
|
|
|
for (MedicalRecQaVO medicalRecQaVO : qaList) {
|
|
|
|
|
if (StrUtil.isBlank(medicalRecQaVO.getLibraryQuestionId())) {
|
|
|
|
|
throw new BusinessException("问题ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
AskPatientAnswer askPatientAnswer = new AskPatientAnswer();
|
|
|
|
|
askPatientAnswer.setLibraryQuestionId(medicalRecQaVO.getLibraryQuestionId());
|
|
|
|
|
askPatientAnswer.setAnswer(CollUtil.newArrayList(medicalRecQaVO.getMedicalRecAnswer()));
|
|
|
|
|
askPatientAnswer.setMedicalId(medicalRec.getId());
|
|
|
|
|
askPatientAnswer.setPatientId(patient.getId());
|
|
|
|
|
askPatientAnswer.insert();
|
|
|
|
|
}
|
|
|
|
|
askPatientAnswerService.saveBatch(qaList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -88,16 +95,92 @@ public class MedicalRecManageServiceImpl implements MedicalRecManageService {
|
|
|
|
|
// 首先找到数据库中的问答
|
|
|
|
|
List<AskPatientAnswer> existQAList = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, medicalRec.getId()).list();
|
|
|
|
|
Map<String, AskPatientAnswer> existQAMap = existQAList.stream().collect(Collectors.toMap(AskPatientAnswer::getId, Function.identity()));
|
|
|
|
|
for (AskPatientAnswer askPatientAnswer : reqVO.getQaList()) {
|
|
|
|
|
if (StrUtil.isNotBlank(askPatientAnswer.getId())) {
|
|
|
|
|
// 存在的移除掉
|
|
|
|
|
existQAMap.remove(askPatientAnswer.getId());
|
|
|
|
|
askPatientAnswer.updateById();
|
|
|
|
|
|
|
|
|
|
for (MedicalRecQaVO medicalRecQaVO : reqVO.getQaList()) {
|
|
|
|
|
if (StrUtil.isBlank(medicalRecQaVO.getLibraryQuestionId())) {
|
|
|
|
|
throw new BusinessException("问题ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isNotBlank(medicalRecQaVO.getId())) {
|
|
|
|
|
// 存在的从Map中移除掉
|
|
|
|
|
AskPatientAnswer existAnswer = existQAMap.remove(medicalRecQaVO.getId());
|
|
|
|
|
// 然后进行更新
|
|
|
|
|
existAnswer.setAnswer(CollUtil.newArrayList(medicalRecQaVO.getMedicalRecAnswer()));
|
|
|
|
|
existAnswer.updateById();
|
|
|
|
|
} else {
|
|
|
|
|
AskPatientAnswer askPatientAnswer = new AskPatientAnswer();
|
|
|
|
|
askPatientAnswer.setLibraryQuestionId(medicalRecQaVO.getLibraryQuestionId());
|
|
|
|
|
askPatientAnswer.setAnswer(CollUtil.newArrayList(medicalRecQaVO.getMedicalRecAnswer()));
|
|
|
|
|
askPatientAnswer.setMedicalId(medicalRec.getId());
|
|
|
|
|
askPatientAnswer.setPatientId(patient.getId());
|
|
|
|
|
askPatientAnswer.insert();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 将删除的移除
|
|
|
|
|
askPatientAnswerService.removeByIds(existQAMap.values().stream().map(AskPatientAnswer::getId).collect(Collectors.toSet()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MedicalRecInfoVO queryMedicalRecInfo(String id) {
|
|
|
|
|
MedicalRec medicalRec = medicalRecService.getById(id);
|
|
|
|
|
MedicalRecInfoVO medicalRecInfoVO = BeanUtil.toBean(medicalRec, MedicalRecInfoVO.class);
|
|
|
|
|
// 病人基本信息
|
|
|
|
|
medicalRecInfoVO.setPatient(patientService.getById(medicalRec.getPatientId()));
|
|
|
|
|
// 辅助检查
|
|
|
|
|
// medicalRecInfoVO.setAncillaryList();
|
|
|
|
|
// 体格检查
|
|
|
|
|
// medicalRecInfoVO.setPhysicalList();
|
|
|
|
|
// 处置计划
|
|
|
|
|
// medicalRecInfoVO.setTreatmentPlanList();
|
|
|
|
|
// 问答策略
|
|
|
|
|
medicalRecInfoVO.setQaList(queryMedicalRecQaInfo(id));
|
|
|
|
|
return medicalRecInfoVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询病例已经配置的的问答信息
|
|
|
|
|
*/
|
|
|
|
|
private List<MedicalRecQaVO> queryMedicalRecQaInfo(String medicalRecId) {
|
|
|
|
|
List<AskPatientAnswer> list = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, medicalRecId).list();
|
|
|
|
|
List<MedicalRecQaVO> medicalRecQaList = list.stream().map(e -> {
|
|
|
|
|
MedicalRecQaVO medicalRecQaVO = new MedicalRecQaVO();
|
|
|
|
|
medicalRecQaVO.setId(e.getId());
|
|
|
|
|
medicalRecQaVO.setLibraryQuestionId(e.getLibraryQuestionId());
|
|
|
|
|
|
|
|
|
|
// 病历的回答
|
|
|
|
|
medicalRecQaVO.setMedicalRecAnswer(CollUtil.getFirst(e.getAnswer()));
|
|
|
|
|
return medicalRecQaVO;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
// 开始构建问题
|
|
|
|
|
if (CollUtil.isNotEmpty(medicalRecQaList)) {
|
|
|
|
|
// 获取问题
|
|
|
|
|
Set<String> libraryQuestionIdSet = medicalRecQaList.stream().map(MedicalRecQaVO::getLibraryQuestionId).collect(Collectors.toSet());
|
|
|
|
|
List<AskTemplateQuestionLibrary> askTemplateQuestionLibraryList = askTemplateQuestionLibraryService.listByIds(libraryQuestionIdSet);
|
|
|
|
|
Map<String, AskTemplateQuestionLibrary> askQuestionMap = askTemplateQuestionLibraryList.stream().collect(Collectors.toMap(AskTemplateQuestionLibrary::getId, Function.identity()));
|
|
|
|
|
// 获取字典
|
|
|
|
|
Set<Long> dictIdSet = askTemplateQuestionLibraryList.stream().map(AskTemplateQuestionLibrary::getDictId).collect(Collectors.toSet());
|
|
|
|
|
Map<Long, CommonDic> dictMap = commonDicService.listByIds(dictIdSet).stream().collect(Collectors.toMap(CommonDic::getId, Function.identity()));
|
|
|
|
|
|
|
|
|
|
for (MedicalRecQaVO medicalRecQaVO : medicalRecQaList) {
|
|
|
|
|
AskTemplateQuestionLibrary questionLibrary = askQuestionMap.get(medicalRecQaVO.getLibraryQuestionId());
|
|
|
|
|
if (ObjectUtil.isNotEmpty(questionLibrary)) {
|
|
|
|
|
// 问题
|
|
|
|
|
medicalRecQaVO.setQuestionList(questionLibrary.getQuestion());
|
|
|
|
|
// 类目
|
|
|
|
|
medicalRecQaVO.setDictId(questionLibrary.getDictId());
|
|
|
|
|
// 类目名称
|
|
|
|
|
medicalRecQaVO.setDictName(dictMap.getOrDefault(questionLibrary.getDictId(), new CommonDic()).getNameZhPath());
|
|
|
|
|
// 默认回答
|
|
|
|
|
medicalRecQaVO.setDefaultAnswer(CollUtil.getFirst(questionLibrary.getDefaultAnswer()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return medicalRecQaList;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteMedicalRec(String id) {
|
|
|
|
|
medicalRecService.removeById(id);
|
|
|
|
|
// 删除病历时,如果是复合疾病,需要将疾病也删除,现在没有做复合疾病,所以先不管
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|