From 04d6318baec753ef11c9d0face4af5bfdbdc0ba6 Mon Sep 17 00:00:00 2001 From: "litao@lymsh.com" Date: Tue, 12 Sep 2017 17:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=93=E9=87=8D=E7=AE=A1=E7=90=86=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lyms/platform/pojo/PatientWeight.java | 16 ++++ .../web/service/impl/PatientWeightServiceImpl.java | 89 +++++++++++++++++++--- .../lyms/platform/operate/web/utils/MathUtil.java | 13 ++++ 3 files changed, 106 insertions(+), 12 deletions(-) diff --git a/platform-dal/src/main/java/com/lyms/platform/pojo/PatientWeight.java b/platform-dal/src/main/java/com/lyms/platform/pojo/PatientWeight.java index 5098aa7..878aed7 100644 --- a/platform-dal/src/main/java/com/lyms/platform/pojo/PatientWeight.java +++ b/platform-dal/src/main/java/com/lyms/platform/pojo/PatientWeight.java @@ -3,6 +3,8 @@ package com.lyms.platform.pojo; import org.springframework.data.mongodb.core.mapping.Document; import java.util.Date; +import java.util.HashMap; +import java.util.Map; /** * 孕产妇体重管理 @@ -49,6 +51,12 @@ public class PatientWeight { // 当前体重 private String nowWeight; + private Map weights = new HashMap(){{ + for (int i = 1; i < 41; i++) { + put(i, 0); + } + }}; + // 前囟 单胎/双胎/多胎 private String bregmatic; @@ -59,6 +67,14 @@ public class PatientWeight { private Date lastMenses; + public Map getWeights() { + return weights; + } + + public void setWeights(Map weights) { + this.weights = weights; + } + public String getVcCardNo() { return vcCardNo; } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java index 692f0e4..5c8f91d 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java @@ -8,9 +8,11 @@ import com.lyms.platform.common.utils.*; import com.lyms.platform.operate.web.facade.AutoMatchFacade; import com.lyms.platform.operate.web.service.PatientWeightService; import com.lyms.platform.operate.web.utils.CollectionUtils; +import com.lyms.platform.operate.web.utils.MathUtil; import com.lyms.platform.operate.web.utils.MongoUtil; import com.lyms.platform.pojo.PatientWeight; import com.lyms.platform.pojo.Patients; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Sort; @@ -35,6 +37,26 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient @Autowired private MongoUtil mongoUtil; + private Map highMap = new HashMap<>(); + + /** + * 最低:0~13 : 0~1.9 13~40 1.9~11.9 + * 最高: 0~2.2 2.2~15.9 + */ + static { + Map highMap = new HashMap<>(); + double avg = 1.9 / 13; + for (int i = 0; i <= 13; i++) { + highMap.put(i, i * avg); + } + + double avg2 = 10.0 / 27; + for (int i = 1; i <= 27; i++) { + highMap.put(13 + i, i * avg2); + } + } + + @Override public BaseResponse init() { @@ -45,7 +67,18 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient @Override public BaseResponse addOrUpdate(Integer userId, PatientWeight patientWeight) { + String nowWeight = patientWeight.getNowWeight(); if(StringUtils.isEmpty(patientWeight.getId())) { + if(StringUtils.isNotBlank(nowWeight) && StringUtils.isNotBlank(patientWeight.getPatientId())) { + Map weights = new HashMap<>(); + PatientWeight weight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId())), PatientWeight.class); + if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) { + weights = weight.getWeights(); + } + weights.put(DateUtil.getWeek(new Date()), nowWeight); + patientWeight.setWeights(weights); + } + String hospitalId = autoMatchFacade.getHospitalId(userId); patientWeight.setHospitalId(hospitalId); patientWeight.setOperaterId(userId.toString()); @@ -66,6 +99,14 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient mongoTemplate.save(patientWeight); return RespBuilder.buildSuccess(patientWeight.getId()); } else { + if(StringUtils.isNotBlank(nowWeight)) { + PatientWeight pw = mongoTemplate.findById(patientWeight.getId(), PatientWeight.class); + if(pw != null) { + Map weights = MapUtils.isEmpty(pw.getWeights()) ? new HashMap() : pw.getWeights(); + weights.put(DateUtil.getWeek(new Date()), nowWeight); + patientWeight.setWeights(weights); + } + } patientWeight.setOperaterId(userId.toString()); Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(patientWeight)); mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(patientWeight.getId())), update, PatientWeight.class); @@ -142,7 +183,7 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient map.put("bregmatic", BregmaticEnums2.getName(patientWeight.getBregmatic())); map.put("bim", patientWeight.getBmi()); // 体质指数(BMI)=体重(kg)÷身高^2(m) - setReport(map); + setReport(map, patientWeight.getWeights()); CollectionUtils.removeNullValue(map); return RespBuilder.buildSuccess(map); @@ -186,9 +227,6 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient setGuide(week, map); // 设置指南 } - - - CollectionUtils.removeNullValue(map); return RespBuilder.buildSuccess(map); } @@ -496,19 +534,28 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient } } - public void setReport(Map report) { + public void setReport(Map report, Map weights) { Map reportModel = new HashMap<>(); - List xAxis = new ArrayList<>(); - for (int i = 0; i < 40; i++) { - xAxis.add(i + 1); - } - reportModel.put("xAxis", xAxis); + reportModel.put("xAxis", MapUtils.isNotEmpty(weights) ? weights.keySet() : new ArrayList<>()); List> series = new ArrayList<>(); Map port = new HashMap<>(); List list = new ArrayList<>(); - list.add(Arrays.asList(1, 3)); - list.add(Arrays.asList(2, 4.2)); + if(MapUtils.isNotEmpty(weights)) { + Iterator> iterator = weights.entrySet().iterator(); + boolean firstFlag = true; + String before = ""; + while (iterator.hasNext()) { + Map.Entry next = iterator.next(); + before = next.getValue(); + if(firstFlag) { + firstFlag = false; + list.add(Arrays.asList(next.getKey(), 0)); + } else { + list.add(Arrays.asList(next.getKey(), getDiff(before, next.getValue()))); + } + } + } port.put("portData", list); series.add(port); @@ -528,4 +575,22 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient report.put("reportModel", reportModel); } + + /** + * 获取两个体重之间相差的数值 + */ + private Double getDiff(String before, String now) { + Double b = Double.parseDouble(before); + Double n = Double.parseDouble(now); + return n - b; + } + + public static void main(String[] args) { + Set keySet = new HashSet<>(); + keySet.add(1); + keySet.add(3); + keySet.add(5); + + } + } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java index 1163a5c..7225e10 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java @@ -2,6 +2,7 @@ package com.lyms.platform.operate.web.utils; import org.apache.commons.lang.StringUtils; +import java.math.BigDecimal; import java.text.DecimalFormat; /** @@ -57,4 +58,16 @@ public class MathUtil { return "0.00%"; } + /** + * 计算相除的值 保留digit位小数 + * @param a + * @param b + * @param digit + * @return + */ + public static Double division(Double a, Double b, Integer digit) { + return new BigDecimal(a / b).setScale(digit, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + } -- 1.8.3.1