|
@@ -1,12 +1,16 @@
|
|
|
package org.dromara.web.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
+import org.dromara.common.core.enums.biz.PatientType;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.domain.BaseEntity;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
@@ -14,22 +18,29 @@ import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.system.config.RedisUtil;
|
|
|
import org.dromara.system.domain.SysDept;
|
|
|
import org.dromara.system.domain.vo.SysDeptVo;
|
|
|
+import org.dromara.system.domain.vo.SysDiseaseLabelVo;
|
|
|
import org.dromara.system.domain.vo.SysWardVo;
|
|
|
import org.dromara.system.mapper.SysDeptMapper;
|
|
|
import org.dromara.system.mapper.SysWardMapper;
|
|
|
import org.dromara.system.service.ISysDeptService;
|
|
|
+import org.dromara.system.service.ISysDiseaseLabelService;
|
|
|
+import org.dromara.web.domain.NutritionDiagnosis;
|
|
|
import org.dromara.web.domain.PatientAccount;
|
|
|
+import org.dromara.web.domain.SysPatient;
|
|
|
import org.dromara.web.domain.TreatmentUser;
|
|
|
import org.dromara.web.domain.bo.TreatmentUserBo;
|
|
|
+import org.dromara.web.domain.vo.NutritionDiagnosisVo;
|
|
|
import org.dromara.web.domain.vo.TreatmentUserVo;
|
|
|
+import org.dromara.web.mapper.NutritionDiagnosisMapper;
|
|
|
import org.dromara.web.mapper.PatientAccountMapper;
|
|
|
+import org.dromara.web.mapper.SysPatientMapper;
|
|
|
import org.dromara.web.mapper.TreatmentUserMapper;
|
|
|
import org.dromara.web.service.ITreatmentUserService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -51,8 +62,14 @@ public class TreatmentUserServiceImpl implements ITreatmentUserService {
|
|
|
|
|
|
private final SysWardMapper wardMapper;
|
|
|
|
|
|
+ private final SysPatientMapper patientMapper;
|
|
|
+
|
|
|
private final PatientAccountMapper accountMapper;
|
|
|
|
|
|
+ private final NutritionDiagnosisMapper diagnosisMapper;
|
|
|
+
|
|
|
+ private final ISysDiseaseLabelService diseaseLabelService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询【请填写功能名称】
|
|
|
*
|
|
@@ -137,47 +154,169 @@ public class TreatmentUserServiceImpl implements ITreatmentUserService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean insertByBo(TreatmentUserBo bo) {
|
|
|
- TreatmentUser add = MapstructUtils.convert(bo, TreatmentUser.class);
|
|
|
- add.setTreatNum(RedisUtil.generatePatientNumber("M"));
|
|
|
- if (null != add && StringUtils.isNotBlank(add.getType())) {
|
|
|
- if ("0".equals(add.getType())) {
|
|
|
- add.setOutpatientNo(RedisUtil.generatePatientNumber("2"));
|
|
|
- } else if ("1".equals(add.getType())) {
|
|
|
- add.setOutpatientNo(RedisUtil.generatePatientNumber("1"));
|
|
|
+ // 1. 创建患者基本信息
|
|
|
+ SysPatient patient = createSysPatient(bo);
|
|
|
+ boolean patientInserted = patientMapper.insert(patient) > 0;
|
|
|
+
|
|
|
+ if (!patientInserted) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 2. 创建治疗用户信息
|
|
|
+ TreatmentUser treatmentUser = createTreatmentUser(bo, patient.getTreatNum());
|
|
|
+ boolean userInserted = baseMapper.insert(treatmentUser) > 0;
|
|
|
+
|
|
|
+ if (!userInserted) {
|
|
|
+ return false;
|
|
|
}
|
|
|
+
|
|
|
+ // 3. 创建患者账户信息
|
|
|
+ createPatientAccount(treatmentUser);
|
|
|
+ bo.setId(treatmentUser.getId());
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 这里应该添加事务回滚逻辑,或者使用Spring的@Transactional
|
|
|
+ log.error("创建患者信息失败", e);
|
|
|
+ return false;
|
|
|
}
|
|
|
- SysWardVo wardVo = wardMapper.selectVoById(bo.getWardId());
|
|
|
- if (null != wardVo) {
|
|
|
- add.setWardName(wardVo.getWardName());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysPatient createSysPatient(TreatmentUserBo bo) {
|
|
|
+ SysPatient patient = new SysPatient();
|
|
|
+ patient.setTreatNum(RedisUtil.generatePatientNumber("M"));
|
|
|
+ patient.setPatientName(bo.getTreatName());
|
|
|
+ patient.setIdCard(bo.getIdCard());
|
|
|
+ patient.setActivity(bo.getActivity());
|
|
|
+ patient.setBirthday(bo.getBirthday());
|
|
|
+ patient.setAge(bo.getAge());
|
|
|
+ patient.setHeight(bo.getHeight());
|
|
|
+ patient.setWeight(bo.getWeight());
|
|
|
+ patient.setSex(bo.getSex());
|
|
|
+ patient.setPhoneNum(bo.getPhoneNum());
|
|
|
+ patient.setAllergyFoot(bo.getAllergyFoot());
|
|
|
+ patient.setAllergyDrug(bo.getAllergyDrug());
|
|
|
+ return patient;
|
|
|
+ }
|
|
|
+
|
|
|
+ private TreatmentUser createTreatmentUser(TreatmentUserBo bo, String treatNum) {
|
|
|
+ TreatmentUser treatmentUser = MapstructUtils.convert(bo, TreatmentUser.class);
|
|
|
+ treatmentUser.setTreatNum(treatNum);
|
|
|
+
|
|
|
+ // 设置门诊号
|
|
|
+ if (StringUtils.isNotBlank(treatmentUser.getType())) {
|
|
|
+ String prefix = PatientType.OUTPATIENT.getCode().equals(treatmentUser.getType()) ? "2" : "1";
|
|
|
+ treatmentUser.setOutpatientNo(RedisUtil.generatePatientNumber(prefix));
|
|
|
}
|
|
|
- add.setBirthday(bo.getBirthday());
|
|
|
- add.setPhoneNum(bo.getPhoneNum());
|
|
|
- validEntityBeforeSave(add);
|
|
|
- boolean flag = baseMapper.insert(add) > 0;
|
|
|
- if (flag) {
|
|
|
- bo.setId(add.getId());
|
|
|
- PatientAccount account = new PatientAccount();
|
|
|
- account.setSerialNo(RedisUtil.generatePatientNumber("A"));
|
|
|
- account.setPatientId(add.getId());
|
|
|
- account.setPatientName(add.getTreatName());
|
|
|
- account.setIdCard(add.getIdCard());
|
|
|
- account.setSex(Long.getLong(add.getSex()));
|
|
|
- account.setPhone(add.getPhoneNum());
|
|
|
- account.setDoorId(add.getDoorId());
|
|
|
- SysDeptVo deptVo = deptMapper.selectVoById(add.getDoorId());
|
|
|
- if (null != deptVo) {
|
|
|
+
|
|
|
+ // 设置病房信息
|
|
|
+ if (bo.getWardId() != null) {
|
|
|
+ SysWardVo wardVo = wardMapper.selectVoById(bo.getWardId());
|
|
|
+ if (wardVo != null) {
|
|
|
+ treatmentUser.setWardName(wardVo.getWardName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ treatmentUser.setBirthday(bo.getBirthday());
|
|
|
+ treatmentUser.setPhoneNum(bo.getPhoneNum());
|
|
|
+ validEntityBeforeSave(treatmentUser);
|
|
|
+
|
|
|
+ return treatmentUser;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createPatientAccount(TreatmentUser treatmentUser) {
|
|
|
+ PatientAccount account = new PatientAccount();
|
|
|
+ account.setSerialNo(RedisUtil.generatePatientNumber("A"));
|
|
|
+ account.setPatientId(treatmentUser.getId());
|
|
|
+ account.setPatientName(treatmentUser.getTreatName());
|
|
|
+ account.setIdCard(treatmentUser.getIdCard());
|
|
|
+
|
|
|
+ // 修复类型转换问题
|
|
|
+ if (StringUtils.isNotBlank(treatmentUser.getSex())) {
|
|
|
+ account.setSex(Long.valueOf(treatmentUser.getSex()));
|
|
|
+ }
|
|
|
+
|
|
|
+ account.setPhone(treatmentUser.getPhoneNum());
|
|
|
+ account.setDoorId(treatmentUser.getDoorId());
|
|
|
+
|
|
|
+ // 设置部门信息
|
|
|
+ if (treatmentUser.getDoorId() != null) {
|
|
|
+ SysDeptVo deptVo = deptMapper.selectVoById(treatmentUser.getDoorId());
|
|
|
+ if (deptVo != null) {
|
|
|
account.setDeptName(deptVo.getDeptName());
|
|
|
}
|
|
|
- account.setVisitType(add.getType());
|
|
|
- account.setWardId(add.getWardId());
|
|
|
- account.setWardName(add.getWardName());
|
|
|
- account.setTreatNum(add.getTreatNum());
|
|
|
- account.setPatientNo(add.getOutpatientNo());
|
|
|
- accountMapper.insert(account);
|
|
|
}
|
|
|
- return flag;
|
|
|
+
|
|
|
+ account.setVisitType(treatmentUser.getType());
|
|
|
+ account.setWardId(treatmentUser.getWardId());
|
|
|
+ account.setWardName(treatmentUser.getWardName());
|
|
|
+ account.setTreatNum(treatmentUser.getTreatNum());
|
|
|
+ account.setPatientNo(treatmentUser.getOutpatientNo());
|
|
|
+
|
|
|
+ accountMapper.insert(account);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /* SysPatient patient = new SysPatient();
|
|
|
+ patient.setTreatNum(RedisUtil.generatePatientNumber("M"));
|
|
|
+ patient.setPatientName(bo.getTreatName());
|
|
|
+ patient.setIdCard(bo.getIdCard());
|
|
|
+ patient.setActivity(bo.getActivity());
|
|
|
+ patient.setBirthday(bo.getBirthday());
|
|
|
+ patient.setAge(bo.getAge());
|
|
|
+ patient.setHeight(bo.getHeight());
|
|
|
+ patient.setWeight(bo.getWeight());
|
|
|
+ patient.setSex(bo.getSex());
|
|
|
+ patient.setPhoneNum(bo.getPhoneNum());
|
|
|
+ patient.setAllergyFoot(bo.getAllergyFoot());
|
|
|
+ patient.setAllergyDrug(bo.getAllergyDrug());
|
|
|
+ boolean flag = patientMapper.insert(patient) > 0;
|
|
|
+ if (flag) {
|
|
|
+ TreatmentUser add = MapstructUtils.convert(bo, TreatmentUser.class);
|
|
|
+ add.setTreatNum(patient.getTreatNum());
|
|
|
+ if (null != add && StringUtils.isNotBlank(add.getType())) {
|
|
|
+ if ("0".equals(add.getType())) {
|
|
|
+ add.setOutpatientNo(RedisUtil.generatePatientNumber("2"));
|
|
|
+ } else if ("1".equals(add.getType())) {
|
|
|
+ add.setOutpatientNo(RedisUtil.generatePatientNumber("1"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SysWardVo wardVo = wardMapper.selectVoById(bo.getWardId());
|
|
|
+ if (null != wardVo) {
|
|
|
+ add.setWardName(wardVo.getWardName());
|
|
|
+ }
|
|
|
+ add.setBirthday(bo.getBirthday());
|
|
|
+ add.setPhoneNum(bo.getPhoneNum());
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ PatientAccount account = new PatientAccount();
|
|
|
+ account.setSerialNo(RedisUtil.generatePatientNumber("A"));
|
|
|
+ account.setPatientId(add.getId());
|
|
|
+ account.setPatientName(add.getTreatName());
|
|
|
+ account.setIdCard(add.getIdCard());
|
|
|
+ account.setSex(Long.getLong(add.getSex()));
|
|
|
+ account.setPhone(add.getPhoneNum());
|
|
|
+ account.setDoorId(add.getDoorId());
|
|
|
+ SysDeptVo deptVo = deptMapper.selectVoById(add.getDoorId());
|
|
|
+ if (null != deptVo) {
|
|
|
+ account.setDeptName(deptVo.getDeptName());
|
|
|
+ }
|
|
|
+ account.setVisitType(add.getType());
|
|
|
+ account.setWardId(add.getWardId());
|
|
|
+ account.setWardName(add.getWardName());
|
|
|
+ account.setTreatNum(add.getTreatNum());
|
|
|
+ account.setPatientNo(add.getOutpatientNo());
|
|
|
+ accountMapper.insert(account);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return flag;
|
|
|
+ }*/
|
|
|
+
|
|
|
/**
|
|
|
* 修改【请填写功能名称】
|
|
|
*
|
|
@@ -204,6 +343,38 @@ public class TreatmentUserServiceImpl implements ITreatmentUserService {
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<TreatmentUserVo> queryListByTreatNum(String treatNum) {
|
|
|
+ List<TreatmentUserVo> userVoList = baseMapper.selectVoList(new LambdaQueryWrapper<TreatmentUser>().eq(TreatmentUser::getTreatNum, treatNum));
|
|
|
+ NutritionDiagnosisVo diagnosis =null;
|
|
|
+ String labelIdsStr = null;
|
|
|
+ List<String> labelNames = null;
|
|
|
+ if (CollUtil.isNotEmpty(userVoList)) {
|
|
|
+ for (TreatmentUserVo vo : userVoList) {
|
|
|
+ diagnosis = diagnosisMapper.selectVoOne(new LambdaQueryWrapper<NutritionDiagnosis>().eq(NutritionDiagnosis::getTreatmentUserId, vo.getId()).orderByDesc(BaseEntity::getCreateTime).last("LIMIT 1"));
|
|
|
+ if (null != diagnosis) {
|
|
|
+ labelIdsStr = diagnosis.getDiagnosisLableId();
|
|
|
+ // 处理产品标签
|
|
|
+ if (StringUtils.isNotBlank(labelIdsStr)) {
|
|
|
+ labelNames = Arrays.stream(labelIdsStr.split(",")).map(String::trim).filter(StringUtils::isNotBlank).map(labelid -> {
|
|
|
+ try {
|
|
|
+ return diseaseLabelService.queryById(Long.parseLong(labelid));
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }).filter(Objects::nonNull).map(SysDiseaseLabelVo::getLabelName).filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!labelNames.isEmpty()) {
|
|
|
+ diagnosis.setDiagnosisLabelStr(String.join(",", labelNames));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setDiagnosisVo(diagnosis);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return userVoList;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验并批量删除【请填写功能名称】信息
|
|
|
*
|