diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PatientWeightController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PatientWeightController.java index e9acc9f..06219f1 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PatientWeightController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/PatientWeightController.java @@ -3,17 +3,13 @@ package com.lyms.platform.operate.web.controller; import com.lyms.platform.common.annotation.TokenRequired; import com.lyms.platform.common.base.BaseController; import com.lyms.platform.common.result.BaseResponse; -import com.lyms.platform.operate.web.service.BabyEyeCheckService; import com.lyms.platform.operate.web.service.PatientWeightService; -import com.lyms.platform.pojo.BabyEyeCheck; import com.lyms.platform.pojo.PatientWeight; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Date; /** * 孕产妇体重管理 @@ -94,4 +90,23 @@ public class PatientWeightController extends BaseController { return patientWeightService.report(id); } + /** + * 体重报告(小程序使用) + */ + @ResponseBody + @RequestMapping(value = "/report/wx/{patientId}/{hospitalId}", method = RequestMethod.GET) + public BaseResponse wxReport(@PathVariable String patientId, @PathVariable String hospitalId) { + return patientWeightService.wxReport(patientId, hospitalId); + } + + /** + * 保存修改体重报告(小程序使用) + * @return + */ + @ResponseBody + @RequestMapping(value = "/wx", method = RequestMethod.POST) + public BaseResponse wxAddOrUpdate(PatientWeight patientWeight) { + return patientWeightService.wxAddOrUpdate(patientWeight); + } + } diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/PatientWeightService.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/PatientWeightService.java index 9e3a46b..830a310 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/PatientWeightService.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/service/PatientWeightService.java @@ -20,4 +20,8 @@ public interface PatientWeightService extends IBaseService { BaseResponse delete(String id); BaseResponse report(String id); + + BaseResponse wxReport(String patientId, String hospitalId); + + BaseResponse wxAddOrUpdate(PatientWeight patientWeight); } 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 911f5c7..dbb1800 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,7 +8,6 @@ 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; @@ -264,6 +263,55 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient return RespBuilder.buildSuccess(); } + @Override + public BaseResponse wxReport(String patientId, String hospitalId) { + PatientWeight patientWeight = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientId).and("hospitalId").is(hospitalId)), PatientWeight.class); + if(patientWeight != null) { + Map map = new HashMap<>(); + setReport(map, patientWeight.getWeights(), patientWeight.getBeforeWeight(), patientWeight.getBmi()); + return RespBuilder.buildSuccess(map); + } + return RespBuilder.buildSuccess(); + } + + @Override + public BaseResponse wxAddOrUpdate(PatientWeight patientWeight) { + String nowWeight = patientWeight.getNowWeight(); + Patients patients = mongoTemplate.findById(patientWeight.getPatientId(), Patients.class); + PatientWeight pw = mongoTemplate.findOne(Query.query(Criteria.where("patientId").is(patientWeight.getPatientId())), PatientWeight.class); + Map weights = new HashMap<>(); + if(pw != null) { + if(MapUtils.isNotEmpty(pw.getWeights())) { + weights = pw.getWeights(); + } + if(patients != null) { + weights.put(DateUtil.getWeek(patients.getLastMenses(), new Date()), nowWeight); + } + pw.setWeights(weights); + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw)); + mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class); + return RespBuilder.buildSuccess(pw.getId()); + } + + if(StringUtils.isEmpty(patientWeight.getId()) && patients != null) { + patientWeight.setCreated(new Date()); + if(StringUtils.isNotBlank(patientWeight.getPatientId())) { + weights.put(DateUtil.getWeek(patients.getLastMenses(), new Date()), nowWeight); + patientWeight.setWeights(weights); + } + if(StringUtils.isNotBlank(patientWeight.getNowWeight()) && patientWeight.getBeforeHeight() != null) { + patientWeight.setBmi(getBmi(patientWeight.getNowWeight(), patientWeight.getBeforeHeight())); + } + patientWeight.setYn("1"); + mongoTemplate.save(patientWeight); + return RespBuilder.buildSuccess(patientWeight.getId()); + } else { + Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(patientWeight)); + mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(patientWeight.getId())), update, PatientWeight.class); + return RespBuilder.buildSuccess(patientWeight.getId()); + } + } + private void setGuide(Integer week, Map map) { if(week < 12) { Map map1 = setData2("膳食清淡、适口", "避免过咸、过甜和油腻的食物,这样能增加食欲,易于消化,有利于降低怀孕早期的妊娠反应,满足营养的需要。每日盐不超过6克,油不超过20克,可食用植物油,少用动物油。");