use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldReturnEmptyCollectionByWrongName.
@Test
public void shouldReturnEmptyCollectionByWrongName() {
StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(WRONG_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, NAME_PROPERTY, name);
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, name, null, null, null, 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 FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonGenderNotMatched.
@Test
public void searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonGenderNotMatched() {
TokenAndListParam tokenAndListParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(WRONG_GENDER));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GENDER_SEARCH_HANDLER, tokenAndListParam);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, tokenAndListParam, null, null, null, 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 FhirRelatedPersonServiceImplTest 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.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = relatedPersonService.searchForRelatedPeople(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 FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForNameMatched.
@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForNameMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = relatedPersonService.searchForRelatedPeople(stringAndListParam, null, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(equalTo(1)));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonCityMatched.
@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonCityMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, stringAndListParam);
when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, null, null, stringAndListParam, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(equalTo(1)));
}
Aggregations