|
|
|
@ -1,27 +1,56 @@
|
|
|
|
|
package com.supervision.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.model.AskPatientAnswer;
|
|
|
|
|
import com.supervision.model.AskTemplateQuestionLibrary;
|
|
|
|
|
import com.supervision.model.CommonDic;
|
|
|
|
|
import com.supervision.model.MedicalRec;
|
|
|
|
|
import com.supervision.service.MedicalRecService;
|
|
|
|
|
import com.supervision.service.*;
|
|
|
|
|
import com.supervision.mapper.MedicalRecMapper;
|
|
|
|
|
import com.supervision.vo.manage.MedicalRecPageReqVO;
|
|
|
|
|
import com.supervision.vo.manage.MedicalRecPageResVO;
|
|
|
|
|
import com.supervision.vo.manage.MedicalRecQaVO;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author flevance
|
|
|
|
|
* @description 针对表【vp_medical_rec(病历表)】的数据库操作Service实现
|
|
|
|
|
* @createDate 2023-11-03 11:25:43
|
|
|
|
|
*/
|
|
|
|
|
* @author flevance
|
|
|
|
|
* @description 针对表【vp_medical_rec(病历表)】的数据库操作Service实现
|
|
|
|
|
* @createDate 2023-11-03 11:25:43
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class MedicalRecServiceImpl extends ServiceImpl<MedicalRecMapper, MedicalRec>
|
|
|
|
|
implements MedicalRecService{
|
|
|
|
|
implements MedicalRecService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CommonDicService commonDicService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AskTemplateQuestionLibraryService askTemplateQuestionLibraryService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AskPatientAnswerService askPatientAnswerService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AskTemplateQuestionSimilarityService askTemplateQuestionSimilarityService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 病历管理-列表查询
|
|
|
|
|
*
|
|
|
|
|
* @param medicalRecPageReqVO
|
|
|
|
|
* @param pageNum
|
|
|
|
|
* @param pageSize
|
|
|
|
@ -29,19 +58,114 @@ public class MedicalRecServiceImpl extends ServiceImpl<MedicalRecMapper, Medical
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public IPage<MedicalRecPageResVO> queryMedicalRecManagePage(MedicalRecPageReqVO medicalRecPageReqVO, Integer pageNum, Integer pageSize) {
|
|
|
|
|
return this.baseMapper.queryMedicalRecManagePage(medicalRecPageReqVO, new Page<>(pageNum,pageSize));
|
|
|
|
|
return this.baseMapper.queryMedicalRecManagePage(medicalRecPageReqVO, new Page<>(pageNum, pageSize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成一个病历编码,是最大的病历编码+1
|
|
|
|
|
* @param code 医院名称缩写
|
|
|
|
|
*
|
|
|
|
|
* @param code 医院名称缩写
|
|
|
|
|
* @param gender 性别 M 男 F 女
|
|
|
|
|
* @param id 记录ID
|
|
|
|
|
* @param id 记录ID
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void updateMedicalRecNo(String code,String gender,String id) {
|
|
|
|
|
public void updateMedicalRecNo(String code, String gender, String id) {
|
|
|
|
|
this.baseMapper.updateMedicalRecNo(code, gender, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存问询问题
|
|
|
|
|
*
|
|
|
|
|
* @param qaList 病历问题列表
|
|
|
|
|
* @param medicalRecId 病历id
|
|
|
|
|
* answerType 0系统默认问题,1病历问询问题
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void saveAskPatientAnswerListByMedicalRec(List<MedicalRecQaVO> qaList, String medicalRecId) {
|
|
|
|
|
List<MedicalRecQaVO> medicalRecQaVOS = queryMedicalDefaultAnswer(null);
|
|
|
|
|
saveAskPatientAnswer(qaList, medicalRecId, 1);
|
|
|
|
|
saveAskPatientAnswer(medicalRecQaVOS, medicalRecId, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void saveAskPatientAnswer(List<MedicalRecQaVO> qaList, String medicalRecId, Integer answerType) {
|
|
|
|
|
if (CollUtil.isEmpty(qaList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (MedicalRecQaVO medicalRecQaVO : qaList) {
|
|
|
|
|
if (StrUtil.isBlank(medicalRecQaVO.getLibraryQuestionId())) {
|
|
|
|
|
throw new BusinessException("问题ID不能为空");
|
|
|
|
|
}
|
|
|
|
|
AskPatientAnswer askPatientAnswer = new AskPatientAnswer();
|
|
|
|
|
askPatientAnswer.setLibraryQuestionId(medicalRecQaVO.getLibraryQuestionId());
|
|
|
|
|
askPatientAnswer.setAnswer(medicalRecQaVO.getMedicalRecAnswer());
|
|
|
|
|
askPatientAnswer.setMedicalId(medicalRecId);
|
|
|
|
|
askPatientAnswer.setAnswerType(answerType);
|
|
|
|
|
askPatientAnswer.setQuestion(CollUtil.getFirst(medicalRecQaVO.getQuestionList()));
|
|
|
|
|
askPatientAnswer.insert();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<MedicalRecQaVO> queryMedicalDefaultAnswer(String medicalRecId) {
|
|
|
|
|
|
|
|
|
|
CommonDic systemDic = commonDicService.lambdaQuery().eq(CommonDic::getGroupCode, "AQT").eq(CommonDic::getCode, "system").one();
|
|
|
|
|
Assert.notNull(systemDic, "未找到系统问题");
|
|
|
|
|
List<CommonDic> childCommonDicList = commonDicService.lambdaQuery().eq(CommonDic::getGroupCode, "AQT")
|
|
|
|
|
.eq(CommonDic::getParentId, systemDic.getId()).list();
|
|
|
|
|
Assert.notNull(childCommonDicList, "未找到系统问题下的子问题");
|
|
|
|
|
Map<Long, CommonDic> childCommonDicMap = childCommonDicList.stream().collect(Collectors.toMap(CommonDic::getId, Function.identity()));
|
|
|
|
|
final Map<String, List<String>> libraryMapQuestion = new HashMap<>();
|
|
|
|
|
// 从疾病问题记录中查询数据
|
|
|
|
|
if (StrUtil.isNotEmpty(medicalRecId)) {
|
|
|
|
|
List<AskPatientAnswer> askPatientAnswerList = askPatientAnswerService.lambdaQuery()
|
|
|
|
|
.eq(AskPatientAnswer::getMedicalId, medicalRecId).eq(AskPatientAnswer::getAnswerType, 0).list();
|
|
|
|
|
|
|
|
|
|
final Map<String, AskTemplateQuestionLibrary> libraryMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(askPatientAnswerList)) {
|
|
|
|
|
// 查询问题库信息
|
|
|
|
|
List<String> questionIds = askPatientAnswerList.stream()
|
|
|
|
|
.map(AskPatientAnswer::getLibraryQuestionId).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
Map<String, List<String>> libraryMapQuestionTmp = askTemplateQuestionSimilarityService.querySimilarityQuestionMapByLibraryIds(questionIds);
|
|
|
|
|
libraryMapQuestion.putAll(libraryMapQuestionTmp);
|
|
|
|
|
Map<String, AskTemplateQuestionLibrary> libraryMapTemp = askTemplateQuestionLibraryService.listByIds(questionIds)
|
|
|
|
|
.stream().collect(Collectors.toMap(AskTemplateQuestionLibrary::getId, Function.identity()));
|
|
|
|
|
libraryMap.putAll(libraryMapTemp);
|
|
|
|
|
}
|
|
|
|
|
return askPatientAnswerList.stream().map(e -> {
|
|
|
|
|
MedicalRecQaVO medicalRecQaVO = new MedicalRecQaVO();
|
|
|
|
|
medicalRecQaVO.setId(e.getId());
|
|
|
|
|
medicalRecQaVO.setLibraryQuestionId(e.getLibraryQuestionId());
|
|
|
|
|
medicalRecQaVO.setMedicalRecAnswer(e.getAnswer());
|
|
|
|
|
// 组装问题列表 和 字典数据
|
|
|
|
|
AskTemplateQuestionLibrary askTemplateQuestionLibrary = libraryMap.get(e.getLibraryQuestionId());
|
|
|
|
|
if (Objects.nonNull(askTemplateQuestionLibrary)) {
|
|
|
|
|
medicalRecQaVO.setQuestionList(libraryMapQuestion.get(e.getLibraryQuestionId()));
|
|
|
|
|
Long dictId = askTemplateQuestionLibrary.getDictId();
|
|
|
|
|
if (Objects.nonNull(dictId)) {
|
|
|
|
|
medicalRecQaVO.setDictId(dictId);
|
|
|
|
|
medicalRecQaVO.setDictNamePath(childCommonDicMap.getOrDefault(dictId, new CommonDic()).getNameZhPath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return medicalRecQaVO;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从问题库中查询数据
|
|
|
|
|
List<Long> commonDicIdList = childCommonDicList.stream().map(CommonDic::getId).collect(Collectors.toList());
|
|
|
|
|
List<AskTemplateQuestionLibrary> askTemplateQuestionLibraryList = askTemplateQuestionLibraryService.lambdaQuery().in(AskTemplateQuestionLibrary::getDictId, commonDicIdList).list();
|
|
|
|
|
return askTemplateQuestionLibraryList.stream().map(e -> {
|
|
|
|
|
MedicalRecQaVO medicalRecQaVO = new MedicalRecQaVO();
|
|
|
|
|
medicalRecQaVO.setLibraryQuestionId(e.getId());
|
|
|
|
|
medicalRecQaVO.setDictNamePath(childCommonDicMap.getOrDefault(e.getDictId(), new CommonDic()).getNameZhPath());
|
|
|
|
|
medicalRecQaVO.setQuestionList(libraryMapQuestion.get(e.getId()));
|
|
|
|
|
return medicalRecQaVO;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|