I’d like feedback on an idea for making the patient dashboard easier to customize without editing PHP or LBF layouts.
The problem
Today the Demographics card is drawn entirely by the LBF layout engine. Over the years, I have heard many complaints about the LBF engine, which has become a bit antiquated.
LBF works well as a configurable data-entry form, but it’s an awkward way to control what a dashboard card shows. A practice that wants a compact demographics card, a different field order, or just the handful of fields its front desk uses has to change the LBF layout, which also changes the full edit form, or edit core templates, which breaks on upgrade.
I would like to add another option for templating forms, which can then be used to customize any card (not just demographics), in addition to be used in other parts of OpenEMR.
I still want to keep LBF layouts and just add another option.
The Idea: Two Kinds of Cards, Side by Side
Each dashboard card would use one of two renderers:
- LBF card: exactly what we have today, unchanged.
- Twig card: a template file that controls both the view and the edit layout, and doesn’t use LBF at all.
A site can use all LBF cards (the default, nothing changes), all Twig cards, or a mix. For example, the standard LBF Demographics card next to a compact Twig contact card:
primary:
- { card: demographics, renderer: lbf }
- { card: contact, renderer: twig, template: contact.twig }
Templates go in a per-site folder (for example sites/<site>/templates/cards/), so they survive upgrades. Drop in a file and it becomes a card option.
What a template looks like
{#--- title: Contact (compact) ---#}
{% if mode == 'view' %}
<dl class="oe-card-grid">
<dt>{{ t('Cell') }}</dt> <dd>{{ patient.phone_cell|phone }}</dd>
<dt>{{ t('Email') }}</dt> <dd>{{ patient.email }}</dd>
<dt>{{ t('Language') }}</dt> <dd>{{ patient.language|list_label }}</dd>
</dl>
{% else %}
<form method="post" action="{{ save_url }}">
{{ csrf_field() }}
{{ input('phone_cell') }} {{ input('email') }} {{ input('language') }}
<button class="btn btn-primary">{{ t('Save') }}</button>
</form>
{% endif %}
Basic use is HTML with blanks to fill in. Conditions, loops, formatting helpers (dates, phone numbers, SSN masking), translation and shared partials are there for anyone who wants more.
How it works without LBF
- Field definitions in code. A typed field list in
src/describes eachpatient_datafield: label, type (text, date, phone, email, select, checkbox…), dropdown list, required, maximum length and permission. Sites can add or override fields in a small YAML file. Dropdown choices still come from the standardlist_optionslists. - Reading goes through the existing service layer (
PatientServiceand related services), the same code the REST/FHIR API uses. - Inputs are drawn by a small set of Twig widgets based on each field’s type. Sites can restyle them.
- Saving goes to a normal PHP endpoint. It checks the CSRF token and write permission, accepts only the fields the template actually displayed, validates with the existing
PatientValidator, and saves withPatientService::update(), again the same path as the API.
Because Twig cards read and write through the service layer, building them also exercises and improves the code the API depends on.
No new dependencies, and safe for user-supplied files
Templates run in Twig’s built-in sandbox mode. Twig is already in OpenEMR, and sandbox mode is designed for untrusted templates. Templates can only use an allow-listed set of tags, filters and data. They can’t run PHP, query the database or read files, and output is always escaped. Templates never write anything; all saving happens in trusted PHP on submit. A broken template shows an error on that card only (details logged for admins), never a broken dashboard.
Things I already know need care
- The LBF save (
updatePatientData()) and the service-layer save (PatientService::update()) may differ in history tracking, audit logging and events. They should be compared first, and the service fixed where needed, so both paths behave the same. - LBF layout settings (required, hidden, skip conditions) won’t apply to Twig cards. That’s intentional, but it must be documented.
- When an LBF card and a Twig card show the same field, saving one should refresh the other, and a stale edit form shouldn’t silently overwrite newer data.
- Address, phone and relationship fields have special handling today. They’d start out read-only in Twig cards.
Proposed phases
- Field definitions, view-only Twig cards, and dashboard configuration mixing LBF and Twig cards.
- Edit mode for simple
patient_datafields throughPatientServiceandPatientValidator. - Employer, contact and other cards through their own services.
- An admin screen to manage cards and fields without editing files.
I’d like to start as a custom module using the existing dashboard card hooks (SectionEvent / CardModel), so no core changes are needed to try it. If it proves useful, the base pieces could move into core.
Questions
- Would your practice use this? Which cards would you most want to customize?
- Per-site template folder, admin screen, or both?
- Is Twig with the sandbox simple enough for the people who would write these templates?
- Maintainers: any concerns with the approach, especially using
PatientService/PatientValidatorfor saves, before I start a prototype?
Thanks for any feedback.
David Eschelbacher


