Search in sources :

Example 6 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldSortLocationsByStateAsRequested.

@Test
public void searchForLocations_shouldSortLocationsByStateAsRequested() {
    SortSpec sort = new SortSpec();
    sort.setParamName("address-state");
    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().getState(), lessThanOrEqualTo(resultsList.get(i).getAddress().getState()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    resultsList = 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().getState(), greaterThanOrEqualTo(resultsList.get(i).getAddress().getState()));
    }
}
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 7 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method getLocationListWithoutNulls.

private List<Location> getLocationListWithoutNulls(SortSpec sort) {
    SearchParameterMap theParams = new SearchParameterMap().setSortSpec(sort);
    IBundleProvider locations = search(theParams);
    assertThat(locations, notNullValue());
    List<Location> locationList = get(locations);
    assertThat(locationList, not(empty()));
    assertThat(locationList, hasSize(greaterThan(1)));
    // Remove locations with sort parameter value null, to allow comparison while asserting.
    switch(sort.getParamName()) {
        case "name":
            locationList.removeIf(p -> p.getName() == null);
            break;
        case "address-city":
            locationList.removeIf(p -> p.getAddress().getCity() == null);
            break;
        case "address-state":
            locationList.removeIf(p -> p.getAddress().getState() == null);
            break;
        case "address-postalCode":
            locationList.removeIf(p -> p.getAddress().getPostalCode() == null);
            break;
        case "address-country":
            locationList.removeIf(p -> p.getAddress().getCountry() == null);
            break;
    }
    return locationList;
}
Also used : IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Location(org.hl7.fhir.r4.model.Location)

Example 8 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldReturnCorrectLocationByParentUUID.

@Test
public void searchForLocations_shouldReturnCorrectLocationByParentUUID() {
    ReferenceAndListParam parentLocation = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(LOCATION_PARENT_UUID).setChain(null)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.LOCATION_REFERENCE_SEARCH_HANDLER, parentLocation);
    IBundleProvider locations = search(theParams);
    assertThat(locations, notNullValue());
    assertThat(locations.size(), equalTo(1));
    List<Location> resultList = get(locations);
    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 9 with Location

use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldReturnCorrectLocationByParentPostalCode.

@Test
public void searchForLocations_shouldReturnCorrectLocationByParentPostalCode() {
    ReferenceAndListParam parentLocation = new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam().setValue(LOCATION_PARENT_POSTAL_CODE).setChain("address-postalcode")));
    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 10 with Location

use of com.ibm.watson.compare_comply.v1.model.Location 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)

Aggregations

Test (org.junit.Test)120 Location (org.hl7.fhir.r4.model.Location)93 Location (org.hl7.fhir.dstu3.model.Location)66 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)42 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)30 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)27 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)20 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)20 StringParam (ca.uhn.fhir.rest.param.StringParam)20 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)16 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)16 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)16 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)16 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)13 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)10