Many healthcare products run on Node.js, and NestJS gives those teams a structured way to build backend services. When one of those services has to pull data from Oracle Health (Cerner) for several hospital customers, structure matters more than speed of the first demo.
This post is for backend engineers and architects building an integration service in NestJS. It covers how to lay out the modules, where queues and retries belong, how to stay inside rate limits, how to map Millennium data into your own model and how to test and monitor the result.
How do you build a Cerner EHR integration with NestJS?
Connecting your product to Oracle Health?
See how we plan and build EHR integrations that hold up across several hospital customers.
A Cerner EHR integration with NestJS is a backend service that calls Oracle Health FHIR APIs through one dedicated client module, runs the work as queued jobs with retries, respects each site's limits and maps the results into your product's own data model. Agnotic Technologies builds these services so each hospital is configuration, not code.
The goal is an adapter your product can trust. Product features should ask for data and get clean records back, without knowing how Oracle Health was called.
How should the NestJS modules be laid out?
Lay the service out as a few feature modules with narrow jobs: one talks to Oracle Health, one runs jobs, one maps data and one stores it. Each module hides its internals behind a small exported interface.
The NestJS documentation says every Nest application has at least one module, the root module, that most applications have several modules each encapsulating a closely related set of capabilities, and that a module encapsulates its providers by default.
- Oracle client module: authentication, HTTP calls, per-site limits and error translation, and nothing else.
- Jobs module: queue producers and consumers, retry rules and the dead-letter review queue.
- Mapping module: pure functions from FHIR resources to your model, easy to test without a network.
- Sites module: configuration for each hospital customer, such as base URLs, enabled resources and schedules.
Keep the Oracle client module free of product logic. When another EHR arrives, you add a sibling client module instead of untangling the first one.
Where do queues fit?
Queues sit between the triggers that ask for data and the workers that call Oracle Health. They turn bursts of requests into a steady flow the EHR and your service can handle.
NestJS provides the @nestjs/bullmq package for BullMQ queues, which persist job data in Redis so producers and consumers can run on one or more nodes, and its documentation lists smoothing out processing peaks as a reason to use queues.
- One queue per kind of work: patient refresh, bulk backfill and write-back each get their own queue.
- Small jobs: one patient or one small batch per job, so a failure affects little.
- Job data: ids and site keys only, never full patient records, because queue storage is another copy of PHI.
- Retention: completed and failed jobs are removed after a short, agreed period so Redis does not keep a history of patient activity.
Run workers as separate processes from the API that accepts product requests. A slow site then delays jobs, not every user of your product.
Backend authentication, briefly
A NestJS service that calls Oracle Health without a user present authenticates as a registered backend client, not as a person. The client module fetches a token, reuses it until shortly before it expires and requests a new one.
Oracle Health lets an application that has its own server making API requests register as a confidential client, and issues its secrets through a Cerner Central system account that is created when the application is registered in code Console.
Keep credentials in a secrets manager, scoped per site and per environment. The full SMART Backend Services flow, with signed assertions and key rotation, deserves its own design review before go-live.
How should retries work?
Retries should repeat only failures that may succeed later, such as timeouts, throttling and server errors, with growing delays between attempts. Errors that mean the request was wrong should fail at once and go to review.
- Retry: network timeouts, throttling responses and 5xx errors, with exponential backoff and jitter.
- Refresh then retry: an expired token, once, after fetching a new token.
- Do not retry: bad requests, missing resources and permission errors.
- Give up: after a set number of attempts, move the job to a review queue with its last error.
Make every job idempotent. A retried job that writes the same record twice should leave one record, keyed on the source system's id.
How do you stay inside rate limits?
Stay inside rate limits by giving each site a request budget in the client module and letting the queue pace jobs to fit it. Treat throttling responses as a signal to slow down, not as errors.
- Per-site budgets: each hospital customer gets its own limit, so one busy site cannot starve the rest.
- Concurrency caps: a small number of workers per site, raised only after watching error rates.
- Backfills off-peak: large historical loads run outside clinic hours where the customer agrees.
- Search over reads: one search returning many records beats many single reads.
Agree volumes with each customer before go-live. A sudden spike from your service looks the same as a fault to a hospital's integration team.
Mapping Millennium data into your model
Mapping turns FHIR resources from Oracle Health into the records your product uses, and it is where most data bugs hide. Keep it in pure functions with tests for every rule.
- Identifiers: store the source system and id beside your own id on every record.
- Codes: map local and standard codes to your terms, and log codes you have not seen before.
- Units and dates: normalize units and keep time zones explicit.
- Missing data: decide per field whether absence means unknown, not recorded or not shared.
Version the mapping rules and record the version on each stored record. When a rule changes, you can find and reprocess only the records the old rule produced.
Failure points in NestJS EHR services
NestJS EHR services usually fail in the plumbing around the calls rather than the calls themselves. These are the patterns to design out.
- God service: one class handles auth, calls, mapping and storage, so every change risks everything.
- PHI in queues: full records stored in job data and kept in Redis long after processing.
- Unbounded retries: a failing site receives thousands of repeated calls overnight.
- Shared limits: all sites share one worker pool, so one slow customer delays the rest.
- Silent drops: failed jobs expire without anyone reviewing them.
- Scattered mapping: translation logic spread across controllers, so one code maps differently in two places.
Each of these is cheaper to prevent in the first sprint than to fix with live hospital customers.
A worked example: a nightly lab sync
A worked example: a care management product needs recent lab results for enrolled patients at three hospital customers on Oracle Health. A scheduler adds one job per enrolled patient to the lab queue each night.
Workers take jobs within each site's budget. The client module searches lab observations since the last successful sync, the mapping module converts codes and units, and records are upserted on the source id.
At one site a burst of throttling responses slows the queue; backoff spreads the jobs out and the sync finishes later without errors. Two jobs fail on a permission error and land in the review queue for the site's analyst.
The next morning, the care team sees fresh results for every enrolled patient except the two under review, and the product marks those as stale rather than hiding them.
Who owns the NestJS service and each hospital link?
The service crosses your team and each hospital's team. Write the split into every customer's onboarding plan.
- Backend team: modules, queues, retries, mapping and monitoring.
- Hospital integration team: enabling the app, scopes, volumes and their own change windows.
- Product owner: which data the product needs and how fresh it must be.
- Security lead: credentials, queue data retention and access to logs.
Agree how each side reports an incident. When a hospital changes its configuration, your team should hear about it before jobs start failing.
How do you test and monitor the service?
Test mapping with unit tests, the client module against recorded responses and the whole flow against an Oracle Health sandbox. Then monitor jobs per site in production.
- Unit tests: every mapping rule, including missing fields and unknown codes.
- Contract tests: the client module against recorded sandbox responses, including errors.
- Load tests: queue behavior under throttling, using a stub that returns throttling responses.
- Monitoring: jobs queued, completed, retried and failed per site, with alerts on growth in the review queue.
Show these numbers to customer success as well as engineering. They are often the first to hear that data looks stale.
What are NestJS EHR integration best practices?
Split the service into small modules with one Oracle client module, run work as small idempotent jobs, keep only ids in job data and give each site its own budget and workers.
Retry only what can succeed later, map data in tested pure functions, keep credentials in a secrets manager and watch failed jobs per site.
How can Agnotic help build a NestJS EHR integration?
Agnotic builds NestJS and Node.js integration services for healthcare products: Oracle Health client modules, BullMQ job pipelines, per-site limits, mapping and monitoring. We also help onboard each hospital customer without code changes.
Build your integration backend with Agnotic
We design backend services that call EHRs safely and keep your product's data clean.
Related reading on Agnotic
Oracle Health integration, queues and API design.


