Commit 074f85070bdd0dd389772c3e764de466cf4e9464

Authored by yangfei

Merge remote-tracking branch 'origin/master'

Showing 18 changed files

platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IBloodSugarDao.java View file @ 074f850
  1 +package com.lyms.platform.biz.dal;
  2 +
  3 +import com.lyms.platform.pojo.BloodSugar;
  4 +import org.springframework.data.mongodb.core.query.Query;
  5 +
  6 +/**
  7 + * 血压
  8 + */
  9 +public interface IBloodSugarDao {
  10 +
  11 + void add(BloodSugar bloodSugar);
  12 +
  13 + void updateXy(Query query, BloodSugar bloodSugar);
  14 +
  15 +}
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/BloodSugarDaoImpl.java View file @ 074f850
  1 +package com.lyms.platform.biz.dal.impl;
  2 +
  3 +import com.lyms.platform.biz.dal.IBloodSugarDao;
  4 +import com.lyms.platform.common.dao.BaseMongoDAOImpl;
  5 +import com.lyms.platform.pojo.BloodSugar;
  6 +import org.springframework.data.mongodb.core.query.Query;
  7 +import org.springframework.stereotype.Repository;
  8 +
  9 +@Repository
  10 +public class BloodSugarDaoImpl extends BaseMongoDAOImpl<BloodSugar> implements IBloodSugarDao {
  11 +
  12 + @Override
  13 + public void add(BloodSugar bloodSugar) {
  14 + save(bloodSugar);
  15 + }
  16 +
  17 + @Override
  18 + public void updateXy(Query query, BloodSugar bloodSugar) {
  19 + update(query, bloodSugar);
  20 + }
  21 +
  22 +}
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/BloodSugarService.java View file @ 074f850
  1 +package com.lyms.platform.biz.service;
  2 +
  3 +
  4 +import com.lyms.platform.biz.dal.IBloodSugarDao;
  5 +import com.lyms.platform.pojo.BloodSugar;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.data.mongodb.core.query.Criteria;
  8 +import org.springframework.data.mongodb.core.query.Query;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +@Service
  12 +public class BloodSugarService {
  13 +
  14 + @Autowired
  15 + private IBloodSugarDao bloodSugarDao;
  16 +
  17 + public void add(BloodSugar bloodSugar) {
  18 + bloodSugarDao.add(bloodSugar);
  19 + }
  20 +
  21 + public void update(BloodSugar bloodSugar) {
  22 + bloodSugarDao.updateXy(Query.query(Criteria.where("id").is(bloodSugar.getId())), bloodSugar);
  23 + }
  24 +
  25 +}
platform-common/src/main/java/com/lyms/platform/common/enums/BloodSugarEnums.java View file @ 074f850
  1 +package com.lyms.platform.common.enums;
  2 +
  3 +/**
  4 + * 血糖时间段枚举
  5 + */
  6 +public enum BloodSugarEnums {
  7 +
  8 + A(1, "空腹"), B(2, "早餐前"), C(3, "早餐后2h"), D(4, "午餐前"), E(5, "午餐后2h"), F(6, "晚餐前"), G(7, "晚餐后2h"), H(8, "夜间"), I(9, "睡前");
  9 +
  10 + BloodSugarEnums(Integer id, String name) {
  11 + this.id = id;
  12 + this.name = name;
  13 + }
  14 +
  15 + private Integer id;
  16 + private String name;
  17 +
  18 + public static String getName(Integer id) {
  19 + if(id == null) {
  20 + return null;
  21 + }
  22 + BloodSugarEnums[] values = BloodSugarEnums.values();
  23 + for (BloodSugarEnums value : values) {
  24 + if (value.getId() == id) {
  25 + return value.getName();
  26 + }
  27 + }
  28 + return null;
  29 + }
  30 +
  31 + public Integer getId() {
  32 + return id;
  33 + }
  34 +
  35 + public void setId(Integer id) {
  36 + this.id = id;
  37 + }
  38 +
  39 + public String getName() {
  40 + return name;
  41 + }
  42 +
  43 + public void setName(String name) {
  44 + this.name = name;
  45 + }
  46 +}
platform-common/src/main/java/com/lyms/platform/common/enums/ErrorPatientEnums.java View file @ 074f850
... ... @@ -4,24 +4,6 @@
4 4 * 健康异常孕妇
5 5 */
6 6 public enum ErrorPatientEnums {
7   -
8   - PATIENT_WEIGHT(1),
9   - TEMP(2),
10   - BLOOD_PRESSURE(3),
11   - BLOOD_SUGAR(4);
12   -
13   - ErrorPatientEnums(Integer id) {
14   - this.id = id;
15   - }
16   -
17   - private Integer id;
18   - public Integer getId() {
19   - return id;
20   - }
21   -
22   - public void setId(Integer id) {
23   - this.id = id;
24   - }
25   -
  7 + PATIENT_WEIGHT, TEMP, BLOOD_PRESSURE, BLOOD_SUGAR;
26 8 }
platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java View file @ 074f850
... ... @@ -1407,6 +1407,8 @@
1407 1407 System.out.println(" end>> " + getyyyy_MM_dd(map.get("end")));
1408 1408 }*/
1409 1409  
  1410 + System.out.println(getBetweenDay(7));
  1411 +
1410 1412 Date date = parseDate("2017-11-30");
1411 1413 System.out.println(getYesterday().toLocaleString());
1412 1414 System.out.println("当月第一天: " + getMonthDay(date, 0, 1).toLocaleString());
platform-dal/src/main/java/com/lyms/platform/beans/SerialIdEnum.java View file @ 074f850
... ... @@ -58,6 +58,7 @@
58 58 AntExPRecordModel("AntExPRecordModel", 97531000451L),
59 59 PatientWeight("PatientWeight", 97531000111L),
60 60 BloodPressure("BloodPressure", 97531333111L),
  61 + BloodSugar("BloodSugar", 97111333111L),
61 62 last("last", 97531009990L);
62 63 private String cname;
63 64 private Long cid;
platform-dal/src/main/java/com/lyms/platform/pojo/BloodPressure.java View file @ 074f850
... ... @@ -13,7 +13,7 @@
13 13 @Document(collection="lyms_blood_pressure")
14 14 public class BloodPressure extends BaseModel {
15 15  
16   - private static final long serialVersionUID = SerialIdEnum.PatientWeight.getCid();
  16 + private static final long serialVersionUID = SerialIdEnum.BloodPressure.getCid();
17 17  
18 18 private String id;
19 19  
platform-dal/src/main/java/com/lyms/platform/pojo/BloodSugar.java View file @ 074f850
  1 +package com.lyms.platform.pojo;
  2 +
  3 +import com.lyms.platform.beans.SerialIdEnum;
  4 +import com.lyms.platform.common.result.BaseModel;
  5 +import org.springframework.data.mongodb.core.mapping.Document;
  6 +
  7 +import java.util.Date;
  8 +
  9 +/**
  10 + * 血糖
  11 + */
  12 +@Document(collection="lyms_blood_sugar")
  13 +public class BloodSugar extends BaseModel {
  14 +
  15 + private static final long serialVersionUID = SerialIdEnum.BloodSugar.getCid();
  16 +
  17 + private String id;
  18 +
  19 + private String parentId;
  20 +
  21 + private Date created;
  22 +
  23 + private String creatYmdDate;
  24 +
  25 + private Integer yn;
  26 +
  27 + private Integer createUser;
  28 +
  29 + private String hospitalId;
  30 +
  31 + private Date modified;
  32 +
  33 + /**
  34 + * 血糖
  35 + */
  36 + private String bloodSugar;
  37 +
  38 + private Integer bloodSugarType;
  39 +
  40 + public Date getModified() {
  41 + return modified;
  42 + }
  43 +
  44 + public void setModified(Date modified) {
  45 + this.modified = modified;
  46 + }
  47 +
  48 + public String getCreatYmdDate() {
  49 + return creatYmdDate;
  50 + }
  51 +
  52 + public void setCreatYmdDate(String creatYmdDate) {
  53 + this.creatYmdDate = creatYmdDate;
  54 + }
  55 +
  56 + public static long getSerialVersionUID() {
  57 + return serialVersionUID;
  58 + }
  59 +
  60 + public String getId() {
  61 + return id;
  62 + }
  63 +
  64 + public void setId(String id) {
  65 + this.id = id;
  66 + }
  67 +
  68 + public String getParentId() {
  69 + return parentId;
  70 + }
  71 +
  72 + public void setParentId(String parentId) {
  73 + this.parentId = parentId;
  74 + }
  75 +
  76 + public Date getCreated() {
  77 + return created;
  78 + }
  79 +
  80 + public void setCreated(Date created) {
  81 + this.created = created;
  82 + }
  83 +
  84 + public Integer getYn() {
  85 + return yn;
  86 + }
  87 +
  88 + public void setYn(Integer yn) {
  89 + this.yn = yn;
  90 + }
  91 +
  92 + public Integer getCreateUser() {
  93 + return createUser;
  94 + }
  95 +
  96 + public void setCreateUser(Integer createUser) {
  97 + this.createUser = createUser;
  98 + }
  99 +
  100 + public String getHospitalId() {
  101 + return hospitalId;
  102 + }
  103 +
  104 + public void setHospitalId(String hospitalId) {
  105 + this.hospitalId = hospitalId;
  106 + }
  107 +
  108 + public String getBloodSugar() {
  109 + return bloodSugar;
  110 + }
  111 +
  112 + public void setBloodSugar(String bloodSugar) {
  113 + this.bloodSugar = bloodSugar;
  114 + }
  115 +
  116 + public Integer getBloodSugarType() {
  117 + return bloodSugarType;
  118 + }
  119 +
  120 + public void setBloodSugarType(Integer bloodSugarType) {
  121 + this.bloodSugarType = bloodSugarType;
  122 + }
  123 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BloodPressureController.java View file @ 074f850
... ... @@ -45,6 +45,11 @@
45 45 return bloodPressureService.info(id);
46 46 }
47 47  
  48 + @ResponseBody
  49 + @RequestMapping(value = "/app/{parentId}", method = RequestMethod.GET)
  50 + public BaseResponse getAppInfo(@PathVariable String parentId) {
  51 + return bloodPressureService.getAppInfo(parentId);
  52 + }
48 53  
49 54 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BloodSugarController.java View file @ 074f850
  1 +package com.lyms.platform.operate.web.controller;
  2 +
  3 +import com.lyms.platform.common.annotation.TokenRequired;
  4 +import com.lyms.platform.common.base.BaseController;
  5 +import com.lyms.platform.common.result.BaseResponse;
  6 +import com.lyms.platform.operate.web.service.IBloodSugarService;
  7 +import com.lyms.platform.pojo.BloodSugar;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Controller;
  10 +import org.springframework.web.bind.annotation.PathVariable;
  11 +import org.springframework.web.bind.annotation.RequestMapping;
  12 +import org.springframework.web.bind.annotation.RequestMethod;
  13 +import org.springframework.web.bind.annotation.ResponseBody;
  14 +
  15 +import javax.servlet.http.HttpServletRequest;
  16 +
  17 +/**
  18 + * 血糖
  19 + */
  20 +@Controller
  21 +@RequestMapping("/blood/sugar")
  22 +public class BloodSugarController extends BaseController {
  23 +
  24 + @Autowired
  25 + private IBloodSugarService bloodSugarService;
  26 +
  27 + @ResponseBody
  28 + @RequestMapping(value = "/init", method = RequestMethod.GET)
  29 + public BaseResponse init() {
  30 + return bloodSugarService.init();
  31 + }
  32 +
  33 + @ResponseBody
  34 + @RequestMapping(method = RequestMethod.POST)
  35 + @TokenRequired
  36 + public BaseResponse add(BloodSugar bloodSugar, HttpServletRequest request) {
  37 + return bloodSugarService.add(getUserId(request), bloodSugar);
  38 + }
  39 +
  40 + @ResponseBody
  41 + @RequestMapping(method = RequestMethod.GET)
  42 + @TokenRequired
  43 + public BaseResponse list(String key, String vcCardNo, Integer weekStart, Integer weekEnd, Integer age, Integer page, Integer limit, HttpServletRequest request) {
  44 + return bloodSugarService.list(key, vcCardNo, weekStart, weekEnd, age, page, limit, getUserId(request));
  45 + }
  46 +
  47 + @ResponseBody
  48 + @RequestMapping(value = "/{parentId}/{type}", method = RequestMethod.GET)
  49 + @TokenRequired
  50 + public BaseResponse info(@PathVariable String parentId, @PathVariable Integer type) {
  51 + return bloodSugarService.info(parentId, type);
  52 + }
  53 +
  54 + @ResponseBody
  55 + @RequestMapping(value = "/app/{parentId}", method = RequestMethod.GET)
  56 + public BaseResponse getAppInfo(@PathVariable String parentId) {
  57 + return bloodSugarService.getAppInfo(parentId);
  58 + }
  59 +
  60 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/TestController.java View file @ 074f850
... ... @@ -17,6 +17,7 @@
17 17 import com.lyms.platform.operate.web.facade.BabyCheckFacade;
18 18 import com.lyms.platform.operate.web.facade.SieveFacade;
19 19 import com.lyms.platform.operate.web.result.HighScoreResult;
  20 +import com.lyms.platform.operate.web.service.IBloodPressureService;
20 21 import com.lyms.platform.operate.web.service.SyncDataTaskService;
21 22 import com.lyms.platform.operate.web.worker.BuildSerToPatientSerWorker;
22 23 import com.lyms.platform.permission.model.Organization;
... ... @@ -38,10 +39,7 @@
38 39 import org.springframework.data.mongodb.core.query.Query;
39 40 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
40 41 import org.springframework.stereotype.Controller;
41   -import org.springframework.web.bind.annotation.RequestMapping;
42   -import org.springframework.web.bind.annotation.RequestMethod;
43   -import org.springframework.web.bind.annotation.RequestParam;
44   -import org.springframework.web.bind.annotation.ResponseBody;
  42 +import org.springframework.web.bind.annotation.*;
45 43  
46 44 import java.io.File;
47 45 import java.io.IOException;
... ... @@ -114,6 +112,15 @@
114 112 private ThreadPoolTaskExecutor commonThreadPool;
115 113 @Autowired
116 114 private PatientServiceService patientServiceService;
  115 +
  116 + @Autowired
  117 + private IBloodPressureService bloodPressureService;
  118 +
  119 + @ResponseBody
  120 + @RequestMapping("/init/blood/pressure")
  121 + public BaseResponse initBloodPressure(@RequestParam Map<String, String> param) {
  122 + return bloodPressureService.initBloodPressure(param);
  123 + }
117 124  
118 125  
119 126 @RequestMapping("/area")
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/RemoteFacade.java View file @ 074f850
... ... @@ -10,6 +10,7 @@
10 10 import org.apache.commons.collections.MapUtils;
11 11 import org.apache.commons.lang.StringUtils;
12 12 import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.data.domain.Sort;
13 14 import org.springframework.data.mongodb.core.MongoTemplate;
14 15 import org.springframework.data.mongodb.core.query.Criteria;
15 16 import org.springframework.data.mongodb.core.query.Query;
... ... @@ -30,9 +31,9 @@
30 31 Date yesterday = DateUtil.getYesterday();
31 32 List<Map<String, Object>> restList = new ArrayList<>();
32 33  
33   - List<PatientWeight> patientWeights = mongoTemplate.find(Query.query(Criteria.where("operaterId").is(operaterId)), PatientWeight.class);
34   - List<BloodPressure> bloodPressures = mongoTemplate.find(Query.query(Criteria.where("operaterId").is(operaterId)), BloodPressure.class);
35   - List<TempModel> tempModels = mongoTemplate.find(Query.query(Criteria.where("operaterId").is(operaterId)), TempModel.class);
  34 + List<PatientWeight> patientWeights = mongoTemplate.find(Query.query(Criteria.where("operaterId").is(operaterId)).with(new Sort(Sort.Direction.DESC, "created")), PatientWeight.class);
  35 + List<BloodPressure> bloodPressures = mongoTemplate.find(Query.query(Criteria.where("operaterId").is(operaterId)).with(new Sort(Sort.Direction.DESC, "created")), BloodPressure.class);
  36 + List<TempModel> tempModels = mongoTemplate.find(Query.query(Criteria.where("operaterId").is(operaterId)).with(new Sort(Sort.Direction.DESC, "created")), TempModel.class);
36 37  
37 38 for (PatientWeight patientWeight : patientWeights) {
38 39 Patients patients = mongoTemplate.findById(patientWeight.getPatientId(), Patients.class);
... ... @@ -58,7 +59,7 @@
58 59 temp.put("beforeWeight", patientWeight.getBeforeWeight());
59 60 temp.put("nowWeight", patientWeight.getNowWeight());
60 61 temp.put("addWeight", addWeight);
61   - temp.put("ckz", "(" + lowMap.get(0) + "~" + highMap.get(0) + ")");
  62 + temp.put("ckz", "(" + lowMap.get(0) + "~" + highMap.get(0) + ")");
62 63 temp.put("type", ErrorPatientEnums.PATIENT_WEIGHT);
63 64 }
64 65 }
65 66  
66 67  
67 68  
68 69  
69 70  
... ... @@ -75,27 +76,25 @@
75 76 for (Map.Entry<String, Double> entry : tempList.entrySet()) {
76 77 if(DateUtil.parseYMD(entry.getKey()).getTime() >= yesterday.getTime()) {
77 78 if(entry.getValue() < 36D || entry.getValue() > 38.5D ) {
78   - /* patients = (patients == null ? mongoTemplate.findById(p, Patients.class) : patients);
  79 + patients = (patients == null ? mongoTemplate.findById(tempModel.getParentId(), Patients.class) : patients);
79 80 temp.put("username", patients.getUsername());
80 81 temp.put("week", DateUtil.getWeekDesc(patients.getLastMenses(), new Date()));
81   - temp.put("parentId", patientWeight.getPatientId());
82   - temp.put("id", patientWeight.getId());
  82 + temp.put("parentId", tempModel.getParentId());
  83 + temp.put("id", tempModel.getId());
83 84 temp.put("day", entry.getKey());
84   - temp.put("desc", addWeight < low ? "增重过少" : "增重过多");
85   - temp.put("beforeWeight", patientWeight.getBeforeWeight());
86   - temp.put("nowWeight", patientWeight.getNowWeight());
87   - temp.put("addWeight", addWeight);
88   - temp.put("ckz", "(" + lowMap.get(0) + "~" + highMap.get(0) + ")");
89   - temp.put("type", ErrorPatientEnums.PATIENT_WEIGHT);*/
  85 + temp.put("desc", entry.getValue() < 36D ? "低热" : "高热");
  86 + temp.put("temp", entry.getValue());
  87 + temp.put("ckz", "(36-37.4)");
  88 + temp.put("type", ErrorPatientEnums.TEMP);
90 89 }
91 90 }
92 91 }
93   -
  92 + if(MapUtils.isNotEmpty(temp)) {
  93 + restList.add(temp);
  94 + }
94 95 }
95   -
96 96 return restList;
97 97 }
98   -
99 98  
100 99 /**
101 100 * 获取两个体重之间相差的数值
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IBloodPressureService.java View file @ 074f850
... ... @@ -3,6 +3,8 @@
3 3 import com.lyms.platform.common.result.BaseResponse;
4 4 import com.lyms.platform.pojo.BloodPressure;
5 5  
  6 +import java.util.Map;
  7 +
6 8 public interface IBloodPressureService extends IBaseService {
7 9  
8 10 BaseResponse addOrUpdate(Integer userId, BloodPressure bloodPressure);
... ... @@ -10,5 +12,9 @@
10 12 BaseResponse list(String key, String vcCardNo, Integer weekStart, Integer weekEnd, Integer age, Integer page, Integer limit, Integer userId);
11 13  
12 14 BaseResponse info(String id);
  15 +
  16 + BaseResponse getAppInfo(String parentId);
  17 +
  18 + BaseResponse initBloodPressure(Map<String, String> param);
13 19 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IBloodSugarService.java View file @ 074f850
  1 +package com.lyms.platform.operate.web.service;
  2 +
  3 +import com.lyms.platform.common.result.BaseResponse;
  4 +import com.lyms.platform.pojo.BloodSugar;
  5 +
  6 +import java.util.Map;
  7 +
  8 +public interface IBloodSugarService extends IBaseService {
  9 +
  10 + BaseResponse add(Integer userId, BloodSugar bloodSugar);
  11 +
  12 + BaseResponse list(String key, String vcCardNo, Integer weekStart, Integer weekEnd, Integer age, Integer page, Integer limit, Integer userId);
  13 +
  14 + BaseResponse info(String parentId, Integer type);
  15 +
  16 + BaseResponse getAppInfo(String parentId);
  17 +
  18 + BaseResponse initBloodSugar(Map<String, String> param);
  19 +
  20 + BaseResponse init();
  21 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodPressureServiceImpl.java View file @ 074f850
1 1 package com.lyms.platform.operate.web.service.impl;
2 2  
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
3 5 import com.lyms.platform.biz.service.BloodPressureService;
4 6 import com.lyms.platform.biz.service.CommonService;
5 7 import com.lyms.platform.common.enums.YnEnums;
... ... @@ -52,6 +54,7 @@
52 54 temp.put("szy", bloodPressure.getSzy());
53 55 temp.put("ssy", bloodPressure.getSsy());
54 56 temp.put("pulse", bloodPressure.getPulse());
  57 + temp.put("timestamp", DateUtil.getyyyy_MM_dd_hms(new Date()));
55 58 temp.put("hospitalId", hospitalId);
56 59 BloodPressure bp = mongoTemplate.findOne(Query.query(Criteria.where("parentId").is(bloodPressure.getParentId()).and("yn").ne(0)), BloodPressure.class);
57 60 bloodPressure.setModified(new Date());
... ... @@ -163,6 +166,37 @@
163 166 return RespBuilder.buildSuccess("xyInfos", xyInfos, "szyMin", szyMin, "ssyMax", ssyMax, "ssy", ssy, "szy", szy, "pulse", pulse);
164 167 }
165 168  
  169 + @Override
  170 + public BaseResponse getAppInfo(String parentId) {
  171 + BloodPressure bloodPressure = mongoTemplate.findOne(Query.query(Criteria.where("parentId").is(parentId)), BloodPressure.class);
  172 + List<Map<String, Object>> restList = new ArrayList<>();
  173 + if(bloodPressure != null) {
  174 + Map<String, Map<String, Object>> infos = bloodPressure.getInfos();
  175 + Object[] keys = infos.keySet().toArray();
  176 + CollectionUtils.reverseArray(keys);
  177 + for (Object key : keys) {
  178 + Map<String, Object> temp = new HashMap<>();
  179 + Map<String, Object> info = infos.get(key);
  180 + temp.put("createTime", info.get("timestamp"));
  181 + temp.put("diastole", info.get("szy"));
  182 + temp.put("pulse", info.get("pulse"));
  183 + temp.put("shrink", info.get("ssy"));
  184 + restList.add(temp);
  185 + }
  186 + }
  187 + return RespBuilder.buildSuccess(restList);
  188 + }
  189 +
  190 + @Override
  191 + public BaseResponse initBloodPressure(Map<String, String> bloods) {
  192 + JSONArray array = JSONArray.parseArray(bloods.get("datas"));
  193 + for (Object obj : array) {
  194 + JSONObject jsonObject = (JSONObject) obj;
  195 + System.out.println(jsonObject);
  196 + }
  197 + return RespBuilder.buildSuccess();
  198 + }
  199 +
166 200 private String getPulseStatus(String ssy, String szy) {
167 201 String status = "";
168 202 if(StringUtils.isNotEmpty(ssy) && StringUtils.isNotEmpty(szy)) {
... ... @@ -176,6 +210,7 @@
176 210 }
177 211 return status;
178 212 }
  213 +
179 214  
180 215 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java View file @ 074f850
  1 +package com.lyms.platform.operate.web.service.impl;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.lyms.platform.biz.service.BloodSugarService;
  6 +import com.lyms.platform.common.enums.BloodSugarEnums;
  7 +import com.lyms.platform.common.enums.YnEnums;
  8 +import com.lyms.platform.common.result.BaseResponse;
  9 +import com.lyms.platform.common.result.PageResult;
  10 +import com.lyms.platform.common.result.RespBuilder;
  11 +import com.lyms.platform.common.utils.DateUtil;
  12 +import com.lyms.platform.common.utils.EnumUtil;
  13 +import com.lyms.platform.operate.web.facade.AccessPermissionFacade;
  14 +import com.lyms.platform.operate.web.facade.AutoMatchFacade;
  15 +import com.lyms.platform.operate.web.service.IBloodSugarService;
  16 +import com.lyms.platform.operate.web.utils.CollectionUtils;
  17 +import com.lyms.platform.operate.web.utils.MongoUtil;
  18 +import com.lyms.platform.pojo.BloodSugar;
  19 +import com.lyms.platform.pojo.Patients;
  20 +import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.data.domain.Sort;
  22 +import org.springframework.data.mongodb.core.MongoTemplate;
  23 +import org.springframework.data.mongodb.core.query.Criteria;
  24 +import org.springframework.data.mongodb.core.query.Query;
  25 +import org.springframework.stereotype.Service;
  26 +
  27 +import java.util.*;
  28 +
  29 +@Service
  30 +public class BloodSugarServiceImpl extends BaseServiceImpl implements IBloodSugarService {
  31 +
  32 + @Autowired
  33 + private BloodSugarService bloodSugarService;
  34 +
  35 + @Autowired
  36 + private MongoTemplate mongoTemplate;
  37 +
  38 + @Autowired
  39 + private AutoMatchFacade autoMatchFacade;
  40 +
  41 + @Autowired
  42 + private MongoUtil mongoUtil;
  43 +
  44 + @Autowired
  45 + private AccessPermissionFacade accessPermissionFacade;
  46 +
  47 +
  48 + public BaseResponse add(Integer userId, BloodSugar bloodSugar) {
  49 + BloodSugar one = mongoTemplate.findOne(Query.query(Criteria.where("parentId").is(bloodSugar.getParentId()).and("created").gt(DateUtil.getYMDTime()).and("bloodSugarType").is(bloodSugar.getBloodSugarType())), BloodSugar.class);
  50 + if(one != null) {
  51 + one.setModified(new Date());
  52 + one.setBloodSugar(bloodSugar.getBloodSugar());
  53 + bloodSugarService.update(one);
  54 + return RespBuilder.buildSuccess(one.getId());
  55 + }
  56 + bloodSugar.setHospitalId(autoMatchFacade.getHospitalId(userId));
  57 + bloodSugar.setCreated(new Date());
  58 + bloodSugar.setCreateUser(userId);
  59 + bloodSugar.setYn(YnEnums.YES.getId());
  60 + bloodSugar.setModified(new Date());
  61 + bloodSugar.setCreatYmdDate(DateUtil.getyyyy_MM_dd(new Date()));
  62 + bloodSugarService.add(bloodSugar);
  63 + return RespBuilder.buildSuccess(bloodSugar.getId());
  64 + }
  65 +
  66 + @Override
  67 + public BaseResponse list(String key, String vcCardNo, Integer weekStart, Integer weekEnd, Integer age, Integer page, Integer limit, Integer userId) {
  68 + List<String> hospitalIds = accessPermissionFacade.getCurrentUserHospPermissions(userId);
  69 + Criteria criteria = Criteria.where("yn").is(1).and("hospitalId").in(hospitalIds);
  70 + List<String> patientIds = mongoUtil.getPatientIdsByCondition(hospitalIds, key, vcCardNo, weekStart, weekEnd, age);
  71 + criteria.and("parentId").in(patientIds);
  72 + PageResult pageResult = findMongoPage(BloodSugar.class, Query.query(criteria).with(new Sort(Sort.Direction.DESC, "created")), page, limit);
  73 + List<BloodSugar> bloodSugars = (List<BloodSugar>) pageResult.getGrid();
  74 + List<Map<String, Object>> restList = new ArrayList<>();
  75 + for (BloodSugar bloodSugar : bloodSugars) {
  76 + Map<String, Object> temp = new HashMap<>();
  77 + Patients p = mongoTemplate.findById(bloodSugar.getParentId(), Patients.class);
  78 + temp.put("id", bloodSugar.getParentId());
  79 + if(p != null) {
  80 + temp.put("username", p.getUsername());
  81 + temp.put("age", DateUtil.getAge(p.getBirth()));
  82 + temp.put("week", DateUtil.getWeekDesc(p.getLastMenses(), new Date()));
  83 + temp.put("riskLevel", mongoUtil.getRiskLevels(p)); //高危等级(颜色)
  84 + temp.put("riskFactor", mongoUtil.getRiskFactor(p)); // 高危因素
  85 + temp.put("dueDate", DateUtil.getyyyy_MM_dd(p.getDueDate()));
  86 + temp.put("bloodSugar", bloodSugar.getBloodSugar() + "mmol/L");
  87 + temp.put("bloodSugarType", BloodSugarEnums.getName(bloodSugar.getBloodSugarType()));
  88 + temp.put("bloodSugarId", bloodSugar.getBloodSugarType());
  89 + temp.put("status", getBloodSugarStatus(bloodSugar.getBloodSugarType(), bloodSugar.getBloodSugar()));
  90 + temp.put("vcCardNo", p.getVcCardNo());
  91 + temp.put("pcerteTypeId", p.getPcerteTypeId());
  92 + temp.put("cardNo", p.getCardNo());
  93 + }
  94 + restList.add(temp);
  95 + }
  96 + pageResult.setGrid(restList);
  97 + return RespBuilder.buildSuccess(pageResult);
  98 + }
  99 +
  100 + private String getBloodSugarStatus(Integer type, String bloodSugar) {
  101 + if(type == BloodSugarEnums.A.getId()) {
  102 + return Double.parseDouble(bloodSugar) > 5.6D ? "高血糖" : Double.parseDouble(bloodSugar) < 3.3D ? "低血糖" : "正常";
  103 + } else if(type == BloodSugarEnums.B.getId() || type == BloodSugarEnums.D.getId() || type == BloodSugarEnums.F.getId() ) {
  104 + return Double.parseDouble(bloodSugar) > 5.8D ? "高血糖" : Double.parseDouble(bloodSugar) < 3.3D ? "低血糖" : "正常";
  105 + } else if(type == BloodSugarEnums.I.getId()) {
  106 + return Double.parseDouble(bloodSugar) > 7.8D ? "高血糖" : Double.parseDouble(bloodSugar) < 6.1D ? "低血糖" : "正常";
  107 + } else {
  108 + return Double.parseDouble(bloodSugar) > 6.7D ? "高血糖" : Double.parseDouble(bloodSugar) < 4.4D ? "低血糖" : "正常";
  109 + }
  110 + }
  111 +
  112 + @Override
  113 + public BaseResponse info(String parentId, Integer type) {
  114 + List<Map<Object, Object>> tabList = new ArrayList<>();
  115 + List<String> betweenDay = DateUtil.getBetweenDay(7);
  116 + Object[] xAxis = betweenDay.toArray();
  117 + CollectionUtils.reverseArray(xAxis);
  118 + List<Double> minAxis;
  119 + List<Double> maxAxis;
  120 + List<String> bloodSugarAxis = new LinkedList<>();
  121 + if(type == BloodSugarEnums.A.getId()) {
  122 + minAxis = Arrays.asList(3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3);
  123 + maxAxis = Arrays.asList(5.6, 5.6, 5.6, 5.6, 5.6, 5.6, 5.6);
  124 + } else if(type == BloodSugarEnums.B.getId() || type == BloodSugarEnums.D.getId() || type == BloodSugarEnums.F.getId() ) {
  125 + minAxis = Arrays.asList(3.3, 3.3, 3.3, 3.3, 3.3, 3.3, 3.3);
  126 + maxAxis = Arrays.asList(5.8, 5.8, 5.8, 5.8, 5.8, 5.8, 5.8);
  127 + } else if(type == BloodSugarEnums.I.getId()) {
  128 + minAxis = Arrays.asList(6.1, 6.1, 6.1, 6.1, 6.1, 6.1, 6.1);
  129 + maxAxis = Arrays.asList(7.8, 7.8, 7.8, 7.8, 7.8, 7.8, 7.8);
  130 + } else {
  131 + minAxis = Arrays.asList(4.4, 4.4, 4.4, 4.4, 4.4, 4.4, 4.4);
  132 + maxAxis = Arrays.asList(6.7, 6.7, 6.7, 6.7, 6.7, 6.7, 6.7);
  133 + }
  134 +
  135 + List<BloodSugar> bloodSugars = mongoTemplate.find(Query.query(Criteria.where("parentId").is(parentId)), BloodSugar.class);
  136 + if(CollectionUtils.isNotEmpty(bloodSugars)) {
  137 + for (int i = 0; i < betweenDay.size(); i++) {
  138 + String day = betweenDay.get(i);
  139 + Map<Object, Object> temp = new HashMap<>();
  140 + for (BloodSugar bloodSugar : bloodSugars) {
  141 + if(day.equals(bloodSugar.getCreatYmdDate())) {
  142 + for (BloodSugarEnums sugarEnums : BloodSugarEnums.values()) {
  143 + if(sugarEnums.getId() == (bloodSugar.getBloodSugarType())) {
  144 + temp.put(sugarEnums.getId(), bloodSugar.getBloodSugar());
  145 + bloodSugarAxis.add(0, bloodSugar.getBloodSugar());
  146 + }
  147 + }
  148 + }
  149 + }
  150 + for (BloodSugarEnums sugarEnums : BloodSugarEnums.values()) {
  151 + if(!temp.containsKey(sugarEnums.getId())) {
  152 + temp.put(sugarEnums.getId(), "--");
  153 + }
  154 + }
  155 + if(bloodSugarAxis.size() < i + 1) {
  156 + bloodSugarAxis.add(0, "0");
  157 + }
  158 + temp.put("date", day);
  159 + tabList.add(temp);
  160 + }
  161 + }
  162 + return RespBuilder.buildSuccess("tabList", tabList, "xAxis", xAxis, "minAxis", minAxis, "maxAxis", maxAxis, "bloodSugarAxis", bloodSugarAxis);
  163 + }
  164 +
  165 + @Override
  166 + public BaseResponse getAppInfo(String parentId) {
  167 + BloodSugar bloodSugar = mongoTemplate.findOne(Query.query(Criteria.where("parentId").is(parentId)), BloodSugar.class);
  168 + List<Map<String, Object>> restList = new ArrayList<>();
  169 + /* if(bloodSugar != null) {
  170 + Map<String, Map<String, Object>> infos = bloodSugar.getInfos();
  171 + Object[] keys = infos.keySet().toArray();
  172 + CollectionUtils.reverseArray(keys);
  173 + for (Object key : keys) {
  174 + Map<String, Object> temp = new HashMap<>();
  175 + Map<String, Object> info = infos.get(key);
  176 + temp.put("createTime", info.get("timestamp"));
  177 + temp.put("diastole", info.get("szy"));
  178 + temp.put("pulse", info.get("pulse"));
  179 + temp.put("shrink", info.get("ssy"));
  180 + restList.add(temp);
  181 + }
  182 + }*/
  183 + return RespBuilder.buildSuccess(restList);
  184 + }
  185 +
  186 + @Override
  187 + public BaseResponse initBloodSugar(Map<String, String> bloods) {
  188 + JSONArray array = JSONArray.parseArray(bloods.get("datas"));
  189 + for (Object obj : array) {
  190 + JSONObject jsonObject = (JSONObject) obj;
  191 + System.out.println(jsonObject);
  192 + }
  193 + return RespBuilder.buildSuccess();
  194 + }
  195 +
  196 + @Override
  197 + public BaseResponse init() {
  198 + return RespBuilder.buildSuccess(EnumUtil.toJson(BloodSugarEnums.class));
  199 + }
  200 +
  201 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/MongoUtil.java View file @ 074f850
... ... @@ -592,6 +592,46 @@
592 592 return sb.length() > 0 ? sb.substring(0, sb.length() - 1).toString() : sb.toString();
593 593 }
594 594  
  595 + /**
  596 + * @param key 姓名/证件号/联系方式
  597 + * @param vcCardNo 就诊卡
  598 + * @param weekStart 当前开始孕周
  599 + * @param weekEnd 当前结束孕周
  600 + * @param age 年龄
  601 + * @return
  602 + */
  603 + public List<Patients> getPatientByCondition(List<String> hospitalIds, String key, String vcCardNo, Integer weekStart, Integer weekEnd, Integer age) {
  604 + Criteria pCriteria = Criteria.where("yn").is(1).and("hospitalId").in(hospitalIds);
  605 + if(StringUtils.isNotEmpty(key)) {
  606 + pCriteria.orOperator(Criteria.where("phone").regex(key), Criteria.where("username").regex(key), Criteria.where("cardNo").is(key));
  607 + }
  608 + if(StringUtils.isNotEmpty(vcCardNo)) {
  609 + pCriteria.and("vcCardNo").is(vcCardNo);
  610 + }
  611 + if(weekStart != null && weekEnd != null) {
  612 + Date start = DateUtil.getWeekStart(weekEnd);
  613 + Date end = DateUtil.getWeekEnd(weekStart);
  614 + pCriteria.and("lastMenses").gt(start).lte(end);
  615 + }
  616 + if(age != null) {
  617 + Date start = DateUtil.getBeforeAge(age);
  618 + Date end = DateUtil.getBeforeAge(age + 1);
  619 + pCriteria.and("birth").gt(end).lte(start);
  620 + }
  621 + List<Patients> patients = mongoTemplate.find(Query.query(pCriteria), Patients.class);
595 622  
  623 + return patients;
  624 + }
  625 +
  626 + public List<String> getPatientIdsByCondition(List<String> hospitalIds, String key, String vcCardNo, Integer weekStart, Integer weekEnd, Integer age) {
  627 + List<Patients> patients = getPatientByCondition(hospitalIds, key, vcCardNo, weekStart, weekEnd, age);
  628 + List<String> ids = new ArrayList<>();
  629 + if(CollectionUtils.isNotEmpty(patients)) {
  630 + for (Patients patient : patients) {
  631 + ids.add(patient.getId());
  632 + }
  633 + }
  634 + return ids;
  635 + }
596 636 }