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;
}
Aggregations