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

Bahmni-IPD-master-cherry-pick | BAH-3513 | Fix. Disable encounter search when patient does not have visit #252

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading