cqframework / clinical-reasoning

CQF Clinical Reasoning on FHIR for Java
https://www.cqframework.org/clinical-reasoning/
Apache License 2.0
34 stars 24 forks source link

QuestionnaireResponse definition based extraction doesn't use Questionnaire definitions #317

Closed soda0289 closed 5 months ago

soda0289 commented 1 year ago

I have been trying to use the QuestionnaireResponse/$extract operation on hapi fhir server and noticed this library implements it little different then I would expect.

Issue 1

When trying to extract data from QuestionnaireResponse using an id, QuestionnaireResponse/1234/$extract, the method resolveQuestionnaireResponse() tries to load a Questionnaire, instead of a QuestionnaireResponse, using the QuestionnaireResponse id and this causes an error to be thrown.

https://github.com/cqframework/clinical-reasoning/blob/805b74933582affea3089f411a523d0c6ad2f57a/evaluator.questionnaireresponse/src/main/java/org/opencds/cqf/cql/evaluator/questionnaireresponse/r4/QuestionnaireResponseProcessor.java#L60

Changing that line to use QuestionnaireResponse.class resource type fixes the error and does let the questionnaire response be loaded. Is this a bug or was it intended?

Issue 2

When reading the itemExtraction extension the code uses the QuestionnareResponse model but the extension definition states that the extension should be on the Questionnaire model or the Questionnaire.item model not the QuestionnaireResponse.

https://github.com/cqframework/clinical-reasoning/blob/805b74933582affea3089f411a523d0c6ad2f57a/evaluator.questionnaireresponse/src/main/java/org/opencds/cqf/cql/evaluator/questionnaireresponse/r4/QuestionnaireResponseProcessor.java#L107

Is this behaviour intended? We do load the Questionnaire to extract observations. Should the code be updated to also read itemExtract extension and definition from Questionnaire as well as QuestionnaireResponse or should it only be from Questionnaire?

@JPercival @barhodes

Im just learning about FHIR and SDC/Questionnaire standards so not 100% sure I understand everything correctly. I can create PR to update this implementation as I'd like to use it instead of writing my own solution.

barhodes commented 1 year ago

The first issue is indeed a bug. We'll get that fixed asap.

As for the 2nd, yes that extension is intended for the Questionnaire. We carry it over to the QuestionnaireResponse to avoid having to look up the Questionnaire or if the Questionnaire isn't available (or doesn't exist because it was generated dynamically).

soda0289 commented 1 year ago

Thanks for looking into it. I can try and create PR to add support for reading itemExtraction extension and definitions from Questionnaire if its not found in QuestionnaireResponse. Checking if the extension exists in QuestionnaireResponse first would be makes sense to me and dose avoid having to lookup Questionnaire if not needed. I would like to support not having to copy over the extensions and definitions into QuestionnaireResponse, at the client level, if not needed.