Search in sources :

Example 1 with EmailDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.EmailDto 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)

Aggregations

Strings (com.google.common.base.Strings)1 LocalDate (java.time.LocalDate)1 Period (java.time.Period)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 ObjectUtils (org.apache.commons.lang3.ObjectUtils)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Address (org.hl7.fhir.r4.model.Address)1 Coding (org.hl7.fhir.r4.model.Coding)1 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)1 Enumerations (org.hl7.fhir.r4.model.Enumerations)1 Extension (org.hl7.fhir.r4.model.Extension)1 Organization (org.hl7.fhir.r4.model.Organization)1 Patient (org.hl7.fhir.r4.model.Patient)1 RelatedPerson (org.hl7.fhir.r4.model.RelatedPerson)1 StringType (org.hl7.fhir.r4.model.StringType)1