Skip to content

Instantly share code, notes, and snippets.

View brianpos's full-sized avatar

Brian Postlethwaite brianpos

View GitHub Profile
@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;
using Hl7.Fhir.Model;
using Hl7.FhirPath;
using Hl7.FhirPath.Expressions;
using NaturalSort.Extension;
using System;
using System.Collections.Generic;
using System.Linq;
// Requires these 2 nuget packages
// <PackageReference Include="NaturalSort.Extension" Version="3.2.0" />
@brianpos
brianpos / EvaluateFhirPathTesterExpression.cs
Last active June 7, 2022 18:30
Sample function for a custom operation to evaluate the results of a fhirpath operation for testing
if (operation == "fhirpath")
{
Resource resource = operationParameters.GetResource("resource");
string resourceId = operationParameters.GetString("resource");
string terminologyServerUrl = operationParameters.GetString("terminologyserver");
if (resource == null && !string.IsNullOrEmpty(resourceId))
{
// load the resource from another server
ResourceIdentity ri = new ResourceIdentity(resourceId);
if (!string.IsNullOrEmpty(ri.BaseUri?.OriginalString))