Skip to content

Instantly share code, notes, and snippets.

View brianpos's full-sized avatar

Brian Postlethwaite brianpos

View GitHub Profile
@brianpos
brianpos / functions.json
Created September 14, 2025 13:17
FhirPath Functions in a json representation
{
"categories": [
{
"name": "Existence",
"sectionNumber": "5.1",
"functions": [
{
"functionName": "empty",
"description": "Returns `true` if the input collection is empty (`{ }`) and `false` otherwise.",
"arguments": [],
@brianpos
brianpos / fhirpath-parser-stress-test.md
Created August 21, 2025 21:30
FHIRPath Parser Stress tester

This isn't a sensible fhirpath expression that does something useful, however it does check the edges of a fhirpath parser. I've tried to check every single parsing rule, not every function avaialable.

(
  (
    (( -5.25 * 2 div 3 mod 2 + +3 - 1).toString() & ' units' )      /* polarity + multiplicative + additive + concatenation */
    |
    ( {} | true | %resource | false | 'hello' | 42 | 123L | @2025-08-21
      | @2025-08-21T12:34:56.789Z | @T08:00:00 | 5 'mg' | 3 days )  /* union of (null, booleans, string, number, long, date, datetime, time, qty(STRING), qty(keyword-unit) */
      | %ext 
@brianpos
brianpos / FhirPathTools.cs
Created April 7, 2025 08:18
Extract from a POC demonstrating an MCP Server for FHIRPath
extern alias r4;
using r4.Hl7.Fhir.Model;
using Hl7.Fhir.Model;
using Hl7.Fhir.StructuredDataCapture;
using Hl7.Fhir.Utility;
using Hl7.FhirPath;
using Hl7.FhirPath.Expressions;
using Microsoft.AspNetCore.DataProtection.KeyManagement;
using ModelContextProtocol.Server;
using System.ComponentModel;
@brianpos
brianpos / CRD-example.md
Last active February 9, 2025 19:34
Annotated example of a FHIR Implementation Guide processing it's dependent packages and canonical resources

The processing output lists for each IG and its dependencies (nested):

  • Package ID
  • Package Version
  • Number of resources that are selected
    • At the root level these are the canonical resoures, so remaining files are likely examples, indexes or non-canonical resources
    • At the dependency level, the number of canonical resources that are required by one of the parent IGs in the dependency tree
  • The total number of resources in the package
  • The number of canonical resources that the package requires (that it does not conain itself) - external canonicals
  • The number of those external canonicals that were not able to be resolved in the IGs dependency tree
  • A bulletted list of the unresolved external canonicals
@brianpos
brianpos / QuestionnaireResponse_Extract_Template.cs
Last active December 11, 2024 23:39
POC implementation of the proposed SDC template based $extract
using Hl7.Fhir.Model;
using Hl7.Fhir.Utility;
using Hl7.FhirPath;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Hl7.Fhir.FhirPath;
using Hl7.Fhir.ElementModel;
@brianpos
brianpos / QuestionnaireResponse_Extract_Definition.cs
Last active January 20, 2025 05:51
Demonstration implementation (WIP) for the definition based FHIR Questionniare data extraction
using Hl7.Fhir.Model;
using Hl7.Fhir.Specification;
using Hl7.Fhir.Specification.Navigation;
using Hl7.Fhir.Specification.Snapshot;
using Hl7.Fhir.Specification.Source;
using Hl7.Fhir.Utility;
using Hl7.Fhir.WebApi;
using Hl7.FhirPath;
using System;
using System.Collections;
@brianpos
brianpos / fhirpath-async.ts
Last active March 25, 2024 02:11
POC showing one possible way to do async functions in the fhirpath.js library without forcing the entire library to be async.
import type { CodeableConcept, Coding, OperationOutcome, OperationOutcomeIssue, Reference, Resource, Parameters } from "fhir/r4b";
import fhirpath from "fhirpath";
import { logMessage, CreateOperationOutcome } from "~/utils/create-outcome";
// --------------------------------------------------------------------------
// The concept of this POC is to demonstrate an approach to perform some
// async based methods as functions inside the fhirpath engine without
// converting the entire engine to process things asynchronously.
// e.g. Terminology functions such as memberOf, subsumes, or resolve()
//
@brianpos
brianpos / sdc-questionnaire-validation.md
Last active October 27, 2023 21:04
FHIR Questionnaire Definition Validation

Questionnaire top level validation should consider:

  • Check the canonical versioning algorithm and version don't contradict each other
  • Add a warning that the canonical URL is highly recommended
  • if status = published, ensure that has a canonical URL
  • information/warning if derivedFRom isn't a versioned canonical URL
  • Should subjectType and launch context be the same?
  • Check the copyright label is from the set of approved licenses?
  • Should there be some date checks on the approved, review and date etc?
  • definitionBased flag
  • anything needed for the replaces extension?
@brianpos
brianpos / FhirPathVistor.cs
Last active June 16, 2023 22:20
Static validation on a FhirPath Expression to verify validity against a specific fhir version (via object model)
using Hl7.Fhir.Introspection;
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using Hl7.FhirPath.Expressions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
@brianpos
brianpos / ProcessPackageCache.cs
Created June 1, 2023 03:36
Scan over a directory that contains directories of expanded FHIR packages and extract a file called sds.json summarizing its contents
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Utility;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;