Search in sources :

Example 71 with Location

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

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

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

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

Example 75 with Location

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

the class LocationFhirResourceProviderWebTest method getLocationById_shouldReturnLocationWithMatchingUuid.

@Test
public void getLocationById_shouldReturnLocationWithMatchingUuid() 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 = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    Location resource = readResponse(response);
    assertThat(resource.getIdElement().getIdPart(), equalTo(LOCATION_UUID));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) 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