sof

package
v0.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sof runs SQL on FHIR v2 ViewDefinitions: a view turns each FHIR resource of one type into rows of named columns, by FHIRPath, so FHIR data can be read as tables by SQL engines, spreadsheets and quality measures.

It follows the ViewDefinition's processing algorithm (column, select, forEach, forEachOrNull, repeat, unionAll, where, constants, %rowIndex, getResourceKey and getReferenceKey) and is checked against the official sql-on-fhir test fixtures.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("the ViewDefinition is not valid")

ErrInvalid is a ViewDefinition that cannot be run: a structural error found before any resource is read.

View Source
var ErrRun = errors.New("the view could not be run")

ErrRun is an error while running a view over a resource (multiple values in a non-collection column, a where clause that is not Boolean).

View Source
var Formats = map[string]string{
	"csv":     "text/csv",
	"ndjson":  "application/x-ndjson",
	"json":    "application/json",
	"parquet": "application/vnd.apache.parquet",
}

Formats are the output formats a view's rows are written in.

Functions

func ReadResources

func ReadResources(r io.Reader, fn func(map[string]any) error) error

ReadResources reads FHIR resources from NDJSON (a bulk export file), a Bundle, a JSON array, or one resource, calling fn for each (a Bundle's entries are unwrapped).

func ReadResourcesBytes

func ReadResourcesBytes(b []byte, fn func(map[string]any) error) error

ReadResourcesBytes is ReadResources over bytes.

Types

type Column

type Column struct {
	Name        string `json:"name"`
	Type        string `json:"type,omitempty"`
	Collection  bool   `json:"collection,omitempty"`
	Description string `json:"description,omitempty"`
	// contains filtered or unexported fields
}

Column is one output column.

type Example

type Example struct {
	Name  string          `json:"name"`
	Title string          `json:"title"`
	View  json.RawMessage `json:"view"`
}

Example is a ViewDefinition shipped as a starting point.

func Examples

func Examples() []Example

Examples are the shipped example views, by name.

type Row

type Row []any

Row is one output row: a value per column, in View.Columns order (nil for null).

type View

type View struct {
	Name     string
	Title    string
	URL      string
	Resource string
	// Columns are the output columns in order.
	Columns []*Column
	// contains filtered or unexported fields
}

View is a compiled ViewDefinition.

func Compile

func Compile(raw []byte) (*View, error)

Compile reads and validates a ViewDefinition (JSON).

func CompileMap

func CompileMap(m map[string]any) (*View, error)

CompileMap is Compile for a decoded ViewDefinition (decoded with UseNumber).

func (*View) Run

func (v *View) Run(resource map[string]any) ([]Row, error)

Run runs the view over one resource (decoded with UseNumber).

type Writer

type Writer interface {
	Write(Row) error
	Close() error
}

Writer writes rows in one format. Close finishes the output (a JSON array's ], a Parquet footer).

func NewWriter

func NewWriter(w io.Writer, format string, cols []*Column, header bool) (Writer, error)

NewWriter makes a writer for format (csv, ndjson, json, parquet). header applies to csv.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL