--- type: "doc" source: "source/elementdefinition-examples.html" ---  \[%settitle Element Definition Examples%\] \[%file newheader%\] \[%file newnavbar%\] <%dtxheader examples ElementDefinition%> ## Element Definition Examples | Responsible Owner: [\[%wgt fhir%\]]([%wg fhir%]) Work Group | [Standards Status](versions#std-process):[Informative](versions#std-process) | | --- | --- | ### Pattern Examples 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](structuredefinition-examples). #### Primitive Types 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: \[%example-start%\] \[%example-json%\] "patternString" : "This is a string value" \[%example-end%\] This pattern fixes the value of the string, so that this value is valid: \[%example-start%\] \[%example-json%\] "element" : "This is a string value" \[%example-end%\] This pattern fixes the value of the string, so that this value is valid: \[%example-start%\] \[%example-json%\] "element" : "This is a string value" \[%example-end%\] as is this: \[%example-start%\] \[%example-json%\] "element" : "This is a string value", "\_element" : { "extension" : \[{ "url" : "http://example.org", "valueCode" : "something" }\] } \[%example-end%\] but this is not: \[%example-start%\] \[%example-json%\] "element" : "This is a string value with additional content" \[%example-end%\] 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](fhirpath) using the [.matches() function](http://hl7.org/fhirpath/N1/#matchesregex-string-boolean). #### Complex Types For complex datatypes, the pattern contains a series of elements which are patterns in their own right. For example, this pattern: \[%example-start%\] \[%example-json%\] "patternCoding" : { "system" : "http://example.org/canonical", "code" : "a-code", "display" : "A display value" } \[%example-end%\] This pattern requires that any coding include these three values, but other elements and extensions are allowed: \[%example-start%\] \[%example-json%\] "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" }\] }\] } } \[%example-end%\] Note that a Coding with any of system, code or display missing does not meet the requirements of the pattern. #### Repeating Value Examples Consider this pattern, specified for an element named "code" that has a cardinality of 0..\*: \[%example-start%\] \[%example-json%\] "patternCodeableConcept" : { "coding" : \[{ "system" : "http://example.org/canonical", "code" : "a-code", "display" : "A display value" }\] } \[%example-end%\] 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: \[%example-start%\] \[%example-json%\] "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" }\] \[%example-end%\] but this is not, since the required elements are present, but on different repeats: \[%example-start%\] \[%example-json%\] "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" }\] \[%example-end%\] Nor is this valid, since the requirement applies to all the repeats: \[%example-start%\] \[%example-json%\] "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" }\] \[%example-end%\] \[%file newfooter%\] try { var currentTabIndex = sessionStorage.getItem('fhir-example-tab-index'); } catch(exception){ } if (!currentTabIndex) currentTabIndex = '0'; \[%example-init%\] function store(currentTab) { try { sessionStorage.setItem('fhir-resource-tab-index', currentTab); } catch(exception){ } \[%example-change%\] document.activeElement.blur(); }