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());
}
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());
}
Aggregations