Search in sources :

Example 16 with SearchQueryBundleProvider

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

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonPostalCodeNotMatched.

@Test
public void searchForRelatedPeople_shouldReturnEmptyCollectionWhenRelatedPersonPostalCodeNotMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NOT_ADDRESS_FIELD)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_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, stringAndListParam, 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) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 17 with SearchQueryBundleProvider

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

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForPartialMatchOnName.

@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForPartialMatchOnName() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(PERSON_PARTIAL_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)));
}
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) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 18 with SearchQueryBundleProvider

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

the class FhirServiceRequestServiceImplTest 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.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, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), 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) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 19 with SearchQueryBundleProvider

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

the class FhirServiceRequestServiceImplTest method searchForServiceRequest_shouldReturnCollectionOfServiceRequestByOccurrence.

@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByOccurrence() {
    DateRangeParam occurrence = new DateRangeParam().setLowerBound(OCCURRENCE).setUpperBound(OCCURRENCE);
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(DATE_RANGE_SEARCH_HANDLER, occurrence);
    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, null, null, null, occurrence, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
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 20 with SearchQueryBundleProvider

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

the class FhirServiceRequestServiceImplTest method searchForServiceRequest_shouldReturnCollectionOfServiceRequestByUUID.

@Test
public void searchForServiceRequest_shouldReturnCollectionOfServiceRequestByUUID() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(SERVICE_REQUEST_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    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, null, null, null, null, uuid, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, Matchers.notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)184 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)184 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)183 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)46 ArrayList (java.util.ArrayList)41 TokenParam (ca.uhn.fhir.rest.param.TokenParam)40 SimpleBundleProvider (ca.uhn.fhir.rest.server.SimpleBundleProvider)38 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