Kulcare Docs
General

Kulcare Next-Generation Database Schema

Status: Analysis & Design Phase Created: 2025-12-28 Purpose: Greenfield database architecture for multi-tenant, FHIR-compliant healthcare platform

Executive Summary

This documentation describes a proposed greenfield database architecture that addresses the limitations of the current "clinic-centric" data model. The new schema is designed to support:

  1. Multi-tenancy with proper isolation using PostgreSQL Row-Level Security (RLS)
  2. Domain-aware organization using PostgreSQL schemas for logical separation
  3. FHIR R4 compliance for healthcare data interoperability
  4. Longitudinal Health Record (LHR) with Episode of Care and coordinated care
  5. AI-assisted care with clinical decision support integration
  6. Multi-country compliance for India, UAE, USA, and GCC region
  7. Enterprise healthcare benefits with ICHRA support and provider empanelment
  8. Pharmaceutical relations in isolated database for compliance
  9. Offline mode support with sync tracking and conflict resolution
  10. Federated deployment with on-premise installations syncing to central cloud

Problem Statement

Current Limitations

The existing database has evolved organically with several architectural challenges:

IssueImpact
Clinic-centric modelAll facilities are "clinics" even when they're hospitals, therapy centers, or surgery centers
501 tables in single schemaNo logical domain separation, difficult to reason about
Inconsistent namingMix of prefixes (basic_*, clinic_*), unprefixed tables, duplicate names
Implicit multi-tenancyTenant isolation via clinic_id without formal enforcement
Limited facility classificationBoolean is_hospital flag cannot capture OPD+IPD+OT specialty centers

Target State

A clean, domain-organized architecture where:

  • Facilities are properly classified by service level, ownership, and specialty scope
  • Clinical data follows FHIR R4 resource patterns
  • Domains are separated into PostgreSQL schemas
  • Multi-tenancy is enforced at the database level
  • AI-assisted care integrates seamlessly with clinical workflows

Design Principles

  1. FHIR-First: Core clinical entities map to FHIR R4 resources
  2. Domain Boundaries: Clear separation between clinical, billing, growth, and identity domains
  3. Tenant Isolation: Row-Level Security for data protection
  4. Reference Data Sharing: Global lookup tables without tenant scope
  5. LHR as Computed View: Longitudinal Health Record aggregated from FHIR resources, not stored
  6. Extensibility: Support for new countries, facility types, and clinical workflows

Document Index

Foundation Documents

DocumentDescription
BackgroundCurrent state analysis, why change is needed
Architectural DecisionsKey design decisions in ADR format
Schema OverviewVisual architecture and schema relationships

Schema Definitions

SchemaDocumentPurpose
referenceReference SchemaGlobal lookup tables, medical coding
identityIdentity SchemaWho provides what, where: tenants, organizations, facilities, providers, services, packages
clinicalClinical SchemaPatients, encounters, care plans, AI suggestions
billingBilling SchemaInvoices, payments, subscriptions, insurance claims
growthGrowth SchemaCampaigns, leads, communications
connectConnect SchemaProfessional networking, job board (cross-tenant)
enterpriseEnterprise SchemaEmployer benefits, empanelment, wellness (cross-tenant)
integrationIntegration SchemaABDM, webhooks, API logs
auditAudit SchemaActivity logs, PHI access, LLM logs
federationFederation SchemaOn-premise sync, patient identity federation

Separate Databases

DatabaseDocumentPurpose
pharma_dbPharma DatabasePharmaceutical relations, campaigns, clinical trials

Feature Documentation

DocumentDescription
Clinical FeaturesLHR, Episode of Care, Coordinated Care, AI-Assisted Care
InternationalizationMulti-country compliance (IN, AE, US, GCC)
Offline ModeOffline sync schema design, conflict resolution
Federated DeploymentOn-premise installations, patient portal integration
NotificationsShared notification system (SMS, push, WhatsApp, Slack)
TeleconsultationVideo sessions, participant management, teleconsultation notifications
Migration ConsiderationsHigh-level migration strategy

Patient Self-Service

DocumentDescription
Patient Self-Service SignupArchitecture, API contracts, patient-clinic linking, and Identity integration
Patient Signup Testing GuideTesting guide for registration, authentication, and clinic linking

Migration Execution

DocumentDescription
Legacy Prescription CleanupRemoval of old appointment-based prescription feature from frontend CMS

Schema Architecture Overview

+-------------------------------------------------------------------------+
|                         KULCARE DATABASE                                |
+-------------------------------------------------------------------------+
|                                                                         |
|  +-------------------------------------------------------------------+  |
|  |  REFERENCE SCHEMA (Global - No tenant_id)                        |  |
|  |  specialties, drugs, lab_tests, procedures, icd_codes, countries |  |
|  +-------------------------------------------------------------------+  |
|                                    |                                    |
|                                    v                                    |
|  +-------------------------------------------------------------------+  |
|  |  IDENTITY SCHEMA (Who provides what, where)                      |  |
|  |  tenants, organizations, facilities, practitioners,              |  |
|  |  vendors, healthcare_services, service_packages                  |  |
|  +-------------------------------------------------------------------+  |
|           |              |              |              |                |
|           v              v              v              v                |
|  +-------------+  +-------------+  +-------------+  +-------------+    |
|  |  CLINICAL   |  |   BILLING   |  |   GROWTH    |  |   CONNECT   |    |
|  |   SCHEMA    |  |   SCHEMA    |  |   SCHEMA    |  |   SCHEMA    |    |
|  +-------------+  +-------------+  +-------------+  +-------------+    |
|  | patients    |  | invoices    |  | campaigns   |  | profiles    |    |
|  | encounters  |  | payments    |  | leads       |  | jobs        |    |
|  | care_plans  |  | insurance   |  | communic-   |  | connections |    |
|  | medications |  | claims      |  | ations      |  | messages    |    |
|  +-------------+  +-------------+  +-------------+  +-------------+    |
|                                                                         |
|  +-------------------------------------------------------------------+  |
|  |  ENTERPRISE SCHEMA (Cross-tenant)                                |  |
|  |  employers, employees, benefit_plans, empaneled_providers        |  |
|  +-------------------------------------------------------------------+  |
|                                                                         |
|  +-------------------------------------------------------------------+  |
|  |  INTEGRATION SCHEMA        |  AUDIT SCHEMA                       |  |
|  |  abdm_records, webhooks    |  activity_logs, phi_access, llm_logs|  |
|  +-------------------------------------------------------------------+  |
|                                                                         |
+-------------------------------------------------------------------------+

+-------------------------------------------------------------------------+
|                     PHARMA DATABASE (Separate)                          |
+-------------------------------------------------------------------------+
|  pharma_companies, campaigns, doctor_engagements, clinical_trials,     |
|  disclosure_records, gift_tracking (API sync with Kulcare)              |
+-------------------------------------------------------------------------+

Terminology

TermDefinition
TenantTop-level isolation boundary (usually an organization)
OrganizationLegal entity that provides healthcare (FHIR: Organization)
FacilityPhysical location where services are delivered (replaces "Clinic")
PractitionerLicensed healthcare provider (doctor, nurse, therapist)
VendorUnlicensed service provider (yoga instructor, lamaze educator)
LHRLongitudinal Health Record - computed aggregate view of patient health
Episode of CareTreatment program container spanning multiple visits
EncounterSingle visit/session between patient and practitioner
EmployerCompany/organization providing healthcare benefits (B2B customer)
ICHRAIndividual Coverage Health Reimbursement Arrangement
EmpanelmentContracted provider relationship with an employer
Service PackageBundled offering of healthcare and vendor services
RLSRow-Level Security - PostgreSQL feature for tenant isolation
Cross-tenantData accessible across multiple tenants (Connect, Enterprise schemas)
Pharma DBSeparate database for pharmaceutical company relations

On this page