use of org.openmrs.module.fhir2.api.search.param.SearchParameterMap in project openmrs-module-fhir2 by openmrs.
the class FhirServiceRequestServiceImplTest method searchForServiceRequest_shouldReturnCollectionOfServiceRequestByCode.
@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByCode() {
TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam(CODE));
SearchParameterMap theParams = new SearchParameterMap();
theParams.addParameter(CODED_SEARCH_HANDLER, code);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(order));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(SERVICE_REQUEST_UUID));
when(translator.toFhirResource(order)).thenReturn(fhirServiceRequest);
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 = serviceRequestService.searchForServiceRequests(null, code, 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.param.SearchParameterMap in project openmrs-module-fhir2 by openmrs.
the class FhirServiceRequestServiceImplTest method searchForPeople_shouldAddRelatedResourcesWhenIncluded.
@Test
public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("ServiceRequest:patient"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(order));
when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(SERVICE_REQUEST_UUID));
when(translator.toFhirResource(order)).thenReturn(fhirServiceRequest);
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 = serviceRequestService.searchForServiceRequests(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.param.SearchParameterMap in project openmrs-module-fhir2 by openmrs.
the class FhirUserServiceImplTest method shouldsearchForUsersByIdentifier.
@Test
public void shouldsearchForUsersByIdentifier() {
TokenAndListParam identifier = new TokenAndListParam().addAnd(new TokenOrListParam().add(USER_SYSTEM_ID));
SearchParameterMap theParams = new SearchParameterMap().addParameter(IDENTIFIER_SEARCH_HANDLER, identifier);
when(dao.getSearchResultUuids(any())).thenReturn(singletonList(USER_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(singletonList(user));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(translator.toFhirResource(user)).thenReturn(practitioner);
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = userService.searchForUsers(theParams);
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.param.SearchParameterMap in project openmrs-module-fhir2 by openmrs.
the class FhirUserServiceImplTest method shouldReturnEmptyCollectionByWrongAddressCountry.
@Test
public void shouldReturnEmptyCollectionByWrongAddressCountry() {
StringAndListParam country = new StringAndListParam().addAnd(new StringParam(WRONG_COUNTRY));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, country);
when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
IBundleProvider results = userService.searchForUsers(theParams);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.search.param.SearchParameterMap in project openmrs-module-fhir2 by openmrs.
the class FhirUserServiceImplTest method shouldSearchForUsersByName.
@Test
public void shouldSearchForUsersByName() {
StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(USER_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, NAME_PROPERTY, name);
when(dao.getSearchResultUuids(any())).thenReturn(singletonList(USER_UUID));
when(dao.getSearchResults(any(), any())).thenReturn(singletonList(user));
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
when(translator.toFhirResource(user)).thenReturn(practitioner);
when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
IBundleProvider results = userService.searchForUsers(theParams);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Aggregations