Search in sources :

Example 21 with Location

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

the class LocationSearchQueryTest method searchForLocations_shouldSortLocationsByNameAsRequested.

@Test
public void searchForLocations_shouldSortLocationsByNameAsRequested() {
    SortSpec sort = new SortSpec();
    sort.setParamName("name");
    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).getName(), lessThanOrEqualTo(resultsList.get(i).getName()));
    }
    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).getName(), greaterThanOrEqualTo(resultsList.get(i).getName()));
    }
}
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 Location

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

the class LocationSearchQueryTest method searchForLocations_shouldAddReverseIncludedEncounterToReturnedResults.

@Test
public void searchForLocations_shouldAddReverseIncludedEncounterToReturnedResults() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(LOCATION_PARENT_UUID));
    HashSet<Include> revIncludes = new HashSet<>();
    revIncludes.add(new Include("Encounter:location"));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.REVERSE_INCLUDE_SEARCH_HANDLER, revIncludes);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = results.getResources(START_INDEX, END_INDEX);
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    Location returnedLocation = (Location) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Encounter.class)), hasProperty("locationFirstRep", hasProperty("location", hasProperty("referenceElement", hasProperty("idPart", equalTo(returnedLocation.getIdElement().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) HashSet(java.util.HashSet) 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 Location

use of org.hl7.fhir.r4.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 24 with Location

use of org.hl7.fhir.r4.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 25 with Location

use of org.hl7.fhir.r4.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)

Aggregations

Test (org.junit.Test)215 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)94 Location (org.hl7.fhir.r4.model.Location)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)71 Location (org.hl7.fhir.dstu3.model.Location)66 InputStream (java.io.InputStream)46 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 Matchers.containsString (org.hamcrest.Matchers.containsString)38 Test (org.junit.jupiter.api.Test)38 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)35 ArrayList (java.util.ArrayList)29 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)29 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)26 Reference (org.hl7.fhir.r4.model.Reference)25 Date (java.util.Date)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)24 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23