Search in sources :

Example 91 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelationsForMatchOnName.

@Test
public void shouldReturnCollectionOfRelationsForMatchOnName() {
    StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(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 92 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonSearchQueryTest method shouldReturnEmptyListByMismatchingUuidAndLastUpdated.

@Test
public void shouldReturnEmptyListByMismatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(RELATIONSHIP_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_VOIDED).setLowerBound(DATE_VOIDED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(0));
    List<RelatedPerson> resultList = get(results);
    assertThat(resultList, empty());
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) 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 93 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonSearchQueryTest method getRelationListForSorting.

private List<RelatedPerson> getRelationListForSorting(SortSpec sort) {
    SearchParameterMap theParams = new SearchParameterMap().setSortSpec(sort);
    IBundleProvider relationships = search(theParams);
    assertThat(relationships, notNullValue());
    List<RelatedPerson> relationList = get(relationships);
    assertThat(relationList, hasSize(greaterThan(1)));
    // Remove related persons with sort parameter value null, to allow comparison while asserting.
    switch(sort.getParamName()) {
        case RelatedPerson.SP_NAME:
            relationList.removeIf(p -> p.getNameFirstRep() == null);
            break;
        case RelatedPerson.SP_BIRTHDATE:
            relationList.removeIf(p -> p.getBirthDate() == null);
            break;
        case RelatedPerson.SP_ADDRESS_CITY:
            relationList.removeIf(p -> p.getAddressFirstRep() == null || p.getAddressFirstRep().getCity() == null);
            break;
        case RelatedPerson.SP_ADDRESS_STATE:
            relationList.removeIf(p -> p.getAddressFirstRep() == null || p.getAddressFirstRep().getState() == null);
            break;
        case RelatedPerson.SP_ADDRESS_POSTALCODE:
            relationList.removeIf(p -> p.getAddressFirstRep() == null || p.getAddressFirstRep().getPostalCode() == null);
            break;
        case RelatedPerson.SP_ADDRESS_COUNTRY:
            relationList.removeIf(p -> p.getAddressFirstRep() == null || p.getAddressFirstRep().getCountry() == null);
            break;
    }
    assertThat(relationList, hasSize(greaterThan(1)));
    return relationList;
}
Also used : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap)

Example 94 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelatedPeopleSortedByCountry.

@Test
public void shouldReturnCollectionOfRelatedPeopleSortedByCountry() {
    SortSpec sort = new SortSpec();
    sort.setParamName(RelatedPerson.SP_ADDRESS_COUNTRY);
    sort.setOrder(SortOrderEnum.ASC);
    List<RelatedPerson> relationshipList = getRelationListForSorting(sort);
    for (int i = 1; i < relationshipList.size(); i++) {
        assertThat(relationshipList.get(i - 1).getAddressFirstRep().getCountry(), lessThanOrEqualTo(relationshipList.get(i).getAddressFirstRep().getCountry()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    relationshipList = getRelationListForSorting(sort);
    for (int i = 1; i < relationshipList.size(); i++) {
        assertThat(relationshipList.get(i - 1).getAddressFirstRep().getCountry(), greaterThanOrEqualTo(relationshipList.get(i).getAddressFirstRep().getCountry()));
    }
}
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 95 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelatedPeopleSortedByCity.

@Test
public void shouldReturnCollectionOfRelatedPeopleSortedByCity() {
    SortSpec sort = new SortSpec();
    sort.setParamName(RelatedPerson.SP_ADDRESS_CITY);
    sort.setOrder(SortOrderEnum.ASC);
    List<RelatedPerson> relationshipList = getRelationListForSorting(sort);
    for (int i = 1; i < relationshipList.size(); i++) {
        assertThat(relationshipList.get(i - 1).getAddressFirstRep().getCity(), lessThanOrEqualTo(relationshipList.get(i).getAddressFirstRep().getCity()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    relationshipList = getRelationListForSorting(sort);
    for (int i = 1; i < relationshipList.size(); i++) {
        assertThat(relationshipList.get(i - 1).getAddressFirstRep().getCity(), greaterThanOrEqualTo(relationshipList.get(i).getAddressFirstRep().getCity()));
    }
}
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)

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