Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

HAPI FHIR: Open-Source Java HL7 FHIR Library, Plain Server vs. JPA Server Architecture, and US Core Validation

A technical health informatics guide to HAPI FHIR, covering the Apache 2.0 Java library for HL7 FHIR, data models and parsers (DSTU2–R5), IGenericClient, Plain Server vs. JPA Server architecture, and Implementation Guide validation.

Written and maintained by CASRAI Editorial Board

Last updated

Short answer: HAPI FHIR (HL7 Application Programming Interface for Fast Healthcare Interoperability Resources) is the reference open-source Java implementation of the HL7 FHIR interoperability standard. Originally developed at the University Health Network (UHN) in Toronto and maintained under the stewardship of Smile Digital Health, HAPI FHIR is distributed under the permissive Apache License 2.0. It provides strongly typed Java object models, JSON/XML/RDF parsers, a fluent RESTful client, an Implementation Guide validator, and two production server frameworks: the HAPI FHIR Plain Server (a stateless facade over existing clinical databases) and the HAPI FHIR JPA Server (a complete relational persistence engine for FHIR resources).

What is HAPI FHIR? Core modules and supported FHIR releases

In health information technology and clinical research informatics, HAPI FHIR serves as the foundational Java software development kit (SDK) for building ONC/ASTP-certified EHR APIs, clinical data repositories, and research data pipelines. The library is organized into modular Maven/Gradle artifacts supporting every major HL7 FHIR specification simultaneously within the same JVM:

  • Structure and Data Model Artifacts (hapi-fhir-structures-*): Provides strongly typed Java classes for every FHIR resource (such as Patient, Observation, Encounter, MedicationRequest, and QuestionnaireResponse) and composite data type across DSTU2, DSTU3 (STU3), R4, R4B, and R5.
  • Core Context and Serialization (FhirContext and IParser): The thread-safe FhirContext object acts as the central factory for a target FHIR version (for example, FhirContext.forR4()). From it, developers instantiate IParser instances that serialize and deserialize FHIR resources seamlessly between Java POJOs and wire formats (application/fhir+json, application/fhir+xml, and RDF Turtle).
  • Fluent RESTful Client (IGenericClient): A type-safe HTTP client that constructs FHIR RESTful operations—including read, vread, search with chained and reverse-chained parameters (_include, _revinclude), conditional creates/updates, and transaction/batch Bundle submissions—against any compliant endpoint such as Epic on FHIR or cloud FHIR stores.
  • Validation and Terminology Engine (hapi-fhir-validation): Implements the official HL7 FhirInstanceValidator, checking resource instances against base FHIR schemas, profile StructureDefinition constraints (such as HL7 US Core), invariants (FHIRPath expressions), and terminology bindings (`ValueSet` and `CodeSystem` lookups).

HAPI FHIR Server architectures: Plain Server vs. JPA Server

When organizations deploy a HAPI FHIR server, they choose between two architectural patterns built on the Java Servlet specification (`RestfulServer`) and Spring Framework:

Architectural Feature HAPI FHIR Plain Server (Facade Pattern) HAPI FHIR JPA Server (Persistence Engine)
Storage Mechanism No HAPI database: Translates incoming FHIR REST requests on the fly into queries against an existing legacy EHR, LIS, or research SQL schema Turnkey Hibernate/JPA schema: Stores FHIR resources, versions, tags, and search indices directly in PostgreSQL, Oracle, SQL Server, or MySQL
Developer Implementation Developers write custom IResourceProvider classes with annotated methods (@Read, @Search, @Create) that map legacy tables to FHIR POJOs Deployed out of the box via hapi-fhir-jpaserver-starter (Spring Boot) with pre-built DAOs (`IFhirResourceDao`) for every resource type
Search Indexing Handled manually by translating FHIR search parameters into custom SQL/stored-procedure queries Automated extraction of standard and custom SearchParameter values into indexed tables (HFJ_SPIDX_STRING, HFJ_SPIDX_TOKEN, HFJ_SPIDX_DATE, HFJ_SPIDX_QUANTITY) plus optional Elasticsearch/OpenSearch full-text indexing
Best Suited For Exposing a read-only or targeted FHIR R4 facade over an existing operational database without duplicating storage Building a standalone Clinical Data Repository (CDR), research data warehouse, payer interoperability hub, or FHIR sandbox

Advanced clinical research and interoperability capabilities in HAPI FHIR

Beyond basic CRUD and RESTful search, the HAPI FHIR JPA Server implements specialized HL7 implementation guides used across clinical trials, quality reporting, and health information exchange:

  1. FHIR Bulk Data Access ($export): Implements the HL7 FHIR Bulk Data Access IG (`Flat FHIR`), enabling asynchronous system-, patient-, or group-level extraction of millions of clinical records in newline-delimited JSON (.ndjson) format for machine learning cohort assembly and population health analytics—the same standard supported by managed platforms such as AWS HealthLake, Azure Health Data Services, and Google Cloud Healthcare API.
  2. Interceptor Framework and SMART on FHIR Security: HAPI FHIR’s server and client pipelines provide hooks (`@Interceptor` and `@Hook`) at every lifecycle point—from incoming HTTP headers and OAuth 2.0 / SMART on FHIR scope verification (`AuthorizationInterceptor` and `RuleBuilder`) to row-level multi-tenant partitioning, consent masking, and HIPAA audit logging (`ConsentInterceptor`).
  3. Clinical Quality Language (CQL) and eCQM Evaluation: Through integration with the Clinical Quality Framework (`cqf-ruler` / `hapi-fhir-jpaserver-cql`), HAPI FHIR evaluates HL7 CQL libraries and `Measure` resources (`$evaluate-measure`) directly against stored patient cohorts for electronic clinical quality measures (eCQMs) and clinical trial eligibility screening.
  4. MDM (Master Data Management) and Subscription Webhooks: Includes an automated Master Person Index / Enterprise Master Patient Index (EMPI) module (`hapi-fhir-jpaserver-mdm`) that links duplicate `Patient` or `Practitioner` records across feeding systems, alongside FHIR `Subscription` engines (REST hook, WebSocket, and message queue channels) that notify downstream applications when matching clinical observations arrive.

Frequently asked questions

What is HAPI FHIR?

HAPI FHIR is an open-source, Apache 2.0-licensed Java library and server framework for the HL7 Fast Healthcare Interoperability Resources (FHIR) standard. Created at University Health Network (UHN) and maintained by Smile Digital Health, it provides Java data models, JSON/XML parsers, a fluent REST client, profile validation tools, and both facade (Plain Server) and database-backed (JPA Server) FHIR server engines.

What is the difference between a HAPI FHIR Plain Server and the HAPI FHIR JPA Server?

A HAPI FHIR Plain Server acts as a stateless middleware layer (facade) where developers write Java `@ResourceProvider` classes to translate FHIR API requests into queries against an existing database. The HAPI FHIR JPA Server is a complete, database-backed FHIR repository built on Spring Boot and Hibernate/JPA that automatically stores, versions, and indexes all FHIR resources and search parameters in a relational database such as PostgreSQL.

How do developers validate US Core or custom Implementation Guides in HAPI FHIR?

Developers load standard NPM/TGZ FHIR Implementation Guide packages (such as `hl7.fhir.us.core.tgz`) into a `ValidationSupportChain` alongside `NpmPackageValidationSupport` and `InMemoryTerminologyServerValidationSupport`, and then invoke `FhirValidator.validateWithResult(resource)` to receive a structured `ValidationResult` and FHIR `OperationOutcome` listing any profile, cardinality, or terminology violations.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about HAPI FHIR: Open-Source Java HL7 FHIR Library, Plain Server vs. JPA Server Architecture, and US Core Validation

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →