From c6b8f11cdd63281b74e8588bad909e78f01c4600 Mon Sep 17 00:00:00 2001 From: wyb <1977763549@qq.com> Date: Thu, 28 Mar 2024 09:50:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BD=9B=E5=B1=B1=E4=B8=89=E9=99=A2?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E6=95=B0=E6=8D=AE=E9=87=87?= =?UTF-8?q?=E9=9B=86=E4=BB=BB=E5=8A=A1=E5=92=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FoShanSyPatientInfoSyncJob.json | 0 pom.xml | 5 + .../com/docus/server/AppRunBootstrap.java | 55 ++++++++ .../controller/FoShanSySyncController.java | 108 +++++++++++++++ .../converter/PatientInfoConverter.java | 123 ++++++++++++++++++ .../docus/server/archive/entity/TBasic.java | 116 +++++++++++++++++ .../archive/job/PatientInfoSyncJob.java | 100 ++++++++++++++ .../server/archive/mapper/TBasicMapper.java | 24 ++++ .../service/PatientInfoSyncService.java | 31 +++++ .../impl/PatientInfoSyncServiceImpl.java | 112 ++++++++++++++++ .../server/archive/utils/PingYinUtil.java | 96 ++++++++++++++ .../fsy/entity/JswzhPatientInfoView.java | 60 +++++++++ .../mapper/JswzhPatientInfoViewMapper.java | 26 ++++ src/main/resources/bootstrap.yml | 12 +- .../mapper/JswzhPatientInfoViewMapper.xml | 28 ++++ src/main/resources/mapper/TBasicMapper.xml | 54 ++++++++ 16 files changed, 944 insertions(+), 6 deletions(-) create mode 100644 data-config/job-config/FoShanSyPatientInfoSyncJob.json create mode 100644 src/main/java/com/docus/server/archive/controller/FoShanSySyncController.java create mode 100644 src/main/java/com/docus/server/archive/converter/PatientInfoConverter.java create mode 100644 src/main/java/com/docus/server/archive/entity/TBasic.java create mode 100644 src/main/java/com/docus/server/archive/job/PatientInfoSyncJob.java create mode 100644 src/main/java/com/docus/server/archive/mapper/TBasicMapper.java create mode 100644 src/main/java/com/docus/server/archive/service/PatientInfoSyncService.java create mode 100644 src/main/java/com/docus/server/archive/service/impl/PatientInfoSyncServiceImpl.java create mode 100644 src/main/java/com/docus/server/archive/utils/PingYinUtil.java create mode 100644 src/main/java/com/docus/server/fsy/entity/JswzhPatientInfoView.java create mode 100644 src/main/java/com/docus/server/fsy/mapper/JswzhPatientInfoViewMapper.java create mode 100644 src/main/resources/mapper/JswzhPatientInfoViewMapper.xml create mode 100644 src/main/resources/mapper/TBasicMapper.xml diff --git a/data-config/job-config/FoShanSyPatientInfoSyncJob.json b/data-config/job-config/FoShanSyPatientInfoSyncJob.json new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml index fe6277f..1dc2ca9 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,11 @@ docus-knife4j-starter + + com.belerweb + pinyin4j + 2.5.1 + diff --git a/src/main/java/com/docus/server/AppRunBootstrap.java b/src/main/java/com/docus/server/AppRunBootstrap.java index 14565b5..25e74a4 100644 --- a/src/main/java/com/docus/server/AppRunBootstrap.java +++ b/src/main/java/com/docus/server/AppRunBootstrap.java @@ -1,12 +1,20 @@ package com.docus.server; +import cn.hutool.extra.spring.SpringUtil; +import com.docus.server.archive.entity.TBasic; +import com.docus.server.archive.mapper.TBasicMapper; +import com.docus.server.archive.utils.PingYinUtil; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.BeanUtils; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; +import java.util.Arrays; +import java.util.Date; + /** * @author wyb @@ -19,4 +27,51 @@ public class AppRunBootstrap { public static void main(String[] args) { SpringApplication.run(AppRunBootstrap.class, args); } + + static void testMysql(){ + TBasicMapper mapper = SpringUtil.getBean(TBasicMapper.class); + long currentTimeMillis = System.currentTimeMillis(); + TBasic tBasic1 = new TBasic(); + tBasic1.setPatientId("FS-TEST-1"); + tBasic1.setJzh("jzh"+ currentTimeMillis); + tBasic1.setInpatientNo(currentTimeMillis +""); + tBasic1.setAdmissTimes(1); + tBasic1.setName("佛山测试1"); + tBasic1.setNameSpell(PingYinUtil.getFirstSpell("佛山测试1")); + tBasic1.setSex("1"); + tBasic1.setSexName("男"); + tBasic1.setAdmissDate(new Date()); + tBasic1.setAdmissDept("221"); + tBasic1.setAdmissDeptName("神经内科"); + tBasic1.setBedNo("神经内科1-1"); + tBasic1.setAttending("wyb"); + tBasic1.setAttendingName("文永斌"); + tBasic1.setAge(50); + tBasic1.setAgeMonth(12); + tBasic1.setAgeDay(3); + tBasic1.setIdCard("xxxxxx"); + tBasic1.setTelphone("666"); + tBasic1.setDisDate(new Date()); + tBasic1.setDisDept("221"); + tBasic1.setDisDeptName("神经内科"); + tBasic1.setTotalCost("28.8"); + tBasic1.setIsDead(0); + tBasic1.setJzCardNo("kh1998"); + tBasic1.setFileSource(1); + tBasic1.setCreateTime(new Date()); + tBasic1.setUpdateTime(new Date()); + TBasic tBasic2 = new TBasic(); + BeanUtils.copyProperties(tBasic1,tBasic2); + tBasic2.setPatientId("FS-TEST-2"); + tBasic2.setAdmissTimes(2); + tBasic2.setJzh("jzh"+(currentTimeMillis+555)); + mapper.insertBatch(Arrays.asList(tBasic1,tBasic2)); + System.out.println("插入后:"+mapper.getByJzh(Arrays.asList(tBasic1.getJzh(),tBasic2.getJzh()))); + tBasic1.setIdCard("modify-1"); + tBasic2.setIdCard("modify-2"); + mapper.updateBatch(Arrays.asList(tBasic1,tBasic2)); + + System.out.println("修改后:"+mapper.getByJzh(Arrays.asList(tBasic1.getJzh(),tBasic2.getJzh()))); + + } } diff --git a/src/main/java/com/docus/server/archive/controller/FoShanSySyncController.java b/src/main/java/com/docus/server/archive/controller/FoShanSySyncController.java new file mode 100644 index 0000000..e3a40e9 --- /dev/null +++ b/src/main/java/com/docus/server/archive/controller/FoShanSySyncController.java @@ -0,0 +1,108 @@ +package com.docus.server.archive.controller; + +import com.docus.core.util.Func; +import com.docus.infrastructure.web.api.CommonResult; +import com.docus.server.archive.service.PatientInfoSyncService; +import com.docus.server.fsy.entity.JswzhPatientInfoView; +import com.docus.server.fsy.mapper.JswzhPatientInfoViewMapper; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * @author YongBin Wen + * @date 2024/3/8 15:21 + */ +@Slf4j +@RequestMapping("/fssy-collect") +@Api(tags = "佛山三院同步接口") +@RestController +public class FoShanSySyncController { + @Resource + private PatientInfoSyncService patientInfoSyncService; + + @Resource + private JswzhPatientInfoViewMapper jswzhPatientInfoViewMapper; + + @ApiOperation(value = "根据时间进行同步出院数据 yyyy-MM-dd") + @GetMapping("/sync/discharge") + public CommonResult syncDischarge(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate) { + String pattern = "yyyy-MM-dd"; + int patternLen = pattern.length(); + if (startDate.length() != patternLen || endDate.length() != patternLen) { + return CommonResult.failed("请传入正确的时间格式 yyyy-MM-dd"); + } + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + try { + sdf.parse(startDate); + sdf.parse(endDate); + } catch (Exception ex) { + return CommonResult.failed("请传入正确的时间格式 yyyy-MM-dd"); + } + int page = 1; + int size = 100; + int total = 0; + try { + while (true) { + int count = patientInfoSyncService.syncDischargeData(startDate + " 00:00:00", endDate + " 23:59:59", page, size); + total += count; + if (count == 0) { + break; + } + page += 1; + } + } catch (Exception ex) { + log.error("同步出院数据接口出错了!" + ex.getMessage(), ex); + return CommonResult.success("同步失败"); + } + return CommonResult.success("同步完成,共同步患者条数:" + total); + } + + @ApiOperation(value = "同步在院数据") + @GetMapping("/sync/inHospital") + public CommonResult syncInHospital() { + try { + patientInfoSyncService.syncInHospitalData(); + return CommonResult.success("同步完成"); + } catch (Exception ex) { + log.error("同步在院数据接口出错!" + ex.getMessage(), ex); + return CommonResult.success("同步出错!"); + } + + } + + @ApiOperation(value = "视图数据获取测试,根据时间范围获取100条出院数据(都传或者都不传) ,如果不传递时间,则获取在院数据") + @GetMapping("/test/patientInfoViewGet") + public CommonResult> viewGet(@RequestParam(value = "startDate", required = false) String startDate, @RequestParam(value = "endDate", required = false) String endDate) { + if (Func.isBlank(startDate) && Func.isBlank(endDate)) { + List inHospital = jswzhPatientInfoViewMapper.getInHospital(); + return CommonResult.success(inHospital); + } + if (Func.isBlank(startDate) || Func.isBlank(endDate)) { + return CommonResult.failed("出院数据查询查询,时间都不为空!"); + } + String pattern = "yyyy-MM-dd"; + int patternLen = pattern.length(); + if (startDate.length() != patternLen || endDate.length() != patternLen) { + return CommonResult.failed("请传入正确的时间格式 yyyy-MM-dd"); + } + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + try { + sdf.parse(startDate); + sdf.parse(endDate); + } catch (Exception ex) { + return CommonResult.failed("请传入正确的时间格式 yyyy-MM-dd"); + } + List discharge = jswzhPatientInfoViewMapper.getDischarge(startDate + " 00:00:00", endDate + " 23:59:59", 1, 100); + return CommonResult.success(discharge); + } + +} diff --git a/src/main/java/com/docus/server/archive/converter/PatientInfoConverter.java b/src/main/java/com/docus/server/archive/converter/PatientInfoConverter.java new file mode 100644 index 0000000..1690bd3 --- /dev/null +++ b/src/main/java/com/docus/server/archive/converter/PatientInfoConverter.java @@ -0,0 +1,123 @@ +package com.docus.server.archive.converter; + +import com.docus.core.util.Func; +import com.docus.server.archive.entity.TBasic; +import com.docus.server.archive.utils.PingYinUtil; +import com.docus.server.fsy.entity.JswzhPatientInfoView; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * @author YongBin Wen + * @date 2024/3/27 14:52 + */ +public class PatientInfoConverter { + private final Map userNameMap; + private final Map deptCodeNameMap; + + public PatientInfoConverter(Map userNameMap, Map deptCodeNameMap) { + this.deptCodeNameMap = deptCodeNameMap; + this.userNameMap = userNameMap; + } + + public TBasic convertArchiveBasicInfo(JswzhPatientInfoView view) { + if (view == null) { + return null; + } + Objects.requireNonNull(userNameMap); + Objects.requireNonNull(deptCodeNameMap); + Map ageMap = parseAge(view.getNL()); + + TBasic tBasic = new TBasic(); + tBasic.setJzh(view.getJZH()); + tBasic.setInpatientNo(view.getZY()); + tBasic.setAdmissTimes(view.getZYCS()); + tBasic.setName(view.getXM()); + tBasic.setNameSpell(PingYinUtil.getFirstSpell(view.getXM())); + tBasic.setSex(sex(view.getXB())); + tBasic.setSexName(sexName(view.getXB())); + tBasic.setAdmissDate(view.getRYRQ()); + tBasic.setAdmissDept(view.getRYKSBQ()); + tBasic.setAdmissDeptName(view.getRYKSMC()); + tBasic.setBedNo(view.getCWDM()); + tBasic.setAttending(view.getDQYS()); + tBasic.setAttendingName(userNameMap.get(view.getDQYS())); + tBasic.setAge(ageMap.get("age")); + tBasic.setAgeMonth(ageMap.get("ageMonth")); + tBasic.setAgeDay(ageMap.get("ageDay")); + tBasic.setIdCard(view.getSFZH()); + tBasic.setTelphone(view.getLXDH()); + tBasic.setDisDate(view.getCYRQ()); + tBasic.setDisDept(view.getDQBQ()); + tBasic.setDisDeptName(view.getDQKS()); + tBasic.setTotalCost(view.getZJINE()); + tBasic.setIsDead(view.getSFSW()); + tBasic.setJzCardNo(view.getJZKH()); + tBasic.setFileSource(1); + return tBasic; + } + + /** + * age + * ageMonth + * ageDay + */ + public static Map parseAge(String nl) { + int age = 0; + int ageMonth = 0; + int ageDay = 0; + if (Func.isNotBlank(nl)) { + String[] split = nl.split("[岁月天]"); + int length = split.length; + // 岁月天都有 + if (length == 3) { + age = Integer.parseInt(split[0]); + ageMonth = Integer.parseInt(split[1]); + ageDay = Integer.parseInt(split[2]); + } + + if (length == 2) { + // 情况一:岁月 情况二:月天 + if (nl.contains("岁")) { + age = Integer.parseInt(split[0]); + ageMonth = Integer.parseInt(split[1]); + } else { + ageMonth = Integer.parseInt(split[0]); + ageDay = Integer.parseInt(split[1]); + } + } + if (length == 1) { + // 包含哪个是哪个 + if (nl.contains("岁")) { + age = Integer.parseInt(split[0]); + } else if (nl.contains("月")) { + ageMonth = Integer.parseInt(split[0]); + } else if (nl.contains("天")) { + ageDay = Integer.parseInt(split[0]); + } + } + } + HashMap map = new HashMap<>(); + map.put("age", age); + map.put("ageMonth", ageMonth); + map.put("ageDay", ageDay); + return map; + } + + public static void main(String[] args) { + System.out.println(parseAge("1天")); + System.out.println(parseAge("2月1天")); + System.out.println(parseAge("9岁8月")); + System.out.println(parseAge("5岁4月3天")); + } + + public static String sex(String sexCode) { + return "M".equalsIgnoreCase(sexCode) ? "1" : "2"; + } + + public static String sexName(String sexCode) { + return "M".equalsIgnoreCase(sexCode) ? "男" : "女"; + } +} diff --git a/src/main/java/com/docus/server/archive/entity/TBasic.java b/src/main/java/com/docus/server/archive/entity/TBasic.java new file mode 100644 index 0000000..d276c50 --- /dev/null +++ b/src/main/java/com/docus/server/archive/entity/TBasic.java @@ -0,0 +1,116 @@ +package com.docus.server.archive.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 病案基本信息 + *

+ * + * @author jiashi + * @since 2021-04-14 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "TBasic对象", description = "病案基本信息") +public class TBasic implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "病案主键") + @TableId(value = "patient_id", type = IdType.ASSIGN_ID) + private String patientId; + + + @ApiModelProperty(value = "记账号") + private String jzh; + + @ApiModelProperty(value = "病案号") + private String inpatientNo; + + @ApiModelProperty(value = "住院次数") + private Integer admissTimes; + + @ApiModelProperty(value = "患者姓名") + private String name; + + @ApiModelProperty(value = "患者拼音首拼") + private String nameSpell; + + @ApiModelProperty(value = "性别代码") + private String sex; + + @ApiModelProperty(value = "性别名称") + private String sexName; + + @ApiModelProperty(value = "住院日期") + private Date admissDate; + + @ApiModelProperty(value = "住院科室") + private String admissDept; + + @ApiModelProperty(value = "住院科室名称") + private String admissDeptName; + + + @ApiModelProperty(value = "床号") + private String bedNo; + + @ApiModelProperty(value = "主管医生工号") + private String attending; + + @ApiModelProperty(value = "主管医生姓名") + private String attendingName; + + @ApiModelProperty(value = "年龄 岁") + private Integer age; + + @ApiModelProperty(value = "年龄 月") + private Integer ageMonth; + + @ApiModelProperty(value = "年龄 天") + private Integer ageDay; + + + @ApiModelProperty(value = "身份证") + private String idCard; + + @ApiModelProperty(value = "联系方式 手机号") + private String telphone; + + @ApiModelProperty(value = "出院日期") + private Date disDate; + + @ApiModelProperty(value = "出院科室") + private String disDept; + + @ApiModelProperty(value = "出院科室名称") + private String disDeptName; + + @ApiModelProperty(value = "患者本次住院总费用") + private String totalCost; + + @ApiModelProperty(value = "是否死亡 0 非死亡 1死亡") + private Integer isDead; + + @ApiModelProperty(value = "记账卡号") + private String jzCardNo; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + + @ApiModelProperty(value = "数据来源 1:需质控归档") + private Integer fileSource; + +} diff --git a/src/main/java/com/docus/server/archive/job/PatientInfoSyncJob.java b/src/main/java/com/docus/server/archive/job/PatientInfoSyncJob.java new file mode 100644 index 0000000..ae147e3 --- /dev/null +++ b/src/main/java/com/docus/server/archive/job/PatientInfoSyncJob.java @@ -0,0 +1,100 @@ +package com.docus.server.archive.job; + +import com.docus.core.util.Func; +import com.docus.infrastructure.core.utils.TableJsonRead; +import com.docus.server.archive.service.PatientInfoSyncService; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.time.LocalDate; +import java.util.Objects; + +/** + * @author YongBin Wen + * @date 2024/3/27 16:23 + */ +@Component +@Slf4j +public class PatientInfoSyncJob { + @Resource + private PatientInfoSyncService patientInfoSyncService; + + /** + * 佛山三院基础数据同步,默认同步当天的和所有在院的 + * + * @date 2024/3/27 16:27 + * @author YongBin Wen + */ + @XxlJob("FoShanSyPatientInfoSyncJob") + public void foShanSyPatientInfoSyncJob() { + String jobConfigPath = "data-config\\job-config"; + String jobConfigName = "FoShanSyPatientInfoSyncJob.json"; + TableJsonRead jsonReader = new TableJsonRead(); + FoShanSyPatientInfoSyncJobConfig syncJobConfig = jsonReader.Read(jobConfigPath, jobConfigName, FoShanSyPatientInfoSyncJobConfig.class); + syncJobConfig = FoShanSyPatientInfoSyncJobConfig.checkAndInit(syncJobConfig); + Integer pageSize = syncJobConfig.getPageSize(); + Integer pageNumber = syncJobConfig.getPageNumber(); + String startDate = syncJobConfig.getStartDate(); + String runJobDate = LocalDate.now().toString(); + + patientInfoSyncService.syncInHospitalData(); + while (true) { + int syscCount = patientInfoSyncService.syncDischargeData(startDate + " 00:00:00", runJobDate + " 23:59:59", pageNumber, pageSize); + if (syscCount < pageSize) { + break; + } + pageNumber += 1; + } + syncJobConfig.setPageNumber(1); + syncJobConfig.setStartDate(runJobDate); + jsonReader.Save(jobConfigPath, jobConfigName, Func.toJson(syncJobConfig)); + } + + private static class FoShanSyPatientInfoSyncJobConfig { + private String startDate; + private Integer pageNumber; + private Integer pageSize; + + public static FoShanSyPatientInfoSyncJobConfig checkAndInit(FoShanSyPatientInfoSyncJobConfig jobConfig) { + if (Objects.isNull(jobConfig)) { + jobConfig = new FoShanSyPatientInfoSyncJobConfig(); + } + if (Objects.isNull(jobConfig.getPageNumber()) || jobConfig.getPageNumber() <= 0) { + jobConfig.setPageNumber(1); + } + if (Objects.isNull(jobConfig.getPageSize()) || jobConfig.getPageSize() <= 0) { + jobConfig.setPageSize(100); + } + if (Objects.isNull(jobConfig.getStartDate())) { + jobConfig.setStartDate(LocalDate.now().toString()); + } + return jobConfig; + } + + public String getStartDate() { + return startDate; + } + + public void setStartDate(String startDate) { + this.startDate = startDate; + } + + public Integer getPageNumber() { + return pageNumber; + } + + public void setPageNumber(Integer pageNumber) { + this.pageNumber = pageNumber; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + } +} diff --git a/src/main/java/com/docus/server/archive/mapper/TBasicMapper.java b/src/main/java/com/docus/server/archive/mapper/TBasicMapper.java new file mode 100644 index 0000000..4b54005 --- /dev/null +++ b/src/main/java/com/docus/server/archive/mapper/TBasicMapper.java @@ -0,0 +1,24 @@ +package com.docus.server.archive.mapper; + + +import com.docus.server.archive.entity.TBasic; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface TBasicMapper { + + /** + * 根据记帐号查找基础数据 + * + * @param jzhList 记帐号 + * @return 基础数据 + */ + List getByJzh(@Param("jzhs") List jzhList); + + int insertBatch(@Param("basicList") List basicList); + + int updateBatch(@Param("basicList") List updateList); +} diff --git a/src/main/java/com/docus/server/archive/service/PatientInfoSyncService.java b/src/main/java/com/docus/server/archive/service/PatientInfoSyncService.java new file mode 100644 index 0000000..ee4dcdc --- /dev/null +++ b/src/main/java/com/docus/server/archive/service/PatientInfoSyncService.java @@ -0,0 +1,31 @@ +package com.docus.server.archive.service; + +import com.docus.server.archive.entity.TBasic; + +import java.util.List; + +/** + * @author YongBin Wen + * @date 2024/3/27 16:25 + */ +public interface PatientInfoSyncService { + + /** + * 同步在院数据 + * @date 2024/3/27 16:56 + * @author YongBin Wen + */ + void syncInHospitalData(); + /** + * + * 根据时间和页码同步出院数据 + * @param startDateTime 开始时间 + * @param endDateTime 结束时间 + * @param pageNumber 页码 + * @param pageSize 页大小 + * @return int 同步出院数据数量 + */ + int syncDischargeData(String startDateTime, String endDateTime, Integer pageNumber, Integer pageSize); + + void insertOrUpdate(List tBasicList); +} diff --git a/src/main/java/com/docus/server/archive/service/impl/PatientInfoSyncServiceImpl.java b/src/main/java/com/docus/server/archive/service/impl/PatientInfoSyncServiceImpl.java new file mode 100644 index 0000000..1692268 --- /dev/null +++ b/src/main/java/com/docus/server/archive/service/impl/PatientInfoSyncServiceImpl.java @@ -0,0 +1,112 @@ +package com.docus.server.archive.service.impl; + +import com.docus.core.util.Func; +import com.docus.infrastructure.redis.service.IdService; +import com.docus.server.archive.converter.PatientInfoConverter; +import com.docus.server.archive.entity.TBasic; +import com.docus.server.archive.mapper.TBasicMapper; +import com.docus.server.archive.service.PatientInfoSyncService; +import com.docus.server.fsy.entity.JswzhPatientInfoView; +import com.docus.server.fsy.mapper.JswzhPatientInfoViewMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @author YongBin Wen + * @date 2024/3/27 16:25 + */ +@Service +@Slf4j +public class PatientInfoSyncServiceImpl implements PatientInfoSyncService { + @Resource + private TBasicMapper tBasicMapper; + @Resource + private JswzhPatientInfoViewMapper jswzhPatientInfoViewMapper; + @Resource + private IdService idService; + + + @Override + public void syncInHospitalData() { + List inHospital = jswzhPatientInfoViewMapper.getInHospital(); + // 在院数据将出院日期设置为空 + for (JswzhPatientInfoView view : inHospital) { + view.setCYRQ(null); + } + convertAndSave(inHospital); + } + + + @Override + public int syncDischargeData(String startDateTime, String endDateTime, Integer pageNumber, Integer pageSize) { + int startRow = (pageNumber - 1) * pageSize + 1; + int endRow = pageNumber * pageSize; + List discharge = jswzhPatientInfoViewMapper.getDischarge(startDateTime, endDateTime, startRow, endRow); + convertAndSave(discharge); + return discharge.size(); + } + + @Override + public void insertOrUpdate(List tBasicList) { + if (Func.isEmpty(tBasicList)) { + return; + } + List jzhList = tBasicList.stream().map(TBasic::getJzh).collect(Collectors.toList()); + Date nowDate = new Date(); + List existsBasicList = tBasicMapper.getByJzh(jzhList); + + // 区分新增和更新的数据 + Map existsJzhPatientMap = Objects.isNull(existsBasicList) ? new HashMap<>() : existsBasicList.stream().collect(Collectors.toMap(TBasic::getJzh, Function.identity())); + List insertList = new ArrayList<>(); + List updateList = new ArrayList<>(); + if (Func.isEmpty(existsBasicList)) { + insertList = tBasicList; + } else { + for (TBasic basic : tBasicList) { + String jzh = basic.getJzh(); + if (existsJzhPatientMap.containsKey(jzh)) { + updateList.add(basic); + } else { + insertList.add(basic); + } + } + } + + // 相应的数据进行数据填充并进行持久化,更新/新增 需要填充patientId,create_time,update_time + if (Func.isNotEmpty(insertList)) { + for (TBasic basic : insertList) { + if (Func.isBlank(basic.getPatientId())) { + basic.setPatientId(idService.getDateSeq() + ""); + } + basic.setCreateTime(nowDate); + basic.setUpdateTime(nowDate); + } + tBasicMapper.insertBatch(insertList); + } + if (Func.isNotEmpty(updateList)) { + for (TBasic basic : updateList) { + TBasic existsBasic = existsJzhPatientMap.get(basic.getJzh()); + basic.setCreateTime(existsBasic.getCreateTime()); + basic.setUpdateTime(nowDate); + basic.setPatientId(existsBasic.getPatientId()); + } + tBasicMapper.updateBatch(updateList); + } + } + + private void convertAndSave(List jswzhPatientInfoViews) { + if (Func.isEmpty(jswzhPatientInfoViews)) { + return; + } + Map userNameMap = new HashMap<>(); + Map deptCodeNameMap = new HashMap<>(); + PatientInfoConverter converter = new PatientInfoConverter(userNameMap, deptCodeNameMap); + List basicList = jswzhPatientInfoViews.stream().map(converter::convertArchiveBasicInfo).collect(Collectors.toList()); + insertOrUpdate(basicList); + } +} diff --git a/src/main/java/com/docus/server/archive/utils/PingYinUtil.java b/src/main/java/com/docus/server/archive/utils/PingYinUtil.java new file mode 100644 index 0000000..02a01b8 --- /dev/null +++ b/src/main/java/com/docus/server/archive/utils/PingYinUtil.java @@ -0,0 +1,96 @@ +package com.docus.server.archive.utils; + +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; +import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; +import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; + +/** + * 拼音工具类 + * + * @author + */ +public class PingYinUtil { + /** + * 将字符串中的中文转化为拼音,其他字符不变 + * + * @param inputString + * @return + */ + public static String getPingYin(String inputString) { + HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); + format.setCaseType(HanyuPinyinCaseType.LOWERCASE); + format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + format.setVCharType(HanyuPinyinVCharType.WITH_V); + + char[] input = inputString.trim().toCharArray(); + String output = ""; + + try { + for (int i = 0; i < input.length; i++) { + if (Character.toString(input[i]).matches("[\\u4E00-\\u9FA5]+")) { + String[] temp = PinyinHelper.toHanyuPinyinStringArray(input[i], format); + output += temp[0]; + } else { + output += Character.toString(input[i]); + } + } + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + return output; + } + /** + * 获取汉字串拼音首字母,英文字符不变 + * @param chinese 汉字串 + * @return 汉语拼音首字母 + */ + public static String getFirstSpell(String chinese) { + StringBuffer pybf = new StringBuffer(); + char[] arr = chinese.toCharArray(); + HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); + defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); + defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + for (int i = 0; i < arr.length; i++) { + if (arr[i] > 128) { + try { + String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat); + if (temp != null) { + pybf.append(temp[0].charAt(0)); + } + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + } else { + pybf.append(arr[i]); + } + } + return pybf.toString().replaceAll("\\W", "").trim(); + } + /** + * 获取汉字串拼音,英文字符不变 + * @param chinese 汉字串 + * @return 汉语拼音 + */ + public static String getFullSpell(String chinese) { + StringBuffer pybf = new StringBuffer(); + char[] arr = chinese.toCharArray(); + HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); + defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); + defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + for (int i = 0; i < arr.length; i++) { + if (arr[i] > 128) { + try { + pybf.append(PinyinHelper.toHanyuPinyinStringArray(arr[i], defaultFormat)[0]); + } catch (BadHanyuPinyinOutputFormatCombination e) { + e.printStackTrace(); + } + } else { + pybf.append(arr[i]); + } + } + return pybf.toString(); + } +} diff --git a/src/main/java/com/docus/server/fsy/entity/JswzhPatientInfoView.java b/src/main/java/com/docus/server/fsy/entity/JswzhPatientInfoView.java new file mode 100644 index 0000000..b3c1113 --- /dev/null +++ b/src/main/java/com/docus/server/fsy/entity/JswzhPatientInfoView.java @@ -0,0 +1,60 @@ +package com.docus.server.fsy.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +/** + * @author YongBin Wen + * @date 2024/3/27 14:18 + */ +@ApiModel("佛山三院患者基础信息视图") +@Data +public class JswzhPatientInfoView { + @ApiModelProperty("ID号(唯一标识)") + private String JZH; + @ApiModelProperty("住院号") + private String ZY; + @ApiModelProperty("住院次数") + private Integer ZYCS; + @ApiModelProperty("姓名") + private String XM; + @ApiModelProperty("性别 M-男 F-女") + private String XB; + @ApiModelProperty("入院时间") + private Date RYRQ; + @ApiModelProperty("BQ 入院科室编码") + private String RYKSBQ; + @ApiModelProperty("MC 入院科室") + private String RYKSMC; + @ApiModelProperty("床号") + private String CWDM; + @ApiModelProperty("主管医生工号") + private String DQYS; + @ApiModelProperty("年龄 13岁8月或1天") + private String NL; + @ApiModelProperty("身份证号") + private String SFZH; + @ApiModelProperty("手机号") + private String LXDH; + @ApiModelProperty("出院日期") + private Date CYRQ; + @ApiModelProperty("当前科室编码") + private String DQBQ; + @ApiModelProperty("当前科室") + private String DQKS; + @ApiModelProperty("患者本次住院总费用") + private String ZJINE; + @ApiModelProperty("住院状态 R-住院登记 I-病房接诊 B-出院登记 O-出院结算 P-预约出院,N-无费退院(无效住院)") + private String ZYZT; + @ApiModelProperty("离院方式 1、医嘱离院 2、医嘱转院 3、医嘱转社区 4非医嘱离院 5.死亡 9 其他") + private String CYQK; + @ApiModelProperty("是否死亡 1死亡 0非死亡 用CYQK 5死亡") + private Integer SFSW; + @ApiModelProperty("删除标志 0未删除 3直接删除 没有删除一说,只有ZYZT字段 N-无费退院(无效住院)") + private String BRBZ; + @ApiModelProperty("记账卡号(用于护理查询)") + private String JZKH; +} diff --git a/src/main/java/com/docus/server/fsy/mapper/JswzhPatientInfoViewMapper.java b/src/main/java/com/docus/server/fsy/mapper/JswzhPatientInfoViewMapper.java new file mode 100644 index 0000000..5eefd70 --- /dev/null +++ b/src/main/java/com/docus/server/fsy/mapper/JswzhPatientInfoViewMapper.java @@ -0,0 +1,26 @@ +package com.docus.server.fsy.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.docus.server.fsy.entity.JswzhPatientInfoView; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author YongBin Wen + * @date 2024/3/27 15:55 + */ +@DS("fsy") +public interface JswzhPatientInfoViewMapper { + /** + * 获取全部在院数据 + */ + List getInHospital(); + + /** + * 根据出院时间范围(yyyy-MM-dd HH:mm:ss),分页 获取出院数据 + * @param startRow oracle ROWNUM 起始 + * @param endRow oracle ROWNUM 结束(包含) + */ + List getDischarge(@Param("disDateBegin") String disDateBegin, @Param("disDateEnd") String disDateEnd, @Param("startRow") int startRow, @Param("endRow") int endRow); +} diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index 4323945..22d35b9 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -33,11 +33,11 @@ spring: test-on-borrow: false test-on-return: false validation-query: select 1 - trusthis: - url: jdbc:sqlserver://200.100.104.22:1433;DatabaseName=hq_framework - username: WZH - password: 123.WZH - driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + fsy: + url: jdbc:oracle:thin:@192.168.1.102:1521:FSY + username: jsba_user + password: Jsba!@#$%12345 + driver-class-name: oracle.jdbc.driver.OracleDriver type: com.alibaba.druid.pool.DruidDataSource # 初始化配置 initial-size: 3 @@ -54,7 +54,7 @@ spring: test-while-idle: true test-on-borrow: false test-on-return: false - validation-query: select 1 + validation-query: select 1 from dual redis: host: redis.docus.cn password: JSdocus@702 diff --git a/src/main/resources/mapper/JswzhPatientInfoViewMapper.xml b/src/main/resources/mapper/JswzhPatientInfoViewMapper.xml new file mode 100644 index 0000000..dad3949 --- /dev/null +++ b/src/main/resources/mapper/JswzhPatientInfoViewMapper.xml @@ -0,0 +1,28 @@ + + + + + JZH,ZY,ZYCS,XM,XB,RYRQ,RYKSBQ,RYKSMC,CWDM,DQYS,NL,SFZH,LXDH,CYRQ,DQBQ,DQKS,ZJINE,ZYZT,CYQK,SFSW,BRBZ,JZKH + + + + + + + + diff --git a/src/main/resources/mapper/TBasicMapper.xml b/src/main/resources/mapper/TBasicMapper.xml new file mode 100644 index 0000000..4a7be12 --- /dev/null +++ b/src/main/resources/mapper/TBasicMapper.xml @@ -0,0 +1,54 @@ + + + + + INSERT INTO `docus_medicalrecord`.`t_basic` + (`patient_id`, `admiss_times`, `inpatient_no`, `name`, `name_spell`, + `sex`, `sex_name`,`age`, `age_month`, `age_day`, `id_card`, `telphone`, + `admiss_date`,`admiss_dept`, `admiss_dept_name`, + `dis_date`,`dis_dept`, `dis_dept_name`, + `attending`, `attending_name`, + `is_dead`,`file_source`, + `jzh`,`bed_no`, `jz_card_no`, `total_cost`, + `create_time`, `update_time`) VALUES + + ( + #{basic.patientId},#{basic.admissTimes},#{basic.inpatientNo},#{basic.name},#{basic.nameSpell}, + #{basic.sex},#{basic.sexName},#{basic.age},#{basic.ageMonth},#{basic.ageDay},#{basic.idCard},#{basic.telphone}, + #{basic.admissDate},#{basic.admissDept},#{basic.admissDeptName}, + #{basic.disDate},#{basic.disDept},#{basic.disDeptName}, + #{basic.attending},#{basic.attendingName}, + #{basic.isDead},#{basic.fileSource}, + #{basic.jzh},#{basic.bedNo},#{basic.jzCardNo},#{basic.totalCost}, + #{basic.createTime},#{basic.updateTime} + ) + + + + + UPDATE `docus_medicalrecord`.`t_basic` + set inpatient_no=#{basic.inpatientNo},admiss_times=#{basic.admissTimes},name=#{basic.name},name_spell=#{basic.nameSpell}, + `sex`= #{basic.sex}, `sex_name`=#{basic.sexName},`age`=#{basic.age}, `age_month`=#{basic.ageMonth}, + `age_day`=#{basic.ageDay}, `id_card`=#{basic.idCard}, `telphone`=#{basic.telphone}, + `admiss_date`=#{basic.admissDate},`admiss_dept`=#{basic.admissDept}, `admiss_dept_name`=#{basic.admissDeptName}, + `dis_date`= #{basic.disDate},`dis_dept`=#{basic.disDept}, `dis_dept_name`=#{basic.disDeptName}, + `attending`= #{basic.attending}, `attending_name`=#{basic.attendingName}, + `is_dead`=#{basic.isDead},`file_source`=#{basic.fileSource}, + `jzh`= #{basic.jzh},`bed_no`=#{basic.bedNo}, `jz_card_no`=#{basic.jzCardNo}, `total_cost`=#{basic.totalCost}, + `create_time`= #{basic.createTime}, `update_time`=#{basic.updateTime} + WHERE patient_id= #{basic.patientId}; + + + + +