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 asPatient,Observation,Encounter,MedicationRequest, andQuestionnaireResponse) and composite data type across DSTU2, DSTU3 (STU3), R4, R4B, and R5. - Core Context and Serialization (
FhirContextandIParser): The thread-safeFhirContextobject acts as the central factory for a target FHIR version (for example,FhirContext.forR4()). From it, developers instantiateIParserinstances 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—includingread,vread,searchwith chained and reverse-chained parameters (_include,_revinclude), conditional creates/updates, and transaction/batchBundlesubmissions—against any compliant endpoint such as Epic on FHIR or cloud FHIR stores. - Validation and Terminology Engine (
hapi-fhir-validation): Implements the official HL7FhirInstanceValidator, checking resource instances against base FHIR schemas, profileStructureDefinitionconstraints (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:
- 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. - 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`).
- 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.
- 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.







