Search in sources :

Example 31 with Location

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

the class LocationFhirResourceProviderTest method findLocationsByState_shouldReturnMatchingBundleOfLocations.

@Test
public void findLocationsByState_shouldReturnMatchingBundleOfLocations() {
    StringAndListParam stateParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE)));
    when(locationService.searchForLocations(isNull(), isNull(), isNull(), isNull(), argThat(Matchers.is(stateParam)), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(location), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchLocations(null, null, null, null, stateParam, null, null, null, null, null, null, null);
    assertThat(results, notNullValue());
    List<Location> resultList = get(results);
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
    assertThat(resultList.get(0).fhirType(), is(FhirConstants.LOCATION));
    assertThat(resultList.get(0).getAddress().getState(), equalTo(STATE));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) MockIBundleProvider(org.openmrs.module.fhir2.providers.r4.MockIBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 32 with Location

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

the class LocationTranslatorImpl method toFhirResource.

/**
 * @see org.openmrs.module.fhir2.api.translators.LocationTranslator#toFhirResource(org.openmrs.Location)
 */
@Override
public Location toFhirResource(@Nonnull org.openmrs.Location openmrsLocation) {
    if (openmrsLocation == null) {
        return null;
    }
    Location fhirLocation = new Location();
    Location.LocationPositionComponent position = new Location.LocationPositionComponent();
    fhirLocation.setId(openmrsLocation.getUuid());
    fhirLocation.setName(getMetadataTranslation(openmrsLocation));
    fhirLocation.setDescription(openmrsLocation.getDescription());
    fhirLocation.setAddress(locationAddressTranslator.toFhirResource(openmrsLocation));
    double latitude = NumberUtils.toDouble(openmrsLocation.getLatitude(), -1.0d);
    if (latitude >= 0.0d) {
        position.setLatitude(latitude);
    }
    double longitude = NumberUtils.toDouble(openmrsLocation.getLongitude(), -1.0d);
    if (longitude >= 0.0d) {
        position.setLongitude(longitude);
    }
    fhirLocation.setPosition(position);
    if (!openmrsLocation.getRetired()) {
        fhirLocation.setStatus(Location.LocationStatus.ACTIVE);
    }
    if (openmrsLocation.getRetired()) {
        fhirLocation.setStatus(Location.LocationStatus.INACTIVE);
    }
    fhirLocation.setTelecom(getLocationContactDetails(openmrsLocation));
    if (openmrsLocation.getTags() != null) {
        for (LocationTag tag : openmrsLocation.getTags()) {
            fhirLocation.getMeta().addTag(FhirConstants.OPENMRS_FHIR_EXT_LOCATION_TAG, tag.getName(), tag.getDescription());
        }
    }
    if (openmrsLocation.getParentLocation() != null) {
        fhirLocation.setPartOf(createLocationReference(openmrsLocation.getParentLocation()));
    }
    fhirLocation.getMeta().setLastUpdated(openmrsLocation.getDateChanged());
    fhirLocation.addContained(provenanceTranslator.getCreateProvenance(openmrsLocation));
    fhirLocation.addContained(provenanceTranslator.getUpdateProvenance(openmrsLocation));
    return fhirLocation;
}
Also used : LocationTag(org.openmrs.LocationTag) Location(org.hl7.fhir.r4.model.Location)

Example 33 with Location

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

the class LocationTranslatorImpl method toOpenmrsType.

/**
 * @see org.openmrs.module.fhir2.api.translators.LocationTranslator#toOpenmrsType(org.openmrs.Location,
 *      org.hl7.fhir.r4.model.Location)
 */
@Override
public org.openmrs.Location toOpenmrsType(@Nonnull org.openmrs.Location openmrsLocation, @Nonnull Location fhirLocation) {
    notNull(openmrsLocation, "The existing Openmrs location should not be null");
    notNull(fhirLocation, "The Location object should not be null");
    openmrsLocation.setUuid(fhirLocation.getIdElement().getIdPart());
    openmrsLocation.setName(fhirLocation.getName());
    openmrsLocation.setDescription(fhirLocation.getDescription());
    if (fhirLocation.getAddress() != null) {
        openmrsLocation.setCityVillage(fhirLocation.getAddress().getCity());
        openmrsLocation.setStateProvince(fhirLocation.getAddress().getState());
        openmrsLocation.setCountry(fhirLocation.getAddress().getCountry());
        openmrsLocation.setPostalCode(fhirLocation.getAddress().getPostalCode());
    }
    if (fhirLocation.getPosition().hasLatitude()) {
        openmrsLocation.setLatitude(fhirLocation.getPosition().getLatitude().toString());
    }
    if (fhirLocation.getPosition().hasLongitude()) {
        openmrsLocation.setLongitude(fhirLocation.getPosition().getLongitude().toString());
    }
    fhirLocation.getTelecom().stream().map(contactPoint -> (LocationAttribute) telecomTranslator.toOpenmrsType(new LocationAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(openmrsLocation::addAttribute);
    if (fhirLocation.getMeta().hasTag()) {
        for (Coding tag : fhirLocation.getMeta().getTag()) {
            openmrsLocation.addTag(locationTagTranslator.toOpenmrsType(tag));
        }
    }
    openmrsLocation.setParentLocation(getOpenmrsParentLocation(fhirLocation.getPartOf()));
    return openmrsLocation;
}
Also used : Setter(lombok.Setter) LocationTranslator(org.openmrs.module.fhir2.api.translators.LocationTranslator) Autowired(org.springframework.beans.factory.annotation.Autowired) Reference(org.hl7.fhir.r4.model.Reference) NumberUtils(org.apache.commons.lang.math.NumberUtils) LocationAttribute(org.openmrs.LocationAttribute) LocationTagTranslator(org.openmrs.module.fhir2.api.translators.LocationTagTranslator) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) AccessLevel(lombok.AccessLevel) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Nonnull(javax.annotation.Nonnull) FhirUtils.getMetadataTranslation(org.openmrs.module.fhir2.api.util.FhirUtils.getMetadataTranslation) Location(org.hl7.fhir.r4.model.Location) FhirLocationDao(org.openmrs.module.fhir2.api.dao.FhirLocationDao) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) LocationAddressTranslator(org.openmrs.module.fhir2.api.translators.LocationAddressTranslator) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) LocationTag(org.openmrs.LocationTag) Objects(java.util.Objects) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) List(java.util.List) Component(org.springframework.stereotype.Component) Coding(org.hl7.fhir.r4.model.Coding) Validate.notNull(org.apache.commons.lang3.Validate.notNull) Coding(org.hl7.fhir.r4.model.Coding) LocationAttribute(org.openmrs.LocationAttribute)

Example 34 with Location

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

the class LocationFhirResourceProviderWebTest method shouldGetLocationHistoryById.

@Test
public void shouldGetLocationHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.Location();
    location.setId(LOCATION_UUID);
    location.addContained(provenance);
    when(locationService.get(LOCATION_UUID)).thenReturn(location);
    MockHttpServletResponse response = getLocationHistoryByIdRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, Matchers.notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), Matchers.notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) IdType(org.hl7.fhir.r4.model.IdType) Coding(org.hl7.fhir.r4.model.Coding) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 35 with Location

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

the class LocationFhirResourceProviderWebTest method shouldVerifyGetLocationHistoryByIdUri.

@Test
public void shouldVerifyGetLocationHistoryByIdUri() throws Exception {
    org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.Location();
    location.setId(LOCATION_UUID);
    when(locationService.get(LOCATION_UUID)).thenReturn(location);
    MockHttpServletResponse response = getLocationHistoryByIdRequest();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) 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