Catalog
affaan-m/healthcare-phi-compliance

affaan-m

healthcare-phi-compliance

Protected Health Information (PHI) and PII compliance patterns for healthcare applications: data classification, row-level access control, tamper-proof audit trails, schema tagging, and common leak vectors such as logs, URLs, and browser storage. Use when code touches patient or clinician data, when implementing HIPAA or GDPR access controls, or when auditing a healthcare system for data exposure.

NewUpdated Sep 27, 2026

Healthcare PHI/PII Compliance Patterns

Patterns for protecting patient data, clinician data, and financial data in healthcare applications. Applicable to HIPAA (US), DISHA (India), GDPR (EU), and general healthcare data protection.

When to Use

  • Building any feature that touches patient records
  • Implementing access control or authentication for clinical systems
  • Designing database schemas for healthcare data
  • Building APIs that return patient or clinician data
  • Implementing audit trails or logging
  • Reviewing code for data exposure vulnerabilities
  • Setting up Row-Level Security (RLS) for multi-tenant healthcare systems

How It Works

Healthcare data protection operates on three layers: classification (what is sensitive), access control (who can see it), and audit (who did see it).

Data Classification

PHI (Protected Health Information) — any data that can identify a patient AND relates to their health: patient name, date of birth, address, phone, email, national ID numbers (SSN, Aadhaar, NHS number), medical record numbers, diagnoses, medications, lab results, imaging, insurance policy and claim details, appointment and admission records, or any combination of the above.

PII (Non-patient-sensitive data) in healthcare systems: clinician/staff personal details, doctor fee structures and payout amounts, employee salary and bank details, vendor payment information.

Access Control: Row-Level Security

ALTER TABLE patients ENABLE ROW LEVEL SECURITY;

-- Scope access by facility
CREATE POLICY "staff_read_own_facility"
  ON patients FOR SELECT TO authenticated
  USING (facility_id IN (
    SELECT facility_id FROM staff_assignments
    WHERE user_id = auth.uid() AND role IN ('doctor','nurse','lab_tech','admin')
  ));

-- Audit log: insert-only (tamper-proof)
CREATE POLICY "audit_insert_only" ON audit_log FOR INSERT
  TO authenticated WITH CHECK (user_id = auth.uid());
CREATE POLICY "audit_no_modify" ON audit_log FOR UPDATE USING (false);
CREATE POLICY "audit_no_delete" ON audit_log FOR DELETE USING (false);

Audit Trail

Every PHI access or modification must be logged:

interface AuditEntry {
  timestamp: string;
  user_id: string;
  patient_id: string;
  action: 'create' | 'read' | 'update' | 'delete' | 'print' | 'export';
  resource_type: string;
  resource_id: string;
  changes?: { before: object; after: object };
  ip_address: string;
  session_id: string;
}

Common Leak Vectors

Error messages: Never include patient-identifying data in error messages thrown to the client. Log details server-side only.

Console output: Never log full patient objects. Use opaque internal record IDs (UUIDs) — not medical record numbers, national IDs, or names.

URL parameters: Never put patient-identifying data in query strings or path segments that could appear in logs or browser history. Use opaque UUIDs only.

Browser storage: Never store PHI in localStorage or sessionStorage. Keep PHI in memory only, fetch on demand.

Service role keys: Never use the service_role key in client-side code. Always use the anon/publishable key and let RLS enforce access.

Logs and monitoring: Never log full patient records. Use opaque record IDs only (not medical record numbers). Sanitize stack traces before sending to error tracking services.

Database Schema Tagging

Mark PHI/PII columns at the schema level:

COMMENT ON COLUMN patients.name IS 'PHI: patient_name';
COMMENT ON COLUMN patients.dob IS 'PHI: date_of_birth';
COMMENT ON COLUMN patients.aadhaar IS 'PHI: national_id';
COMMENT ON COLUMN doctor_payouts.amount IS 'PII: financial';

Deployment Checklist

Before every deployment:

  • No PHI in error messages or stack traces
  • No PHI in console.log/console.error
  • No PHI in URL parameters
  • No PHI in browser storage
  • No service_role key in client code
  • RLS enabled on all PHI/PII tables
  • Audit trail for all data modifications
  • Session timeout configured
  • API authentication on all PHI endpoints
  • Cross-facility data isolation verified

Examples

Example 1: Safe vs Unsafe Error Handling

// BAD — leaks PHI in error
throw new Error(`Patient ${patient.name} not found in ${patient.facility}`);

// GOOD — generic error, details logged server-side with opaque IDs only
logger.error('Patient lookup failed', { recordId: patient.id, facilityId });
throw new Error('Record not found');

Example 2: RLS Policy for Multi-Facility Isolation

-- Doctor at Facility A cannot see Facility B patients
CREATE POLICY "facility_isolation"
  ON patients FOR SELECT TO authenticated
  USING (facility_id IN (
    SELECT facility_id FROM staff_assignments WHERE user_id = auth.uid()
  ));

-- Test: login as doctor-facility-a, query facility-b patients
-- Expected: 0 rows returned

Example 3: Safe Logging

// BAD — logs identifiable patient data
console.log('Processing patient:', patient);

// GOOD — logs only opaque internal record ID
console.log('Processing record:', patient.id);
// Note: even patient.id should be an opaque UUID, not a medical record number
Files1
1 files · 1.0 KB

Select a file to preview

Overall Score

88/100

Grade

A

Excellent

Grades are signals, not a certification. Always review a skill yourself before use.

Safety

92

Quality

87

Clarity

89

Completeness

81

Summary

This skill provides healthcare PHI/PII compliance patterns for HIPAA, DISHA, GDPR, and general data protection regulations. It covers data classification, row-level security (RLS) implementation, tamper-proof audit trails, database schema tagging, and common data leak vectors (error messages, logs, URLs, browser storage). The skill is reference material and documentation—it does not execute code or write to systems; instead, it teaches agents how to guide healthcare development teams in implementing secure patterns.

Detected Capabilities

documentation and reference materialcode examples (TypeScript, SQL)audit trail design patternsdatabase access control guidancehealthcare compliance checklist

Trigger Keywords

Phrases that agents use to match this skill to user intent.

healthcare complianceHIPAA audit trailsrow-level securityphi pii protectionpatient data isolationcompliance checklisthealthcare schema designmulti-facility access control

Risk Signals

INFO

No dynamic code execution, shell commands, or file writes detected

entire skill
INFO

No secrets, credentials, API keys, or environment variables accessed or exposed

entire skill
INFO

SQL code examples use parameterized patterns and do not show injection vectors

Access Control section
INFO

Skill provides guidance only—does not execute, deploy, or modify systems

entire skill

Use Cases

  • Implement row-level security policies for multi-facility healthcare systems
  • Design HIPAA-compliant audit trails for patient data access
  • Audit healthcare code for PHI/PII exposure in logs, URLs, and error messages
  • Mark sensitive database columns with PHI/PII classification comments
  • Configure access control policies that isolate patient data by facility
  • Review healthcare schemas and APIs for data leak vulnerabilities before deployment
  • Train development teams on healthcare data protection compliance patterns

Quality Notes

  • Well-structured documentation with clear section hierarchy (When to Use, How It Works, Common Leak Vectors)
  • Practical examples showing both 'BAD' and 'GOOD' patterns for error handling, logging, and RLS policies
  • Comprehensive deployment checklist provides actionable guardrails for teams
  • Covers multiple compliance frameworks (HIPAA, DISHA, GDPR) with generic patterns applicable across regions
  • Data classification definitions are precise and healthcare-specific (PHI vs PII distinction clear)
  • Audit trail interface is concrete (AuditEntry TypeScript type) with required fields for compliance
  • Database schema tagging approach (SQL comments) is practical and low-friction
  • Common leak vectors section directly addresses real-world exposure patterns (URLs, console logs, localStorage)
  • Examples are concise and illustrative—good signal/noise ratio
Model: claude-haiku-4-5-20251001Analyzed: Sep 27, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Version History

  1. v3.0

    Contract changed: description

    ✦ AIActivates for row-level access control, tamper-proof audit trails, and schema tagging; adds HIPAA/GDPR and storage leak vectors to scope.

    triggering2026-09-27

    LATEST
  2. v2.0

    Contract changed: description

    ✦ AIClarifies skill activation criteria: specifies use when code touches PHI or PII in healthcare systems.

    triggering2026-09-09

    View This Version
  3. v1.2

    Content updated

    ✦ AINo behavioral changes to skill instructions or requirements.

    2026-07-14

    View This Version
  4. v1.1

    Content updated

    ✦ AIAdds LICENSE file to distribution.

    2026-04-20

    View This Version
  5. v1.0

    2026-04-12

    View This VersionInitial version

Use affaan-m/healthcare-phi-compliance in your dev environment

Command Palette

Search for a command to run...