Skip to content

Instantly share code, notes, and snippets.

@ryukzak
Last active October 23, 2025 07:38
Show Gist options
  • Select an option

  • Save ryukzak/285a03539c660cf30b8fdfc2f647011c to your computer and use it in GitHub Desktop.

Select an option

Save ryukzak/285a03539c660cf30b8fdfc2f647011c to your computer and use it in GitHub Desktop.

ORM on FHIR: Mapping FHIR Entities to Code

Developers can write raw SQL queries with string interpolation — but they don’t like it. They prefer using ORMs because they get type safety, IDE support, less boilerplate, database agnosticism, easier schema maintenance, etc. The same logic applies to FHIR.

In this talk, I’ll describe the motivation and challenges of building such an “ORM,” introduce TypeSchema — our approach to generating SDKs from FHIR Implementation Guides — and share our roadmap for making it production-ready.

Aleksandr Penskoi, Health Samurai Engineer.


What is "ORM on FHIR"?

FHIR IGs <------------------------------------> Programming Data Entities
- FHIR packages                                 - namespaces & modules
- resource, complex, primitive, logical types   - types & structures & objects
    - choice types, bindings, constraints           - marshaling
    - extensions                                    - validation
- profiles                                      - clients
    - slices                                    - FHIR related/non related code
- CRUD & operations

Challenges

  1. A lot of non-directly mapped concepts1:
    • Hierarchical data structures, Backbone elements
    • Choice types
    • Bindings
    • Extensions
    • Customized data shape: profiles and slices
  2. Opinionated decisions (language, framework, company, team, person).
  3. Complexity of input data:
    • Multiple packages
    • Multiple FHIR core package versions
    • Canonical URL and name collisions
    • Static resolution and consistency
    • Complicated specification formats
  4. Absurd amount of output source code for simple cases

Approach: Open Source FHIR Codegen Framework

FHIR IGs ---> TypeSchemas ------------------------> Codegen Framework
              - Simplify data entity                          |    Customizable
              - Prepare for opinionated decisions             |<---- Generator
              - Expanded binding                              |        Code
              - Package aware resolution                      v
              - Tree shaking                                 SDK - TypeScript
                                                                 - Python
                                                                 - C#

Roadmap

  1. Proof-of-concept for FHIR core package:
  2. Migration to common stack (TS): atomic-ehr/codegen
    • TypeScript
    • [*] C#
    • Python
    • [*] Package aware canonical resolution
    • [*] Profiles and slices
    • Extensions
    • Client examples
  3. Dogfooding in codegen itself
  4. Work with non-core packages, including profiles and slices:
    • [*] hl7.cda.uv.core
    • hl7.fhir.us.core

Footnotes

  1. Depends on target programming language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment