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

Error for Path Selection of Attributes Named like Functions

Open giuliabaldini opened this issue 3 years ago • 3 comments

Hi there,

there are sometimes problems if a path selection attribute has the same name as an existing operation. For example, div is the integer division, but it is also used in many generated public FHIR resources. In this case, the path text.div will yield an error.

import json
from fhirpathpy import evaluate
from pathlib import Path

with Path("tests/resources/observation-example.json").open("r") as fp:
    resource = json.load(fp)

res = evaluate(resource, "Observation.text.div")

print(res)

returns

Exception: Infix invoke should have arity 2

I think that this error could be fixed by looking at whether there is a dot or not before the declaration.

Best, Giulia

giuliabaldini avatar May 27 '22 08:05 giuliabaldini

According to the specification https://build.fhir.org/ig/HL7/FHIRPath/#keywords keyword like div must be wrapped with backticks, but it's not supported yet

ruscoder avatar May 23 '23 09:05 ruscoder

@giuliabaldini you can use workaround for the old grammar like Patient.text."div".

But there's an issue #13 that will change quotes to backticks.

ruscoder avatar May 23 '23 09:05 ruscoder

It should be fixed starting from 1.0.0 version @giuliabaldini Could you please check?

ir4y avatar May 13 '24 02:05 ir4y