diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/constant/TestRecordSampleDataConstant.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/constant/TestRecordSampleDataConstant.java index 7935bd7..e89d9d1 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/constant/TestRecordSampleDataConstant.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/constant/TestRecordSampleDataConstant.java @@ -9,11 +9,11 @@ public interface TestRecordSampleDataConstant { double HAIR_CASE_NEGATIVE_RT_ERROR = -2.5; // 保留时间相对误差(正负2.5%) - - double HAIR_CASE_ION_ABUNDANCE_RATIO_1 = 0.5; // 离子丰度比 中的比较值1 50% + double HAIR_CASE_ION_ABUNDANCE_RATIO_1 = 50; // 离子丰度比 中的比较值1 50% - double HAIR_CASE_ION_ABUNDANCE_RATIO_2 = 0.2; // 离子丰度比 中的比较值2 20% + double HAIR_CASE_ION_ABUNDANCE_RATIO_2 = 20; // 离子丰度比 中的比较值2 20% - double HAIR_CASE_ION_ABUNDANCE_RATIO_3 = 0.1; // 离子丰度比 中的比较值3 10% + double HAIR_CASE_ION_ABUNDANCE_RATIO_3 = 10; // 离子丰度比 中的比较值3 10% double HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_1 = 20d; // 离子丰度比 > 50% 的最大允许偏差范围(正负20%) + diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/ProcessInspectDataService.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/ProcessInspectDataService.java new file mode 100644 index 0000000..2d7f092 --- /dev/null +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/ProcessInspectDataService.java @@ -0,0 +1,69 @@ +package digital.laboratory.platform.inspection.service; + +import digital.laboratory.platform.inspection.dto.HairSewageDataDto; + +import java.math.BigDecimal; + +/** + * @author ChenJiangBao + * @version 1.0 + * @description: 处理检验数据接口 + * @date 2025/3/24 9:56 + */ +public interface ProcessInspectDataService { + + //设置是否在误差范围内 + String getWithinErrorText(BigDecimal actualValue, BigDecimal expectedValue); + + //判断保留时间范围是否符合 + String getRtWithinErrorText(double targetRtErr, double errorRange); + + /** + * 计算离子丰度比 相对偏差 (目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100 + * + * @param ionAbundanceRatioWithinError 检测样本的丰度比偏差 + * @param stdIonAbundanceRatio 标准物质的离子丰度比 + */ + String calculateHairCaseIonAbundanceRatioWithinError(double ionAbundanceRatioWithinError, double stdIonAbundanceRatio); + + /** + * 计算离子丰度比偏差 + * + * @param sampleIonAbundanceRatio 目标物的离子丰度比 + * @param stdIonAbundanceRatio 标准物质的离子丰度比 + * @return + */ + double getAbundanceRatioErrorValue(double sampleIonAbundanceRatio, double stdIonAbundanceRatio); + + /** + * 计算相对误差 (目标物保留时间 - 标准物保留时间) / 标准物质保留时间 * 100 + * + * @param hairSewageDataDto + * @param hairSewageDataDtoStd + */ + void calculateHairCaseRtTimeError(HairSewageDataDto hairSewageDataDto, HairSewageDataDto hairSewageDataDtoStd); + + /** + * 计算保留时间的相对误差 + * + * @param targetRtTime 目标物保留时间信息 + * @param stdRtTime 标准物保留时间信息 + * @return + */ + double getHairCaseRtTimeError(double targetRtTime, double stdRtTime); + + /** + * 判断保留时间相对误差是否符合误差范围 + * + * @param rtTimeError + */ + String setHairCaseRtTimeWithinError(double rtTimeError); + + /** + * 获取碎片的丰度比偏差范围 + * + * @param abundanceRatio + * @return + */ + BigDecimal getErrorRange(BigDecimal abundanceRatio); +} diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java index 62b094c..f6cef54 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java @@ -362,7 +362,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { .in(TestRecordReagent::getId, testRecord.getReagentConsumablesList()) .eq(TestRecordReagent::getCategory, "标准物质")); - if (references == null || references.size() == 0) { + if (references == null || references.isEmpty()) { data.put("referenceMaterialName", "未找到试剂耗材数据!"); } else { @@ -377,7 +377,7 @@ public class InspectRecordServiceImpl implements InspectRecordService { .in(TestRecordReagent::getId, testRecord.getReagentConsumablesList()) .eq(TestRecordReagent::getCategory, "试剂")); - if (reagents == null || reagents.size() == 0) { + if (reagents == null || reagents.isEmpty()) { data.put("reagentConsumableName", "未找到试剂耗材数据!"); } else { String reagentConsumableName = reagents.stream() diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/ProcessInspectDataServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/ProcessInspectDataServiceImpl.java new file mode 100644 index 0000000..87ab0ac --- /dev/null +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/ProcessInspectDataServiceImpl.java @@ -0,0 +1,180 @@ +package digital.laboratory.platform.inspection.service.impl; + +import digital.laboratory.platform.inspection.constant.TestRecordSampleDataConstant; +import digital.laboratory.platform.inspection.dto.HairSewageDataDto; +import digital.laboratory.platform.inspection.service.ProcessInspectDataService; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; + +/** + * @author ChenJiangBao + * @version 1.0 + * @description: 处理检验数据接口 实现类 + * @date 2025/3/24 9:57 + */ +@Service +public class ProcessInspectDataServiceImpl implements ProcessInspectDataService { + + //设置是否在误差范围内 + @Override + public String getWithinErrorText(BigDecimal actualValue, BigDecimal expectedValue) { + if (actualValue.compareTo(expectedValue) < 0) { // actualValue < expectedValue + return TestRecordSampleDataConstant.IS; + } else { + return TestRecordSampleDataConstant.NO; + } + } + + + //判断保留时间范围是否符合 + @Override + public String getRtWithinErrorText(double targetRtErr, double errorRange) { + if (targetRtErr < errorRange) { + return TestRecordSampleDataConstant.IS; + } else { + return TestRecordSampleDataConstant.NO; + } + + } + + /** + * 计算离子丰度比 相对偏差 (目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100 + * + * @param ionAbundanceRatioWithinError 检测样本的丰度比偏差 + * @param stdIonAbundanceRatio 标准物质的离子丰度比 + */ + @Override + public String calculateHairCaseIonAbundanceRatioWithinError(double ionAbundanceRatioWithinError, double stdIonAbundanceRatio) { + + // 判断是否在离子丰度比允许的最大偏差范围 + if (stdIonAbundanceRatio > TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_1) { + + return setHairCaseWhetherCheckOut( + ionAbundanceRatioWithinError, + TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_1, + TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_1); + + } else if (stdIonAbundanceRatio > TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_2 + && stdIonAbundanceRatio <= TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_1) { + + return setHairCaseWhetherCheckOut( + ionAbundanceRatioWithinError, + TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_2, + TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_2); + + } else if (stdIonAbundanceRatio > TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_3 + && stdIonAbundanceRatio <= TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_2) { + + return setHairCaseWhetherCheckOut( + ionAbundanceRatioWithinError, + TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_3, + TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_3); + } else { + return setHairCaseWhetherCheckOut( + ionAbundanceRatioWithinError, + TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_4, + TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_4); + } + } + + /** + * 计算离子丰度比偏差 + * + * @param sampleIonAbundanceRatio 目标物的离子丰度比 + * @param stdIonAbundanceRatio 标准物质的离子丰度比 + * @return + */ + @Override + public double getAbundanceRatioErrorValue(double sampleIonAbundanceRatio, double stdIonAbundanceRatio) { + double diffValue = sampleIonAbundanceRatio - stdIonAbundanceRatio; + double abundanceRatioErrorValue = Math.abs(diffValue) / stdIonAbundanceRatio * 100; + return abundanceRatioErrorValue; + } + + /** + * 计算相对误差 (目标物保留时间 - 标准物保留时间) / 标准物质保留时间 * 100 + * + * @param hairSewageDataDto + * @param hairSewageDataDtoStd + */ + @Override + public void calculateHairCaseRtTimeError(HairSewageDataDto hairSewageDataDto, HairSewageDataDto hairSewageDataDtoStd) { + if ( !TestRecordSampleDataConstant.isInvalidValue(hairSewageDataDto.getTargetRtTime()) ) { + // 计算保留时间的相对误差 + double rtTimeError = getHairCaseRtTimeError(hairSewageDataDto.getTargetRtTime(), hairSewageDataDtoStd.getStdRtTime()); + hairSewageDataDto.setRtTimeError(rtTimeError); + // 判断保留时间相对误差是否符合误差范围 + hairSewageDataDto.setRtTimeWithinError(setHairCaseRtTimeWithinError(hairSewageDataDto.getRtTimeError())); + } else { + hairSewageDataDto.setRtTimeError(TestRecordSampleDataConstant.INVALID_VALUE); + hairSewageDataDto.setRtTimeWithinError("/"); + } + } + + /** + * 计算保留时间的相对误差 + * + * @param targetRtTime 目标物保留时间信息 + * @param stdRtTime 标准物保留时间信息 + * @return + */ + @Override + public double getHairCaseRtTimeError(double targetRtTime, double stdRtTime) { + return (targetRtTime - stdRtTime) / stdRtTime * 100; + } + + /** + * 判断保留时间相对误差是否符合误差范围 + * + * @param rtTimeError + */ + @Override + public String setHairCaseRtTimeWithinError(double rtTimeError) { + if (rtTimeError > TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_RT_ERROR + && rtTimeError < TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_RT_ERROR) { + return TestRecordSampleDataConstant.IS; + } else { + return TestRecordSampleDataConstant.NO; + } + } + + /** + * 获取碎片的丰度比偏差范围 + * + * @param abundanceRatio + * @return + */ + @Override + public BigDecimal getErrorRange(BigDecimal abundanceRatio) { + double retValue; + if (abundanceRatio.compareTo(BigDecimal.valueOf(50)) > 0) { // abundanceRatio > 50 + retValue = 10; + } else if (abundanceRatio.compareTo(BigDecimal.valueOf(20)) > 0) { // abundanceRatio > 20 + retValue = 15; + } else if (abundanceRatio.compareTo(BigDecimal.valueOf(10)) > 0) { // abundanceRatio > 10 + retValue = 20; + } else { + retValue = 50; + } + return BigDecimal.valueOf(retValue); + } + + + /** + * 根据计算出来的离子丰度比误差来判断是否检出 + * + * @param ionAbundanceRatioWithinError + * @param positive + * @param negative + */ + private String setHairCaseWhetherCheckOut(double ionAbundanceRatioWithinError, double positive, double negative) { + if (ionAbundanceRatioWithinError < positive + && ionAbundanceRatioWithinError > negative) { + return TestRecordSampleDataConstant.IS; + } else { + return TestRecordSampleDataConstant.NO; + } + } + +} diff --git a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java index 3fefd72..cf081b7 100644 --- a/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java +++ b/dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java @@ -54,6 +54,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -107,6 +108,9 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl { // int size = testRecordSampleSolutionsNoList.size(); // 这里判断了如果不是检材也返回true,是检材的话判断是不是这个业务id下的检材,根据编号判断 - if (!item.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_ANALYTE) || + return !item.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_ANALYTE) || (item.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_ANALYTE) && testRecordSampleSolutionsNoList.contains(item.getSampleNo()) - )) { - return true; - } else { - return false; - } + ); }).collect(Collectors.toList()); ESTBusinessInfoVO estBusinessInfoVO = estBusinessInfoVOS.get(0); // 封装的结果集 @@ -970,12 +970,13 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_1) { - - setHairCaseWhetherCheckOut( - hairSewageDataDto, - TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_1, - TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_1); - - } else if (stdIonAbundanceRatio > TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_2 - && stdIonAbundanceRatio <= TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_1) { - - setHairCaseWhetherCheckOut( - hairSewageDataDto, - TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_2, - TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_2); - - } else if (stdIonAbundanceRatio > TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_3 - && stdIonAbundanceRatio <= TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_2) { - - setHairCaseWhetherCheckOut( - hairSewageDataDto, - TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_3, - TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_3); - } else if (stdIonAbundanceRatio <= TestRecordSampleDataConstant.HAIR_CASE_ION_ABUNDANCE_RATIO_3) { - setHairCaseWhetherCheckOut( - hairSewageDataDto, - TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_MAX_ALLOW_ERROR_4, - TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_MAX_ALLOW_ERROR_4); - } - } else { - hairSewageDataDto.setIonAbundanceRatioWithinError(TestRecordSampleDataConstant.INVALID_VALUE); - hairSewageDataDto.setWhetherCheckOut("/"); - } - } - - /** - * 根据计算出来的离子丰度比误差来判断是否检出 - * - * @param hairSewageDataDto - * @param positive - * @param negative - */ - private void setHairCaseWhetherCheckOut(HairSewageDataDto hairSewageDataDto, double positive, double negative) { - if (hairSewageDataDto.getIonAbundanceRatioWithinError() < positive - && hairSewageDataDto.getIonAbundanceRatioWithinError() > negative) { - hairSewageDataDto.setWhetherCheckOut(TestRecordSampleDataConstant.IS); - hairSewageDataDto.setIsDetected(1); - } else { - hairSewageDataDto.setWhetherCheckOut(TestRecordSampleDataConstant.NO); - hairSewageDataDto.setIsDetected(0); - } - } - - /** - * 计算相对误差 (目标物保留时间 - 标准物保留时间) / 标准物质保留时间 * 100 - * - * @param hairSewageDataDto - * @param hairSewageDataDtoStd - */ - private void calculateHairCaseRtTimeError(HairSewageDataDto hairSewageDataDto, HairSewageDataDto hairSewageDataDtoStd) { - if ( !TestRecordSampleDataConstant.isInvalidValue(hairSewageDataDto.getTargetRtTime()) ) { - // 计算保留时间的相对误差 - double rtTimeError = getHairCaseRtTimeError(hairSewageDataDto.getTargetRtTime(), hairSewageDataDtoStd.getStdRtTime()); - hairSewageDataDto.setRtTimeError(rtTimeError); - // 判断保留时间相对误差是否符合误差范围 - hairSewageDataDto.setRtTimeWithinError(setHairCaseRtTimeWithinError(hairSewageDataDto.getRtTimeError())); - } else { - hairSewageDataDto.setRtTimeError(TestRecordSampleDataConstant.INVALID_VALUE); - hairSewageDataDto.setRtTimeWithinError("/"); - } - } - - /** - * 计算保留时间的相对误差 - * - * @param targetRtTime 目标物保留时间信息 - * @param stdRtTime 标准物保留时间信息 - * @return - */ - private double getHairCaseRtTimeError(double targetRtTime, double stdRtTime) { - return (targetRtTime - stdRtTime) / stdRtTime * 100; - } - - /** - * 判断保留时间相对误差是否符合误差范围 - * - * @param rtTimeError - */ - private String setHairCaseRtTimeWithinError(double rtTimeError) { - if (rtTimeError > TestRecordSampleDataConstant.HAIR_CASE_NEGATIVE_RT_ERROR - && rtTimeError < TestRecordSampleDataConstant.HAIR_CASE_POSITIVE_RT_ERROR) { - return TestRecordSampleDataConstant.IS; - } else { - return TestRecordSampleDataConstant.NO; - } - } /** * 设置标准物的溶液浓度 @@ -1378,18 +1267,18 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl testRecordSampleDataList_std) { List retStd = testRecordSampleDataList_std.stream() @@ -1495,39 +1365,6 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl 0.5) { - retValue = 10; - } else if (abundanceRatio > 0.2) { - retValue = 15; - } else if (abundanceRatio > 0.1) { - retValue = 20; - } else { - retValue = 50; - } - return retValue; - } - private double getStdCorrespondingAbundanceRatio(String massValue, String compoundName, List testRecordSampleDataList_std) { double retValue = 0; //根据化合物名称找出对应的标准品 @@ -1890,15 +1727,17 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl implements TestRecordSampledataExpandService{ + @Resource + private TestRecordService testRecordService; + @Resource private TestRecordSampleDataService testRecordSampleDataService; + @Resource + private ProcessInspectDataService processInspectDataService; + /** * 封装处理毛发案件、任务等检验扩展数据信息 * @param hairSewageDataDto @@ -154,6 +163,7 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl stdDataExpandList = null; if (!testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) { TestRecordSampleData stdTestSampleData = testRecordSampleDataService.getOne(Wrappers.lambdaQuery().eq(TestRecordSampleData::getTestId, testRecordSampleData.getTestId()).eq(TestRecordSampleData::getCompoundName, testRecordSampleData.getCompoundName()).eq(TestRecordSampleData::getSampleType, TestRecordSampleDataConstant.SAMPLE_TYPE_STD)); @@ -169,10 +179,15 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl