When CDS on FHIR with PlanDefinitions fits your decision support program
This section is for a team that needs clinical decision support delivered into EHR workflows and wants the logic stored as FHIR content rather than hard-coded in service code. A PlanDefinition is a FHIR resource that describes a care process: the conditions that matter, the actions to take, and the rules that choose between them. The $apply operation takes a PlanDefinition, a patient context and a set of inputs, evaluates the referenced logic, and returns a request-level result such as a CarePlan, RequestGroup or set of proposed resources. CDS Hooks sits in front of that flow. An EHR fires a hook such as patient-view or order-select, the CDS service receives the context, and the service returns cards that the clinician sees in the workflow. When the service is built on PlanDefinitions, it calls $apply and turns the result into cards, so clinical owners can change the content without changing the service code.
Choose this approach when the decision logic changes often, when several services need to share the same rules, or when clinical informaticists, not developers, must be able to review and version the content. Writing services directly is usually simpler when the logic is small, stable and tied to one EHR integration, because every extra FHIR resource is another artifact to test and keep in sync. Confirm early which hooks your EHR supports, which CDS Hooks version it implements, and whether the logic needs CQL, which affects the libraries you must load (see the sibling topics on CQL and CDS Hooks services).
This page does not cover clinical validation, certification or regulatory classification of decision support software. Those obligations depend on your jurisdiction, product claims and intended use, and they should be confirmed with your regulatory and clinical governance functions. The clinical content, its evidence base, approval workflow and ongoing review remain your organization's responsibility. DeployOpen can build, test and operate the FHIR and CDS infrastructure, but it does not decide what the guidance should say or whether it is safe to deploy.
How an EHR hook reaches a PlanDefinition through $apply
The sequence starts when the EHR fires a CDS Hooks request at the hook endpoint, which runs on the HAPI FHIR server. The EHR sends prefetch data with the request, or the service fetches it from the FHIR data store under its own credentials. The service then calls PlanDefinition $apply, which resolves the referenced Library and evaluates the CQL against the patient data. The service turns the result into CDS cards and returns them to the EHR. Check the trust boundary: the EHR, the hook endpoint and the FHIR data store sit in different trust zones, so authentication, scopes and audit logging must be designed at each crossing.
Hook request flows through PlanDefinition $apply to CDS cards across trust boundaries.
What PlanDefinition, Library and CQL each contribute to a decision support service
Each artifact in a CDS on FHIR service has one job, and mixing those jobs is the most common source of rework. The PlanDefinition describes the decision support pathway: which trigger starts it, which conditions must hold, and which actions follow. Its action entries can point to a condition expressed as a CQL expression and to a dynamicValue that sets fields on a proposed resource. The PlanDefinition does not hold the logic itself. Treat it as the contract that a clinical content owner reviews, because it answers the question of what the service is supposed to do and when.
The Library resource holds the CQL that decides applicability and produces values. It defines the patient context, the data retrieved from FHIR, and named expressions such as whether an eligible patient meets a criterion. The PlanDefinition refers to those expressions by name, so a change to a threshold belongs in the Library and its version, not in the pathway. Keep the CQL logic, its FHIR model and terminology dependencies declared in the Library so that a reviewer can trace each decision to a single expression. Loading and evaluating Libraries on the server is covered in the sibling topic on running CQL on a HAPI FHIR server.
The service layer is the code that receives a CDS Hooks request, evaluates the PlanDefinition through $apply where your design uses it, and maps the resulting request or action into CDS Hooks cards or system actions. This layer owns the hook wiring, prefetch and the response shape, so confirm the exact resource profiles, extensions and service wiring against the HAPI FHIR and CDS Hooks documentation for the version you run. Ask your implementation team to show, for one sample patient, the path from each card back to a named CQL expression and a versioned PlanDefinition.
Which publishing approach fits each decision support service
This table compares three ways to publish decision support on a HAPI FHIR server: PlanDefinition applied through $apply, a hand-written @CdsService method, and a hybrid. Read each row against the service you are planning, then check the testing and audit trade-offs with the engineers who will maintain it.
| Decision point | PlanDefinition through $apply | Hand-written @CdsService method | Hybrid: service plus stored PlanDefinitions |
|---|---|---|---|
| When it fits | Pathway logic that clinical informaticists want to read, version and reuse as FHIR resources, with CQL-backed conditions | Logic that needs custom code paths, external calls or behavior a PlanDefinition cannot express clearly | Several pathways that share one hook entry point, where the hook handling differs from the clinical rules |
| Who maintains the content | Clinical informatics or content authors editing PlanDefinition and Library resources, with engineers owning the server | Developers who write and review Java, with clinical reviewers signing off on the rules in code | Developers own the hook service; clinical authors own the stored pathways it calls |
| How changes are released | Publish new PlanDefinition and Library versions to the server; confirm your approval step before activation | Ship a new build of the service through your normal application release process | Hook code changes through application releases; pathway changes through resource versions |
| Testing effort | Test CQL and PlanDefinition outputs against sample patients; fewer code tests but more data-driven cases | Unit and integration tests cover each rule path in code; effort grows with each branch | Two test tracks: code tests for hook behavior and resource-level tests for the pathways |
| Auditability | Stored resource versions show what logic ran; confirm that your audit setup records the resource version used | Logic lives in source control; audit depends on build records and logging you add yourself | Pathway versions are recorded as resources, while code versions need matching build traceability |
| Main trade-off | Easier review and versioning of clinical logic, with limits on what the pathway language can express | Full flexibility, with clinical logic harder to review outside engineering | Clear ownership split, but two release tracks must stay aligned |
Build sequence for publishing a PlanDefinition as a CDS service
This sequence takes a team from a confirmed HAPI FHIR version to a CDS Hooks service that evaluates PlanDefinitions through $apply, with a check at each step so problems surface before any clinician sees a card.
Confirm the HAPI FHIR version and JDK requirement
Pick the HAPI FHIR release and FHIR version you will run, then confirm the Java runtime it requires. The HAPI FHIR versions documentation states that 8.2.0 requires JDK 17, and the release line you choose should be checked against that page before anything is built. Record the chosen version, JDK and FHIR version in the project's decision log, because the CQL engine, $apply behavior and CDS Hooks libraries all depend on them. Done when the build pipeline compiles against the recorded JDK and a version lock file is committed.
Deploy the JPA server with a production database
Deploy the hapi-fhir-jpaserver-starter in your infrastructure, using PostgreSQL or Microsoft SQL Server rather than the embedded H2 default, since the starter documentation lists those two for production and does not support MySQL. The platform team owns the database, backups and network placement, and the application team owns the server configuration. Done when a test client can create and read a Patient resource through the base URL and the metadata endpoint returns the FHIR version you recorded in step one.
Load Library and PlanDefinition resources
Load the CQL Library resources, their ELM and value set dependencies, and the PlanDefinition resources that reference them. Use a versioned load process from source control so every server environment receives the same content. Check that each Library has a version and status, and that the PlanDefinition's library reference resolves on the server. Done when a GET on each PlanDefinition returns a 200 response and the referenced Library resolves without errors in the server log.
Verify $apply output on test patients
Call PlanDefinition/$apply for a set of synthetic test patients chosen to hit each branch of the logic, including patients who should trigger no recommendation. Compare the returned RequestGroup against expected output that clinical and informatics reviewers signed off on. Confirm that the action conditions, dynamic values and referenced resources match. Done when every test case returns the expected RequestGroup, and any mismatch is logged as a defect against a specific Library version before the next step begins.
Implement and register the CDS Hooks service
Write the CDS Hooks service that accepts a hook request, calls $apply on the PlanDefinition, and maps the RequestGroup into CDS cards. The HAPI FHIR CDS Hooks support provides the service annotations used to declare the service and its prefetch template. Register the service so the discovery endpoint lists the hook, its id and its prefetch requirements. Done when the discovery response shows the expected service and a direct call with a sample hook request returns cards that match the step four output.
Configure prefetch and confirm data access
Define the prefetch queries the service needs so the EHR sends only the resources the PlanDefinition reads, and confirm that auto-prefetch does not pull more data than the logic requires. Compare the prefetch bundle against the data elements the CQL uses. Done when a hook request built from the prefetch template produces the same card as one where the server fetches the data itself, and no extra resource types appear in the request log.
Test the hook with an EHR sandbox
Connect the registered service to an EHR sandbox that supports CDS Hooks, and fire the hook for each test patient in the sandbox. Confirm the card renders, the suggested actions appear as expected, and the feedback or response callbacks reach your server. Record the sandbox name and version used. The sandbox must be confirmed with your EHR vendor, since capabilities differ. Done when every test patient produces a card that matches the expected output, and the sandbox test record is attached to the release.
Enable audit, access controls and version management before go-live
Before any clinician sees a card, enable the authorization and audit controls for the CDS service and the FHIR server, using the AuthorizationInterceptor and BALP audit logging as building blocks that your security team configures. Confirm that only authorized callers can invoke the hook and that every $apply call is logged. Set a rule that Library and PlanDefinition changes go through review and a new version before deployment. Done when a test call without credentials is rejected, the audit log records the test invocations, and the version record for the released content is stored.
How to manage versions of decision support content over time
Every PlanDefinition and Library that a CDS service depends on needs an explicit version and a status, and the two must be read together. The status tells you whether a resource is a draft, active or retired, and only resources in an approved state should answer live requests. A change should move through the same path every time: a draft is authored and reviewed, approved by the clinical owner who signs off on the logic, published as active, and later retired once a replacement is live. Retired content stays on the server so that past responses can still be traced to the logic that produced them. Record who approved each transition and why, because auditors and clinical governance committees will ask for that history before they ask for the CQL itself.
A running service should be able to say which version answered a request. In practice this means the response's card or action should carry enough identifying detail (the PlanDefinition's canonical URL and version, and the Library versions it references) so that a clinician complaint or an incident can be traced back to exact content. Keep the CQL and the FHIR JSON or XML for each release in a source-controlled repository, tagged with the same version strings the server reports. Test each version against a fixed set of patient cases with known expected outcomes, and rerun that suite before every promotion. A rollback plan should name the previous active version, the step that reactivates it, and who may trigger it.
Securing hook endpoints, patient data and audit trails
A CDS on FHIR service touches patient data on every call: the hook request, the prefetched resources, the evaluation and the card returned to the clinician. HAPI FHIR gives you building blocks for these controls, not a finished security layer, so each card below is a decision your team has to make and verify. Treat the server, the hook endpoints and the decision logic as one system with one owner.
Authenticating hook calls and the FHIR server
Decide how the EHR proves its identity when it calls your CDS Hooks endpoints, and how your CDS service authenticates to the FHIR server when it reads patient data or runs $apply. These are two separate trust relationships with separate credentials. Confirm which authentication interceptors your HAPI FHIR version supports, how tokens are validated and rotated, and whether service accounts are limited to the read and evaluation operations the PlanDefinition needs.
Authorization and search narrowing
HAPI FHIR's AuthorizationInterceptor decides which resources a caller may read, create or update. Consent and search narrowing interceptors can further limit what a request returns, so a CDS service only sees the patient records its role allows. Write the rules from the PlanDefinition's data requirements outward: list each resource type and search parameter the service needs, and deny everything else by default. Test with a caller that should be refused.
BALP audit logging for reads and evaluations
Audit every read that a CDS evaluation performs, plus the $apply call itself, so you can show who triggered a recommendation and which patient data informed it. HAPI FHIR offers BALP audit logging as a building block. Confirm that it records the evaluation requests and the prefetch reads, that logs go to storage your security team can query, and that retention matches your policy. Logs are only useful if someone reviews them.
Prefetch data and card content in logs
Prefetch payloads and the cards returned to clinicians contain protected health information, so default request logging can copy patient data into places it should not reach. Set logging levels so bodies and query strings are not written to application logs, and check error traces, metrics labels and reverse proxy logs for the same content. Ask your team to document where each category of data lands and who can read it.
Change control over decision logic
A PlanDefinition, its CQL libraries and its value sets determine what clinicians are told. Put them in the same review and release process as application code: version each Library and PlanDefinition, require sign-off from clinical and informatics owners, and record which version answered each request in the audit trail. Keep the ability to roll back a published version, and test changes against stored example patients before they reach the production endpoint.
Operator controls around the server
HAPI FHIR does not supply network segmentation, secrets management, backups, vulnerability management or incident response. Your organization must provide these around the server: TLS at the reverse proxy, restricted network paths from the EHR, a managed secrets store, tested database backups, patching on a planned schedule and a named owner for CDS alerts. Ask your security team to confirm which of these controls exist before the first hook is registered.
What buyers ask before building CDS on FHIR with a partner
What drives the cost and effort of a CDS on FHIR build?
The biggest driver is how many decision support services you need and how complex the clinical logic is. Each PlanDefinition, its CQL libraries, its CDS Hooks triggers and its prefetch needs add design, build and test work. Cost also rises with the number of EHR integrations, the number of clinical content owners who must sign off, and whether you need a repeatable release process. Costs that recur include hosting, monitoring, content maintenance and retesting after each HAPI FHIR or CQL change. Ask for the written scope to list services, hooks, data sources, environments and the sign-off steps that DeployOpen would support, so each cost line maps to a deliverable.
How long does a CDS on FHIR project take, and what sets the duration?
Duration depends mainly on the number of services, how much clinical logic must be authored and validated, and how many EHR environments must be tested. Clinical review cycles often set the pace more than engineering does, because logic changes need agreed clinical intent before code changes. Access to test patient data, identity setup and sandbox availability can also add waiting time. Ask any partner for a timeline tied to named milestones and to the dependencies you must clear, such as data access approvals and clinical reviewer availability. Treat any duration without a written scope as a guess.
What must our clinical and IT teams provide before the build starts?
Clinical teams must define the decision each service supports, the triggering workflow, the recommendation wording and the evidence the logic relies on. IT teams must provide a running HAPI FHIR JPA server or agree on its deployment, network paths to the EHR sandbox, service accounts, test patient data that the organization is allowed to use, and an identity provider for any authenticated access. Security and privacy staff should review data flows early. Put named owners for each item in the written scope so that delays are visible and assigned.
Can an internal team build CDS on FHIR without a partner?
Yes, if the team already runs a HAPI FHIR server, has CQL and FHIR skills, and can staff clinical review and testing. HAPI FHIR is open source under the Apache Software License 2.0, so no license fee applies to the software itself. The harder work is clinical governance, validation against the EHR, and keeping content current over time. Many teams split the work, building the core services internally and buying specific help such as a security review, sandbox testing or a release pipeline. Compare the internal headcount and skills you would need against a fixed-scope proposal from a partner.
How is testing against an EHR sandbox scoped?
Testing scope starts with the list of services, the hooks each one answers to, the EHR sandbox versions available and the test scenarios that matter clinically. A typical scope covers normal triggers, missing or partial data, duplicate or conflicting recommendations, error handling, and authorization for each request. Ask the partner which sandbox they will test against, who provides sandbox accounts, how test patients are created or selected, and how defects are reported and retested. Confirm whether clinical reviewers must approve test results and how much retesting is included in the fixed scope.
How are ongoing content updates handled after go-live?
Decision support content changes when guidelines, code systems or local policies change, so updates should follow a versioned release process. Each PlanDefinition, Library and CDS service version needs an owner, a change record, clinical sign-off, regression tests and a rollback path. The HAPI FHIR server must be upgraded on its own schedule, and each upgrade should be retested against the full set of services. Ask for the update process in writing, including how often content is reviewed, how emergency changes are handled and whether a retainer covers ongoing releases, testing and monitoring.
Limits to confirm in your environment before you commit
CDS on FHIR depends on several moving parts: the HAPI FHIR release, the JDK, the CQL and $apply features your content uses, the hooks your EHR actually sends, and the people who sign off on clinical logic. Confirm each of these against the vendor, the standards documentation or your own test environment before you commit to a design.
FHIR, CDS Hooks and CQL support
Confirm which FHIR version, CDS Hooks specification version and CQL support your chosen HAPI FHIR release provides. The JPA server covers DSTU2, DSTU3, R4, R4B and R5, but CDS Hooks and CQL behavior is set by the libraries and modules you add, so check the release notes and the CDS Hooks and CQL specifications for the exact versions. Record the versions in your design document so later upgrades have a baseline.
HAPI FHIR versions$apply and CQL feature coverage
List the PlanDefinition features your content depends on, such as dynamic values, nested action conditions, and the CQL functions and libraries they call. Then test each one on the release you plan to run, using a PlanDefinition that mirrors your real logic. Features that work in one CQL engine version may behave differently in another, so treat unsupported constructs as a blocker until a test proves otherwise.
JDK requirement for your release
Each HAPI FHIR release sets its own minimum Java Development Kit. HAPI FHIR 8.2.0 requires JDK 17, and the 8.8.2 release is newer, so confirm its JDK requirement in the release notes before you choose a base image or build pipeline. Mismatched JDK versions often surface only at startup, so verify the runtime in your staging environment rather than assuming the build machine matches production.
HAPI FHIR versionsEHR hook and prefetch support
Confirm with each EHR vendor which hooks it fires, such as patient-view or order-select, and which prefetch templates it honors. A service that asks for data the EHR will not supply forces slower FHIR queries at runtime, and an unsupported hook means the service never runs. Test the exact hook and prefetch combination in the vendor's sandbox before you agree on the service contract.
Clinical validation and sign-off
Decide who owns the clinical correctness of each PlanDefinition, who approves a change, and who confirms the output matches the guideline it implements. Engineering can verify that the logic runs, but it cannot establish that the recommendation is clinically appropriate. Write these roles into your change process, and confirm with your clinical governance and compliance leads what evidence they need before content goes live.
Maintenance of open-source dependencies
Check that every library and module in the path, including CQL engine components, CDS Hooks libraries and any custom interceptors, is still maintained and has a published upgrade path. Dependencies that stop receiving updates can leave you running logic on unpatched code. Review the project activity and release history before you commit, and record an owner and a review date for each dependency.
How DeployOpen works on this
DeployOpen plans, builds, tests and hands over CDS on FHIR work on a HAPI FHIR JPA server running in infrastructure you control. We start from the decision support content your clinical and informatics teams need, then agree the boundaries of the work in writing before any build begins.
How we scope
- We inventory the PlanDefinitions, Library resources and CDS Hooks services your clinical teams want to run.
- We confirm which HAPI FHIR version, JDK and database your environment will use before fixing the build plan.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
How we build
- We configure PlanDefinition $apply flows and CQL libraries on your HAPI FHIR server, with test data for each branch.
- We wire CDS Hooks services with authentication, the AuthorizationInterceptor and audit logging in your environment.
- We test services against an EHR sandbox and record results so clinical reviewers can trace each recommendation.
How we hand over
- We deliver versioned content, deployment configuration and runbooks for loading, updating and rolling back decision support.
- We document the version control process for PlanDefinitions and Libraries, including who approves a change.
- We walk your engineers and clinical informaticists through operation, testing and the upgrade plan.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Retainers can cover HAPI FHIR version upgrades, schema migrations and retesting of decision support content.
- Ask us to confirm the support boundaries, response expectations and change process in the written scope.

