use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project cqf-ruler by DBCG.
the class ExtractProviderIT method testExtract_noQuestionnaireReference_throwsException.
@Test
public void testExtract_noQuestionnaireReference_throwsException() throws IOException {
QuestionnaireResponse test = (QuestionnaireResponse) getFhirContext().newJsonParser().parseResource(stringFromResource("mypain-questionnaire-response-no-url.json"));
Parameters params = new Parameters();
params.addParameter().setName("questionnaireResponse").setResource(test);
assertThrows(InternalErrorException.class, () -> {
getClient().operation().onType(QuestionnaireResponse.class).named("$extract").withParameters(params).returnResourceType(Bundle.class).execute();
});
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse in project fhir-bridge by ehrbase.
the class FindQuestionnaireResponseTransactionIT method findQuestionnaireResponseSearch.
@Test
void findQuestionnaireResponseSearch() throws IOException {
for (int i = 0; i < 3; i++) {
create("QuestionnaireResponse/transactions/find-questionnaire-response-search.json");
}
Bundle bundle = search("QuestionnaireResponse?patient.identifier=" + PATIENT_ID + "&status=entered-in-error");
Assertions.assertEquals(3, bundle.getTotal());
bundle.getEntry().forEach(entry -> {
var questionnaireResponse = (QuestionnaireResponse) entry.getResource();
Assertions.assertEquals(PATIENT_ID, questionnaireResponse.getSubject().getIdentifier().getValue());
Assertions.assertEquals(QuestionnaireResponse.QuestionnaireResponseStatus.ENTEREDINERROR, questionnaireResponse.getStatus());
});
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse 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());
}
use of org.hl7.fhir.r4b.model.QuestionnaireResponse 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.fhir.r4b.model.QuestionnaireResponse in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConvertService method convert.
public Map<String, Object> convert(JSONObject questionnaireResponse) throws IOException {
QuestionnaireResponse qs = (QuestionnaireResponse) fhirContext.newJsonParser().parseResource(questionnaireResponse.toString());
if (qs.getQuestionnaire() == null) {
throw new IllegalStateException(String.format("QuestionnaireResponse '%s' does not contain a link to a Questionnaire.", qs.getIdElement().getIdPart()));
}
Optional<Questionnaire> foundQuestionnaire = questionnaireRepository.findByCanonnicalUri(qs.getQuestionnaire());
if (!foundQuestionnaire.isPresent()) {
throw new ResourceNotFoundException(String.format("Questionnaire was not found by URL '%s'.", qs.getQuestionnaire()));
}
Questionnaire questionnaire = foundQuestionnaire.get();
String mapUri = ((CanonicalType) questionnaire.getExtensionByUrl(MAP_EXTENSION).getValue()).getValueAsString();
boolean mapExists = validationEngine.getContext().listTransforms().stream().anyMatch(map -> map.getUrl().equals(mapUri));
if (!mapExists) {
loadMapIg(mapUri);
}
return new ObjectMapper().readValue(convertToBundle(questionnaireResponse, mapUri), Map.class);
}
Aggregations