Communitygithub.com

医疗PHI/PII合规模式

面向医疗应用的受保护健康信息(PHI)和个人身份信息(PII)合规模式。涵盖数据分类、访问控制、审计跟踪、加密以及常见泄露向量。当代码涉及医疗系统中的PHI或PII,或审计访问控制、审计跟踪、泄露向量时使用。

PII合规模式 是什么?

该技能为开发AI Agent或构建医疗相关应用的开发者提供了一套完整的PHI/PII合规模式。它基于医疗数据保护的三层架构:数据分类(标识敏感内容)、访问控制(限制谁能看到)和审计(记录谁看过)。技能详细定义了PHI(如患者姓名、诊断、病历号)和PII(如医生薪酬、员工银行信息)的边界,并提供了具体实现方法,包括使用Row-Level Security(RLS)进行多机构数据隔离、通过不可篡改的审计日志追踪所有数据访问、以及在错误处理、日志记录、URL参数和浏览器存储等环节避免数据泄露的实践。支持HIPAA(美国)、DISHA(印度)和GDPR(欧盟)等主流医疗数据保护法规。该技能适用于Claude Code、Cursor、Codex等AI Agent平台,可通过读取项目的SKILL.md文件自动激活。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/healthcare-phi-compliance

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

PII合规模式 是做什么的?

保护医疗应用中患者数据、临床医生数据和财务数据的模式。适用于HIPAA(美国)、DISHA(印度)、GDPR(欧盟)及通用医疗数据保护。

何时使用

  • 构建任何涉及患者记录的功能
  • 实现临床系统的访问控制或身份验证
  • 设计医疗数据的数据库架构
  • 构建返回患者或临床医生数据的API
  • 实现审计跟踪或日志记录
  • 审查代码中的数据暴露漏洞
  • 为多租户医疗系统设置行级安全(RLS)

工作原理

医疗数据保护分为三个层级:分类(哪些是敏感的)、访问控制(谁能看到)和审计(谁看到了)。

数据分类

PHI(受保护健康信息)——任何能够识别患者身份且与其健康相关的数据:患者姓名、出生日期、地址、电话、电子邮件、国家身份证号(社会安全号码、阿达尔号码、NHS号码)、病历号、诊断、药物、化验结果、影像、保险单和理赔详情、预约和入院记录,或上述信息的任意组合。

**PII(非患者敏感数据)**在医疗系统中包括:临床医生/员工个人信息、医生收费结构和付款金额、员工工资和银行信息、供应商付款信息。

访问控制:行级安全

ALTER TABLE patients ENABLE ROW LEVEL SECURITY;

-- 按机构限定访问范围
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')
  ));

-- 审计日志:仅插入(防篡改)
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);

审计跟踪

每次PHI访问或修改都必须记录:

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;
}

常见泄露向量

错误消息: 切勿在返回给客户端的错误消息中包含患者身份识别数据。详细信息仅在服务器端记录。

控制台输出: 切勿记录完整的患者对象。使用不透明的内部记录ID(UUID)——而非病历号、国家身份证号或姓名。

URL参数: 切勿在可能出现在日志或浏览器历史记录中的查询字符串或路径段中包含患者身份识别数据。仅使用不透明的UUID。

浏览器存储: 切勿将PHI存储在localStorage或sessionStorage中。PHI仅保留在内存中,按需获取。

服务角色密钥: 切勿在客户端代码中使用service_role密钥。始终使用anon/publishable密钥,并让RLS强制执行访问控制。

日志和监控: 切勿记录完整的患者记录。仅使用不透明的记录ID(而非病历号)。在发送到错误跟踪服务之前,清理堆栈跟踪。

数据库模式标记

在模式级别标记PHI/PII列:

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';

部署检查清单

每次部署前:

  • 错误消息或堆栈跟踪中无PHI
  • console.log/console.error中无PHI
  • URL参数中无PHI
  • 浏览器存储中无PHI
  • 客户端代码中无service_role密钥
  • 所有PHI/PII表上已启用RLS
  • 所有数据修改均有审计跟踪
  • 已配置会话超时
  • 所有PHI端点均需API身份验证
  • 已验证跨机构数据隔离

示例

示例1:安全与不安全的错误处理

// 错误——在错误中泄露PHI
throw new Error(`患者 ${patient.name} 在 ${patient.facility} 未找到`);

// 正确——通用错误,详情在服务器端使用不透明ID记录
logger.error('患者查找失败', { recordId: patient.id, facilityId });
throw new Error('记录未找到');

示例2:多机构隔离的RLS策略

-- 机构A的医生无法看到机构B的患者
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()
  ));

-- 测试:以机构A医生身份登录,查询机构B患者
-- 预期:返回0行

示例3:安全日志记录

// 错误——记录了可识别的患者数据
console.log('正在处理患者:', patient);

// 正确——仅记录不透明的内部记录ID
console.log('正在处理记录:', patient.id);
// 注意:即使patient.id也应为不透明的UUID,而非病历号

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能