Chuyển đến nội dung chính

Lesson 3: Health Data Classification (PHI/ePHI) & Risk Assessment

Classify medical data according to sensitivity level: PHI, ePHI, PII, clinical data, administrative data. Develop Data Classification Policy, Data Flow Mapping, Risk Assessment according to NIST SP 800-30, and set up Risk Register for medical microservices system.

🏗️ Architecture — Lesson 3 Lesson 3: Medical Data Classification (PHI/ePHI) & Risk Assessment

Building a Microservices Healthcare System — Quarkus, PostgreSQL, Keycloak with HIPAA standards

Part 1: Architecture & Platform

xdev.asia

1. Data Classification Framework for Healthcare

Medical data classification pyramid — 4 levels from Public to Restricted

1.1. Why is it necessary to classify data?

Not all data needs the same level of protection. Data classification helps:

  • Optimize security costs: Focus resources on the most important data
  • Legal compliance: Apply correct controls according to regulatory requirements
  • Reduce attack surface: Limit the scope of sensitive data
  • Incident response: Prioritize handling when a breach occurs

1.2. Healthcare Data Classification Levels

Medical data classification pyramid — 4 levels from Public to Restricted

LevelNameExampleEncryptionAccessAudit
4 - RESTRICTEDMaximum restrictionsHIV/AIDS, mental health, genetics, addiction treatment, reproductive healthRequired (AES-256)Named individuals onlyFull logging, real-time alerts
3 - CONFIDENTIALSecurityMedical records, tests, prescriptions, diagnostic imaging, health insuranceRequired (AES-256)Role-based (treating clinicians)Full logging
2 - INTERNALInternalAppointment schedule, statistics (anonymous), medical staff, configurationRecommendedDepartment-basedStandard logging
1 - PUBLICPublicList of services, working hours, hospital contacts, health instructionsNot requiredPublicBasic logging

1.3. Data Classification in PostgreSQL Schema

-- Data classification metadata table
CREATE TABLE data_classification (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    schema_name VARCHAR(100) NOT NULL,
    table_name VARCHAR(100) NOT NULL,
    column_name VARCHAR(100) NOT NULL,
    classification_level INTEGER NOT NULL CHECK (classification_level BETWEEN 1 AND 4),
    classification_label VARCHAR(50) NOT NULL,
    contains_phi BOOLEAN DEFAULT false,
    encryption_required BOOLEAN DEFAULT false,
    masking_rule VARCHAR(100),
    retention_days INTEGER,
    legal_basis TEXT,
    created_at TIMESTAMPTZ DEFAULT NOW(),
    updated_at TIMESTAMPTZ DEFAULT NOW()
);

-- Ví dụ classification cho patient table
INSERT INTO data_classification (schema_name, table_name, column_name,
    classification_level, classification_label, contains_phi, encryption_required, masking_rule)
VALUES
    ('public', 'patients', 'id', 2, 'INTERNAL', false, false, NULL),
    ('public', 'patients', 'full_name', 3, 'CONFIDENTIAL', true, true, 'PARTIAL_MASK'),
    ('public', 'patients', 'date_of_birth', 3, 'CONFIDENTIAL', true, false, 'YEAR_ONLY'),
    ('public', 'patients', 'cccd_number', 3, 'CONFIDENTIAL', true, true, 'FULL_MASK'),
    ('public', 'patients', 'phone', 3, 'CONFIDENTIAL', true, true, 'PARTIAL_MASK'),
    ('public', 'patients', 'email', 3, 'CONFIDENTIAL', true, true, 'PARTIAL_MASK'),
    ('public', 'patients', 'address', 3, 'CONFIDENTIAL', true, true, 'CITY_ONLY'),
    ('public', 'patients', 'blood_type', 2, 'INTERNAL', false, false, NULL),
    ('public', 'patients', 'hiv_status', 4, 'RESTRICTED', true, true, 'FULL_MASK'),
    ('public', 'patients', 'insurance_number', 3, 'CONFIDENTIAL', true, true, 'PARTIAL_MASK');

2. Data Flow Mapping

2.1. PHI Data Flow in Microservices

Flow of PHI data across microservices — from Patient Portal through API Gateway, Keycloak to services and databases

2.2. Data Flow Documentation Template

#Data ElementSourceDestinationTransportationEncryptionClassification
1Patient NamePortalPatient ServiceHTTPS/TLS 1.3In-transit + At-restL3
2Lab ResultsLab InstrumentsLab ServiceHL7v2/MLLP over TLSIn-transit + At-restL3
3Diagnosis CodeClinical ServiceBilling ServiceKafka (SSL)Application-levelL3
4HIV StatusClinical ServiceClinical DBJDBC/SSLColumn encryptionL4
5Audit EventAll ServicesAudit ServiceKafka (SSL)Event encryptionL2
6AppointmentsScheduling ServiceNotification ServiceKafka (SSL)In-transitL2

3. Risk Assessment according to NIST SP 800-30

3.1. Risk Assessment Methodology

6 steps to assess risk according to NIST SP 800-30 — from Identifying Threats to Risk Response

3.2. Threat Identification for Healthcare Microservices

Threat CategoryThreatThreat Source
ExternalSQL Injection into Patient ServiceAttacker
ExternalRansomware encrypts databaseCybercriminal
ExternalMITM attack on API callsNetwork attacks
ExternalCredential stuffing into Patient PortalBot networks
InternalUnauthorized employee access to PHIInsider
InternalDatabase admin exports all patient dataPrivileged users
InternalDeveloper hardcode credentialsNegligent employees
EnvironmentalDatabase corruption due to hardware failureInfrastructure
EnvironmentalData loss due to natural disastersNatural disasters
Supply ChainVulnerability in Quarkus dependencyThird-party

3.3. Vulnerability Assessment

// Ví dụ: Checklist kiểm tra vulnerabilities trong Quarkus service
public class SecurityVulnerabilityChecklist {

    // V1: SQL Injection - Sử dụng parameterized queries
    // ❌ VULNERABLE
    String badQuery = "SELECT * FROM patients WHERE name = '" + userInput + "'";

    // ✅ SECURE
    @NamedQuery(name = "Patient.findByName",
                query = "SELECT p FROM Patient p WHERE p.name = :name")
    List<Patient> findByName(@Param("name") String name);

    // V2: Broken Authentication - Token validation
    // ❌ VULNERABLE: Không verify token
    String userId = jwt.getClaim("sub"); // Không verify expiration, issuer

    // ✅ SECURE: Quarkus OIDC tự động verify
    @Authenticated
    @RolesAllowed("doctor")
    public Response getPatient(UUID id) { ... }

    // V3: Sensitive Data Exposure in Logs
    // ❌ VULNERABLE
    log.info("Patient created: " + patient.toString()); // Logs PHI!

    // ✅ SECURE
    log.info("Patient created: id={}", patient.getId()); // Only log ID
}

3.4. Risk Matrix

5x5 risk assessment matrix — Likelihood x Impact from LOW to CRITICAL

Negligible (1)Low (2)Medium (3)High (4)Critical (5)
Very High (5)LOWMEDIUMHIGHCRITICALCRITICAL
High (4)LOWMEDIUMHIGHHIGHCRITICAL
Medium (3)LOWLOWMEDIUMHIGHHIGH
Low (2)LOWLOWLOWMEDIUMMEDIUM
Very Low (1)LOWLOWLOWLOWMEDIUM

4. Risk Register for Healthcare Microservices

4.1. Risk Register Template

IDRisk DescriptionLikelihoodImpactRisk LevelMitigationOwnerStatus
R001SQL Injection into Patient APIMedium (3)Critical (5)HIGHParameterized queries, input validation, WAFDev TeamMitigation
R002Insider access PHI not authorizedHigh (4)High (4)HIGHRBAC, RLS, Audit logging, DLPSecurity TeamIn Progress
R003Ransomware encrypts patient_dbMedium (3)Critical (5)HIGHImmutable backups, network segmentation, EDROps TeamMitigation
R004Keycloak token theftMedium (3)High (4)HIGHShort-lived tokens, mTLS, DPoPDev TeamIn Progress
R005PHI exposure in logsHigh (4)High (4)HIGHLog sanitization, PHI detection in CI/CDDev TeamOpen
R006Unencrypted PHI in KafkaMedium (3)High (4)HIGHApplication-level encryption, Kafka SSLDev TeamOpen
R007Database backup theftLow (2)Critical (5)MEDIUMEncrypted backups, key managementOps TeamMitigation
R008API key/credential exposureMedium (3)High (4)HIGHVault secrets management, no hardcoded secretsAll TeamsIn Progress
R009DDoS on patient portalMedium (3)Medium (3)MEDIUMRate limiting, WAF, CDNOps TeamMitigation
R010Third-party dependency CVEHigh (4)Medium (3)HIGHAutomated scanning, Dependabot, SBOMDev TeamOngoing

4.2. Risk Treatment Plan

4 risk handling strategies — Mitigate, Transfer, Accept, Avoid

  • MITIGATE ← Preferred for HIGH risks: Implement controls, reduce likelihood/impact
  • TRANSFER (Transfer): Cyber insurance, outsourcing to specialist provider
  • ACCEPT (Accept) ← Only for LOW risks: Document risk acceptance, monitor
  • AVOID (Avoid): Eliminate sources of risk, change architecture

5. Data Retention Policy

5.1. Retention Requirements for Vietnamese Health

Data typeStorage timeLegal basis
Outpatient medical records10 yearsCircular 46/2018/TT-BYT
Inpatient medical records20 yearsCircular 46/2018/TT-BYT
Death medical records20 yearsCircular 46/2018/TT-BYT
Test results10 yearsHospital regulations
Diagnostic imaging10 yearsHospital regulations
Audit logs6 years (HIPAA)HIPAA §164.530(j)
Prescription5 yearsPharmacy Law
Consent recordsLifetime + 6 yearsHIPAA / Decree 13/2023

5.2. Automated Retention in PostgreSQL

-- Partition strategy for data retention
CREATE TABLE audit_events (
    id UUID DEFAULT gen_random_uuid(),
    event_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    event_type VARCHAR(50) NOT NULL,
    actor_id UUID NOT NULL,
    resource_type VARCHAR(100) NOT NULL,
    resource_id UUID,
    action VARCHAR(20) NOT NULL,
    outcome VARCHAR(20) NOT NULL,
    details JSONB
) PARTITION BY RANGE (event_time);

-- Create monthly partitions
CREATE TABLE audit_events_2026_01 PARTITION OF audit_events
    FOR VALUES FROM ('2026-01-01') TO ('2026-02-01');

CREATE TABLE audit_events_2026_02 PARTITION OF audit_events
    FOR VALUES FROM ('2026-02-01') TO ('2026-03-01');

-- Automated partition management
-- Drop partitions older than retention period (6 years for HIPAA)
-- Archive to cold storage before dropping

6. Summary

In this lesson, we have:

  • Develop a 4-level Data Classification Framework for medical data
  • Create Data Flow Mapping for PHI via microservices architecture
  • Perform Risk Assessment according to NIST SP 800-30 methodology
  • Set up Risk Register with risk treatment plans
  • Definition of Data Retention Policy according to Vietnamese regulations and HIPAA

Exercises

  1. Classify all tables/columns in your medical system database into 4 levels
  2. Draw Data Flow Diagram for 3 main use cases: registering for examination, recording test results, prescribing medicine
  3. Perform Risk Assessment and create Risk Register for at least 15 risks
  4. Develop a Data Retention Policy suitable for the organization


◀ Previous articleNext article ▶
Lesson 2: Safe Microservices Architecture for Healthcare with Quarkus StackLesson 4: Threat Modeling STRIDE/DREAD for Health Information System