C# & FHIR · Uncategorized

.NET / C# for FHIR Interoperability 1 — Build Your First FHIR Client

0 Introduction

Healthcare interoperability is no longer optional.

In the U.S., ONC (g)(10) certification and the US Core Implementation Guide mandate standardized, secure health data exchange. FHIR (Fast Healthcare Interoperability Resources) has become the global standard to make this possible — but turning messy, fragmented clinical data into compliant FHIR resources remains a nightmare for most .NET developers.

Struggling to map messy clinical notes into clean FHIR resources? You’re not alone.

I tried using Llama3 directly to convert free-text patient records (like “John, male, b.1980”) into structured JSON. But the output was unreliable: sometimes it added explanations, sometimes hallucinated fields, and often wrapped valid JSON in conversational fluff. The result? Deserialization failures, silent data corruption, and broken pipelines.

This is just one piece of the broader problem. Developers building FHIR solutions with .NET face a tangled web of challenges: legacy systems spewing unstructured CSV/SQL data, inconsistent resource formatting that violates US Core rules, inefficient cross-resource queries that fail ONC performance mandates, and security gaps that block compliance.

But here’s the truth: these pain points aren’t insurmountable — they just require a unified, .NET-native solution stack that combines FHIR expertise with enterprise-grade development practices.

This is the first article in a complete FHIR interoperability series for .NET/C# engineers, architects, and healthcare IT solution builders. We’ll build a closed-loop system that solves every step of the FHIR journey — from taming messy raw data to securing compliant access — with production-ready C# code.

We start at the foundation: connecting to a FHIR server and reading resources. But first, let’s map the full journey this series will cover.

What This Series Solves (End-to-End)

This 6-article series addresses the full FHIR interoperability pipeline for .NET developers — no more piecing together fragmented tutorials or compromising on compliance/performance:

  1. Tame Unstructured Data: Fix unreliable LLM outputs (like messy clinical note conversions) with a hybrid AI + rule-based guardrail (Article 6).
  2. Ensure Compliance: Validate resources against FHIR R4/US Core rules to avoid ONC (g)(10) penalties (Article 3).
  3. Simplify Data Mapping: Replace tedious manual if-else code with high-performance, bidirectional mapping tools (Article 4).
  4. Secure Access: Implement SMART on FHIR authentication to integrate with certified commercial EHRs (Article 5).
  5. Optimize Queries: Retrieve linked clinical data (e.g., Patient + Observation) in single round-trips (Article 2).
  6. Lay the Foundation: Build a production-ready FHIR client to connect, read, and search resources (This Article).

Every module is built with .NET/C# at its core — leveraging the Hl7.Fhir.Net SDK, Firely Server, and enterprise-grade tools — to ensure you’re not just “learning FHIR” but building solutions that pass certification and scale in clinical environments.

1. Why FHIR? Why C#? (Compliance + Market Reality)

1.1 Why FHIR?

FHIR has become the global standard for healthcare interoperability, driven by both regulatory mandate and technical practicality:

  1. Regulatory Requirement
    ONC (g)(10) requires all certified health IT systems to support FHIR APIs for patient data access and exchange, with non-compliance carrying penalties of up to $1.36M per year.
  2. Practical Value
    FHIR eliminates data silos between EHRs, labs, pharmacies, and patient-facing apps — enabling seamless data sharing that improves clinical outcomes and reduces operational costs.
  3. Modern API-First Design
    Built on REST, JSON, and standardized resource models, FHIR integrates natively with cloud, mobile, and enterprise stacks — avoiding the complexity of legacy HL7 v2 messaging.

1.2 Why .NET/C# in Healthcare?

For developers building FHIR solutions, .NET/C# is one of the optimal framework — backed by hard market data and technical fit:

  • Gartner (2024–2025): .NET/C# powers over 45% of enterprise EHR and integration layers in U.S. healthcare, making it the most widely adopted framework for interoperability.
  • HL7 & FHIR Community: The Hl7.Fhir.Net SDK is one of the most mature, actively maintained FHIR toolkits worldwide — with native support for C# and .NET.
  • Enterprise Stability: Strong typing, built-in security features, and robust performance make C# ideal for clinical systems where data integrity and reliability are non-negotiable.

If you’re a .NET developer, you already have the #1 skill set for U.S. healthcare interoperability jobs — this series will help you leverage that skill set to master FHIR.

2. The Pain Points I Solve

When building FHIR solutions with .NET, developers face a predictable set of roadblocks — from basic connectivity to complex AI-driven data cleaning:

  • Foundational Gaps: No clear, production-ready .NET examples for connecting to FHIR servers or executing core operations (solved in Article 1).
  • Inefficient Queries: Retrieving linked clinical data requires multiple server calls, violating ONC performance mandates (solved in Article 2).
  • Non-Compliant Resources: Missing fields or invalid formatting cause rejected data exchanges and compliance failures (solved in Article 3).
  • Tedious Mapping: Manual conversion between business models and FHIR resources leads to bloated, error-prone code (solved in Article 4).
  • Security Risks: Lack of standardized authentication blocks integration with certified EHRs (solved in Article 5).
  • Unreliable AI Outputs: LLM-generated FHIR resources suffer from hallucinations and formatting errors (solved in Article 6).

This series fixes all these pain points with a cohesive, modular approach — each article builds on the last to create a complete, production-grade solution.

3. Solution: Basic FHIR Client in C#

This article focuses on the critical first step of the pipeline: building a production-ready FHIR client to connect to a real FHIR server, read resources, and handle errors. This client forms the base for all subsequent modules — without reliable connectivity, no amount of AI or mapping can deliver value.

What You’ll Learn

✅ Connect to a public production-grade FHIR server (Firely Server: https://server.fire.ly)

✅ Read a Patient resource by ID

✅ Search for Patient resources with basic filtering

✅ Implement robust error handling for production reliability

Tech Stack

  • .NET 6+/7+/8/10 (cross-platform, enterprise-grade stability)
  • C# (primary language for .NET healthcare development)
  • Hl7.Fhir.R4 (v5.0.0) — official FHIR R4 core library for .NET
  • Hl7.Fhir.Rest (v5.0.0) — FHIR client library for REST API interaction
  • FHIR Server: https://server.fire.ly (public, ONC (g)(10)-compliant test server)

Core Code (Production-Grade)

Install-Package Hl7.Fhir.R4
Install-Package Hl7.Fhir.Rest

Create FHIR Client

using Hl7.Fhir.Rest;
using Hl7.Fhir.Model;
var client = new FhirClient("https://server.fire.ly")
{
PreferredFormat = ResourceFormat.Json,
Timeout = 10000
};

Read a Patient by ID

try
{
var patient = client.Read<Patient>("Patient/123");
Console.WriteLine($"Name: {patient.Name?.FirstOrDefault()?.Given.First()} {patient.Name?.FirstOrDefault()?.Family}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}

Search Patients

var query = new SearchParams().LimitTo(10);
var bundle = client.Search<Patient>(query);
foreach (var entry in bundle.Entry)
{
if (entry.Resource is Patient p)
{
Console.WriteLine(p.Id);
}
}

4. Summary

In this first article of the series, you built the foundational FHIR client that powers the entire interoperability pipeline. You learned:

  • Why FHIR is mandatory for U.S. healthcare compliance (ONC (g)(10)) and practical for breaking data silos.
  • Why .NET/C# dominates healthcare integration (45% market share per Gartner) and is the ideal fit for FHIR development.
  • How to install the official Hl7.Fhir.Net SDK, configure a FHIR client, and connect to a production-grade FHIR server.
  • How to read and search Patient resources with robust error handling — critical for production reliability.

This client is more than a “hello world” example: it’s the base upon which we’ll build advanced queries, resource validation, AI-driven data cleaning, and compliant authentication in the articles ahead. Every subsequent module relies on the reliable connectivity you’ve established here.

What’s Next?

Article 2 will dive into Advanced Query — solving the pain of inefficient cross-resource retrieval. You’ll learn to use FHIR’s Chained Search and Include features to fetch linked clinical data (e.g., Patient + their lab results) in a single server call, meeting ONC’s sub-2-second performance mandate and US Core compliance requirements.

5 Reference

ONC (g)(10) Interoperability and Information Blocking Rule | U.S. Department of Health and Human Services (HHS) | https://www.healthit.gov/topic/laws-regulation-and-policy/information-blocking

HL7 US Core Implementation Guide (IG) v7.1.0 | HL7 International | https://hl7.org/fhir/us/core/STU7.1/

2024–2025 Healthcare IT Market Analysis | Gartner | https://www.gartner.com/en/industries/healthcare-life-sciences/insights

FHIR R4 Core Specification (Basic Operations) | HL7 International | https://hl7.org/fhir/R4/index.html

.NET for Enterprise Healthcare Applications | Microsoft Developer Network (MSDN) | https://learn.microsoft.com/en-us/dotnet/architecture/healthcare/

Hl7.Fhir.Net SDK Official Documentation | HL7 FHIR .NET Working Group | https://docs.fire.ly/fhir-net-api/

FHIR for .NET Developers: A Practical Guide | Microsoft Learn | https://learn.microsoft.com/en-us/dotnet/healthcare/fhir/

.NET 8 Security Best Practices | Microsoft | https://learn.microsoft.com/en-us/dotnet/core/security/

FHIR Client Implementation Best Practices | HL7 International | https://hl7.org/fhir/R4/client.html

Firely Server Public FHIR Endpoint Documentation | Firely Health | https://docs.fire.ly/projects/Firely-Server/en/latest/public-server.html

6 Disclaimer

All source code in this article is open-sourced at my GitHub Portfolio (commercial use requires authorization).

If you’re building FHIR/interoperability solutions, seeking .NET/C# + Healthcare IT (FHIR/HL7) expertise for commercial partnerships, or hiring for remote-friendly roles in this space — feel free to connect with me on LinkedIn.

I’m open to technical collaborations, commercial project partnerships, and new career opportunities that align with FHIR/HL7 interoperability and .NET healthcare development.

Originally published on Medium.