fhirpath

package module
v0.0.0-...-37133b3 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: MIT Imports: 4 Imported by: 0

README

fhirpath

Evaluates FHIR Path against FHIR resources.

This is a work in progress. 36 out of the 686 official tests pass.

Install

Require github.com/halprin/fhirpath in your go.mod file or use go to add it.

go get github.com/halprin/fhirpath

API

Start by importing the package.

import "github.com/halprin/fhirpath"
Evaluate

fhirpath.Evaluate is the main function of the API.

It takes two arguments.

  1. fhirString - string. Contains the FHIR JSON that the FHIR path will evaluate against.
  2. fhirPath - string. The FHIR path that is evaluated.

There are two return values.

  1. []T - A slice of values based on the evaluation of the FHIR path against the FHIR JSON. If the evaluation resulted in nothing, an empty slice is returned. A slice of size 1 or larger is possible depending on whether the evaluation matched multiple values.
  2. error - Optional. If not nil, an error was generated during evaluation.

fhirpath.Evaluate is a generic function, so it takes a type parameter. Upon evaluation, any results that are not the same as the type parameter are filtered out. If you want nothing filtered out, use any as the type paramter.

Example
package main

import (
	"fmt"
	"github.com/halprin/fhirpath"
)

// see https://github.com/halprin/fhirpath/blob/main/sample/patient.json
//go:embed sample/patient.json
var fhirPatient string

func main() {
	result, err := fhirpath.Evaluate[string](fhirPatient, "Patient.identifier.where(system='http://new-republic.gov/galactic-citizen-identifier').value")
	if err != nil {
		panic("FHIR path evaluation failed")
	}

	fmt.Printf("Number of results=%d\n", len(result)) // Number of results=1
	fmt.Printf("First result=%s\n", result[0])        // First result=b531d827-de9a-4e2e-a53b-8621bd29f656
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate[T any](fhirString string, fhirPath string) ([]T, error)

Evaluate evaluates the FHIR path against the supplied FHIR JSON. Returns a slice of values and an optional error. If the evaluation resulted in nothing, an empty slice is returned. A slice of size 1 or larger is possible depending on whether the evaluation matched multiple values. This function is a generic function, so it takes a type parameter. Upon evaluation, any results that are not the same as the type parameter are filtered out. If you want nothing filtered out, use `any` as the type paramter.

func EvaluateWithContext

func EvaluateWithContext[T any](fhirString string, fhirPath string, context context.Definition) ([]T, error)

Types

This section is empty.

Directories

Path Synopsis
internal
engine
Package engine evaluates the grammar.Tree and returns the results.
Package engine evaluates the grammar.Tree and returns the results.
grammar
Package grammar is used to create a `Tree` structure given a FHIR path to be parsed.
Package grammar is used to create a `Tree` structure given a FHIR path to be parsed.
grammar/antlrGen
Package antlrGen contains the generated ANTLR Go code created from the ANTLR .g4 file.
Package antlrGen contains the generated ANTLR Go code created from the ANTLR .g4 file.

Jump to

Keyboard shortcuts

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