|
@@ -1,35 +1,30 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import org.assertj.core.util.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.diagbot.dto.PhysicalInfoDTO;
|
|
|
-import com.diagbot.dto.SearchEvaluatorDTO;
|
|
|
+import com.diagbot.dto.EvaluatorCalDTO;
|
|
|
import com.diagbot.entity.InquiryEvaluator;
|
|
|
import com.diagbot.entity.InquiryInfo;
|
|
|
-import com.diagbot.entity.PhysicalInfo;
|
|
|
import com.diagbot.entity.PhysicalVal;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
import com.diagbot.enums.PhysicalTypeEnum;
|
|
|
-import com.diagbot.enums.SexEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.impl.InquiryEvaluatorServiceImpl;
|
|
|
import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
-import com.diagbot.util.RegexValidateUtil;
|
|
|
import com.diagbot.vo.AddEvaluatorVO;
|
|
|
-import com.diagbot.vo.SearchEvaluatorVO;
|
|
|
+import com.diagbot.vo.EvaluatorCalVO;
|
|
|
|
|
|
/**
|
|
|
* @author: zhoutg
|
|
@@ -42,194 +37,153 @@ public class InquiryEvaluatorFacade extends InquiryEvaluatorServiceImpl {
|
|
|
@Autowired
|
|
|
private InquiryInfoFacade inquiryInfoFacade;
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- InquiryEvaluatorFacade inquiryEvaluatorFacade = new InquiryEvaluatorFacade();
|
|
|
+ /**
|
|
|
+ * 儿童体质辨识--添加
|
|
|
+ * @param addDeptInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean addEvaluator(AddEvaluatorVO addDeptInfoVO) {
|
|
|
+ QueryWrapper<InquiryInfo> inquiryInfoQe = new QueryWrapper<>();
|
|
|
+ inquiryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
+ inquiryInfoQe.eq("hospital_id", addDeptInfoVO.getHospitalId());
|
|
|
+ inquiryInfoQe.eq("hospital_dept_id", addDeptInfoVO.getHospitalDeptId());
|
|
|
+ inquiryInfoQe.eq("doctor_id", addDeptInfoVO.getDoctorId());
|
|
|
+ inquiryInfoQe.eq("patient_id", addDeptInfoVO.getPatientId());
|
|
|
+ inquiryInfoQe.eq("inquiry_code", addDeptInfoVO.getInquiryCode());
|
|
|
+ InquiryInfo inquiryInfo = inquiryInfoFacade.getOne(inquiryInfoQe);
|
|
|
+
|
|
|
+ Date now = DateUtil.now();
|
|
|
+
|
|
|
+ if(inquiryInfo==null){
|
|
|
+ inquiryInfo = new InquiryInfo();
|
|
|
+ inquiryInfo.setGmtCreate(now);
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(addDeptInfoVO, inquiryInfo);
|
|
|
+ inquiryInfo.setGmtModified(now);
|
|
|
+ inquiryInfoFacade.saveOrUpdate(inquiryInfo);
|
|
|
+
|
|
|
InquiryEvaluator inquiryEvaluator = new InquiryEvaluator();
|
|
|
- inquiryEvaluator.setMildValue(new BigDecimal(70.0)); // 平和体质
|
|
|
- inquiryEvaluator.setFaintValue(new BigDecimal(50.0)); // 气虚体质
|
|
|
- inquiryEvaluator.setStagnantValue(new BigDecimal(49.0)); // 积滞同质
|
|
|
- inquiryEvaluator.setWetValue(new BigDecimal(31.0)); // 湿滞体质
|
|
|
- inquiryEvaluator.setHeartValue(new BigDecimal(31.000)); // 心肝火旺体质
|
|
|
- inquiryEvaluator.setExceptValue(new BigDecimal(22.01)); // 异禀体质
|
|
|
- //inquiryEvaluatorFacade.valueSort(inquiryEvaluator);
|
|
|
- inquiryEvaluatorFacade.cal(inquiryEvaluator);
|
|
|
+ BeanUtil.copyProperties(addDeptInfoVO, inquiryEvaluator);
|
|
|
+ inquiryEvaluator.setInquiryId(inquiryInfo.getId());
|
|
|
+ inquiryEvaluator.setGmtCreate(now);
|
|
|
+ inquiryEvaluator.setGmtModified(now);
|
|
|
+
|
|
|
+ if (!save(inquiryEvaluator)) {
|
|
|
+ throw new CommonException(CommonErrorCode.INSERT_DATA_FAILED, "评估结果提交失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
- * 计算体质
|
|
|
- *
|
|
|
- * @param evaluator 参数
|
|
|
+ * 儿童体质辨识--体质计算
|
|
|
+ * @param evaluatorCalVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public InquiryEvaluator cal(InquiryEvaluator evaluator) {
|
|
|
-
|
|
|
- List<PhysicalVal> list = this.valueSort(evaluator);
|
|
|
- Double max = list.get(0).getValue();
|
|
|
- Double min = list.get(4).getValue();
|
|
|
-
|
|
|
- if (max >= 50) {
|
|
|
+ public EvaluatorCalDTO evaluatorCal(EvaluatorCalVO evaluatorCalVO){
|
|
|
+ EvaluatorCalDTO evaluatorCalDTO = new EvaluatorCalDTO();
|
|
|
+
|
|
|
+ List<PhysicalVal> physicalValList = valueSort(evaluatorCalVO);
|
|
|
+ Double max = physicalValList.get(0).getValue();
|
|
|
+ Double min = physicalValList.get(4).getValue();
|
|
|
+
|
|
|
+ String physicalRes = null,physicalTypes=null;
|
|
|
+ if(max>=50){
|
|
|
// 最大值有多个【是XX体质兼有XX体质】,最大值只有1个【是XX体质】
|
|
|
- if (list.get(1).getValue() >= 50) {
|
|
|
- evaluator.setPhysicalRes("是" +
|
|
|
- PhysicalTypeEnum.getName(list.get(0).getEnumNo())
|
|
|
- + "兼有" +
|
|
|
- PhysicalTypeEnum.getName(list.get(1).getEnumNo()));
|
|
|
- evaluator.setPhysicalTypes("" + list.get(0).getEnumNo() + "," + list.get(1).getEnumNo());
|
|
|
- } else {
|
|
|
- evaluator.setPhysicalRes("是" +
|
|
|
- PhysicalTypeEnum.getName(list.get(0).getEnumNo()));
|
|
|
- evaluator.setPhysicalTypes("" + list.get(0).getEnumNo());
|
|
|
+ if(physicalValList.get(1).getValue()>=50){
|
|
|
+ physicalRes = "是"
|
|
|
+ + PhysicalTypeEnum.getName(physicalValList.get(0).getEnumNo())
|
|
|
+ + "兼有"
|
|
|
+ + PhysicalTypeEnum.getName(physicalValList.get(1).getEnumNo());
|
|
|
+ physicalTypes = physicalValList.get(0).getEnumNo()
|
|
|
+ + ","
|
|
|
+ + physicalValList.get(1).getEnumNo();
|
|
|
+ }else{
|
|
|
+ physicalRes = "是" + PhysicalTypeEnum.getName(physicalValList.get(0).getEnumNo());
|
|
|
+ physicalTypes = String.valueOf(physicalValList.get(0).getEnumNo());
|
|
|
}
|
|
|
- } else if (max < 30) {
|
|
|
+ }else if(max<30){
|
|
|
// 同时其他5种体质转化分均<30分, max[2/3/4/5/6] < 30
|
|
|
- evaluator.setPhysicalRes("平和体质");
|
|
|
- evaluator.setPhysicalTypes(String.valueOf(PhysicalTypeEnum.mild.getKey()));
|
|
|
- } else {
|
|
|
- if (evaluator.getMildValue().doubleValue() >= 60.0) {
|
|
|
- if (max < 50 && min >= 30) {
|
|
|
+ physicalRes = "平和体质";
|
|
|
+ physicalTypes = String.valueOf(PhysicalTypeEnum.mild.getKey());
|
|
|
+ }else{
|
|
|
+ if(evaluatorCalVO.getMildValue().doubleValue()>=60.0){
|
|
|
+ if(max<50&&min>=30){
|
|
|
// 同时其他5种体质转化分均<50分,min[2/3/4/5/6] >= 30 and max[2/3/4/5/6] < 50
|
|
|
- evaluator.setPhysicalRes("基本是平和体质");
|
|
|
- evaluator.setPhysicalTypes(String.valueOf(PhysicalTypeEnum.mild.getKey()));
|
|
|
- } else if (max < 50 && max >= 30 && min < 30) {
|
|
|
+ physicalRes = "基本是平和体质";
|
|
|
+ physicalTypes = String.valueOf(PhysicalTypeEnum.mild.getKey());
|
|
|
+ }else if(max<50&&max>=30&&min<30){
|
|
|
// 同时其他5种体质转化分有30-49分,max[2/3/4/5/6] < 50 and max[2/3/4/5/6] >= 30 and min[2/3/4/5/6] < 30
|
|
|
- evaluator.setPhysicalRes("基本是平和体质兼倾向" + PhysicalTypeEnum.getName(list.get(0).getEnumNo()));
|
|
|
- evaluator.setPhysicalTypes(String.valueOf(PhysicalTypeEnum.mild.getKey()) + "," + list.get(0).getEnumNo());
|
|
|
+ physicalRes = "基本是平和体质兼倾向" + PhysicalTypeEnum.getName(physicalValList.get(0).getEnumNo());
|
|
|
+ physicalTypes = PhysicalTypeEnum.mild.getKey() + "," + physicalValList.get(0).getEnumNo();
|
|
|
}
|
|
|
- } else {
|
|
|
- if (list.get(0).getValue().equals(list.get(1).getValue())) {
|
|
|
- evaluator.setPhysicalRes(
|
|
|
- "倾向是" +
|
|
|
- PhysicalTypeEnum.getName(list.get(0).getEnumNo())
|
|
|
- + "兼有" +
|
|
|
- PhysicalTypeEnum.getName(list.get(1).getEnumNo()));
|
|
|
- evaluator.setPhysicalTypes("" + list.get(0).getEnumNo() + "," + list.get(1).getEnumNo());
|
|
|
- } else {
|
|
|
- evaluator.setPhysicalRes("倾向是" +
|
|
|
- PhysicalTypeEnum.getName(list.get(0).getEnumNo()));
|
|
|
- evaluator.setPhysicalTypes("" + list.get(0).getEnumNo());
|
|
|
+ }else{
|
|
|
+ if(physicalValList.get(0).getValue().equals(physicalValList.get(1).getValue())){
|
|
|
+ physicalRes = "倾向是"
|
|
|
+ + PhysicalTypeEnum.getName(physicalValList.get(0).getEnumNo())
|
|
|
+ + "兼有"
|
|
|
+ + PhysicalTypeEnum.getName(physicalValList.get(1).getEnumNo());
|
|
|
+ physicalTypes = physicalValList.get(0).getEnumNo() + "," + physicalValList.get(1).getEnumNo();
|
|
|
+ }else{
|
|
|
+ physicalRes = "倾向是" + PhysicalTypeEnum.getName(physicalValList.get(0).getEnumNo());
|
|
|
+ physicalTypes = String.valueOf(physicalValList.get(0).getEnumNo());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return evaluator;
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(evaluatorCalVO, evaluatorCalDTO);;
|
|
|
+ evaluatorCalDTO.setPhysicalRes(physicalRes);
|
|
|
+ evaluatorCalDTO.setPhysicalTypes(physicalTypes);
|
|
|
+ evaluatorCalDTO.setPhysicalInfoList(Lists.newArrayList(physicalInfoFacade.listByIds(Arrays.asList(physicalTypes.split(",")).stream().map(i->Integer.parseInt(i)).collect(Collectors.toList()))));
|
|
|
+
|
|
|
+ return evaluatorCalDTO;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 对偏颇体质排序
|
|
|
- *
|
|
|
- * @param evaluator
|
|
|
- * @return 列表
|
|
|
+ * @param evaluatorCalVO
|
|
|
+ * @return
|
|
|
*/
|
|
|
- private List<PhysicalVal> valueSort(InquiryEvaluator evaluator){
|
|
|
+ private List<PhysicalVal> valueSort(EvaluatorCalVO evaluatorCalVO){
|
|
|
List<PhysicalVal> res = ListUtil.newArrayList();
|
|
|
//气虚体质转化分
|
|
|
PhysicalVal faintValue = new PhysicalVal();
|
|
|
- faintValue.setValue(evaluator.getFaintValue().doubleValue());
|
|
|
+ faintValue.setValue(evaluatorCalVO.getFaintValue().doubleValue());
|
|
|
faintValue.setEnumNo(PhysicalTypeEnum.faint.getKey());
|
|
|
faintValue.setOrderNo(1);
|
|
|
res.add(faintValue);
|
|
|
//积滞体质转化分
|
|
|
PhysicalVal stagnantValue = new PhysicalVal();
|
|
|
- stagnantValue.setValue(evaluator.getStagnantValue().doubleValue());
|
|
|
+ stagnantValue.setValue(evaluatorCalVO.getStagnantValue().doubleValue());
|
|
|
stagnantValue.setEnumNo(PhysicalTypeEnum.stagnant.getKey());
|
|
|
stagnantValue.setOrderNo(2);
|
|
|
res.add(stagnantValue);
|
|
|
//湿滞体质转化分
|
|
|
PhysicalVal wetValue = new PhysicalVal();
|
|
|
- wetValue.setValue(evaluator.getWetValue().doubleValue());
|
|
|
+ wetValue.setValue(evaluatorCalVO.getWetValue().doubleValue());
|
|
|
wetValue.setEnumNo(PhysicalTypeEnum.wet.getKey());
|
|
|
wetValue.setOrderNo(3);
|
|
|
res.add(wetValue);
|
|
|
//心肝火旺体质转化分
|
|
|
PhysicalVal heartValue = new PhysicalVal();
|
|
|
- heartValue.setValue(evaluator.getHeartValue().doubleValue());
|
|
|
+ heartValue.setValue(evaluatorCalVO.getHeartValue().doubleValue());
|
|
|
heartValue.setEnumNo(PhysicalTypeEnum.heart.getKey());
|
|
|
heartValue.setOrderNo(4);
|
|
|
res.add(heartValue);
|
|
|
//异禀体质转化分
|
|
|
PhysicalVal exceptValue = new PhysicalVal();
|
|
|
- exceptValue.setValue(evaluator.getExceptValue().doubleValue());
|
|
|
+ exceptValue.setValue(evaluatorCalVO.getExceptValue().doubleValue());
|
|
|
exceptValue.setEnumNo(PhysicalTypeEnum.except.getKey());
|
|
|
exceptValue.setOrderNo(5);
|
|
|
res.add(exceptValue);
|
|
|
|
|
|
- List<PhysicalVal> collect
|
|
|
- = res.stream()
|
|
|
- .sorted(Comparator.comparing(PhysicalVal::getValue).reversed()
|
|
|
- .thenComparing(PhysicalVal::getOrderNo))
|
|
|
+ return res.stream()
|
|
|
+ .sorted(Comparator.comparing(PhysicalVal::getValue)
|
|
|
+ .reversed()
|
|
|
+ .thenComparing(PhysicalVal::getOrderNo))
|
|
|
.collect(Collectors.toList());
|
|
|
- return collect;
|
|
|
- }
|
|
|
-
|
|
|
- public Boolean addEvaluator(AddEvaluatorVO addDeptInfoVO) {
|
|
|
- //参数验证
|
|
|
- if (!RegexValidateUtil.checkMobileNumber(addDeptInfoVO.getPhone())) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
|
|
|
- "请输入正确的手机号");
|
|
|
- }
|
|
|
- if (null == SexEnum.getName(addDeptInfoVO.getSex())) {
|
|
|
- throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
|
|
|
- "请输入正确的性别类型");
|
|
|
- }
|
|
|
-
|
|
|
- Date now = DateUtil.now();
|
|
|
-
|
|
|
- QueryWrapper<InquiryInfo> inquiryInfoQe = new QueryWrapper<>();
|
|
|
- inquiryInfoQe.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- inquiryInfoQe.eq("hospital_id", addDeptInfoVO.getHospitalId());
|
|
|
- inquiryInfoQe.eq("hospital_dept_id", addDeptInfoVO.getHospitalDeptId());
|
|
|
- inquiryInfoQe.eq("doctor_id", addDeptInfoVO.getDoctorId());
|
|
|
- inquiryInfoQe.eq("patient_id", addDeptInfoVO.getPatientId());
|
|
|
- inquiryInfoQe.eq("inquiry_code", addDeptInfoVO.getInquiryCode());
|
|
|
- InquiryInfo inquiryInfo = inquiryInfoFacade.getOne(inquiryInfoQe);
|
|
|
-
|
|
|
- if(inquiryInfo==null){
|
|
|
- inquiryInfo = new InquiryInfo();
|
|
|
- inquiryInfo.setGmtCreate(now);
|
|
|
- }
|
|
|
-
|
|
|
- BeanUtil.copyProperties(addDeptInfoVO, inquiryInfo);
|
|
|
- inquiryInfo.setGmtModified(now);
|
|
|
- inquiryInfoFacade.saveOrUpdate(inquiryInfo);
|
|
|
-
|
|
|
- InquiryEvaluator evaluator = new InquiryEvaluator();
|
|
|
- BeanUtil.copyProperties(addDeptInfoVO, evaluator);
|
|
|
- evaluator.setInquiryId(inquiryInfo.getId());
|
|
|
-
|
|
|
- //计算
|
|
|
- this.cal(evaluator);
|
|
|
-
|
|
|
- //保存结果
|
|
|
- evaluator.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
- evaluator.setGmtCreate(now);
|
|
|
- evaluator.setGmtModified(now);
|
|
|
- Boolean res = this.save(evaluator);
|
|
|
- if (!res) {
|
|
|
- throw new CommonException(CommonErrorCode.INSERT_DATA_FAILED, "评估结果提交失败!");
|
|
|
- }
|
|
|
- return res;
|
|
|
}
|
|
|
-
|
|
|
- public IPage<SearchEvaluatorDTO> getEvaluatorPage(SearchEvaluatorVO searchEvaluatorVO) {
|
|
|
- IPage<SearchEvaluatorDTO> res = this.baseMapper.getEvaluators(searchEvaluatorVO);
|
|
|
- if (ListUtil.isNotEmpty(res.getRecords())) {
|
|
|
- Map<String, PhysicalInfo> pMap = physicalInfoFacade.getPhysicalMap();
|
|
|
-
|
|
|
- for (SearchEvaluatorDTO searchEvaluatorDTO : res.getRecords()) {
|
|
|
- String[] physicalTypes = searchEvaluatorDTO.getPhysicalTypes().split(",");
|
|
|
- List<PhysicalInfoDTO> physicalInfoDTOList = ListUtil.newArrayList();
|
|
|
- for (String s : physicalTypes) {
|
|
|
- PhysicalInfoDTO physicalInfoDTO = new PhysicalInfoDTO();
|
|
|
- if (null != pMap.get(s)) {
|
|
|
- BeanUtil.copyProperties(pMap.get(s), physicalInfoDTO);
|
|
|
- physicalInfoDTOList.add(physicalInfoDTO);
|
|
|
- }
|
|
|
- }
|
|
|
- searchEvaluatorDTO.setPhysicalInfoDTOList(physicalInfoDTOList);
|
|
|
- }
|
|
|
- }
|
|
|
- return res;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
}
|