diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AntenatalExaminationFacade.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AntenatalExaminationFacade.java index 1f6c6c1..1c401b3 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AntenatalExaminationFacade.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/AntenatalExaminationFacade.java @@ -1316,7 +1316,7 @@ public class AntenatalExaminationFacade { * @param list 同一产程记录 * @param sortList 排序的结果 */ - private void updateEditEnable(List list, List> sortList) { + public static void updateEditEnable(List list, List> sortList) { //如果上个产程有数据,并且本产程有记录就设置上个产程不可编辑 if (CollectionUtils.isNotEmpty(sortList) && CollectionUtils.isNotEmpty(list)) { List l = sortList.get(sortList.size() - 1); @@ -1332,7 +1332,7 @@ public class AntenatalExaminationFacade { } } - private void sort(List listData) { + public static void sort(List listData) { Collections.sort(listData, new Comparator() { @Override public int compare(AntData o1, AntData o2) { diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientMedicalRecordFacade.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientMedicalRecordFacade.java new file mode 100644 index 0000000..619e0e4 --- /dev/null +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientMedicalRecordFacade.java @@ -0,0 +1,494 @@ +package com.lyms.platform.operate.web.facade; + +import com.lyms.platform.biz.service.*; +import com.lyms.platform.common.constants.ErrorCodeConstants; +import com.lyms.platform.common.enums.YnEnums; +import com.lyms.platform.common.result.BaseObjectResponse; +import com.lyms.platform.common.result.BaseResponse; +import com.lyms.platform.common.utils.DateUtil; +import com.lyms.platform.operate.web.request.AntExListQueryRequest; +import com.lyms.platform.operate.web.result.AntData; +import com.lyms.platform.operate.web.result.AntexListResult; +import com.lyms.platform.operate.web.result.HighScoreResult; +import com.lyms.platform.permission.model.Organization; +import com.lyms.platform.permission.service.OrganizationService; +import com.lyms.platform.pojo.*; +import com.lyms.platform.query.*; +import org.apache.commons.collections.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Component; + +import java.util.*; + + +/** + * 电子病历 + *

+ * 详细描述 + *

+ * 示例代码 + *

+ * 
+ * + * @author JIAZHI.JIANG + * @version BME V100R001 2018-02-08 11:56 + * @since BME V100R001C40B104 + */ +@Component +public class PatientMedicalRecordFacade { + + //日志调测器 + private static final Logger logger = LoggerFactory.getLogger(PatientMedicalRecordFacade.class); + + @Autowired + private OrganizationGroupsFacade groupsFacade; + @Autowired + private PatientsService patientsService; + @Autowired + private AutoMatchFacade autoMatchFacade; + @Autowired + private AntenatalExaminationFacade examinationFacade; + @Autowired + private OrganizationService organizationService; + + @Autowired + private AntenatalExaminationService antenatalExaminationService; + + @Autowired + private DischargeAbstractMotherService dischargeAbstractMotherService; + @Autowired + private PostReviewService postReviewService; + + @Autowired + private MatDeliverService matDeliverService; + + @Autowired + private StopPregnancyService stopPregnancyService; + + + /** + * 获取电子病历接口 + * + * @param exListQueryRequest 电子病历请求对象 + * @param userId 用户登录id + * @return 查询结果 + */ + public BaseResponse findAntExListTwo(AntExListQueryRequest exListQueryRequest, Integer userId) { + AntexListResult antexListResult = new AntexListResult(); + + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setCardNo(exListQueryRequest.getCardNo()); + patientsQuery.setYn(YnEnums.YES.getId()); + patientsQuery.setPhone(exListQueryRequest.getPhone()); + patientsQuery.setPid(exListQueryRequest.getPid()); + patientsQuery.setBuildType(1); + //在区域组的时候不用查询隐藏档案 + if (null != groupsFacade.findByCurrentUserId(autoMatchFacade.getHospitalId(userId))) { + patientsQuery.setExtEnable(false); + } + + //获取所有的建档记录 + List list = patientsService.queryPatient(patientsQuery); + + //处理电子病历的数据 + doExecuteMedicalRecord(antexListResult, userId, exListQueryRequest, list); + + return new BaseObjectResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(antexListResult); + } + + /** + * 处理电子病历的数据 + * + * @param antexListResult + * @param userId + * @param exListQueryRequest + * @param list + */ + private void doExecuteMedicalRecord(AntexListResult antexListResult, Integer userId, AntExListQueryRequest exListQueryRequest, List list) { + Patients patients2 = examinationFacade.findOnePatient(null, null, null, groupsFacade.findGroupHospital(userId, true), -1, true, exListQueryRequest.getPid(), false); + antexListResult.convertToResult(null, patients2, null); + List sortList = new ArrayList(); + + if (CollectionUtils.isNotEmpty(list)) { + HighScoreResult highScoreResult = examinationFacade.findLastRisk(list.get(0).getPid(), false); + antexListResult.setRiskFactor(highScoreResult.getHighRisk()); + antexListResult.setRiskScore(highScoreResult.getScoreStr()); + + //分组后的数据 + MedicalRecord medicalRecord = doHandMedicalRecordGroup(list); + + //处理已经分娩的电子病历数据 + if (CollectionUtils.isNotEmpty(medicalRecord.getFmPatient())) { + int size = medicalRecord.getFmPatient().size(); + for (int i = 0; i < size; i++) { + + MedicalRecordGroupVo medicalRecordGroupVo = medicalRecord.getFmPatient().get(i); + + List listData = new ArrayList(); + //处理分娩前的数据 + doHandBeforeFmRecord(medicalRecordGroupVo, listData); + //处理分娩后的数据 + doHandAfterFmRecord(medicalRecordGroupVo, listData, i + 1 == size ? new Date() : medicalRecord.getFmPatient().get(i).getMinLastMenses()); + //排序并修改按钮状态 + triggerAfterCompletion(listData, sortList); + } + } + + //处理未分娩的电子病历数据 + if (CollectionUtils.isNotEmpty(medicalRecord.getUfmPatient())) { + List listData = new ArrayList(); + for (MedicalRecordGroupVo medicalRecordGroupVo : medicalRecord.getUfmPatient()) { + //处理分娩前的数据 + doHandBeforeFmRecord(medicalRecordGroupVo, listData); + } + //排序并修改按钮状态 + triggerAfterCompletion(listData, sortList); + } + } + antexListResult.setData(sortList); + } + + /** + * 排序并修改按钮状态 + * + * @param listData 一个产程的数据 + * @param sortList 多个产程的数据集合 + */ + private void triggerAfterCompletion(List listData, List sortList) { + //排序并修改按钮状态 + AntenatalExaminationFacade.sort(listData); + AntenatalExaminationFacade.updateEditEnable(listData, sortList); + sortList.add(listData); + } + + /** + * 处理分娩后的数据 + * + * @param medicalRecordGroupVo + * @param listData + */ + private void doHandAfterFmRecord(MedicalRecordGroupVo medicalRecordGroupVo, List listData, Date nextLastMenses) { + PostReviewQuery postReviewQuery = new PostReviewQuery(); + String pid = medicalRecordGroupVo.getPid(); + postReviewQuery.setStart(medicalRecordGroupVo.getFmDate()); + //下次建档记录前都是产后复查,如果没有下个产程的数据就直接显示 + postReviewQuery.setEnd(nextLastMenses); + postReviewQuery.setPid(pid); + Organization organization = null; + + + MatDeliverQuery matDeliverQuery = new MatDeliverQuery(); + matDeliverQuery.setPid(medicalRecordGroupVo.getPid()); + matDeliverQuery.setYn(YnEnums.YES.getId()); + matDeliverQuery.setCreatedStart(medicalRecordGroupVo.getFmDate()); + matDeliverQuery.setEndStart(nextLastMenses); + List metDel = matDeliverService.query(matDeliverQuery); + + if (CollectionUtils.isNotEmpty(metDel)) { + MaternalDeliverModel model = metDel.get(0); + if (null != model.getHospitalId()) { + organization = organizationService.getOrganization(Integer.valueOf(model.getHospitalId())); + } + listData.add(new AntData(model, medicalRecordGroupVo.getMinLastMenses(), null != organization ? organization.getName() : "")); + } else { + StopPregQuery query = new StopPregQuery(); + query.setYn(YnEnums.YES.getId()); + query.setPid(medicalRecordGroupVo.getPid()); + query.setStopDateStart(medicalRecordGroupVo.getFmDate()); + query.setStopDateEnd(nextLastMenses); + List stopPregs = stopPregnancyService.queryStopPreg(query); + if (CollectionUtils.isNotEmpty(stopPregs)) { + StopPregModel model = stopPregs.get(0); + if (null != model.getHospitalId()) { + organization = organizationService.getOrganization(Integer.valueOf(model.getHospitalId())); + } + listData.add(new AntData(model, medicalRecordGroupVo.getMinLastMenses(), null != organization ? organization.getName() : "")); + } + } + + + DischargeAbstractMotherQuery dischargeAbstractMotherQuery = new DischargeAbstractMotherQuery(); + dischargeAbstractMotherQuery.setPid(pid); + dischargeAbstractMotherQuery.setYn(YnEnums.YES.getId()); + dischargeAbstractMotherQuery.setStart(medicalRecordGroupVo.getFmDate()); + dischargeAbstractMotherQuery.setEnd(nextLastMenses); + + List dischargeAbstractMotherModels = dischargeAbstractMotherService.query(dischargeAbstractMotherQuery); + + if (CollectionUtils.isNotEmpty(dischargeAbstractMotherModels)) { + for (DischargeAbstractMotherModel model : dischargeAbstractMotherModels) { + listData.add(new AntData(model, null != organization ? organization.getName() : "", medicalRecordGroupVo.getFmDate())); + } + } + + + //产后复查记录 + List reviewModels = postReviewService.findWithList(postReviewQuery); + if (CollectionUtils.isNotEmpty(reviewModels)) { + for (PostReviewModel postReviewModel : reviewModels) { + if (postReviewModel.getYn() == YnEnums.YES.getId()) { + if (null != postReviewModel.getHospitalId()) { + organization = organizationService.getOrganization(Integer.valueOf(postReviewModel.getHospitalId())); + } + listData.add(new AntData(postReviewModel, null != organization ? organization.getName() : "", medicalRecordGroupVo.getFmDate())); + } + } + } + } + + /** + * 处理分娩前的数据 + * + * @param medicalRecordGroupVo + * @param listData + * @return + */ + private List doHandBeforeFmRecord(MedicalRecordGroupVo medicalRecordGroupVo, List listData) { + + Organization organization = null; + String pid = ""; + + for (String patientId : medicalRecordGroupVo.getPatientIds()) { + + Patients patients = patientsService.findOnePatientById(patientId); + //建档记录 + if (null != patients.getHospitalId()) { + organization = organizationService.getOrganization(Integer.valueOf(patients.getHospitalId())); + } + pid = patients.getPid(); + if (!"2".equals(patients.getEnable())) { + listData.add(new AntData(patients, null != organization ? organization.getName() : "")); + } + } + + + //初诊记录 + AntExChuQuery antExChuQuery = new AntExChuQuery(); + antExChuQuery.setYn(YnEnums.YES.getId()); + antExChuQuery.setStart(medicalRecordGroupVo.getMinLastMenses()); + antExChuQuery.setEnd(medicalRecordGroupVo.getFmDate()); + antExChuQuery.setPid(pid); + + List antExChuModels = antenatalExaminationService.queryAntExChu(antExChuQuery); + if (CollectionUtils.isNotEmpty(antExChuModels)) { + for (AntExChuModel an : antExChuModels) { + if (null != an.getHospitalId()) { + organization = organizationService.getOrganization(Integer.valueOf(an.getHospitalId())); + } + listData.add(new AntData(an, null != organization ? organization.getName() : "", medicalRecordGroupVo.getMinLastMenses())); + } + } + + //复诊记录 + AntExQuery antExQuery = new AntExQuery(); + antExQuery.setYn(YnEnums.YES.getId()); + antExQuery.setPid(pid); + antExQuery.setStart(medicalRecordGroupVo.getMinLastMenses()); + antExQuery.setEnd(medicalRecordGroupVo.getFmDate()); + + List list1 = antenatalExaminationService.queryAntenatalExamination(antExQuery.convertToQuery().addOrder(Sort.Direction.DESC, "checkDate")); + if (CollectionUtils.isNotEmpty(list1)) { + for (AntenatalExaminationModel an : list1) { + if (null != an.getHospitalId()) { + organization = organizationService.getOrganization(Integer.valueOf(an.getHospitalId())); + } + listData.add(new AntData(an, null != organization ? organization.getName() : "", medicalRecordGroupVo.getMinLastMenses())); + } + } + return listData; + } + + /** + * 把建档的数据按分娩日期进行分组 + * + * @param patientses + * @return + */ + private MedicalRecord doHandMedicalRecordGroup(List patientses) { + Map patientGroup = new HashMap<>(); + List groupVoList = new ArrayList<>(); + MedicalRecordGroupVo recordGroupVo = null; + for (Patients patients : patientses) { + //已分娩的 + if (patients.getType() == 3) { + String mapkey = DateUtil.getyyyy_MM_dd(patients.getFmDate()); + //未分娩的 + if (patientGroup.containsKey(mapkey)) { + MedicalRecordGroupVo medicalRecordGroupVo = patientGroup.get(mapkey); + medicalRecordGroupVo.getPatientIds().add(patients.getId()); + medicalRecordGroupVo.setMinLastMenses(patients.getLastMenses()); + medicalRecordGroupVo.setPid(patients.getPid()); + } else { + List patientId = new ArrayList<>(); + patientId.add(patients.getId()); + MedicalRecordGroupVo medicalRecordGroupVo = new MedicalRecordGroupVo(patients.getFmDate(), patients.getLastMenses(), patientId, patients.getPid()); + patientGroup.put(mapkey, medicalRecordGroupVo); + } + } else if (patients.getType() == 1) { + List patientId = new ArrayList<>(); + patientId.add(patients.getId()); + if (null == recordGroupVo) { + recordGroupVo = new MedicalRecordGroupVo(patients.getFmDate(), patients.getLastMenses(), patientId, patients.getPid()); + } else { + recordGroupVo.getPatientIds().add(patients.getId()); + recordGroupVo.setMinLastMenses(patients.getLastMenses()); + recordGroupVo.setPid(patients.getPid()); + } + } + } + + if (null != recordGroupVo) { + groupVoList.add(recordGroupVo); + } + + sort(groupVoList, Boolean.TRUE); + return new MedicalRecord(toListAndSort(patientGroup), groupVoList); + } + + /** + * 把分组后的数据转成集合并排序 + * + * @param patientGroup + * @return + */ + private List toListAndSort(Map patientGroup) { + Set> medicalRecordGroupVoSet = patientGroup.entrySet(); + Iterator> IT = medicalRecordGroupVoSet.iterator(); + List DATA = new ArrayList<>(); + + while (IT.hasNext()) { + DATA.add(IT.next().getValue()); + } + sort(DATA, Boolean.FALSE); + return DATA; + } + + /** + * @param DATA + * @param fmNull 分娩时间是否为空 TRUE/FALSE + */ + private void sort(List DATA, boolean fmNull) { + Comparator comparator = null; + + + if (fmNull) { + comparator = new Comparator() { + @Override + public int compare(MedicalRecordGroupVo o1, MedicalRecordGroupVo o2) { + if (o1.getMinLastMenses() != null && null != o2.getMinLastMenses() && o1.getMinLastMenses().after(o2.getMinLastMenses())) { + return -1; + } + if (o1.getMinLastMenses() != null && null != o2.getMinLastMenses() && o1.getMinLastMenses().before(o2.getMinLastMenses())) { + return 1; + } + return 0; + } + }; + } else { + comparator = new Comparator() { + @Override + public int compare(MedicalRecordGroupVo o1, MedicalRecordGroupVo o2) { + if (o1.getFmDate() != null && null != o2.getFmDate() && o1.getFmDate().after(o2.getFmDate())) { + return -1; + } + if (o1.getFmDate() != null && null != o2.getFmDate() && o1.getFmDate().before(o2.getFmDate())) { + return 1; + } + return 0; + } + }; + } + //按照数据排序 + Collections.sort(DATA, comparator); + } + + + private class MedicalRecord { + //已分娩的建档数据 + private List fmPatient; + //未分娩的建档数据 + private List ufmPatient; + + + public MedicalRecord(List fmPatient, List ufmPatient) { + this.fmPatient = fmPatient; + this.ufmPatient = ufmPatient; + } + + public List getFmPatient() { + return fmPatient; + } + + public void setFmPatient(List fmPatient) { + this.fmPatient = fmPatient; + } + + public List getUfmPatient() { + return ufmPatient; + } + + public void setUfmPatient(List ufmPatient) { + this.ufmPatient = ufmPatient; + } + } + + /** + * 病历分组对象 + */ + private class MedicalRecordGroupVo { + //分娩时间 + private Date fmDate; + //这个产程里面最早的一个末次月经时间 + private Date minLastMenses; + //孕妇建档id + private List patientIds; + + private String pid; + + public MedicalRecordGroupVo(Date fmDate, Date minLastMenses, List patientIds, String pid) { + this.fmDate = fmDate; + this.minLastMenses = minLastMenses; + this.patientIds = patientIds; + this.pid = pid; + } + + public String getPid() { + return pid; + } + + public void setPid(String pid) { + if (null != pid) { + this.pid = pid; + } + } + + public Date getFmDate() { + return fmDate; + } + + public void setFmDate(Date fmDate) { + this.fmDate = fmDate; + } + + public Date getMinLastMenses() { + return minLastMenses; + } + + public void setMinLastMenses(Date minLastMenses) { + if (minLastMenses.getTime() < this.minLastMenses.getTime()) { + this.minLastMenses = minLastMenses; + } + } + + public List getPatientIds() { + return patientIds; + } + + public void setPatientIds(List patientIds) { + this.patientIds = patientIds; + } + } +}