From 6a5e6eb4b92f98ef3f733efe1640f5cf12a9764e Mon Sep 17 00:00:00 2001 From: liuhongrui Date: Tue, 25 Feb 2025 16:28:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=97=85=E4=BA=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/core/common/utils/StringUtils.java | 17 ++ .../core/framework/config/SecurityConfig.java | 2 + .../PatientInformationController.java | 168 ++++++++++++++++++ .../dto/PatientInformationDto.java | 124 +++++++++++++ .../mapper/PatientManageMapper.java | 42 +++++ .../patientmanage/PatientManageMapper.xml | 74 ++++++++ .../service/IPatientService.java | 9 + .../service/impl/OrganizationServiceImpl.java | 6 +- .../service/impl/PatientServiceImpl.java | 27 +++ 9 files changed, 466 insertions(+), 3 deletions(-) create mode 100644 openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/controller/PatientInformationController.java create mode 100644 openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/dto/PatientInformationDto.java create mode 100644 openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/mapper/PatientManageMapper.java create mode 100644 openhis-server/openhis-application/src/main/resources/mapper/patientmanage/PatientManageMapper.xml diff --git a/openhis-server/core-common/src/main/java/com/core/common/utils/StringUtils.java b/openhis-server/core-common/src/main/java/com/core/common/utils/StringUtils.java index 1fbb017c..88a3449e 100644 --- a/openhis-server/core-common/src/main/java/com/core/common/utils/StringUtils.java +++ b/openhis-server/core-common/src/main/java/com/core/common/utils/StringUtils.java @@ -569,4 +569,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { } return sb.toString(); } + + /** + * 拼接多个字符串,忽略null值。 + * @param parts 可变参数,可以传入任意数量的字符串 + * @return 拼接后的完整字符串 + */ + public static String joinStrings(String... parts) { + StringBuilder result = new StringBuilder(); + for (String part : parts) { + if (part != null) { // 忽略null值 + result.append(part); + } + } + return result.toString(); + } + + } \ No newline at end of file diff --git a/openhis-server/core-framework/src/main/java/com/core/framework/config/SecurityConfig.java b/openhis-server/core-framework/src/main/java/com/core/framework/config/SecurityConfig.java index c6e85ee2..5154bbd2 100644 --- a/openhis-server/core-framework/src/main/java/com/core/framework/config/SecurityConfig.java +++ b/openhis-server/core-framework/src/main/java/com/core/framework/config/SecurityConfig.java @@ -106,6 +106,8 @@ public class SecurityConfig { .permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**") .permitAll() + .antMatchers("/patientmanage/information/**") + .permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated(); }) diff --git a/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/controller/PatientInformationController.java b/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/controller/PatientInformationController.java new file mode 100644 index 00000000..da0377c2 --- /dev/null +++ b/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/controller/PatientInformationController.java @@ -0,0 +1,168 @@ +package com.openhis.web.patientmanage.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.core.common.core.domain.R; +import com.core.common.enums.AssignSeqEnum; +import com.core.common.utils.AssignSeqUtil; +import com.core.common.utils.ChineseConvertUtils; +import com.core.common.utils.MessageUtils; +import com.core.common.utils.StringUtils; +import com.core.common.utils.bean.BeanUtils; +import com.openhis.administration.domain.Patient; +import com.openhis.administration.service.IPatientService; +import com.openhis.common.constant.PromptMsgConstant; +import com.openhis.web.patientmanage.dto.PatientInformationDto; +import com.openhis.web.patientmanage.mapper.PatientManageMapper; + +import lombok.extern.slf4j.Slf4j; + +/** + * 病人管理——病人信息 + * + * @author liuhr + * @date 2025/2/22 + */ +@RestController +@RequestMapping("/patientmanage/information") +@Slf4j +public class PatientInformationController { + + @Autowired + private IPatientService patientService; + + @Autowired(required = false) + private AssignSeqUtil assignSeqUtil; + + @Autowired(required = false) + PatientManageMapper patientManageMapper; + + @Autowired(required = false) + StringUtils stringUtils; + + // todo 暂且机构ID写死,后续从登录里取得 + private final Long organizationId = 91L; + + /** + * 添加病人信息 + * + * @param patientInformationDto 病人信息 + */ + @PostMapping("/patient-information") + public R addPatient(@Validated @RequestBody PatientInformationDto patientInformationDto) { + + Patient patient = new Patient(); + BeanUtils.copyProperties(patientInformationDto, patient); + + // 使用基础采番,设置病人ID + String code = assignSeqUtil.getSeq(AssignSeqEnum.PATIENT_NUM.getPrefix()); + patient.setBusNo(code); + // 设置生日 + patient.setBirthDate(patientService.extractBirthday(patient.getIdCard())); + // 设置机构ID + patient.setOrganizationId(organizationId); + // 设置拼音首拼 + patient.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(patient.getName())); + // 设置五笔首拼 + patient.setWbStr(ChineseConvertUtils.toWBFirstLetter(patient.getName())); + // 设置地址 + String fullAddress = stringUtils.joinStrings(patient.getAddressProvince(), patient.getAddressCity(), + patient.getAddressDistrict(), patient.getAddressStreet()); + patient.setAddress(fullAddress); + + // 调用服务层保存病人信息 + boolean savePatientSuccess = patientService.save(patient); + + if (!savePatientSuccess) { + return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00003, null)); + } + + return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00001, new Object[] {"病人信息"})); + } + + /** + * 修改病人信息 + * + * @param patientInformationDto 病人信息 + */ + @PutMapping("/patient-information") + public R editPatient(@Validated @RequestBody PatientInformationDto patientInformationDto) { + + Patient patient = new Patient(); + BeanUtils.copyProperties(patientInformationDto, patient); + + // 设置生日 + patient.setBirthDate(patientService.extractBirthday(patient.getIdCard())); + // 设置拼音首拼 + patient.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(patient.getName())); + // 设置五笔首拼 + patient.setWbStr(ChineseConvertUtils.toWBFirstLetter(patient.getName())); + // 设置地址 + String fullAddress = stringUtils.joinStrings(patient.getAddressProvince(), patient.getAddressCity(), + patient.getAddressDistrict(), patient.getAddressStreet()); + patient.setAddress(fullAddress); + + // 调用服务层更新病人信息 + boolean updateSuccess = patientService.updateById(patient); + + if (!updateSuccess) { + return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null)); + } + + return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"病人信息"})); + } + + /** + * 删除病人信息 + * + * @param id 主表id + */ + // todo 删除需要么?或者逻辑删除后续再改 + @DeleteMapping("/patient-information") + public R deletePatient(@RequestParam Long id) { + + boolean deleteSuccess = patientService.removeById(id); + + if (!deleteSuccess) { + return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null)); + } + + return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00005, new Object[] {"病人信息"})); + } + + /** + * 分页查询病人信息,可选条件 + * + * @param busNo 病人ID(可选) + * @param name 病人姓名(可选) + * @param pageNo 页码(默认为1) + * @param pageSize 每页大小(默认为10) + */ + @GetMapping("/patient-information-page") + public R getPatient(@RequestParam(required = false) String busNo, @RequestParam(required = false) String name, + @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { + + // 跳过的记录数 + Integer offset = (pageNo - 1) * pageSize; + // 连表查询患者信息 + List listPatients = patientManageMapper.getPatientPage(busNo, name, pageSize, offset); + // 查询总记录数 + long total = patientManageMapper.countPatients(busNo, name); + // 创建Page对象并设置属性 + Page patientInformationPage = new Page<>(pageNo, pageSize, total); + patientInformationPage.setRecords(listPatients); + + if (patientInformationPage == null || patientInformationPage.getRecords().isEmpty()) { + return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00006, null)); + } + return R.ok(patientInformationPage, + MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"病人信息"})); + } + +} diff --git a/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/dto/PatientInformationDto.java b/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/dto/PatientInformationDto.java new file mode 100644 index 00000000..300a346a --- /dev/null +++ b/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/dto/PatientInformationDto.java @@ -0,0 +1,124 @@ +package com.openhis.web.patientmanage.dto; + +import java.util.Date; + +import com.openhis.common.enums.AdministrativeGender; +import com.openhis.common.enums.MaritalStatus; +import com.openhis.common.enums.OccupationType; + +import lombok.Data; + +/** + * 病人信息Dto + * + * @author liuhr + * @date 2025/2/22 + */ +@Data +public class PatientInformationDto { + + private Long id; + + /** 活动标记 */ + private Integer activeFlag; + + /** 临时标识 */ + private Integer tempFlag; + + /** 患者姓名 */ + private String name; + + /** 患者其他名称 */ + private String nameJson; + + /** 患者院内编码/病历号 */ + private String busNo; + + /** 性别编码 */ + private AdministrativeGender genderEnum; + + /** 生日 */ + private Date birthDate; + + /** 死亡时间 */ + private Date deceasedDate; + + /** 婚姻状态 */ + private MaritalStatus maritalStatusEnum; + + /** 职业编码 */ + private OccupationType prfsEnum; + + /** 电话 */ + private String phone; + + /** 地址 */ + private String address; + + /** 地址省 */ + private String addressProvince; + + /** 地址市 */ + private String addressCity; + + /** 地址区 */ + private String addressDistrict; + + /** 地址街道 */ + private String addressStreet; + + /** 患者其他地址 */ + private String addressJson; + + /** 民族 */ + private String nationalityCode; + + /** 身份证号 */ + private String idCard; + + /** 拼音码 */ + private String pyStr; + + /** 五笔码 */ + private String wbStr; + + /** 血型ABO */ + private String bloodAbo; + + /** 血型RH */ + private String bloodRh; + + /** 工作单位 */ + private String workCompany; + + /** 籍贯 */ + private String nativePlace; + + /** 国家编码 */ + private String countryCode; + + /** 联系人 */ + private String linkName; + + /** 联系人关系 */ + private Integer linkRelationCode; + + /** 联系人电话 */ + private String linkTelcom; + + /** 其他联系人 */ + private String linkJsons; + + /** 机构Id */ + private Long organizationId; + + /** 机构名 */ + private String organizationName; + + /** 创建时间 */ + private Date createTime; + + /** 删除标识 */ + // 0 为未删除,1 为删除 + private String deleteFlag; +} diff --git a/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/mapper/PatientManageMapper.java b/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/mapper/PatientManageMapper.java new file mode 100644 index 00000000..72eca389 --- /dev/null +++ b/openhis-server/openhis-application/src/main/java/com/openhis/web/patientmanage/mapper/PatientManageMapper.java @@ -0,0 +1,42 @@ +package com.openhis.web.patientmanage.mapper; + +import java.util.List; + +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.openhis.administration.domain.Patient; +import com.openhis.web.patientmanage.dto.PatientInformationDto; + +/** + * 病人信息管理 + * + * @author Wuser + * @date 2025/2/25 + */ +@Repository +public interface PatientManageMapper extends BaseMapper { + + /** + * 病人信息分页查询 + * + * @param busNo 病人ID + * @param name 病人姓名 + * @param pageSize 页面大小 + * @param offset 跳过条数 + * @return 分页查询 + */ + List getPatientPage(@Param("busNo") String busNo, @Param("name") String name, + @Param("pageSize") Integer pageSize, @Param("offset") Integer offset); + + /** + * 统计总记录数的方法 + * + * @param busNo 病人ID + * @param name 病人姓名 + * @return 分页查询 + */ + long countPatients(@Param("busNo") String busNo, @Param("name") String name); + +} diff --git a/openhis-server/openhis-application/src/main/resources/mapper/patientmanage/PatientManageMapper.xml b/openhis-server/openhis-application/src/main/resources/mapper/patientmanage/PatientManageMapper.xml new file mode 100644 index 00000000..5f27675b --- /dev/null +++ b/openhis-server/openhis-application/src/main/resources/mapper/patientmanage/PatientManageMapper.xml @@ -0,0 +1,74 @@ + + + + + + + \ No newline at end of file diff --git a/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/IPatientService.java b/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/IPatientService.java index 7132bf90..41a9a251 100644 --- a/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/IPatientService.java +++ b/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/IPatientService.java @@ -1,5 +1,7 @@ package com.openhis.administration.service; +import java.util.Date; + import com.baomidou.mybatisplus.extension.service.IService; import com.openhis.administration.domain.Patient; @@ -11,4 +13,11 @@ import com.openhis.administration.domain.Patient; */ public interface IPatientService extends IService { + /** + * 从身份证号码中提取生日 + * + * @param idCard 身份证号 + * @return 出生日 + */ + Date extractBirthday(String idCard); } \ No newline at end of file diff --git a/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/OrganizationServiceImpl.java b/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/OrganizationServiceImpl.java index ccc2a727..5b1a1f8c 100644 --- a/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/OrganizationServiceImpl.java +++ b/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/OrganizationServiceImpl.java @@ -54,14 +54,14 @@ public class OrganizationServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>(); // 设置查询条件为机构Id code - queryWrapper.eq("code", code); + queryWrapper.eq("bus_no", busNo); return organizationMapper.selectOne(queryWrapper); } diff --git a/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/PatientServiceImpl.java b/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/PatientServiceImpl.java index 8db1d887..ab2b7e2c 100644 --- a/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/PatientServiceImpl.java +++ b/openhis-server/openhis-domain/src/main/java/com/openhis/administration/service/impl/PatientServiceImpl.java @@ -1,5 +1,11 @@ package com.openhis.administration.service.impl; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Date; + import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -16,4 +22,25 @@ import com.openhis.administration.service.IPatientService; @Service public class PatientServiceImpl extends ServiceImpl implements IPatientService { + /** + * 从身份证号码中提取生日 + * + * @param idCard 身份证号 + * @return 出生日 + */ + public Date extractBirthday(String idCard) { + if (idCard == null) { + // 身份证号码为空 + return null; + } + + // 提取第7到14位作为生日字符串 + String birthdayStr = idCard.substring(6, 14); + // 将生日字符串转换为 LocalDate + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + LocalDate date = LocalDate.parse(birthdayStr, formatter); + // 使用系统默认时区,将 LocalDate 转换为 Date + return Date.from(Instant.from(date.atStartOfDay(ZoneId.systemDefault()))); + } + } \ No newline at end of file