use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude.
@Test
public void searchForPeople_shouldNotAddRelatedResourcesForEmptyInclude() {
HashSet<Include> includes = new HashSet<>();
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(person));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PERSON_UUID));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson);
IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, null, null, null, includes);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList.size(), equalTo(1));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenPersonStateNotMatched.
@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenPersonStateNotMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NOT_ADDRESS_FIELD)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, stringAndListParam);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude));
IBundleProvider results = personService.searchForPeople(null, null, null, null, stringAndListParam, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldReturnEmptyCollectionByWrongUUID.
@Test
public void shouldReturnEmptyCollectionByWrongUUID() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(WRONG_UUID));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, null, null, null, null, uuid, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldSearchForPractitionersByAddressCity.
@Test
public void shouldSearchForPractitionersByAddressCity() {
StringAndListParam city = new StringAndListParam().addAnd(new StringParam(CITY));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, city);
when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
when(practitionerDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(provider));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner);
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, null, city, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldReturnEmptyCollectionByWrongGivenName.
@Test
public void shouldReturnEmptyCollectionByWrongGivenName() {
StringAndListParam givenName = new StringAndListParam().addAnd(new StringParam(WRONG_GIVEN_NAME));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.GIVEN_PROPERTY, givenName);
when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = practitionerService.searchForPractitioners(null, null, givenName, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
Aggregations