|
|
package com.supervision.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.supervision.constant.TreatmentPlanIdConstant;
|
|
|
import com.supervision.controller.TreatmentPlanController;
|
|
|
import com.supervision.model.ConfigDrug;
|
|
|
import com.supervision.model.ConfigTreatmentPlan;
|
|
|
import com.supervision.model.Process;
|
|
|
import com.supervision.model.TreatmentPlanRecord;
|
|
|
import com.supervision.pojo.vo.DealPlanResVO;
|
|
|
import com.supervision.service.*;
|
|
|
import com.supervision.vo.ask.TreatmentPlanRecordVo;
|
|
|
import com.supervision.vo.manage.TreatmentPlanTreeNode;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.sql.Struct;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
public class TreatmentPlanServiceImpl implements TreatmentPlanService {
|
|
|
|
|
|
private final TreatmentPlanRecordService treatmentPlanRecordService;
|
|
|
|
|
|
private final ProcessService processService;
|
|
|
|
|
|
private final ConfigDrugService configDrugService;
|
|
|
|
|
|
private final ConfigTreatmentPlanService configTreatmentPlanService;
|
|
|
|
|
|
@Override
|
|
|
public boolean saveTreatmentPlanRecord(TreatmentPlanRecord treatmentPlanRecord) {
|
|
|
|
|
|
assertSaveTreatmentPlanRecord(treatmentPlanRecord);
|
|
|
|
|
|
return treatmentPlanRecordService.save(treatmentPlanRecord);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* detail to @see com.supervision.service.impl.TreatmentPlanServiceImpl#queryTreatmentPlanDetails(java.lang.String)
|
|
|
* @param processId 流程id
|
|
|
* @param disposalPlanType 处置类型 0:药物 1:其他
|
|
|
* @return List<TreatmentPlanRecord>
|
|
|
*/
|
|
|
@Deprecated
|
|
|
@Override
|
|
|
public List<TreatmentPlanRecord> queryTreatmentPlanRecord(String processId, String disposalPlanType) {
|
|
|
|
|
|
Assert.notEmpty(processId,"流程id不允许为空");
|
|
|
|
|
|
return treatmentPlanRecordService.lambdaQuery().eq(TreatmentPlanRecord::getProcessId, processId)
|
|
|
.eq("0".equals(disposalPlanType), TreatmentPlanRecord::getDisposalPlan, TreatmentPlanIdConstant.DRUG_ID)
|
|
|
.notIn("1".equals(disposalPlanType), TreatmentPlanRecord::getDisposalPlan,
|
|
|
CollUtil.newArrayList(TreatmentPlanIdConstant.DRUG_ID)).list();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean updateTreatmentPlanRecord(TreatmentPlanRecord treatmentPlanRecord) {
|
|
|
|
|
|
Assert.notEmpty(treatmentPlanRecord.getId(),"主键不能为空");
|
|
|
assertSaveTreatmentPlanRecord(treatmentPlanRecord);
|
|
|
|
|
|
return treatmentPlanRecordService.updateById(treatmentPlanRecord);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean deleteTreatmentPlanRecord(String id) {
|
|
|
|
|
|
Assert.notEmpty("主键id不能为空");
|
|
|
|
|
|
return treatmentPlanRecordService.removeById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean confirmTreatmentPlan(String processId, String status) {
|
|
|
|
|
|
Assert.isTrue(CollectionUtil.newArrayList("0","1","2").contains(status),"状态值有误");
|
|
|
|
|
|
Process process = processService.getById(processId);
|
|
|
Assert.notNull(process,"流程数据不存在");
|
|
|
|
|
|
if (Integer.valueOf(status).compareTo(process.getStatus()) <= 0){
|
|
|
return true;
|
|
|
}
|
|
|
process.setStatus(Integer.valueOf(status));
|
|
|
return processService.updateById(process);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<ConfigDrug> getDrugList() {
|
|
|
|
|
|
return configDrugService.list();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<TreatmentPlanTreeNode> queryTree(Integer disposalMethod) {
|
|
|
|
|
|
return configTreatmentPlanService.queryTree(disposalMethod);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public DealPlanResVO queryTreatmentPlanDetails(String processId) {
|
|
|
// 1. 查询处置计划记录
|
|
|
List<? extends TreatmentPlanRecord> treatmentPlanRecordList = treatmentPlanRecordService.queryByProcessId(processId);
|
|
|
DealPlanResVO dealPlanResVO = new DealPlanResVO();
|
|
|
if (CollUtil.isEmpty(treatmentPlanRecordList)){
|
|
|
dealPlanResVO.setOtherTreatmentPlan(CollectionUtil.newArrayList());
|
|
|
dealPlanResVO.setDrugTreatmentPlan(CollectionUtil.newArrayList());
|
|
|
return dealPlanResVO;
|
|
|
}
|
|
|
dealPlanResVO.setUserTreatmentPlanType(CollUtil.getFirst(treatmentPlanRecordList).getDisposalMethod());
|
|
|
|
|
|
Map<String, List<TreatmentPlanRecord>> treatmentPlanIdMap = treatmentPlanRecordList.stream().map(item->BeanUtil.toBean(item, TreatmentPlanRecordVo.class))
|
|
|
.collect(Collectors.groupingBy(v ->
|
|
|
Objects.isNull(v.getTreatmentPlanId()) ? "DRUG" :"OTHER"));
|
|
|
|
|
|
dealPlanResVO.setDrugTreatmentPlan(treatmentPlanIdMap.getOrDefault("DRUG", CollUtil.newArrayList()));
|
|
|
dealPlanResVO.setOtherTreatmentPlan(treatmentPlanIdMap.getOrDefault("OTHER", CollUtil.newArrayList()));
|
|
|
return dealPlanResVO;
|
|
|
}
|
|
|
|
|
|
private void assertSaveTreatmentPlanRecord(TreatmentPlanRecord record){
|
|
|
Assert.notEmpty(record.getProcessId(),"流程id不能为空");
|
|
|
Assert.notNull(record.getDisposalMethod(),"处置方式不能为为空");
|
|
|
//Assert.notNull(record.getDisposalPlan(),"处置计划不能为空");
|
|
|
if (StrUtil.isEmpty(record.getTreatmentPlanId())){
|
|
|
Assert.notEmpty(record.getDrugId(),"药物id不能为空");
|
|
|
}
|
|
|
}
|
|
|
}
|