Search in sources :

Example 41 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PersonTranslatorImplTest method shouldTranslateOpenmrsAddressToFhirAddress.

@Test
public void shouldTranslateOpenmrsAddressToFhirAddress() {
    Address address = new Address();
    address.setId(ADDRESS_UUID);
    address.setCity(ADDRESS_CITY);
    when(addressTranslator.toFhirResource(argThat(allOf(hasProperty("uuid", equalTo(ADDRESS_UUID)), hasProperty("cityVillage", equalTo(ADDRESS_CITY)))))).thenReturn(address);
    Person person = new Person();
    PersonAddress personAddress = new PersonAddress();
    personAddress.setUuid(ADDRESS_UUID);
    personAddress.setCityVillage(ADDRESS_CITY);
    person.addAddress(personAddress);
    org.hl7.fhir.r4.model.Person result = personTranslator.toFhirResource(person);
    assertThat(result.getAddress(), notNullValue());
    assertThat(result.getAddress(), not(empty()));
    assertThat(result.getAddress().get(0), equalTo(address));
}
Also used : Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person) Test(org.junit.Test)

Example 42 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class LocationAddressTranslatorImpl method toFhirResource.

@Override
public Address toFhirResource(@Nonnull Location omrsLocation) {
    Address address = null;
    if (omrsLocation != null) {
        address = new Address();
        address.setId(null);
        address.setCity(omrsLocation.getCityVillage());
        address.setState(omrsLocation.getStateProvince());
        address.setCountry(omrsLocation.getCountry());
        address.setPostalCode(omrsLocation.getPostalCode());
        addAddressExtensions(address, omrsLocation);
    }
    return address;
}
Also used : Address(org.hl7.fhir.r4.model.Address)

Example 43 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PatientTranslatorImpl method toFhirResource.

@Override
public Patient toFhirResource(@Nonnull org.openmrs.Patient openmrsPatient) {
    notNull(openmrsPatient, "The Openmrs Patient object should not be null");
    Patient patient = new Patient();
    patient.setId(openmrsPatient.getUuid());
    patient.setActive(!openmrsPatient.getVoided());
    for (PatientIdentifier identifier : openmrsPatient.getActiveIdentifiers()) {
        patient.addIdentifier(identifierTranslator.toFhirResource(identifier));
    }
    for (PersonName name : openmrsPatient.getNames()) {
        patient.addName(nameTranslator.toFhirResource(name));
    }
    if (openmrsPatient.getGender() != null) {
        patient.setGender(genderTranslator.toFhirResource(openmrsPatient.getGender()));
    }
    patient.setBirthDateElement(birthDateTranslator.toFhirResource(openmrsPatient));
    if (openmrsPatient.getDead()) {
        if (openmrsPatient.getDeathDate() != null) {
            patient.setDeceased(new DateTimeType(openmrsPatient.getDeathDate()));
        } else {
            patient.setDeceased(new BooleanType(true));
        }
    } else {
        patient.setDeceased(new BooleanType(false));
    }
    for (PersonAddress address : openmrsPatient.getAddresses()) {
        patient.addAddress(addressTranslator.toFhirResource(address));
    }
    patient.setTelecom(getPatientContactDetails(openmrsPatient));
    patient.getMeta().setLastUpdated(openmrsPatient.getDateChanged());
    patient.addContained(provenanceTranslator.getCreateProvenance(openmrsPatient));
    patient.addContained(provenanceTranslator.getUpdateProvenance(openmrsPatient));
    return patient;
}
Also used : PersonName(org.openmrs.PersonName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) PersonAddress(org.openmrs.PersonAddress) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 44 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PatientTranslatorImpl method toOpenmrsType.

@Override
public org.openmrs.Patient toOpenmrsType(@Nonnull org.openmrs.Patient currentPatient, @Nonnull Patient patient) {
    notNull(currentPatient, "The existing Openmrs Patient object should not be null");
    notNull(patient, "The Patient object should not be null");
    currentPatient.setUuid(patient.getId());
    for (Identifier identifier : patient.getIdentifier()) {
        PatientIdentifier omrsIdentifier = identifierTranslator.toOpenmrsType(identifier);
        if (omrsIdentifier != null) {
            currentPatient.addIdentifier(omrsIdentifier);
        }
    }
    for (HumanName name : patient.getName()) {
        currentPatient.addName(nameTranslator.toOpenmrsType(name));
    }
    if (patient.hasGender()) {
        currentPatient.setGender(genderTranslator.toOpenmrsType(patient.getGender()));
    }
    if (patient.hasBirthDateElement()) {
        birthDateTranslator.toOpenmrsType(currentPatient, patient.getBirthDateElement());
    }
    if (patient.hasDeceased()) {
        try {
            patient.getDeceasedBooleanType();
            currentPatient.setDead(patient.getDeceasedBooleanType().booleanValue());
        } catch (FHIRException ignored) {
        }
        try {
            patient.getDeceasedDateTimeType();
            currentPatient.setDead(true);
            currentPatient.setDeathDate(patient.getDeceasedDateTimeType().getValue());
        } catch (FHIRException ignored) {
        }
    }
    for (Address address : patient.getAddress()) {
        currentPatient.addAddress(addressTranslator.toOpenmrsType(address));
    }
    patient.getTelecom().stream().map(contactPoint -> (PersonAttribute) telecomTranslator.toOpenmrsType(new PersonAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(currentPatient::addAttribute);
    return currentPatient;
}
Also used : FhirPersonDao(org.openmrs.module.fhir2.api.dao.FhirPersonDao) Setter(lombok.Setter) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Autowired(org.springframework.beans.factory.annotation.Autowired) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) Address(org.hl7.fhir.r4.model.Address) AccessLevel(lombok.AccessLevel) HumanName(org.hl7.fhir.r4.model.HumanName) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Nonnull(javax.annotation.Nonnull) PatientIdentifierTranslator(org.openmrs.module.fhir2.api.translators.PatientIdentifierTranslator) PatientTranslator(org.openmrs.module.fhir2.api.translators.PatientTranslator) Patient(org.hl7.fhir.r4.model.Patient) PersonAddress(org.openmrs.PersonAddress) PersonName(org.openmrs.PersonName) PatientIdentifier(org.openmrs.PatientIdentifier) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) PersonAttribute(org.openmrs.PersonAttribute) BirthDateTranslator(org.openmrs.module.fhir2.api.translators.BirthDateTranslator) PersonNameTranslator(org.openmrs.module.fhir2.api.translators.PersonNameTranslator) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Component(org.springframework.stereotype.Component) GenderTranslator(org.openmrs.module.fhir2.api.translators.GenderTranslator) Validate.notNull(org.apache.commons.lang3.Validate.notNull) FHIRException(org.hl7.fhir.exceptions.FHIRException) PersonAddressTranslator(org.openmrs.module.fhir2.api.translators.PersonAddressTranslator) HumanName(org.hl7.fhir.r4.model.HumanName) Identifier(org.hl7.fhir.r4.model.Identifier) PatientIdentifier(org.openmrs.PatientIdentifier) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) FHIRException(org.hl7.fhir.exceptions.FHIRException) PatientIdentifier(org.openmrs.PatientIdentifier) PersonAttribute(org.openmrs.PersonAttribute)

Example 45 with Address

use of org.hl7.fhir.dstu2.model.Address in project openmrs-module-fhir2 by openmrs.

the class PersonAddressTranslatorImpl method toFhirResource.

@Override
public Address toFhirResource(@Nonnull PersonAddress address) {
    if (address == null || address.getVoided()) {
        return null;
    }
    Address fhirAddress = new Address();
    fhirAddress.setId(address.getUuid());
    fhirAddress.setCity(address.getCityVillage());
    fhirAddress.setState(address.getStateProvince());
    fhirAddress.setCountry(address.getCountry());
    fhirAddress.setPostalCode(address.getPostalCode());
    // TODO is this the right mapping?
    if (address.getPreferred() != null) {
        if (address.getPreferred()) {
            fhirAddress.setUse(Address.AddressUse.HOME);
        } else {
            fhirAddress.setUse(Address.AddressUse.OLD);
        }
    }
    addAddressExtensions(fhirAddress, address);
    return fhirAddress;
}
Also used : Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress)

Aggregations

Address (org.hl7.fhir.r4.model.Address)75 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)31 Patient (org.hl7.fhir.r4.model.Patient)30 PersonAddress (org.openmrs.PersonAddress)27 HumanName (org.hl7.fhir.r4.model.HumanName)24 Identifier (org.hl7.fhir.r4.model.Identifier)23 ArrayList (java.util.ArrayList)22 Address (org.hl7.fhir.dstu3.model.Address)22 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)19 Location (org.hl7.fhir.r4.model.Location)13 Organization (org.hl7.fhir.r4.model.Organization)13 InputStream (java.io.InputStream)12 IdType (org.hl7.fhir.dstu3.model.IdType)12 Patient (org.hl7.fhir.dstu3.model.Patient)12 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)12 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)12