use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonNameNotMatched.
@Test
public void searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonNameNotMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NOT_FOUND_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, stringAndListParam);
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(stringAndListParam, null, 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.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenPersonCountryNotMatched.
@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenPersonCountryNotMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NOT_ADDRESS_FIELD)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, stringAndListParam);
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, null, null, null, null, null, stringAndListParam, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonStateNotMatched.
@Test
public void searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonStateNotMatched() {
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, translator, globalPropertyService, searchQueryInclude));
IBundleProvider results = relatedPersonService.searchForRelatedPeople(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.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForPeople_shouldAddRelatedResourcesWhenIncluded.
@Test
public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("RelatedPerson:patient"));
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.singleton(new Patient()));
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(2));
assertThat(resultList, hasItem(is(instanceOf(Patient.class))));
}
use of org.openmrs.module.fhir2.api.search.SearchQueryBundleProvider in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenLastUpdatedNotMatched.
@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenLastUpdatedNotMatched() {
DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(WRONG_LAST_UPDATED_DATE).setLowerBound(WRONG_LAST_UPDATED_DATE);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
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, null, null, null, null, null, null, null, lastUpdated, null, null);
assertThat(results, notNullValue());
assertThat(get(results), empty());
}
Aggregations