use of org.hl7.fhir.dstu3.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class RelatedPersonSearchQueryTest method shouldAddRelatedPatientsToResultListWhenIncluded.
@Test
public void shouldAddRelatedPatientsToResultListWhenIncluded() {
TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(RELATIONSHIP_WITH_PATIENT_UUID));
HashSet<Include> includes = new HashSet<>();
includes.add(new Include("RelatedPerson:patient"));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
IBundleProvider results = search(theParams);
assertThat(results, notNullValue());
assertThat(results.size(), equalTo(1));
List<IBaseResource> resultList = results.getResources(0, 10);
assertThat(resultList, not(empty()));
// included resource added as part of result list
assertThat(resultList.size(), equalTo(2));
assertThat(((RelatedPerson) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(RELATIONSHIP_WITH_PATIENT_UUID));
RelatedPerson returnedRelatedPerson = (RelatedPerson) resultList.iterator().next();
assertThat(resultList, hasItem(allOf(is(instanceOf(Patient.class)), hasProperty("id", equalTo(returnedRelatedPerson.getPatient().getReferenceElement().getIdPart())))));
}
use of org.hl7.fhir.dstu3.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelationsForPartialMatchOnPersonName.
@Test
public void shouldReturnCollectionOfRelationsForPartialMatchOnPersonName() {
StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(PARTIAL_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, name);
IBundleProvider relations = search(theParams);
assertThat(relations, notNullValue());
assertThat(relations.size(), greaterThanOrEqualTo(1));
List<RelatedPerson> relationList = get(relations);
assertThat(relationList, hasSize(greaterThanOrEqualTo(1)));
assertThat(relationList.get(0).getNameFirstRep().getNameAsSingleString(), containsString(NAME));
}
use of org.hl7.fhir.dstu3.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelatedPeopleSortedByBirthDate.
@Test
public void shouldReturnCollectionOfRelatedPeopleSortedByBirthDate() {
SortSpec sort = new SortSpec();
sort.setParamName(RelatedPerson.SP_BIRTHDATE);
sort.setOrder(SortOrderEnum.ASC);
List<RelatedPerson> relationshipList = getRelationListForSorting(sort);
for (int i = 1; i < relationshipList.size(); i++) {
assertThat(relationshipList.get(i - 1).getBirthDate(), sameOrBefore(relationshipList.get(i).getBirthDate()));
}
sort.setOrder(SortOrderEnum.DESC);
relationshipList = getRelationListForSorting(sort);
for (int i = 1; i < relationshipList.size(); i++) {
assertThat(relationshipList.get(i - 1).getBirthDate(), sameOrAfter(relationshipList.get(i).getBirthDate()));
}
}
use of org.hl7.fhir.dstu3.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class RelatedPersonSearchQueryTest method shouldHandleComplexQuery.
@Test
public void shouldHandleComplexQuery() {
StringAndListParam nameParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(NAME)));
TokenAndListParam genderParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(MALE_GENDER));
DateRangeParam birthDateParam = new DateRangeParam().setLowerBound(BIRTH_DATE).setUpperBound(BIRTH_DATE);
StringAndListParam cityParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY)));
StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE)));
StringAndListParam postalCodeParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE)));
StringAndListParam countryParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(COUNTRY)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, nameParam).addParameter(FhirConstants.GENDER_SEARCH_HANDLER, genderParam).addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, birthDateParam).addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, cityParam).addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, stateParam).addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, postalCodeParam).addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, countryParam);
IBundleProvider relationships = search(theParams);
List<RelatedPerson> relationList = get(relationships);
assertThat(relationships, notNullValue());
assertThat(relationList, not(empty()));
assertThat(relationList, hasSize(greaterThanOrEqualTo(1)));
assertThat(relationList.get(0).getNameFirstRep().getNameAsSingleString(), containsString(NAME));
assertThat(relationList, everyItem(hasProperty("gender", equalTo(Enumerations.AdministrativeGender.MALE))));
assertThat(relationList.get(0).getBirthDate().toString(), startsWith(BIRTH_DATE));
assertThat(relationList.get(0).getAddressFirstRep().getCity(), equalTo(CITY));
assertThat(relationList.get(0).getAddressFirstRep().getState(), equalTo(STATE));
assertThat(relationList.get(0).getAddressFirstRep().getPostalCode(), equalTo(POSTAL_CODE));
assertThat(relationList.get(0).getAddressFirstRep().getCountry(), equalTo(COUNTRY));
}
use of org.hl7.fhir.dstu3.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.
the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelatedPeopleForMatchOnCity.
@Test
public void shouldReturnCollectionOfRelatedPeopleForMatchOnCity() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, stringAndListParam);
IBundleProvider relationships = search(theParams);
assertThat(relationships, notNullValue());
assertThat(relationships.size(), equalTo(1));
List<RelatedPerson> relationList = get(relationships);
assertThat(relationList, hasSize(equalTo(1)));
assertThat(relationList.get(0).getAddressFirstRep().getCity(), equalTo(CITY));
}
Aggregations