Generating PDFs with Medplum Bots

Medplum Bot PDF templates produce CMS-1500 forms, superbills and letters from FHIR data. This page covers how the pieces fit, what to configure, and what to confirm before you rely on them in a self-hosted deployment.

On this page

Generating PDF documents with Medplum Bot PDF templates

A team that needs CMS-1500 claim forms, superbills or patient letters built from FHIR data inside a self-hosted Medplum deployment has a direct path: Medplum lists Bot PDF templates for CMS 1500 and superbill documents, and the generated file is stored as a FHIR Binary resource. The decision to make first is whether those documents should be produced inside Medplum at all. Building PDFs in Medplum keeps the source data, the generation logic and the stored output under one set of access controls, audit trails and deployment boundaries, which is often easier to justify to a compliance reviewer than copying patient data into a separate document system. It also means the Bot that renders the document runs under the same identity and permissions model as the rest of your integrations.

Be clear about what the template work includes. The CMS 1500 and superbill templates are a starting point, not a finished product for your payers, practice or letterhead. Each document requires mapping FHIR fields such as Patient, Coverage, Practitioner, Organization and Claim or Encounter data to the positions and values on the form, and a review of which fields are mandatory for your use. Patient letters are less standardized, so the template, wording, branding and any clinical or legal review are work your team owns or contracts out. Plan for template changes whenever a payer, a form revision or your own policy changes, and confirm with your vendor what Medplum-supplied templates cover today before you scope the work.

Decide the security context of the output before the first Bot runs. The stored Binary carries a securityContext reference that determines which patient compartment or access policy can read the document, so a letter stored with the wrong reference may be visible to users who should not see it. Confirm how the securityContext is set in your template or Bot code, which roles can read Binary resources in your project, and whether the output must be reviewed in an audit log. Test with a non-production project using synthetic patients first, and review the access policies in Medplum's compliance documentation for how shared responsibility applies to your deployment.

How a PDF request moves from FHIR data to a stored Binary

A request starts with a trigger, such as an API call, a Subscription or a custom operation, and invokes a Bot on the Medplum server. The Bot reads the FHIR resources it needs under its access policy, renders the document from a PDF template, and writes the result back as a Binary. The trust boundary sits between the Bot runtime and the Medplum server, so confirm which identity the Bot runs as, what it can read, and which securityContext the Binary carries before the document is released.

Trigger, Bot, template and Binary storage, with the Bot runtime boundary marked.

Which document type and trigger fit your workflow

This table compares the document types and the ways to invoke a Bot that renders them, so you can match each to a workflow. Read each row for when it fits, the data it needs and what to confirm about template coverage before committing to a design. The main takeaway is that the trigger choice shapes who runs the Bot and with which access, so decide that alongside the document type.

OptionWhen it fitsData it needsWhat to confirm
CMS-1500 claim formGenerating paper or payer-facing claim forms from billing resources for a claims workflowPatient, coverage, provider, encounter and charge data as FHIR resourcesThat the Bot PDF template matches the CMS-1500 version your payers accept and your field mapping
SuperbillGiving patients an itemized receipt of services for out-of-network or self-submitted claimsEncounter, practitioner, organization, fee and diagnosis dataTemplate field coverage for your practice's billing codes and required provider identifiers
Custom letterPatient notices, appointment letters or payer correspondence where no bundled template existsThe FHIR resources you choose to merge into the letter, such as Patient, Appointment or CommunicationThat you build and maintain the template yourself, and who approves wording and clinical content
Manual Bot callStaff trigger generation from a chart or claim screen on demand, with low volumeResource ID passed as input at call timeWhich user identity runs the Bot and whether that user can read every resource in the template
Subscription triggerDocuments should appear automatically when a resource reaches a status, such as a finalized encounterResource change payload plus any referenced resources the Bot readsThe Subscription criteria, the per-project limit, and how failed runs are retried and logged
Scheduled Cron triggerBatch runs, such as end-of-day superbills or weekly patient lettersQuery or input defined on the Cron resource for the batch windowWhich identity the schedule uses, how skipped runs are detected, and where output is reviewed
Custom operationA system or app calls a documented FHIR operation to request a document on demandOperation parameters validated against the OperationDefinitionThat the operation stays FHIR conformant and that callers hold permission to invoke it

Setting up a PDF Bot in a self-hosted Medplum project

This sequence takes a self-hosted Medplum project from a confirmed version and Bot runtime to a tested PDF Bot that writes its output as a Binary with a deliberate securityContext. Each step ends with a check you can repeat before anything reaches production.

  1. Confirm the Medplum version and Bot runtime

    The platform or infrastructure owner records the Medplum server version running in the self-hosted deployment and confirms which Bot execution runtime is configured, such as the Medplum-managed AWS Lambda path or an external runtime. Check the version against the upgrading and release documentation so you know the Bot features you plan to use are present. The step is done when you can name the server version, the runtime and the non-production project where testing will happen, and the team has written them down in the implementation record.

  2. Create the Bot and its access policy

    A developer creates the Bot in the non-production project and gives it a dedicated access policy that allows only the resource types it needs to read, such as Patient, Encounter, Coverage or Practitioner, and permission to create Binary resources. Avoid reusing a broad administrator identity for the Bot. The step is done when the Bot exists, has a memberships or access policy record, and a test request made as that identity can read the input resources but cannot touch unrelated data.

  3. Load or build the PDF template

    Choose the document type the workflow produces. Medplum lists Bot PDF templates for CMS 1500 and superbill documents, so start there if they match your need, and confirm with your forms and billing owners that the template layout and field mapping are current. For other letters or forms, a template must be designed and validated against a sample document with your compliance and clinical reviewers. The step is done when a blank or sample template renders in the test project and the team has a field-by-field map from FHIR data to printed fields.

  4. Write the Bot to read FHIR inputs and create the Binary

    A developer writes the Bot to take a trigger input, such as an Encounter or Claim ID, read the required FHIR resources through the Medplum client using the Bot's identity, populate the template fields, generate the PDF, and create a Binary resource containing the output. Handle missing or incomplete data explicitly so the Bot fails with a clear error rather than producing a partly filled form. The step is done when a manual invocation with sample data returns a Binary reference and the output matches the field map.

  5. Set the securityContext on the output

    The developer sets the securityContext on the Binary so it points to the Patient or other subject the document describes, which governs who can read it through access policies. Confirm this with your access control owner against the project's binary security settings before go-live, since an incorrect reference can expose a document or hide it from the people who need it. The step is done when a user with the intended access can open the Binary, and a user without it, including the Bot identity used for other work, cannot.

  6. Test with sample data in a non-production project

    Run the Bot against synthetic or de-identified sample patients and claims in the non-production project, including edge cases such as missing diagnosis codes, multiple payers and long names that overflow fields. Compare each rendered PDF with the expected output and inspect the Bot's logs and AuditEvents for the executions. The step is done when a test document renders correctly for every case, the Binary and its access match the design, and the results are recorded so the same tests can be repeated before any promotion to production.

Choosing the securityContext for generated Binary resources

A generated PDF often contains protected health information, so the securityContext on the Binary decides who can read it. The Bot should set this field deliberately in its code instead of accepting whatever default the write produces. Treat the choice as a design decision for each document type: a superbill for a patient visit, a CMS-1500 claim form and a letter to a patient each carry different people who legitimately need to see them. Record the decision in the Bot's design notes so reviewers can check it later.

Link the Binary to the resource it documents. A superbill or CMS-1500 form should reference the Patient, and where the document supports a claim, the related Claim or Encounter, so that access to the record and access to the file follow the same path. Confirm in your own environment which resource types your access policies can reference when evaluating a Binary, because a link that no policy recognizes gives reviewers nothing to test. Keep the Binary's identifiers and subject references consistent with how your other clinical documents are filed, so that a search for a patient's documents returns the PDF.

The securityContext works together with your access policies and project configuration, so it is only as strict as the rules that read it. Before going live, test that a user without rights to the related Patient or Claim cannot retrieve the file by its Binary ID, and that a user who should have access can. Run the same check with the Bot's own membership, since a Bot that generates documents may have broader rights than the people it serves. The wider model of projects, access policies, tenants and binary security is covered in the access control guidance for Medplum, which should be the reference for the full set of rules.

Security and operational risks in generated documents

Generated PDFs carry the same protected health information as the FHIR resources they are built from, so the risks sit in the data path: what goes into the template, who the Bot runs as, where the output lands and what gets logged. Each card below is a point to design and verify in your own self-hosted deployment before claims, superbills or letters go to patients or payers.

PHI in outputs and logs

A CMS-1500 or superbill contains patient names, identifiers, diagnosis and procedure codes and payer details. Check what the Bot writes to its console and execution logs, what error messages include when a template fails, and whether any intermediate data is written to disk or a queue on the host. Confirm that logs carry resource IDs rather than document content and that your log platform's retention and access rules match the PHI you generate.

Medplum integration docs

Bot run-as identity and privilege

A PDF Bot reads Patient, Encounter, Coverage and Practitioner resources, so its identity determines what a generated document can contain. Decide whether the Bot runs as a dedicated integration identity with narrow access policies or inherits the caller's rights. Review every Bot membership in each project, because a Bot with broad read access can assemble documents for patients the requesting user should never see.

Template and data version drift

A CMS-1500 template revised after a payer or form change, or a superbill layout edited in one project but not another, produces documents that differ from earlier ones for the same encounter. Record which template version and Bot version produced each output, and keep templates under the same change control as Bot code. Without that record, a reissued claim cannot be matched to the form that originally went out.

Binary storage and retention

Each generated PDF is stored as a Binary, and its securityContext decides who can read it. A document saved with a weak or missing security context can be reached through the Binary endpoint by users who never should see it. Confirm the access policy on the Binary, the retention period your records policy requires, and how superseded or voided documents are removed from storage and any backups you keep.

Audit trail of generation events

Regulators and payers may ask who generated a claim, when, from which data and whether it was sent. Confirm that each generation event is captured with the requesting user or Subscription, the Bot version, the source resource versions and the resulting Binary reference. Check that AuditEvent records are retained in your self-hosted database and included in your backup and restore tests, not left to default settings.

Shared responsibility for compliance

Medplum states that compliance is a shared responsibility between Medplum and its customers. On a self-hosted deployment, your organization owns the hosting, backups, access reviews, logging configuration and template governance behind every generated document. Ask your compliance team to map each control for document generation to a named owner, and confirm with your assessor which evidence they will request.

Medplum compliance docs

Questions buyers ask about PDF generation with Medplum Bots

What drives the cost of generating PDFs with Medplum Bots?

The main cost driver is how many distinct documents you need and how closely each must match an existing paper or payer form. A CMS-1500 claim form, a superbill and a set of patient letters each require a template, field mapping from FHIR resources, and layout checks. Costs rise with the number of templates, the number of data sources feeding each one (Patient, Encounter, Coverage, Practitioner, Organization), and the number of rounds of review by clinical, billing and compliance staff. Ask any partner for a quote that lists templates separately, states which form versions are included, and separates the one-time build from any ongoing template maintenance.

How long does a first PDF template take to validate?

The duration depends on the team, the number of templates in scope and how quickly sign-off happens. A single letter with clean source data is usually far quicker to validate than a form like the CMS-1500 that must be checked field by field against a current specification and real claim examples. Delays most often come from waiting for sample data, from disagreements about how a field should be populated, and from reviewers who need several passes. Ask for a written timeline that shows the validation steps, who signs off each one, and what happens if a reviewer finds a mismatch.

What does the work need from our team before it starts?

The work needs three things from your side: representative sample data, the exact form versions you must produce, and named sign-off owners. Sample data should include both typical records and edge cases, such as missing secondary insurance, multiple diagnoses or patients with long names, so the template is tested beyond the happy path. Form versions matter because a template built for one revision may not match another, so confirm which versions your payers or regulators accept. Sign-off should name who approves layout, who approves field logic and who approves the final output before it is stored as a Binary.

Can an in-house team build PDF templates on Medplum without a partner?

An in-house team can build PDF templates if it has engineers comfortable with TypeScript and Medplum Bots, and billing or clinical staff who can define the field rules. The harder part is usually not the code but the validation: someone must confirm that every mapped field matches the form specification and the source data, and that a reviewer can trace each value. Teams often underestimate how much time that review takes and how many revisions a claim form needs. A partner is most useful when the scope is fixed, the deadline is firm or the team lacks prior experience with healthcare forms. Decide based on skills, review capacity and how often you expect to change templates.

How are PDF templates kept working across Medplum upgrades?

Templates should be version-controlled with the Bots that render them, and every Medplum upgrade should include a regression run that regenerates sample documents and compares them with approved outputs. Medplum requires self-hosted deployments to move through each minor version in sequence, so the template tests should run at every step rather than only at the end. Keep a record of which Medplum version and which form revision each approved template was validated against. Confirm with Medplum's upgrading guide and release notes what changed in the PDF tooling before you apply the upgrade to production.

Where should generated PDFs be stored, and what security settings do they need?

Store each generated PDF as a Binary resource and set its securityContext so that only the users and Bots that need the document can read it. Access depends on the Binary's securityContext and on the project's access policies, so test that a user without the right role cannot retrieve a claim form or letter. Document who can read, replace or delete these Binaries, and whether the retention period follows your records policy. Confirm the exact configuration against Medplum's access control documentation for your version before going live.

What compliance evidence should a PDF workflow produce?

A PDF workflow should produce evidence that each template was validated, approved and tested after changes, and that generated documents are stored with controlled access. Keep the approval record, the sample data used for testing, the template version and the Medplum version in use together. Medplum's compliance documentation describes compliance as a shared responsibility between Medplum and its customers, so your own records must cover the template logic and access settings you control. Ask your compliance team which of these records they need and how long they must be kept.

Who builds, tests and maintains the documents

The client's team should own the decisions that determine what a generated document says, and an implementation partner typically carries the engineering that makes it happen. In practice, the split usually looks like this: the client's billing or clinical staff define the content of each CMS-1500 form, superbill or letter, the client's engineers confirm which FHIR resources and fields feed each template, and the partner builds the Bot code, the template mapping, the Binary storage logic and the test fixtures. Access policies are a shared job. The partner can draft the Bot membership and access policy that lets the Bot read the Claim, Encounter or Patient data it needs and write the resulting Binary, but the client's security team should review that scope against least privilege before go-live.

Validation is where the client's domain staff carry the most weight. Billing staff should check claim forms field by field against a known good output, and clinical staff should check letters and superbills for wording, required identifiers and provider details. Ask the partner to deliver sample inputs and expected outputs as part of the build, and confirm that the client's staff, not the partner, approve each template version. Also confirm who reviews the generated PDFs against the payer or regulatory rules that apply to them, because Medplum's compliance documentation, which describes its compliance coverage, states that compliance is a shared responsibility between Medplum and its customers.

Maintenance is recurring work that is easy to underestimate. Each Medplum upgrade can change Bot runtime behavior, dependencies or the way Binaries are served, and every change to a payer form or letter requirement means a template change and a new validation cycle. Agree in writing who runs regression tests on the PDF Bots after each upgrade, who owns template version changes, and how long the partner remains responsible for fixes. Quotes should separate the one-time build from the ongoing retainer, and should state whether the partner will re-validate templates against the client's own sign-off criteria after each change.

How DeployOpen scopes PDF generation work

Each PDF engagement is scoped as fixed work with deliverables agreed in writing before build starts. The cards below cover the decisions that set that scope, from which documents and data are in play to how the Bots are tested, handed over and maintained after go-live.

Document types and layouts

Start by listing every document the Bot must produce, such as CMS-1500 claim forms, superbills or patient letters, and which Medplum Bot PDF templates cover each one. Confirm which templates your Medplum version supports and where a document needs a custom layout. Each document type adds template design, field mapping and review effort, so the list drives most of the scope.

Medplum integration docs

Source data and field mapping

Map every template field to a FHIR path in Patient, Encounter, Coverage, Practitioner, Organization or Claim data. Record which fields are required, which come from more than one resource, and how missing values are handled. Ambiguous mappings, such as billing versus rendering provider, are the most common source of rework, so settle them with the billing or records owner before build.

Bot design and output storage

Define how the Bot is triggered, whether by a request, a Subscription or a custom operation, and what it writes back. Decide the Binary storage pattern and the securityContext that controls who can read the generated document. Confirm that the Bot's access policy and run-as identity can read the source data but cannot widen access to the stored PDF.

Testing with representative data

Agree a test set with synthetic or de-identified records that covers complete claims, partial records, multiple payers and long line-item lists. Check rendered output against the approved template, and confirm that failed renders produce a clear error rather than a blank document. Testing scope should be written into the agreement so acceptance criteria are clear.

Handover and runbook

At handover, your team receives the Bot source, template files, mapping documentation, configuration and a runbook for changing a field or adding a document type. Confirm who holds the repository, secrets and project admin rights after go-live. A written runbook keeps later changes from depending on the original builders.

Ongoing template maintenance

Document layouts, payer forms and Medplum releases change over time. DeployOpen offers retainers that cover template maintenance and upgrades, so changes and upgrade testing are handled under an agreed arrangement rather than ad hoc. Ask what a retainer includes, how change requests are priced and how Medplum upgrades are tested against the Bots before they reach production.

How DeployOpen delivers and supports Medplum PDF generation

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own infrastructure, including the Medplum server and the Bots that generate documents on it. For PDF generation, that means the work runs in your cloud account, data center or air-gapped network, against your Medplum project, with your identity provider and your logging. The delivery team builds the Bots that fill the CMS-1500, superbill and letter templates from FHIR data, and it writes the code that stores each output as a Binary with the securityContext your access model requires. Nothing is handed to a DeployOpen-hosted service.

Before handover, the team tests who can read the generated Binaries. That includes checking that a patient, a clinician, a billing user and a Bot identity each see only what their access policies allow, that the securityContext on each Binary matches the intended compartment, and that direct URL access to a Binary is blocked for users outside that compartment. The team also tests failure paths, such as incomplete source data and a template that does not render, so that you know what the system does before a claim or statement is sent. Your security and compliance staff should confirm the exact Binary security settings they require, because those depend on your data classification and your own policy.

DeployOpen hands over runbooks covering Bot deployment, template changes, secrets rotation, troubleshooting failed renders and how to reproduce a document from its source resources. DeployOpen prepares systems, controls and evidence for compliance assessments, such as configuration records and access test results, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies make those determinations. Medplum's compliance documentation states that compliance is a shared responsibility between Medplum and its customers, so ask your assessor which PDF controls they expect you to evidence. Ongoing support, upgrades and continuous testing are available as retainers, and engagements are fixed-scope with written deliverables agreed before work starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.