Stream: shorthand
Topic: Constraining integer in FSH
Nathan Davis (Sep 29 2020 at 15:18):
How do I restrict valueInteger to values of 0-10 in FSH?
Jens Villadsen (Sep 29 2020 at 15:44):
Sounds like either an fp invariant or a valueset binding to me
Chris Moesel (Sep 29 2020 at 16:13):
Yes, I think you'd need to create in invariant using FHIRPath. First you create the Invariant. Something like this:
Invariant: zero-to-ten
Description: "Value must be an integer between 0 and 10 (inclusive)"
Expression: "$this >= 0 and $this <= 10"
Severity: #error
And then in your profile (assuming on Observation):
* valueInteger obeys zero-to-ten
Or if value[x]
is restricted to only allow integer anyway, you can just do:
* value[x] obeys zero-to-ten
Nathan Davis (Sep 29 2020 at 16:32):
@Jens Villadsen @Chris Moesel Thank you!
Grahame Grieve (Sep 29 2020 at 21:06):
why not use minValue and maxValue ?
Chris Moesel (Sep 29 2020 at 21:38):
Honestly? Because I forgot they exist?
Chris Moesel (Sep 29 2020 at 21:41):
OK. So a better way would be:
* valueInteger ^minValueInteger = 0
* valueInteger ^maxValueInteger = 10
Or if value[x]
is restricted to only allow integer anyway:
* value[x] ^minValueInteger = 0
* value[x] ^maxValueInteger = 10
Thanks for keeping me honest, @Grahame Grieve!
Jens Villadsen (Sep 30 2020 at 10:21):
Lol
Moritz Kähler (Dec 07 2021 at 08:08):
Hi, I'm not sure if it's correct to post the question here.
If I try to express min/max value in the same way for valueQuantity it does not work.
- valueQuantity ^minValueQuantity = 0
- valueQuantity ^maxValueQuantity = 100
see example here
https://fshschool.org/FSHOnline/#/share/3pRcOuL
causes:
error Cannot assign number value: 0. Value does not match element type: Quantity
Line: 12
error Cannot assign number value: 100. Value does not match element type: Quantity
Line: 13
In XML/JSON format this is supported.
Any ideas?
Chris Moesel (Dec 07 2021 at 13:30):
Hi @Moritz Kähler. Assigning a Quantity in FSH requires you to specify the units. So you need to do something more like this:
* valueQuantity ^minValueQuantity = 0 'kg'
* valueQuantity ^maxValueQuantity = 100 'kg'
If you really wanted to specify the value only (without units), then you'd need to do this:
* valueQuantity ^minValueQuantity.value = 0
* valueQuantity ^maxValueQuantity.value = 100
BUT... I would not recommend that. For the min/max to be meaningful, you really ought to set the units.
Moritz Kähler (Dec 07 2021 at 14:48):
Hi Chris Moesel, thank you for the quick answer.
I can build the .fsh files now. But if I validate resources against the profile (using hapi server) the validation does not fail if I provide a value less than 0.
If I use Invariants, the validation fails. Is this an issue with hapi or is this the intended behavior?
Chris Moesel (Dec 07 2021 at 20:10):
That sounds like a HAPI validator issue to me.
Grahame Grieve (Dec 08 2021 at 03:56):
you're right. The validator will start validating min and max quantities when next released
Moritz Kähler (Dec 08 2021 at 08:19):
Thanks for confirming the issue with validator. Good to know, that this will be fixed in the next release.
Last updated: Apr 12 2022 at 19:14 UTC