Database Schema

Complete database schema and entity relationships for the MediPact platform.

Entity Relationship Diagram

Core Tables

PATIENTS

Stores patient identity and Hedera account information

ColumnTypeDescription
upiSTRING (PK)Universal Patient Identifier
hedera_account_idSTRINGHedera account (0.0.xxxxx) for revenue
evm_addressSTRINGEVM-compatible address (0x...)
payment_methodSTRING'bank' or 'mobile_money'
bank_account_numberSTRING (encrypted)Encrypted bank account number
withdrawal_threshold_usdDECIMALAuto-withdrawal threshold (default: $10.00)
auto_withdraw_enabledBOOLEANEnable automatic withdrawals

HOSPITALS

Hospital registration and verification

ColumnTypeDescription
hospital_idSTRING (PK)Unique hospital identifier
hedera_account_idSTRINGHedera account for revenue
evm_addressSTRINGEVM-compatible address (0x...)
payment_methodSTRING'bank' or 'mobile_money'
bank_account_numberSTRING (encrypted)Encrypted bank account number
withdrawal_threshold_usdDECIMALAuto-withdrawal threshold (default: $100.00)
verification_statusSTRINGpending, verified, rejected

RESEARCHERS

Researcher registration and access levels

ColumnTypeDescription
researcher_idSTRING (PK)Unique researcher identifier
hedera_account_idSTRINGHedera account for payments
access_levelSTRINGbasic, verified, premium

CONSENTS

Patient consent records linked to HCS and smart contracts

ColumnTypeDescription
consent_idSTRING (PK)Unique consent identifier
upiSTRING (FK)Patient UPI reference
anonymous_patient_idSTRINGAnonymous ID (PID-001)
hcs_topic_idSTRINGHCS topic for consent proof
data_hashSTRINGHash of anonymized dataset

DATASETS

Marketplace datasets with HCS topic references

ColumnTypeDescription
dataset_idSTRING (PK)Unique dataset identifier
hospital_idSTRING (FK)Hospital that created the dataset
consent_topic_idSTRINGHCS topic for consent verification
data_topic_idSTRINGHCS topic for data proof
priceDECIMAL(20,8)Price in HBAR
price_usdDECIMAL(10,2)Price in USD
pricing_categorySTRINGPricing category (basic, condition, lab, etc.)

WITHDRAWAL_HISTORY

Tracks all withdrawal requests and their status

ColumnTypeDescription
idINTEGER (PK)Unique withdrawal ID
upiSTRING (FK)Patient UPI (if patient withdrawal)
hospital_idSTRING (FK)Hospital ID (if hospital withdrawal)
user_typeSTRING'patient' or 'hospital'
amount_hbarDECIMAL(20,8)Withdrawal amount in HBAR
amount_usdDECIMAL(10,2)Withdrawal amount in USD
payment_methodSTRING'bank' or 'mobile_money'
destination_accountSTRINGBank account or mobile money number (masked)
statusSTRINGpending, processing, completed, failed
transaction_idSTRINGFiat transfer transaction ID (if available)

Key Relationships

Patient Identity (UPI)

The Universal Patient Identifier (UPI) enables cross-hospital patient identity linking. A patient can be registered at multiple hospitals, and all records are linked through the UPI.

Consent Tracking

Each consent record links a patient (via UPI) to an anonymous patient ID, HCS topic, and data hash. This enables verification of consent both on-chain (via ConsentManager contract) and off-chain (via database queries).

Hedera Integration

All entities that receive revenue (patients, hospitals) have Hedera account IDs stored in the database. Researchers also have Hedera accounts for making payments. HCS topic IDs are stored for verification purposes.