use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenPersonPostalCodeNotMatched.
@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenPersonPostalCodeNotMatched() {
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, personTranslator, globalPropertyService, searchQueryInclude));
IBundleProvider results = personService.searchForPeople(null, null, null, null, null, stringAndListParam, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldAddRelatedResourcesWhenIncluded.
@Test
public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("Person:patient"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
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.singleton(new Patient()));
when(personTranslator.toFhirResource(person)).thenReturn(fhirPerson);
IBundleProvider results = personService.searchForPeople(null, null, null, 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.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenPersonGenderNotMatched.
@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenPersonGenderNotMatched() {
TokenAndListParam tokenAndListParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(WRONG_GENDER));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GENDER_SEARCH_HANDLER, tokenAndListParam);
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, tokenAndListParam, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldReturnEmptyCollectionWhenPersonBirthDateNotMatched.
@Test
public void searchForPeople_shouldReturnEmptyCollectionWhenPersonBirthDateNotMatched() {
DateRangeParam dateRangeParam = new DateRangeParam().setLowerBound(NOT_FOUND_PERSON_BIRTH_DATE).setUpperBound(NOT_FOUND_PERSON_BIRTH_DATE);
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, dateRangeParam);
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, dateRangeParam, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of org.openmrs.module.fhir2.api.translators.PersonTranslator in project openmrs-module-fhir2 by openmrs.
the class FhirPersonServiceImplTest method searchForPeople_shouldReturnCollectionOfPersonWhenPersonCountryMatched.
@Test
public void searchForPeople_shouldReturnCollectionOfPersonWhenPersonCountryMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(COUNTRY)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, stringAndListParam);
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, stringAndListParam, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Aggregations