Hi everyone,
I’d like to share a new encounter form, pain_zones, inspired by the existing pain map form but rebuilt around a relational data model. It is GPL-3.0 and I’m looking for feedback.
Repository: GitHub - luisuriarte/pain_zones · GitHub
Why a new form
The original pain map stores its marks in a single delimited string. This version stores one row per mark, so the data can be queried, compared between visits and reused in reports.
What it does
- Adult male/female figures, anterior and posterior views (4 SVG files in
assets/), with about 260 clickable anatomical zones. - Each mark records: figure and view, zone id, laterality, x/y position (percent of the figure’s viewBox), intensity 0–10, pain quality, radiation, onset, duration, aggravating and relieving factors, and notes.
- Marks are drawn as numbered pins, and each zone is tinted with the colour of the highest intensity recorded in it. The colour scale (blue at 1 to purple at 10, grouped as mild 1–3, moderate 4–6, severe 7–10) is stored in
list_options(pain_zones_level) and can be edited under Administration > Lists. - A sidebar lists every mark across all four panels. Clicking one switches to its panel and opens it.
- A read-only mode for users without write access.
report.phpprints a text table for the encounter summary and patient report.
Data model
form_pain_zones: form header, general notes.form_pain_zones_marks: one row per mark, with CHECK constraints on intensity (0–10) and position (0–100).form_pain_zones_history: change log (insert/update/delete with a JSON snapshot of each mark).list_options: the intensity levels with colours and severity bands.
Implementation notes
- Marks are kept in the browser and sent in one POST on save. The server validates every field, derives laterality from the zone id, checks the zone id against a whitelist read from the SVG files, and applies the changes in a single transaction.
- It uses the usual OpenEMR pieces: ACL check (
patients/med), CSRF token, parameterized queries,xl()/text()for output,addForm()registration. - Zone ids are in English. A Spanish translation file (
lang_custom.sql) is included.
Requirements and testing
- Developed and tested on OpenEMR 8.2.0 and 8.4.1, PHP 8.5.4, MariaDB 11.8.6.
- It uses classes from recent OpenEMR code (for example
EncounterFormAccessandQueryUtils::inTransaction), so it has not been tested on older releases [adjust to your facts].
Installation
- Copy the folder to
interface/forms/pain_zones/. - Register it in Administration > Forms > Forms Administration and click Install DB (this runs
table.sql). - Optional: import
lang_custom.sqlfor the Spanish translation.
Not done yet
- Comparing marks between visits or a cumulative heat map per zone.
- Generating the text summary (
summary_textis in the table but not filled yet) for use in other modules. - Patient entry from the portal before the visit.
- Drawing the figure inside the PDF report (today it prints a table).
I’d appreciate feedback on the data model, the zone list, and whether this would be useful as a pull request to the core forms. Screenshots are attached below.
Thanks!
Luis







