Git Product home page Git Product logo

fhirpath's Introduction

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
}

fhirpath's People

Contributors

halprin avatar renovate[bot] avatar basiliskus avatar

Stargazers

 avatar Tom Willis avatar Jason Kulatunga avatar

Watchers

Jason Kulatunga avatar Tom Willis avatar  avatar

fhirpath's Issues

Progress + Collaboration?

Hey @halprin
I'm a big fan of this work. I'm building an open source PHR called Fasten Health that's also written in Go, and I had do a number of unsavory things to extract data from FHIR Resources, including running fhirpath.js in a Goja JS VM.

I'd love to migrate to a Go native version of FhirPath, and I'd love to assist/collaborate if you're open to it.

Your README says that "5 out of the 686 official tests pass.", but it hasn't been updated in a couple of months. Is that still accurate?

Fix Escaped Identifiers

I created a new branch, fix-escaped-identifier. In that branch, I created a test in evaluate_test.go, called TestEvaluate_EscapedIdentifier that basically tests FHIR Path that contains backticks. E.g. name.`given`. Notice the backticks. name.given works, but not with the backticks around the identifier. This should also fix some of the official tests in official_test.go, specifically TestOfficial/testBasics/testEscapedIdentifier. Feel free to reach out if you have questions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.