use of org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto in project Gravity-SDOH-Exchange-RI by FHIR.
the class PersonalCharacteristicsInfoHolderToDtoConverter method convertEthnicity.
private void convertEthnicity(Observation obs, PersonalCharacteristicDto dto) {
List<CodeableConcept> detailedValues = new ArrayList<>();
obs.getComponent().stream().filter(c -> CharacteristicCode.SYSTEM.equals(c.getCode().getCodingFirstRep().getSystem()) && c.hasValueCodeableConcept()).map(Observation.ObservationComponentComponent::getValueCodeableConcept).forEach(cc -> {
if (DetailedEthnicityCode.CODES.containsKey(cc.getCodingFirstRep().getCode())) {
detailedValues.add(cc);
} else {
Validated.withError(dto, () -> {
EthnicityCode ethnicityCode = EthnicityCode.fromCode(cc.getCodingFirstRep().getCode());
dto.setValue(new CodingDto(ethnicityCode.getCode(), ethnicityCode.getDisplay()));
});
}
});
dto.setDetailedValues(detailedValues.stream().map(v -> {
Coding coding = v.getCodingFirstRep();
return new CodingDto(coding.getCode(), coding.getDisplay());
}).collect(Collectors.toList()));
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto in project Gravity-SDOH-Exchange-RI by FHIR.
the class PersonalCharacteristicsInfoHolderToDtoConverter method convert.
@Override
public PersonalCharacteristicDto convert(T infoHolder) {
Observation obs = infoHolder.getObservation();
PersonalCharacteristicDto dto = new PersonalCharacteristicDto(obs.getIdElement().getIdPart());
List<String> errors = new ArrayList<>();
// Type
Validated.withError(dto, () -> dto.setType(CharacteristicCode.fromCode(obs.getCode().getCodingFirstRep().getCode())));
try {
// Method + detail
CodeableConcept method = obs.getMethod();
Validated.withError(dto, () -> dto.setMethod(CharacteristicMethod.fromCode(method.getCodingFirstRep().getCode())));
dto.setMethodDetail(method.getText());
// Value + detail
if (obs.getValue() instanceof CodeableConcept) {
CodeableConcept value = (CodeableConcept) obs.getValue();
dto.setValue(new CodingDto(value.getCodingFirstRep().getCode(), value.getCodingFirstRep().getDisplay()));
dto.setValueDetail(value.getText());
} else if (obs.hasComponent() && CharacteristicCode.ETHNICITY.equals(dto.getType())) {
convertEthnicity(obs, dto);
} else if (obs.hasComponent() && CharacteristicCode.RACE.equals(dto.getType())) {
convertRace(obs, dto);
}
} catch (FHIRException exc) {
dto.getErrors().add(exc.getMessage());
}
// Description. Will make sense only for the race and ethnicity
dto.setDescription(obs.getComponent().stream().filter(c -> CharacteristicCode.SYSTEM.equals(c.getCode().getCodingFirstRep().getSystem()) && c.hasValueStringType()).map(cc -> cc.getValueStringType().getValue()).findFirst().orElse(null));
// Performer
Practitioner performer = infoHolder.getPerformer();
dto.setPerformer(new ReferenceDto(performer.getIdElement().getIdPart(), performer.getNameFirstRep().getNameAsSingleString()));
// Has Attachment
if (CharacteristicCode.SEX_GENDER.equals(dto.getType()) && obs.hasDerivedFrom()) {
dto.setHasAttachment(true);
}
return dto;
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto in project Gravity-SDOH-Exchange-RI by FHIR.
the class PersonalCharacteristicsInfoHolderToDtoConverter method convertRace.
private void convertRace(Observation obs, PersonalCharacteristicDto dto) {
List<CodeableConcept> detailedValues = new ArrayList<>();
List<CodeableConcept> values = new ArrayList<>();
obs.getComponent().stream().filter(c -> CharacteristicCode.SYSTEM.equals(c.getCode().getCodingFirstRep().getSystem()) && c.hasValueCodeableConcept()).map(Observation.ObservationComponentComponent::getValueCodeableConcept).forEach(cc -> {
if (DetailedRaceCode.CODES.containsKey(cc.getCodingFirstRep().getCode())) {
detailedValues.add(cc);
} else {
Validated.withError(dto, () -> {
RaceCode.fromCode(cc.getCodingFirstRep().getCode());
values.add(cc);
});
}
});
dto.setDetailedValues(detailedValues.stream().map(v -> {
Coding coding = v.getCodingFirstRep();
return new CodingDto(coding.getCode(), coding.getDisplay());
}).collect(Collectors.toList()));
dto.setValues(values.stream().map(v -> {
Coding coding = v.getCodingFirstRep();
return new CodingDto(coding.getCode(), coding.getDisplay());
}).collect(Collectors.toList()));
}
Aggregations