|
|
@ -1,6 +1,8 @@ |
|
|
|
package digital.laboratory.platform.inspection.service.impl; |
|
|
|
package digital.laboratory.platform.inspection.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
@ -19,8 +21,11 @@ import digital.laboratory.platform.inspection.entity.TestRecordReagent; |
|
|
|
import digital.laboratory.platform.inspection.service.*; |
|
|
|
import digital.laboratory.platform.inspection.service.*; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.EntrustInfo; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.EntrustInfo; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.SampleInfo; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.SampleInfo; |
|
|
|
|
|
|
|
import digital.laboratory.platform.inspetion.api.entity.TargetObject; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.TestRecord; |
|
|
|
import digital.laboratory.platform.inspetion.api.entity.TestRecord; |
|
|
|
|
|
|
|
import digital.laboratory.platform.sys.enums.entrust.EntrustBiologyType; |
|
|
|
import org.apache.commons.io.output.ByteArrayOutputStream; |
|
|
|
import org.apache.commons.io.output.ByteArrayOutputStream; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
@ -33,6 +38,7 @@ import java.util.stream.Collectors; |
|
|
|
* @description: 生成检验记录相关接口实现类 |
|
|
|
* @description: 生成检验记录相关接口实现类 |
|
|
|
* @date 2025/3/18 14:50 |
|
|
|
* @date 2025/3/18 14:50 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Service |
|
|
|
public class InspectRecordServiceImpl implements InspectRecordService { |
|
|
|
public class InspectRecordServiceImpl implements InspectRecordService { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource |
|
|
@ -320,12 +326,24 @@ public class InspectRecordServiceImpl implements InspectRecordService { |
|
|
|
data.put("inspectDay", testRecord.getTestStartDate().getDayOfMonth()); |
|
|
|
data.put("inspectDay", testRecord.getTestStartDate().getDayOfMonth()); |
|
|
|
|
|
|
|
|
|
|
|
// 检材性状描述和检验要求成分
|
|
|
|
// 检材性状描述和检验要求成分
|
|
|
|
List<SampleInfo> sampleInfoList = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery().eq(SampleInfo::getBusinessId, entrustInfo.getId())); |
|
|
|
List<SampleInfo> sampleInfoList = getSampleInfosByMaterialType(entrustInfo, materialType); |
|
|
|
// 对检材进行筛选,如果materialType 不为空则进行操作
|
|
|
|
String materialCharacterDesc = buildMaterialCharacterDesc(sampleInfoList); |
|
|
|
if (StrUtil.isNotBlank(materialType)) { |
|
|
|
String targetObjectStr = sampleInfoList |
|
|
|
|
|
|
|
.stream() |
|
|
|
} |
|
|
|
.flatMap( |
|
|
|
// buildMaterialCharacterDesc()
|
|
|
|
sampleInfo -> { |
|
|
|
|
|
|
|
String toJSONString = JSONArray.toJSONString(sampleInfo.getTargetObject()); |
|
|
|
|
|
|
|
List<TargetObject> drugLiteList = JSONArray.parseArray(toJSONString, TargetObject.class); |
|
|
|
|
|
|
|
return drugLiteList.stream(); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.collect(Collectors.toList()) // 得到转换好的筛查物对象
|
|
|
|
|
|
|
|
.stream() |
|
|
|
|
|
|
|
.map(TargetObject::getName) |
|
|
|
|
|
|
|
.collect(Collectors.toSet()) // 区筛查物对象名称并去重
|
|
|
|
|
|
|
|
.stream() |
|
|
|
|
|
|
|
.collect(Collectors.joining("、")); // 拼接筛查物名称
|
|
|
|
|
|
|
|
data.put("materialCharacterDesc", materialCharacterDesc); |
|
|
|
|
|
|
|
data.put("ingredient", targetObjectStr); |
|
|
|
|
|
|
|
|
|
|
|
// 设置使用的标准物质和试剂
|
|
|
|
// 设置使用的标准物质和试剂
|
|
|
|
List<TestRecordReagent> references = testRecordReagentService.list(Wrappers.<TestRecordReagent>lambdaQuery() |
|
|
|
List<TestRecordReagent> references = testRecordReagentService.list(Wrappers.<TestRecordReagent>lambdaQuery() |
|
|
@ -357,4 +375,73 @@ public class InspectRecordServiceImpl implements InspectRecordService { |
|
|
|
} |
|
|
|
} |
|
|
|
return data; |
|
|
|
return data; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 根据委托信息和检材类型获取检材信息列表 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param entrustInfo 委托信息对象 |
|
|
|
|
|
|
|
* @param materialType 检材类型, 毛发或尿液 |
|
|
|
|
|
|
|
* @return 检材信息列表 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private List<SampleInfo> getSampleInfosByMaterialType(EntrustInfo entrustInfo, String materialType) { |
|
|
|
|
|
|
|
List<SampleInfo> sampleInfoList = sampleInfoService.list(Wrappers.<SampleInfo>lambdaQuery().eq(SampleInfo::getBusinessId, entrustInfo.getId())); |
|
|
|
|
|
|
|
// 对检材进行筛选,如果materialType 不为空则进行操作
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(materialType)) { |
|
|
|
|
|
|
|
if (materialType.equals("毛发")) { |
|
|
|
|
|
|
|
sampleInfoList = sampleInfoList.stream() |
|
|
|
|
|
|
|
.filter(o -> EntrustBiologyType.HAIR.equals(EntrustBiologyType.isExist(o.getForm()))) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 尿液
|
|
|
|
|
|
|
|
sampleInfoList = sampleInfoList.stream() |
|
|
|
|
|
|
|
.filter(o -> EntrustBiologyType.URINE.equals(EntrustBiologyType.isExist(o.getForm()))) |
|
|
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sampleInfoList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 构建检材性状描述 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param sampleInfoList 样本信息列表 |
|
|
|
|
|
|
|
* @return 物料特性描述,如果无法构建则返回null |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String buildMaterialCharacterDesc(List<SampleInfo> sampleInfoList) { |
|
|
|
|
|
|
|
if (CollUtil.isEmpty(sampleInfoList)) { |
|
|
|
|
|
|
|
return StrUtil.EMPTY; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 仅有一个样本时,直接返回
|
|
|
|
|
|
|
|
if (sampleInfoList.size() == 1) { |
|
|
|
|
|
|
|
return "检材为" + sampleInfoList.get(0).getForm() + "。"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 按 form 分组
|
|
|
|
|
|
|
|
Map<String, List<SampleInfo>> sampleMapGroupByForm = sampleInfoList.stream() |
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(SampleInfo::getForm)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 所有样本 form 相同
|
|
|
|
|
|
|
|
if (sampleMapGroupByForm.size() == 1) { |
|
|
|
|
|
|
|
String form = sampleMapGroupByForm.keySet().iterator().next(); // 取唯一的 key
|
|
|
|
|
|
|
|
String orderNoStr = sampleInfoList.stream() |
|
|
|
|
|
|
|
.map(sample -> sample.getOrderNo() + "号") |
|
|
|
|
|
|
|
.collect(Collectors.joining("、")); |
|
|
|
|
|
|
|
return orderNoStr + "检材均为" + form + "。"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 存在多个 form 的情况
|
|
|
|
|
|
|
|
List<String> descriptions = new ArrayList<>(); |
|
|
|
|
|
|
|
sampleMapGroupByForm.forEach((form, value) -> { |
|
|
|
|
|
|
|
String orderNoStr = value.stream() |
|
|
|
|
|
|
|
.map(sample -> sample.getOrderNo() + "号") |
|
|
|
|
|
|
|
.collect(Collectors.joining("、")); |
|
|
|
|
|
|
|
descriptions.add(orderNoStr + "检材均为" + form); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return String.join(";", descriptions) + "。"; // 用分号连接不同类型的描述
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|