From 03e3b95bd01057de98c8e9e4f68982be14d26043 Mon Sep 17 00:00:00 2001 From: lxd <1004405501@qq.com> Date: Wed, 12 Mar 2025 12:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=A3=E8=80=85=E5=9F=BA=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?Excel=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InspectPatientController.java | 91 +++++++++++++++++++ .../vo/InspectPatientInfoVO.java | 43 +++++++++ 2 files changed, 134 insertions(+) create mode 100644 yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/vo/InspectPatientInfoVO.java diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java index 0b640ad..10a1418 100644 --- a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/InspectPatientController.java @@ -3,6 +3,12 @@ package cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient; import cn.iocoder.yudao.framework.common.util.io.FileUtils; import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO; import cn.iocoder.yudao.module.infra.service.config.ConfigService; +import com.mysql.cj.result.Row; +import org.apache.poi.sl.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; import org.springframework.security.access.prepost.PreAuthorize; @@ -10,6 +16,10 @@ import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import java.io.InputStream; +import java.time.LocalDate; +import java.time.Period; +import java.time.format.DateTimeFormatter; import java.util.*; import java.io.IOException; @@ -17,6 +27,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import static cn.hutool.poi.excel.cell.CellUtil.getCellValue; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; @@ -27,6 +39,7 @@ import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; import cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient.vo.*; import cn.iocoder.yudao.module.inspect.dal.dataobject.inspectpatient.InspectPatientDO; import cn.iocoder.yudao.module.inspect.service.inspectpatient.InspectPatientService; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; @@ -58,7 +71,85 @@ public class InspectPatientController { return success(patientService.createPatient(createReqVO)); } + @GetMapping("/getUSPatientInfo") + @Operation(summary = "对外根据体检编号获取患者信息") + public CommonResult getUSPatientInfo(@RequestParam("medicalSn") String medicalSn) + { + InspectPatientInfoVO patientInfoVO=new InspectPatientInfoVO(); + InspectPatientDO patientDO= patientService.getPatientInfo(medicalSn); + if(patientDO!=null) + { + patientInfoVO.setJianchaid(patientDO.getCardId()); + patientInfoVO.setJianchabh(patientDO.getMedicalSn()); + patientInfoVO.setName(patientDO.getPName()); + patientInfoVO.setBirthdate(patientDO.getBirthday().toLocalDate().toString()); + // 计算年龄 + LocalDate birthDate = patientDO.getBirthday().toLocalDate(); + LocalDate currentDate = LocalDate.now(); + int age = Period.between(birthDate, currentDate).getYears(); + patientInfoVO.setAge(String.valueOf(age)); + patientInfoVO.setSex(patientDO.getGender()); + // 使用 DateTimeFormatter 格式化 medicalDateTime + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + patientInfoVO.setKaifangsj(patientDO.getMedicalDateTime().format(formatter)); + patientInfoVO.setExamItemName("超声检查"); + patientInfoVO.setExamItemCode("US00001"); + } + return success(patientInfoVO); + } + @PostMapping("/uploadExcel") + @Operation(summary = "上传Excel文件") + public List> uploadExcel(@RequestParam("file") MultipartFile file) { + if (file.isEmpty()) { + throw new RuntimeException("文件为空"); + } + + try (InputStream inputStream = file.getInputStream(); + Workbook workbook = new XSSFWorkbook(inputStream)) { + + Sheet sheet = (Sheet) workbook.getSheetAt(0); + Iterator< org.apache.poi.ss.usermodel.Row> rowIterator = sheet.iterator(); + + List> data = new ArrayList<>(); + while (rowIterator.hasNext()) { + org.apache.poi.ss.usermodel.Row row = rowIterator.next(); + Iterator cellIterator = row.cellIterator(); + + List rowData = new ArrayList<>(); + while (cellIterator.hasNext()) { + Cell cell = cellIterator.next(); + String cellValue = getCellValue(cell); + rowData.add(cellValue); + } + data.add(rowData); + } + + return data; + + } catch (IOException e) { + throw new RuntimeException("读取Excel文件失败", e); + } + } + + private String getCellValue(Cell cell) { + switch (cell.getCellType()) { + case STRING: + return cell.getStringCellValue(); + case NUMERIC: + if (DateUtil.isCellDateFormatted(cell)) { + return cell.getDateCellValue().toString(); + } else { + return String.valueOf(cell.getNumericCellValue()); + } + case BOOLEAN: + return String.valueOf(cell.getBooleanCellValue()); + case FORMULA: + return cell.getCellFormula(); + default: + return ""; + } + } @PutMapping("/update") @Operation(summary = "更新患者信息") public CommonResult updatePatient(@Valid @RequestBody InspectPatientSaveReqVO updateReqVO) { diff --git a/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/vo/InspectPatientInfoVO.java b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/vo/InspectPatientInfoVO.java new file mode 100644 index 0000000..60f28a4 --- /dev/null +++ b/yudao-module-inspect/yudao-module-inspect-biz/src/main/java/cn/iocoder/yudao/module/inspect/controller/admin/inspectpatient/vo/InspectPatientInfoVO.java @@ -0,0 +1,43 @@ +package cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient.vo; + +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class InspectPatientInfoVO { + + @Schema(description = "患者ID") + private String jianchaid; + + @Schema(description = "姓名") + private String name; + + @Schema(description = "检查编号") + private String jianchabh; + + @Schema(description = "出生日期") + private String birthdate; + + @Schema(description = "年龄") + private String age; + + @Schema(description = "性别") + private String sex; + + @Schema(description = "医院名称") + private String yiyuanname; + + @Schema(description = "医院编码") + private String yiyuancode; + + @Schema(description = "开单时间") + private String kaifangsj; + + @Schema(description = "检查名称") + private String examItemName; + + @Schema(description = "检查编码") + private String examItemCode; + +}