Running CQL on a HAPI FHIR server: when your team needs it
If your organization wants clinical logic written in CQL to run against FHIR data you host, the question is whether the HAPI FHIR JPA server can do that job for you or whether the logic belongs somewhere else. The JPA server is a complete RESTful FHIR server backed by a relational database, and the clinical reasoning capabilities built on it let your team load Library resources that contain CQL, then evaluate that logic against patient data already stored on the server. That makes it a fit when the data you need to reason over already lives in your FHIR repository and when the same logic must be reviewed, versioned and rerun by your own staff rather than by a vendor's hosted service.
The engine does not do the surrounding work on its own. It does not decide which measures, rules or thresholds are clinically correct, it does not clean or map source data into FHIR, and it does not secure access to results. Those responsibilities stay with your clinical informatics and security teams, and HAPI FHIR states it offers building blocks rather than a single security layer, so authorization, consent and audit must be designed around the server. Confirm before committing that the specific operations and CQL features you need are implemented in the HAPI FHIR version you plan to run, and check the release notes for the version you choose against the HAPI FHIR JPA server introduction.
Choose the server-side approach when the logic is measure or rule evaluation that depends on stored resources, needs a repeatable audit trail, and must sit inside your data boundary. Call logic from elsewhere when the rules depend on data outside the FHIR store, when a clinical application needs a fast answer at the point of care that a separate service already provides, or when your team lacks the capacity to test and maintain CQL libraries as controlled artifacts. Before you start, list every data source the logic reads, decide who approves changes to each Library, and confirm that your chosen JDK and database versions match the HAPI FHIR documentation for the release you plan to deploy.
Which CQL deployment options fit which team
This table compares the main ways to run CQL evaluation alongside a HAPI FHIR server, with the team profile each suits and the trade-off it carries. Read each row as a placement decision, then check the database and starter choices in the last rows, since they limit what the server can run.
| Option | When it fits | Main trade-off |
|---|---|---|
| Clinical reasoning on the JPA server | A small team that wants Library, Measure and CQL evaluation in the same server that already stores patient data and serves FHIR APIs | One deployment to patch, scale and back up, so evaluation load can compete with clinical reads and writes |
| CQL evaluation in a separate service | An organization that wants isolated scaling for population runs and a separate change cycle for logic and measures | Extra service to deploy, secure and monitor, plus a data path that must keep the copy of patient data in sync |
| Embedded H2 database for trials | Local testing of Library and CQL logic with sample data before a production database is chosen | Not suitable for production use, so results from it do not show production performance |
| PostgreSQL as the production database | Teams that want a supported production database for the JPA server, with their own database operations skills | Database tuning, backup and storage sizing become your responsibility and must be tested with CQL workloads |
| Microsoft SQL Server as the production database | Organizations whose database standards and skills center on SQL Server | Confirm the exact supported version and settings for your starter release before committing |
| Starter deployment with Docker or Helm | Teams that want a packaged starter to run in containers on infrastructure they control | Configuration, custom CQL libraries and terminology content must be carried into each image or chart values |
| Custom WAR or Spring Boot build | Teams with an existing Java application platform that needs custom interceptors or libraries | You own the build pipeline, dependency updates and the Java version requirements for each HAPI release |
| Partitioned data for regions or tenants | Multi-region or multi-tenant programs that need separated data for evaluation runs | Partition design affects searches and evaluation scope, so confirm it with a test plan before loading data |
How to set up CQL evaluation on HAPI FHIR
This sequence takes a HAPI FHIR JPA server from a clean install to a verified CQL evaluation against test patient data. Each step closes with a check, so the team knows the server is ready before any production logic or data is loaded.
Confirm the JDK and database baseline
The platform engineering team confirms the Java runtime and database before anything else. HAPI FHIR 8.2.0 requires JDK 17, so the team checks the documented requirement for the exact release it plans to run, and confirms that the JPA server starter will use PostgreSQL or Microsoft SQL Server rather than the embedded H2 default. MySQL is not supported. Done means the JDK version, database engine and driver are recorded in the build plan and match the versions documentation for the chosen release.
Start the JPA server with a clean database
The team deploys the hapi-fhir-jpaserver-starter using one of the supported methods, such as the hapiproject/hapi Docker image, Docker Compose, Spring Boot, a WAR on Tomcat, Jetty or Wildfly, or the Helm chart on Kubernetes. The database connection settings are supplied through the configuration for that method. Done means the server starts, creates its schema, and answers a capability statement request at the metadata endpoint with the expected FHIR version.
Enable clinical reasoning in the configuration
The platform team turns on the clinical reasoning features in the server configuration so that Library, Measure and PlanDefinition operations are available. The exact configuration keys differ by starter version and by deployment method, so the team must confirm each key name and default against the documentation for the chosen version before editing any file or environment variable. Done means the capability statement lists the clinical reasoning operations the team expects, and the server log shows no startup errors for the CQL components.
Load Library and supporting resources
A clinical informatics analyst uploads the CQL Library resource with its ELM, if the team generates it, along with the value sets and code systems the logic references. The team loads terminology resources before the Library so that references resolve at evaluation time. Dependencies such as FHIR model info and any included libraries must also be present. Done means each Library reads back with status active, and a test read returns the CQL text and the referenced resources without missing-reference errors.
Load test patient data
The team loads a small, known set of synthetic or de-identified patients with Patient, Encounter, Condition, Observation and other resources the CQL queries. Each test patient has an expected result written down before the run, so that the evaluation can be judged against a fixed answer. Done means each test patient can be read back, and the expected results for each patient are recorded in a test sheet kept with the Library version.
Run an evaluation against the test patients
The team invokes the library evaluation operation for one test patient, then for the full test set, using the Library identifier and the patient reference. Results are returned as a Parameters resource that contains the defined expressions. Done means the evaluation completes without errors for every test patient, and the returned values match the expected results recorded in the previous step.
Confirm results and record the baseline
A clinical reviewer compares each returned value with the expected result and investigates any mismatch by checking the CQL logic, the value set contents and the test data. The team records the server version, Library version, configuration and test outcomes as the baseline for the environment. Done means every test case passes or has a documented explanation, and the baseline is stored so that any later upgrade or Library change can be retested against it.
How CQL libraries and patient data meet on the server
A CQL library reaches the HAPI FHIR server as a FHIR Library resource that carries the CQL text, its declared dependencies and, where used, its compiled ELM form. When an evaluation is requested for one patient or a population, the server's CQL engine loads that library, resolves each include to another stored Library, and then runs the logic against resources already held in the server's database. Patient-level data such as Patient, Condition, Observation and MedicationRequest is read through the same FHIR search machinery the server uses for every other client, so the quality of the output depends on what has been loaded and indexed. The result comes back as FHIR, typically a MeasureReport for measure evaluation or a Parameters resource for an expression evaluation, which the caller can store or pass on. The practical decision is therefore which resources the logic needs, and whether they are present, current and complete in this server before anything is evaluated.
Terminology is the dependency teams most often underestimate. Value set and code system references in CQL are resolved against terminology content the server can reach, so the value sets, CodeSystem and ValueSet resources, and any terminology service configuration must be in place before evaluation. If a value set is missing, the logic may fail outright or, worse, quietly return no matches, which reads as a clean result. Before go-live, confirm with your clinical informatics team which code systems each library uses, which versions of each are expected, and where those resources will be loaded from. The HAPI FHIR terminology services documentation describes the JPA server's role here, and the separate terminology topic in this group covers loading and versioning in detail. Confirm the exact configuration against the version you deploy, because the terminology behavior is tied to the server release.
Request flow from Library to evaluation result
The flow starts with a client calling the $evaluate or $cql operation on the HAPI FHIR JPA server. The server loads the Library resource and its CQL logic, then reads patient resources from the relational database through the JPA layer. Terminology inputs such as value sets are resolved by the server's terminology services before the result returns to the client. Check that the trust boundary matches your deployment, because the terminology source and any external calls may sit outside it.
Evaluation request moving from client through the server to the database and back.
Securing CQL evaluation and the data it reads
HAPI FHIR gives you building blocks for authentication, authorization, consent, audit and data separation, but it does not decide who may do what for you. The cards below cover the components to assemble and the access decisions your team must make before Libraries are loaded and evaluations run against patient data.
Authentication in front of the server
Authentication interceptors decide who reaches the FHIR endpoints at all. Every operation that loads a Library, runs an evaluation or reads patient resources depends on this identity check. Confirm which identity provider issues the tokens, how clients prove who they are for system-to-system evaluation jobs, and how token lifetimes and revocation are handled for those service accounts. A shared static credential for batch evaluation is a risk to avoid.
HAPI FHIR security docsOperation-level authorization rules
The AuthorizationInterceptor is where you write rules that separate roles, such as who may create or update Library and Measure resources, who may call the evaluation operations, and who may only read results. Clinical reasoning operations touch both content and patient data, so define the rules per operation and per resource type rather than granting broad read access. Test each rule with a client that should be denied.
Content governance for Libraries
Anyone who can write a Library can change the logic that decides who appears in a report or receives a decision support prompt. Restrict Library writes to a controlled group, require review before a version becomes active in production, and keep a record of which Library version produced each evaluation. Your access model should separate authors, reviewers and the service account that runs evaluations.
Consent and search narrowing
Consent interceptors and search narrowing interceptors limit what a given caller can retrieve from the data that CQL reads. This matters when a measure population should only include patients a requester is permitted to see, or when a service should not receive data outside its purpose. Document which data classes each evaluation requires, then confirm that the narrowing rules still produce the population you expect.
Partitioning for data separation
Partitioning places each resource in a partition, which can support multitenancy, separate data sources or group data by region. Use it when different organizations or business units must not share patient data in the same evaluation context. Partition design affects how Library resources are shared or isolated, so decide where shared content lives and confirm that evaluations read only from the intended partition.
Partitioning docsAudit trail and cross-origin settings
BALP audit logging records access to FHIR resources so you can reconstruct who evaluated which measure against which patients. Pair it with CORS settings that allow only the browser origins you trust. Confirm where audit records are stored, who can read them, how long they are kept under your policy, and that evaluation requests are logged along with the data they touched.
Questions teams ask before running CQL on HAPI FHIR
What drives the cost of running CQL on a HAPI FHIR server?
The cost is driven mainly by how many measures or decision rules you need, how complex the CQL logic is, how much clinical data the logic must read, and how many systems feed the server. Each of these changes the amount of modeling, testing and data mapping work. Costs fall into one-time work (server setup, loading Library and Measure resources, validating results, building test cases) and recurring work (updating logic when specifications change, upgrades and monitoring). When you ask for a quote, request a line-item breakdown by these components and confirm who pays for clinical validation, since that work is often the largest share.
How long does a first working CQL evaluation usually take?
Duration depends on scope: the number of libraries, the data sources feeding the patient records, and whether the logic is an existing published measure or new decision support. A first evaluation of one library against a small test dataset is far shorter than a population run across a live clinical data feed. HAPI FHIR documentation does not give a timeline for this work, so treat any figure from a vendor or partner as a claim to check against your written scope. Ask for milestones tied to specific outputs, such as a loaded library, a passing test patient set and a reviewed evaluation result.
What does the work need from our team?
You need named people for four roles: a clinical informaticist or measure owner who can confirm the logic matches the intended specification, a FHIR or integration engineer who knows your data sources, an infrastructure owner for the server, and a security contact who approves access to patient data. Expect to provide sample data or a test environment, the terminology content the logic references, and decisions on which data is in scope. Without a clinical owner, teams often spend the most time arguing about logic rather than running it.
Can our in-house team run CQL on HAPI FHIR without a partner?
Yes, if you have engineers comfortable with Java and FHIR and at least one person who can read CQL and the measure specifications. The HAPI FHIR project is Apache Software License 2.0 licensed and runs on JDK 17 for the 8.2.0 release, so the software itself carries no license fee. The harder parts are clinical validation, which requires reference results to compare against, and the operational setup. A partner is worth considering when the timeline is fixed, when you lack CQL experience, or when auditors will ask for documented test evidence.
What recurs after go-live?
Recurring work includes updating libraries when clinical specifications or code systems change, retesting logic against known patient cases after each change, upgrading HAPI FHIR and its Java runtime, monitoring evaluation jobs, and reviewing access logs. The HAPI FHIR project publishes releases such as v8.8.2 (25 September 2026), so plan a regular upgrade review rather than waiting for a support deadline. Confirm with your partner whether ongoing support, upgrades and continuous testing are covered by a retainer or billed separately.
Which parts of the CQL setup carry the most risk?
The main risks are incorrect logic that looks correct in a test, patient data that does not match the terminology the logic expects, and access controls that were never applied to the evaluation endpoints. HAPI FHIR states that it does not provide a single security layer, so you must add authentication, the AuthorizationInterceptor and audit logging yourself. Test against a reference set of patients with known answers before production, and document which controls you added, because those records are what compliance reviewers will ask for.
What should we ask for in a quote for this work?
Ask for a written scope listing each library and measure in scope, the data sources, the environments to be built (development, test and production), and the testing approach, including how results will be compared to reference outputs. Request a deliverables list, a named set of milestones, the client responsibilities, and the assumptions behind them. Also ask what is one-time, what is recurring, how changes to scope are priced, and whether security testing and documentation for compliance reviews are included. DeployOpen does not publish a price list; a quote follows from the agreed written scope.
Testing CQL before it reaches production
Test every Library on a non-production HAPI FHIR server before it reaches a clinical or payer environment. Load the Library, its ValueSets and the measure or PlanDefinition that calls it into a dedicated test server, then evaluate the logic against a fixed set of patient records whose expected results were written down in advance. Each test case should name the patient, the measurement period, the expected population membership and the expected result, so a failure points to a specific CQL expression rather than to a vague difference in totals. Keep the test server on the same HAPI FHIR version and database engine you plan to run in production, because schema and evaluation behavior can differ between releases. Confirm the exact version and Java requirement in the HAPI FHIR versions page before you freeze the test environment.
Build test data from synthetic patients or from clinical scenarios written by your clinical informaticists, never from copies of production records. Store the test bundles, expected outputs and the Library version identifiers in the same version control repository, and treat a change to any of them as a reviewed change. When you move to a new HAPI FHIR release, rerun the full suite before and after the upgrade, and compare results for each Library version so that an upgrade cannot silently change a measure result. Plan the upgrade sequence with the HAPI FHIR releases page in hand, and record which Library version was active in each environment and on each date. Access to the test server should follow the same identity and audit rules as production, because test servers often hold data copies that are still sensitive even when they are labeled as samples.
Agree the independent reference checks early, because they set the schedule and the evidence you will need. Decide which measures or decision support logic will be checked against an external reference, who performs the check, and what they need from you, such as the Library source, test bundles and the expected outputs. DeployOpen does not issue audit reports or certifications, so any independent verification must come from a party you choose and whose scope you define in writing. Ask that party to confirm which reference implementation and measure version they use, and record any differences in a documented decision before go-live.
How DeployOpen scopes and delivers CQL on HAPI FHIR
DeployOpen starts every CQL engagement with a written scope that names the HAPI FHIR version, the FHIR version (DSTU2, DSTU3, R4, R4B or R5), the Library and Measure resources to be loaded, the patient data sources the logic will read, and who signs off each stage. An environment review follows. It covers where the HAPI FHIR JPA server will run, which JDK the chosen release requires (HAPI FHIR 8.2.0 requires JDK 17), which database the server will use, and how the server sits behind the reverse proxy and identity layer your organization already runs. Decisions made here, such as the database and the deployment method, are recorded before any configuration is written, because they determine what the CQL evaluation can rely on later.
Configuration and build are done inside your cloud accounts, data centers or air-gapped network. DeployOpen sets the JPA server configuration, loads the Library resources and value sets, and wires the evaluation path to your stored patient data. The test plan is the part most often underspecified. It should include CQL compilation checks, evaluation against a fixed set of synthetic patients with known expected results, and comparison of outputs against reference results your clinical informatics team accepts. Handover includes the runbook, the configuration record, the test evidence and a list of what your team must confirm with the vendor, such as the behavior of the CQL engine version your release bundles.
DeployOpen prepares evidence for compliance reviews, including configuration records, access control settings, test results and operating procedures, so your compliance and security teams can assess the system. DeployOpen does not issue audit reports, attestations or certifications. Independent auditors and certification bodies make those determinations, and your organization should confirm early which controls a particular assessor expects to see.
How DeployOpen works on HAPI FHIR clinical reasoning
DeployOpen plans, builds and hands over CQL evaluation on a self-hosted HAPI FHIR JPA server inside your own infrastructure. The work starts with a written scope that names the libraries, data sources and tests your team needs, so your compliance and clinical informatics reviewers can check the result before it reaches production.
How we scope
- Inventory the CQL libraries, value sets and FHIR versions your logic depends on before any build work starts
- Confirm which patient data sources, partitions and clinical systems the evaluation will read from
- Agree the written scope, deliverables and timeline in writing before work begins, as most engagements are fixed-scope
How we build
- Deploy the JPA server starter with a supported production database in your environment, such as PostgreSQL or Microsoft SQL Server
- Load Library resources with CQL and their dependencies, then confirm the server evaluates them against stored patient data
- Test CQL logic against known patient cases in a non-production environment before any release to production
How we hand over
- Document the library loading process, version control approach and the steps to publish a new CQL release
- Provide test cases, expected results and evidence that your team can rerun after changes or upgrades
- Deliver access control, audit logging and configuration decisions so your security and compliance teams can review them
How we support
- Offer ongoing support, upgrades and continuous testing for the CQL setup as a retainer
- Plan HAPI FHIR version upgrades, including the Java requirement for your chosen release, before they reach production
- Ask your team to confirm the vendor and standards requirements that apply to your clinical data environment

