Commit 04d6318baec753ef11c9d0face4af5bfdbdc0ba6
1 parent
db3ab800f6
Exists in
master
and in
6 other branches
体重管理相关代码
Showing 3 changed files with 106 additions and 12 deletions
platform-dal/src/main/java/com/lyms/platform/pojo/PatientWeight.java
View file @
04d6318
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | import org.springframework.data.mongodb.core.mapping.Document; |
4 | 4 | |
5 | 5 | import java.util.Date; |
6 | +import java.util.HashMap; | |
7 | +import java.util.Map; | |
6 | 8 | |
7 | 9 | /** |
8 | 10 | * 孕产妇体重管理 |
... | ... | @@ -49,6 +51,12 @@ |
49 | 51 | // 当前体重 |
50 | 52 | private String nowWeight; |
51 | 53 | |
54 | + private Map<Integer, String> weights = new HashMap(){{ | |
55 | + for (int i = 1; i < 41; i++) { | |
56 | + put(i, 0); | |
57 | + } | |
58 | + }}; | |
59 | + | |
52 | 60 | // 前囟 单胎/双胎/多胎 |
53 | 61 | private String bregmatic; |
54 | 62 | |
... | ... | @@ -58,6 +66,14 @@ |
58 | 66 | private String bmi; |
59 | 67 | |
60 | 68 | private Date lastMenses; |
69 | + | |
70 | + public Map<Integer, String> getWeights() { | |
71 | + return weights; | |
72 | + } | |
73 | + | |
74 | + public void setWeights(Map<Integer, String> weights) { | |
75 | + this.weights = weights; | |
76 | + } | |
61 | 77 | |
62 | 78 | public String getVcCardNo() { |
63 | 79 | return vcCardNo; |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/PatientWeightServiceImpl.java
View file @
04d6318
... | ... | @@ -8,9 +8,11 @@ |
8 | 8 | import com.lyms.platform.operate.web.facade.AutoMatchFacade; |
9 | 9 | import com.lyms.platform.operate.web.service.PatientWeightService; |
10 | 10 | import com.lyms.platform.operate.web.utils.CollectionUtils; |
11 | +import com.lyms.platform.operate.web.utils.MathUtil; | |
11 | 12 | import com.lyms.platform.operate.web.utils.MongoUtil; |
12 | 13 | import com.lyms.platform.pojo.PatientWeight; |
13 | 14 | import com.lyms.platform.pojo.Patients; |
15 | +import org.apache.commons.collections.MapUtils; | |
14 | 16 | import org.apache.commons.lang.StringUtils; |
15 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
16 | 18 | import org.springframework.data.domain.Sort; |
17 | 19 | |
... | ... | @@ -35,7 +37,27 @@ |
35 | 37 | @Autowired |
36 | 38 | private MongoUtil mongoUtil; |
37 | 39 | |
40 | + private Map<Integer, Double> highMap = new HashMap<>(); | |
38 | 41 | |
42 | + /** | |
43 | + * 最低:0~13 : 0~1.9 13~40 1.9~11.9 | |
44 | + * 最高: 0~2.2 2.2~15.9 | |
45 | + */ | |
46 | + static { | |
47 | + Map<Integer, Double> highMap = new HashMap<>(); | |
48 | + double avg = 1.9 / 13; | |
49 | + for (int i = 0; i <= 13; i++) { | |
50 | + highMap.put(i, i * avg); | |
51 | + } | |
52 | + | |
53 | + double avg2 = 10.0 / 27; | |
54 | + for (int i = 1; i <= 27; i++) { | |
55 | + highMap.put(13 + i, i * avg2); | |
56 | + } | |
57 | + } | |
58 | + | |
59 | + | |
60 | + | |
39 | 61 | @Override |
40 | 62 | public BaseResponse init() { |
41 | 63 | List<Map<String, Object>> bregmaticEnums2 = EnumUtil.toJson(BregmaticEnums2.class); |
42 | 64 | |
... | ... | @@ -45,7 +67,18 @@ |
45 | 67 | |
46 | 68 | @Override |
47 | 69 | public BaseResponse addOrUpdate(Integer userId, PatientWeight patientWeight) { |
70 | + String nowWeight = patientWeight.getNowWeight(); | |
48 | 71 | if(StringUtils.isEmpty(patientWeight.getId())) { |
72 | + if(StringUtils.isNotBlank(nowWeight) && StringUtils.isNotBlank(patientWeight.getPatientId())) { | |
73 | + Map<Integer, String> weights = new HashMap<>(); | |
74 | + PatientWeight weight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId())), PatientWeight.class); | |
75 | + if(weight != null && MapUtils.isNotEmpty(weight.getWeights())) { | |
76 | + weights = weight.getWeights(); | |
77 | + } | |
78 | + weights.put(DateUtil.getWeek(new Date()), nowWeight); | |
79 | + patientWeight.setWeights(weights); | |
80 | + } | |
81 | + | |
49 | 82 | String hospitalId = autoMatchFacade.getHospitalId(userId); |
50 | 83 | patientWeight.setHospitalId(hospitalId); |
51 | 84 | patientWeight.setOperaterId(userId.toString()); |
... | ... | @@ -66,6 +99,14 @@ |
66 | 99 | mongoTemplate.save(patientWeight); |
67 | 100 | return RespBuilder.buildSuccess(patientWeight.getId()); |
68 | 101 | } else { |
102 | + if(StringUtils.isNotBlank(nowWeight)) { | |
103 | + PatientWeight pw = mongoTemplate.findById(patientWeight.getId(), PatientWeight.class); | |
104 | + if(pw != null) { | |
105 | + Map<Integer, String> weights = MapUtils.isEmpty(pw.getWeights()) ? new HashMap<Integer, String>() : pw.getWeights(); | |
106 | + weights.put(DateUtil.getWeek(new Date()), nowWeight); | |
107 | + patientWeight.setWeights(weights); | |
108 | + } | |
109 | + } | |
69 | 110 | patientWeight.setOperaterId(userId.toString()); |
70 | 111 | Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(patientWeight)); |
71 | 112 | mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(patientWeight.getId())), update, PatientWeight.class); |
... | ... | @@ -142,7 +183,7 @@ |
142 | 183 | map.put("bregmatic", BregmaticEnums2.getName(patientWeight.getBregmatic())); |
143 | 184 | map.put("bim", patientWeight.getBmi()); // 体质指数(BMI)=体重(kg)÷身高^2(m) |
144 | 185 | |
145 | - setReport(map); | |
186 | + setReport(map, patientWeight.getWeights()); | |
146 | 187 | |
147 | 188 | CollectionUtils.removeNullValue(map); |
148 | 189 | return RespBuilder.buildSuccess(map); |
... | ... | @@ -186,9 +227,6 @@ |
186 | 227 | setGuide(week, map); // 设置指南 |
187 | 228 | } |
188 | 229 | |
189 | - | |
190 | - | |
191 | - | |
192 | 230 | CollectionUtils.removeNullValue(map); |
193 | 231 | return RespBuilder.buildSuccess(map); |
194 | 232 | } |
195 | 233 | |
196 | 234 | |
... | ... | @@ -496,19 +534,28 @@ |
496 | 534 | } |
497 | 535 | } |
498 | 536 | |
499 | - public void setReport(Map<String,Object> report) { | |
537 | + public void setReport(Map<String, Object> report, Map<Integer, String> weights) { | |
500 | 538 | Map<String, Object> reportModel = new HashMap<>(); |
501 | - List<Integer> xAxis = new ArrayList<>(); | |
502 | - for (int i = 0; i < 40; i++) { | |
503 | - xAxis.add(i + 1); | |
504 | - } | |
505 | - reportModel.put("xAxis", xAxis); | |
539 | + reportModel.put("xAxis", MapUtils.isNotEmpty(weights) ? weights.keySet() : new ArrayList<>()); | |
506 | 540 | |
507 | 541 | List<Map<String, Object>> series = new ArrayList<>(); |
508 | 542 | Map<String, Object> port = new HashMap<>(); |
509 | 543 | List<Object> list = new ArrayList<>(); |
510 | - list.add(Arrays.asList(1, 3)); | |
511 | - list.add(Arrays.asList(2, 4.2)); | |
544 | + if(MapUtils.isNotEmpty(weights)) { | |
545 | + Iterator<Map.Entry<Integer, String>> iterator = weights.entrySet().iterator(); | |
546 | + boolean firstFlag = true; | |
547 | + String before = ""; | |
548 | + while (iterator.hasNext()) { | |
549 | + Map.Entry<Integer, String> next = iterator.next(); | |
550 | + before = next.getValue(); | |
551 | + if(firstFlag) { | |
552 | + firstFlag = false; | |
553 | + list.add(Arrays.asList(next.getKey(), 0)); | |
554 | + } else { | |
555 | + list.add(Arrays.asList(next.getKey(), getDiff(before, next.getValue()))); | |
556 | + } | |
557 | + } | |
558 | + } | |
512 | 559 | port.put("portData", list); |
513 | 560 | series.add(port); |
514 | 561 | |
... | ... | @@ -528,5 +575,23 @@ |
528 | 575 | |
529 | 576 | report.put("reportModel", reportModel); |
530 | 577 | } |
578 | + | |
579 | + /** | |
580 | + * 获取两个体重之间相差的数值 | |
581 | + */ | |
582 | + private Double getDiff(String before, String now) { | |
583 | + Double b = Double.parseDouble(before); | |
584 | + Double n = Double.parseDouble(now); | |
585 | + return n - b; | |
586 | + } | |
587 | + | |
588 | + public static void main(String[] args) { | |
589 | + Set<Integer> keySet = new HashSet<>(); | |
590 | + keySet.add(1); | |
591 | + keySet.add(3); | |
592 | + keySet.add(5); | |
593 | + | |
594 | + } | |
595 | + | |
531 | 596 | } |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MathUtil.java
View file @
04d6318
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | import org.apache.commons.lang.StringUtils; |
4 | 4 | |
5 | +import java.math.BigDecimal; | |
5 | 6 | import java.text.DecimalFormat; |
6 | 7 | |
7 | 8 | /** |
... | ... | @@ -56,6 +57,18 @@ |
56 | 57 | return getProportion(obj, Integer.parseInt(count.toString())); |
57 | 58 | return "0.00%"; |
58 | 59 | } |
60 | + | |
61 | + /** | |
62 | + * 计算相除的值 保留digit位小数 | |
63 | + * @param a | |
64 | + * @param b | |
65 | + * @param digit | |
66 | + * @return | |
67 | + */ | |
68 | + public static Double division(Double a, Double b, Integer digit) { | |
69 | + return new BigDecimal(a / b).setScale(digit, BigDecimal.ROUND_HALF_UP).doubleValue(); | |
70 | + } | |
71 | + | |
59 | 72 | |
60 | 73 | } |