diff --git a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniObsServiceImpl.java b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniObsServiceImpl.java index 698b3db31..5c9087d46 100644 --- a/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniObsServiceImpl.java +++ b/bahmnicore-api/src/main/java/org/bahmni/module/bahmnicore/service/impl/BahmniObsServiceImpl.java @@ -18,8 +18,10 @@ import org.openmrs.api.ConceptService; import org.openmrs.api.ObsService; import org.openmrs.api.VisitService; +import org.openmrs.api.context.Context; import org.openmrs.module.bahmniemrapi.encountertransaction.contract.BahmniObservation; import org.openmrs.module.bahmniemrapi.encountertransaction.mapper.OMRSObsToBahmniObsMapper; +import org.openmrs.util.LocaleUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -69,11 +71,20 @@ public Collection observationsFor(String patientUuid, Collect private List getConceptNames(Collection concepts) { List conceptNames = new ArrayList<>(); for (Concept concept : concepts) { - conceptNames.add(concept.getName().getName()); + if(concept != null) { + conceptNames.add(getConceptName(concept, Context.getLocale())); + } } return conceptNames; } + private String getConceptName(Concept concept, Locale searchLocale) { + if (concept.getName(searchLocale) != null) + return concept.getName(searchLocale).getName(); + else + return concept.getName(LocaleUtility.getDefaultLocale()).getName(); + } + @Override public Collection observationsFor(String patientUuid, Concept rootConcept, Concept childConcept, Integer numberOfVisits, Date startDate, Date endDate, String patientProgramUuid) { Collection encounters = programWorkflowService.getEncountersByPatientProgramUuid(patientProgramUuid); diff --git a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolver.java b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolver.java new file mode 100644 index 000000000..cb53511c5 --- /dev/null +++ b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolver.java @@ -0,0 +1,21 @@ +package org.bahmni.module.bahmnicore.web.v1_0; + +import org.openmrs.api.APIException; +import org.openmrs.util.LocaleUtility; + +import java.util.Locale; + +public class LocaleResolver { + + public static Locale identifyLocale(String locale) { + if (locale != null && !locale.isEmpty()) { + Locale searchLocale = LocaleUtility.fromSpecification(locale); + if (searchLocale.getLanguage().isEmpty()) { + throw new APIException("Invalid locale: " + locale); + } + return searchLocale; + } else { + return LocaleUtility.getDefaultLocale(); + } + } +} diff --git a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/display/controls/BahmniObservationsController.java b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/display/controls/BahmniObservationsController.java index 0af0d3237..b3ac3f141 100644 --- a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/display/controls/BahmniObservationsController.java +++ b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/controller/display/controls/BahmniObservationsController.java @@ -6,6 +6,7 @@ import org.bahmni.module.bahmnicore.obs.ObservationsAdder; import org.bahmni.module.bahmnicore.service.BahmniObsService; import org.bahmni.module.bahmnicore.util.MiscUtils; +import org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver; import org.openmrs.Concept; import org.openmrs.ConceptSearchResult; import org.openmrs.Visit; @@ -35,6 +36,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver.identifyLocale; + @Controller @RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/bahmnicore/observations") public class BahmniObservationsController extends BaseRestController { @@ -92,18 +95,6 @@ private List searchConceptsByName(List conceptNames, Locale sea return new ArrayList<>(conceptSet); } - private Locale identifyLocale(String locale) { - if (locale != null && !locale.isEmpty()) { - Locale searchLocale = LocaleUtility.fromSpecification(locale); - if (searchLocale.getLanguage().isEmpty()) { - throw new APIException("Invalid locale: " + locale); - } - return searchLocale; - } else { - return LocaleUtility.getDefaultLocale(); - } - } - @RequestMapping(method = RequestMethod.GET, params = {"visitUuid"}) @ResponseBody public Collection get(@RequestParam(value = "visitUuid", required = true) String visitUuid, diff --git a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandler.java b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandler.java index f0614a6eb..4100ff7c5 100644 --- a/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandler.java +++ b/bahmnicore-omod/src/main/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandler.java @@ -2,12 +2,14 @@ import org.apache.commons.collections.CollectionUtils; import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService; +import org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver; import org.openmrs.Concept; import org.openmrs.Encounter; import org.openmrs.Obs; import org.openmrs.Patient; import org.openmrs.PatientProgram; import org.openmrs.Visit; +import org.openmrs.api.APIException; import org.openmrs.api.context.Context; import org.openmrs.module.episodes.Episode; import org.openmrs.module.episodes.service.EpisodeService; @@ -20,22 +22,22 @@ import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.InvalidSearchException; import org.openmrs.module.webservices.rest.web.response.ResponseException; +import org.openmrs.util.LocaleUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Locale; import static java.util.Arrays.asList; +import static org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver.identifyLocale; @Component public class VisitFormsSearchHandler implements SearchHandler { @Autowired private EpisodeService episodeService; - private final String ALL_OBSERVATION_TEMPLATES = "All Observation Templates"; private final String QUERY_INFORMATION = "Allows you to search All Observation Templates by patientUuid"; @@ -52,6 +54,7 @@ public PageableResult search(RequestContext context) throws ResponseException { String patientProgramUuid = context.getRequest().getParameter("patientProgramUuid"); int numberOfVisits = Integer.parseInt(context.getRequest().getParameter("numberOfVisits")); String[] conceptNames = context.getRequest().getParameterValues("conceptNames"); + Locale searchLocale = identifyLocale(context.getRequest().getSession().getAttribute("locale").toString()); Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); if (patient == null) { @@ -59,9 +62,14 @@ public PageableResult search(RequestContext context) throws ResponseException { } List conceptNamesList = new ArrayList<>(); if (conceptNames == null) { - conceptNamesList = getConcepts(Context.getConceptService().getConcept(ALL_OBSERVATION_TEMPLATES).getSetMembers()); + List concepts = Context.getConceptService().getConceptsByName(ALL_OBSERVATION_TEMPLATES, Locale.ENGLISH, false); + if(!concepts.isEmpty()){ + for (Concept concept : concepts) { + conceptNamesList = getConcepts(concept.getSetMembers(), searchLocale); + } + } } else { - conceptNamesList = Arrays.asList(conceptNames); + conceptNamesList = asList(conceptNames); } List encounterList; @@ -71,12 +79,12 @@ public PageableResult search(RequestContext context) throws ResponseException { encounterList = getEncountersFor(numberOfVisits, patient); } - List finalObsList = getObservations(patient, conceptNamesList, encounterList); + List finalObsList = getObservations(patient, conceptNamesList, encounterList, searchLocale); return new NeedsPaging(finalObsList, context); } - private List getObservations(Patient patient, List conceptNames, List encounterList) { + private List getObservations(Patient patient, List conceptNames, List encounterList, Locale searchLocale) { List finalObsList = new ArrayList<>(); if (CollectionUtils.isEmpty(encounterList)) { return finalObsList; @@ -86,8 +94,8 @@ private List getObservations(Patient patient, List conceptNames, Li for (Obs obs : initialObsList) { String name = null; - if(obs.getConcept()!= null && obs.getConcept().getFullySpecifiedName(Locale.ENGLISH) != null){ - name = obs.getConcept().getFullySpecifiedName(Locale.ENGLISH).getName(); + if(obs.getConcept()!= null){ + name = getConceptName(obs.getConcept(), searchLocale); } if (conceptNames.contains(name)) { finalObsList.add(obs); @@ -113,18 +121,23 @@ private List getEncountersWithinProgram(String patientProgramUuid) { return encounterList; } - private List getConcepts(List concepts) { + private List getConcepts(List concepts, Locale searchLocale) { List conceptNames = new ArrayList<>(); if (concepts == null) return conceptNames; - for (Concept concept : concepts) { - conceptNames.add(concept.getFullySpecifiedName(Locale.ENGLISH).getName()); + conceptNames.add(getConceptName(concept, searchLocale)); } - return conceptNames; } + private String getConceptName(Concept concept, Locale searchLocale) { + if(concept.getFullySpecifiedName(searchLocale) != null) + return concept.getFullySpecifiedName(searchLocale).getName(); + else + return concept.getFullySpecifiedName(LocaleUtility.getDefaultLocale()).getName(); + } + private List listOfVisitsNeeded(int numberOfVisits, Patient patient) { List visitsByPatient = Context.getVisitService().getVisitsByPatient(patient); int subsetVisits = numberOfVisits; diff --git a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolverTest.java b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolverTest.java new file mode 100644 index 000000000..1cd47ee7b --- /dev/null +++ b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/LocaleResolverTest.java @@ -0,0 +1,38 @@ +package org.bahmni.module.bahmnicore.web.v1_0; + +import static org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver.identifyLocale; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.openmrs.util.LocaleUtility; + +import java.util.Locale; + +public class LocaleResolverTest { + + @Test + public void shouldReturnDefaultLocaleIfNull() { + Locale locale = identifyLocale(null); + assertEquals(LocaleUtility.getDefaultLocale(), locale); + } + + @Test + public void shouldReturnDefaultLocaleIfEmpty() { + Locale locale = identifyLocale(""); + assertEquals(LocaleUtility.getDefaultLocale(), locale); + } + + @Test + public void shouldReturnParsedLocaleIfValid() { + Locale locale = identifyLocale("en_US"); + assertEquals(new Locale("en", "US"), locale); + } + + @Test(expected = AssertionError.class) + public void shouldThrowExceptionIfInvalidLocale() { + identifyLocale("invalid"); + fail("Should have thrown exception"); + } + +} \ No newline at end of file diff --git a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandlerTest.java b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandlerTest.java index 3b5f9d66d..5135e6952 100644 --- a/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandlerTest.java +++ b/bahmnicore-omod/src/test/java/org/bahmni/module/bahmnicore/web/v1_0/search/VisitFormsSearchHandlerTest.java @@ -1,6 +1,7 @@ package org.bahmni.module.bahmnicore.web.v1_0.search; import org.bahmni.module.bahmnicore.service.BahmniProgramWorkflowService; +import org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -27,17 +28,21 @@ import org.openmrs.module.webservices.rest.web.resource.api.SearchConfig; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; import org.openmrs.module.webservices.rest.web.response.InvalidSearchException; +import org.openmrs.util.LocaleUtility; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; +import static org.bahmni.module.bahmnicore.web.v1_0.LocaleResolver.identifyLocale; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -50,8 +55,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; +import static org.powermock.api.mockito.PowerMockito.mockStatic; -@PrepareForTest(Context.class) +@PrepareForTest({Context.class, LocaleUtility.class, LocaleResolver.class}) @RunWith(PowerMockRunner.class) public class VisitFormsSearchHandlerTest { @@ -73,14 +79,18 @@ public class VisitFormsSearchHandlerTest { private BahmniProgramWorkflowService programWorkflowService; @Mock private EpisodeService episodeService; - private Patient patient; private Concept concept; private Obs obs; + private final List concepts = new ArrayList<>(); + private final String conceptNames = null; + @Before public void before() throws Exception { initMocks(this); + mockStatic(LocaleUtility.class); + mockStatic(LocaleResolver.class); setUp(); } @@ -98,10 +108,16 @@ public Obs createObs(Concept concept) { public void setUp() throws Exception { HttpServletRequest req = Mockito.mock(HttpServletRequest.class); + HttpSession session = Mockito.mock(HttpSession.class); + when(context.getLimit()).thenReturn(3); when(context.getRequest()).thenReturn(req); + when(context.getRequest().getSession()).thenReturn(session); when(context.getRequest().getParameter("patient")).thenReturn("patientUuid"); when(context.getRequest().getParameter("numberOfVisits")).thenReturn("10"); + when(context.getRequest().getSession().getAttribute("locale")).thenReturn(Locale.ENGLISH); + when(identifyLocale(any())).thenReturn(Locale.ENGLISH); + when(LocaleUtility.getDefaultLocale()).thenReturn(Locale.ENGLISH); String[] conceptNames = {"Vitals"}; when(context.getRequest().getParameterValues("conceptNames")).thenReturn(conceptNames); @@ -115,6 +131,8 @@ public void setUp() throws Exception { PowerMockito.when(Context.getConceptService()).thenReturn(conceptService); concept = createConcept("Vitals", "en"); + PowerMockito.when(identifyLocale(any())).thenReturn(Locale.ENGLISH); + Visit visit = new Visit(); PowerMockito.when(Context.getVisitService()).thenReturn(visitService); PowerMockito.when(Context.getVisitService().getVisitsByPatient(patient)).thenReturn(Arrays.asList(visit)); @@ -140,12 +158,40 @@ public void shouldSupportVersions1_10To2() { } @Test - public void shouldReturnConceptSpecificObsIfConceptNameIsSpecified() throws Exception { + public void shouldReturnConceptSpecificObsIfConceptNameIsSpecified() { String [] conceptNames = new String[]{"Vitals"}; when(context.getRequest().getParameterValues("conceptNames")).thenReturn(conceptNames); concept = createConcept("Vitals", "en"); - PowerMockito.when(conceptService.getConcept("All Observation Templates")).thenReturn(concept); + PowerMockito.when(obsService.getObservations(any(List.class), any(List.class), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(false))).thenReturn(Arrays.asList(obs)); + NeedsPaging searchResults = (NeedsPaging) visitFormsSearchHandler.search(context); + assertThat(searchResults.getPageOfResults().size(), is(equalTo(1))); + } + + @Test + public void shouldReturnConceptSpecificObsIfConceptNameIsFoundInUserLocale() { + PowerMockito.when(identifyLocale(any())).thenReturn(Locale.FRENCH); + + String [] conceptNames = new String[]{"Vitals_fr"}; + when(context.getRequest().getParameterValues("conceptNames")).thenReturn(conceptNames); + + Concept obsConcept = createConcept("Vitals_fr", "fr"); + Obs obs = createObs(obsConcept); + + PowerMockito.when(obsService.getObservations(any(List.class), any(List.class), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(false))).thenReturn(Arrays.asList(obs)); + NeedsPaging searchResults = (NeedsPaging) visitFormsSearchHandler.search(context); + assertThat(searchResults.getPageOfResults().size(), is(equalTo(1))); + } + + @Test + public void shouldReturnConceptSpecificObsIfConceptNameIsNullInUserLocaleButFoundInDefaultSearch() { + PowerMockito.when(identifyLocale(any())).thenReturn(Locale.FRENCH); + + String [] conceptNames = new String[]{"Vitals"}; + when(context.getRequest().getParameterValues("conceptNames")).thenReturn(conceptNames); + + Concept obsConcept = createConcept("Vitals", "en"); + Obs obs = createObs(obsConcept); PowerMockito.when(obsService.getObservations(any(List.class), any(List.class), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(false))).thenReturn(Arrays.asList(obs)); NeedsPaging searchResults = (NeedsPaging) visitFormsSearchHandler.search(context); @@ -153,7 +199,8 @@ public void shouldReturnConceptSpecificObsIfConceptNameIsSpecified() throws Exce } @Test - public void shouldReturnAllObsIfConceptNameIsNotSpecified() throws Exception { + public void shouldReturnConceptSpecificObsIfConceptNameIsFoundInDefaultLocale() { + PowerMockito.when(identifyLocale(any())).thenReturn(Locale.FRENCH); when(context.getRequest().getParameterValues("conceptNames")).thenReturn(null); @@ -162,7 +209,27 @@ public void shouldReturnAllObsIfConceptNameIsNotSpecified() throws Exception { Concept historyConcept = createConcept("History and Examination", "en"); parentConcept.addSetMember(historyConcept); - PowerMockito.when(conceptService.getConcept("All Observation Templates")).thenReturn(parentConcept); + when(conceptService.getConceptsByName("All Observation Templates", Locale.ENGLISH, false)).thenReturn(Arrays.asList(parentConcept)); + + Concept obsConcept = createConcept("History and Examination", "en"); + Obs obs = createObs(obsConcept); + + PowerMockito.when(obsService.getObservations(any(List.class), any(List.class), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(false))).thenReturn(Arrays.asList(obs)); + NeedsPaging searchResults = (NeedsPaging) visitFormsSearchHandler.search(context); + assertThat(searchResults.getPageOfResults().size(), is(equalTo(1))); + } + + @Test + public void shouldReturnAllObsIfConceptNameIsNotSpecified() { + + when(context.getRequest().getParameterValues("conceptNames")).thenReturn(null); + Concept parentConcept = new Concept(); + parentConcept.addSetMember(concept); + Concept historyConcept = createConcept("History and Examination", "en"); + parentConcept.addSetMember(historyConcept); + + when(conceptService.getConceptsByName("All Observation Templates", Locale.ENGLISH, false)).thenReturn(Arrays.asList(parentConcept)); + Obs obs2 = createObs(historyConcept); PowerMockito.when(obsService.getObservations(any(List.class), any(List.class), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(null), eq(false))).thenReturn(Arrays.asList(obs, obs2)); @@ -171,7 +238,7 @@ public void shouldReturnAllObsIfConceptNameIsNotSpecified() throws Exception { } @Test - public void shouldReturnEmptyObservationsIfAllConceptNamesAreInvalid() throws Exception { + public void shouldReturnEmptyObservationsIfAllConceptNamesAreInvalid() { String[] conceptNames = {null, null}; when(context.getRequest().getParameterValues("conceptNames")).thenReturn(conceptNames); @@ -181,9 +248,7 @@ public void shouldReturnEmptyObservationsIfAllConceptNamesAreInvalid() throws Ex Concept historyConcept = createConcept("History and Examination", "en"); parentConcept.addSetMember(historyConcept); - PowerMockito.when(conceptService.getConcept("All Observation Templates")).thenReturn(parentConcept); PowerMockito.when(Context.getConceptService()).thenReturn(conceptService); - PowerMockito.when(conceptService.getConceptByName(null)).thenReturn(null); Obs obs2 = createObs(historyConcept); @@ -200,9 +265,9 @@ public void shouldThrowExceptionIfThePatienUuidIsNull(){ } @Test - public void shouldGetObservationsWithinThePatientProgramIfThePatientProgramUuidIsPassed() throws Exception { - when(conceptService.getConcept("All Observation Templates")).thenReturn(concept); + public void shouldGetObservationsWithinThePatientProgramIfThePatientProgramUuidIsPassed() { when(context.getRequest().getParameterValues("conceptNames")).thenReturn(null); + when(conceptService.getConceptsByName("conceptNames",Locale.ENGLISH,null)).thenReturn(concepts); String patientProgramUuid = "patient-program-uuid"; when(context.getRequest().getParameter("patientProgramUuid")).thenReturn(patientProgramUuid); when(Context.getService(BahmniProgramWorkflowService.class)).thenReturn(programWorkflowService); @@ -217,7 +282,7 @@ public void shouldGetObservationsWithinThePatientProgramIfThePatientProgramUuidI visitFormsSearchHandler.search(context); - verify(conceptService, times(1)).getConcept("All Observation Templates"); + verify(conceptService, times(1)).getConceptsByName("All Observation Templates",Locale.ENGLISH, false); verify(programWorkflowService, times(1)).getPatientProgramByUuid(patientProgramUuid); verify(episodeService, times(1)).getEpisodeForPatientProgram(patientProgram); verify(visitService, never()).getVisitsByPatient(patient); @@ -226,9 +291,9 @@ public void shouldGetObservationsWithinThePatientProgramIfThePatientProgramUuidI } @Test - public void shouldNotFetchAnyObservationsIfThereIsNoEpisodeForTheProgram() throws Exception { - when(conceptService.getConcept("All Observation Templates")).thenReturn(concept); + public void shouldNotFetchAnyObservationsIfThereIsNoEpisodeForTheProgram() { when(context.getRequest().getParameterValues("conceptNames")).thenReturn(null); + when(conceptService.getConceptsByName("conceptNames",Locale.ENGLISH, null)).thenReturn(concepts); String patientProgramUuid = "patient-program-uuid"; when(context.getRequest().getParameter("patientProgramUuid")).thenReturn(patientProgramUuid); when(Context.getService(BahmniProgramWorkflowService.class)).thenReturn(programWorkflowService); @@ -241,7 +306,7 @@ public void shouldNotFetchAnyObservationsIfThereIsNoEpisodeForTheProgram() throw visitFormsSearchHandler.search(context); - verify(conceptService, times(1)).getConcept("All Observation Templates"); + verify(conceptService, times(1)).getConceptsByName("All Observation Templates", Locale.ENGLISH, false); verify(programWorkflowService, times(1)).getPatientProgramByUuid(patientProgramUuid); verify(episodeService, times(1)).getEpisodeForPatientProgram(patientProgram); verify(visitService, never()).getVisitsByPatient(patient); @@ -250,8 +315,8 @@ public void shouldNotFetchAnyObservationsIfThereIsNoEpisodeForTheProgram() throw } @Test - public void shouldNotFetchAnyObservationsIfThereAreNoEncountersInEpisode() throws Exception { - when(conceptService.getConcept("All Observation Templates")).thenReturn(concept); + public void shouldNotFetchAnyObservationsIfThereAreNoEncountersInEpisode() { + when(conceptService.getConceptsByName(conceptNames, Locale.ENGLISH, null)).thenReturn(concepts); when(context.getRequest().getParameterValues("conceptNames")).thenReturn(null); String patientProgramUuid = "patient-program-uuid"; when(context.getRequest().getParameter("patientProgramUuid")).thenReturn(patientProgramUuid); @@ -266,7 +331,7 @@ public void shouldNotFetchAnyObservationsIfThereAreNoEncountersInEpisode() throw visitFormsSearchHandler.search(context); - verify(conceptService, times(1)).getConcept("All Observation Templates"); + verify(conceptService, times(1)).getConceptsByName("All Observation Templates", Locale.ENGLISH, false); verify(programWorkflowService, times(1)).getPatientProgramByUuid(patientProgramUuid); verify(episodeService, times(1)).getEpisodeForPatientProgram(patientProgram); verify(visitService, never()).getVisitsByPatient(patient);