Search in sources :

Example 26 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldSearchForUsersByAddressCountry.

@Test
public void shouldSearchForUsersByAddressCountry() {
    StringAndListParam country = new StringAndListParam().addAnd(new StringParam(COUNTRY));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(ADDRESS_SEARCH_HANDLER, COUNTRY_PROPERTY, country);
    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)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 27 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldReturnEmptyCollectionByWrongAddressPostalCode.

@Test
public void shouldReturnEmptyCollectionByWrongAddressPostalCode() {
    StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(WRONG_POSTAL_CODE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, postalCode);
    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());
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 28 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldsearchForUsersByAddressCity.

@Test
public void shouldsearchForUsersByAddressCity() {
    StringAndListParam city = new StringAndListParam().addAnd(new StringParam(CITY));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(ADDRESS_SEARCH_HANDLER, CITY_PROPERTY, city);
    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)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 29 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldReturnEmptyCollectionByWrongLastUpdated.

@Test
public void shouldReturnEmptyCollectionByWrongLastUpdated() {
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(WRONG_LAST_UPDATED_DATE).setLowerBound(WRONG_LAST_UPDATED_DATE);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_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 = userService.searchForUsers(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 30 with SearchQueryInclude

use of org.openmrs.module.fhir2.api.search.SearchQueryInclude in project openmrs-module-fhir2 by openmrs.

the class FhirUserServiceImplTest method shouldsearchForUsersByAddressPostalCode.

@Test
public void shouldsearchForUsersByAddressPostalCode() {
    StringAndListParam postalCode = new StringAndListParam().addAnd(new StringParam(POSTAL_CODE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(ADDRESS_SEARCH_HANDLER, POSTAL_CODE_PROPERTY, postalCode);
    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)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)190 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)187 Test (org.junit.Test)184 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)148 StringParam (ca.uhn.fhir.rest.param.StringParam)72 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)66 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)49 TokenParam (ca.uhn.fhir.rest.param.TokenParam)41 ArrayList (java.util.ArrayList)41 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)39 Include (ca.uhn.fhir.model.api.Include)29 HashSet (java.util.HashSet)29 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)29 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)28 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)27 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)22 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)22 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)22 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)19 Patient (org.openmrs.Patient)12