Search in sources :

Example 26 with Address

use of com.adobe.target.delivery.v1.model.Address in project openmrs-module-fhir2 by openmrs.

the class PersonAddressTranslatorImplTest method shouldConvertHomeAddressToPreferred.

@Test
public void shouldConvertHomeAddressToPreferred() {
    Address address = new Address();
    address.setUse(Address.AddressUse.HOME);
    assertThat(addressTranslator.toOpenmrsType(address).getPreferred(), is(true));
}
Also used : Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) Test(org.junit.Test)

Example 27 with Address

use of com.adobe.target.delivery.v1.model.Address in project openmrs-module-fhir2 by openmrs.

the class PersonTranslatorImplTest method shouldTranslateFhirAddressToPersonAddress.

@Test
public void shouldTranslateFhirAddressToPersonAddress() {
    PersonAddress personAddress = new PersonAddress();
    personAddress.setUuid(ADDRESS_UUID);
    personAddress.setCityVillage(ADDRESS_CITY);
    org.hl7.fhir.r4.model.Person person = new org.hl7.fhir.r4.model.Person();
    Address address = person.addAddress();
    address.setId(ADDRESS_UUID);
    address.setCity(ADDRESS_CITY);
    when(addressTranslator.toOpenmrsType(address)).thenReturn(personAddress);
    Person result = personTranslator.toOpenmrsType(person);
    assertThat(result, notNullValue());
    assertThat(result.getPersonAddress(), notNullValue());
    assertThat(result.getPersonAddress().getUuid(), equalTo(ADDRESS_UUID));
    assertThat(result.getPersonAddress().getCityVillage(), equalTo(ADDRESS_CITY));
}
Also used : PersonAddress(org.openmrs.PersonAddress) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person) Test(org.junit.Test)

Example 28 with Address

use of com.adobe.target.delivery.v1.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 29 with Address

use of com.adobe.target.delivery.v1.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 30 with Address

use of com.adobe.target.delivery.v1.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)

Aggregations

Address (org.hl7.fhir.r4.model.Address)75 Test (org.junit.Test)35 Address (org.hl7.fhir.dstu3.model.Address)22 PersonAddress (org.openmrs.PersonAddress)21 HumanName (org.hl7.fhir.r4.model.HumanName)20 Patient (org.hl7.fhir.r4.model.Patient)18 ArrayList (java.util.ArrayList)17 Identifier (org.hl7.fhir.r4.model.Identifier)17 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)16 Test (org.junit.jupiter.api.Test)13 Organization (org.hl7.fhir.r4.model.Organization)12 Address (com.amazonaws.services.ec2.model.Address)7 HumanName (org.hl7.fhir.dstu3.model.HumanName)7 PatientCommunicationComponent (org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)5 HashSet (java.util.HashSet)5 Coding (org.hl7.fhir.r4.model.Coding)5 StringType (org.hl7.fhir.r4.model.StringType)5 Before (org.junit.Before)5