Search in sources :

Example 1 with PersonalCharacteristicDto

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()));
}
Also used : CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Coding(org.hl7.fhir.r4.model.Coding) ArrayList(java.util.ArrayList) Observation(org.hl7.fhir.r4.model.Observation) EthnicityCode(org.hl7.gravity.refimpl.sdohexchange.codes.EthnicityCode) DetailedEthnicityCode(org.hl7.gravity.refimpl.sdohexchange.codes.DetailedEthnicityCode) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 2 with PersonalCharacteristicDto

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;
}
Also used : CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Converter(org.springframework.core.convert.converter.Converter) EthnicityCode(org.hl7.gravity.refimpl.sdohexchange.codes.EthnicityCode) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) CharacteristicCode(org.hl7.gravity.refimpl.sdohexchange.codes.CharacteristicCode) PersonalCharacteristicsInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.characteristic.PersonalCharacteristicsInfoBundleExtractor.PersonalCharacteristicsInfoHolder) RaceCode(org.hl7.gravity.refimpl.sdohexchange.codes.RaceCode) Collectors(java.util.stream.Collectors) Validated(org.hl7.gravity.refimpl.sdohexchange.dto.Validated) ArrayList(java.util.ArrayList) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) List(java.util.List) PersonalCharacteristicDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto) DetailedRaceCode(org.hl7.gravity.refimpl.sdohexchange.codes.DetailedRaceCode) Coding(org.hl7.fhir.r4.model.Coding) CharacteristicMethod(org.hl7.gravity.refimpl.sdohexchange.codes.CharacteristicMethod) FHIRException(org.hl7.fhir.exceptions.FHIRException) Observation(org.hl7.fhir.r4.model.Observation) DetailedEthnicityCode(org.hl7.gravity.refimpl.sdohexchange.codes.DetailedEthnicityCode) Practitioner(org.hl7.fhir.r4.model.Practitioner) Practitioner(org.hl7.fhir.r4.model.Practitioner) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) PersonalCharacteristicDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto) Observation(org.hl7.fhir.r4.model.Observation) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 3 with PersonalCharacteristicDto

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()));
}
Also used : CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Coding(org.hl7.fhir.r4.model.Coding) ArrayList(java.util.ArrayList) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

ArrayList (java.util.ArrayList)3 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3 Coding (org.hl7.fhir.r4.model.Coding)3 Observation (org.hl7.fhir.r4.model.Observation)3 CodingDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto)3 DetailedEthnicityCode (org.hl7.gravity.refimpl.sdohexchange.codes.DetailedEthnicityCode)2 EthnicityCode (org.hl7.gravity.refimpl.sdohexchange.codes.EthnicityCode)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 Practitioner (org.hl7.fhir.r4.model.Practitioner)1 CharacteristicCode (org.hl7.gravity.refimpl.sdohexchange.codes.CharacteristicCode)1 CharacteristicMethod (org.hl7.gravity.refimpl.sdohexchange.codes.CharacteristicMethod)1 DetailedRaceCode (org.hl7.gravity.refimpl.sdohexchange.codes.DetailedRaceCode)1 RaceCode (org.hl7.gravity.refimpl.sdohexchange.codes.RaceCode)1 Validated (org.hl7.gravity.refimpl.sdohexchange.dto.Validated)1 ReferenceDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto)1 PersonalCharacteristicDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.characteristic.PersonalCharacteristicDto)1 PersonalCharacteristicsInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.characteristic.PersonalCharacteristicsInfoBundleExtractor.PersonalCharacteristicsInfoHolder)1 Converter (org.springframework.core.convert.converter.Converter)1