<StructureDefinition xmlns="http://hl7.org/fhir">
  <id value="ncdhc-observation-base" />
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-category">
    <valueString value="Clinical.Diagnostics" />
  </extension>
  <extension url="http://hl7.org/fhir/StructureDefinition/structuredefinition-security-category">
    <valueCode value="patient" />
  </extension>
  <url value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/StructureDefinition/ncdhc-observation-base" />
  <version value="current" />
  <name value="NCDHCObservationBase" />
  <title value="NCDHC Observation Base" />
  <status value="active" />
  <description value="This is the base profile for NCDHC Obsrevation. All NCDHC Observation profiles SHALL extend this profile (vital-sgins profiles are excluded)" />
  <fhirVersion value="4.0.1" />
  <mapping>
    <identity value="workflow" />
    <uri value="http://hl7.org/fhir/workflow" />
    <name value="Workflow Pattern" />
  </mapping>
  <mapping>
    <identity value="sct-concept" />
    <uri value="http://snomed.info/conceptdomain" />
    <name value="SNOMED CT Concept Domain Binding" />
  </mapping>
  <mapping>
    <identity value="v2" />
    <uri value="http://hl7.org/v2" />
    <name value="HL7 v2 Mapping" />
  </mapping>
  <mapping>
    <identity value="rim" />
    <uri value="http://hl7.org/v3" />
    <name value="RIM Mapping" />
  </mapping>
  <mapping>
    <identity value="w5" />
    <uri value="http://hl7.org/fhir/fivews" />
    <name value="FiveWs Pattern Mapping" />
  </mapping>
  <mapping>
    <identity value="sct-attr" />
    <uri value="http://snomed.org/attributebinding" />
    <name value="SNOMED CT Attribute Binding" />
  </mapping>
  <kind value="resource" />
  <abstract value="true" />
  <type value="Observation" />
  <baseDefinition value="http://hl7.org/fhir/StructureDefinition/Observation" />
  <derivation value="constraint" />
  <differential>
    <element id="Observation">
      <path value="Observation" />
      <constraint>
        <key value="dom-2" />
        <severity value="error" />
        <human value="If the resource is contained in another resource, it SHALL NOT contain nested Resources" />
        <expression value="contained.contained.empty()" />
        <xpath value="not(parent::f:contained and f:contained)" />
        <source value="http://hl7.org/fhir/StructureDefinition/DomainResource" />
      </constraint>
      <constraint>
        <key value="dom-3" />
        <severity value="error" />
        <human value="If the resource is contained in another resource, it SHALL be referred to from elsewhere in the resource or SHALL refer to the containing resource" />
        <expression value="contained.where((('#'+id in (%resource.descendants().reference | %resource.descendants().as(canonical) | %resource.descendants().as(uri) | %resource.descendants().as(url))) or descendants().where(reference = '#').exists() or descendants().where(as(canonical) = '#').exists() or descendants().where(as(canonical) = '#').exists()).not()).trace('unmatched', id).empty()" />
        <xpath value="not(exists(for $id in f:contained/*/f:id/@value return $contained[not(parent::*/descendant::f:reference/@value=concat('#', $contained/*/id/@value) or descendant::f:reference[@value='#'])]))" />
        <source value="http://hl7.org/fhir/StructureDefinition/DomainResource" />
      </constraint>
      <constraint>
        <key value="dom-4" />
        <severity value="error" />
        <human value="If a resource is contained in another resource, it SHALL NOT have a meta.versionId or a meta.lastUpdated" />
        <expression value="contained.meta.versionId.empty() and contained.meta.lastUpdated.empty()" />
        <xpath value="not(exists(f:contained/*/f:meta/f:versionId)) and not(exists(f:contained/*/f:meta/f:lastUpdated))" />
        <source value="http://hl7.org/fhir/StructureDefinition/DomainResource" />
      </constraint>
      <constraint>
        <key value="dom-5" />
        <severity value="error" />
        <human value="If a resource is contained in another resource, it SHALL NOT have a security label" />
        <expression value="contained.meta.security.empty()" />
        <xpath value="not(exists(f:contained/*/f:meta/f:security))" />
        <source value="http://hl7.org/fhir/StructureDefinition/DomainResource" />
      </constraint>
      <constraint>
        <extension url="http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice">
          <valueBoolean value="true" />
        </extension>
        <extension url="http://hl7.org/fhir/StructureDefinition/elementdefinition-bestpractice-explanation">
          <valueMarkdown value="When a resource has no narrative, only systems that fully understand the data can display the resource to a human safely. Including a human readable representation in the resource makes for a much more robust eco-system and cheaper handling of resources by intermediary systems. Some ecosystems restrict distribution of resources to only those systems that do fully understand the resources, and as a consequence implementers may believe that the narrative is superfluous. However experience shows that such eco-systems often open up to new participants over time." />
        </extension>
        <key value="dom-6" />
        <severity value="warning" />
        <human value="A resource should have narrative for robust management" />
        <expression value="text.`div`.exists()" />
        <xpath value="exists(f:text/h:div)" />
        <source value="http://hl7.org/fhir/StructureDefinition/DomainResource" />
      </constraint>
      <constraint>
        <key value="obs-6" />
        <severity value="error" />
        <human value="dataAbsentReason SHALL only be present if Observation.value[x] is not present" />
        <expression value="dataAbsentReason.empty() or value.empty()" />
        <xpath value="not(exists(f:dataAbsentReason)) or (not(exists(*[starts-with(local-name(.), 'value')])))" />
      </constraint>
      <constraint>
        <key value="obs-7" />
        <severity value="error" />
        <human value="If Observation.code is the same as an Observation.component.code then the value element associated with the code SHALL NOT be present" />
        <expression value="value.empty() or component.code.where(coding.intersect(%resource.code.coding).exists()).empty()" />
        <xpath value="not(f:*[starts-with(local-name(.), 'value')] and (for $coding in f:code/f:coding return f:component/f:code/f:coding[f:code/@value=$coding/f:code/@value] [f:system/@value=$coding/f:system/@value]))" />
      </constraint>
      <constraint>
        <key value="ncdhc-obs-inv-001-val-ar" />
        <severity value="error" />
        <human value="If neither of component nor hasMember nor interpretation element is present, then either a value[x] or a data absent reason must be present" />
        <expression value="component.exists() or interpretation.exists() or value.exists() or hasMember.exists() or dataAbsentReason.exists()" />
        <source value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/StructureDefinition/ncdhc-observation-base" />
      </constraint>
      <constraint>
        <key value="ncdhc-obs-inv-003-exm-org" />
        <severity value="error" />
        <human value="An organisation which captures the relevant details shall be present" />
        <expression value="(dataAbsentReason.empty()) implies (performer.reference.resolve().where($this is Organization).exists())" />
        <source value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/StructureDefinition/ncdhc-observation-base" />
      </constraint>
      <constraint>
        <key value="ncdhc-obs-inv-002-exm-pract" />
        <severity value="error" />
        <human value="Person who is clinically responsible for the undertaking of the exam shall be present" />
        <expression value="(dataAbsentReason.empty()) implies (performer.reference.resolve().where($this is PractitionerRole).exists())" />
        <source value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/StructureDefinition/ncdhc-observation-base" />
      </constraint>
    </element>
    <element id="Observation.code.coding">
      <path value="Observation.code.coding" />
      <slicing>
        <discriminator>
          <type value="pattern" />
          <path value="$this" />
        </discriminator>
        <description value="Slice based on the code.coding pattern" />
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <min value="1" />
    </element>
    <element id="Observation.subject">
      <path value="Observation.subject" />
      <min value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org.au/fhir/StructureDefinition/au-patient" />
      </type>
    </element>
    <element id="Observation.effective[x]">
      <path value="Observation.effective[x]" />
      <min value="1" />
    </element>
    <element id="Observation.performer">
      <path value="Observation.performer" />
      <slicing>
        <discriminator>
          <type value="type" />
          <path value="$this.resolve()" />
        </discriminator>
        <description value="Slice based on type:$this.resolve()" />
        <ordered value="false" />
        <rules value="open" />
      </slicing>
      <type>
        <code value="Reference" />
        <targetProfile value="http://hl7.org.au/fhir/StructureDefinition/au-organization" />
        <targetProfile value="http://hl7.org.au/fhir/StructureDefinition/au-practitionerrole" />
        <targetProfile value="http://hl7.org.au/fhir/StructureDefinition/au-patient" />
        <targetProfile value="http://hl7.org.au/fhir/StructureDefinition/au-practitioner" />
      </type>
    </element>
    <element id="Observation.performer:examiner">
      <path value="Observation.performer" />
      <sliceName value="examiner" />
      <min value="0" />
      <max value="*" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/StructureDefinition/ncdhc-practitioner-role" />
      </type>
    </element>
    <element id="Observation.performer:legalOrg">
      <path value="Observation.performer" />
      <sliceName value="legalOrg" />
      <min value="0" />
      <max value="1" />
      <type>
        <code value="Reference" />
        <targetProfile value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/StructureDefinition/ncdhc-organisation" />
      </type>
    </element>
    <element id="Observation.dataAbsentReason">
      <path value="Observation.dataAbsentReason" />
      <binding>
        <strength value="extensible" />
        <valueSet value="http://build.fhir.org/ig/hl7au/au-fhir-childhealth/ValueSet/ncdhc-observation-data-absent-reason-1" />
      </binding>
    </element>
  </differential>
</StructureDefinition>