Communitygithub.com

医療向けPHI/PIIコンプライアンス

医療アプリケーションにおける保護対象保健情報(PHI)と個人識別情報(PII)のコンプライアンスパターン。データ分類、アクセス制御、監査証跡、暗号化、一般的な漏洩ベクトルをカバーします。PHIやPIIを扱うコードや、アクセス制御・監査証跡・漏洩ベクトルの監査時に使用します。

PIIコンプライアンス とは?

このスキルは、医療アプリケーションにおける患者データ、臨床データ、財務データの保護に特化したコンプライアンスパターンを提供します。HIPAA(米国)、DISHA(インド)、GDPR(EU)など、主要な規制に準拠するための実践的なガイドラインです。データ分類(PHI/PIIの定義)、行レベルセキュリティ(RLS)によるアクセス制御、改ざん防止可能な監査証跡、エラーメッセージやログ・URLパラメータ・ブラウザストレージなど一般的な漏洩ベクトルの防止策を具体的なコード例とともに解説します。主にPostgreSQLとTypeScriptを前提としており、Claude Code、Cursor、CodexなどのAIエージェントが医療システムを構築・レビューする際に、安全なデータ取り扱いを徹底するためのガイドとして機能します。

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

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

医療向けPHI/PIIコンプライアンスパターン

医療アプリケーションにおける患者データ、臨床データ、財務データを保護するためのパターン。HIPAA(米国)、DISHA(インド)、GDPR(EU)、および一般的な医療データ保護に適用可能です。

使用するタイミング

  • 患者記録に触れる機能を構築する場合
  • 臨床システムのアクセス制御や認証を実装する場合
  • 医療データのデータベーススキーマを設計する場合
  • 患者データや臨床データを返すAPIを構築する場合
  • 監査証跡やログを実装する場合
  • データ露出の脆弱性がないかコードをレビューする場合
  • マルチテナント医療システムの行レベルセキュリティ(RLS)を設定する場合

仕組み

医療データ保護は3つの層で機能します:分類(何が機密か)、アクセス制御(誰が見られるか)、監査(誰が見たか)。

データ分類

PHI(保護対象保健情報) — 患者を識別でき、かつその健康に関連するデータ:患者名、生年月日、住所、電話番号、メールアドレス、国民ID番号(SSN、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)を使用する — 診療記録番号、国民ID、氏名は使用しない。

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.

関連スキル