Pain Zones: an improved graphical pain map encounter form (relational storage, per-mark intensity, SVG figures)

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.php prints 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 EncounterFormAccess and QueryUtils::inTransaction), so it has not been tested on older releases [adjust to your facts].

Installation

  1. Copy the folder to interface/forms/pain_zones/.
  2. Register it in Administration > Forms > Forms Administration and click Install DB (this runs table.sql).
  3. Optional: import lang_custom.sql for the Spanish translation.

Not done yet

  • Comparing marks between visits or a cumulative heat map per zone.
  • Generating the text summary (summary_text is 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

1 Like

Just a reminder. I have several very good pain questionnaires available in contrib directory.

1 Like

Oh, thanks, I hadn’t seen them. I’ll take a look.

Luis

1 Like

Yep just import from portal dashboard and register in encounter. They may be a good companion with your feature.

I’m a bit hesitant about that; I know it’s a good idea, but I don’t want to modify the core codebase—maybe just a module or two.

Okay I get it. I was just pointing out questionnaires is already a part of core for doing treatment assessments.

I have added a comparison with previous encounters and a PDF print option.