Evaluates FHIR Path against FHIR resources.
This is a work in progress. 36 out of the 686 official tests pass.
Require github.com/halprin/fhirpath
in your go.mod
file or use go
to add it.
go get github.com/halprin/fhirpath
Start by importing the package.
import "github.com/halprin/fhirpath"
fhirpath.Evaluate
is the main function of the API.
It takes two arguments.
fhirString
-string
. Contains the FHIR JSON that the FHIR path will evaluate against.fhirPath
-string
. The FHIR path that is evaluated.
There are two return values.
[]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.error
- Optional. If notnil
, 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.
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
}