healthcare-phi-compliance
affaan-m/everything-claude-code
Protect patient data with PHI/PII compliance patterns for HIPAA, GDPR, and healthcare regulations.
What is healthcare-phi-compliance?
Provides data classification, access control, audit trail, and encryption patterns for healthcare applications handling Protected Health Information (PHI) and Personally Identifiable Information (PII). Use when building patient records, clinical systems, healthcare APIs, or any feature touching sensitive health or financial data.
- Classify PHI (patient-identifying health data) and PII (clinician/staff sensitive data) at the schema level
- Implement Row-Level Security (RLS) policies to isolate patient data by facility and role
- Create tamper-proof audit trails logging all PHI access and modifications with user, timestamp, and action
- Identify and prevent common data leak vectors (error messages, console logs, URL parameters, browser storage, service keys)
- Provide deployment checklists and safe logging/error handling patterns
- Support multi-tenant healthcare systems with cross-facility data isolation
How to install healthcare-phi-compliance
npx skills add https://github.com/affaan-m/everything-claude-code --skill healthcare-phi-complianceHow to use healthcare-phi-compliance
- 1.Review the data classification section to identify PHI and PII columns in your schema
- 2.Add RLS policies to all tables containing PHI or PII using the provided SQL patterns
- 3.Implement audit logging for all PHI access and modifications using the AuditEntry interface
- 4.Audit your codebase for common leak vectors: error messages, console logs, URL parameters, and browser storage
- 5.Tag PHI/PII columns with SQL COMMENT statements for schema-level documentation
- 6.Run the deployment checklist before each release to verify no PHI is exposed
Use cases
- Building patient record management systems with role-based access control
- Implementing audit compliance for HIPAA, GDPR, or DISHA regulations
- Designing healthcare APIs that return patient or clinician data securely
- Setting up Row-Level Security in multi-tenant clinical databases
- Reviewing code for PHI exposure vulnerabilities before deployment
- Healthcare software engineers and architects
- Backend developers building clinical systems or patient portals
- Database designers implementing healthcare data schemas
- Compliance officers and security reviewers
- Teams building multi-tenant healthcare platforms
healthcare-phi-compliance FAQ
PHI is any data that can identify a patient AND relates to their health: name, date of birth, address, phone, email, national IDs (SSN, Aadhaar, NHS number), medical record numbers, diagnoses, medications, lab results, imaging, insurance details, and appointment records.
Never include patient-identifying data in errors thrown to the client. Log full details server-side only with opaque internal record IDs (UUIDs), not medical record numbers or names. Return generic error messages to the client.
RLS is a database-level access control mechanism that restricts which rows a user can see based on their role and facility assignment. It prevents doctors at Facility A from querying patients at Facility B, and ensures clinicians only see patients they are authorized to treat.
No. Never store PHI in browser storage. Keep PHI in memory only and fetch it on demand from the server. Browser storage is vulnerable to XSS attacks and data leakage.
No. Never use the service_role key in client-side code. Always use the anon/publishable key and let RLS enforce access control at the database level. Service role keys bypass RLS and expose all data.
Full instructions (SKILL.md)
Source of truth, from affaan-m/everything-claude-code.
name: healthcare-phi-compliance description: Protected Health Information (PHI) and Personally Identifiable Information (PII) compliance patterns for healthcare applications. Covers data classification, access control, audit trails, encryption, and common leak vectors. metadata: origin: Health1 Super Speciality Hospitals — contributed by Dr. Keyur Patel version: "1.0.0"
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
Related skills
More from affaan-m/everything-claude-code and the wider catalog.
security-review
Security checklist and patterns for authentication, input validation, secrets, and sensitive features.
golang-patterns
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable applications.
coding-standards
Baseline coding conventions for naming, readability, immutability, and quality across projects.
frontend-patterns
React and Next.js patterns for components, state management, performance, and modern frontend practices.
backend-patterns
REST/GraphQL API design, database optimization, and server-side patterns for Node.js, Express, and Next.js.
golang-testing
Go testing patterns: table-driven tests, subtests, benchmarks, fuzzing, and TDD methodology.