Search in sources :

Example 1 with ReferenceDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class AssessmentInfoToDtoConverter method convert.

@Override
public AssessmentDto convert(AssessmentInfoHolder infoHolder) {
    AssessmentDto assessmentDto = new AssessmentDto();
    QuestionnaireResponse questionnaireResponse = infoHolder.getQuestionnaireResponse();
    assessmentDto.setId(questionnaireResponse.getIdElement().getIdPart());
    if (infoHolder.getQuestionnaire() != null) {
        assessmentDto.setName(infoHolder.getQuestionnaire().getTitle());
    } else {
        assessmentDto.setName(questionnaireResponse.getQuestionnaire());
        assessmentDto.getErrors().add("QuestionnaireResponse references a Questionnaire by the URL which does not exist. Using the URL as a " + "name instead.");
    }
    assessmentDto.setQuestionnaireUrl(questionnaireResponse.getQuestionnaire());
    assessmentDto.setDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
    assessmentDto.setAssessmentResponse(assessmentResponseToDtoConverter.convert(infoHolder));
    assessmentDto.setHealthConcerns(infoHolder.getConditions().stream().map(condition -> new ReferenceDto(condition.getIdElement().getIdPart(), codeableConceptToStringConverter.convert(condition.getCode()))).collect(Collectors.toList()));
    return assessmentDto;
}
Also used : ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) AssessmentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 2 with ReferenceDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConditionBundleToDtoConverterBase method conditionInfoToDto.

protected T conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
    T conditionDto = newConditionDtoImpl();
    Condition condition = conditionInfo.getCondition();
    conditionDto.setId(condition.getIdElement().getIdPart());
    conditionDto.setName(codeableConceptToStringConverter.convert(condition.getCode()));
    Coding categoryCoding = FhirUtil.findCoding(condition.getCategory(), SDOHMappings.getInstance().getSystem());
    // TODO remove this in future. Fow now two different categories might be used before discussed.
    if (categoryCoding == null) {
        categoryCoding = FhirUtil.findCoding(condition.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
    }
    if (categoryCoding == null) {
        conditionDto.getErrors().add("SDOH category is not found.");
    } else {
        conditionDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
    }
    Optional<Coding> icdCodeCodingOptional = findCode(condition.getCode(), System.ICD_10);
    if (icdCodeCodingOptional.isPresent()) {
        Coding icdCodeCoding = icdCodeCodingOptional.get();
        conditionDto.setIcdCode(new CodingDto(icdCodeCoding.getCode(), icdCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("ICD-10 code is not found.");
    }
    Optional<Coding> snomedCodeCodingOptional = findCode(condition.getCode(), System.SNOMED);
    if (snomedCodeCodingOptional.isPresent()) {
        Coding snomedCodeCoding = snomedCodeCodingOptional.get();
        conditionDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("SNOMED-CT code is not found.");
    }
    QuestionnaireResponse questionnaireResponse = conditionInfo.getQuestionnaireResponse();
    if (questionnaireResponse != null) {
        conditionDto.setAssessmentDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
        Questionnaire questionnaire = conditionInfo.getQuestionnaire();
        if (questionnaire != null) {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaire.getTitle()));
        } else {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaireResponse.getQuestionnaire()));
            conditionDto.getErrors().add("Based on QuestionnaireResponse doesn't have a matching Questionnaire to get a title from. Using URL " + "instead.");
        }
    } else {
        conditionDto.setBasedOn(new StringTypeDto(condition.getEvidenceFirstRep().getCodeFirstRep().getText()));
        Reference recorder = condition.getRecorder();
        conditionDto.setAuthoredBy(new ReferenceDto(recorder.getReferenceElement().getIdPart(), recorder.getDisplay()));
    }
    // abatement must be available for all resolved condition
    if (ConditionClinicalStatusCodes.RESOLVED.toCode().equals(condition.getClinicalStatus().getCodingFirstRep().getCode())) {
        if (condition.getAbatement() instanceof DateTimeType) {
            conditionDto.setResolutionDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getAbatement()));
        } else {
            conditionDto.getErrors().add("Condition is resolved but an abatement property is missing or not of a DateTimeType type.");
        }
    }
    return conditionDto;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 3 with ReferenceDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class GoalBundleToDtoConverter method convert.

@Override
public List<GoalDto> convert(Bundle bundle) {
    List<GoalDto> result = FhirUtil.getFromBundle(bundle, Goal.class).stream().map(goal -> {
        GoalDto goalDto = new GoalDto();
        goalDto.setId(goal.getIdElement().getIdPart());
        if (goal.hasDescription() && goal.getDescription().hasText()) {
            goalDto.setName(goal.getDescription().getText());
        } else {
            goalDto.getErrors().add("Goal description.text not found. Name cannot be set.");
        }
        if (goal.hasAchievementStatus()) {
            goalDto.setAchievementStatus(GoalAchievement.fromCode(goal.getAchievementStatus().getCodingFirstRep().getCode()));
        } else {
            goalDto.getErrors().add("No achievement status available.");
        }
        // TODO reused from HealthConcernBundleToDtoConverter class. Refactor!
        Coding categoryCoding = FhirUtil.findCoding(goal.getCategory(), SDOHMappings.getInstance().getSystem());
        // TODO remove this in future. Fow now two different categories might be used before discussed.
        if (categoryCoding == null) {
            categoryCoding = FhirUtil.findCoding(goal.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
        }
        if (categoryCoding == null) {
            goalDto.getErrors().add("SDOH category is not found.");
        } else {
            goalDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
        }
        Optional<Coding> snomedCodeCodingOptional = findCode(goal.getDescription(), System.SNOMED);
        if (snomedCodeCodingOptional.isPresent()) {
            Coding snomedCodeCoding = snomedCodeCodingOptional.get();
            goalDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
        } else {
            goalDto.getErrors().add("SNOMED-CT code is not found.");
        }
        if (goal.hasExpressedBy()) {
            Reference expressedBy = goal.getExpressedBy();
            goalDto.setAddedBy(new ReferenceDto(expressedBy.getReferenceElement().getIdPart(), expressedBy.getDisplay()));
        } else {
            goalDto.getErrors().add("Goal expressedBy property is missing. addedBy will be null.");
        }
        goalDto.setStartDate(FhirUtil.toLocalDate(goal.getStartDateType()));
        // TODO this is invalid. To clarify!
        if (goal.getLifecycleStatus() == Goal.GoalLifecycleStatus.COMPLETED) {
            if (goal.hasStatusDate()) {
                goalDto.setEndDate(FhirUtil.toLocalDate(goal.getStatusDateElement()));
            } else {
                goalDto.getErrors().add("Goal statusDate must be set when the lifecycleStatus is COMPLETED. endDate will be null.");
            }
        }
        goalDto.setComments(goal.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
        goalDto.setProblems(goal.getAddresses().stream().filter(ref -> Condition.class.getSimpleName().equals(ref.getReferenceElement().getResourceType())).map(ref -> (Condition) ref.getResource()).map(cond -> new ConditionDto(cond.getIdElement().getIdPart(), codeableConceptToStringConverter.convert(cond.getCode()))).collect(Collectors.toList()));
        return goalDto;
    }).collect(Collectors.toList());
    // TODO refactor. method too long.
    // TODO refactor. Almost the same fragmen exists in a ProblemInfoBundleExtractor
    Map<String, GoalDto> idToDtoMap = result.stream().collect(Collectors.toMap(g -> g.getId(), Function.identity()));
    for (Task task : FhirUtil.getFromBundle(bundle, Task.class)) {
        if (!task.hasFocus() || !(task.getFocus().getResource() instanceof ServiceRequest)) {
            continue;
        }
        ServiceRequest sr = (ServiceRequest) task.getFocus().getResource();
        sr.getSupportingInfo().stream().filter(ref -> Goal.class.getSimpleName().equals(ref.getReferenceElement().getResourceType()) && idToDtoMap.containsKey(ref.getReferenceElement().getIdPart())).forEach(ref -> idToDtoMap.get(ref.getReferenceElement().getIdPart()).getTasks().add(new TaskInfoDto(task.getIdElement().getIdPart(), task.getDescription(), task.getStatus())));
    }
    return result;
}
Also used : Converter(org.springframework.core.convert.converter.Converter) GoalDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalDto) Goal(org.hl7.fhir.r4.model.Goal) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Task(org.hl7.fhir.r4.model.Task) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) List(java.util.List) GoalAchievement(org.hl7.fhir.r4.model.codesystems.GoalAchievement) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) Coding(org.hl7.fhir.r4.model.Coding) Map(java.util.Map) Optional(java.util.Optional) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto) System(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System) SDOHMappings(org.hl7.gravity.refimpl.sdohexchange.sdohmappings.SDOHMappings) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Condition(org.hl7.fhir.r4.model.Condition) GoalDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) Task(org.hl7.fhir.r4.model.Task) Optional(java.util.Optional) Reference(org.hl7.fhir.r4.model.Reference) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Goal(org.hl7.fhir.r4.model.Goal) Coding(org.hl7.fhir.r4.model.Coding) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto)

Example 4 with ReferenceDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto 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 5 with ReferenceDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class PatientTaskItemInfoHolderToItemDtoConverter method convert.

@Override
public PatientTaskItemDto convert(T taskInfoHolder) {
    Task task = taskInfoHolder.getTask();
    Questionnaire questionnaire = taskInfoHolder.getQuestionnaire();
    PatientTaskItemDto taskDto = createDto();
    taskDto.setId(task.getIdElement().getIdPart());
    taskDto.setName(task.getDescription());
    taskDto.setPriority(task.getPriority().getDisplay());
    taskDto.setLastModified(FhirUtil.toLocalDateTime(task.getLastModifiedElement()));
    taskDto.setStatus(task.getStatus().getDisplay());
    taskDto.setStatusReason(task.getStatusReason().getText());
    setReferralTask(task, taskDto);
    List<Coding> codings = task.getCode().getCoding();
    PatientTaskCode code = getCode(taskDto, codings);
    if (code != null) {
        Coding coding = code.toCoding();
        taskDto.setCode(new CodingDto(coding.getCode(), coding.getDisplay()));
    }
    setTaskType(task, taskDto, code);
    if (questionnaire != null) {
        taskDto.setAssessment(new ReferenceDto(questionnaire.getIdElement().getIdPart(), questionnaire.getTitle()));
    }
    for (TaskOutputComponent outputComponent : task.getOutput()) {
        Type componentValue = outputComponent.getValue();
        Coding coding = FhirUtil.findCoding(Lists.newArrayList(outputComponent.getType()), SDCTemporaryCode.SYSTEM, SDCTemporaryCode.QUESTIONNAIRE_RESPONSE.getCode());
        if (coding != null) {
            Reference qrRef = (Reference) componentValue;
            if (QuestionnaireResponse.class.getSimpleName().equals(qrRef.getReferenceElement().getResourceType())) {
                taskDto.setAssessmentResponse(new ReferenceDto(qrRef.getReferenceElement().getIdPart(), coding.getDisplay()));
            }
        }
        if (componentValue instanceof CodeableConcept) {
            CodeableConcept outcome = (CodeableConcept) componentValue;
            taskDto.setOutcome(outcome.getText());
        }
    }
    return taskDto;
}
Also used : Task(org.hl7.fhir.r4.model.Task) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) PatientTaskItemDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.patienttask.PatientTaskItemDto) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) Type(org.hl7.fhir.r4.model.Type) PatientTaskType(org.hl7.gravity.refimpl.sdohexchange.dto.request.patienttask.PatientTaskType) Coding(org.hl7.fhir.r4.model.Coding) PatientTaskCode(org.hl7.gravity.refimpl.sdohexchange.codes.PatientTaskCode) TaskOutputComponent(org.hl7.fhir.r4.model.Task.TaskOutputComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Aggregations

ReferenceDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto)5 Coding (org.hl7.fhir.r4.model.Coding)4 CodingDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto)4 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)3 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)3 Reference (org.hl7.fhir.r4.model.Reference)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Condition (org.hl7.fhir.r4.model.Condition)2 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)2 Task (org.hl7.fhir.r4.model.Task)2 Converter (org.springframework.core.convert.converter.Converter)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)1 Goal (org.hl7.fhir.r4.model.Goal)1