SQL on FHIR
2.1.0-pre - release International flag

SQL on FHIR - Local Development build (v2.1.0-pre) built by the FHIR (HL7® FHIR® Standard) Build Tools. See the Directory of published versions

Example Binary: CodeSystemHierarchy

{
  "resourceType" : "https://sql-on-fhir.org/ig/StructureDefinition/ViewDefinition",
  "id" : "CodeSystemHierarchy",
  "name" : "code_system_hierarchy",
  "status" : "draft",
  "resource" : "CodeSystem",
  "select" : [
    {
      "column" : [
        {
          "path" : "getResourceKey()",
          "name" : "id",
          "description" : "CodeSystem identifier"
        }
      ]
    },
    {
      "column" : [
        {
          "path" : "code",
          "name" : "parent_code",
          "description" : "Code of the parent concept in the hierarchy"
        }
      ],
      "select" : [
        {
          "column" : [
            {
              "path" : "code",
              "name" : "code",
              "description" : "Code of the child concept"
            }
          ],
          "forEach" : "concept"
        }
      ],
      "repeat" : [
        "concept"
      ]
    }
  ]
}

Notes:

This will result in a “code_system_hierarchy” table that looks like this:

id parent_code code
1 vehicle car
1 vehicle truck
1 vehicle motorbike
1 car sedan
1 car suv
1 car hatchback
1 truck pickup
1 truck semi

Given a CodeSystem with nested concepts like:

  • vehicle
    • car
      • sedan
      • suv
      • hatchback
    • truck
      • pickup
      • semi
    • motorbike

The repeat directive walks down the concept tree, and at each level the nested forEach extracts each child concept. This produces parent-child pairs that can be used to build adjacency lists for hierarchical queries or to analyse the structure of a terminology.