Search in sources :

Example 31 with QuestionnaireResponse

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();
    });
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 32 with QuestionnaireResponse

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());
    });
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) Test(org.junit.jupiter.api.Test)

Example 33 with QuestionnaireResponse

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

Example 34 with QuestionnaireResponse

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());
}
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 35 with QuestionnaireResponse

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);
}
Also used : Questionnaire(org.hl7.fhir.r4.model.Questionnaire) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)15 ArrayList (java.util.ArrayList)14 Bundle (org.hl7.fhir.r4.model.Bundle)11 QuestionnaireResponse (org.hl7.fhir.dstu3.model.QuestionnaireResponse)8 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)8 Row (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)8 Test (org.junit.jupiter.api.Test)8 Reference (org.hl7.fhir.dstu3.model.Reference)7 Reference (org.hl7.fhir.r4.model.Reference)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 Map (java.util.Map)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 FhirUtil (org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil)5 Coding (org.hl7.fhir.r4.model.Coding)4 Date (java.util.Date)3 Getter (lombok.Getter)3 Bundle (org.hl7.fhir.dstu3.model.Bundle)3