Communitygithub.com

醫療保健 PHI/PII 合規模式

針對醫療保健應用程式的受保護健康資訊 (PHI) 與個人識別資訊 (PII) 合規模式。涵蓋資料分類、存取控制、稽核軌跡、加密及常見洩漏向量。當程式碼在醫療系統中涉及 PHI 或 PII,或稽核存取控制、稽核軌跡或洩漏向量時使用。

PII 合規模式 是什麼?

此技能提供一套完整的模式,協助開發人員在醫療保健應用程式中保護病患、臨床人員及財務資料,並符合 HIPAA(美國)、DISHA(印度)、GDPR(歐盟)等法規。其核心運作基於三個層級:資料分類(識別 PHI 與 PII)、存取控制(透過資料庫列層級安全性 RLS 限制誰能查看資料)以及稽核(記錄所有存取與修改)。技能涵蓋常見的資料洩漏向量,例如錯誤訊息、主控台輸出、URL 參數、瀏覽器儲存、服務角色金鑰以及日誌/監控,並提供具體的安全與不安全撰寫範例。此外,還包含資料庫綱要標記、部署前檢查清單以及跨機構隔離的 RLS 政策範例,適用於 Claude Code、Cursor、Codex 等 AI 編碼代理,協助團隊在開發流程中即時實踐合規性。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

PII 合規模式 是做什麼的?

用於保護醫療保健應用程式中病患資料、臨床人員資料和財務資料的模式。適用於 HIPAA(美國)、DISHA(印度)、GDPR(歐盟)以及一般的醫療保健資料保護。

使用時機

  • 建置任何涉及病患記錄的功能
  • 為臨床系統實作存取控制或驗證
  • 設計醫療保健資料的資料庫綱要
  • 建置回傳病患或臨床人員資料的 API
  • 實作稽核軌跡或記錄
  • 審查程式碼是否存在資料暴露漏洞
  • 為多租戶醫療保健系統設定列層級安全性 (RLS)

運作方式

醫療保健資料保護分為三個層級:分類(何者為敏感資料)、存取控制(誰可以查看)以及稽核(誰曾經查看)。

資料分類

PHI(受保護健康資訊) — 任何能夠識別病患且與其健康相關的資料:病患姓名、出生日期、地址、電話、電子郵件、國家身分證號碼(社會安全號碼、Aadhaar、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 ${patient.name} not found in ${patient.facility}`);

// 好 — 通用錯誤,詳細資訊使用不透明 ID 在伺服器端記錄
logger.error('Patient lookup failed', { recordId: patient.id, facilityId });
throw new Error('Record not found');

範例 2:多機構隔離的 RLS 政策

-- Facility A 的醫師無法查看 Facility 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()
  ));

-- 測試:以 facility-a 的醫師身分登入,查詢 facility-b 的病患
-- 預期:回傳 0 行

範例 3:安全記錄

// 不好 — 記錄可識別的病患資料
console.log('Processing patient:', patient);

// 好 — 僅記錄不透明的內部記錄 ID
console.log('Processing record:', 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/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

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.

相關技能