Introducing open-pharma-dosing — an open-source library for structured medication frequency encoding and FHIR R4 conversion

Hi all,

I’d like to share a project I’ve been working on and get the community’s thoughts: open-pharma-dosing, an open-source, zero-dependency
library that converts clinical dosing frequency shorthand into structured data and FHIR R4 Timing resources.

The problem

Clinical systems routinely deal with dosing frequencies like “BD”, “TDS”, “PRN Q4H”, or “STAT” — but there’s no lightweight,
open-source library that:

  • Maps these codes to structured timing metadata
  • Converts them bidirectionally to/from FHIR R4 Timing and Dosage resources
  • Generates concrete administration schedules
  • Handles locale differences (e.g. “BD” in the UK vs “BID” in the US)
  • Validates dosing instructions for clinical sense

Most teams end up writing this logic from scratch, often inconsistently.

Design decisions I’d like feedback on

  1. Embedded registry — All 33 codes are compiled into the binary as struct literals. No runtime file loading, no database dependency.
    This keeps it fast and self-contained but means adding codes requires a code change. Is this the right trade-off for clinical software?
  2. FHIR roundtrip fidelity — FromFhirTiming(ToFhirTiming(code)) == code holds for all 33 supported codes. This is tested and enforced.
    Are there edge cases from real-world FHIR implementations that would break this?
  3. Clinically sensible defaults — Default times are chosen for clinical reality, not mathematical spacing. For example, QDS (four times
    daily) defaults to 06:00, 12:00, 18:00, 22:00 rather than every 6 hours from midnight. Would clinicians in your context expect
    different defaults?
  4. Locale model — Currently en-GB and en-US, with the architecture ready for fr, es, sw, ha, and yo (Swahili, Hausa, Yoruba are
    intentional for deployment contexts in sub-Saharan Africa). What other locales would be useful?
  5. Category taxonomy — Frequencies are classified into 7 categories: regular, interval, time_of_day, meal_relative, prn, one_off,
    extended. Meal-relative codes (AC, PC, CC) are treated as modifiers that combine with a base frequency rather than standalone
    frequencies. Does this model hold up against your clinical workflows?

Current state

What I’m looking for

  • Clinical validation — Do the 33 codes and their default timings match what you see in practice? Are there common frequencies missing?
  • FHIR interop experience — Has anyone dealt with dosing frequency mapping to FHIR Timing in production? What broke?
  • Locale contributions — Especially interested in contributors who can validate dosing terminology in non-English clinical contexts
  • Use case alignment — Would this be useful in your stack? What would need to change?

Happy to answer questions or walk through the code. Looking forward to the discussion. @pacharanero @eatyourpeas

1 Like

AMAZING work @FibrinLab - really great to see people thinking about the infrastructure like this and sharing it in open source. These kinds of infrastructural tools where hard and deep thought and clinical knowledge application is needed, and as open tools everyone can potentially benefit.

I’m aware of some pieces of work that have been done over the years into what was called ‘Dose Syntax’, which is very similar to what you are considering here. I will try to find out some more information for you and will share it here. For now: https://digital.nhs.uk/developer/api-catalogue/dose-syntax-standards

I have some initial feedback and will add more as I think of it. There are some other good minds on this forum, so they may add thoughts. Some of them have done similar mapping work for NHS Digital/England/Scotland I think.

  1. Naming - names are important, but hard to get right. I would avoid the use of ‘pharma’ because it tends to suggest pharmaceutical companies or the pharma industry. Maybe something like Open Dose Syntax perhaps?

  2. Embedded registry - although JSON is fine, and for anyone that can edit a file they could extend or amend that JSON at open-pharm-dosing/data/frequencies.json at main · Open-Nucleus/open-pharm-dosing · GitHub and submit a PR, I wonder if it would be better if it was a little more human-readable, and possibly if it was in a format (eg. TOML or YAML) that allowed comments (JSON doesn’t) then it would be easier to include ‘literate programming’ annotations over time.