Using the base profile for CodeSystem, I came across one of the constraints with a FHIR path expression that to me sounds like it will always return false.
Take the following CodeSystem resource for example:
{
"resourceType": "CodeSystem",
"concept": [{
"code": "example"
}]
}
In the base CodeSystem profile, we have the following constraint with the FHIR path expression:
{
"key": "csd-1",
"severity": "error",
"human": "Within a code system definition, all the codes SHALL be unique",
"expression": "concept.code.combine($this.descendants().concept.code).isDistinct()",
"xpath": "count(distinct-values(descendant::f:concept/f:code/@value))=count(descendant::f:concept)"
}
So this is using the combine(other : collection) : collection
expression here. To begin, concept.code
is executed first, which should return a collection of ["example"]
. Next, $this.descendants().concept.code
is executed, which should also return ["example"]
. Next, the two results are combined, but duplicate values should not be removed. So the result of that should be ["example", "example"]
. The isDistinct()
function is performed last, which should return false
since there are duplicates.
As I understand $this
should be referring to the node in focus, which should just be the CodeSystem
resource. This is because combine()
doesn’t take in an input collection after some chained evaluation like other functions, rather it just works off of the focused collection.
Am I following this correctly? From what I can see, this FHIR path expression will always return false
, this is because $this.descendants().concept.code
will always also include concept.code
. Am I missing something?
Shouldn’t the FHIR path expression instead be concept.descendants().code.isDistinct()
. I feel like I am missing something about how $this
or descendants()
works…