Skip to content

Many String FhirPath functions (e.g. startsWith) fail with extension only value #2960

@brianpos

Description

@brianpos

Describe the bug
When an "extension only" value is provided to the startsWith('xxx') function, a null reference exception is thrown.
This is due to the code going direct to the system string functions without handling any of the null stuff.

t.Add("startsWith", (string f, string fragment) => f.StartsWith(fragment), doNullProp: true);

To Reproduce
Steps to reproduce the behavior:
Run the below expression on this test instance

{
    "resourceType": "Patient",
    "id": "example",

    "managingOrganization": {
        "_reference": { "id": "element id" }
    }
}

Can test this in the fhirpath lab too.

managingOrganization.trace('v').reference.startsWith('#')

🧪 Test with FHIRPath-Lab

Returns the error:
Invalid expression: Invocation of function 'startsWith' failed: Object reference not set to an instance of an object.

Expected behavior
This not throw an error and return an empty set as there is no primitive string.
(check the spec, there are some other issues around this at the moment also...)
https://chat.fhir.org/#narrow/channel/179266-fhirpath/topic/result.20of.20toString.20with.20extension.20only.20value

Version used:

  • FHIR Version: R4
  • Version: v5.10.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions