FHIR Complete

Multi-Tenant Architecture

Organization isolation, national registries, and data scoping

Overview

Every piece of data in the system is scoped to an organization (tenant). The org_id from the JWT token determines which data a user can see.

How It Works

Login → Org Selection → JWT { org_id: "xxx" } → All queries filtered by org_id

Row Level Security (RLS)

Every resource table has RLS policies that:

  1. Extract org_id from the current session
  2. Filter rows to only those belonging to that organization
  3. Prevent cross-tenant data access

Organization Hierarchy

┌─────────────────────┐
│  National Org       │  is_national = true
│  (cross-org access) │  country_code = 'SK'
└─────────────────────┘

    ┌────┴────┐
    ▼         ▼
┌──────┐  ┌──────┐
│ Org A│  │ Org B│  is_national = false
│      │  │      │  country_code = 'SK'
└──────┘  └──────┘

Organization IDs

Important: There are two different "org IDs":

ColumnTablePurpose
org_idorganizationsThe JWT claim, used for RLS (UUID)
idresources_organizationInternal PK, NOT the tenant ID

Always use organizations.org_id (= JWT org_id) for tenant scoping.

National Organizations

Organizations with is_national = true have special powers:

  • Cross-org visibility: Can view patients from all orgs with the same country_code
  • National registry: Used for health registries and regulatory reporting
  • CodeSystem ownership: Own shared medical terminology data
National OrgCountryOwns
Indonesian National (cb6cd836)IDICD-10, ICD-9-CM codes
Slovak National (fdfc8af2)SKICD-10 chapters, SNOMED CT

Shared Data

CodeSystem resources (ICD-10, ICD-9-CM, SNOMED CT) are not tenant-scoped:

  • can_access_resource_row() returns true for all CodeSystem resources
  • Any authenticated user can read terminology data regardless of org

Country-Aware Features

The system adapts behavior based on country_code:

FeatureSK (Slovakia)ID (Indonesia)
ICD-10 format22 chapter resources (2,351 codes)267 flat resources
Condition codingICD-10 onlyICD-10 + Kemenkes dual coding
LanguageSlovak + EnglishIndonesian + English
Labor rules (HR)Slovak labor codeIndonesian labor law

Multi-Org Users

Staff and patients can belong to multiple organizations:

  • Staff hold a set of roles per organization
  • Patients hold a membership per organization, each with its own approval status

At login, users see all their orgs and select one. The JWT is scoped to that single org.

Organizational Affiliations

Organizations can have relationships (parent-child, network membership) via FHIR OrganizationAffiliation resources.

Specializations

Organizations declare their specialties using SNOMED CT codes (via OrganizationAffiliation). These are used for:

  • Public organization search and filtering
  • Patient-facing org discovery
  • Provider directory listings