| | |
| | | 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; |
| | |
| | | |
| | | 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; |
| | |
| | | * @return |
| | | */ |
| | | // @Override |
| | | |
| | | /** |
| | | * 获取患者信息总数(去重) |
| | | * |
| | |
| | | } |
| | | 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; |
| | | } |
| | | } |
| | | |