Search in sources :

Example 1 with PersonTranslator

use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirPersonServiceImplTest 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, personTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, null, lastUpdated, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 2 with PersonTranslator

use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirPersonServiceImplTest 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, personTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, stringAndListParam, 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 3 with PersonTranslator

use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenUUIDNotMatched.

@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenUUIDNotMatched() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(WRONG_PERSON_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, uuid, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), empty());
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 4 with PersonTranslator

use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenPersonCityNotMatched.

@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenPersonCityNotMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NOT_ADDRESS_FIELD)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude));
    IBundleProvider results = personService.searchForPeople(null, null, null, stringAndListParam, 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) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 5 with PersonTranslator

use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.

the class FhirPersonServiceImplTest method searchForPeople_shouldReturnCollectionOfPeopleWhenUUIDMatched.

@Test
public void searchForPeople_shouldReturnCollectionOfPeopleWhenUUIDMatched() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid);
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(person));
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(PERSON_UUID));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, personTranslator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson);
    IBundleProvider results = personService.searchForPeople(null, null, null, null, null, null, null, uuid, null, null, null);
    assertThat(results, notNullValue());
    assertThat(get(results), not(empty()));
    assertThat(results.size(), greaterThanOrEqualTo(1));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)21 Test (org.junit.Test)21 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)21 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)17 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)11 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)11 StringParam (ca.uhn.fhir.rest.param.StringParam)11 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)4 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)4 Include (ca.uhn.fhir.model.api.Include)2 TokenOrListParam (ca.uhn.fhir.rest.param.TokenOrListParam)2 TokenParam (ca.uhn.fhir.rest.param.TokenParam)2 HashSet (java.util.HashSet)2 SearchQueryInclude (org.openmrs.module.fhir2.api.search.SearchQueryInclude)2 Date (java.util.Date)1 Patient (org.hl7.fhir.r4.model.Patient)1