Stream: implementers
Topic: Slicing on pattern/fixed
Nik Klassen (Jul 20 2020 at 17:49):
I'm working on implementing validation against StructureDefinitions. One thing I'm finding confusing is how cardinality affects the evaluation of pattern/fixed constraints. Looking at the Java FHIR validator. It seems that for non-slices: min: 0 and fixed fails on an empty field; min: 0 and pattern does not fail on an empty field. It seems like they should both fail, but the slicing case is more confusing. An empty slice doesn't fail for pattern or fixed on an empty field. This makes sense intuitively, if a slice is allowed to be empty then we shouldn't check the pattern rules. But we do check them if it's not a slice, which makes actually implementing these rules confusing. So the question is why does it pass when the slice is empty? Is it because we don't run any rules on an empty slice? Or is it something more specialized, like we should not recheck the discriminator rule specifically? If there was a binding in addition to the pattern/fixed does that get run? I think the easiest way to implement this is "when evaluating slice rules, if the slice is empty don't check any of the other rules in the slice definition", but I want to make sure I'm not missing an edge case
Gino Canessa (Jul 20 2020 at 18:13):
My (non-authoritative) interpretation:
Non-Sliced:
- pattern is a check against a present value; since
min: 0
means the field is optional, the pattern isn't tested and a missing value passes. - fixed is a check that the exact value is present - even though the value is optional, the required value isn't present and it fails.
Slicing is more complicated, because slicing =).
- If the slice is required and
slicing.rules = closed
(assuming the correct value is present somewhere else), it should fail (invalid value). - If the slice is required and not present (regardless of open/closed), it should fail (required slice not found).
- If the slice is defined but not required, it should pass.
Nik Klassen (Jul 20 2020 at 19:01):
Everything here matches my understanding, except the first point. The spec says "pattern[x]: Specifies a value that the value in the instance SHALL follow - that is, any value in the pattern must be found in the instance." the value in the instance says to me that there must be an instance to check against.
Grahame Grieve (Jul 20 2020 at 20:38):
It seems that for non-slices: min: 0 and fixed fails on an empty field; min: 0 and pattern does not fail on an empty field
That's certainly surprising to me
Grahame Grieve (Jul 20 2020 at 20:38):
do you have your test cases?
Nik Klassen (Jul 21 2020 at 17:45):
I used the ElementDefinition
{
"path": "Patient.identifier",
"id": "Patient.identifier",
"min": 0,
"max": "*",
"base": {
"min": 0,
"max": "*"
},
"patternIdentifier": {
"use": "usual"
}
}
with an empty Patient. It may be that using a StructureDefinition this minimal isn't expected to work. sd.json patient.json
Grahame Grieve (Jul 21 2020 at 23:08):
I moved this discussion to https://chat.fhir.org/#narrow/stream/179177-conformance/topic/fixed.2Fpattern.20on.20min.20.3D.200 for ease of focus
Last updated: Apr 12 2022 at 19:14 UTC