新增通过Excel登记患者信息和检查项目方法
This commit is contained in:
parent
7528f43794
commit
b752be334f
@ -50,6 +50,12 @@
|
||||
<version>2.4.1-jdk8-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-digester</groupId>
|
||||
<artifactId>commons-digester</artifactId>
|
||||
<version>2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
@ -3,6 +3,10 @@ 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 cn.iocoder.yudao.module.inspect.controller.admin.inspectpatientitems.vo.InspectPatientitemsSaveReqVO;
|
||||
import cn.iocoder.yudao.module.inspect.dal.dataobject.inspectitems.InspectitemsDO;
|
||||
import cn.iocoder.yudao.module.inspect.service.exammodule.ExammoduleService;
|
||||
import cn.iocoder.yudao.module.inspect.service.inspectpatientitems.InspectPatientitemsService;
|
||||
import com.mysql.cj.result.Row;
|
||||
import org.apache.poi.sl.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
@ -18,6 +22,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@ -55,6 +60,12 @@ public class InspectPatientController {
|
||||
private InspectPatientService patientService;
|
||||
@Resource
|
||||
private ConfigService configService;
|
||||
|
||||
@Resource
|
||||
private ExammoduleService exammoduleService;
|
||||
@Resource
|
||||
private InspectPatientitemsService patientitemsService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建患者信息")
|
||||
public CommonResult<Integer> createPatient(@Valid @RequestBody InspectPatientSaveReqVO createReqVO) {
|
||||
@ -100,35 +111,114 @@ public class InspectPatientController {
|
||||
|
||||
@PostMapping("/uploadExcel")
|
||||
@Operation(summary = "上传Excel文件")
|
||||
public List<List<String>> uploadExcel(@RequestParam("file") MultipartFile file) {
|
||||
public CommonResult<String> uploadExcel(@RequestParam("file") MultipartFile file) {
|
||||
if (file.isEmpty()) {
|
||||
throw new RuntimeException("文件为空");
|
||||
return success("文件为空");
|
||||
}
|
||||
|
||||
try (InputStream inputStream = file.getInputStream();
|
||||
Workbook workbook = new XSSFWorkbook(inputStream)) {
|
||||
|
||||
// 获取第一个Sheet
|
||||
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);
|
||||
if (sheet == null) {
|
||||
return success("Sheet为空");
|
||||
}
|
||||
|
||||
return data;
|
||||
Iterator<org.apache.poi.ss.usermodel.Row> rowIterator = sheet.iterator();
|
||||
|
||||
// 读取表头
|
||||
if (!rowIterator.hasNext()) {
|
||||
return success("Excel文件为空");
|
||||
}
|
||||
org.apache.poi.ss.usermodel.Row headerRow = rowIterator.next();
|
||||
Map<Integer, String> headerMap = new HashMap<>();
|
||||
for (int i = 0; i < headerRow.getLastCellNum(); i++) {
|
||||
Cell cell = headerRow.getCell(i);
|
||||
if (cell != null) {
|
||||
headerMap.put(i, getCellValue(cell));
|
||||
}
|
||||
}
|
||||
|
||||
// 验证列标题(可选)
|
||||
String[] expectedHeaders = {"姓名", "身份证号", "出生日期","性别","联系电话","住址"};
|
||||
for (String expectedHeader : expectedHeaders) {
|
||||
if (!headerMap.containsValue(expectedHeader)) {
|
||||
return success("列标题不符合预期");
|
||||
}
|
||||
}
|
||||
|
||||
// 读取数据行 需要插入患者信息和患者项目信息
|
||||
//检查套餐信息
|
||||
List<InspectitemsDO> doList= exammoduleService.selectItemsByExamModuleID(1001);
|
||||
//患者信息
|
||||
List<InspectPatientSaveReqVO> dataList = new ArrayList<>();
|
||||
//检查项目
|
||||
List<InspectPatientitemsSaveReqVO> dataList2 = new ArrayList<>();
|
||||
while (rowIterator.hasNext()) {
|
||||
org.apache.poi.ss.usermodel.Row row = rowIterator.next();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
String MedicalSn= Long.toString(timestamp);
|
||||
//患者信息
|
||||
InspectPatientSaveReqVO rowData = new InspectPatientSaveReqVO();
|
||||
//套餐信息
|
||||
InspectPatientitemsSaveReqVO rowData2 = new InspectPatientitemsSaveReqVO();
|
||||
rowData.setMedicalSn(MedicalSn);
|
||||
//填充患者信息
|
||||
for (int i = 0; i < row.getLastCellNum(); i++) {
|
||||
Cell cell = row.getCell(i);
|
||||
if (cell != null) {
|
||||
String columnName = headerMap.get(i);
|
||||
switch (columnName) {
|
||||
case "姓名":
|
||||
rowData.setPName(getCellValue(cell));
|
||||
break;
|
||||
case "身份证号":
|
||||
rowData.setCardId(getCellValue(cell));
|
||||
break;
|
||||
case "出生日期":
|
||||
rowData.setBirthday(LocalDate.parse(getCellValue(cell)));
|
||||
break;
|
||||
case "性别":
|
||||
rowData.setGender(getCellValue(cell));
|
||||
break;
|
||||
case "联系电话":
|
||||
rowData.setPhoneNum(getCellValue(cell));
|
||||
break;
|
||||
case "住址":
|
||||
rowData.setDomicileaddress(getCellValue(cell));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rowData.setStatus(0);
|
||||
rowData.setCreateTime(LocalDateTime.now());
|
||||
dataList.add(rowData);
|
||||
//填写项目信息
|
||||
for (InspectitemsDO inspectitemsDO:doList)
|
||||
{
|
||||
rowData2.setMedicalSn(MedicalSn);
|
||||
rowData2.setItemCode(inspectitemsDO.getItemCode());
|
||||
rowData2.setItemName(inspectitemsDO.getItemName());
|
||||
rowData2.setPrice(inspectitemsDO.getPrice());
|
||||
rowData2.setSectionID(inspectitemsDO.getSectionID());
|
||||
rowData2.setItemStatus("0");
|
||||
rowData2.setGroupname(inspectitemsDO.getGroupname());
|
||||
rowData2.setGroupcode(inspectitemsDO.getGroupcode());
|
||||
rowData2.setCreateTime(LocalDateTime.now());
|
||||
rowData2.setHighValue(inspectitemsDO.getHighValue());
|
||||
rowData2.setLowValue(inspectitemsDO.getLowValue());
|
||||
rowData2.setMealfrontorafter(inspectitemsDO.getMealfrontorafter());
|
||||
dataList2.add(rowData2);
|
||||
}
|
||||
}
|
||||
patientService.createPatientList(dataList);
|
||||
patientitemsService.createPatientListitems(dataList2);
|
||||
|
||||
return success("上传成功");
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("读取Excel文件失败", e);
|
||||
return success("读取Excel文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,11 @@ public interface InspectPatientService {
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createPatient(@Valid InspectPatientSaveReqVO createReqVO);
|
||||
/*
|
||||
*
|
||||
* 批量插入患者信息数据
|
||||
* */
|
||||
boolean createPatientList(List<InspectPatientSaveReqVO> listcreateReqVO);
|
||||
|
||||
/**
|
||||
* 更新患者信息
|
||||
|
@ -1,10 +1,8 @@
|
||||
package cn.iocoder.yudao.module.inspect.service.inspectpatient;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectpatient.vo.*;
|
||||
@ -15,6 +13,8 @@ import cn.iocoder.yudao.module.inspect.dal.mysql.inspectpatient.InspectPatientMa
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
@ -37,6 +37,13 @@ public class InspectPatientServiceImpl implements InspectPatientService {
|
||||
// 返回
|
||||
return patient.getId();
|
||||
}
|
||||
@Override
|
||||
public boolean createPatientList(List<InspectPatientSaveReqVO> listcreateReqVO)
|
||||
{
|
||||
// 插入
|
||||
List<InspectPatientDO> patient = BeanUtils.toBean(listcreateReqVO, InspectPatientDO.class);
|
||||
return patientMapper.insertBatch(patient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePatient(InspectPatientSaveReqVO updateReqVO) {
|
||||
|
Loading…
Reference in New Issue
Block a user