Search in sources :

Example 1 with Location

use of com.walmartlabs.concord.runtime.v2.model.Location in project openmrs-module-fhir2 by openmrs.

the class FhirLocationServiceImplTest method getLocationByUuid_shouldGetLocationByUuid.

@Test
public void getLocationByUuid_shouldGetLocationByUuid() {
    when(locationDao.get(LOCATION_UUID)).thenReturn(location);
    when(locationTranslator.toFhirResource(location)).thenReturn(fhirLocation);
    org.hl7.fhir.r4.model.Location result = fhirLocationService.get(LOCATION_UUID);
    assertThat(result, notNullValue());
    assertThat(result.getId(), equalTo(LOCATION_UUID));
    assertThat(result.getName(), equalTo(LOCATION_NAME));
    assertThat(result.getDescription(), equalTo(LOCATION_DESCRIPTION));
}
Also used : Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 2 with Location

use of com.walmartlabs.concord.runtime.v2.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldReturnCorrectLocationByCity.

@Test
public void searchForLocations_shouldReturnCorrectLocationByCity() {
    StringAndListParam city = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(LOCATION_CITY)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CITY_SEARCH_HANDLER, city);
    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).getAddress().getCity(), equalTo(LOCATION_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) 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 3 with Location

use of com.walmartlabs.concord.runtime.v2.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationSearchQueryTest method searchForLocations_shouldReturnEmptyCollectionWhenCalledWithUnknownCity.

@Test
public void searchForLocations_shouldReturnEmptyCollectionWhenCalledWithUnknownCity() {
    StringAndListParam city = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(UNKNOWN_LOCATION_CITY)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CITY_SEARCH_HANDLER, city);
    IBundleProvider locations = search(theParams);
    assertThat(locations, notNullValue());
    assertThat(locations.size(), equalTo(0));
    List<Location> resultList = get(locations);
    assertThat(resultList, empty());
}
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) 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 4 with Location

use of com.walmartlabs.concord.runtime.v2.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 5 with Location

use of com.walmartlabs.concord.runtime.v2.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)

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