fhirpath-py icon indicating copy to clipboard operation
fhirpath-py copied to clipboard

Bug with getting a Coding answer from QuestionnaireResponse

Open mkizesov opened this issue 3 years ago • 2 comments

Example:

from fhirpathpy import evaluate

evaluate(
    questionnaire_response,
    "QuestionnaireResponse.repeat(item).where(linkId='acc-have-claim-number').answer.value.Coding"
)
questionnaire_response = {
 "item": [
  {
   "item": [
    {
     "item": [
      {
       "answer": [
        {
         "value": {
          "Coding": {
           "code": "373066001",
           "system": "http://snomed.info/sct",
           "display": "Yes"
          }
         }
        }
       ],
       "linkId": "acc-have-claim-number"
      },
      {
       "answer": [
        {
         "value": {
          "string": "wfwefwf"
         }
        }
       ],
       "linkId": "acc-claim-number"
      }
     ],
     "linkId": "acc-claim-number-group"
    },
    {
     "linkId": "acc-claim-details-group"
    }
   ],
   "linkId": "patient-acc"
  }
 ]
}

mkizesov avatar Jul 17 '20 05:07 mkizesov

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/__init__.py", line 66, in evaluate
    return apply_parsed_path(resource, node, context, model)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/__init__.py", line 30, in apply_parsed_path
    node = do_eval(ctx, dataRoot, parsedPath["children"][0])
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 36, in invocation_expression
    parentData,
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 34, in <lambda>
    lambda accumulator, children: engine.do_eval(ctx, accumulator, children),
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 36, in invocation_expression
    parentData,
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 34, in <lambda>
    lambda accumulator, children: engine.do_eval(ctx, accumulator, children),
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 36, in invocation_expression
    parentData,
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 34, in <lambda>
    lambda accumulator, children: engine.do_eval(ctx, accumulator, children),
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 36, in invocation_expression
    parentData,
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 34, in <lambda>
    lambda accumulator, children: engine.do_eval(ctx, accumulator, children),
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 36, in invocation_expression
    parentData,
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 34, in <lambda>
    lambda accumulator, children: engine.do_eval(ctx, accumulator, children),
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 76, in term_expression
    return engine.do_eval(ctx, parentData, node["children"][0])
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 28, in invocation_term
    return engine.do_eval(ctx, parentData, node["children"][0])
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 216, in member_invocation
    filtered = [x for x in parentData if x["resourceType"] == key]
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 216, in <listcomp>
    filtered = [x for x in parentData if x["resourceType"] == key]
KeyError: 'resourceType'

mkizesov avatar Jul 17 '20 05:07 mkizesov

if we add resourceType to questionnaire_response, we'll get this error:

questionnaire_response['resourceType'] = 'QuestionnaireResponse'
evaluate(
    questionnaire_response,
    "QuestionnaireResponse.repeat(item).where(linkId='acc-have-claim-number').answer.value.Coding"
)

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/__init__.py", line 66, in evaluate
    return apply_parsed_path(resource, node, context, model)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/__init__.py", line 30, in apply_parsed_path
    node = do_eval(ctx, dataRoot, parsedPath["children"][0])
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 36, in invocation_expression
    parentData,
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 34, in <lambda>
    lambda accumulator, children: engine.do_eval(ctx, accumulator, children),
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/__init__.py", line 41, in do_eval
    return evaluator(ctx, parentData, node)
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 216, in member_invocation
    filtered = [x for x in parentData if x["resourceType"] == key]
  File "/Users/miron/dev/cure8health/environment/backend/venv/lib/python3.7/site-packages/fhirpathpy/engine/evaluators/__init__.py", line 216, in <listcomp>
    filtered = [x for x in parentData if x["resourceType"] == key]
TypeError: 'ResourceNode' object is not subscriptable

mkizesov avatar Jul 17 '20 05:07 mkizesov