Update: mockups, findings, and why I think this needs to be in core
A few follow-ups since my original post: what it could look like, what I found in the code, a second use for the same idea, and a concrete plan. All patients, phone numbers and amounts in the mockups are made up, and nothing is built yet. The mockups use OpenEMR’s current light theme and Bootstrap 4, so nothing new is needed on the styling side.
1. What a Twig card looks like next to an LBF card
- Top left is the Demographics card as it is today (
renderer: lbf). It stays exactly as it is, and stays the default. - Top right is a Twig card (
renderer: twig) that a practice laid out for a quick look: language and interpreter, cell phone and SMS consent, email, portal status, PCP, pharmacy, last and next visit, insurance eligibility and balance. It pulls from several services (patient, insurance, appointments, billing), and anything the user isn’t allowed to see is removed before the template gets it. - Bottom left is the same card in edit mode after a failed save. Only the fields the card displayed can be saved; address, insurance and balance are read-only here. More on saving in section 3.
- Bottom right is everything the practice edits: one template file and one line in the dashboard config. LBF, Twig and built-in cards can sit side by side.
LBF is great for data entry and for practices that already have their layouts set up; this just gives a second option for cards that are mostly about display.
2. This can’t be done as a module
My original post suggested starting as a module. After looking at the code, that won’t work for the main goal. In demographics.php, core dispatches SectionEvent('primary') and then adds its own cards (Demographics, Billing, Insurance) after listeners have run. SectionEvent only has addCard(); it can’t remove or replace a card. So a module could add a Twig card next to the LBF Demographics card, but could never replace it or let a site choose LBF or Twig per card. That requires a change to how core builds the dashboard.
3. Saving: the LBF save vs PatientService::update()
Templates never write anything. A Twig card’s save goes through fixed PHP code: CSRF and patients/demo write check, accept only the fields the card displayed, validate with PatientValidator, save with PatientService::update() (the same path as the REST API).
Comparing that with the LBF save, the two are closer than I expected. updatePatientData() (the LBF save) already calls PatientService::databaseUpdate(), so both share the same SQL, audit logging and BeforePatientUpdatedEvent / PatientUpdatedEvent. The API’s update() method validated with PatientValidator (the LBF path doesn’t), but it wrote its own update instead of calling databaseUpdate(), which left three gaps:
- it didn’t set
updated_by, so patient edits made through the REST/FHIR API didn’t record who made them - it skipped the portal-username fix-up that
databaseUpdate()does - its
PatientUpdatedEventpayload was shaped differently (the “after” data was a list of records, which breaks listeners such as the telehealth module’s patient registration)
That’s an API bug whether or not this proposal goes anywhere, so I created a PR to fix it: PR #15459 makes update() validate and then save through databaseUpdate(), so the API and the demographics form now behave the same. With that fix, a Twig card can save through update() and get validation plus everything the LBF save does.
Also, demographics_save.php fires PatientUpdatedEventAux with the raw form data (Weno uses this for pharmacies), and saves addresses, phone numbers and relationships through their own services. Twig cards would leave those fields read-only at first.
4. Twig sandbox security
Twig’s sandbox had a number of bypass CVEs in 2024–2026, all fixed by 3.27; OpenEMR is on 3.30.0. To keep the risk low:
- a separate Twig environment and cache for user templates, sandbox always on, strict mode enabled
- templates get only plain data, no service objects or methods
- a small allow-list: no
raw, no callable filters - data filtered by permission before rendering
- templates as files on disk only at first
5. A second use: the day’s schedule, outside the calendar
This isn’t only about dashboard cards. As part of the Visit List calendar work (calendar changes proposal), I’m planning a Daily Schedule window: one provider, one date, every patient in order, with what the front desk and the provider need at a glance. Here it is for a regular clinic day:
Visit type and reason, insurance eligibility, copay and balance, alerts (allergies, overdue labs, referral or prior auth needed, intake forms), status with room and wait time, and the next appointment. Open slots have a Book button, and status and reason can be changed right there, then saved together with Update.
The Template dropdown is the point: a front desk wants insurance and balances, a nurse wants rooming and alerts, a provider wants the reason and history. Each is a different template over the same data, and the PDF button renders the same template, so the screen and the printout match.
And the same page for a practice that does home visits:
Visit order, stop numbers (two patients at one address share a stop), address and phone for routing, gate codes and other patient notes, practice-specific flags, status, follow-up interval and next appointment. There would also be a Total Schedule window covering a date range and several providers (for example, sorted by ZIP for routing home visits).
Every practice wants these pages laid out differently, so it’s the same problem as the cards, and it works the same way:
- templates in
sites/<site>/templates/schedule/, with a shipped default - the controller loads the data in a few batched queries, with permissions and provider/facility scope already applied, and passes it as plain data
- the template can lay out, sort, group and format that data, but can’t fetch anything else or save
- practice-specific fields (flags, patient notes) come from fields the admin picks, so core never hard-codes them
- sensitive fields (SSN, insurance IDs) appear only if the admin turns them on for that template
- editing (status, appointment comment, visit order, follow-up interval) goes through one fixed controller that checks permissions and saves through the services
With two features needing the same thing, I think the sandboxed renderer belongs in core as shared infrastructure, not inside either feature.
6. Proposed plan: small core PRs, each useful on its own
- Fix
PatientService::update()(updated_by, portal fix-up, consistent event payload). A bug fix for the API regardless of this proposal. Done: PR #15459, waiting for review. - Allow dashboard cards to be replaced or removed through
SectionEvent, with core cards added before the dispatch. Useful for modules too; no change for users. - A shared sandboxed template renderer in
src/Common/Twig/, with tests. Used by both the dashboard cards and the schedule windows; letters and portal document templates could use it later. - A field list and read-only patient data object in
src/Patient/, with tests. - A template-based card type (
TemplateCard extends CardModel) that loads templates from a per-site folder, off by default behind a global setting, with one example template. The LBF Demographics card stays the default. - Dashboard configuration to choose LBF or Twig per card.
- Edit mode for simple
patient_datafields through the fixedPatientService::update().
Nothing changes for existing sites unless an admin turns it on, and PRs 1 and 2 don’t involve Twig at all.
7. Questions
- Practices: would you use cards or a schedule page like these? What would you put on yours?
- Maintainers: before I put real time into PRs 3–7: if this were built as a series of small core PRs like the above, off by default and with LBF cards unchanged, would you be open to accepting it into core, including a shared sandboxed template renderer used by both the dashboard cards and the schedule windows? PR 1 is already up; I’m happy to do PR 2 next if that looks reasonable on its own.
Thanks.
— David


