|
|
@@ -1,6 +1,9 @@
|
|
|
package cn.iocoder.yudao.module.system.service.biz;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
|
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyHealthRecordImportExcelVO;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.biz.vo.ElderlyHealthRecordPageReqVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyHealthRecordDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyInfoDO;
|
|
|
@@ -12,10 +15,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class ElderlyHealthRecordServiceImpl implements ElderlyHealthRecordService {
|
|
|
@@ -74,5 +81,73 @@ public class ElderlyHealthRecordServiceImpl implements ElderlyHealthRecordServic
|
|
|
elderlyHealthRecordMapper.updateById(elderlyHealthRecordDO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map<String, Object> importHealthRecord(List<ElderlyHealthRecordImportExcelVO> dataList) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ List<ElderlyHealthRecordImportExcelVO> errorList = new ArrayList<>();
|
|
|
+ int successCount = 0;
|
|
|
+ for (ElderlyHealthRecordImportExcelVO vo : dataList) {
|
|
|
+ // 1. 以身份证匹配长者
|
|
|
+ ElderlyInfoDO elderlyInfoDO = elderlyInfoMapper.selectOne(new LambdaQueryWrapperX<ElderlyInfoDO>()
|
|
|
+ .eq(ElderlyInfoDO::getIdCard, vo.getIdCard()));
|
|
|
+ if (elderlyInfoDO == null) {
|
|
|
+ vo.setErrorMsg("未找到身份证[" + vo.getIdCard() + "]对应的长者");
|
|
|
+ errorList.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long elderId = elderlyInfoDO.getId();
|
|
|
+
|
|
|
+ // 2. 查询该长者是否已存在健康档案
|
|
|
+ ElderlyHealthRecordDO existing = elderlyHealthRecordMapper.selectOne(new LambdaQueryWrapperX<ElderlyHealthRecordDO>()
|
|
|
+ .eq(ElderlyHealthRecordDO::getElderId, elderId));
|
|
|
+
|
|
|
+ if (existing != null) {
|
|
|
+ // 已存在 -> 更新
|
|
|
+ applyImportFields(existing, vo);
|
|
|
+ elderlyHealthRecordMapper.updateById(existing);
|
|
|
+ } else {
|
|
|
+ // 不存在 -> 新增
|
|
|
+ ElderlyHealthRecordDO record = new ElderlyHealthRecordDO();
|
|
|
+ record.setElderId(elderId);
|
|
|
+ record.setTenantId(elderlyInfoDO.getTenantId());
|
|
|
+ record.setCreateDate(LocalDateTime.now());
|
|
|
+ record.setCreateBy(SecurityFrameworkUtils.getLoginUserNickname());
|
|
|
+ applyImportFields(record, vo);
|
|
|
+ elderlyHealthRecordMapper.insert(record);
|
|
|
+ }
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
+ result.put("successCount", successCount);
|
|
|
+ result.put("failCount", errorList.size());
|
|
|
+ result.put("errorList", errorList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将导入 VO 中的字段映射到健康档案 DO
|
|
|
+ */
|
|
|
+ private void applyImportFields(ElderlyHealthRecordDO record, ElderlyHealthRecordImportExcelVO vo) {
|
|
|
+ record.setAsphyxiationByChoking(vo.getAsphyxiationByChoking());
|
|
|
+ record.setPressureSores(vo.getPressureSores());
|
|
|
+ record.setFallPreventionMeasures(vo.getFallPreventionMeasures());
|
|
|
+ record.setAssessSimpleMentalState(vo.getAssessSimpleMentalState());
|
|
|
+ record.setEmpyrosis(vo.getEmpyrosis());
|
|
|
+ record.setFallDown(vo.getFallDown());
|
|
|
+ record.setWanderAway(vo.getWanderAway());
|
|
|
+ record.setAntiEntertainment(vo.getAntiEntertainment());
|
|
|
+ record.setCommitSuicide(vo.getCommitSuicide());
|
|
|
+ record.setNurse(vo.getNurse());
|
|
|
+ record.setDoctor(vo.getDoctor());
|
|
|
+ record.setNurseAssistant(vo.getNurseAssistant());
|
|
|
+ record.setCareNote(vo.getCareNote());
|
|
|
+ // 过敏史写入过敏食物字段
|
|
|
+ record.setHistoryFoodAllergies(vo.getAllergyHistory());
|
|
|
+ // 既往病史
|
|
|
+ record.setPreexistingDisease(vo.getPastHistory());
|
|
|
+ record.setMedicationHistory(vo.getMedicationHistory());
|
|
|
+ record.setDietaryGuidelines(vo.getDietaryGuidelines());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|