Snapshot 3: Connectathon 32 Base

This page is part of the FHIR Specification (v5.0.0-snapshot3: R5 Snapshot #3, to support Connectathon 32). The current version which supercedes this version is 5.0.0. For a full list of available versions, see the Directory of published versions . Page versions: R5 R4B R4 R3 R2

FHIR Infrastructure icon Work GroupMaturity Level: N/AStandards 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:

 <patternString value="This is a string value"/>

This pattern fixes the value of the string, so that this value is valid:

  <element value="This is a string value"/>

This pattern fixes the value of the string, so that this value is valid:

  <element value="This is a string value"/>

as is this:

  <element value="This is a string value">
    <extension url="http://example.org">
      <valueCode value="something"/>
    </extension>
  </element>

but this is not:

  <element value="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 icon.

Note also that the pattern value is not format specific. These two JSON examples are also valid when tested against the pattern:

  "element" : "This is a string value"

and

  "element" : "This is a string value",
  "_element" : [{
    "url" : "http://example.org",
    "valueCode" : "something"
  }]

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>  

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="http://hl7.org/fhir/StructureDefinition/translation">
        <extension url="content">
        <valueString value="Un valor de visualización"/>
      </extension>
    </display>
  </coding>  

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>  

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>  

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>  

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>