|
@@ -1,6 +1,5 @@
|
|
|
package com.github.jfcloud.gene.lis.service;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.db.Entity;
|
|
@@ -26,6 +25,8 @@ import org.springframework.stereotype.Service;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -45,12 +46,14 @@ public class LisSyncService {
|
|
|
public void sync(Long sampleId) {
|
|
|
SampleAnimalVo animalDetail = sampleAnimalService.getDetail(sampleId);
|
|
|
Assert.notNull(animalDetail, "同步LIS失败,动物样本检测不存在");
|
|
|
- Assert.isTrue(animalDetail.getScientificSampleType().contains(ScientificSampleTypeEnum.serum.getDescription()), "同步LIS失败,只有包含血清样本送检才可以同步");
|
|
|
+ Assert.isTrue(StrUtil.isNotBlank(animalDetail.getScientificSampleType()) &&
|
|
|
+ animalDetail.getScientificSampleType().contains(ScientificSampleTypeEnum.serum.getDescription()), "同步LIS失败,只有包含血清样本送检才可以同步");
|
|
|
SampleCheckSerumVo serum = animalDetail.getOrder().getSerum();
|
|
|
|
|
|
SampleCheckOrder checkOrder = checkOrderMapper.selectById(serum.getId());
|
|
|
+ JSONObject extObj = new JSONObject();
|
|
|
if (StrUtil.isNotBlank(checkOrder.getExtData())) {
|
|
|
- JSONObject extObj = JSON.parseObject(checkOrder.getExtData());
|
|
|
+ extObj = JSON.parseObject(checkOrder.getExtData());
|
|
|
Assert.isFalse(extObj.containsKey("lisId"), "同步LIS失败,已同步过");
|
|
|
}
|
|
|
|
|
@@ -59,30 +62,93 @@ public class LisSyncService {
|
|
|
//HT_SCIENCE_APPLY主键非自增,为年份2位+月份2位+日期2位+483+7位序列号,为了避免冲突,这里使用480
|
|
|
String idPrefix = sampleInfo.getApplyTime().format(DateTimeFormatter.ofPattern("yyMMdd")) + "480";
|
|
|
long firstId = Long.parseLong(String.format("%s%07d", idPrefix, 1));
|
|
|
- //查询当前最大的id
|
|
|
- String sql = String.format("select top 1 id from dbo.HT_SCIENCE_APPLY where id like '%s%%' order by id desc ", idPrefix);
|
|
|
- List<Entity> idEntities = lisDb.query(sql);
|
|
|
- if (CollUtil.isNotEmpty(idEntities)) {
|
|
|
- firstId = idEntities.get(0).getLong("id") + 1;
|
|
|
+ long itemFirstId = Long.parseLong(String.valueOf(firstId).replace("480", "481"));
|
|
|
+ //编号起始与结尾
|
|
|
+ int beginNo = 1;
|
|
|
+ int endNo = 1;
|
|
|
+ //查询当前最大的id与编号(编号格式HKYBKY20250326-14-15)
|
|
|
+ String sql = String.format("select top 1 id, SampleNo from dbo.HT_SCIENCE_APPLY where id like '%s%%' order by id desc ", idPrefix);
|
|
|
+ Entity idEntity = lisDb.queryOne(sql);
|
|
|
+ if (idEntity != null) {
|
|
|
+ firstId = idEntity.getLong("id") + 1;
|
|
|
+ String sampleNo = idEntity.getStr("SampleNo");
|
|
|
+ String[] split = sampleNo.split("-");
|
|
|
+ beginNo = Integer.parseInt(split[2]) + 1;
|
|
|
}
|
|
|
|
|
|
- //todo 同步LIS
|
|
|
+ //查询当天的样本编号
|
|
|
+ String noPrefix = "HKYBKY" + sampleInfo.getApplyTime().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+
|
|
|
+ //查询科室表HT_INFO_DEP对应的机构
|
|
|
+ List<Entity> depEntities = lisDb.query("select id, name, hsp_id from dbo.HT_INFO_DEP");
|
|
|
+ Map<Long, Entity> depMap = depEntities.stream().collect(Collectors.toMap(e -> e.getLong("id"), Function.identity()));
|
|
|
+
|
|
|
+ //根据昵称查询用户id
|
|
|
+ Entity applyUser = lisDb.queryOne("select top 1 user_id from dbo.HT_INFO_USER_EXTEND where name = '" + serum.getApplyUserName() + "' order by user_id desc");
|
|
|
+
|
|
|
+ //同步LIS
|
|
|
List<HtScienceApply> applyList = new ArrayList<>();
|
|
|
List<HtScienceApplyItem> applyItemList = new ArrayList<>();
|
|
|
for (CheckItemSerumVo item : serum.getItems()) {
|
|
|
HtScienceApply scienceApply = new HtScienceApply();
|
|
|
scienceApply.setId(firstId++);
|
|
|
- scienceApply.setPhone(serum.getApplyUserMobile());
|
|
|
+ if (serum.getSendOrgId() != null) {
|
|
|
+ scienceApply.setHspId(depMap.get(serum.getSendOrgId()).getStr("hsp_id"));
|
|
|
+ }
|
|
|
+ scienceApply.setPetType(item.getLisPetTypeId());
|
|
|
scienceApply.setEmail(serum.getApplyUserEmail());
|
|
|
+ scienceApply.setPhone(serum.getApplyUserMobile());
|
|
|
+ scienceApply.setCreateName(serum.getApplyUserName());
|
|
|
+ scienceApply.setCreateId(applyUser.getStr("user_id"));
|
|
|
+ scienceApply.setCreateTime(checkOrder.getCreateTime());
|
|
|
+ scienceApply.setSex(item.getLisSexId());
|
|
|
+ scienceApply.setAge(Integer.parseInt(item.getAge()));
|
|
|
+ scienceApply.setFastFlag(Integer.parseInt(item.getQuick()));
|
|
|
+ scienceApply.setApplyDep(serum.getSendOrgId().toString());
|
|
|
+ scienceApply.setApplyDocId(serum.getSendUserId().toString());
|
|
|
+ scienceApply.setApplyDoc(serum.getSendUserName());
|
|
|
+ scienceApply.setApplyTime(serum.getApplyDate());
|
|
|
+ scienceApply.setDeliverOper(serum.getSendUserName());
|
|
|
+ scienceApply.setDeliverOperId(serum.getSendUserId().toString());
|
|
|
+ scienceApply.setDeliverTime(serum.getApplyDate());
|
|
|
+ scienceApply.setSampleCount(Integer.parseInt(item.getCodeSuffix()));
|
|
|
+ scienceApply.setPreText(item.getCodePrefix());
|
|
|
+ scienceApply.setBeginNo(String.format("%0" + item.getCodeSuffix().length() +"d", 1));
|
|
|
+
|
|
|
+ endNo = beginNo + scienceApply.getSampleCount() - 1;
|
|
|
+ scienceApply.setSampleNo(noPrefix + "-" + beginNo + "-" + endNo);
|
|
|
applyList.add(scienceApply);
|
|
|
+
|
|
|
+ //检测指标
|
|
|
+ if (StrUtil.isNotBlank(item.getTarget())) {
|
|
|
+ List<Long> itemIds = JSON.parseArray(item.getTarget(), Long.class);
|
|
|
+ for (Long itemId : itemIds) {
|
|
|
+ HtScienceApplyItem applyItem = new HtScienceApplyItem();
|
|
|
+ applyItem.setId(itemFirstId++);
|
|
|
+ applyItem.setApplyId(scienceApply.getId());
|
|
|
+ applyItem.setItemId(itemId);
|
|
|
+ applyItemList.add(applyItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ Assert.notEmpty(applyList, "同步LIS失败,无血清送检单");
|
|
|
+ Assert.notEmpty(applyItemList, "同步LIS失败,无检测指标");
|
|
|
+ JSONObject finalExtObj = extObj;
|
|
|
lisDb.execute(db -> {
|
|
|
try {
|
|
|
List<Entity> applyEntities = applyList.stream().map(x -> Entity.create("dbo.HT_SCIENCE_APPLY").parseBean(x)).collect(Collectors.toList());
|
|
|
db.insert(applyEntities);
|
|
|
List<Entity> applyItemEntities = applyItemList.stream().map(x -> Entity.create("dbo.HT_SCIENCE_APPLY_ITEM").parseBean(x)).collect(Collectors.toList());
|
|
|
db.insert(applyItemEntities);
|
|
|
+
|
|
|
+ //保存id
|
|
|
+ List<Long> applyIdList = applyList.stream().map(HtScienceApply::getId).collect(Collectors.toList());
|
|
|
+ finalExtObj.put("lisId", applyIdList);
|
|
|
+ SampleCheckOrder co = new SampleCheckOrder();
|
|
|
+ co.setId(checkOrder.getId());
|
|
|
+ co.setExtData(finalExtObj.toString());
|
|
|
+ co.updateById();
|
|
|
} catch (Exception e) {
|
|
|
log.error("同步LIS失败", e);
|
|
|
}
|