20250324 更新

1.实现更新实验扩展数据时计算丰度比以及丰度比偏差
master
陈江保 5 days ago
parent 795ff83e1e
commit 3242d66835
  1. 6
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/constant/TestRecordSampleDataConstant.java
  2. 69
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/ProcessInspectDataService.java
  3. 4
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/InspectRecordServiceImpl.java
  4. 180
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/ProcessInspectDataServiceImpl.java
  5. 209
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampleDataServiceImpl.java
  6. 17
      dlp-drugtesting-biz/src/main/java/digital/laboratory/platform/inspection/service/impl/TestRecordSampledataExpandServiceImpl.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%) +

@ -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);
}

@ -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()

@ -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;
}
}
}

@ -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<TestRecordSampl
@Resource
private TestRecordReagentService testRecordReagentService;
@Resource
private ProcessInspectDataService processInspectDataService;
/**
* 校验实验状态是否完成完成则提升不能修改数据
*
@ -193,14 +197,10 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
.last("ORDER BY SUBSTRING_INDEX(name, '-', -1) + 0")).stream().filter(item -> {
// 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<TestRecordSampl
// 离子丰度比
if (hairCompoundData.getRatioActual() == null) {
if (hairCompoundData.getArea() != null && hairCompoundData.getArea1() != null) {
hairSewageDataDto.setIonAbundanceRatio(hairCompoundData.getArea1() / hairCompoundData.getArea());
hairSewageDataDto.setIonAbundanceRatio(hairCompoundData.getArea1() / hairCompoundData.getArea() * 100);
} else {
hairSewageDataDto.setIonAbundanceRatio(TestRecordSampleDataConstant.INVALID_VALUE);
}
} else {
hairSewageDataDto.setIonAbundanceRatio(hairCompoundData.getRatioActual());
// 从文件中获取到的丰度比并没有乘以100
hairSewageDataDto.setIonAbundanceRatio(hairCompoundData.getRatioActual() * 100);
}
Double rtTime = hairCompoundData.getRtTime() == null ? TestRecordSampleDataConstant.INVALID_VALUE : hairCompoundData.getRtTime(); // 取文件的保留时间
hairSewageDataDto.setTargetRtTime(rtTime); // 目标物保留时间, 标准物质的保留时间同时存在 TargetRtTime 和 StdRtTime
@ -1011,129 +1012,17 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
// 设置标准物质浓度
HairSewageDataDto hairSewageDataDtoStd = stdMap.get(hairSewageDataDto.getCompoundName()); // 获取化合物下的标准物质信息
if (hairSewageDataDtoStd != null) {
// hairSewageDataDto.setConcentration(hairSewageDataDtoStd.getStdConcentration());
// hairSewageDataDto.setStdRtTime(hairSewageDataDtoStd.getStdRtTime());
// 计算相对误差 (目标物保留时间 - 标准物保留时间) / 标准物质保留时间 * 100
calculateHairCaseRtTimeError(hairSewageDataDto, hairSewageDataDtoStd);
processInspectDataService.calculateHairCaseRtTimeError(hairSewageDataDto, hairSewageDataDtoStd);
// 计算离子丰度比 相对偏差 (目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100
calculateHairCaseIonAbundanceRatioWithinError(hairSewageDataDto, hairSewageDataDtoStd);
hairSewageDataDto.setIonAbundanceRatioWithinError(processInspectDataService.getAbundanceRatioErrorValue(hairSewageDataDto.getIonAbundanceRatio(), hairSewageDataDtoStd.getIonAbundanceRatio()));
hairSewageDataDto.setWhetherCheckOut(processInspectDataService.calculateHairCaseIonAbundanceRatioWithinError(hairSewageDataDto.getIonAbundanceRatioWithinError(), hairSewageDataDtoStd.getIonAbundanceRatio()));
hairSewageDataDto.setIsDetected(hairSewageDataDto.getWhetherCheckOut().equals(TestRecordSampleDataConstant.IS) ? 1 : 0);
}
// else {
// log.info("没有找到该标准溶液,化合物 {} 样本ID {}", hairSewageDataDto.getCompoundName(), hairSewageDataDto.getSampleNo());
// hairSewageDataDto.setStdConcentration("-1");
// hairSewageDataDto.setStdRtTime(TestRecordSampleDataConstant.INVALID_VALUE);
// }
});
return testRecordSampleDataListAnalyte;
}
/**
* 计算离子丰度比 相对偏差 (目标物离子丰度比 - 标准物离子丰度比) / 标准物质离子丰度比 * 100
*
* @param hairSewageDataDto
* @param hairSewageDataDtoStd
*/
private void calculateHairCaseIonAbundanceRatioWithinError(HairSewageDataDto hairSewageDataDto, HairSewageDataDto hairSewageDataDtoStd) {
if ( !TestRecordSampleDataConstant.isInvalidValue(hairSewageDataDto.getIonAbundanceRatio()) ) {
double ionAbundanceRatioWithinError = getAbundanceRatioErrorValue(hairSewageDataDto.getIonAbundanceRatio(), hairSewageDataDtoStd.getIonAbundanceRatio());
hairSewageDataDto.setIonAbundanceRatioWithinError(ionAbundanceRatioWithinError);
double stdIonAbundanceRatio = hairSewageDataDtoStd.getIonAbundanceRatio();
// 判断是否在离子丰度比允许的最大偏差范围
if (stdIonAbundanceRatio > 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<TestRecordSampl
double mzValue = npsTestDetailDataStruct.getArea() / npsTestDetailDataStruct_Base.getArea() * 100;
npsTestDetailDataStruct.setAbundanceRatio(mzValue);
//设置误差范围,基峰不用设置误差范围
double errorRange = getErrorRange(mzValue);
npsTestDetailDataStruct.setErrorRange(errorRange);
BigDecimal errorRange = processInspectDataService.getErrorRange(BigDecimal.valueOf(mzValue));
npsTestDetailDataStruct.setErrorRange(errorRange.doubleValue());
//设置标准品的丰度比
double stdCorrespondingAbundanceRatio = getStdCorrespondingAbundanceRatio(npsTestDetailDataStruct.getMass(),
npsTestDetailDataStruct.getName(), testRecordSampleDataList_std);
npsTestDetailDataStruct.setAbundanceRatio_std(stdCorrespondingAbundanceRatio);
//设置偏差,公式是 样品-标准品/标准品
double abundanceRatioErrorValue = getAbundanceRatioErrorValue(npsTestDetailDataStruct.getAbundanceRatio(),
double abundanceRatioErrorValue = processInspectDataService.getAbundanceRatioErrorValue(npsTestDetailDataStruct.getAbundanceRatio(),
npsTestDetailDataStruct.getAbundanceRatio_std());
npsTestDetailDataStruct.setAbundanceRatioError(abundanceRatioErrorValue);
//设置是否在误差范围内
String withinErrorText = getWithinErrorText(npsTestDetailDataStruct.getAbundanceRatioError(), npsTestDetailDataStruct.getErrorRange());
String withinErrorText = processInspectDataService.getWithinErrorText(BigDecimal.valueOf(npsTestDetailDataStruct.getAbundanceRatioError()), BigDecimal.valueOf(npsTestDetailDataStruct.getErrorRange()));
npsTestDetailDataStruct.setWithinError(withinErrorText);
otherList.add(npsTestDetailDataStruct);
} else {
@ -1411,7 +1300,7 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
double tmp1 = (sampleRetTime - stdRtTime) / stdRtTime;
tmp1 = Math.abs(tmp1) * 100;
npsCaseTestDataDto.setRtTimeError(tmp1);
String rtWithinErrorText = getRtWithinErrorText(tmp1, 1);
String rtWithinErrorText = processInspectDataService.getRtWithinErrorText(tmp1, 1);
npsCaseTestDataDto.setRtTimeWithinError(rtWithinErrorText);
//设置碎片峰的结果,条件是 除了基峰外的所有特征碎片都满足 离子丰度误差,才算是检出条件之一
int isOk = checkOtherFragmentResult(otherList);
@ -1462,25 +1351,6 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
return npsTestDetailDataStruct_Base;
}
//设置是否在误差范围内
private String getWithinErrorText(double actualValue, double expectedValue) {
if (actualValue < expectedValue) {
return TestRecordSampleDataConstant.IS;
} else {
return TestRecordSampleDataConstant.NO;
}
}
//判断保留时间范围是否符合
private String getRtWithinErrorText(double targetRtErr, double errorRange) {
if (targetRtErr < errorRange) {
return TestRecordSampleDataConstant.IS;
} else {
return TestRecordSampleDataConstant.NO;
}
}
//查找标准品的保留时间
private double findStdRtTime(String compoundName, List<NPSCaseTestDataDto> testRecordSampleDataList_std) {
List<NPSCaseTestDataDto> retStd = testRecordSampleDataList_std.stream()
@ -1495,39 +1365,6 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
}
}
/**
* 计算离子丰度比偏差
*
* @param sampleIonAbundanceRatio 目标物的离子丰度比
* @param stdIonAbundanceRatio 标准物质的离子丰度比
* @return
*/
private double getAbundanceRatioErrorValue(double sampleIonAbundanceRatio, double stdIonAbundanceRatio) {
double diffValue = sampleIonAbundanceRatio - stdIonAbundanceRatio;
double abundanceRatioErrorValue = Math.abs(diffValue) / stdIonAbundanceRatio * 100;
return abundanceRatioErrorValue;
}
/**
* 获取碎片的丰度比偏差范围
*
* @param abundanceRatio
* @return
*/
private double getErrorRange(double abundanceRatio) {
double retValue = 0;
if (abundanceRatio > 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<NPSCaseTestDataDto> testRecordSampleDataList_std) {
double retValue = 0;
//根据化合物名称找出对应的标准品
@ -1890,15 +1727,17 @@ public class TestRecordSampleDataServiceImpl extends ServiceImpl<TestRecordSampl
if ( data.getTargetRtTime() != null && std.getTargetRtTime() != null ) {
TestRecord testRecord = testRecordService.getById(data.getTestId());
if (testRecord.getBusinessType().equals(BusinessType.BOINT_CASE.getBusinessType())) {
data.setRtTimeError(processInspectDataService.getHairCaseRtTimeError(data.getTargetRtTime(), std.getStdRtTime()));
data.setRtTimeWithinError(
setHairCaseRtTimeWithinError(
getHairCaseRtTimeError(data.getTargetRtTime(), std.getStdRtTime())
processInspectDataService.setHairCaseRtTimeWithinError(
data.getRtTimeError()
)
);
} else {
data.setRtTimeError(processInspectDataService.getHairCaseRtTimeError(data.getTargetRtTime(), std.getStdRtTime()));
data.setRtTimeWithinError(
getRtWithinErrorText(
Math.abs(getHairCaseRtTimeError(data.getTargetRtTime(), std.getStdRtTime())),
processInspectDataService.getRtWithinErrorText(
Math.abs(data.getRtTimeError()),
1
)
);

@ -14,9 +14,12 @@ import digital.laboratory.platform.inspection.dto.HairSewageDataDto;
import digital.laboratory.platform.inspection.dto.NPSCaseTestDataDto;
import digital.laboratory.platform.inspection.entity.TestRecordSampleDataExpand;
import digital.laboratory.platform.inspection.mapper.TestRecordSampleDataExpandMapper;
import digital.laboratory.platform.inspection.service.ProcessInspectDataService;
import digital.laboratory.platform.inspection.service.TestRecordSampleDataService;
import digital.laboratory.platform.inspection.service.TestRecordSampledataExpandService;
import digital.laboratory.platform.inspection.service.TestRecordService;
import digital.laboratory.platform.inspection.utils.datafile.nps.NPSTestDetailDataStruct;
import digital.laboratory.platform.inspetion.api.entity.TestRecord;
import digital.laboratory.platform.sys.entity.Drug;
import org.springframework.stereotype.Service;
@ -36,9 +39,15 @@ import java.util.stream.Collectors;
public class TestRecordSampledataExpandServiceImpl extends ServiceImpl<TestRecordSampleDataExpandMapper, TestRecordSampleDataExpand>
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<TestRecor
if (!sampleDataExpand.getBasePeak() && basePeakData != null) {
// 获取标准物质的扩展信息,1 先查询对应的实验数据 2 根据实验数据的实验id以及化合物以及类型获取标准物质的实验数据信息 3 根据标准物质实验数据id取对应的扩展数据
TestRecordSampleData testRecordSampleData = testRecordSampleDataService.getById(sampleDataExpand.getTestDataId());
TestRecord testRecord = testRecordService.getById(testRecordSampleData.getTestId());
List<TestRecordSampleDataExpand> stdDataExpandList = null;
if (!testRecordSampleData.getSampleType().equals(TestRecordSampleDataConstant.SAMPLE_TYPE_STD)) {
TestRecordSampleData stdTestSampleData = testRecordSampleDataService.getOne(Wrappers.<TestRecordSampleData>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<TestRecor
.divide(stdDataExpand.getIonAbundanceRatio(), 5, BigDecimal.ROUND_HALF_UP)
.multiply(BigDecimal.valueOf(100));
sampleDataExpand.setIonAbundanceRatioError(ionAbundanceRatioError);
// sampleDataExpand.setIonAbundanceRatioWithinError();
if (testRecord.getBusinessType().equals(BusinessType.NPS_CASE.getBusinessType())) {
sampleDataExpand.setIonAbundanceRatioWithinError(processInspectDataService.getWithinErrorText(ionAbundanceRatioError, processInspectDataService.getErrorRange(sampleDataExpand.getIonAbundanceRatio())));
} else {
sampleDataExpand.setIonAbundanceRatioWithinError(processInspectDataService.calculateHairCaseIonAbundanceRatioWithinError(ionAbundanceRatioError.doubleValue(), stdDataExpand.getIonAbundanceRatio().doubleValue()));
}
}
});
}
update = super.updateById(sampleDataExpand);
}
}

Loading…
Cancel
Save