liusheng
2 天以前 8249bbcc710c42f89c69fb0bd575094acd2e418d
smartor/src/main/java/com/smartor/service/impl/PatArchiveServiceImpl.java
@@ -30,6 +30,10 @@
import java.io.FileOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -650,11 +654,13 @@
        List<PatArchive> patArchiveList1 = DtoConversionUtils.sourceToTarget(patArchiveList, PatArchive.class);
        //给患者联系人赋值
//        for (PatArchive pa : patArchives) {
        for (PatArchive pa : patArchiveList1) {
            PatArchivecontact patArchivecontact = new PatArchivecontact();
            patArchivecontact.setPatid(pa.getId());
            pa.setPatArchivecontactList(patArchivecontactMapper.selectPatArchivecontactList(patArchivecontact));
            Map<String, String> map = calculateAge(pa.getBirthdate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(), LocalDate.now());
            pa.setAge(StringUtils.isNotEmpty(map.get("age")) ? Long.valueOf(map.get("age")) : null);
            pa.setAgeUnit(map.get("ageUnit") != null ? map.get("ageUnit") : "");
        }
        return patArchiveList1;
@@ -831,6 +837,7 @@
     * @return
     */
//    @Override
    /**
     * 获取患者信息总数(去重)
     *
@@ -854,7 +861,7 @@
        } else if (patArchiveReq.getAllhosp() != null && patArchiveReq.getAllhosp() == 2) {
            // 查看住院  1  查看门诊  2   查看体检  3 查看出院 4
//            count = patArchiveMapper.countPatArchiveInfoByOuthospQC(patArchiveReq);
            PatMedOuthospQueryReq req=new PatMedOuthospQueryReq();
            PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
            String deptcodes = CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) ? null : String.join(",", patArchiveReq.getLeaveldeptcodes());
            String leavehospitaldistrictcodes = CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) ? null : String.join(",", patArchiveReq.getLeavehospitaldistrictcodes());
            req.setDeptcode(deptcodes);
@@ -882,7 +889,7 @@
        List<PatArchiveOthreInfo> patArchiveList = new ArrayList<>();
        //门急诊信息,采用分表查询(先查门急诊的存储过程,再查患者基本信息表,关联条件:patid)
        PatMedOuthospQueryReq req=new PatMedOuthospQueryReq();
        PatMedOuthospQueryReq req = new PatMedOuthospQueryReq();
        String deptcodes = CollectionUtils.isEmpty(patArchiveReq.getLeaveldeptcodes()) ? null : String.join(",", patArchiveReq.getLeaveldeptcodes());
        String leavehospitaldistrictcodes = CollectionUtils.isEmpty(patArchiveReq.getLeavehospitaldistrictcodes()) ? null : String.join(",", patArchiveReq.getLeavehospitaldistrictcodes());
        req.setDeptcode(deptcodes);
@@ -891,10 +898,10 @@
        req.setDrname(StringUtils.isNotEmpty(patArchiveReq.getDrname()) ? patArchiveReq.getDrname() : null);
        req.setPatname(StringUtils.isNotEmpty(patArchiveReq.getName()) ? patArchiveReq.getName() : null);
        req.setDiagname(StringUtils.isNotEmpty(patArchiveReq.getLeavediagname()) ? patArchiveReq.getLeavediagname() : null);
        req.setPageNum(patArchiveReq.getPageNum()==null?null:patArchiveReq.getPageNum());
        req.setPageSize(patArchiveReq.getPageSize()==null?null:patArchiveReq.getPageSize());
        req.setPageNum(patArchiveReq.getPageNum() == null ? null : patArchiveReq.getPageNum());
        req.setPageSize(patArchiveReq.getPageSize() == null ? null : patArchiveReq.getPageSize());
        List<PatMedOuthosp> patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(req);
        for (PatMedOuthosp patMedOuthosp:patMedOuthosps ) {
        for (PatMedOuthosp patMedOuthosp : patMedOuthosps) {
            PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp.getPatid());
            PatArchiveOthreInfo patArchiveOthreInfo = DtoConversionUtils.sourceToTarget(patArchive, PatArchiveOthreInfo.class);
            patArchiveOthreInfo.setDeptcode(patMedOuthosp.getDeptcode());
@@ -905,5 +912,57 @@
        }
        return patArchiveList;
    }
    public Map<String, String> calculateAge(LocalDate birthdate, LocalDate today) {
        if (birthdate == null || today.isBefore(birthdate)) {
            return null;
        }
        Map<String, String> ageMap = new HashMap<>();
        Period period = Period.between(birthdate, today);
        long totalDays = ChronoUnit.DAYS.between(birthdate, today);
        long totalMonths = ChronoUnit.MONTHS.between(birthdate, today);
        int years = period.getYears();
        int months = period.getMonths();
        int days = period.getDays();
        String ageUnit;
        Integer age;
        String ageUnit2 = null;
        Integer age2 = null;
        if (totalDays < 90) {
            // 小于 1 个月,按天计算
            ageUnit = "天";
            age = (int) totalDays;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", null);
            ageMap.put("ageUnit2", null);
        } else if (totalMonths < 36) {
            // 小于 1 年,按月 + 天计算
            ageUnit = "月";
            age = (int) totalMonths;
            ageUnit2 = "天";
            age2 = days;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", age2 != null ? age2.toString() : null);
            ageMap.put("ageUnit2", ageUnit2);
        } else {
            // 大于 1 年,按年 + 月计算
            ageUnit = "岁";
            age = years;
            ageUnit2 = "月";
            age2 = months;
            ageMap.put("age", age != null ? age.toString() : null);
            ageMap.put("ageUnit", ageUnit);
            ageMap.put("age2", age2 != null ? age2.toString() : null);
            ageMap.put("ageUnit2", ageUnit2);
        }
        return ageMap;
    }
}