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.

- When a new patient uuid without visit is passed, encounterSearch happens without any criteria leading to OutOfMemoryError.
  • Loading branch information
mohan-13 committed Feb 2, 2024
1 parent 7ffa7d5 commit 1364cd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ 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);

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 1364cd2

Please sign in to comment.