Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSEMR-471 Match the total TX Curr on graph, card and regimens #54

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -517,8 +517,7 @@ public Object getPatientsOnAdultRegimenTreatment(HttpServletRequest request,
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 @@ -543,8 +542,7 @@ public Object getPatientsOnChildRegimenTreatment(HttpServletRequest request,
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));
}
}