grammar: FHIRConnect/v0.0.1
type: model
metadata:
  name: "OBSERVATION.head_circumference.v1"
  version: 0.0.1a # version of this particular mapping
spec: # schema specific to the FHIRConnect v0.0.1 engine
  system: FHIR
  version: R4
  openEhrConfig:
    archetype: "openEHR-EHR-OBSERVATION.head_circumference.v1"
  fhirConfig:
    structureDefinition: http://hl7.org/fhir/StructureDefinition/Observation

preprocessor:
  hierarchy:
    with:
      fhir: "$resource"
      openehr: "$archetype/data[at0001]/events[at0010]"
    split:
      fhir:
        create: "resource"

  fhirConditions:
    - targetRoot: "$resource"
      targetAttribute: "code.coding.code"
      operator: "one of"
      criteria: "8287-5"

    - targetRoot: "$resource"
      targetAttribute: "status"
      operator: "one of"
      criteria: "final"

mappings:

  - name: "headCircumference"
    with:
      fhir: "$resource.value"
      openehr: "$archetype/data[at0001]/events[at0010]/data[at0003]/items[at0004]"

  - name: "category"
    with:
      fhir: "$resource.category.coding"
      openehr: "$archetype"
    manual:
      - name: "vitalSignsCategory"
        fhir:
          - path: "code"
            value: "vital-signs"
          - path: "system"
            value: "http://terminology.hl7.org/CodeSystem/observation-category"
          - path: "display"
            value: "Vital Signs"

  - name: "time"
    with:
      fhir: "$resource.effective"
      openehr: "$archetype/data[at0001]/events[at0010]/time"

  - name: "status"
    unidirectional: "openehr->fhir"
    with:
      fhir: "$resource"
      openehr: "$archetype"
    manual:
      - name: "status"
        fhir:
          - path: "status"
            value: "final"

  - name: "profile"
    unidirectional: "openehr->fhir"
    with:
      fhir: "$resource"
      openehr: "$archetype"
    manual:
      - name: "profile"
        fhir:
          - path: "meta.profile"
            value: "http://hl7.org/fhir/us/vitals/StructureDefinition/head-occipital-frontal-circumference"

  - name: "code"
    unidirectional: "openehr->fhir"
    with:
      fhir: "$resource.code.coding"
      openehr: "$archetype"
    manual:
      - name: "code"
        fhir:
          - path: "code"
            value: "8287-5"
          - path: "system"
            value: "http://loinc.org"
          - path: "display"
            value: "Head Occipital-frontal circumference by Tape measure"
