Installation
Install the HealthData.Interop.Fhir NuGet package into your .NET project:
# 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
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:
- FHIR Complexity Made Simple — The FHIR specification has thousands of pages. This library wraps the most commonly used operations (patient CRUD, search, validation) into clean, testable services so you don't have to reinvent the wheel.
- HIPAA Compliance by Design — Role-Based Access Control (RBAC), PHI masking before logging, immutable audit trails, and encryption helpers are built in. You shouldn't need a compliance consultant to write safe healthcare code.
- US Core Conformance Checking — ONC certification requires US Core profile conformance. This library validates your resources against federal standards before they hit production.
- ETL Without the Headache — Migrating legacy CSV/SQL data to FHIR is tedious. The ETL pipeline automates mapping, gender normalization, and idempotent upserts with compile-time code generation (Mapperly).
- Local AI Validation — Normalize messy clinical data using a local LLM (Ollama). No PHI leaves your network because inference runs entirely on-premise.
- Battle-Tested Against Public Servers — Each module is designed to run against real public FHIR servers (hapi.fhir.org, sandbox.smarte.onhealth.it) with graceful fallbacks for network issues, spec downloads, and duplicate resource handling.
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:
| Module | What it does | Why 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
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.