Search in sources :

Example 1 with SearchQueryInclude

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

the class FhirPractitionerServiceImplTest method shouldSearchForPractitionersByIdentifier.

@Test
public void shouldSearchForPractitionersByIdentifier() {
    TokenAndListParam identifier = new TokenAndListParam().addAnd(new TokenOrListParam().add(IDENTIFIER));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.IDENTIFIER_SEARCH_HANDLER, identifier);
    when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(practitionerDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(provider));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner);
    when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
    IBundleProvider results = practitionerService.searchForPractitioners(identifier, 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(greaterThanOrEqualTo(1)));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 2 with SearchQueryInclude

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

the class FhirPractitionerServiceImplTest method shouldReturnEmptyCollectionByWrongFamilyName.

@Test
public void shouldReturnEmptyCollectionByWrongFamilyName() {
    StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(WRONG_FAMILY_NAME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.FAMILY_PROPERTY, familyName);
    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, familyName, null, null, null, null, null, null, null);
    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) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 3 with SearchQueryInclude

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

the class FhirPractitionerServiceImplTest method shouldNotAddRelatedResourcesToReturnedResultsForEmptyReverseInclude.

@Test
public void shouldNotAddRelatedResourcesToReturnedResultsForEmptyReverseInclude() {
    HashSet<Include> revIncludes = new HashSet<>();
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
    when(practitionerDao.getSearchResultUuids(any())).thenReturn(singletonList(UUID));
    when(practitionerDao.getSearchResults(any(), any())).thenReturn(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, null, null, null, null, null, null, revIncludes);
    List<IBaseResource> resultList = get(results);
    assertThat(resultList, notNullValue());
    assertThat(resultList, Matchers.not(empty()));
    assertThat(resultList.size(), Matchers.equalTo(1));
}
Also used : SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 4 with SearchQueryInclude

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

the class FhirPractitionerServiceImplTest method shouldSearchForPractitionersByGivenNameWhoIsUserAndProvider.

@Test
public void shouldSearchForPractitionersByGivenNameWhoIsUserAndProvider() {
    StringAndListParam givenName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_GIVEN_NAME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, FhirConstants.GIVEN_PROPERTY, givenName);
    when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(UUID));
    when(practitionerDao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(provider));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(practitionerTranslator.toFhirResource(provider)).thenReturn(practitioner);
    when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2));
    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, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(2)));
}
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) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 5 with SearchQueryInclude

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

the class FhirPractitionerServiceImplTest method shouldSearchForPractitionersByFamilyNameWhoIsUser.

@Test
public void shouldSearchForPractitionersByFamilyNameWhoIsUser() {
    StringAndListParam familyName = new StringAndListParam().addAnd(new StringParam(PRACTITIONER_FAMILY_NAME));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, FAMILY_PROPERTY, familyName);
    when(practitionerDao.getSearchResultUuids(any())).thenReturn(emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
    when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider(practitioner2));
    IBundleProvider results = practitionerService.searchForPractitioners(null, null, null, familyName, null, null, null, null, null, null, null);
    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) SimpleBundleProvider(ca.uhn.fhir.rest.server.SimpleBundleProvider) 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