Skip to content

Add Nullable for Functions that Might Be Run on None Elements #1

Description

@giuliabaldini

Issue#15

Hi there,

I would like to use functions like "replace" on resources that might have empty values, as for example:

diagnostic_report_1 = {
    "resourceType": "DiagnosticReport",
    "id": "abc",
    "subject": {"reference": "Patient/cdf"},
}

diagnostic_report_2 = {
    "resourceType": "DiagnosticReport",
    "id": "abc",
}
res_1 = evaluate(
    resource=diagnostic_report_1, path="subject.reference.replace('Patient/', ''"
)
print(res_1)

res_2 = evaluate(
    resource=diagnostic_report_2,
    path="subject.reference.replace('Patient/', ''",
)
print(res_2)

In this case, the query will work for diagnostic_report_1, but it will not for diagnostic_report_2, because the second patient does not have a subject.reference.

I know that this can be fixed by adding a "nullable"=True in invocations/init.py. Alternatively, it would be possible to add a check in engine/init.py making sure that the second argument is actually valid.
After all, it can always happen that the previous calls yield an invalid value and that the function cannot be applied anymore. Is there any reason why the functions should not be "nullable" by default, or why this check should not be performed?

Thank you in advance for your time.

Best,
Giulia

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions