Skip to content

Commit

Permalink
BAH-3513 | Fix. Disable encounter search when patient does not have v…
Browse files Browse the repository at this point in the history
…isit (#251)

* BAH-3513 | Fix. Disable encounter search when patient does not have visit.

- When a new patient uuid without visit is passed, encounterSearch happens without any criteria leading to OutOfMemoryError.

* BAH-3513 | Add. Message for the condition block added
  • Loading branch information
mohan-13 authored Feb 5, 2024
1 parent 7ffa7d5 commit 414cc29
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public BahmniFormDetailsServiceImpl(PatientService patientService, VisitService
public Collection<FormDetails> getFormDetails(String patientUuid, FormType formType, int numberOfVisits) {
Patient patient = getPatient(patientUuid);
List<Visit> visits = visitService.getVisitsByPatient(patient);

//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<Visit> limitedVisits = limitVisits(visits, numberOfVisits);

List<Encounter> encounters = getEncounters(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 Expand Up @@ -314,21 +336,4 @@ private void verifyCommonMockCalls() {
any(Boolean.class));
}

private void 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));

}

}

0 comments on commit 414cc29

Please sign in to comment.