HealthData.Interop.Fhir

A .NET 8 reference library for Healthcare Data Interoperability, FHIR R4 client utilities, HIPAA compliance helpers, and US Core conformance checking.

.NET 8 LTS FHIR R4 HIPAA Compliant US Core IG v1.3.3
Rong(Rex) Fan

By Rong (Rex) Fan

📢 Free Resource

Building FHIR interoperability? I made a free checklist of the 12 pitfalls teams hit before Cures Act certification.

Installation

Install the HealthData.Interop.Fhir NuGet package into your .NET project:

📦 Download on NuGet.org
# Via .NET CLI
dotnet add package HealthData.Interop.Fhir

# Via Package Manager Console
Install-Package HealthData.Interop.Fhir

# Via Paket
paket add HealthData.Interop.Fhir
Note: This package targets .NET 8.0 LTS. Compatible with .NET 9, .NET 10 and later versions due to forward compatibility of the .NET platform.

Quick Start

Get up and running in minutes with FHIR R4 client operations:

using HealthDataInteropSharedLibrary.BasicClient;
using Hl7.Fhir.Model;

var client = new FhirBasicService(
    "https://r4.sandbox.smarte.onhealth.it",
    logLevel: LogLevel.Information);

// Search for patients
var results = await client.SearchPatientsAsync("John");
foreach (var patient in results)
{
    Console.WriteLine($"Patient: {patient.Name?.FirstOrDefault()?.Family}");
}

Why Use This Library?

Healthcare data interoperability is one of the most challenging problems in modern software engineering. This library addresses real-world pain points:

This library demonstrates healthcare interoperability patterns. It is intended as a reference implementation and educational resource — see the License section below.

Modules & Business Value

Each module solves a specific healthcare interoperability challenge. Here is why you need them:

ModuleWhat it doesWhy use this module?
BasicClient FHIR R4 REST client for Patient/CareProvider operations Don't reinvent the wheel. It handles FHIR search parameters and resource parsing out of the box, saving you from writing raw HttpClient boilerplate.
AdvancedQuery Chained parameters, _include, _summary search strategies Basic queries are often slow and return too much data. This optimizes network round-trips and reduces payload size by fetching only what you need.
ResourceValidator Firely SDK validation + US Core conformance checker Clinical data is often messy. This acts as a "clinical firewall," ensuring resources strictly adhere to HL7 FHIR R4 rules and federal US Core requirements before storage.
Etl CSV to FHIR Patient mapping pipeline with Mapperly Most healthcare data exists in legacy databases or Excel. This bridges the gap, migrating legacy CSV/SQL data into standardized FHIR resources automatically.
AIDataValidator Local LLM (Ollama) semantic data normalization Traditional ETL fails on "fuzzy" data. AI semantic analysis can normalize messy text (e.g., different gender formats) where regex falls short, without sending PHI to the cloud.
SmartOnFHIR OAuth2/OIDC SMART on FHIR authentication Accessing an EHR is impossible without proper auth. This implements the industry-standard SMART on FHIR protocol for secure, token-based patient access.
Compliance HIPAA RBAC, PHI encryption, audit logging HIPAA is non-negotiable. This provides out-of-the-box Role-Based Access Control (RBAC) and immutable audit trails to protect you from compliance penalties.

API Reference

BasicClient.FhirBasicService

// Constructor: requires base FHIR server URL
var service = new FhirBasicService("https://your-fhir-server", logLevel);

// Key methods:
await service.SearchPatientsAsync(name);     // Search patients by name
await service.GetPatientAsync(id);           // Get single patient
await service.ReadCareProviderAsync(id);     // Read CareProvider

ResourceValidator.ResourceValidationService

var validator = new ResourceValidationService();
bool isValid = validator.Validate(patient);
var issues = validator.GetValidationIssues(patient);

ResourceValidator.UsCoreConformanceChecker

// Check if a Patient resource conforms to US Core profile
var result = UsCoreConformanceChecker.CheckPatientConformance(patient);
Console.WriteLine(result.IsUsCoreConformant); // true or false

// Ensure Patient has US Core profile in Meta
bool added = UsCoreConformanceChecker.EnsureUsCoreProfile(patient);

Compliance.HipaaComplianceOrchestrator

// 8-role RBAC compliance check
var result = HipaaComplianceOrchestrator.EvaluateAccess(
    role: FhirUserRole.Physician,
    action: "ReadPatient",
    patientId: "123");

// PHI encryption service
var encrypted = PhiEncryptionService.Encrypt(sensitiveData);
var decrypted = PhiEncryptionService.Decrypt(encrypted);

// Immutable audit log
AuditLog.LogAccess(username, resourceId, action, success);

Etl.EtlPipelineService

// CSV to FHIR Patient mapping pipeline
await EtlPipelineService.RunEtlPipelineAsync("data.csv", outputDir, logger);

AIDataValidator.AiValidatorService

// Requires Ollama running locally with llama3 model
var validator = new AiValidatorService(
    "http://localhost:11434",
    "llama3");

var cleanedData = await validator.NormalizePatientDataAsync(rawData);

Security Notice

Production Requirement: HTTPS must be enforced in production environments. The demo modules may include TLS certificate validation bypassing for local development due to network issues. This is never acceptable in production. Always use valid certificates and enforce TLS 1.2+ for all FHIR server connections.

License & Disclaimer

This library is licensed under the MIT License.

NO WARRANTY / NO MAINTENANCE:

This project is provided as a static portfolio snapshot to demonstrate technical competence. The author provides NO FUTURE MAINTENANCE, bug fixes, feature updates, or support. You are expected to use this code entirely at your own risk.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM THE USE OF THIS SOFTWARE.