FHIR Chat · Converting one Quantity to another · fhirpath

Stream: fhirpath

Topic: Converting one Quantity to another


view this post on Zulip Paul Lynch (Nov 02 2018 at 19:43):

As I mentioned on the questionnaire stream we have a need to do a calculation using a Quantity whose unit dimension is known but whose precise unit is not known in advance, and which will need to be converted to a known unit in order to be used in the FHIRPath formula. Should this functionality of converting one Quantity to another of a different unit be added to FHIRPath?

The actual work of writing a converter for UCUM units is already done (see for instance https://github.com/lhncbc/ucum-lhc)-- we would just need some syntax for it in FHIRPath, and then of course FHIRPath engines would need to include such a library to support it.

view this post on Zulip Brian Postlethwaite (Nov 03 2018 at 01:28):

That's an interesting problem, and I guess would need to write a custom function to perform this action (not something that is supported in fhirpath).
I'm also interested in if others think this is something to add in.
(If you do come up with a custom implementation, let me know what you decide to call it and I'll add it to our implementation too)

view this post on Zulip Paul Lynch (Nov 05 2018 at 16:58):

How about: convert('target-ucum-unit'). If the input collection (the left of .convert) is an array of Quantities, the result will be the Quantities in the target unit. If any element of the input array is not a Quantity or is not convertible an error would be raised.

Unless someone has a better solution, I will open a GForge ticket for this.

view this post on Zulip Brian Postlethwaite (Nov 05 2018 at 22:23):

What about toQuantity('mm') or is that feeling more like a type conversion

view this post on Zulip Brian Postlethwaite (Nov 05 2018 at 22:24):

The bare convert just looks to open to missinterpretation

view this post on Zulip Paul Lynch (Nov 05 2018 at 22:31):

Yes, toQuantity('ucum type') is probably better.

view this post on Zulip Paul Lynch (Nov 07 2018 at 17:56):

I just realized that Quanitity in FHIR (an object with fields) is different than a quantity in FHIRPath (looks like: 4 'mm'). What would toQuantity(unit) operate on? I would like it to operate on FHIR Quantity objects. Perhaps then it would need to be added to FHIR extensions to FHIRPath, rather than to FHIRPath core.

view this post on Zulip Grahame Grieve (Nov 09 2018 at 00:27):

what's special about FHIR quantities as opposed to FHIRPath quantities?

view this post on Zulip Bryn Rhodes (Nov 09 2018 at 01:30):

FHIR quantities support a comparator.

view this post on Zulip Paul Lynch (Nov 09 2018 at 16:26):

And, FHIR quantities are an object. I suppose internally 4 'mm' would be some sort of object too, but FHIR Quantity is a specific kind of object with defined fields. It might be that the section on converting FHIR primitive types into FHIRPath types (http://hl7.org/fhir/2018Sep/fhirpath.html#types) could include Quantity (though that might not be primitive?) but I don't see anything about such a conversion at present.

view this post on Zulip Grahame Grieve (Nov 09 2018 at 20:29):

I guess we should add that too. I use FHIR quantities internally for a FHIRPath quantity, and silently carry the comparator, though calculations on that can be fun


Last updated: Apr 12 2022 at 19:14 UTC