From 65b3cc6854c84f542962bf776b7c0f0cad2167c8 Mon Sep 17 00:00:00 2001 From: Omar Ahmed Date: Wed, 1 Feb 2017 13:38:45 +0500 Subject: [PATCH] Omar Ahmed |ED-4|Patient Monitoring tool improvments for configurable status tracking --- .../flowsheet/config/FlowsheetConfig.java | 35 ++++++++ .../constants/FlowsheetConstant.java | 6 +- .../org/bahmni/flowsheet/ui/FlowsheetUI.java | 6 +- ...PatientMonitoringFlowsheetServiceImpl.java | 83 +++++++++++++------ ...tientMonitoringFlowsheetServiceImplIT.java | 4 +- 5 files changed, 101 insertions(+), 33 deletions(-) diff --git a/omod/src/main/java/org/bahmni/flowsheet/config/FlowsheetConfig.java b/omod/src/main/java/org/bahmni/flowsheet/config/FlowsheetConfig.java index 4545ac5a8..063d9d6d7 100644 --- a/omod/src/main/java/org/bahmni/flowsheet/config/FlowsheetConfig.java +++ b/omod/src/main/java/org/bahmni/flowsheet/config/FlowsheetConfig.java @@ -8,6 +8,10 @@ import java.util.List; public class FlowsheetConfig { + private boolean trackPending; + private boolean trackPlanned; + private int monthsPostTreatEnd; + private List milestoneConfigs; private List questionConfigs = new ArrayList<>(); @@ -37,4 +41,35 @@ public QuestionConfig getQuestionConfigByName(String name){ } return null; } + + @JsonProperty(FlowsheetConstant.TRACK_PENDING) + public boolean getTrackPending() { + return trackPending; + } + + @JsonProperty(FlowsheetConstant.TRACK_PENDING) + public void setTrackPending(boolean trackPending) { + this.trackPending = trackPending; + } + + @JsonProperty(FlowsheetConstant.TRACK_PLANNED) + public boolean getTrackPlanned() { + return trackPlanned; + } + + @JsonProperty(FlowsheetConstant.TRACK_PLANNED) + public void setTrackPlanned(boolean trackPlanned) { + this.trackPlanned = trackPlanned; + } + + @JsonProperty(FlowsheetConstant.MONTHS_POST_TREATMENT_END) + public int getMonthsPostTreatEnd() { + return monthsPostTreatEnd; + } + + @JsonProperty(FlowsheetConstant.MONTHS_POST_TREATMENT_END) + public void setMonthsPostTreatEnd(int monthsPostTreatEnd) { + this.monthsPostTreatEnd = monthsPostTreatEnd; + } + } diff --git a/omod/src/main/java/org/bahmni/flowsheet/constants/FlowsheetConstant.java b/omod/src/main/java/org/bahmni/flowsheet/constants/FlowsheetConstant.java index 6ab2be4e0..87ff7f3b5 100644 --- a/omod/src/main/java/org/bahmni/flowsheet/constants/FlowsheetConstant.java +++ b/omod/src/main/java/org/bahmni/flowsheet/constants/FlowsheetConstant.java @@ -15,5 +15,9 @@ private FlowsheetConstant() { public static final String MAX = "max"; public static final String HANDLER = "handler" ; public static final String QUESTIONS = "questions"; - public static final String CONFIG = "config"; + public static final String CONFIG = "config"; + public static final String TRACK_PLANNED = "trackPlanned"; + public static final String TRACK_PENDING= "trackPending"; + public static final String MONTHS_POST_TREATMENT_END = "monthsPostTreatmentEnd"; + } diff --git a/omod/src/main/java/org/bahmni/flowsheet/ui/FlowsheetUI.java b/omod/src/main/java/org/bahmni/flowsheet/ui/FlowsheetUI.java index 709ef6921..efc5761d6 100644 --- a/omod/src/main/java/org/bahmni/flowsheet/ui/FlowsheetUI.java +++ b/omod/src/main/java/org/bahmni/flowsheet/ui/FlowsheetUI.java @@ -27,12 +27,12 @@ public void setFlowsheetData(Map> flowsheetData) { this.flowsheetData = flowsheetData; } - public String getHighlightedMilestone() { + public String getHighlightedCurrentMilestone() { return highlightedCurrentMilestone; } - public void setHighlightedMilestone(String highlightedMilestone) { - this.highlightedCurrentMilestone = highlightedMilestone; + public void setHighlightedCurrentMilestone(String highlightedCurrentMilestone) { + this.highlightedCurrentMilestone = highlightedCurrentMilestone; } public List getMilestones() { diff --git a/omod/src/main/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImpl.java b/omod/src/main/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImpl.java index 16f61414c..a193a8c4c 100644 --- a/omod/src/main/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImpl.java +++ b/omod/src/main/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImpl.java @@ -73,7 +73,15 @@ public FlowsheetUI getFlowsheetForPatientProgram(PatientProgram patientProgram, Set floatingMilestoneNames = getFloatingMilestoneNames(flowsheetConfig.getMilestoneConfigs()); setNotApplicableStatusToFixedMilestones(endDate, milestones, floatingMilestoneNames); - String highlightedCurrentMilestoneName = findCurrentMonthMilestone(milestones, endDate, floatingMilestoneNames); + + int monthsPostTreatment=0; + if(flowsheetConfig.getMonthsPostTreatEnd()> -1) + { + monthsPostTreatment = flowsheetConfig.getMonthsPostTreatEnd(); + } + + String highlightedCurrentMilestoneName = findCurrentMonthMilestone(milestones, endDate, floatingMilestoneNames, monthsPostTreatment); + String treatmentEndMilestoneName = findEndDateMilestone(milestones, endDate, floatingMilestoneNames); List questionConfigs = flowsheetConfig.getQuestionConfigs(); @@ -83,12 +91,8 @@ public FlowsheetUI getFlowsheetForPatientProgram(PatientProgram patientProgram, String questionName = questionConfig.getName(); List colorCodes = new LinkedList<>(); for (Milestone milestone : milestones) { - Question milestoneQuestion = getQuestionFromSet(milestone.getQuestions(), questionName); - if (milestoneQuestion == null) { - colorCodes.add("grey"); - } else { - colorCodes.add(getColorCodeForStatus(milestoneQuestion.getResult().getStatus())); - } + Question milestoneQuestion = getQuestionFromSet(milestone.getQuestions(), questionName); + colorCodes.add(getColorCodeForStatus(milestoneQuestion, flowsheetConfig)); } flowsheetData.put(questionName, colorCodes); } @@ -100,7 +104,7 @@ public FlowsheetUI getFlowsheetForPatientProgram(PatientProgram patientProgram, } presentationFlowsheet.setMilestones(flowsheetMilestones); - presentationFlowsheet.setHighlightedMilestone(highlightedCurrentMilestoneName); + presentationFlowsheet.setHighlightedCurrentMilestone(highlightedCurrentMilestoneName); presentationFlowsheet.setEndDateMilestone(treatmentEndMilestoneName); presentationFlowsheet.setFlowsheetData(flowsheetData); return presentationFlowsheet; @@ -246,26 +250,39 @@ private String getProgramAttribute(BahmniPatientProgram bahmniPatientProgram, St return ""; } - private String findCurrentMonthMilestone(Set milestones, Date endDate, Set floatingMilestones) { + private String findCurrentMonthMilestone(Set milestones, Date endDate, Set floatingMilestones,int monthsPostEndDate) { + Date currentDate = new Date(); + Date endDatePlusMonths = null; + Milestone currentMilestone=null; + if (endDate == null) { endDate = new Date(); } + boolean trackAfterEndDate=false; - //TODO: Use the following snippet based on Configuration json - + if(monthsPostEndDate>0) + { + trackAfterEndDate = true; + } Calendar cal = GregorianCalendar.getInstance(); cal.setTime(endDate); - cal.add(6, Calendar.MONTH); - endDate = cal.getTime(); - + cal.add(Calendar.MONTH, monthsPostEndDate); + endDatePlusMonths = cal.getTime(); + for (Milestone milestone : milestones) { - if ((!floatingMilestones.contains(milestone.getName())) - && (milestone.getStartDate().before(endDate) || DateUtils.isSameDay(milestone.getStartDate(), endDate)) - && (milestone.getEndDate().after(endDate) || DateUtils.isSameDay(milestone.getEndDate(), endDate))) { - return milestone.getName(); + if( (!floatingMilestones.contains(milestone.getName())) + && (milestone.getStartDate().before(currentDate) || DateUtils.isSameDay(milestone.getStartDate(), currentDate)) + && (milestone.getEndDate().after(currentDate) || DateUtils.isSameDay(milestone.getEndDate(), currentDate))) { + currentMilestone = milestone; + break; } } - return ""; + if(currentMilestone==null) + return ""; + if(currentMilestone.getStartDate().before(endDatePlusMonths)) + return currentMilestone.getName(); + else + return ""; } private String findEndDateMilestone(Set milestones, Date endDate, Set floatingMilestones) { @@ -311,20 +328,32 @@ private FlowsheetConfig getFlowsheetConfig(String configFilePath) throws Excepti return flowsheetConfig; } - private String getColorCodeForStatus(Status status) { - if (status.equals(Status.DATA_ADDED)) { - return "green"; + private String getColorCodeForStatus(Question milestoneQuestion, FlowsheetConfig flowsheetConf) { + + String result="grey"; + if(milestoneQuestion == null || milestoneQuestion.getResult() == null) + return result; + + Status status = milestoneQuestion.getResult().getStatus(); + + if (status.equals(Status.DATA_ADDED)) { + result = "green"; } - if (status.equals(Status.PLANNED)) { - return "grey"; + + if ( status.equals(Status.PLANNED)) { + if(flowsheetConf.getTrackPlanned()) + result = "yellow"; } + if (status.equals(Status.PENDING)) { - return "grey"; + if(flowsheetConf.getTrackPending()) + result = "purple"; } + if (status.equals(Status.NOT_APPLICABLE)) { - return "grey"; + result="grey"; } - return "grey"; + return result; } } diff --git a/omod/src/test/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImplIT.java b/omod/src/test/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImplIT.java index 110524cfa..51df44249 100644 --- a/omod/src/test/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImplIT.java +++ b/omod/src/test/java/org/openmrs/module/endtb/flowsheet/service/impl/PatientMonitoringFlowsheetServiceImplIT.java @@ -111,7 +111,7 @@ public void shouldSetFlowsheetWhenEndDateIsGiven() throws Exception { assertEquals("M4", flowsheetHeaders.get(3).getName()); assertEquals("MTx", flowsheetHeaders.get(4).getName()); assertEquals("M6M", flowsheetHeaders.get(5).getName()); - assertEquals("M3", flowsheetUI.getHighlightedMilestone()); + assertEquals("M3", flowsheetUI.getHighlightedCurrentMilestone()); assertEquals(6, flowsheetData.get("New Drugs").size()); assertEquals(6, flowsheetData.get("Blood Pressure").size()); assertEquals("grey", coloursForNewDrugs.get(0)); @@ -164,7 +164,7 @@ public void shouldSetFlowsheetWhenEndDateIsNotGiven() throws Exception { assertEquals("M4", flowsheetHeaders.get(3).getName()); assertEquals("MTx", flowsheetHeaders.get(4).getName()); assertEquals("M6M", flowsheetHeaders.get(5).getName()); - assertEquals("", flowsheetUI.getHighlightedMilestone()); + assertEquals("", flowsheetUI.getHighlightedCurrentMilestone()); assertEquals(6, flowsheetData.get("New Drugs").size()); assertEquals(6, flowsheetData.get("Blood Pressure").size()); assertEquals("grey", coloursForNewDrugs.get(0));