fix(patient): 修复患者信息新增和更新逻辑
- 修改handlePatientInfo方法中的患者对象初始化逻辑 - 添加患者ID存在时的查询验证机制 - 区分新增和更新操作分别调用不同的服务方法 - 移除重复的身份证号查询条件优化性能 - 统一患者信息保存和更新的操作流程
This commit is contained in:
@@ -308,12 +308,20 @@ public class PatientInformationServiceImpl implements IPatientInformationService
|
||||
* @return 患者信息
|
||||
*/
|
||||
private Patient handlePatientInfo(PatientBaseInfoDto patientInfoDto) {
|
||||
Patient patient = new Patient();
|
||||
patient.setId(patientInfoDto.getId());
|
||||
if (patientInfoDto.getId() == null) {
|
||||
Patient patient;
|
||||
if (patientInfoDto.getId() != null) {
|
||||
// 更新现有患者信息
|
||||
patient = patientService.getById(patientInfoDto.getId());
|
||||
if (patient == null) {
|
||||
throw new ServiceException("患者信息不存在,无法更新");
|
||||
}
|
||||
} else {
|
||||
// 新增患者信息
|
||||
patient = new Patient();
|
||||
patient.setBusNo(assignSeqUtil.getSeq(AssignSeqEnum.PATIENT_NUM.getPrefix(), 10));
|
||||
patientInfoDto.setActiveFlag(PublicationStatus.ACTIVE.getValue()); // 默认启用
|
||||
patient.setActiveFlag(PublicationStatus.ACTIVE.getValue()); // 默认启用
|
||||
}
|
||||
|
||||
patient.setName(patientInfoDto.getName()); // 患者姓名
|
||||
patient.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(patientInfoDto.getName())); // 拼音首拼
|
||||
patient.setWbStr(ChineseConvertUtils.toWBFirstLetter(patientInfoDto.getName())); // 五笔首拼
|
||||
@@ -337,7 +345,14 @@ public class PatientInformationServiceImpl implements IPatientInformationService
|
||||
patient.setDeceasedDate(patientInfoDto.getDeceasedDate()); // 死亡时间
|
||||
patient.setNationalityCode(patientInfoDto.getNationalityCode());// 民族
|
||||
patient.setActiveFlag(patientInfoDto.getActiveFlag());// 活动标识
|
||||
patientService.saveOrUpdate(patient);
|
||||
|
||||
if (patientInfoDto.getId() != null) {
|
||||
// 更新操作
|
||||
patientService.updateById(patient);
|
||||
} else {
|
||||
// 新增操作
|
||||
patientService.save(patient);
|
||||
}
|
||||
|
||||
return patient;
|
||||
}
|
||||
|
||||
@@ -32,18 +32,11 @@ public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> impl
|
||||
*/
|
||||
@Override
|
||||
public boolean saveOrUpdatePatient(Patient patient) {
|
||||
|
||||
// 身份证ID,患者ID,确定唯一患者
|
||||
LambdaQueryWrapper<Patient> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Patient::getId, patient.getId()).eq(Patient::getIdCard, patient.getIdCard());
|
||||
|
||||
Patient existingPatient = baseMapper.selectOne(queryWrapper);
|
||||
if (existingPatient != null) {
|
||||
// 如果记录存在,更新记录
|
||||
patient.setId(existingPatient.getId());
|
||||
if (patient.getId() != null) {
|
||||
// 如果提供了ID,则直接更新该ID的记录
|
||||
return baseMapper.updateById(patient) > 0;
|
||||
} else {
|
||||
// 如果记录不存在,插入新记录
|
||||
// 如果没有提供ID,则插入新记录
|
||||
return baseMapper.insert(patient) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user