From b0a5fd76f59b52cf09760a52169272202bf98039 Mon Sep 17 00:00:00 2001 From: LiJianZhao Date: Tue, 29 Apr 2025 10:17:31 +0800 Subject: [PATCH] deb --- .../patient/RegistrationController.java | 3 +- .../server/entity/patient/PatientInfo.java | 52 +++++++- .../entity/patient/PatientRegistration.java | 2 +- .../patient/dto/RegistrationSaveDto.java | 79 +++++++++++ .../service/patient/PatientInfoService.java | 123 +++++++++++++++++- .../patient/PatientRegistrationService.java | 26 ++-- 6 files changed, 268 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/syjiaer/clinic/server/entity/patient/dto/RegistrationSaveDto.java diff --git a/src/main/java/com/syjiaer/clinic/server/controller/patient/RegistrationController.java b/src/main/java/com/syjiaer/clinic/server/controller/patient/RegistrationController.java index dc02b00..80e591f 100644 --- a/src/main/java/com/syjiaer/clinic/server/controller/patient/RegistrationController.java +++ b/src/main/java/com/syjiaer/clinic/server/controller/patient/RegistrationController.java @@ -6,6 +6,7 @@ import com.syjiaer.clinic.server.common.vo.Result; import com.syjiaer.clinic.server.controller.BaseController; import com.syjiaer.clinic.server.entity.patient.PatientRegistration; import com.syjiaer.clinic.server.entity.patient.dto.RegistrationQuery; +import com.syjiaer.clinic.server.entity.patient.dto.RegistrationSaveDto; import com.syjiaer.clinic.server.entity.patient.vo.PatientAndRegistrationInfoVo; import com.syjiaer.clinic.server.service.patient.PatientInfoService; import com.syjiaer.clinic.server.service.patient.PatientRegistrationService; @@ -30,7 +31,7 @@ public class RegistrationController extends BaseController { @RequestMapping("/add") public Result registration() { - PatientRegistration registrationParam = parmsUtil.getObjectWithCheck("data", PatientRegistration.class); + RegistrationSaveDto registrationParam = parmsUtil.getObjectWithCheck("data", RegistrationSaveDto.class); String mdtrtCertNo = parmsUtil.getString("mdtrtCertNo"); String mdtrtCertType = parmsUtil.getString("mdtrtCertType"); patientRegistrationService.registration(registrationParam,mdtrtCertType,mdtrtCertNo); diff --git a/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientInfo.java b/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientInfo.java index 2975c01..9e0edbb 100644 --- a/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientInfo.java +++ b/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientInfo.java @@ -5,20 +5,21 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; import lombok.Getter; import lombok.Setter; import lombok.ToString; import lombok.experimental.Accessors; - -import java.io.Serializable; - /** *

* 患者信息 *

* * @author NiuZiYuan - * @since 2025-04-17 + * @since 2025-04-29 */ @Getter @Setter @@ -40,12 +41,51 @@ public class PatientInfo implements Serializable { @ApiModelProperty("手机号") private String phone; - @ApiModelProperty("身份证号") - private String certno; + @ApiModelProperty("证件号码") + private String certNo; @ApiModelProperty("性别") private String sex; @ApiModelProperty("年龄") private Integer age; + + @ApiModelProperty("证件类型") + private String certType; + + @ApiModelProperty("来源") + private String source; + + @ApiModelProperty("民族") + private String nation; + + @ApiModelProperty("地区") + private String area; + + @ApiModelProperty("地址") + private String address; + + @ApiModelProperty("备注") + private String remark; + + @ApiModelProperty("创建日期") + private LocalDateTime createDatetime; + + @ApiModelProperty("会员等级") + private Integer levelId; + + @ApiModelProperty("经验值") + private Integer exp; + + @ApiModelProperty("积分余额") + private Integer integralBalance; + + @ApiModelProperty("0没绑医保 1已绑定") + private Integer isBindSocial; + + @ApiModelProperty("余额") + private BigDecimal balance; + + @ApiModelProperty("生日") + private LocalDate brithday; } diff --git a/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientRegistration.java b/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientRegistration.java index f9a3bbc..43550a9 100644 --- a/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientRegistration.java +++ b/src/main/java/com/syjiaer/clinic/server/entity/patient/PatientRegistration.java @@ -18,7 +18,7 @@ import lombok.experimental.Accessors; *

* * @author NiuZiYuan - * @since 2025-04-23 + * @since 2025-04-29 */ @Getter @Setter diff --git a/src/main/java/com/syjiaer/clinic/server/entity/patient/dto/RegistrationSaveDto.java b/src/main/java/com/syjiaer/clinic/server/entity/patient/dto/RegistrationSaveDto.java new file mode 100644 index 0000000..308af7a --- /dev/null +++ b/src/main/java/com/syjiaer/clinic/server/entity/patient/dto/RegistrationSaveDto.java @@ -0,0 +1,79 @@ +package com.syjiaer.clinic.server.entity.patient.dto; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +@Data +public class RegistrationSaveDto { + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty("科室id") + private Integer organizationSectionId; + + @ApiModelProperty("医生id") + private Integer organizationDoctorId; + + @ApiModelProperty("患者姓名") + private String name; + + @ApiModelProperty("患者年龄") + private Integer age; + + @ApiModelProperty("患者手机号") + private String phone; + + @ApiModelProperty("就诊类型") + private Short visitType; + + @ApiModelProperty("挂号时间") + private LocalDateTime createDatetime; + + @ApiModelProperty("推荐") + private String recommendations; + + @ApiModelProperty("备注") + private String memo; + + @ApiModelProperty("预诊") + private String advanceDiagnosis; + + @ApiModelProperty("挂号费") + private BigDecimal registrationMoney; + + @ApiModelProperty("逻辑删除") + private Integer delFlag; + + @ApiModelProperty("挂号类型") + private Integer type; + + @ApiModelProperty("性别") + private String gender; + + @ApiModelProperty("病人id") + private Integer patientInfoId; + + @ApiModelProperty("挂号状态 1候诊 2在诊 3已诊 0取消") + private Integer status; + + @ApiModelProperty("人员编号") + private String psnNo; + + @ApiModelProperty("险种类型") + private String insutype; + + @ApiModelProperty("就诊id 挂号后医保返会") + private String mdtrtId; + + @ApiModelProperty("流水号") + private String fstNo; + + @ApiModelProperty("证件号码") + private String certNo; + @ApiModelProperty("证件类型") + private String certType; +} diff --git a/src/main/java/com/syjiaer/clinic/server/service/patient/PatientInfoService.java b/src/main/java/com/syjiaer/clinic/server/service/patient/PatientInfoService.java index d6a0dbb..acf393f 100644 --- a/src/main/java/com/syjiaer/clinic/server/service/patient/PatientInfoService.java +++ b/src/main/java/com/syjiaer/clinic/server/service/patient/PatientInfoService.java @@ -1,26 +1,147 @@ package com.syjiaer.clinic.server.service.patient; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.syjiaer.clinic.server.common.exception.MessageException; import com.syjiaer.clinic.server.entity.patient.PatientInfo; +import com.syjiaer.clinic.server.entity.vip.Vip; +import com.syjiaer.clinic.server.entity.vip.VipExpLog; +import com.syjiaer.clinic.server.entity.vip.VipIntegralLog; +import com.syjiaer.clinic.server.entity.vip.VipLevelConfig; import com.syjiaer.clinic.server.mapper.patient.PatientInfoMapper; +import com.syjiaer.clinic.server.mapper.vip.VipExpLogMapper; +import com.syjiaer.clinic.server.mapper.vip.VipIntegralLogMapper; +import com.syjiaer.clinic.server.mapper.vip.VipLevelConfigMapper; import com.syjiaer.clinic.server.service.BaseService; +import com.syjiaer.clinic.server.service.vip.VipLevelConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + @Service public class PatientInfoService extends BaseService { @Autowired private PatientInfoMapper patientInfoMapper; + @Autowired + private VipLevelConfigMapper vipLevelConfigMapper; + @Autowired + private VipLevelConfigService vipLevelConfigService; + @Autowired + private VipExpLogMapper vipExpLogMapper; + @Autowired + private VipIntegralLogMapper vipIntegralLogMapper; public void save(PatientInfo patientInfo){ + patientInfo.setCreateDatetime(LocalDateTime.now()); + if (patientInfo.getBrithday() != null) { + int currentYear = LocalDate.now().getYear(); + int birthYear = patientInfo.getBrithday().getYear(); + patientInfo.setAge(currentYear - birthYear); + } + VipLevelConfig level = vipLevelConfigService.getByExp(patientInfo.getExp()); + if (level != null){ + patientInfo.setLevelId(level.getLevelId()); + }else { + patientInfo.setLevelId(0); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.eq("phone", patientInfo.getPhone()); + queryWrapper.eq("certno", patientInfo.getPhone()); PatientInfo dbInfo = patientInfoMapper.selectOne(queryWrapper); if (dbInfo != null){ patientInfo.setId(dbInfo.getId()); + patientInfo.setExp(null); + patientInfo.setLevelId(null); + patientInfo.setIntegralBalance(null); + patientInfo.setBalance(null); } patientInfoMapper.insertOrUpdate(patientInfo); } + + /** + * 改变会员经验值 + * @param patientId + * @param changeExp + * @param remark + */ + @Transactional(rollbackFor = Exception.class) + public void changeExp(int patientId, int changeExp, String remark){ + PatientInfo patientInfo = patientInfoMapper.selectById(patientId); + if(patientInfo==null){ + throw new MessageException("会员不存在"); + } + int start_exp = patientInfo.getExp(); + int end_exp = start_exp + changeExp; + if(end_exp<0){ + end_exp=0; + changeExp = -start_exp; + } + patientInfo.setExp(end_exp); + // 记录日志 + VipExpLog vipExpLog = new VipExpLog(); + vipExpLog.setStartExp(start_exp); + vipExpLog.setChangeExp(changeExp); + vipExpLog.setEndExp(end_exp); + vipExpLog.setVipId(patientId); + vipExpLog.setCreateDatetime(LocalDateTime.now()); + vipExpLog.setRemark(remark); + //更新VIP等级 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.orderByDesc("start_exp"); + List vipLevelConfigs = vipLevelConfigMapper.selectList(queryWrapper); + for (VipLevelConfig vipLevelConfig : vipLevelConfigs) { + if(end_exp>=vipLevelConfig.getStartExp()){ + patientInfo.setLevelId(vipLevelConfig.getLevelId()); + System.out.println(vipLevelConfig.getLevelId()); + System.out.println(end_exp); + break; + } + } + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id",patientId); + updateWrapper.set("level_id",patientInfo.getLevelId()); + updateWrapper.set("exp",patientInfo.getExp()); + // 保存 + patientInfoMapper.update(updateWrapper); + vipExpLogMapper.insert(vipExpLog); + } + + + /** + * 改变vip积分 + * @param patientId + * @param addIntegral + * @param remark + */ + @Transactional(rollbackFor = Exception.class) + public void changeIntegral(int patientId, int addIntegral, String remark) { + PatientInfo patientInfo = patientInfoMapper.selectById(patientId); + if(patientInfo==null){ + throw new MessageException("会员不存在"); + } + Integer beforeIntegral = patientInfo.getIntegralBalance(); + Integer finalIntegral = beforeIntegral + addIntegral; + PatientInfo updatePatient = new PatientInfo(); + updatePatient.setId(patientId); + updatePatient.setIntegralBalance(finalIntegral); + patientInfoMapper.updateById(updatePatient); + //记录日志 + VipIntegralLog vipIntegralLog = new VipIntegralLog(); + vipIntegralLog.setBeforeIntegral(beforeIntegral); + vipIntegralLog.setAfterIntegral(finalIntegral); + vipIntegralLog.setChangeIntegral(addIntegral); + vipIntegralLog.setRemark(remark); + vipIntegralLog.setCreateTime(LocalDateTime.now()); + vipIntegralLog.setVipId(patientId); + vipIntegralLogMapper.insert(vipIntegralLog); + } + + } diff --git a/src/main/java/com/syjiaer/clinic/server/service/patient/PatientRegistrationService.java b/src/main/java/com/syjiaer/clinic/server/service/patient/PatientRegistrationService.java index 3ddda46..7221143 100644 --- a/src/main/java/com/syjiaer/clinic/server/service/patient/PatientRegistrationService.java +++ b/src/main/java/com/syjiaer/clinic/server/service/patient/PatientRegistrationService.java @@ -3,6 +3,7 @@ package com.syjiaer.clinic.server.service.patient; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.syjiaer.clinic.server.common.api.annotations.IMField; import com.syjiaer.clinic.server.common.api.input.IM2201; import com.syjiaer.clinic.server.common.api.request.SocialRequest; import com.syjiaer.clinic.server.common.constants.Constants; @@ -16,6 +17,7 @@ import com.syjiaer.clinic.server.entity.organization.OrganizationSection; import com.syjiaer.clinic.server.entity.patient.PatientInfo; import com.syjiaer.clinic.server.entity.patient.PatientRegistration; import com.syjiaer.clinic.server.entity.patient.dto.RegistrationQuery; +import com.syjiaer.clinic.server.entity.patient.dto.RegistrationSaveDto; import com.syjiaer.clinic.server.entity.patient.vo.PatientAndRegistrationInfoVo; import com.syjiaer.clinic.server.mapper.organization.OrganizationMemberMapper; import com.syjiaer.clinic.server.mapper.organization.OrganizationSectionMapper; @@ -48,7 +50,7 @@ public class PatientRegistrationService extends BaseService { private OrganizationSectionMapper organizationSectionMapper; @Autowired @Lazy - private PatientRegistrationService patientRegistrationService; + private PatientRegistrationService patientRegistrationService; @Autowired private SocialRequest socialRequest; @@ -58,11 +60,18 @@ public class PatientRegistrationService extends BaseService { * @param patientRegistrationParam 挂号信息 */ @Transactional(rollbackFor = Exception.class) - public PatientRegistration registration(PatientRegistration registrationParam,String mdtrtCertType, String mdtrtCertNo) { - //TODO 挂号和患者 记录身份证号非必填 + public PatientRegistration registration(RegistrationSaveDto registrationParam, String mdtrtCertType, String mdtrtCertNo) { if (registrationParam == null) { throw new MessageException("data参数为空"); } + if (registrationParam.getCertType() == null){ + throw new MessageException("证件类型不能为空"); + } + if (registrationParam.getCertNo() == null){ + throw new MessageException("证件号码不能为空"); + } + + LocalDateTime now =LocalDateTime.now(); String fstNo = StringUtil.getCode("FSN"); if (registrationParam.getPatientInfoId() == null){ @@ -73,9 +82,11 @@ public class PatientRegistrationService extends BaseService { patientInfo.setPhone(registrationParam.getPhone()); patientInfo.setSex(registrationParam.getGender()); patientInfo.setAge(registrationParam.getAge()); + patientInfo.setCertType(registrationParam.getCertType()); + patientInfo.setCertNo(registrationParam.getCertNo()); QueryWrapper patientInfoQuery = new QueryWrapper<>(); - patientInfoQuery.eq("phone", registrationParam.getPhone()); + patientInfoQuery.eq("cert_no", registrationParam.getCertNo()); List patientInfoList = patientInfoMapper.selectList(patientInfoQuery); if (patientInfoList.isEmpty()) { patientInfoMapper.insert(patientInfo); @@ -120,14 +131,11 @@ public class PatientRegistrationService extends BaseService { regisWrapper.set("type",2); regisWrapper.eq("id",registration.getId()); patientRegistrationMapper.update(null,regisWrapper); - - - return registration; } public PatientRegistration regisByDockerAndPatient(OrganizationMember docker, PatientInfo patient, Short type, Integer status){ - PatientRegistration registration = new PatientRegistration(); + RegistrationSaveDto registration = new RegistrationSaveDto(); //病人信息 registration.setPatientInfoId(patient.getId()); registration.setName(patient.getName()); @@ -143,6 +151,8 @@ public class PatientRegistrationService extends BaseService { registration.setCreateDatetime(LocalDateTime.now()); registration.setRegistrationMoney(BigDecimal.valueOf(0)); registration.setDelFlag(0); + + return patientRegistrationService.registration(registration,null,null); }