use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForNameMatched.
@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForNameMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(GIVEN_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)));
}
use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonCityMatched.
@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonCityMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, 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(null, null, null, stringAndListParam, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(equalTo(1)));
}
use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForPeople_shouldAddRelatedResourcesWhenIncluded.
@Test
public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("RelatedPerson:patient"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
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.singleton(new Patient()));
IBundleProvider results = relatedPersonService.searchForRelatedPeople(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.hl7.fhir.r4.model.RelatedPerson 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)));
}
use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method shouldGetRelatedPersonById.
@Test
public void shouldGetRelatedPersonById() {
Relationship relationship = new Relationship();
relationship.setUuid(RELATED_PERSON_UUID);
RelatedPerson relatedPerson = new RelatedPerson();
relatedPerson.setId(RELATED_PERSON_UUID);
when(dao.get(RELATED_PERSON_UUID)).thenReturn(relationship);
when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
RelatedPerson result = relatedPersonService.get(RELATED_PERSON_UUID);
assertThat(result, notNullValue());
assertThat(result.getId(), notNullValue());
assertThat(result.getId(), equalTo(RELATED_PERSON_UUID));
}
Aggregations