Search in sources :

Example 1 with ConditionInfoHolder

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

the class ConditionInfoBundleExtractor method extract.

@Override
public List<? extends ConditionInfoHolder> extract(Bundle bundle) {
    Map<String, Observation> allObservations = FhirUtil.getFromBundle(bundle, Observation.class).stream().collect(Collectors.toMap(observation -> observation.getIdElement().getIdPart(), Function.identity()));
    Map<String, QuestionnaireResponse> allQuestionnaireResponses = FhirUtil.getFromBundle(bundle, QuestionnaireResponse.class).stream().collect(Collectors.toMap(qr -> qr.getIdElement().getIdPart(), Function.identity()));
    Map<String, Questionnaire> allQuestionnaires = FhirUtil.getFromBundle(bundle, Questionnaire.class).stream().collect(Collectors.toMap(q -> q.getUrl(), Function.identity()));
    return FhirUtil.getFromBundle(bundle, Condition.class).stream().map(condition -> {
        Reference evidenceReference = condition.getEvidence().stream().map(ConditionEvidenceComponent::getDetail).flatMap(Collection::stream).findFirst().orElse(null);
        QuestionnaireResponse questionnaireResponse = null;
        Questionnaire questionnaire = null;
        List<Observation> observations = new ArrayList<>();
        if (evidenceReference != null) {
            Observation evidenceObservation = allObservations.remove(evidenceReference.getReferenceElement().getIdPart());
            observations.add(evidenceObservation);
            questionnaireResponse = allQuestionnaireResponses.get(findQuestionnaireResponseId(evidenceObservation));
            String questionnaireResponseId = questionnaireResponse.getIdElement().getIdPart();
            Iterator<Entry<String, Observation>> iterator = allObservations.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, Observation> observationEntry = iterator.next();
                Observation value = observationEntry.getValue();
                if (containsQuestionnaireReference(value, questionnaireResponseId)) {
                    observations.add(value);
                    iterator.remove();
                }
            }
            questionnaire = allQuestionnaires.get(questionnaireResponse.getQuestionnaire());
        }
        return new ConditionInfoHolder(condition, questionnaire, questionnaireResponse, observations);
    }).collect(Collectors.toList());
}
Also used : Getter(lombok.Getter) Iterator(java.util.Iterator) Collection(java.util.Collection) Condition(org.hl7.fhir.r4.model.Condition) ConditionInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ConditionInfoBundleExtractor.ConditionInfoHolder) Reference(org.hl7.fhir.r4.model.Reference) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) AllArgsConstructor(lombok.AllArgsConstructor) Observation(org.hl7.fhir.r4.model.Observation) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Condition(org.hl7.fhir.r4.model.Condition) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) ConditionEvidenceComponent(org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Entry(java.util.Map.Entry) Observation(org.hl7.fhir.r4.model.Observation) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ConditionInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ConditionInfoBundleExtractor.ConditionInfoHolder)

Example 2 with ConditionInfoHolder

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

the class ProblemInfoBundleExtractor method extract.

@Override
public List<ProblemInfoHolder> extract(Bundle bundle) {
    List<? extends ConditionInfoHolder> conditionInfoHolders = conditionInfoBundleExtractor.extract(bundle);
    Map<String, ProblemInfoHolder> idToHolderMap = new HashMap<>();
    for (ConditionInfoHolder h : conditionInfoHolders) {
        idToHolderMap.put(h.getCondition().getIdElement().getIdPart(), new ProblemInfoHolder(h));
    }
    for (Task task : FhirUtil.getFromBundle(bundle, Task.class)) {
        if (!task.hasFocus() || !(task.getFocus().getResource() instanceof ServiceRequest)) {
            continue;
        }
        ServiceRequest sr = (ServiceRequest) task.getFocus().getResource();
        sr.getReasonReference().stream().filter(ref -> Condition.class.getSimpleName().equals(ref.getReferenceElement().getResourceType()) && idToHolderMap.containsKey(ref.getReferenceElement().getIdPart())).forEach(ref -> idToHolderMap.get(ref.getReferenceElement().getIdPart()).getTasks().add(new TaskInfoHolder(task.getIdElement().getIdPart(), task.getDescription(), task.getStatus())));
    }
    for (Goal goal : FhirUtil.getFromBundle(bundle, Goal.class)) {
        goal.getAddresses().stream().filter(ref -> Condition.class.getSimpleName().equals(ref.getReferenceElement().getResourceType()) && idToHolderMap.containsKey(ref.getReferenceElement().getIdPart())).forEach(ref -> {
            idToHolderMap.get(ref.getReferenceElement().getIdPart()).getGoals().add(new GoalInfoHolder(goal.getIdElement().getIdPart(), goal.getDescription().getText(), goal.getLifecycleStatus()));
        });
    }
    return new ArrayList<>(idToHolderMap.values());
}
Also used : Task(org.hl7.fhir.r4.model.Task) List(java.util.List) Getter(lombok.Getter) Goal(org.hl7.fhir.r4.model.Goal) Map(java.util.Map) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Bundle(org.hl7.fhir.r4.model.Bundle) Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) ArrayList(java.util.ArrayList) Task(org.hl7.fhir.r4.model.Task) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Goal(org.hl7.fhir.r4.model.Goal)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Getter (lombok.Getter)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 Condition (org.hl7.fhir.r4.model.Condition)2 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 ConditionEvidenceComponent (org.hl7.fhir.r4.model.Condition.ConditionEvidenceComponent)1 Goal (org.hl7.fhir.r4.model.Goal)1 Observation (org.hl7.fhir.r4.model.Observation)1 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)1 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)1