Model

Trees and tables

In it's core, FQL is a tree-to-tree rewriting system. But it's primary goal is to produce tables. To create maximal expressivity and composability, these two models (trees and tables) have to be integrate and mapped in to one monoid like structure.

One structure

Let's start with the elements in those two models:

  1. A tree in FHIR consists of a node with a name, a type and a value. Each node can also have children. In most cases it's either a value OR children, but not always. So we can't take that as a core part of the model.

  2. A table consists of the table. A table contains rows and columns. And the columns can also be seen as fields in a row.

The most elementary way is by equivocating the top node of a tree with a table, the children of that node with rows and the children of those nodes with fields. Although this might be perceived as unsatisfactory, it's practically sufficient. It's upto a table renderer to choose how to deal with structures in or under the field level.

And so in it's core, we now only have nodes, who can be marked as table, row of field.

Complication

There is one fundamental complication, and that is that with FHIR, specifically FHIRpath, in order to merge the principles of JSON with XML, we allow multiple fields with the same name under one node. In JSON and most programming languages they are interpreted as arrays. The goal of FQL is not to flavour those structures by interpretation. So on this level we'll leave that in the middle, and allow multiple nodes on the same level with the same name.

Output

Although FQL is meant to produce tables, it can be used to produce arbitrary tree structures. It's input and output is just list of node where each node has arbitrary depth.

Validity

FQL is primary purpose is to gain insight into resources and conformance resources. And on of the main use cases here is to check for validity. FQL should there fore be able to deal with resources that are missing nodes. It must be able to deal with resources with invalid cardinalities. It does not have to deal with fields that do not exist according to the (FHIR) standard.