From 9ea10ca75a28660168d662bc18f669e36ab756ce Mon Sep 17 00:00:00 2001 From: liquanyu Date: Thu, 17 Jan 2019 16:29:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=80=E7=B3=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lyms/platform/pojo/BloodSugar.java | 22 +++ .../com/lyms/platform/query/BloodSugarQuery.java | 61 +++++++ .../web/controller/BloodSugarController.java | 13 +- .../operate/web/service/IBloodSugarService.java | 2 + .../web/service/impl/BloodSugarServiceImpl.java | 192 ++++++++++++++++++++- 5 files changed, 283 insertions(+), 7 deletions(-) diff --git a/platform-dal/src/main/java/com/lyms/platform/pojo/BloodSugar.java b/platform-dal/src/main/java/com/lyms/platform/pojo/BloodSugar.java index 5027548..70e8d3c 100644 --- a/platform-dal/src/main/java/com/lyms/platform/pojo/BloodSugar.java +++ b/platform-dal/src/main/java/com/lyms/platform/pojo/BloodSugar.java @@ -65,6 +65,28 @@ public class BloodSugar extends BaseModel { //当前孕周 private Integer currentWeek; + //0 未推送 1已经推送 + private Integer exceptionSend; + + //0 未推送 1已经推送 + private Integer sevenSend; + + public Integer getExceptionSend() { + return exceptionSend; + } + + public void setExceptionSend(Integer exceptionSend) { + this.exceptionSend = exceptionSend; + } + + public Integer getSevenSend() { + return sevenSend; + } + + public void setSevenSend(Integer sevenSend) { + this.sevenSend = sevenSend; + } + public Integer getCurrentWeek() { return currentWeek; } diff --git a/platform-dal/src/main/java/com/lyms/platform/query/BloodSugarQuery.java b/platform-dal/src/main/java/com/lyms/platform/query/BloodSugarQuery.java index 521e943..b6cafd2 100644 --- a/platform-dal/src/main/java/com/lyms/platform/query/BloodSugarQuery.java +++ b/platform-dal/src/main/java/com/lyms/platform/query/BloodSugarQuery.java @@ -19,10 +19,16 @@ public class BloodSugarQuery extends BaseQuery implements IConvertToNativeQuery private String id; private String parentId; + private List parentIds; private String pid; private Boolean isExistReportDate; private Date createdStart; private Date createdEnd; + //0 未推送 1已经推送 + private Integer exceptionSend; + + //0 未推送 1已经推送 + private Integer sevenSend; @Override public MongoQuery convertToQuery() { @@ -35,6 +41,38 @@ public class BloodSugarQuery extends BaseQuery implements IConvertToNativeQuery if(StringUtils.isNotEmpty(parentId)){ condition = condition.and("parentId", parentId, MongoOper.IS); } + + if(CollectionUtils.isNotEmpty(parentIds)){ + condition = condition.and("parentId", parentIds, MongoOper.IN); + } + + if(exceptionSend != null){ + if (exceptionSend == 0) + { + MongoCondition con1 = MongoCondition.newInstance("exceptionSend", exceptionSend, MongoOper.IS); + MongoCondition con = MongoCondition.newInstance("exceptionSend", false, MongoOper.EXISTS); + condition = condition.orCondition(new MongoCondition[]{con1, con}); + } + else + { + condition = condition.and("exceptionSend", exceptionSend, MongoOper.IS); + } + + } + + if(sevenSend != null){ + if (sevenSend == 0) + { + MongoCondition con1 = MongoCondition.newInstance("sevenSend", sevenSend, MongoOper.IS); + MongoCondition con = MongoCondition.newInstance("sevenSend", false, MongoOper.EXISTS); + condition = condition.orCondition(new MongoCondition[]{con1, con}); + } + else + { + condition = condition.and("sevenSend", sevenSend, MongoOper.IS); + } + } + if(StringUtils.isNotEmpty(pid)){ condition = condition.and("pid", pid, MongoOper.IS); } @@ -67,6 +105,29 @@ public class BloodSugarQuery extends BaseQuery implements IConvertToNativeQuery return condition.toMongoQuery(); } + public Integer getExceptionSend() { + return exceptionSend; + } + + public void setExceptionSend(Integer exceptionSend) { + this.exceptionSend = exceptionSend; + } + + public Integer getSevenSend() { + return sevenSend; + } + + public void setSevenSend(Integer sevenSend) { + this.sevenSend = sevenSend; + } + + public List getParentIds() { + return parentIds; + } + + public void setParentIds(List parentIds) { + this.parentIds = parentIds; + } public String getId() { return id; diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BloodSugarController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BloodSugarController.java index b74ac99..29ea206 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BloodSugarController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BloodSugarController.java @@ -8,10 +8,7 @@ import com.lyms.platform.operate.web.service.IBloodSugarService; import com.lyms.platform.pojo.BloodSugar; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Date; @@ -124,7 +121,13 @@ public class BloodSugarController extends BaseController { public BaseResponse getSysBloodSugarReport(@PathVariable String patientId ,HttpServletRequest httpServletRequest) { LoginContext loginState = (LoginContext) httpServletRequest.getAttribute("loginContext"); - return bloodSugarService.getSysBloodSugarReport(patientId,loginState.getId()); + return bloodSugarService.getSysBloodSugarReport(patientId, loginState.getId()); + } + + @ResponseBody + @RequestMapping(value = "/getBloodSugars/{doctorId}/{type}/{status}", method = RequestMethod.GET) + public BaseResponse getBloodSugars(@PathVariable String doctorId,@PathVariable Integer type,@PathVariable Integer status,@RequestParam(required = false) String keyword) { + return bloodSugarService.getBloodSugars(doctorId, type, status, keyword); } } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IBloodSugarService.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IBloodSugarService.java index 24aaaa9..3565dd1 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IBloodSugarService.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/IBloodSugarService.java @@ -31,4 +31,6 @@ public interface IBloodSugarService extends IBaseService { BaseResponse addWeightInfo(String id, String beforeWeight, String currentWeight); BaseResponse getSysBloodSugarReport(String patientId,Integer userId); + + BaseResponse getBloodSugars(String doctorId, Integer type, Integer status, String keyword); } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java index f268eb1..523c614 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/impl/BloodSugarServiceImpl.java @@ -3,8 +3,10 @@ package com.lyms.platform.operate.web.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.lyms.platform.biz.service.*; +import com.lyms.platform.common.constants.ErrorCodeConstants; import com.lyms.platform.common.enums.BloodSugarEnums; import com.lyms.platform.common.enums.BloodSugarEnums2; +import com.lyms.platform.common.enums.PatientSerEnums; import com.lyms.platform.common.enums.YnEnums; import com.lyms.platform.common.result.*; import com.lyms.platform.common.utils.DateUtil; @@ -21,11 +23,15 @@ import com.lyms.platform.operate.web.utils.MathUtil; import com.lyms.platform.operate.web.utils.MongoUtil; import com.lyms.platform.operate.web.utils.ReportConfig; import com.lyms.platform.permission.model.Organization; +import com.lyms.platform.permission.model.PatientService; +import com.lyms.platform.permission.model.PatientServiceQuery; import com.lyms.platform.permission.service.OrganizationService; +import com.lyms.platform.permission.service.PatientServiceService; import com.lyms.platform.pojo.*; import com.lyms.platform.query.AntExChuQuery; import com.lyms.platform.query.AntExRecordQuery; import com.lyms.platform.query.BloodSugarQuery; +import com.lyms.platform.query.PatientsQuery; import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.map.HashedMap; import org.springframework.beans.factory.annotation.Autowired; @@ -74,6 +80,9 @@ public class BloodSugarServiceImpl extends BaseServiceImpl implements IBloodSuga private AntenatalExaminationService antenatalExaminationService; @Autowired + private PatientServiceService patientServiceService; + + @Autowired private ComputeKulServiceManager computeKulServiceManager; @Autowired @@ -374,7 +383,7 @@ public class BloodSugarServiceImpl extends BaseServiceImpl implements IBloodSuga } } if(flag) { - weekMap.put("value", "--"); + weekMap.put("value", ""); } weekAvgMap.add(weekMap); } @@ -413,7 +422,7 @@ public class BloodSugarServiceImpl extends BaseServiceImpl implements IBloodSuga } } if(flag) { - monthMap.put("value", "--"); + monthMap.put("value", ""); } monthAvgMap.add(monthMap); } @@ -1194,4 +1203,183 @@ public class BloodSugarServiceImpl extends BaseServiceImpl implements IBloodSuga map.put("name", value); } + + @Override + public BaseResponse getBloodSugars(String doctorId, Integer type, Integer status, String keyword) { + List datas = new ArrayList<>(); + List pids = new ArrayList<>(); + if (org.apache.commons.lang.StringUtils.isNotEmpty(keyword)) + { + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setYn(YnEnums.YES.getId()); + patientsQuery.setQueryNo(keyword); + patientsQuery.setType(1); + List pats = patientsService.queryPatient(patientsQuery); + if (CollectionUtils.isNotEmpty(pats)) + { + for (Patients pat : pats) + { + pids.add(pat.getId()); + } + } + else + { + return new BaseObjectResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(datas); + } + } + + + PatientServiceQuery patientQuery = new PatientServiceQuery(); + patientQuery.setSerDoct(doctorId); + patientQuery.setSerType(PatientSerEnums.SerTypeEnums.xt.getId()); + patientQuery.setSerStatus(1); + if (CollectionUtils.isNotEmpty(pids)) + { + patientQuery.setParentIds((String[]) pids.toArray(new String[pids.size()])); + } + List list = patientServiceService.queryPatientService(patientQuery); + List patientIds = new ArrayList<>(); + + if (CollectionUtils.isNotEmpty(list)) + { + for (PatientService ps : list) + { + Patients pat = patientsService.findOnePatientById(ps.getParentid()); + if (pat != null && pat.getType() == 1) + { + patientIds.add(ps.getParentid()); + } + } + } + + BloodSugarQuery bloodSugarQuery = new BloodSugarQuery(); + bloodSugarQuery.setParentIds(patientIds); + //七天没有记录的 + if (type == 1) + { + bloodSugarQuery.setCreatedEnd(DateUtil.addDay(new Date(),-7)); + if (status != null && status == 1) + { + bloodSugarQuery.setSevenSend(status); + } + else if (status != null && status == 0) + { + bloodSugarQuery.setSevenSend(status); + } + } + //大于等于连续3次异常的 + else if (type == 2) + { + if (status != null && status == 1) + { + bloodSugarQuery.setExceptionSend(status); + } + else if (status != null && status == 0) + { + bloodSugarQuery.setExceptionSend(status); + } + } + + List bloodSugars = bloodSugarService.queryBloodSugarList(bloodSugarQuery,Sort.Direction.DESC, "created"); + + Map> listMap = new HashMap<>(); + + if (CollectionUtils.isNotEmpty(bloodSugars)) + { + for (BloodSugar bloodSugar : bloodSugars) + { + List bss = listMap.get(bloodSugar.getParentId()); + if (CollectionUtils.isEmpty(bss)) + { + bss = new ArrayList<>(); + } + bss.add(bloodSugar); + listMap.put(bloodSugar.getParentId(),bss); + } + } + if (listMap.size() > 0) + { + for (String key : listMap.keySet()) + { + List sugarList = listMap.get(key); + if (CollectionUtils.isNotEmpty(sugarList)) + { + Map map = new HashMap(); + BloodSugar bloodSugar1 = sugarList.get(0); + if (type == 2) + { + + boolean isContinue = false; + Map> maps = new HashMap<>(); + if (CollectionUtils.isNotEmpty(sugarList)) + { + for (BloodSugar bloodSugar : sugarList) + { + List bss = maps.get(bloodSugar.getCreatYmdDate()); + if (CollectionUtils.isEmpty(bss)) + { + bss = new ArrayList<>(); + } + bss.add(bloodSugar); + maps.put(bloodSugar.getCreatYmdDate(),bss); + } + } + maps = sortMapByKey(maps); + if (maps.size() > 0) { + int count = 0; + for (String key1 : maps.keySet()) { + List bss = maps.get(key1); + if (CollectionUtils.isNotEmpty(bss)) + { + for (BloodSugar bs : bss) + { + int result = getBloodSugarStatus(bs.getBloodSugarType(),Float.parseFloat(bs.getBloodSugar())); + if (result != 0) + { + count++; + break; + } + } + } + if (count >= 3) + { + isContinue = true; + break; + } + } + } + + if (!isContinue) + { + continue; + } + } + else if (type == 1) + { + BloodSugarQuery bloodSugarQuery1 = new BloodSugarQuery(); + bloodSugarQuery1.setParentId(bloodSugar1.getParentId()); + bloodSugarQuery1.setCreatedStart(DateUtil.addDay(new Date(), -7)); + List list1 = bloodSugarService.queryBloodSugarList(bloodSugarQuery1,Sort.Direction.DESC, "created"); + if (CollectionUtils.isNotEmpty(list1)) + { + continue; + } + } + + Patients patients = patientsService.findOnePatientById(bloodSugar1.getParentId()); + + map.put("patientId",patients != null ? patients.getId() : ""); + map.put("name",patients != null ? patients.getUsername() : ""); + map.put("age",patients != null ? DateUtil.getAge(patients.getBirth(), bloodSugar1.getCreated()): ""); + map.put("week",patients != null ? DateUtil.getWeekDesc(patients.getLastMenses(), bloodSugar1.getCreated()): ""); + map.put("bloodSugar",bloodSugar1.getBloodSugar()); + map.put("days",DateUtil.getDays(bloodSugar1.getCreated(), new Date())); + map.put("phone",patients.getPhone()); + datas.add(map); + } + } + } + return new BaseObjectResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(datas); + } + } -- 1.8.3.1