|
|
|
@ -16,27 +16,35 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
import digital.laboratory.platform.common.core.constant.CommonConstants; |
|
|
|
|
import digital.laboratory.platform.common.core.exception.CheckedException; |
|
|
|
|
import digital.laboratory.platform.common.core.util.R; |
|
|
|
|
import digital.laboratory.platform.common.mybatis.security.service.DLPUser; |
|
|
|
|
import digital.laboratory.platform.comservice.entity.DlpDictData; |
|
|
|
|
import digital.laboratory.platform.comservice.feign.RemoteDictDataService; |
|
|
|
|
import digital.laboratory.platform.inspection.constant.*; |
|
|
|
|
import digital.laboratory.platform.inspection.enums.BusinessType; |
|
|
|
|
import digital.laboratory.platform.inspection.enums.StdSolutionNum; |
|
|
|
|
import digital.laboratory.platform.inspection.enums.TaskTestDataStatus; |
|
|
|
|
import digital.laboratory.platform.inspection.constant.TestRecordSampleDataConstant; |
|
|
|
|
import digital.laboratory.platform.inspection.dto.*; |
|
|
|
|
import digital.laboratory.platform.inspection.entity.*; |
|
|
|
|
import digital.laboratory.platform.inspection.event.AuditDataExecutionEvent; |
|
|
|
|
import digital.laboratory.platform.inspection.event.FinishTestExecutionEvent; |
|
|
|
|
import digital.laboratory.platform.inspection.mapper.SampleInjectorMapper; |
|
|
|
|
import digital.laboratory.platform.inspection.mapper.TestRecordSampleDataMapper; |
|
|
|
|
import digital.laboratory.platform.inspection.query.AnalysisTestResultPageQuery; |
|
|
|
|
import digital.laboratory.platform.inspection.query.QueryTestResultPageQuery; |
|
|
|
|
import digital.laboratory.platform.inspection.service.*; |
|
|
|
|
import digital.laboratory.platform.inspection.utils.datafile.hair.HairSewageCompoundData; |
|
|
|
|
import digital.laboratory.platform.inspection.utils.datafile.nps.NPSDataFileStruct; |
|
|
|
|
import digital.laboratory.platform.inspection.utils.datafile.nps.NPSTestDetailDataStruct; |
|
|
|
|
import digital.laboratory.platform.inspection.vo.ESTBusinessInfoVO; |
|
|
|
|
import digital.laboratory.platform.inspection.vo.ResultConcentrationVO; |
|
|
|
|
import digital.laboratory.platform.inspection.vo.TestRecordReagentVO; |
|
|
|
|
import digital.laboratory.platform.inspection.vo.TestResultBusinessVO; |
|
|
|
|
import digital.laboratory.platform.inspetion.api.entity.EntrustInfo; |
|
|
|
|
import digital.laboratory.platform.inspetion.api.entity.SampleInfo; |
|
|
|
|
import digital.laboratory.platform.inspetion.api.entity.TestRecord; |
|
|
|
|
import digital.laboratory.platform.sys.entity.Drug; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
@ -96,6 +104,9 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl |
|
|
|
|
@Resource |
|
|
|
|
private ApplicationContext applicationContext; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private TestRecordReagentService testRecordReagentService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 校验实验状态是否完成,完成则提升不能修改数据 |
|
|
|
|
* |
|
|
|
@ -261,7 +272,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Page<Object> getSampleTestDataByTestIdPage(AnalysisTestResultPageDTO pageDTO) { |
|
|
|
|
public Page<Object> getSampleTestDataByTestIdPage(AnalysisTestResultPageQuery pageDTO) { |
|
|
|
|
Page<TestRecordSampleData> page = this.page(new Page<>(pageDTO.getCurrent(), pageDTO.getSize()), Wrappers.<TestRecordSampleData>lambdaQuery() |
|
|
|
|
.eq(TestRecordSampleData::getTestId, pageDTO.getTestId()) |
|
|
|
|
.orderByDesc(TestRecordSampleData::getCompoundName) |
|
|
|
@ -367,7 +378,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public IPage<TestResultBusinessVO> queryTestResultPage(Page<TestResultBusinessVO> testResultBusinessVOPage, QueryTestResultPageDTO dto, Object... arg) { |
|
|
|
|
public IPage<TestResultBusinessVO> queryTestResultPage(Page<TestResultBusinessVO> testResultBusinessVOPage, QueryTestResultPageQuery dto, Object... arg) { |
|
|
|
|
DLPUser dlpUsers = (DLPUser) arg[0]; |
|
|
|
|
IPage<TestResultBusinessVO> testResultBusinessVOIPage = new Page<>(); |
|
|
|
|
/** 1 查询当前用户做了哪些实验 |
|
|
|
@ -1741,10 +1752,10 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl |
|
|
|
|
* @param businessIdList |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private QueryWrapper<TestResultBusinessVO> generateQueryWrapperByDTO(QueryTestResultPageDTO dto, Set<String> businessIdList) { |
|
|
|
|
private QueryWrapper<TestResultBusinessVO> generateQueryWrapperByDTO(QueryTestResultPageQuery dto, Set<String> businessIdList) { |
|
|
|
|
QueryWrapper<TestResultBusinessVO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
// 获取查询的关键字字段
|
|
|
|
|
String keyword = dto.getKeyword(); |
|
|
|
|
String keyword = dto.getKeywords(); |
|
|
|
|
queryWrapper.in("T.id", businessIdList); |
|
|
|
|
queryWrapper.eq("T.type", dto.getType()); |
|
|
|
|
queryWrapper.ge("T.status", 3); |
|
|
|
@ -1753,8 +1764,8 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl |
|
|
|
|
.and(StrUtil.isNotBlank(keyword), wrapper -> |
|
|
|
|
wrapper.like("T.case_name", keyword)); |
|
|
|
|
// 时间范围查询,包含开始时间和结束时间
|
|
|
|
|
queryWrapper.ge(dto.getStartTime() != null, "T.create_time", dto.getStartTime()) |
|
|
|
|
.le(dto.getEndTime() != null, "T.create_time", dto.getEndTime()); |
|
|
|
|
queryWrapper.ge(dto.getStartDate() != null, "T.create_time", dto.getStartDate()) |
|
|
|
|
.le(dto.getEndDate() != null, "T.create_time", dto.getEndDate()); |
|
|
|
|
// 根据创建时间进行排序
|
|
|
|
|
if (dto.getType().equals(20000)) { |
|
|
|
|
queryWrapper.orderByDesc("T.task_start_date"); |
|
|
|
@ -1779,74 +1790,89 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl |
|
|
|
|
* 自动创建测试记录样本数据 |
|
|
|
|
* |
|
|
|
|
* @param testId 测试记录的ID |
|
|
|
|
* @param compoundName 化合物名称 |
|
|
|
|
* @param reagentId 化合物名称 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void autoCreateData(String testId, String compoundName) { |
|
|
|
|
// 根据测试记录ID获取测试记录对象
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public void autoCreateData(String testId, String reagentId) { |
|
|
|
|
TestRecord testRecord = testRecordService.getById(testId); |
|
|
|
|
if (testRecord == null) { |
|
|
|
|
throw new CheckedException("Test record not found for ID: " + testId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 从测试记录中获取样本测试ID列表
|
|
|
|
|
List<String> sampleIdList = testRecord.getSampleTestList(); |
|
|
|
|
TestRecordReagentVO reagentVO = testRecordReagentService.getVOById(reagentId); |
|
|
|
|
if (reagentVO == null) { |
|
|
|
|
throw new CheckedException("Reagent not found for ID: " + reagentId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Drug drug = reagentVO.getDrug(); |
|
|
|
|
String compoundName = drug.getEnglishName(); |
|
|
|
|
|
|
|
|
|
// 根据样本ID列表查询样本信息列表
|
|
|
|
|
List<String> sampleIdList = testRecord.getSampleTestList(); |
|
|
|
|
List<SampleInfo> sampleInfos = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery() |
|
|
|
|
.in(SampleInfo::getId, sampleIdList)); |
|
|
|
|
|
|
|
|
|
// 用于存储生成的测试记录样本数据的列表
|
|
|
|
|
ArrayList<TestRecordSampleData> sampleDataList = new ArrayList<>(); |
|
|
|
|
List<TestRecordSampleData> sampleDataList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
TestRecordSampleData stdSampleData = createSampleData(compoundName, TestRecordSampleDataConstant.SAMPLE_TYPE_STD, TestRecordSampleDataConstant.SAMPLE_TYPE_STD + "-" + compoundName); |
|
|
|
|
sampleDataList.add(stdSampleData); |
|
|
|
|
|
|
|
|
|
// 创建一个标准样本数据对象
|
|
|
|
|
TestRecordSampleData data = new TestRecordSampleData(); |
|
|
|
|
// 设置化合物名称
|
|
|
|
|
data.setCompoundName(compoundName); |
|
|
|
|
// 设置样本编号,格式为 "STD-" 加上化合物名称
|
|
|
|
|
data.setSampleNo("STD-" + compoundName); |
|
|
|
|
// 设置样本类型为 "STD"
|
|
|
|
|
data.setSampleType("STD"); |
|
|
|
|
// 设置样本名称,格式为 "STD-" 加上化合物名称
|
|
|
|
|
data.setName("STD-" + compoundName); |
|
|
|
|
// 设置样本状态为 0
|
|
|
|
|
data.setStatus(0); |
|
|
|
|
// 生成一个32位的大写UUID作为样本数据ID
|
|
|
|
|
data.setId(IdWorker.get32UUID().toUpperCase()); |
|
|
|
|
|
|
|
|
|
// 将标准样本数据添加到样本数据列表中
|
|
|
|
|
sampleDataList.add(data); |
|
|
|
|
|
|
|
|
|
// 遍历样本信息列表,为每个样本创建对应的测试记录样本数据
|
|
|
|
|
sampleInfos.forEach(item -> { |
|
|
|
|
TestRecordSampleData sampleData = new TestRecordSampleData(); |
|
|
|
|
// 设置化合物名称
|
|
|
|
|
data.setCompoundName(compoundName); |
|
|
|
|
// 设置样本编号为样本的受理编号
|
|
|
|
|
data.setSampleNo(item.getAcceptNo()); |
|
|
|
|
// 设置样本类型为 "Analyte"
|
|
|
|
|
data.setSampleType("Analyte"); |
|
|
|
|
// 设置样本名称为样本的受理编号
|
|
|
|
|
data.setName(item.getAcceptNo()); |
|
|
|
|
// 设置样本状态为 0
|
|
|
|
|
data.setStatus(0); |
|
|
|
|
// 生成一个32位的大写UUID作为样本数据ID
|
|
|
|
|
data.setId(IdWorker.get32UUID().toUpperCase()); |
|
|
|
|
// 将样本数据添加到样本数据列表中
|
|
|
|
|
sampleDataList.add(data); |
|
|
|
|
TestRecordSampleData sampleData = createSampleData(compoundName, TestRecordSampleDataConstant.SAMPLE_TYPE_ANALYTE, item.getAcceptNo()); |
|
|
|
|
sampleDataList.add(sampleData); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (drug != null && StrUtil.isAllNotBlank(drug.getMainProductIon(), drug.getMinorProductIon(), drug.getCharacteristicIons())) { |
|
|
|
|
// 当对应的毒品信息不为空,添加扩展数据
|
|
|
|
|
List<TestRecordSampleDataExpand> testRecordSampleDataExpandList = sampleDataList.stream().flatMap(sampleData -> { |
|
|
|
|
List<TestRecordSampleDataExpand> testRecordSampleDataExpand = testRecordSampledataExpandService.saveExpDataByBusinessType(sampleData.getId(), drug, testRecord.getBusinessType()); |
|
|
|
|
return testRecordSampleDataExpand.stream(); |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
testRecordSampledataExpandService.saveBatch(testRecordSampleDataExpandList); |
|
|
|
|
} |
|
|
|
|
super.saveBatch(sampleDataList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建一个检验数据样本数据对象 |
|
|
|
|
* |
|
|
|
|
* @param compoundName 化合物名称 |
|
|
|
|
* @param sampleType 样本类型 |
|
|
|
|
* @param sampleNo 样本编号 |
|
|
|
|
* @return 返回创建的测试记录样本数据对象 |
|
|
|
|
*/ |
|
|
|
|
private TestRecordSampleData createSampleData(String compoundName, String sampleType, String sampleNo) { |
|
|
|
|
TestRecordSampleData data = new TestRecordSampleData(); |
|
|
|
|
data.setCompoundName(compoundName); |
|
|
|
|
data.setSampleNo(sampleNo); |
|
|
|
|
data.setSampleType(sampleType); |
|
|
|
|
data.setName(sampleNo); |
|
|
|
|
data.setStatus(TaskTestDataStatus.WAIT_REVIEW.getCode()); |
|
|
|
|
data.setId(IdWorker.getIdStr()); |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 自动删除指定测试记录和化合物名称对应的测试记录样本数据 |
|
|
|
|
* |
|
|
|
|
* @param testId 测试记录的ID |
|
|
|
|
* @param compoundName 化合物名称 |
|
|
|
|
* @param reagentId 化合物名称 |
|
|
|
|
* @return 如果删除成功返回 true,否则返回 false |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public boolean autoDelData(String testId, String compoundName) { |
|
|
|
|
// 根据测试记录ID和化合物名称删除对应的测试记录样本数据
|
|
|
|
|
return this.remove(Wrappers.<TestRecordSampleData>lambdaQuery() |
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
public boolean autoDelData(String testId, String reagentId) { |
|
|
|
|
TestRecordReagentVO reagentVO = testRecordReagentService.getVOById(reagentId); |
|
|
|
|
Drug drug = reagentVO.getDrug(); |
|
|
|
|
String compoundName = drug.getName(); |
|
|
|
|
List<TestRecordSampleData> removeDataList = this.list(Wrappers.<TestRecordSampleData>lambdaQuery() |
|
|
|
|
.eq(TestRecordSampleData::getTestId, testId) |
|
|
|
|
.eq(TestRecordSampleData::getCompoundName, compoundName)); |
|
|
|
|
List<String> removeIds = removeDataList.stream().map(TestRecordSampleData::getId).collect(Collectors.toList()); |
|
|
|
|
// 根据测试记录ID和化合物名称删除对应的测试记录样本数据
|
|
|
|
|
testRecordSampledataExpandService.remove(Wrappers.<TestRecordSampleDataExpand>lambdaQuery().in(TestRecordSampleDataExpand::getTestDataId, removeIds)); |
|
|
|
|
return this.removeBatchByIds(removeIds); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|