FHIR Chat · fhirPath length() expression · fhirpath

Stream: fhirpath

Topic: fhirPath length() expression


view this post on Zulip David deRoode (Jan 31 2022 at 21:28):

Attempting to craft an expression stating effectiveDateTime shall be greater than a 9 character string. Have tried variations of 'DiagnosticReport.effective.ofType(DateTime).length()>9' and 'DiagnosticReport.effectiveDateTime.length()>9' with no luck. Any hints are much appreciated

view this post on Zulip Lloyd McKenzie (Jan 31 2022 at 21:56):

@Bryn Rhodes @Paul Lynch

view this post on Zulip Brian Postlethwaite (Feb 01 2022 at 04:37):

effective.toString().Length()

view this post on Zulip David deRoode (Feb 01 2022 at 20:20):

Thanks Brian. For StructureDefinition:
<element id="DiagnosticReport.effective[x]">
<path value="DiagnosticReport.effective[x]"/>
<constraint>
<key value="0o95dEq9"/>
<severity value="error"/>
<human value="effectiveDateTime SHALL include the month and day"/>
<expression value="DiagnosticReport.effective.toString().Length()>9"/>
</constraint>
</element>...

I'm still seeing:
<issue>
<severity value="error"/>
<code value="processing"/>
<diagnostics value="0o95dEq9: 'effectiveDateTime SHALL include the month and day' Rule 'effectiveDateTime SHALL include the month and day' Failed"/>
<location value="DiagnosticReport.effective.ofType(dateTime)"/>
<location value="Line 1, Col 1467"/>
</issue>

In response to /$validate an example with: <effectiveDateTime value="2021-01-01T21:39:30.000Z"/>

view this post on Zulip Brian Postlethwaite (Feb 01 2022 at 21:26):

When you have the constraint at the element level you don't spcifiy the entire path.

view this post on Zulip Brian Postlethwaite (Feb 01 2022 at 21:27):

(if you put the constraint at the root, then the full path)

view this post on Zulip David deRoode (Feb 02 2022 at 03:16):

ah, makes sense- thanks for the help!

view this post on Zulip David deRoode (Feb 04 2022 at 18:24):

Just to share the working expression for this: got it to work with the expression in the root of the resource and included the full path. Also, lowercase 'l' in .length():
<element id="DiagnosticReport">
<path value="DiagnosticReport"/>
<constraint>
<key value="0o95dEq9"/>
<severity value="error"/>
<human value="effectiveDateTime SHALL include the month and day"/>
<expression value="effective.toString().length()>9"/>
</constraint>

view this post on Zulip Brian Postlethwaite (Feb 04 2022 at 20:35):

Just a note that this expression would make effective mandatory too.
If that's not intended, move the constraint into the effective element and remove it from the expression, making it toString().length() >9
Or in the constraint put effective.exists() implies effective.toString....


Last updated: Apr 12 2022 at 19:14 UTC