Stream: implementers
Topic: Date differences
Shravankumar (Aug 25 2021 at 11:43):
How to write fhir expression for date difference.
Like age calculator
e.g. days_diff('2018-03-01' , '2021-05-28').
Year_diff('2018-03-01' , '2021-05-28').
months_diff('2018-03-01' , '2021-05-28')
Lloyd McKenzie (Aug 25 2021 at 13:54):
@Shravankumar I changed the topic heading for you. (You'd originally posted under 'DocumentReference Encounter', which wasn't really related to your question.)
FHIRPath provides a mechanism to do date math - see http://hl7.org/fhirpath/#subtraction-2
Rajesh (Aug 26 2021 at 16:33):
Hi @Lloyd McKenzie
http://hl7.org/fhirpath/#subtraction-2 expects the right hand operand to be a time valued quantity like 1 day
or 24 months
, but what I have is a Date/DateTime.
in demo website https://hl7.github.io/fhirpath.js/
@2025-01-01 - @2020-01-01 //Result- Error: Cannot ["2025-01-01"] - ["2020-01-01"]
For below JSON structure. How can I calculate the duration in days b/w start and end date using fhirpath?
{
"start" : "2020-01-01",
"end" : "2025-01-01"
}
Lloyd McKenzie (Aug 26 2021 at 16:39):
Hmm. That's odd. I'd have expected FHIRPath to be able to do math on two dates, not just date + quantity. @Bryn Rhodes @Grahame Grieve
Bryn Rhodes (Aug 26 2021 at 16:59):
That's true, FHIRPath does not currently support duration or difference calculation. There is an open tracker for this: https://jira.hl7.org/browse/FHIR-19896
Bryn Rhodes (Aug 26 2021 at 17:01):
CQL has Duration and Difference calculations specified.
Last updated: Apr 12 2022 at 19:14 UTC