Search in sources :

Example 26 with RelatedPerson

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())))));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 27 with RelatedPerson

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));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 28 with RelatedPerson

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()));
    }
}
Also used : SortSpec(ca.uhn.fhir.rest.api.SortSpec) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 29 with RelatedPerson

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));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 30 with RelatedPerson

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));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)87 RelatedPerson (org.hl7.fhir.r4.model.RelatedPerson)54 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)51 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)29 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)24 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)24 StringParam (ca.uhn.fhir.rest.param.StringParam)24 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)24 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)20 RelatedPerson (org.hl7.fhir.dstu3.model.RelatedPerson)17 Test (org.junit.jupiter.api.Test)17 Resource (org.hl7.fhir.r4.model.Resource)14 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)13 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)12 Patient (org.hl7.fhir.r4.model.Patient)12 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)11 Identifier (org.hl7.fhir.r4.model.Identifier)10 Reference (org.hl7.fhir.r4.model.Reference)9