Search in sources :

Example 21 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldSortLocationsByPostalCodeAsRequested.

@Test
public void searchForLocations_shouldSortLocationsByPostalCodeAsRequested() {
    SortSpec sort = new SortSpec();
    sort.setParamName("address-postalCode");
    sort.setOrder(SortOrderEnum.ASC);
    List<Location> resultsList = getLocationListWithoutNulls(sort);
    // check if the sorting is indeed correct by ascending order
    for (int i = 1; i < resultsList.size(); i++) {
        assertThat(resultsList.get(i - 1).getAddress().getPostalCode(), lessThanOrEqualTo(resultsList.get(i).getAddress().getPostalCode()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    resultsList = new ArrayList<>(getLocationListWithoutNulls(sort));
    // check if the sorting is indeed correct by descending order
    for (int i = 1; i < resultsList.size(); i++) {
        assertThat(resultsList.get(i - 1).getAddress().getPostalCode(), greaterThanOrEqualTo(resultsList.get(i).getAddress().getPostalCode()));
    }
}
Also used : SortSpec(ca.uhn.fhir.rest.api.SortSpec) Location(org.hl7.fhir.r4.model.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 22 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldReturnCorrectLocationByParentCountry.

@Test
public void searchForLocations_shouldReturnCorrectLocationByParentCountry() {
    ReferenceAndListParam parentLocation = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(LOCATION_PARENT_COUNTRY).setChain("address-country")));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.LOCATION_REFERENCE_SEARCH_HANDLER, parentLocation);
    IBundleProvider locations = search(theParams);
    List<Location> resultList = get(locations);
    assertThat(locations, notNullValue());
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(resultList.get(0).getIdElement().getIdPart(), equalTo(LOCATION_UUID));
}
Also used : ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Location(org.hl7.fhir.r4.model.Location) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 23 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PatientSearchQueryTest method shouldReturnCollectionOfPatientsSortedByCity.

@Test
public void shouldReturnCollectionOfPatientsSortedByCity() {
    SortSpec sort = new SortSpec();
    sort.setParamName("address-city");
    sort.setOrder(SortOrderEnum.ASC);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_PROPERTY, new StringAndListParam().addAnd(new StringParam("City"))).setSortSpec(sort);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    List<Patient> resultList = get(results);
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertThat(resultList.get(i - 1).getAddressFirstRep().getCity(), lessThanOrEqualTo(resultList.get(i).getAddressFirstRep().getCity()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    theParams.setSortSpec(sort);
    results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    resultList = get(results);
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertThat(resultList.get(i - 1).getAddressFirstRep().getCity(), greaterThanOrEqualTo(resultList.get(i).getAddressFirstRep().getCity()));
    }
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Patient(org.hl7.fhir.r4.model.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SortSpec(ca.uhn.fhir.rest.api.SortSpec) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 24 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PatientSearchQueryTest method shouldReturnCollectionOfPatientsSortedByCountry.

@Test
public void shouldReturnCollectionOfPatientsSortedByCountry() {
    SortSpec sort = new SortSpec();
    sort.setParamName("address-country");
    sort.setOrder(SortOrderEnum.ASC);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, new StringAndListParam().addAnd(new StringParam("Fake"))).setSortSpec(sort);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    List<Patient> resultList = get(results);
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertThat(resultList.get(i - 1).getAddressFirstRep().getCountry(), lessThanOrEqualTo(resultList.get(i).getAddressFirstRep().getCountry()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    theParams.setSortSpec(sort);
    results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), greaterThan(1));
    resultList = get(results);
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertThat(resultList.get(i - 1).getAddressFirstRep().getCountry(), greaterThanOrEqualTo(resultList.get(i).getAddressFirstRep().getCountry()));
    }
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) Patient(org.hl7.fhir.r4.model.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) SortSpec(ca.uhn.fhir.rest.api.SortSpec) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 25 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class LocationAddressTranslatorImplTest method shouldTranslateLocationPostalCodeToAddressCode.

@Test
public void shouldTranslateLocationPostalCodeToAddressCode() {
    omrsLocation.setPostalCode(POSTAL_CODE);
    org.hl7.fhir.r4.model.Address address = translator.toFhirResource(omrsLocation);
    assertThat(address, notNullValue());
    assertThat(address.getPostalCode(), notNullValue());
    assertThat(address.getPostalCode(), equalTo(POSTAL_CODE));
}
Also used : Address(org.hl7.fhir.r4.model.Address) Test(org.junit.Test)

Aggregations

Address (org.hl7.fhir.r4.model.Address)75 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)31 Patient (org.hl7.fhir.r4.model.Patient)30 PersonAddress (org.openmrs.PersonAddress)27 HumanName (org.hl7.fhir.r4.model.HumanName)24 Identifier (org.hl7.fhir.r4.model.Identifier)23 ArrayList (java.util.ArrayList)22 Address (org.hl7.fhir.dstu3.model.Address)22 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)19 Location (org.hl7.fhir.r4.model.Location)13 Organization (org.hl7.fhir.r4.model.Organization)13 InputStream (java.io.InputStream)12 IdType (org.hl7.fhir.dstu3.model.IdType)12 Patient (org.hl7.fhir.dstu3.model.Patient)12 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12