Stream: implementers
Topic: Slice on code type discrminator with existence of value
Laureen Loison (Dec 03 2019 at 15:27):
Hello, I try to create a Slice on CommunicationRequest resource on status field and I would like to say : "status = active only if communication request have at least one recipient" do you know how to do that with a slice or constraint ?
Thanks
Lloyd McKenzie (Dec 03 2019 at 17:45):
That should be a constraint, not a slice. Slice is for repeating elements within a resource, not for the resource as a whole.
Laureen Loison (Dec 03 2019 at 17:56):
Great, thanks, I try with this constraint add in Forge but no errors comes ...
Here it's my try :
{
"key": "cmr-1",
"severity": "error",
"human": "if status = active we must have a recipient,",
"expression": "status != 'active' | recipient.exists()"
}
Do you thing it's a correct expression ? Should I need to add a xpath ?
Thanks
Lloyd McKenzie (Dec 03 2019 at 18:22):
It should be status != 'active' or recipient.exists()
Laureen Loison (Dec 04 2019 at 11:23):
It should be
status != 'active' or recipient.exists()
I try but he didn't work. I have no error on my validation, have you got an other idea ?
Lloyd McKenzie (Dec 04 2019 at 13:06):
The invariant is being declared on "CommunicationRequest" root element, correct? How are you trying to validate?
Laureen Loison (Dec 04 2019 at 14:24):
Oh sorry I think the constraint should be declared on "CommunicationRequest.status" field, I try and it's work perfectly, thank you
Lloyd McKenzie (Dec 04 2019 at 14:52):
Constraints always have to appear on an ancestor (typically the nearest ancestor) that contains all elements referenced by the constraint. Paths are expressed with respect to the element the constraint appears on.
Last updated: Apr 12 2022 at 19:14 UTC