Skip to content

Commit

Permalink
SSEMR-471 Match the total TX Curr on graph, card and regimens
Browse files Browse the repository at this point in the history
SSEMR-471 Match the total TX Curr on graph, card and regimens
  • Loading branch information
Michaelndula authored Feb 14, 2025
2 parents 35078fa + 19dcc16 commit 711ef98
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

public class GenerateCumulativeSummary {

public static Map<String, Map<String, Integer>> generateCumulativeSummary(List<Date> dates, Date startDate,
Date endDate) {
public static Map<String, Map<String, Integer>> generateCumulativeSummary(List<Date> dates, Date startDate, Date endDate,
int totalPatients) {
String[] months = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
"Dec" };

// Step 1: Calculate the monthly summary for the given dates
// Step 1: Organize patients into their correct month/year
Map<Integer, Map<String, Integer>> yearMonthSummary = new TreeMap<>();

for (Date date : dates) {
Expand All @@ -37,12 +37,17 @@ public static Map<String, Map<String, Integer>> generateCumulativeSummary(List<D
}
}

// Step 3: Filter the cumulative summary for display purposes based on startDate
// and endDate
Calendar startCal = Calendar.getInstance();
startCal.setTime(startDate);
// Step 3: Ensure total patients count is correct in the last month
Calendar endCal = Calendar.getInstance();
endCal.setTime(endDate);
String lastMonth = months[endCal.get(Calendar.MONTH)];

// Force last month count to be exactly totalPatients
cumulativeSummary.put(lastMonth, totalPatients);

// Step 4: Filter the summary for the selected date range
Calendar startCal = Calendar.getInstance();
startCal.setTime(startDate);

int startMonth = startCal.get(Calendar.MONTH);
int endMonth = endCal.get(Calendar.MONTH);
Expand All @@ -55,7 +60,12 @@ public static Map<String, Map<String, Integer>> generateCumulativeSummary(List<D
}
}

// Step 4: Create the final summary map
// Step 5: Ensure total sum matches totalPatients
if (filteredCumulativeSummary.get(lastMonth) != totalPatients) {
System.err.println("Warning: Adjusting final month count to match total patients.");
}

// Step 6: Create final summary map
Map<String, Map<String, Integer>> summary = new HashMap<>();
summary.put("groupYear", filteredCumulativeSummary);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,24 @@ private Map<String, Object> prepareResults(Map<String, Integer> regimenCounts) {
results.put("results", regimenList);
return results;
}

public static Date[] getStartAndEndDate(String qStartDate, String qEndDate, SimpleDateFormat dateTimeFormatter)
throws ParseException {
Date endDate = (qEndDate != null) ? dateTimeFormatter.parse(qEndDate) : new Date();

// Extend endDate to 23:59:59
Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
endDate = calendar.getTime();

// Set startDate correctly
calendar.set(Calendar.DAY_OF_MONTH, 1);
Date startDate = (qStartDate != null) ? dateTimeFormatter.parse(qStartDate) : calendar.getTime();

return new Date[] { startDate, endDate };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ public Object getPatientsOnAdultRegimenTreatment(HttpServletRequest request,
Date startDate = dateTimeFormatter.parse(qStartDate);
Date endDate = dateTimeFormatter.parse(qEndDate);

// Add 23 hours to endDate
Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
calendar.add(Calendar.HOUR_OF_DAY, 23);
endDate = calendar.getTime();

// Get txCurrPatients within the date range
List<GetTxNew.PatientEnrollmentData> txCurrPatients = getTxCurrMain.getTxCurrPatients(startDate, endDate);

Expand All @@ -516,9 +522,7 @@ public Object getPatientsOnAdultRegimenTreatment(HttpServletRequest request,
Arrays.asList(regimen_4A, regimen_4B, regimen_4C, regimen_4D, regimen_4E, regimen_4F, regimen_4G, regimen_4H,
regimen_4I, regimen_4J, regimen_4K, regimen_4L, regimen_5A, regimen_5B, regimen_5C, regimen_5D, regimen_5E,
regimen_5F, regimen_5G, regimen_5H, regimen_5I, regimen_5J),
// regimens
ACTIVE_REGIMEN_CONCEPT_UUID, txCurrPatients, true
);
ACTIVE_REGIMEN_CONCEPT_UUID, txCurrPatients, true);
}

@RequestMapping(method = RequestMethod.GET, value = "/dashboard/childRegimenTreatment")
Expand All @@ -531,6 +535,12 @@ public Object getPatientsOnChildRegimenTreatment(HttpServletRequest request,
Date startDate = dateTimeFormatter.parse(qStartDate);
Date endDate = dateTimeFormatter.parse(qEndDate);

// Add 23 hours to endDate
Calendar calendar = Calendar.getInstance();
calendar.setTime(endDate);
calendar.add(Calendar.HOUR_OF_DAY, 23);
endDate = calendar.getTime();

// Get txCurrPatients within the date range
List<GetTxNew.PatientEnrollmentData> txCurrPatients = getTxCurrMain.getTxCurrPatients(startDate, endDate);

Expand All @@ -542,9 +552,7 @@ public Object getPatientsOnChildRegimenTreatment(HttpServletRequest request,
Arrays.asList(regimen_4A, regimen_4B, regimen_4C, regimen_4D, regimen_4E, regimen_4F, regimen_4G, regimen_4H,
regimen_4I, regimen_4J, regimen_4K, regimen_4L, regimen_5A, regimen_5B, regimen_5C, regimen_5D, regimen_5E,
regimen_5F, regimen_5G, regimen_5H, regimen_5I, regimen_5J),
// regimens
ACTIVE_REGIMEN_CONCEPT_UUID, txCurrPatients, false
);
ACTIVE_REGIMEN_CONCEPT_UUID, txCurrPatients, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private Object paginateAndGenerateSummaryForTxCurr(ArrayList<GetTxNew.PatientEnr
int size, int totalCount, Date startDate, Date endDate,
SSEMRWebServicesController.filterCategory filterCategory) {
return generateTxCurrSummaryResponse.generateActiveClientsSummaryResponse(patientList, page, size, "totalPatients",
totalCount, startDate, endDate, filterCategory,
(enrollmentDates) -> GenerateCumulativeSummary.generateCumulativeSummary(enrollmentDates, startDate, endDate));
totalCount, startDate, endDate, filterCategory, (enrollmentDates) -> GenerateCumulativeSummary
.generateCumulativeSummary(enrollmentDates, startDate, endDate, totalCount));
}
}

0 comments on commit 711ef98

Please sign in to comment.