diff --git a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IPatientWeightDao.java b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IPatientWeightDao.java new file mode 100644 index 0000000..0408781 --- /dev/null +++ b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/IPatientWeightDao.java @@ -0,0 +1,15 @@ +package com.lyms.platform.biz.dal; + +import com.lyms.platform.pojo.PatientWeight; +import org.springframework.data.mongodb.core.query.Query; + +/** + * 体重管理 + */ +public interface IPatientWeightDao { + + void add(PatientWeight patientWeight); + + void updatePatient(Query query, PatientWeight patientWeight); + +} diff --git a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/PatientWeightDaoImpl.java b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/PatientWeightDaoImpl.java new file mode 100644 index 0000000..2537988 --- /dev/null +++ b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/dal/impl/PatientWeightDaoImpl.java @@ -0,0 +1,25 @@ +package com.lyms.platform.biz.dal.impl; + +import com.lyms.platform.biz.dal.IPatientWeightDao; +import com.lyms.platform.common.dao.BaseMongoDAOImpl; +import com.lyms.platform.pojo.PatientWeight; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Repository; + +/** + * 产前检查 初诊记录 + */ +@Repository +public class PatientWeightDaoImpl extends BaseMongoDAOImpl implements IPatientWeightDao { + + @Override + public void add(PatientWeight patientWeight) { + save(patientWeight); + } + + @Override + public void updatePatient(Query query, PatientWeight patientWeight) { + update(query, patientWeight); + } + +} diff --git a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/PatientWeightService2.java b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/PatientWeightService2.java new file mode 100644 index 0000000..6433fcd --- /dev/null +++ b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/PatientWeightService2.java @@ -0,0 +1,23 @@ +package com.lyms.platform.biz.service; + + +import com.lyms.platform.biz.dal.IPatientWeightDao; +import com.lyms.platform.pojo.PatientWeight; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Service; + +@Service +public class PatientWeightService2 { + + @Autowired + private IPatientWeightDao patientWeightDao; + + public void add(PatientWeight patientWeight) { + patientWeightDao.add(patientWeight); + } + + public void update(Query query, PatientWeight patientWeight) { + patientWeightDao.updatePatient(query, patientWeight); + } +} diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/ReflectionUtils.java b/platform-common/src/main/java/com/lyms/platform/common/utils/ReflectionUtils.java index ae3fe56..e6fda0c 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/ReflectionUtils.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/ReflectionUtils.java @@ -9,9 +9,12 @@ import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,6 +68,21 @@ public class ReflectionUtils { } + public static Map beanToStrMap(Object obj) { + Map map = beanToMap(obj); + Map restMap = new HashMap<>(); + if(MapUtils.isNotEmpty(map)) { + Set> entries = map.entrySet(); + Iterator> iterator = entries.iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + restMap.put(entry.getKey(), entry.getValue() + ""); + } + } + return restMap; + + } + /** * 调用Setter方法.使用value的Class来查找Setter方法. */ 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 eff94b5..7029fd5 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 @@ -109,4 +109,14 @@ public class PatientWeightController extends BaseController { return patientWeightService.wxAddOrUpdate(patientWeight); } + /** + * 保存修改体重报告(小程序使用) + * @return + */ + @ResponseBody + @RequestMapping(value = "/wx/sync", method = RequestMethod.POST) + public BaseResponse wxAddOrUpdateSync(PatientWeight patientWeight) { + return patientWeightService.wxAddOrUpdateSync(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 cdcf71c..80eb903 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 @@ -24,4 +24,6 @@ public interface PatientWeightService extends IBaseService { BaseResponse wxReport(String pid); BaseResponse wxAddOrUpdate(PatientWeight patientWeight); + + BaseResponse wxAddOrUpdateSync(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 353199b..718d79e 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 @@ -1,5 +1,7 @@ package com.lyms.platform.operate.web.service.impl; +import com.lyms.platform.biz.service.PatientWeightService2; +import com.lyms.platform.biz.service.PatientsService; import com.lyms.platform.common.enums.*; import com.lyms.platform.common.result.BaseResponse; import com.lyms.platform.common.result.PageResult; @@ -40,7 +42,10 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient private MongoUtil mongoUtil; @Autowired - private AntenatalExaminationFacade antenatalExaminationFacade; + private PatientWeightService2 patientWeightService2; + + @Autowired + private PatientsService patientsService; /** * 最低:0~13 : 0~1.9 13~40 1.9~11.9 @@ -79,7 +84,8 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient patients.setEnable("2"); patients.setSource(patientWeight.getPatientId()); patients.setCreated(new Date()); - mongoTemplate.save(patients); +// mongoTemplate.save(patients); + patientsService.addPatient(patients); patientWeight.setPatientId(patients.getId()); } Map dayWeights = new HashMap<>(); @@ -90,9 +96,9 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient dayWeights.put(DateUtil.getyyyy_MM_dd(new Date()), nowWeight); pw.setDayWeights(dayWeights); pw.setNowWeight(patientWeight.getNowWeight()); -// pw.setBmi(getBmi(patientWeight.getNowWeight(), pw.getBeforeHeight())); - Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw)); - mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class); +// Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw)); +// mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class); + patientWeightService2.update(Query.query(Criteria.where("id").is(pw.getId())), pw); return RespBuilder.buildSuccess(pw.getId()); } @@ -109,12 +115,14 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient patientWeight.setBmi(getBmi(patientWeight.getBeforeWeight(), patientWeight.getBeforeHeight())); } patientWeight.setYn("1"); - mongoTemplate.save(patientWeight); +// mongoTemplate.save(patientWeight); + patientWeightService2.add(patientWeight); return RespBuilder.buildSuccess(patientWeight.getId()); } else { patientWeight.setOperaterId(userId.toString()); - Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(patientWeight)); - mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(patientWeight.getId())), update, PatientWeight.class); +// Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(patientWeight)); +// mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(patientWeight.getId())), update, PatientWeight.class); + patientWeightService2.update(Query.query(Criteria.where("id").is(patientWeight.getId())), patientWeight); return RespBuilder.buildSuccess(patientWeight.getId()); } } @@ -260,7 +268,11 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient map.put("beforeWeight", patientWeight.getBeforeWeight() + " 公斤"); map.put("bmi", patientWeight.getBmi()); map.put("nowWeight", patientWeight.getNowWeight() + " 公斤"); - map.put("pregnancy", DateUtil.getWeekDesc(patients.getLastMenses(), new Date())); + String pregnancy = DateUtil.getWeekDesc(patients.getLastMenses(), new Date()); + if(StringUtils.isNotEmpty(pregnancy) && pregnancy.endsWith("0天")) { + pregnancy.replaceAll("\\+0天", ""); + } + map.put("pregnancy", pregnancy); if(week != null) { setInfo(week, map); // 设置孕期相关营养信息 setRecipe(week, map); // 设置食谱 @@ -322,8 +334,53 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient dayWeights.put(DateUtil.getyyyy_MM_dd(new Date()), nowWeight); pw.setNowWeight(nowWeight); pw.setDayWeights(dayWeights); +// Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw)); +// mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class); + patientWeightService2.update(Query.query(Criteria.where("id").is(pw.getId())), pw); + return RespBuilder.buildSuccess(pw.getId()); + } + + if(StringUtils.isEmpty(patientWeight.getId()) && patients != null) { + patientWeight.setCreated(new Date()); + patientWeight.setHospitalId(patients.getHospitalId()); + if(StringUtils.isNotBlank(patientWeight.getNowWeight()) && patientWeight.getBeforeHeight() != null) { + patientWeight.setBmi(getBmi(patientWeight.getNowWeight(), patientWeight.getBeforeHeight())); + } + patientWeight.setYn("1"); + patientWeight.setPid(patients.getPid()); +// mongoTemplate.save(patientWeight); + patientWeightService2.add(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); + patientWeightService2.update(Query.query(Criteria.where("id").is(patientWeight.getId())), patientWeight); + return RespBuilder.buildSuccess(patientWeight.getId()); + } + } + + @Override + public BaseResponse wxAddOrUpdateSync(PatientWeight patientWeight) { + String nowWeight = patientWeight.getNowWeight(); + Patients patients = mongoTemplate.findById(patientWeight.getPatientId(), Patients.class); + PatientWeight pw = mongoTemplate.findOne(Query.query(Criteria.where("pid").is(patientWeight.getPid())), PatientWeight.class); + Map dayWeights = new HashMap<>(); + if(pw == null && StringUtils.isEmpty(patientWeight.getBeforeWeight())) { + return RespBuilder.buildErro(ResponseCode.NEED_ADD_PATIENT_WEIGHT); + } + if(pw != null && StringUtils.isNotEmpty(patientWeight.getBeforeWeight())) { + return RespBuilder.buildErro(ResponseCode.PATIENT_WEIGHT_IS_EXIST); + } + if(pw != null) { + if(MapUtils.isNotEmpty(pw.getDayWeights())) { + dayWeights = pw.getDayWeights(); + } + dayWeights.put(DateUtil.getyyyy_MM_dd(new Date()), nowWeight); + pw.setNowWeight(nowWeight); + pw.setDayWeights(dayWeights); Update update = MongoConvertHelper.convertToNativeUpdate(ReflectionUtils.getUpdateField(pw)); mongoTemplate.updateFirst(Query.query(Criteria.where("id").is(pw.getId())), update, PatientWeight.class); +// patientWeightService2.update(Query.query(Criteria.where("id").is(pw.getId())), pw); return RespBuilder.buildSuccess(pw.getId()); } @@ -336,10 +393,12 @@ public class PatientWeightServiceImpl extends BaseServiceImpl implements Patient patientWeight.setYn("1"); patientWeight.setPid(patients.getPid()); mongoTemplate.save(patientWeight); +// patientWeightService2.add(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); +// patientWeightService2.update(Query.query(Criteria.where("id").is(patientWeight.getId())), patientWeight); return RespBuilder.buildSuccess(patientWeight.getId()); } }