Search in sources :

Example 1 with AssessmentInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder 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 AssessmentInfoHolder

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder in project Gravity-SDOH-Exchange-RI by FHIR.

the class AseessmentInfoBundleExtractor method extract.

@Override
public List<AssessmentInfoHolder> extract(Bundle bundle) {
    Map<String, Questionnaire> questionnaires = new HashMap<>();
    FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().forEach(q -> questionnaires.put(q.getUrl(), q));
    return FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().map(questionnaireResponse -> {
        List<Observation> observations = FhirUtil.getFromBundle(bundle, Observation.class).stream().filter(observation -> containsQuestionnaireReference(observation, questionnaireResponse.getIdElement().getIdPart())).collect(Collectors.toList());
        // Observations might be derived not only from the Questionnaire, but also from other Observations.
        // If we do not include these "intermediate" observations - the link between the QuestionnaireResponse and
        // Condition will not be found.
        List<Observation> derivedObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().filter(observation -> containsObservationReference(observation, observations)).collect(Collectors.toList());
        observations.addAll(derivedObservations);
        List<Condition> conditions = FhirUtil.getFromBundle(bundle, Condition.class).stream().filter(condition -> containsObservationReference(condition, observations)).collect(Collectors.toList());
        Questionnaire questionnaire = questionnaires.get(questionnaireResponse.getQuestionnaire());
        return new AssessmentInfoHolder(questionnaireResponse, questionnaire, observations, conditions);
    }).collect(Collectors.toList());
}
Also used : Getter(lombok.Getter) Collection(java.util.Collection) Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) List(java.util.List) Map(java.util.Map) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) AllArgsConstructor(lombok.AllArgsConstructor) AssessmentInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder) Observation(org.hl7.fhir.r4.model.Observation) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) AssessmentInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) HashMap(java.util.HashMap) List(java.util.List) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Aggregations

QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Getter (lombok.Getter)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 Condition (org.hl7.fhir.r4.model.Condition)1 ConditionEvidenceComponent (org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent)1 Observation (org.hl7.fhir.r4.model.Observation)1 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)1 AssessmentDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto)1 ReferenceDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto)1 AssessmentInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor.AssessmentInfoHolder)1 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)1