|
@@ -1,5 +1,11 @@
|
|
|
package thyyxxk.webserver.service.chronicDisease;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -8,19 +14,30 @@ import thyyxxk.webserver.constants.YbTjConstant;
|
|
|
import thyyxxk.webserver.dao.his.chronicDisease.ChronicDiseaseDao;
|
|
|
import thyyxxk.webserver.dao.his.chronicDisease.CrmPatientMiDao;
|
|
|
import thyyxxk.webserver.dao.his.chronicDisease.CrmPatientTzxxDao;
|
|
|
+import thyyxxk.webserver.dao.his.chronicDisease.CrmVisitRecordDao;
|
|
|
import thyyxxk.webserver.dao.his.inpatient.casefrontsheet.SheetCreatedDao;
|
|
|
import thyyxxk.webserver.entity.ResultVo;
|
|
|
import thyyxxk.webserver.entity.chronicDisease.CrmPatientMi;
|
|
|
import thyyxxk.webserver.entity.chronicDisease.CrmPatientTzxx;
|
|
|
+import thyyxxk.webserver.entity.chronicDisease.CrmVisitRecord;
|
|
|
+import thyyxxk.webserver.entity.chronicDisease.CrmVisitRecordVo;
|
|
|
import thyyxxk.webserver.entity.dictionary.CodeName;
|
|
|
+import thyyxxk.webserver.entity.login.UserInfo;
|
|
|
+import thyyxxk.webserver.service.externalhttp.emr.EmrEditor;
|
|
|
+import thyyxxk.webserver.service.redislike.RedisLikeService;
|
|
|
+import thyyxxk.webserver.utils.AssertUtil;
|
|
|
import thyyxxk.webserver.utils.ResultVoUtil;
|
|
|
import thyyxxk.webserver.utils.StringUtil;
|
|
|
import thyyxxk.webserver.utils.YbReportUtil;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @ClassName ChronicDiseaseService
|
|
@@ -39,12 +56,18 @@ public class ChronicDiseaseService {
|
|
|
private final CrmPatientMiDao cpmDao;
|
|
|
private final SheetCreatedDao createdDao;
|
|
|
private final CrmPatientTzxxDao tzxxDao;
|
|
|
+ private final EmrEditor emr;
|
|
|
+ private final CrmVisitRecordDao crmEmrDao;
|
|
|
+ private final RedisLikeService redisLikeService;
|
|
|
|
|
|
- public ChronicDiseaseService(ChronicDiseaseDao dao, CrmPatientMiDao cpmDao, SheetCreatedDao createdDao, CrmPatientTzxxDao tzxxDao) {
|
|
|
+ public ChronicDiseaseService(ChronicDiseaseDao dao, CrmPatientMiDao cpmDao, SheetCreatedDao createdDao, CrmPatientTzxxDao tzxxDao, EmrEditor emr, CrmVisitRecordDao crmEmrDao, RedisLikeService redisLikeService) {
|
|
|
this.dao = dao;
|
|
|
this.cpmDao = cpmDao;
|
|
|
this.createdDao = createdDao;
|
|
|
this.tzxxDao = tzxxDao;
|
|
|
+ this.emr = emr;
|
|
|
+ this.crmEmrDao = crmEmrDao;
|
|
|
+ this.redisLikeService = redisLikeService;
|
|
|
if (crmDictionary == null) {
|
|
|
crmDictionary = new HashMap<>();
|
|
|
}
|
|
@@ -127,20 +150,36 @@ public class ChronicDiseaseService {
|
|
|
cpmDao.deleteCrmPatientMiByPId(crmMi.getPId());
|
|
|
}
|
|
|
} else {
|
|
|
+ // 填写身份证件判断是否已存在信息
|
|
|
+ CrmPatientMi mi1 = cpmDao.selectCrmPatientMiBySocialNo(crmMi.getSocialNo());
|
|
|
+ if(null != mi1){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, crmMi.getSocialNo().substring(crmMi.getSocialNo().length() - 4) + "已存在首次慢病信息,无需重新登记!");
|
|
|
+ }
|
|
|
// 新增的时候添加pId
|
|
|
String pId = YbTjConstant.CRM_YY_TH + YbReportUtil.generateUkStr(1, 8);
|
|
|
crmMi.setPId(pId);
|
|
|
}
|
|
|
+
|
|
|
+ // 根据证件号补充基本信息
|
|
|
+ CrmVisitRecordVo data = crmEmrDao.selectCrmEmrPatientVoByMzCode(crmMi.getSocialNo());
|
|
|
+ if(null != data){
|
|
|
+ crmMi.setHisMzNo(data.getHisMzNo());
|
|
|
+ }
|
|
|
+ data = crmEmrDao.selectCrmEmrPatientVoByZyCode(crmMi.getSocialNo());
|
|
|
+ if(null != data){
|
|
|
+ crmMi.setHisZyNo(data.getHisZyNo());
|
|
|
+ }
|
|
|
+
|
|
|
+ int num = cpmDao.insert(crmMi);
|
|
|
+ if(num == 0){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存慢特病基本信息失败!");
|
|
|
+ }
|
|
|
CrmPatientTzxx crmTzXx = tzxxDao.selectCrmTzxxByPid(crmMi.getPId(), crmMi.getVisitTimes());
|
|
|
if(null != crmTzXx){
|
|
|
tzxxDao.deleteCrmTzxxByPid(crmMi.getPId(), crmMi.getVisitTimes());
|
|
|
}
|
|
|
CrmPatientTzxx tzXx = getCrmPatientTzxx(crmMi);
|
|
|
- int num = cpmDao.insert(crmMi);
|
|
|
int nom = tzxxDao.insert(tzXx);
|
|
|
- if(num == 0){
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存慢特病基本信息失败!");
|
|
|
- }
|
|
|
resultMap.put("cg", "保存慢特病基本信息成功!");
|
|
|
return ResultVoUtil.success(resultMap);
|
|
|
} catch(Exception e){
|
|
@@ -175,8 +214,6 @@ public class ChronicDiseaseService {
|
|
|
crmDictionary.put("getSexCode", createdDao.getSexCode());
|
|
|
// 婚姻状况字典
|
|
|
crmDictionary.put("getMarriageCode", createdDao.getMarriageCode());
|
|
|
- // 来源途径
|
|
|
- crmDictionary.put("getAdmissWay", createdDao.getAdmissWay());
|
|
|
// 联系人关系字典
|
|
|
crmDictionary.put("getRelations", createdDao.getRelations());
|
|
|
// 职业字典
|
|
@@ -195,6 +232,8 @@ public class ChronicDiseaseService {
|
|
|
crmDictionary.put("getArea", dao.getArea(""));
|
|
|
// 证件类型字典
|
|
|
crmDictionary.put("getPsnCertType", dao.getPsnCertType());
|
|
|
+ // 来源途径
|
|
|
+ crmDictionary.put("getAdmissWay", dao.getAdmissWay());
|
|
|
}
|
|
|
return ResultVoUtil.success(crmDictionary);
|
|
|
}
|
|
@@ -230,37 +269,37 @@ public class ChronicDiseaseService {
|
|
|
} else if(StringUtil.isBlank(crmMi.getPType())){
|
|
|
msg = "保存慢特病基本信息失败,病人来源为空,请检查!";
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getHeight()))){
|
|
|
+ if(null != crmMi.getHeight()){
|
|
|
if(!crmMi.getHeight().toString().matches(s1)){
|
|
|
msg = "保存慢特病基本信息失败,病人身高填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getWeight()))){
|
|
|
+ if(null != crmMi.getWeight()){
|
|
|
if(!String.valueOf(crmMi.getWeight()).matches(s1)){
|
|
|
msg = "保存慢特病基本信息失败,病人体重填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getTemperature()))){
|
|
|
+ if(null != crmMi.getTemperature()){
|
|
|
if(!String.valueOf(crmMi.getTemperature()).matches(s1)){
|
|
|
msg = "保存慢特病基本信息失败,病人体温填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getHeartRate()))){
|
|
|
+ if(null != crmMi.getHeartRate()){
|
|
|
if(!String.valueOf(crmMi.getHeartRate()).matches(s)){
|
|
|
msg = "保存慢特病基本信息失败,病人心率填写不符合(仅限纯数字),请检查!";
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getBloodSugar()))){
|
|
|
+ if(null != crmMi.getBloodSugar()){
|
|
|
if(!String.valueOf(crmMi.getBloodSugar()).matches(s1)){
|
|
|
msg = "保存慢特病基本信息失败,病人血糖填写不符合(仅限纯数字以及小数点),请检查!";
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getBloodPressureLow()))){
|
|
|
+ if(null != crmMi.getBloodPressureLow()){
|
|
|
if(!String.valueOf(crmMi.getBloodPressureLow()).matches(s)){
|
|
|
msg = "保存慢特病基本信息失败,病人舒张血压填写不符合(仅限纯数字),请检查!";
|
|
|
}
|
|
|
}
|
|
|
- if(StringUtil.notBlank(String.valueOf(crmMi.getBloodPressureHigh()))){
|
|
|
+ if(null != crmMi.getBloodPressureHigh()){
|
|
|
if(!String.valueOf(crmMi.getBloodPressureHigh()).matches(s)){
|
|
|
msg = "保存慢特病基本信息失败,病人收缩血压填写不符合(仅限纯数字),请检查!";
|
|
|
}
|
|
@@ -282,4 +321,123 @@ public class ChronicDiseaseService {
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询所有慢特病模板
|
|
|
+ * @return 返回模板
|
|
|
+ */
|
|
|
+ public JSONArray getCrmEmrModel(){
|
|
|
+ return emr.getDeptList(YbTjConstant.CRM_DEPT_CODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description 查询慢病模板记录
|
|
|
+ * @Author hsh
|
|
|
+ * @param param 查询条件
|
|
|
+ * @return CrmVisitRecord 慢病模板记录
|
|
|
+ * @Date 2023/12/9 9:55
|
|
|
+ */
|
|
|
+ public List<CrmVisitRecord> queryCrmEmrTree(CrmVisitRecord param) {
|
|
|
+ List<CrmVisitRecord> result;
|
|
|
+ QueryWrapper<CrmVisitRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("p_id", param.getPId());
|
|
|
+ String strTemplate = "第{}次慢病回访记录";
|
|
|
+ queryWrapper.ne("visit_times", param.getVisitTimes());
|
|
|
+ List<CrmVisitRecord> list = crmEmrDao.selectList(queryWrapper);
|
|
|
+ result = getTree(list, strTemplate);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CrmVisitRecord> getTree(List<CrmVisitRecord> list, String strTemplate) {
|
|
|
+ if(CollUtil.isEmpty(list)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ List<CrmVisitRecord> result = new ArrayList<>();
|
|
|
+ Map<Integer, List<CrmVisitRecord>> collect = list.stream().collect(Collectors.groupingBy(CrmVisitRecord::getVisitTimes));
|
|
|
+ Integer index = 1;
|
|
|
+ for(Integer key : collect.keySet()){
|
|
|
+ CrmVisitRecord tem = new CrmVisitRecord();
|
|
|
+ tem.setId(index);
|
|
|
+ tem.setName(StrUtil.format(strTemplate, key));
|
|
|
+ tem.setChildren(collect.get(key));
|
|
|
+ result.add(tem);
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description 查询慢特病登记信息
|
|
|
+ * @Author hsh
|
|
|
+ * @param keyCode 关键字
|
|
|
+ * @return CrmPatientMi
|
|
|
+ * @Date 2023/12/9 9:47
|
|
|
+ */
|
|
|
+ public ResultVo<CrmPatientMi> queryCrmPatientInfoByCode(String keyCode) {
|
|
|
+ AssertUtil.isnotBlank(keyCode,"关键字不能为空");
|
|
|
+
|
|
|
+ //查询慢特病登记记录
|
|
|
+ CrmPatientMi mi = cpmDao.selectCrmPatientMiByCode(keyCode);
|
|
|
+ if(null == mi){
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查询病人慢特病登记记录, 请先登记或检查关键字是否正确!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer times = crmEmrDao.selectCrmEmrPatientMaxById(mi.getPId());
|
|
|
+ if(null != times && times > 0){
|
|
|
+ mi.setVisitTimes(times + 1);
|
|
|
+ } else {
|
|
|
+ mi.setVisitTimes(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取登录人信息
|
|
|
+ UserInfo user = redisLikeService.getUserInfoByToken();
|
|
|
+ mi.setUserIdCode(user.getCodeRs());
|
|
|
+ mi.setUserName(user.getName());
|
|
|
+ mi.setDeptCode(user.getDeptCode());
|
|
|
+ mi.setDeptName(user.getDeptName());
|
|
|
+
|
|
|
+ List<CodeName> sex = createdDao.getSexCode();
|
|
|
+ Optional<CodeName> s = sex.stream().filter(codeName -> codeName.getCode().equals(mi.getSex())).findFirst();
|
|
|
+ s.ifPresent(codeName -> mi.setSexValue(codeName.getName()));
|
|
|
+ List<CodeName> way = dao.getAdmissWay();
|
|
|
+ Optional<CodeName> w = way.stream().filter(codeName -> codeName.getCode().equals(mi.getPType())).findFirst();
|
|
|
+ w.ifPresent(codeName -> mi.setPtName(codeName.getName()));
|
|
|
+
|
|
|
+ return ResultVoUtil.success(mi);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description 保存慢特病电子模板信息
|
|
|
+ * @Author hsh
|
|
|
+ * @param param 保存信息
|
|
|
+ * @return String
|
|
|
+ * @Date 2023/12/9 9:42
|
|
|
+ */
|
|
|
+ public ResultVo<String> saveCrmEmrModel(CrmVisitRecord param) {
|
|
|
+ AssertUtil.isnotBlank(param.getPId(),"用户ID不能为空");
|
|
|
+ AssertUtil.isnotBlank(param.getVisitTimes(),"用户慢病回访次数不能为空");
|
|
|
+ AssertUtil.isnotBlank(param.getEmrDocumentId(),"文档id不能为空");
|
|
|
+ JSONObject saveJson = new JSONObject();
|
|
|
+ saveJson.put("document", param.getDocumentData());
|
|
|
+ System.out.println(saveJson);
|
|
|
+ try {
|
|
|
+ emr.saveDocument(saveJson);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.EMR_SAVE, "病历保存错误,请重试!" + e.getMessage());
|
|
|
+ }
|
|
|
+ QueryWrapper<CrmVisitRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("emr_document_id", param.getEmrDocumentId());
|
|
|
+ CrmVisitRecord crmRecord = crmEmrDao.selectOne(queryWrapper);
|
|
|
+ if (crmRecord == null) {
|
|
|
+ param.setVisitDate(new Date());
|
|
|
+ crmEmrDao.insert(param);
|
|
|
+ } else {
|
|
|
+ param.setModifyId(param.getUserIdCode());
|
|
|
+ param.setModifyDate(new Date());
|
|
|
+ UpdateWrapper<CrmVisitRecord> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.eq("emr_document_id", param.getEmrDocumentId());
|
|
|
+ crmEmrDao.update(param, updateWrapper);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION,"保存慢病电子病历成功!");
|
|
|
+ }
|
|
|
+
|
|
|
}
|