20250414 更新

1.在检验扩展数据表添加字段离子丰度比最大允许相对偏差
2.根据委托类型拆分计算方法
master
陈江保 3 days ago
parent ff745d6217
commit 43b58ed5ec
  1. 5
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/entity/TestRecordSampleDataExpand.java
  2. 76
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.java
  3. 10
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/vo/TestRecordSampleDataExpandVO.java
  4. 3
      dlp-drugtesting-biz/src/main/resources/mapper/TestRecordSampleDataExpandMapper.xml

@ -65,4 +65,9 @@ public class TestRecordSampleDataExpand extends BaseEntity {
* 定性离子对生物案件使用
*/
private String qualitativeIonPair;
/**
* 离子丰度比最大允许相对偏差 存入的是数值但是默认是正负符合如10实际上指的是+10或-10
*/
private BigDecimal maxAllowedIonRatioDeviation;
}

@ -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("没有找到匹配的标准物质检验数据!");
}

@ -49,6 +49,9 @@ public class TestRecordSampleDataExpandVO {
@ApiModelProperty(value = "定性离子对,生物案件使用", example = "C6H12O6")
private String qualitativeIonPair;
@ApiModelProperty(value = "离子丰度比最大允许相对偏差, 存入的是数值,但是默认是正负符合,如10,实际上指的是+10或-10")
private BigDecimal maxAllowedIonRatioDeviation;
/************************ 处理需要特定格式返回的字段 **************************/
public String getIonAbundanceRatio() {
@ -71,5 +74,12 @@ public class TestRecordSampleDataExpandVO {
}
return ionAbundanceRatioWithinError;
}
public String getMaxAllowedIonRatioDeviation() {
if (getBasePeak()) {
return TestRecordSampleDataConstant.INVALID_VALUE_STR;
}
return "±" + maxAllowedIonRatioDeviation;
}
}

@ -15,6 +15,7 @@
<result property="fragmentRetTime" column="fragment_ret_time" jdbcType="DECIMAL"/>
<result property="massToChargeRatio" column="mass_to_charge_ratio" jdbcType="DECIMAL"/>
<result property="qualitativeIonPair" column="qualitative_ion_pair" jdbcType="VARCHAR"/>
<result property="maxAllowedIonRatioDeviation" column="max_allowed_ion_ratio_deviation" jdbcType="DECIMAL"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
@ -32,6 +33,7 @@
<result property="fragmentRetTime" column="fragment_ret_time" jdbcType="DECIMAL"/>
<result property="massToChargeRatio" column="mass_to_charge_ratio" jdbcType="DECIMAL"/>
<result property="qualitativeIonPair" column="qualitative_ion_pair" jdbcType="VARCHAR"/>
<result property="maxAllowedIonRatioDeviation" column="max_allowed_ion_ratio_deviation" jdbcType="DECIMAL"/>
</resultMap>
<sql id="Base_Column_List">
@ -45,6 +47,7 @@
exp.ion_abundance_ratio_within_error,
exp.mass_to_charge_ratio,
exp.qualitative_ion_pair,
exp.max_allowed_ion_ratio_deviation,
exp.create_by,
exp.create_time,
exp.update_by,

Loading…
Cancel
Save