Skip to content

Commit

Permalink
add. cherry-picks to resolve OutOfMemory issue (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun-Go authored Feb 7, 2024
1 parent 0daecc9 commit 8adf760
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public Collection<FormDetails> getFormDetails(String patientUuid, FormType formT
List<Visit> visits = visitService.getVisitsByPatient(patient);
List<Visit> limitedVisits = limitVisits(visits, numberOfVisits);

//Warning: This check is needed to avoid getEncounters returning ALL non-voided encounters of all patients leading to OutOfMemoryError:Java Heap
//Refer: https://bahmni.atlassian.net/browse/BAH-3513
if(visits.isEmpty())
return Collections.emptyList();

List<Encounter> encounters = getEncounters(limitedVisits);

if (isNotEmpty(encounters) && isNotEmpty(limitedVisits)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,36 @@ public void shouldReturnFormDetailsGivenPatientUuidFormTypeAsV2AndNumberOfVisits
@Test
public void shouldReturnEmptyCollectionsOfFormDetailsIfPatientDoesNotHaveVisits() {
when(visitService.getVisitsByPatient(patient)).thenReturn(Collections.emptyList());
shouldReturnEmptyCollectionsOfFormDetailsIfPatientDoesNotHaveVisitsOrEncounters();
Collection<FormDetails> formDetailsCollection = bahmniFormDetailsService.getFormDetails(patientUuid, FormType.FORMS2, -1);

assertEquals(0, formDetailsCollection.size());

verify(patientService, times(1)).getPatientByUuid(patientUuid);
verify(visitService, times(1)).getVisitsByPatient(patient);
verify(encounterService, times(0)).getEncounters(any(EncounterSearchCriteria.class));

verify(patient, times(0)).getPerson();
verify(obsService, times(0)).getObservations(anyListOf(Person.class),
anyListOf(Encounter.class), any(), any(), any(), any(), any(), any(), any(), any(), any(),
any(Boolean.class));

}

@Test
public void shouldReturnEmptyCollectionsOfFormDetailsIfPatientDoesNotHaveEncounters() {
when(encounterService.getEncounters(any(EncounterSearchCriteria.class))).thenReturn(Collections.emptyList());
shouldReturnEmptyCollectionsOfFormDetailsIfPatientDoesNotHaveVisitsOrEncounters();
Collection<FormDetails> formDetailsCollection = bahmniFormDetailsService.getFormDetails(patientUuid, FormType.FORMS2, -1);

assertEquals(0, formDetailsCollection.size());

verify(patientService, times(1)).getPatientByUuid(patientUuid);
verify(visitService, times(1)).getVisitsByPatient(patient);
verify(encounterService, times(1)).getEncounters(any(EncounterSearchCriteria.class));

verify(patient, times(0)).getPerson();
verify(obsService, times(0)).getObservations(anyListOf(Person.class),
anyListOf(Encounter.class), any(), any(), any(), any(), any(), any(), any(), any(), any(),
any(Boolean.class));
}

@Test
Expand Down

0 comments on commit 8adf760

Please sign in to comment.