Search in sources :

Example 26 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project openmrs-module-fhir2 by openmrs.

the class TelecomTranslatorImplTest method shouldTranslateWithCorrectProviderAttributeTypeForContactDetails.

@Test
public void shouldTranslateWithCorrectProviderAttributeTypeForContactDetails() {
    ContactPoint contactPoint = new ContactPoint();
    contactPoint.setId(CONTACT_POINT_ID);
    contactPoint.setValue(CONTACT_POINT_VALUE);
    ProviderAttributeType attributeType = new ProviderAttributeType();
    attributeType.setName(PROVIDER_ATTRIBUTE_TYPE_NAME);
    attributeType.setUuid(PROVIDER_ATTRIBUTE_TYPE_UUID);
    when(globalPropertyService.getGlobalProperty(FhirConstants.PROVIDER_CONTACT_POINT_ATTRIBUTE_TYPE)).thenReturn(PROVIDER_ATTRIBUTE_TYPE_UUID);
    when(providerService.getProviderAttributeTypeByUuid(PROVIDER_ATTRIBUTE_TYPE_UUID)).thenReturn(attributeType);
    ProviderAttribute result = (ProviderAttribute) telecomTranslator.toOpenmrsType(new ProviderAttribute(), contactPoint);
    assertThat(result, notNullValue());
    assertThat(result.getAttributeType().getUuid(), equalTo(PROVIDER_ATTRIBUTE_TYPE_UUID));
}
Also used : ContactPoint(org.hl7.fhir.r4.model.ContactPoint) ProviderAttribute(org.openmrs.ProviderAttribute) ProviderAttributeType(org.openmrs.ProviderAttributeType) Test(org.junit.Test)

Example 27 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project openmrs-module-fhir2 by openmrs.

the class TelecomTranslatorImplTest method shouldTranslateProviderAttributeUuidToFhirContactPointId.

@Test
public void shouldTranslateProviderAttributeUuidToFhirContactPointId() {
    ProviderAttribute providerAttribute = new ProviderAttribute();
    providerAttribute.setUuid(PROVIDER_ATTRIBUTE_UUID);
    providerAttribute.setValue(PROVIDER_ATTRIBUTE_VALUE);
    ContactPoint contactPoint = telecomTranslator.toFhirResource(providerAttribute);
    assertThat(contactPoint, notNullValue());
    assertThat(contactPoint.getId(), equalTo(PROVIDER_ATTRIBUTE_UUID));
}
Also used : ContactPoint(org.hl7.fhir.r4.model.ContactPoint) ProviderAttribute(org.openmrs.ProviderAttribute) Test(org.junit.Test)

Example 28 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint 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 29 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project openmrs-module-fhir2 by openmrs.

the class PersonTranslatorImpl method toOpenmrsType.

@Override
public Person toOpenmrsType(@Nonnull Person openmrsPerson, @Nonnull org.hl7.fhir.r4.model.Person person) {
    notNull(openmrsPerson, "The existing Openmrs Person object should not be null");
    notNull(person, "The Person object should not be null");
    openmrsPerson.setUuid(person.getId());
    for (HumanName name : person.getName()) {
        openmrsPerson.addName(nameTranslator.toOpenmrsType(name));
    }
    if (person.hasGender()) {
        openmrsPerson.setGender(genderTranslator.toOpenmrsType(person.getGender()));
    }
    if (person.hasBirthDateElement()) {
        birthDateTranslator.toOpenmrsType(openmrsPerson, person.getBirthDateElement());
    }
    for (Address address : person.getAddress()) {
        openmrsPerson.addAddress(addressTranslator.toOpenmrsType(address));
    }
    person.getTelecom().stream().map(contactPoint -> (PersonAttribute) telecomTranslator.toOpenmrsType(new PersonAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(openmrsPerson::addAttribute);
    return openmrsPerson;
}
Also used : Person(org.openmrs.Person) Setter(lombok.Setter) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) PersonAttribute(org.openmrs.PersonAttribute) BirthDateTranslator(org.openmrs.module.fhir2.api.translators.BirthDateTranslator) Autowired(org.springframework.beans.factory.annotation.Autowired) PersonNameTranslator(org.openmrs.module.fhir2.api.translators.PersonNameTranslator) Objects(java.util.Objects) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) Address(org.hl7.fhir.r4.model.Address) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) FhirPatientDao(org.openmrs.module.fhir2.api.dao.FhirPatientDao) Component(org.springframework.stereotype.Component) AccessLevel(lombok.AccessLevel) GenderTranslator(org.openmrs.module.fhir2.api.translators.GenderTranslator) HumanName(org.hl7.fhir.r4.model.HumanName) PatientReferenceTranslator(org.openmrs.module.fhir2.api.translators.PatientReferenceTranslator) Validate.notNull(org.apache.commons.lang3.Validate.notNull) Nonnull(javax.annotation.Nonnull) PersonAddressTranslator(org.openmrs.module.fhir2.api.translators.PersonAddressTranslator) PersonTranslator(org.openmrs.module.fhir2.api.translators.PersonTranslator) PersonAddress(org.openmrs.PersonAddress) PersonName(org.openmrs.PersonName) HumanName(org.hl7.fhir.r4.model.HumanName) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) PersonAttribute(org.openmrs.PersonAttribute)

Example 30 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project openmrs-module-fhir2 by openmrs.

the class PractitionerTranslatorProviderImpl method toOpenmrsType.

@Override
public Provider toOpenmrsType(@Nonnull Provider existingProvider, @Nonnull Practitioner practitioner) {
    if (existingProvider == null) {
        return null;
    }
    if (practitioner == null) {
        return null;
    }
    existingProvider.setUuid(practitioner.getId());
    existingProvider.setIdentifier(practitioner.getIdentifierFirstRep().getValue());
    if (existingProvider.getPerson() == null) {
        existingProvider.setPerson(new Person());
    }
    if (practitioner.hasBirthDateElement()) {
        birthDateTranslator.toOpenmrsType(existingProvider.getPerson(), practitioner.getBirthDateElement());
    }
    for (HumanName name : practitioner.getName()) {
        existingProvider.getPerson().addName(nameTranslator.toOpenmrsType(name));
    }
    if (practitioner.hasGender()) {
        existingProvider.getPerson().setGender(genderTranslator.toOpenmrsType(practitioner.getGender()));
    }
    for (Address address : practitioner.getAddress()) {
        existingProvider.getPerson().addAddress(addressTranslator.toOpenmrsType(address));
    }
    practitioner.getTelecom().stream().map(contactPoint -> (ProviderAttribute) telecomTranslator.toOpenmrsType(new ProviderAttribute(), contactPoint)).filter(Objects::nonNull).forEach(existingProvider::addAttribute);
    return existingProvider;
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) ProviderAttribute(org.openmrs.ProviderAttribute) Person(org.openmrs.Person)

Aggregations

ContactPoint (org.hl7.fhir.r4.model.ContactPoint)56 Test (org.junit.Test)28 Address (org.hl7.fhir.r4.model.Address)18 Identifier (org.hl7.fhir.r4.model.Identifier)17 HumanName (org.hl7.fhir.r4.model.HumanName)16 PersonAttribute (org.openmrs.PersonAttribute)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)14 Test (org.junit.jupiter.api.Test)14 ArrayList (java.util.ArrayList)12 Organization (org.hl7.fhir.r4.model.Organization)12 ProviderAttribute (org.openmrs.ProviderAttribute)11 HashSet (java.util.HashSet)10 IdType (org.hl7.fhir.dstu3.model.IdType)9 Patient (org.hl7.fhir.r4.model.Patient)9 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)7 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)6 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)6 HashMap (java.util.HashMap)5 Base64 (org.apache.commons.codec.binary.Base64)5