患者基本信息增加接口上传Excel文件

This commit is contained in:
lxd 2025-03-12 12:43:37 +08:00
parent 7295a5b9a5
commit 03e3b95bd0
2 changed files with 134 additions and 0 deletions

View File

@ -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<InspectPatientInfoVO> 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<List<String>> 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<List<String>> data = new ArrayList<>();
while (rowIterator.hasNext()) {
org.apache.poi.ss.usermodel.Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
List<String> 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<Boolean> updatePatient(@Valid @RequestBody InspectPatientSaveReqVO updateReqVO) {

View File

@ -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;
}