Skip to content

Quick Start

This guide will help you get started with OctoFHIR FHIRPath quickly using the CLI tool.

Make sure you have installed the CLI tool:

Terminal window
cargo install --path fhirpath-cli

The most common use case is evaluating FHIRPath expressions against FHIR resources.

Terminal window
# Evaluate an expression against a FHIR resource
octofhir-fhirpath eval "Patient.name.given" patient.json
# Specify output format
octofhir-fhirpath eval "Patient.name.given" patient.json --format json
octofhir-fhirpath eval "Patient.name.given" patient.json --format pretty

You can also validate FHIRPath expression syntax:

Terminal window
# Check if an expression is syntactically valid
octofhir-fhirpath validate "Patient.name.given"
octofhir-fhirpath validate "Patient.invalid..syntax"

Create a sample patient.json file to test with:

{
"resourceType": "Patient",
"id": "example",
"name": [
{
"use": "official",
"family": "Smith",
"given": ["John", "Michael"]
}
],
"gender": "male",
"birthDate": "1990-01-01"
}

Try these expressions with your sample patient:

Terminal window
# Get the resource type
octofhir-fhirpath eval "resourceType" patient.json
# Get the patient's family name
octofhir-fhirpath eval "name.family" patient.json
# Get all given names
octofhir-fhirpath eval "name.given" patient.json
# Get the first given name
octofhir-fhirpath eval "name.given[0]" patient.json
# Get the gender
octofhir-fhirpath eval "gender" patient.json
# Get names with official use
octofhir-fhirpath eval "name.where(use = 'official')" patient.json

OctoFHIR FHIRPath supports different output formats:

Terminal window
octofhir-fhirpath eval "name.given" patient.json --format pretty

Output:

["John", "Michael"]
Terminal window
octofhir-fhirpath eval "name.given" patient.json --format json

Output:

["John", "Michael"]