EHR Quality-Governance Skill
Purpose
Complete EHR quality-governance tasks — duplicate-chart merge readiness packets, referral coordination, care transition packets, duplicate review with ServiceRequest validation, and batch referral audits — by querying a read-only EHR REST API, cross-referencing clinical records, validating codes, and producing normalized JSON output.
When to Use
Invoke this skill when the task involves:
- A read-only EHR REST API with endpoints for patients, conditions, medications, allergies, encounters, documents, providers, ICD-10 lookup, referrals, duplicates, audit logs, immunizations, disclosures, service requests, and service codes
- Producing a normalized JSON object that conforms to a provided answer template
- Clinical data reconciliation across multiple record sources
- ICD-10 code validation against a directory
- Quality-governance decisions (merge/disposition, referral readiness, audit action plans)
Workflow
Phase 1 — Orient
- Read the task prompt (
input/prompt.txt) to identify:
- Task type: merge packet, referral coordination, care transition, duplicate review + SR, or batch audit
- Entity IDs: patient IDs, referral IDs, candidate IDs, provider IDs, batch IDs
- The answer template path (
input/payloads/answer_template.json)
- Read the answer template to understand the required output shape, field types, enums, and ordering rules.
- Read any additional payload files (e.g.,
merge_packet_request.json) for extra context or entity lists.
- Read
environment_access.md for the base URL and allowed endpoints.
Phase 2 — Gather Evidence
Query the EHR API systematically. Start broad, then narrow:
- Patient identity:
GET /api/patients/{patient_id} for demographics, MRN, DOB, display name, provider links.
- Active clinical lists:
GET /api/patients/{patient_id}/conditions, /medications, /allergies. Filter to active records. Extract normalized_key values.
- Encounters:
GET /api/patients/{patient_id}/encounters. Sort by date; filter by relevance window and signed status.
- Documents:
GET /api/patients/{patient_id}/documents. Filter to final-status documents; classify by type (echo, office note, chart summary, etc.).
- Audit logs:
GET /api/audit-logs (may accept query params). Look for entries referencing the candidate or patient IDs.
- Duplicate candidates:
GET /api/duplicates/{candidate_id} for match/conflict signals, status.
- Referrals:
GET /api/referrals/{referral_id} or GET /api/referrals for search.
- Providers:
GET /api/providers/{provider_id} for name, role, facility, phone, fax, service line.
- ICD-10:
GET /api/icd10/{code} for chapter, description, laterality.
- Service requests:
GET /api/patients/{patient_id}/service-requests or direct lookup.
- Immunizations:
GET /api/patients/{patient_id}/immunizations — pick latest by date.
- Disclosures:
GET /api/patients/{patient_id}/disclosures — match by recipient provider and purpose.
Use the API exclusively through <TASK_ENV_BASE_URL> as the base. All endpoints are GET-only and unauthenticated.
Phase 3 — Reconcile and Validate
When data appears in multiple sources, prefer the patient-level active-list endpoints over embedded previews (e.g., duplicate candidate previews). The authoritatively sourced data is always from the dedicated patient endpoints. Track what is added vs. what the preview already contained.
For ICD-10 code validation:
- Look up each code via
GET /api/icd10/{code}.
- If the endpoint returns a result, the code is valid; check its
chapter field.
- Compare the chapter against the expected service line chapter (e.g., musculoskeletal codes for orthopedics).
- Check for laterality mismatches: compare the code's laterality with the diagnosis narrative.
- Check for narrative mismatches: compare the code's description with the stated diagnosis narrative.
- Flag as
out_of_range_chapter when the code's actual chapter doesn't match the expected service chapter; flag as unknown_code when the ICD-10 lookup returns nothing.
For duplicate candidate evaluation:
- Read match signals and conflict signals from the duplicate candidate endpoint.
- Cross-reference with patient demographics: compare DOB, insurance, phone, address, name, sex between the two patients.
- If the duplicate candidate endpoint already designates a target and source, validate that choice against the evidence.
- Clinical key unions: collect active condition/medication/allergy
normalized_key values from BOTH patients, deduplicate, and sort alphabetically.
- Document selection: include only identity-relevant or external-continuity documents; exclude internal chart summaries.
- Audit selection: include only audit entries that reference the merge candidate or patient pair.
For referral coordination:
- Identify the primary diagnosis code from the referral's reason/intake.
- Validate it against ICD-10; classify as
valid_matches_narrative, valid_but_narrative_mismatch, invalid_code, or wrong_service_chapter.
- Collect supporting codes from the same referral.
- Check allergy readiness from the patient's allergy list; classify as
complete_documented, incomplete_needs_clarification, no_known_allergies, or conflicting_allergy_records.
- Identify the most recent relevant encounter (by date) that matches the referral's clinical context.
- Evaluate document evidence: check for echo, office note, and other required documents; track what's missing.
- Assess authorization: status (
approved/pending/denied/not_required/unknown), referral status (open/closed/cancelled/draft), urgency.
- Identify medication highlights relevant to the service line.
For care transition packets:
- Select the 4 most recent encounters relevant to the surgical/service handoff, newest first.
- Apply a handoff window rule (e.g., ~90 days for orthopedic surgery). Exclude stale encounters outside the window and unrelated visit types.
- Identify the latest immunization by date.
- Match the disclosure record by recipient provider ID and purpose.
- Detect risk flags by mapping active conditions and medications to known perioperative risk categories (e.g., insulin-dependent diabetes →
perioperative_glucose_plan_needed, memory loss → cognitive_memory_loss, latex allergy → latex_allergy). Each risk flag must be backed by evidence: condition keys, medication keys, and/or encounter IDs.
For batch referral audits:
- Iterate over every referral in the batch.
- Validate each diagnosis code against ICD-10 for:
- Chapter out of range for the service line (codes with chapters other than the expected one).
- Laterality mismatch (code laterality doesn't match narrative).
- Narrative mismatch (code description doesn't match stated narrative).
- Detect duplicate groups: same patient with multiple referrals for the same clinical issue →
same_patient_resubmission type.
- Detect insurance anomalies: different patients sharing the same insurance ID.
- Build follow-up queues for: missing authorization, pending authorization, missing records (office notes), pending imaging.
- Assign tiered action plans:
- Tier 1 (immediate): duplicate blockers and urgent coding issues.
- Tier 2 (short-term): routine coding, authorization, or document blockers.
- Tier 3 (administrative): document completion tasks.
- Compute summary counts that add up correctly across all categories.
Phase 4 — Produce Output
Build the JSON output by populating every field in the answer template:
- Follow the template exactly: every required key must be present. Use the enum values as specified.
- Sort set arrays alphabetically by default, unless the template explicitly says otherwise (e.g., encounters ordered by date, referral objects by referral_id).
- Use stable IDs: never invent IDs; only use values that appear in API responses.
- Use
null where the template allows it and the data is genuinely absent (not just empty).
- Return only the JSON object — no explanatory prose, no markdown fences, no narrative text.
- Dates use YYYY-MM-DD format from API response fields.
API Reference
All endpoints are read-only GET requests against <TASK_ENV_BASE_URL>. No authentication required.
| Endpoint |
Use |
GET /api/patients |
List/search patients |
GET /api/patients/{id} |
Patient demographics, MRN, DOB, name, provider links |
GET /api/patients/{id}/conditions |
Active/inactive conditions with normalized_key, ICD-10 code, status |
GET /api/patients/{id}/medications |
Active/inactive medications with normalized_key, dose, route, frequency |
GET /api/patients/{id}/allergies |
Allergies with normalized_key, allergen, reaction, severity, status |
GET /api/patients/{id}/encounters |
Encounters with date, type, signed_status, diagnosis codes, provider |
GET /api/patients/{id}/documents |
Documents with type, status, date |
GET /api/patients/{id}/immunizations |
Immunizations with date, vaccine name |
GET /api/patients/{id}/disclosures |
Disclosure records with status, purpose, recipient |
GET /api/patients/{id}/service-requests |
ServiceRequests with status, intent, priority, codes, provider |
GET /api/audit-logs |
Audit log entries |
GET /api/duplicates/candidates |
List duplicate candidates |
GET /api/duplicates/{id} |
Duplicate candidate detail with match/conflict signals, target/source |
GET /api/referrals |
Search/list referrals |
GET /api/referrals/{id} |
Referral detail with diagnosis codes, narrative, status, patient, batch |
GET /api/icd10 |
List ICD-10 codes |
GET /api/icd10/{code} |
Code detail: description, chapter, laterality |
GET /api/providers |
List providers |
GET /api/providers/{id} |
Provider detail: name, role, facility, phone, fax, service_line |
GET /api/service-codes |
List service codes |
GET /api/service-codes/{code} |
Service code validity and detail |
Key Conventions
Normalized Keys
Clinical records carry a normalized_key field — a stable, lowercase, snake_case identifier (e.g., hypertension, diabetes_type_2, right_knee_oa). Always use these keys for set operations, comparisons, and output arrays. They are the canonical identifiers for conditions, medications, and allergies across the system.
Active vs. Inactive Records
Every condition, medication, and allergy has a status field. Only records with an active status belong in active-key arrays. Inactive, resolved, or entered-in-error records go into excluded/distractor arrays if the template asks for them.
Enum Conventions
Templates use enums extensively. Match the exact string value from the template — do not paraphrase, abbreviate, or invent values. If the template lists ready_to_merge as a disposition, use exactly that string.
Sorting Rules
- Arrays described as "sets" or with
set_semantics: true: sort alphabetically/numerically ascending by the string value.
- Arrays with explicit ordering (e.g., encounters newest-first, referrals by referral_id): follow that ordering.
- When in doubt between two conventions, alphabetical ascending is the safe default.
Reconciliation Authority
When the same clinical data appears in both a composite record (duplicate candidate preview, referral intake) and a patient-level endpoint, the patient-level endpoint is authoritative. Report any keys found in the patient endpoints that were missing from the composite.
Provider Identification
Providers are referenced by provider_id across the API. When a task names a specific provider (e.g., PRV-ORTHO-XXX), look them up via GET /api/providers/{id} to get their full profile. When a patient has a linked primary care provider, look them up the same way. For specialist providers connected to documents or referrals, trace the document/referral's provider reference.
Evidence Traceability
Every clinical claim in the output must be traceable to an API response. Risk flags map to specific condition keys, medication keys, or encounter IDs. Document evidence cites specific document IDs. Audit findings cite specific audit IDs. Never fabricate evidence identifiers.
1---2name: fewshot-attempt-02-413description: EHR Quality-Governance Skill4---5# EHR Quality-Governance Skill67## Purpose89Complete EHR quality-governance tasks — duplicate-chart merge readiness packets, referral coordination, care transition packets, duplicate review with ServiceRequest validation, and batch referral audits — by querying a read-only EHR REST API, cross-referencing clinical records, validating codes, and producing normalized JSON output.1011## When to Use1213Invoke this skill when the task involves:14- A read-only EHR REST API with endpoints for patients, conditions, medications, allergies, encounters, documents, providers, ICD-10 lookup, referrals, duplicates, audit logs, immunizations, disclosures, service requests, and service codes15- Producing a normalized JSON object that conforms to a provided answer template16- Clinical data reconciliation across multiple record sources17- ICD-10 code validation against a directory18- Quality-governance decisions (merge/disposition, referral readiness, audit action plans)1920## Workflow2122### Phase 1 — Orient23241. Read the task prompt (`input/prompt.txt`) to identify:25 - **Task type**: merge packet, referral coordination, care transition, duplicate review + SR, or batch audit26 - **Entity IDs**: patient IDs, referral IDs, candidate IDs, provider IDs, batch IDs27 - **The answer template path** (`input/payloads/answer_template.json`)282. Read the answer template to understand the required output shape, field types, enums, and ordering rules.293. Read any additional payload files (e.g., `merge_packet_request.json`) for extra context or entity lists.304. Read `environment_access.md` for the base URL and allowed endpoints.3132### Phase 2 — Gather Evidence3334Query the EHR API systematically. Start broad, then narrow:3536- **Patient identity**: `GET /api/patients/{patient_id}` for demographics, MRN, DOB, display name, provider links.37- **Active clinical lists**: `GET /api/patients/{patient_id}/conditions`, `/medications`, `/allergies`. Filter to active records. Extract `normalized_key` values.38- **Encounters**: `GET /api/patients/{patient_id}/encounters`. Sort by date; filter by relevance window and signed status.39- **Documents**: `GET /api/patients/{patient_id}/documents`. Filter to final-status documents; classify by type (echo, office note, chart summary, etc.).40- **Audit logs**: `GET /api/audit-logs` (may accept query params). Look for entries referencing the candidate or patient IDs.41- **Duplicate candidates**: `GET /api/duplicates/{candidate_id}` for match/conflict signals, status.42- **Referrals**: `GET /api/referrals/{referral_id}` or `GET /api/referrals` for search.43- **Providers**: `GET /api/providers/{provider_id}` for name, role, facility, phone, fax, service line.44- **ICD-10**: `GET /api/icd10/{code}` for chapter, description, laterality.45- **Service requests**: `GET /api/patients/{patient_id}/service-requests` or direct lookup.46- **Immunizations**: `GET /api/patients/{patient_id}/immunizations` — pick latest by date.47- **Disclosures**: `GET /api/patients/{patient_id}/disclosures` — match by recipient provider and purpose.4849Use the API exclusively through `<TASK_ENV_BASE_URL>` as the base. All endpoints are GET-only and unauthenticated.5051### Phase 3 — Reconcile and Validate5253**When data appears in multiple sources**, prefer the patient-level active-list endpoints over embedded previews (e.g., duplicate candidate previews). The authoritatively sourced data is always from the dedicated patient endpoints. Track what is *added* vs. what the preview already contained.5455**For ICD-10 code validation:**56- Look up each code via `GET /api/icd10/{code}`.57- If the endpoint returns a result, the code is valid; check its `chapter` field.58- Compare the chapter against the expected service line chapter (e.g., musculoskeletal codes for orthopedics).59- Check for laterality mismatches: compare the code's laterality with the diagnosis narrative.60- Check for narrative mismatches: compare the code's description with the stated diagnosis narrative.61- Flag as `out_of_range_chapter` when the code's actual chapter doesn't match the expected service chapter; flag as `unknown_code` when the ICD-10 lookup returns nothing.6263**For duplicate candidate evaluation:**64- Read match signals and conflict signals from the duplicate candidate endpoint.65- Cross-reference with patient demographics: compare DOB, insurance, phone, address, name, sex between the two patients.66- If the duplicate candidate endpoint already designates a target and source, validate that choice against the evidence.67- Clinical key unions: collect active condition/medication/allergy `normalized_key` values from BOTH patients, deduplicate, and sort alphabetically.68- Document selection: include only identity-relevant or external-continuity documents; exclude internal chart summaries.69- Audit selection: include only audit entries that reference the merge candidate or patient pair.7071**For referral coordination:**72- Identify the primary diagnosis code from the referral's reason/intake.73- Validate it against ICD-10; classify as `valid_matches_narrative`, `valid_but_narrative_mismatch`, `invalid_code`, or `wrong_service_chapter`.74- Collect supporting codes from the same referral.75- Check allergy readiness from the patient's allergy list; classify as `complete_documented`, `incomplete_needs_clarification`, `no_known_allergies`, or `conflicting_allergy_records`.76- Identify the most recent relevant encounter (by date) that matches the referral's clinical context.77- Evaluate document evidence: check for echo, office note, and other required documents; track what's missing.78- Assess authorization: status (`approved`/`pending`/`denied`/`not_required`/`unknown`), referral status (`open`/`closed`/`cancelled`/`draft`), urgency.79- Identify medication highlights relevant to the service line.8081**For care transition packets:**82- Select the 4 most recent encounters relevant to the surgical/service handoff, newest first.83- Apply a handoff window rule (e.g., ~90 days for orthopedic surgery). Exclude stale encounters outside the window and unrelated visit types.84- Identify the latest immunization by date.85- Match the disclosure record by recipient provider ID and purpose.86- Detect risk flags by mapping active conditions and medications to known perioperative risk categories (e.g., insulin-dependent diabetes → `perioperative_glucose_plan_needed`, memory loss → `cognitive_memory_loss`, latex allergy → `latex_allergy`). Each risk flag must be backed by evidence: condition keys, medication keys, and/or encounter IDs.8788**For batch referral audits:**89- Iterate over every referral in the batch.90- Validate each diagnosis code against ICD-10 for:91 - Chapter out of range for the service line (codes with chapters other than the expected one).92 - Laterality mismatch (code laterality doesn't match narrative).93 - Narrative mismatch (code description doesn't match stated narrative).94- Detect duplicate groups: same patient with multiple referrals for the same clinical issue → `same_patient_resubmission` type.95- Detect insurance anomalies: different patients sharing the same insurance ID.96- Build follow-up queues for: missing authorization, pending authorization, missing records (office notes), pending imaging.97- Assign tiered action plans:98 - **Tier 1 (immediate)**: duplicate blockers and urgent coding issues.99 - **Tier 2 (short-term)**: routine coding, authorization, or document blockers.100 - **Tier 3 (administrative)**: document completion tasks.101- Compute summary counts that add up correctly across all categories.102103### Phase 4 — Produce Output104105Build the JSON output by populating every field in the answer template:1061071. **Follow the template exactly**: every required key must be present. Use the enum values as specified.1082. **Sort set arrays alphabetically** by default, unless the template explicitly says otherwise (e.g., encounters ordered by date, referral objects by referral_id).1093. **Use stable IDs**: never invent IDs; only use values that appear in API responses.1104. **Use `null` where the template allows it** and the data is genuinely absent (not just empty).1115. **Return only the JSON object** — no explanatory prose, no markdown fences, no narrative text.1126. **Dates use YYYY-MM-DD format** from API response fields.113114## API Reference115116All endpoints are read-only GET requests against `<TASK_ENV_BASE_URL>`. No authentication required.117118| Endpoint | Use |119|---|---|120| `GET /api/patients` | List/search patients |121| `GET /api/patients/{id}` | Patient demographics, MRN, DOB, name, provider links |122| `GET /api/patients/{id}/conditions` | Active/inactive conditions with `normalized_key`, ICD-10 `code`, status |123| `GET /api/patients/{id}/medications` | Active/inactive medications with `normalized_key`, dose, route, frequency |124| `GET /api/patients/{id}/allergies` | Allergies with `normalized_key`, allergen, reaction, severity, status |125| `GET /api/patients/{id}/encounters` | Encounters with date, type, signed_status, diagnosis codes, provider |126| `GET /api/patients/{id}/documents` | Documents with type, status, date |127| `GET /api/patients/{id}/immunizations` | Immunizations with date, vaccine name |128| `GET /api/patients/{id}/disclosures` | Disclosure records with status, purpose, recipient |129| `GET /api/patients/{id}/service-requests` | ServiceRequests with status, intent, priority, codes, provider |130| `GET /api/audit-logs` | Audit log entries |131| `GET /api/duplicates/candidates` | List duplicate candidates |132| `GET /api/duplicates/{id}` | Duplicate candidate detail with match/conflict signals, target/source |133| `GET /api/referrals` | Search/list referrals |134| `GET /api/referrals/{id}` | Referral detail with diagnosis codes, narrative, status, patient, batch |135| `GET /api/icd10` | List ICD-10 codes |136| `GET /api/icd10/{code}` | Code detail: description, chapter, laterality |137| `GET /api/providers` | List providers |138| `GET /api/providers/{id}` | Provider detail: name, role, facility, phone, fax, service_line |139| `GET /api/service-codes` | List service codes |140| `GET /api/service-codes/{code}` | Service code validity and detail |141142## Key Conventions143144### Normalized Keys145146Clinical records carry a `normalized_key` field — a stable, lowercase, snake_case identifier (e.g., `hypertension`, `diabetes_type_2`, `right_knee_oa`). Always use these keys for set operations, comparisons, and output arrays. They are the canonical identifiers for conditions, medications, and allergies across the system.147148### Active vs. Inactive Records149150Every condition, medication, and allergy has a `status` field. Only records with an active status belong in active-key arrays. Inactive, resolved, or entered-in-error records go into excluded/distractor arrays if the template asks for them.151152### Enum Conventions153154Templates use enums extensively. Match the exact string value from the template — do not paraphrase, abbreviate, or invent values. If the template lists `ready_to_merge` as a disposition, use exactly that string.155156### Sorting Rules157158- Arrays described as "sets" or with `set_semantics: true`: sort alphabetically/numerically ascending by the string value.159- Arrays with explicit ordering (e.g., encounters newest-first, referrals by referral_id): follow that ordering.160- When in doubt between two conventions, alphabetical ascending is the safe default.161162### Reconciliation Authority163164When the same clinical data appears in both a composite record (duplicate candidate preview, referral intake) and a patient-level endpoint, the patient-level endpoint is authoritative. Report any keys found in the patient endpoints that were missing from the composite.165166### Provider Identification167168Providers are referenced by `provider_id` across the API. When a task names a specific provider (e.g., `PRV-ORTHO-XXX`), look them up via `GET /api/providers/{id}` to get their full profile. When a patient has a linked primary care provider, look them up the same way. For specialist providers connected to documents or referrals, trace the document/referral's provider reference.169170### Evidence Traceability171172Every clinical claim in the output must be traceable to an API response. Risk flags map to specific condition keys, medication keys, or encounter IDs. Document evidence cites specific document IDs. Audit findings cite specific audit IDs. Never fabricate evidence identifiers.