Skip to content

Instantly share code, notes, and snippets.

View brianpos's full-sized avatar

Brian Postlethwaite brianpos

View GitHub Profile
@brianpos
brianpos / use_nash_JWT.cs
Created January 8, 2020 23:42
Retrieving an access token and calling a FHIR api using a NASH based JWT bearer
// <package id="jose-jwt" version="2.1.0" targetFramework="net461" />
public async Task UseNASHcertificate()
{
// retrieve the NASH/Medicare certificate (from the local store - but could come from elsewhere)
var cert = GetNASHOrMedicareCertificate();
// Use the Digital certificate as a client cert for the http connection
// to the token endpoint
HttpClientHandler handler = new HttpClientHandler();
@brianpos
brianpos / StructureMap_Serializer.cs
Created September 6, 2021 05:53
StructureMap Serialization for FHIR Mapping Language
/// <summary>
/// https://hl7.org/fhir/mapping.g4
/// </summary>
public class StructureMap_Serializer
{
public string Write_structureMap(StructureMap sm)
{
// mapId structure* imports* group+ EOF
StringBuilder sb = new StringBuilder();
sb.AppendLine(Write_mapId(sm));
@brianpos
brianpos / FhirMappingLanguageParser.cs
Last active September 11, 2021 22:00
Kick starter sample for taking a FHIR Mapping Language input string and converting it into a FHIR R4 StructureMap resource
[TestMethod]
public void TestFmlParserReal()
{
var expression = "map \"http://hl7.org/fhir/StructureMap/tutorial\" = tutorial\r\n";
expression += "uses \"http://hl7.org/fhir/StructureDefinition/Patient\" alias pat as source\r\n";
expression += "uses \"http://hl7.org/fhir/StructureDefinition/RelatedPerson\" alias rp as target\r\n";
expression += "imports \"http://hl7.org/fhir/StructureMap/core\"\r\n";
expression += "group tutorial\r\n";
Console.WriteLine(expression);
@brianpos
brianpos / structureddatacapture.ts
Last active January 29, 2022 01:36
FHIR SDC TypeScript Extension Helpers
import extensionHelpers from "fhir-extension-helpers";
/** Helper methods */
export namespace structuredDataCapture {
/* Extension URLs used in the Structure Data Capture IG */
// ----------------------------------------------------------------------
// markdown
// markdown(0..1)
// This is an equivalent of the string on which the extension is sent, but includes additional markdown (see documentation about [markdown](datatypes.html#markdown). Note that using HTML [xhtml](extension-rendering-xhtml.html) can allow for greater precision of display.
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
using Hl7.FhirPath;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@brianpos
brianpos / hl7.fhir.au.base.extensions.cs
Created April 26, 2022 08:09
Initial pass at Extension Methods code generated for the AU Base extensions.
// <auto-generated/>
// Contents of: hl7.fhir.au.base version: 2.2.0
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using Hl7.Fhir.Model;
@brianpos
brianpos / QuestionnaireResponse_Validator.cs
Created May 17, 2022 07:41
A more complete version of the subset of QuestionnaireResponse Validations in dotnet
public class QuestionnaireResponse_Validator
{
public QuestionnaireResponse_Validator(ValidationSettings settings = null)
{
_settings = settings ?? new ValidationSettings()
{
TerminologyServerAddress = "https://sqlonfhir-r4.azurewebsites.net/fhir",
TerminologyServerFhirClientSettings = new FhirClientSettings()
{
VerifyFhirVersion = false,
@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))
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 / 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;