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