Search in sources :

Example 31 with ContactPoint

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

use of org.hl7.fhir.r4b.model.ContactPoint in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientToDtoConverter method convert.

@Override
public PatientDto convert(PatientInfo patientInfo) {
    Patient patient = patientInfo.getPatient();
    PatientDto patientDto = new PatientDto();
    patientDto.setId(patient.getIdElement().getIdPart());
    patientDto.setName(patient.getNameFirstRep().getNameAsSingleString());
    // Get Date of Birth and Age
    if (patient.hasBirthDate()) {
        LocalDate dob = FhirUtil.toLocalDate(patient.getBirthDateElement());
        patientDto.setDob(dob);
        patientDto.setAge(Period.between(dob, LocalDate.now(ZoneOffset.UTC)).getYears());
    }
    // Get gender
    patientDto.setGender(ObjectUtils.defaultIfNull(patient.getGender(), Enumerations.AdministrativeGender.UNKNOWN).getDisplay());
    // Get communication language
    patientDto.setLanguage(patient.getCommunication().stream().filter(Patient.PatientCommunicationComponent::getPreferred).map(c -> c.getLanguage().getCodingFirstRep()).map(c -> c.getDisplay() != null ? c.getDisplay() : c.getCode()).filter(Objects::nonNull).findFirst().orElse(null));
    // Get Address full String. No need to compose it on UI side.
    patientDto.setAddress(patient.getAddress().stream().filter(a -> (patient.getAddress().size() == 1 && a.getUse() == null) || Address.AddressUse.HOME.equals(a.getUse())).map(this::convertAddress).findFirst().orElse(null));
    List<ContactPoint> telecom = patient.getTelecom();
    // Get phone numbers
    patientDto.getPhones().addAll(telecom.stream().filter(t -> ContactPoint.ContactPointSystem.PHONE.equals(t.getSystem())).map(cp -> {
        String display = cp.getUse() == null ? null : cp.getUse().getDisplay();
        return new PhoneDto(display, cp.getValue());
    }).collect(Collectors.toList()));
    // Get email addreses
    patientDto.getEmails().addAll(telecom.stream().filter(t -> ContactPoint.ContactPointSystem.EMAIL.equals(t.getSystem())).map(cp -> {
        String display = cp.getUse() == null ? null : cp.getUse().getDisplay();
        return new EmailDto(display, cp.getValue());
    }).collect(Collectors.toList()));
    if (patientInfo.getEmployment() != null) {
        String employmentStatus = patientInfo.getEmployment().getValueCodeableConcept().getCodingFirstRep().getDisplay();
        patientDto.setEmploymentStatus(employmentStatus);
    }
    if (patientInfo.getEducation() != null) {
        String education = patientInfo.getEducation().getValueCodeableConcept().getCodingFirstRep().getDisplay();
        patientDto.setEducation(education);
    }
    // Get race
    Extension race = patient.getExtensionByUrl(UsCorePatientExtensions.RACE);
    patientDto.setRace(convertExtension(race));
    // Get ethnicity
    Extension ethnicity = patient.getExtensionByUrl(UsCorePatientExtensions.ETHNICITY);
    patientDto.setEthnicity(convertExtension(ethnicity));
    // Get marital status
    Coding ms = patient.getMaritalStatus().getCodingFirstRep();
    patientDto.setMaritalStatus(Optional.ofNullable(ms.getDisplay()).orElse(Optional.ofNullable(ms.getCode()).orElse(null)));
    patientDto.getInsurances().addAll(convertPayors(patientInfo.getPayors()));
    return patientDto;
}
Also used : EmailDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.EmailDto) ArrayList(java.util.ArrayList) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Strings(com.google.common.base.Strings) Address(org.hl7.fhir.r4.model.Address) ObjectUtils(org.apache.commons.lang3.ObjectUtils) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringType(org.hl7.fhir.r4.model.StringType) PatientDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.PatientDto) ZoneOffset(java.time.ZoneOffset) PatientInfo(org.hl7.gravity.refimpl.sdohexchange.info.PatientInfo) Patient(org.hl7.fhir.r4.model.Patient) Converter(org.springframework.core.convert.converter.Converter) Period(java.time.Period) Enumerations(org.hl7.fhir.r4.model.Enumerations) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Organization(org.hl7.fhir.r4.model.Organization) List(java.util.List) UsCorePatientExtensions(org.hl7.gravity.refimpl.sdohexchange.fhir.UsCorePatientExtensions) PhoneDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.PhoneDto) Coding(org.hl7.fhir.r4.model.Coding) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Extension(org.hl7.fhir.r4.model.Extension) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Extension(org.hl7.fhir.r4.model.Extension) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Coding(org.hl7.fhir.r4.model.Coding) Patient(org.hl7.fhir.r4.model.Patient) EmailDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.EmailDto) PhoneDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.PhoneDto) LocalDate(java.time.LocalDate) PatientDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.PatientDto)

Example 33 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project integration-adaptor-111 by nhsconnect.

the class RelatedPersonMapperTest method shouldCreateRelatedPersonWhenPatientHasEcTelecom.

@Test
public void shouldCreateRelatedPersonWhenPatientHasEcTelecom() {
    TEL[] telecomArray = createTelecomArray();
    telecomArray[0].setUse(Collections.singletonList("EC"));
    when(clinicalDocumentDocument.getRecordTargetArray(0)).thenReturn(recordTarget);
    when(recordTarget.getPatientRole()).thenReturn(patientRole);
    when(patientRole.getTelecomArray()).thenReturn(telecomArray);
    when(contactPoint.getValue()).thenReturn(TELECOM_VALUE);
    when(contactPointMapper.mapContactPoint(ArgumentMatchers.any())).thenReturn(contactPoint);
    RelatedPerson relatedPerson = relatedPersonMapper.createEmergencyContactRelatedPerson(clinicalDocumentDocument, encounter);
    assertThat(relatedPerson.hasRelationship()).isTrue();
    assertThat(relatedPerson.getRelationship().getCoding().size()).isEqualTo(1);
    assertThat(relatedPerson.getRelationship().getCodingFirstRep().getCode()).isEqualTo("C");
    assertThat(relatedPerson.getRelationship().getCodingFirstRep().getDisplay()).isEqualTo("Emergency Contact");
    assertThat(relatedPerson.getTelecom().get(0).getValue()).isEqualTo(TELECOM_VALUE);
}
Also used : TEL(uk.nhs.connect.iucds.cda.ucr.TEL) RelatedPerson(org.hl7.fhir.dstu3.model.RelatedPerson) Test(org.junit.jupiter.api.Test)

Example 34 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project integration-adaptor-111 by nhsconnect.

the class OrganizationMapperTest method mockItkOrganization.

private POCDMT000002UK01Organization mockItkOrganization() {
    POCDMT000002UK01Organization itkOrganization = mock(POCDMT000002UK01Organization.class);
    AD itkAddress = mock(AD.class);
    TEL itkTelecom = mock(TEL.class);
    CE codeEntity = mock(CE.class);
    II[] iiArray = new II[] { ii };
    when(itkOrganization.getIdArray()).thenReturn(iiArray);
    when(ii.isSetExtension()).thenReturn(true);
    when(ii.getExtension()).thenReturn(ODS_CODE);
    when(itkOrganization.sizeOfIdArray()).thenReturn(1);
    when(itkOrganization.getAddrArray()).thenReturn(new AD[] { itkAddress });
    when(itkOrganization.getTelecomArray()).thenReturn(new TEL[] { itkTelecom });
    when(itkOrganization.isSetStandardIndustryClassCode()).thenReturn(true);
    when(itkOrganization.getStandardIndustryClassCode()).thenReturn(codeEntity);
    when(codeEntity.getDisplayName()).thenReturn(GP_PRACTICE);
    when(contactPointMapper.mapContactPoint(any())).thenReturn(contactPoint);
    when(addressMapper.mapAddress(any())).thenReturn(address);
    when(nodeUtil.getNodeValueString(itkOrganization.getNameArray(0))).thenReturn(ORGANIZATION_NAME);
    when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
    Organization organization = organizationMapper.mapOrganization(itkOrganization);
    assertThat(organization.getName()).isEqualTo(ORGANIZATION_NAME);
    assertThat(organization.getAddressFirstRep()).isEqualTo(address);
    assertThat(organization.getTelecomFirstRep()).isEqualTo(contactPoint);
    assertThat(organization.getTypeFirstRep().getText()).isEqualTo(GP_PRACTICE);
    assertThat(organization.getIdentifierFirstRep().getValue()).isEqualTo(ODS_CODE);
    assertThat(organization.getIdElement().getValue()).isEqualTo(RANDOM_UUID);
    return itkOrganization;
}
Also used : II(uk.nhs.connect.iucds.cda.ucr.II) CE(uk.nhs.connect.iucds.cda.ucr.CE) AD(uk.nhs.connect.iucds.cda.ucr.AD) Organization(org.hl7.fhir.dstu3.model.Organization) POCDMT000002UK01Organization(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Organization) TEL(uk.nhs.connect.iucds.cda.ucr.TEL) POCDMT000002UK01Organization(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Organization) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 35 with ContactPoint

use of org.hl7.fhir.r4b.model.ContactPoint in project integration-adaptor-111 by nhsconnect.

the class PractitionerMapperTest method shouldMapPractitionerFromAssociatedEntity.

@Test
public void shouldMapPractitionerFromAssociatedEntity() {
    POCDMT000002UK01AssociatedEntity associatedEntity = POCDMT000002UK01AssociatedEntity.Factory.newInstance();
    associatedEntity.setAssociatedPerson(createPerson());
    associatedEntity.setTelecomArray(createTelecomArray());
    associatedEntity.setAddrArray(createAddrArray());
    when(humanNameMapper.mapHumanName(ArgumentMatchers.any())).thenReturn(humanName);
    when(contactPointMapper.mapContactPoint(ArgumentMatchers.any())).thenReturn(contactPoint);
    when(addressMapper.mapAddress(ArgumentMatchers.any())).thenReturn(address);
    when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
    Practitioner practitioner = practitionerMapper.mapPractitioner(associatedEntity);
    assertThat(practitioner.getIdElement().getValue()).isEqualTo(RANDOM_UUID);
    assertThat(practitioner.getActive()).isEqualTo(true);
    assertThat(practitioner.getNameFirstRep()).isEqualTo(humanName);
    assertThat(practitioner.getTelecomFirstRep()).isEqualTo(contactPoint);
    assertThat(practitioner.getAddressFirstRep()).isEqualTo(address);
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) POCDMT000002UK01AssociatedEntity(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01AssociatedEntity) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

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