Skip to content

FHIRPath nested extention issue #82

Description

@tstrass

If you attempt to evaluate a FHIRPath that has an extension somewhere other than the root object, the following error is thrown:

Extension function not applicable to NilClass:

To reproduce:

With this Patient

{
  "telecom": [
    {
      "system": "phone",
      "value": "(333) 333-3333",
      "extension": [
          {
            "url": "http://example.com/phone-type",
            "valueString": "Smartphone"
          }
      ]
    }
  ],
  "resourceType": "Patient"
}

If I call:

FHIRPath.evaluate("Patient.telecom[0].extension('http://example.com/phone-type')", patient_json)

I get the following output:

D, [2021-03-22T18:44:27.444782 #97061] DEBUG -- : TOKENS: ["Patient", "telecom[0]", "extension", "(", "'phone-type'", ")"]
D, [2021-03-22T18:44:27.445396 #97061] DEBUG -- : TREE: ["Patient", "telecom[0]", :extension, ["'phone-type'"]]
D, [2021-03-22T18:44:27.445681 #97061] DEBUG -- : DATA: ["Patient", "telecom[0]", :extension, ["'phone-type'"]]
D, [2021-03-22T18:44:27.456356 #97061] DEBUG -- : V===> [{"telecom"=>[{"system"=>"phone", "value"=>"(333) 333-3333", "rank"=>1, "extension"=>[{"url"=>"http://example.com/phone-type", "valueString"=>"Smartphone"}]}], "resourceType"=>"Patient"}, "telecom[0]", :extension, ["'phone-type'"]]
D, [2021-03-22T18:44:27.456710 #97061] DEBUG -- : V===> [nil, {"system"=>"phone", "value"=>"(333) 333-3333", "rank"=>1, "extension"=>[{"url"=>"http://example.com/phone-type", "valueString"=>"Smartphone"}]}, :extension, ["'phone-type'"]]
D, [2021-03-22T18:44:27.456932 #97061] DEBUG -- : Evaling Extension Block....
*** RuntimeError Exception: Extension function not applicable to NilClass:

As another example, I have also seen an error thrown when attempting to eval a FHIRPath to a US Core ethnicity code, since it is an extension nested within an extension.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions