|
|
|
@ -26,6 +26,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -85,8 +86,7 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecor |
|
|
|
|
// 检验数据
|
|
|
|
|
List<NPSTestDetailDataStruct> npsTestSampleDataList = npsCaseTestDataDto.getTestSampleDataList(); |
|
|
|
|
|
|
|
|
|
List<TestRecordSampleDataExpand> testRecordSampleDataExpandList = npsTestSampleDataList.stream().map(item -> { |
|
|
|
|
return createTestRecordSampleDataExpand( |
|
|
|
|
List<TestRecordSampleDataExpand> testRecordSampleDataExpandList = npsTestSampleDataList.stream().map(item -> createTestRecordSampleDataExpand( |
|
|
|
|
testDataId, |
|
|
|
|
item.getIsBasePeak() == 1 ? Boolean.TRUE : Boolean.FALSE, |
|
|
|
|
item.getArea(), |
|
|
|
@ -96,8 +96,7 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecor |
|
|
|
|
item.getRetTime(), |
|
|
|
|
item.getMass(), |
|
|
|
|
null, null |
|
|
|
|
); |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
)).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
return testRecordSampleDataExpandList; |
|
|
|
|
} |
|
|
|
@ -182,8 +181,13 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecor |
|
|
|
|
} |
|
|
|
|
List<TestRecordSampleDataExpand> finalStdDataExpandList = stdDataExpandList; |
|
|
|
|
testRecordSampleData.setIsDetected(1); // 默认检出
|
|
|
|
|
boolean isNPSCase = testRecord.getBusinessType().equals(BusinessType.NPS_CASE.getBusinessType()); // 是否是常规毒品案件
|
|
|
|
|
value.forEach(sampleDataExpand -> { |
|
|
|
|
calculateIonAbundanceRatio(basePeakData, testRecord, finalStdDataExpandList, sampleDataExpand); |
|
|
|
|
if (isNPSCase) { |
|
|
|
|
calculateIonAbundanceRatioNormal(finalStdDataExpandList, sampleDataExpand); |
|
|
|
|
} else { |
|
|
|
|
calculateIonAbundanceRatioBiology(basePeakData, finalStdDataExpandList, sampleDataExpand); |
|
|
|
|
} |
|
|
|
|
if ( |
|
|
|
|
!isSTDSample && |
|
|
|
|
testRecordSampleData.getIsDetected().equals(1) && |
|
|
|
@ -253,47 +257,67 @@ public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecor |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算离子丰度比 |
|
|
|
|
* 计算离子丰度比(生物样本) |
|
|
|
|
* |
|
|
|
|
* @param basePeakData 基准峰数据 |
|
|
|
|
* @param testRecord 测试记录 |
|
|
|
|
* @param finalStdDataExpandList 最终标准数据扩展列表 |
|
|
|
|
* @param sampleDataExpand 样本数据扩展 |
|
|
|
|
*/ |
|
|
|
|
private void calculateIonAbundanceRatio(TestRecordSampleDataExpand basePeakData, TestRecord testRecord, List<TestRecordSampleDataExpand> finalStdDataExpandList, TestRecordSampleDataExpand sampleDataExpand) { |
|
|
|
|
private void calculateIonAbundanceRatioBiology(TestRecordSampleDataExpand basePeakData, List<TestRecordSampleDataExpand> finalStdDataExpandList, TestRecordSampleDataExpand sampleDataExpand) { |
|
|
|
|
if (sampleDataExpand.getPeakArea() != null && basePeakData.getPeakArea() != null) { |
|
|
|
|
sampleDataExpand.setIonAbundanceRatio(sampleDataExpand.getPeakArea().divide(basePeakData.getPeakArea(), 5, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100))); |
|
|
|
|
sampleDataExpand.setIonAbundanceRatio(sampleDataExpand.getPeakArea().divide(basePeakData.getPeakArea(), 5, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100))); |
|
|
|
|
if (CollUtil.isNotEmpty(finalStdDataExpandList)) { |
|
|
|
|
finalStdDataExpandList.forEach(stdDataExpand -> { |
|
|
|
|
boolean matched = false; // 匹配对应的标准物质数据
|
|
|
|
|
boolean isNPSCase = testRecord.getBusinessType().equals(BusinessType.NPS_CASE.getBusinessType()); // 是否是常规毒品案件
|
|
|
|
|
if (isNPSCase) { |
|
|
|
|
matched = stdDataExpand.getMassToChargeRatio().equals(sampleDataExpand.getMassToChargeRatio()); |
|
|
|
|
} else { |
|
|
|
|
matched = stdDataExpand.getQualitativeIonPair().equals(sampleDataExpand.getQualitativeIonPair()); |
|
|
|
|
} |
|
|
|
|
if (matched) { |
|
|
|
|
if (stdDataExpand.getQualitativeIonPair().equals(sampleDataExpand.getQualitativeIonPair())) { |
|
|
|
|
BigDecimal ionAbundanceRatioError = sampleDataExpand.getIonAbundanceRatio() |
|
|
|
|
.subtract(stdDataExpand.getIonAbundanceRatio()) |
|
|
|
|
.divide(stdDataExpand.getIonAbundanceRatio(), 5, BigDecimal.ROUND_HALF_UP) |
|
|
|
|
.divide(stdDataExpand.getIonAbundanceRatio(), 5, RoundingMode.HALF_UP) |
|
|
|
|
.multiply(BigDecimal.valueOf(100)); |
|
|
|
|
sampleDataExpand.setIonAbundanceRatioError(ionAbundanceRatioError); |
|
|
|
|
if (isNPSCase) { |
|
|
|
|
// 取绝对值的原因是简化逻辑,不然需要判断正负值的范围
|
|
|
|
|
sampleDataExpand.setIonAbundanceRatioWithinError( |
|
|
|
|
processInspectDataService.getWithinErrorText( |
|
|
|
|
ionAbundanceRatioError.abs(), |
|
|
|
|
processInspectDataService.getErrorRange(stdDataExpand.getIonAbundanceRatio()) |
|
|
|
|
sampleDataExpand.setMaxAllowedIonRatioDeviation( |
|
|
|
|
BigDecimal.valueOf( |
|
|
|
|
processInspectDataService.getHairCaseIonAbundanceRatioWithinErrorRange(stdDataExpand.getIonAbundanceRatio().doubleValue()) |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
sampleDataExpand.setIonAbundanceRatioWithinError( |
|
|
|
|
processInspectDataService.calculateHairCaseIonAbundanceRatioWithinError( |
|
|
|
|
ionAbundanceRatioError.doubleValue(), |
|
|
|
|
stdDataExpand.getIonAbundanceRatio().doubleValue() |
|
|
|
|
sampleDataExpand.getMaxAllowedIonRatioDeviation().doubleValue() |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
log.warn("没有找到匹配的标准物质检验数据!"); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算离子丰度比 (常规毒品) |
|
|
|
|
* |
|
|
|
|
* @param finalStdDataExpandList 最终标准数据扩展列表 |
|
|
|
|
* @param sampleDataExpand 样本数据扩展 |
|
|
|
|
*/ |
|
|
|
|
private void calculateIonAbundanceRatioNormal(List<TestRecordSampleDataExpand> finalStdDataExpandList, TestRecordSampleDataExpand sampleDataExpand) { |
|
|
|
|
// 常规毒品的不需要去填写峰面积,直接填丰度比的值
|
|
|
|
|
if ( sampleDataExpand.getIonAbundanceRatio() != null) { |
|
|
|
|
if (CollUtil.isNotEmpty(finalStdDataExpandList)) { |
|
|
|
|
finalStdDataExpandList.forEach(stdDataExpand -> { |
|
|
|
|
if (stdDataExpand.getMassToChargeRatio().equals(sampleDataExpand.getMassToChargeRatio())) { |
|
|
|
|
BigDecimal ionAbundanceRatioError = sampleDataExpand.getIonAbundanceRatio() |
|
|
|
|
.subtract(stdDataExpand.getIonAbundanceRatio()) |
|
|
|
|
.divide(stdDataExpand.getIonAbundanceRatio(), 5, RoundingMode.HALF_UP) |
|
|
|
|
.multiply(BigDecimal.valueOf(100)); |
|
|
|
|
sampleDataExpand.setIonAbundanceRatioError(ionAbundanceRatioError); |
|
|
|
|
sampleDataExpand.setMaxAllowedIonRatioDeviation(processInspectDataService.getErrorRange(stdDataExpand.getIonAbundanceRatio())); |
|
|
|
|
// 取绝对值的原因是简化逻辑,不然需要判断正负值的范围
|
|
|
|
|
sampleDataExpand.setIonAbundanceRatioWithinError( |
|
|
|
|
processInspectDataService.getWithinErrorText( |
|
|
|
|
ionAbundanceRatioError.abs(), |
|
|
|
|
sampleDataExpand.getMaxAllowedIonRatioDeviation() |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
log.warn("没有找到匹配的标准物质检验数据!"); |
|
|
|
|
} |
|
|
|
|