This
page
is
part
of
the
Continuous
Integration
Build
of
FHIR
Specification
(v5.0.0:
R5
-
STU
).
This
is
the
current
published
version
in
it's
permanent
home
(it
will
always
(will
be
available
incorrect/inconsistent
at
this
URL).
For
a
full
list
of
available
versions,
see
times).
See
the
Directory
of
published
versions
.
Page
versions:
R5
R4B
R4
R3
R2
Responsible
Owner:
FHIR
Infrastructure
Work
Group
|
Standards Status : Informative |
An element definition can provide a pattern that partially constrains the value domain of the element that it describes. This is effectively constraint by example. This section provides examples for some uses of pattern. For other ElementDefinition examples, see the extensive StructureDefinition example list .
These examples show how a pattern behaves when an element definition applies to an element that cannot repeat.
For a primitive datatype, patterns are typically used to fix the value of datatype, and leave the element id and extension unspecified. For example:
This pattern fixes the value of the string, so that this value is valid:
This pattern fixes the value of the string, so that this value is valid:
as is this:
<element value="This is a string value">
<extension url="http://example.org">
<valueCode value="something"/>
</extension>
</element>
"element" : "This is a string value",
"_element" : {
"extension" : [{
"url" : "http://example.org",
"valueCode" : "something"
}]
}
but this is not:
<element value="This is a string value with additional content"/>
"element" : "This is a string value with additional content"
If
a
fixed
value
had
been
used,
then
the
second
example
would
not
be
valid,
because
an
extension
could
not
be
added.
Note
that
it's
not
possible
to
only
partially
specify
the
content
of
any
particular
primitive
value,
such
that
the
third
example
is
valid
-
this
can
only
be
done
with
a
FHIRPath
constraint
using
the
.matches()
function
.
For complex datatypes, the pattern contains a series of elements which are patterns in their own right. For example, this pattern:
<patternCoding>
<system value="http://example.org/canonical"/>
<code value="a-code"/>
<display value="A display value"/>
</patternCoding>
"patternCoding" : {
"system" : "http://example.org/canonical",
"code" : "a-code",
"display" : "A display value"
}
This pattern requires that any coding include these three values, but other elements and extensions are allowed:
<coding>
<system value="http://example.org/canonical"/>
<version value="0.1.0"/>
<code value="a-code"/>
<display value="A display value">
<extension url="http://hl7.org/fhir/StructureDefinition/translation">
<extension url="lang">
<valueCode value="es"/>
</extension>
<extension url="content">
<valueString value="Un valor de visualización"/>
</extension>
</extension>
</display>
</coding>
"coding" : {
"system" : "http://example.org/canonical",
"version" : "0.1.0" ,
"code" : "a-code",
"display" : "A display value",
"_display" : {
"extension" : [{
"url" : "http://hl7.org/fhir/StructureDefinition/translation",
"extension" : [{
"url" : "lang"" : {
"valueCode" : "es"
}, {
"url" : "content"" : {
"valueString" : "Un valor de visualización"
}]
}]
}
}
Note that a Coding with any of system, code or display missing does not meet the requirements of the pattern.
Consider this pattern, specified for an element named "code" that has a cardinality of 0..*:
<patternCodeableConcept>
<coding>
<system value="http://example.org/canonical"/>
<code value="a-code"/>
<display value="A display value"/>
</coding>
</patternCodeableConcept>
"patternCodeableConcept" : {
"coding" : [{
"system" : "http://example.org/canonical",
"code" : "a-code",
"display" : "A display value"
}]
}
This means that any code element present SHALL have at least one coding with at least that system, code, and display. Other codings may be present, and the order does not matter.
So this is valid:
<code>
<coding>
<system value="http://example.org/other-canonical"/>
<code value="b-code"/>
<display value="A different code"/>
</coding>
<coding>
<system value="http://example.org/canonical"/>
<code value="a-code"/>
<display value="A display value"/>
</coding>
<text value="This is some text"/>
</code>
"code" : [{
"coding" : [{
"system" : "http://example.org/other-canonical",
"code" : "b-code",
"display" : "A different code"
}, {
"system" : "http://example.org/canonical",
"code" : "a-code",
"display" : "A display value"
}],
"text" : "This is some text"
}]
but this is not, since the required elements are present, but on different repeats:
<code>
<coding>
<system value="http://example.org/canonical"/>
<code value="b-code"/>
<display value="A different code"/>
</coding>
<coding>
<system value="http://example.org/other-canonical"/>
<code value="a-code"/>
<display value="A display value"/>
</coding>
<text value="This is some text"/>
</code>
"code" : [{
"coding" : [{
"system" : "http://example.org/canonical",
"code" : "b-code",
"display" : "A different code"
}, {
"system" : "http://example.org/other-canonical",
"code" : "a-code",
"display" : "A display value"
},
"text" : "This is some text"
}]
Nor is this valid, since the requirement applies to all the repeats:
<code>
<coding>
<system value="http://example.org/other-canonical"/>
<code value="b-code"/>
<display value="A different code"/>
</coding>
</code>
<code>
<coding>
<system value="http://example.org/canonical"/>
<code value="a-code"/>
<display value="A display value"/>
</coding>
<text value="This is some text"/>
</code>
"code" : [{
"coding" : [{
"system" : "http://example.org/other-canonical",
"code" : "b-code",
"display" : "A different code"
}]
}, {
"coding" : [{
"system" : "http://example.org/canonical",
"code" : "a-code",
"display" : "A display value"
}],
"text" : "This is some text"
}]