As Sherlock, I've deduced this request stems from the need for airtight compliance in handling Substance Use Disorder (SUD) records under 42 CFR Part 2. This regulation demands ironclad protections: patient consent for disclosures, bans on redisclosure, physical/logical segmentation of records, and immutable audit trails.
I've assembled a complete compliance pack below—templates, policies, database schemas, and code snippets ready for implementation in EHRs, APIs, or health systems. Copy-paste, customize, and deploy. All elements align precisely with 42 CFR §§ 2.31–2.67 (consent), § 2.32 (redisclosure), § 2.16 (segmentation), and § 2.53 (audit/accounting).
⚠️ Disclaimer: This is a toolkit, not legal advice. Consult counsel and test in your environment. Trailblazer Labs assumes no liability.
1. Consent Terms
Purpose: Standardized, revocable consent forms for SUD disclosures. Must include recipient(s), purpose, expiration (e.g., 1 year or event), and revocation rights (§ 2.31).
Sample Patient Consent Form (HTML/PDF Template)
html
<!DOCTYPE html>
<html>
<head><title>42 CFR Part 2 Consent Form</title></head>
<body>
<h1>Patient Consent for Disclosure of SUD Records (42 CFR Part 2)</h1>
<p>I, <input type="text" name="patient_name" placeholder="Patient Full Name" required>, authorize:</p>
<ul>
<li><strong>Disclosing Program:</strong> <input type="text" name="disclosing_program" placeholder="e.g., Trailblazer SUD Clinic"></li>
<li><strong>Recipient(s):</strong> <input type="text" name="recipients" placeholder="e.g., Dr. Jane Doe, Acme Hospital EMR System" required></li>
<li><strong>Purpose:</strong> <input type="text" name="purpose" placeholder="e.g., Treatment Coordination" required></li>
</ul>
<p><strong>Expiration:</strong> <input type="date" name="expiration"> (or upon event: <input type="text" name="event" placeholder="e.g., discharge">)</p>
<p><strong>Redisclosure Ban:</strong> Recipient may NOT redisclose without my written consent.</p>
<p>I may revoke this consent at any time in writing. Revocation effective upon receipt, except for prior disclosures.</p>
<p>Signature: _______________________ Date: <input type="date"></p>
<p><em>NOTICE: This consent complies with 42 CFR Part 2. SUD records are protected.</em></p>
</body>
</html>
API Consent Storage Schema (SQL)
sql
CREATE TABLE part2_consents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
patient_id UUID NOT NULL,
disclosing_program VARCHAR(255) NOT NULL,
recipients TEXT NOT NULL, -- JSON array for multiple
purpose TEXT NOT NULL,
expiration_date DATE NOT NULL,
revocation_date DATE NULL, -- NULL until revoked
signature TEXT NOT NULL, -- Base64 image or hash
created_at TIMESTAMP DEFAULT NOW(),
revoked BOOLEAN DEFAULT FALSE,
UNIQUE(patient_id, recipients, purpose) -- Prevent dupes
);
-- Index for quick checks
CREATE INDEX idx_consents_patient_active ON part2_consents(patient_id) WHERE revoked = FALSE;
Usage Policy: Before any disclosure, query SELECT * FROM part2_consents WHERE patient_id = ? AND recipients LIKE ? AND purpose = ? AND revoked = FALSE AND expiration_date > NOW();. Deny if no match.
2. Redisclosure Bans
Purpose: Prohibit recipients from redisclosing Part 2 info without new consent (§ 2.32). Use notices on all docs/emails/exports.
╔══════════════════════════════════════════════════════════════════════════════╗
║ 42 CFR PART 2 CONFIDENTIALITY NOTICE ║
║ SUD records may NOT be redisclosed without patient WRITTEN CONSENT. ║
║ Violation: Federal penalty up to $50,000 & 10 years imprisonment (42 USC §290║
║ Recipient: [DYNAMIC: Insert recipient name] | Consent Expires: [DATE] ║
╚══════════════════════════════════════════════════════════════════════════════╝
[DOCUMENT CONTENT HERE]
Email Footer Template
code
--
42 CFR Part 2 Notice: This transmission contains protected SUD information.
Do NOT redisclose without the patient's signed consent (42 CFR § 2.32).
If received in error, notify sender and destroy immediately.
API Middleware (Node.js/Express Example)
javascript
app.use('/api/part2/disclose', (req, res, next) => {
const notice = `42 CFR Part 2: Do NOT redisclose without consent. Expires: ${consent.expiration_date}`;
req.headers['x-part2-notice'] = notice; // Inject into response headers
// For PDFs: Use pdf-lib to watermark
next();
});
Policy: Append notice to ALL Part 2 exports. Log redisclosure attempts as violations.
3. Segmentation
Purpose: Segregate SUD records from general medical records. Access only with consent/qualified personnel (§ 2.16, § 2.19).
-- Main patient table (non-SUD)
CREATE TABLE patients (
id UUID PRIMARY KEY,
name VARCHAR(255),
dob DATE,
-- NO SUD fields here
);
-- Segregated SUD table (encrypted at rest)
CREATE TABLE part2_sud_records (
id UUID PRIMARY KEY,
patient_id UUID REFERENCES patients(id) ON DELETE CASCADE,
sud_data JSONB NOT NULL, -- Encrypted payload
access_consent_id UUID REFERENCES part2_consents(id),
created_at TIMESTAMP DEFAULT NOW(),
FOREIGN KEY (patient_id) -- But queries require consent join
);
-- Row-Level Security (RLS) Policy
ALTER TABLE part2_sud_records ENABLE ROW LEVEL SECURITY;
CREATE POLICY part2_access ON part2_sud_records
FOR ALL USING (
EXISTS (SELECT 1 FROM part2_consents c
WHERE c.patient_id = part2_sud_records.patient_id
AND c.recipients LIKE '%' || current_user || '%'
AND NOT c.revoked
AND c.expiration_date > CURRENT_DATE)
);
Access Control List (ACL) Policy Document
code
PART 2 SEGMENTATION POLICY
1. SUD records stored in isolated DB schema/table.
2. Access requires:
- Valid Part 2 consent matching user/recipient.
- Role: 'part2-auditor', 'qualified-personnel', or consented recipient.
3. No joins/queries mixing SUD + non-SUD without consent.
4. Encryption: AES-256 at rest/transit.
5. Physical: Separate servers/VPCs for SUD if possible.
Violation: Immediate termination + report to SAMHSA.
Implementation Tip: Use ORMs like Prisma/Sequelize with RLS hooks. Firewall queries.
4. Audit Logs
Purpose: Immutable logs of all access/disclosures for 6+ years (§ 2.53). Include who, what, when, why.
Audit Log Schema (SQL)
sql
CREATE TABLE part2_audit_logs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
patient_id UUID NOT NULL,
user_id UUID NOT NULL, -- Who accessed
action VARCHAR(50) NOT NULL, -- 'VIEW', 'DISCLOSE', 'REVOKE'
resource_type VARCHAR(50), -- 'RECORD', 'CONSENT'
resource_id UUID,
ip_address INET,
user_agent TEXT,
reason TEXT, -- Consent ID or 'emergency'
success BOOLEAN NOT NULL,
timestamp TIMESTAMP DEFAULT NOW(),
INDEX idx_audit_patient (patient_id, timestamp),
INDEX idx_audit_user (user_id, timestamp)
);
-- Immutable: No UPDATE/DELETE triggers
CREATE TRIGGER prevent_audit_mod BEFORE UPDATE OR DELETE ON part2_audit_logs
FOR EACH ROW RAISE EXCEPTION 'Audit logs immutable';
Logging Function (Python Example – For Flask/Django)
python
import uuid
import logging
from datetime import datetime
def log_part2_access(patient_id, user_id, action, resource_id, reason, success=True):
log_entry = {
'id': str(uuid.uuid4()),
'patient_id': patient_id,
'user_id': user_id,
'action': action,
'resource_id': resource_id,
'reason': reason,
'success': success,
'timestamp': datetime.utcnow()
}
# Insert to DB (e.g., via SQLAlchemy)
db.session.add(AuditLog(**log_entry))
db.session.commit()
logging.info(f"Part 2 Audit: {action} on {patient_id} by {user_id}")
Query for Accounting of Disclosures (Patient Request)
sql
SELECT * FROM part2_audit_logs
WHERE patient_id = ?
AND action IN ('DISCLOSE', 'VIEW')
ORDER BY timestamp DESC
LIMIT 100; -- Provide to patient on request (§ 2.23)
Retention Policy: Archive logs for 6 years post-final disclosure. Export to CSV/PDF for audits.
Deployment Checklist
Integrate consent checks into all SUD endpoints.
Watermark all exports.
Enable RLS on SUD tables.
Auto-log every access (middleware/hook).
Train staff: Annual Part 2 certification.
Test: Simulate revocation—ensure access blocks.
Report: SAMHSA hotline for breaches.
This pack forms a fortress against breaches. If you need integrations (e.g., FHIR, AWS), schemas for other DBs, or Holmes-level forensics on your setup, provide details. Elementary! 🕵️♂️