Cedar Ridge Intake Coordination — Agent Operating Procedure
Purpose
This skill covers the reusable workflow for completing Cedar Ridge healthcare intake coordination tasks. Each task instance provides a natural-language prompt, an answer template JSON schema, and optionally additional input payloads. The agent queries a REST + SQL API to gather records, reconciles data across endpoints, applies business rules encoded in the template's controlled vocabularies, and returns a single JSON object conforming exactly to the template.
Do not hard-code task-specific values (roster IDs, batch IDs, patient lists, program codes, dates). Read them from the prompt and template. All tasks follow the same skeleton; this document describes the skeleton.
Phase 1 — Orient
1.1 Read the environment manifest
Read environment_access.md (project root, or at the path noted in the prompt). It supplies:
base_url — the root of the coordination portal API.
allowed_endpoints — the exact HTTP method + path combinations available.
- Any credential or access notes.
Substitute every occurrence of <TASK_ENV_BASE_URL> in the prompt and any payload with the base_url from this file. No other base URLs are valid.
1.2 Read the prompt
The prompt (prompt.txt, or the path given) names:
- The task type (access verification, referral audit, transfer review, enrollment panel, referral-to-chart activation, etc.).
- The target batch/roster/cohort identifier.
- Any extra input payloads (e.g., a roster file or candidate list path).
- The output template path (
input/payloads/answer_template.json or as specified).
1.3 Read the answer template
The answer template is the source of truth for every field, type, allowed value, ordering, and required key in the final output. Read it before querying the API — it tells you what to look for.
Pay attention to:
| Template feature |
How to apply |
required_top_level_keys |
Every key in this list must appear in the final object. |
type: "enum" with allowed_values / allowed |
Only these exact strings may appear in that field. Never invent codes. |
type: "list" with ordering |
Sort as specified: ascending <field>, alphabetical by <field>, or unordered set (any order, no duplicates). |
required_value / expected_value / constant |
The field must hold this exact value. Copy it verbatim. |
format: "YYYY-MM-DD" |
All dates must use ISO-8601 calendar-date strings. |
numeric_precision: "integer counts" |
Summary counts are integers, never floats. |
type: "boolean" |
Use JSON true / false (not strings). |
type: "integer_or_null" |
The field is either a whole number or JSON null. |
type: "enum_or_null" |
The field is one of the allowed strings or JSON null. |
item_required_keys |
Every element in a list of objects must include these keys. |
1.4 Read additional input payloads
If the prompt or template references extra payload files (e.g., target_roster.json), read them. They may supply the target patient/referral list, service dates, or other task-scoped parameters. Incorporate those values when assembling the output (e.g., requested_service_date from the roster record).
Phase 2 — Gather
2.1 Choose endpoints
From environment_access.md, the standard endpoints are:
| Method |
Path |
Typical use |
GET |
/ |
Health check / portal root. |
GET |
/patients |
List all patients. |
GET |
/patients/{patient_id} |
Single patient profile, insurance, demographics. |
GET |
/referrals |
List all referrals (specialty intake batches). |
GET |
/referrals/{referral_id} |
Single referral: ICD codes, urgency, status, documents, authorizations. |
GET |
/transfers |
List all transfers (dialysis, facility transfers). |
GET |
/transfers/{transfer_id} |
Single transfer: packet documents, requested start, patient, receiving facility. |
GET |
/documents |
List all documents. Filter or correlate with patient/transfer IDs from other endpoints. |
GET |
/chart/{patient_id} |
Patient chart: active problems, vitals, labs, medications, allergies, consent status. |
GET |
/programs/{program_code}/candidates |
Candidates for a chronic-care program identified by program code. |
GET |
/icd/{code} |
ICD-10 code metadata: chapter, description, laterality when applicable. |
GET |
/pharmacies |
Pharmacy directory with network status. |
POST |
/query |
Read-only SQL endpoint. Send {"query": "<SQL>"}. Use for cross-entity reconciliation when REST endpoints alone are insufficient. |
Only use endpoints listed in the manifest. Do not guess URLs.
2.2 Fan-out strategy
- Fetch the batch-level collection first (e.g.,
GET /referrals, GET /transfers, GET /programs/{code}/candidates, GET /patients). Filter client-side to the target batch/roster.
- Drill into each record — for each referral, transfer, or patient in the batch, fetch its detail endpoint and its associated chart (
GET /chart/{patient_id}).
- Resolve code metadata — for every ICD-10 code encountered, call
GET /icd/{code} to retrieve chapter and laterality.
- Resolve pharmacy data — when insurance or prescription benefit checks require network status, consult
GET /pharmacies.
- Pull documents —
GET /documents and correlate by patient_id, transfer_id, or referral_id to assess completeness.
2.3 Use POST /query for reconciliation
When you need to join across entities or verify consistency, use the SQL endpoint:
POST /query
{"query": "SELECT ..."}
This is especially useful for:
- Finding referrals that share the same insurance policy across different patients.
- Listing documents associated with transfers or referrals.
- Checking for duplicate referrals (same patient, same specialty, overlapping dates).
The exact query syntax depends on the portal's schema. Explore with SELECT * FROM <table> LIMIT 1 first to discover column names.
Phase 3 — Reconcile
Apply business rules derived from the template's controlled vocabularies and the task prompt. These are the reusable rule categories; the specific codes and thresholds come from the template.
3.1 Insurance and benefits verification
- Compare each patient's insurance fields against the
valid / invalid / missing enum in the template.
- Check prescription benefit (PBM) validity using the template's reason codes.
- Cross-reference the patient's pharmacy against the
/pharmacies directory to determine in_network / out_of_network / unknown.
3.2 Clinical coding and narrative consistency
- For each referral, compare its ICD-10 codes against:
- The ICD metadata (
/icd/{code}) — chapter should match the referring specialty.
- The referral narrative/description — the condition described should be consistent with the codes.
- Laterality — if the code has a laterality component, it must match the narrative and the body site.
- Flag discrepancies using the issue codes from the template.
3.3 Duplicate detection
- Group referrals by patient + specialty + overlapping date windows.
- For each group, decide
consolidate_to_primary vs keep_separate based on whether they are true duplicates or distinct episodes of care.
- Include a
primary_referral_id (the one to keep) in each group.
3.4 Document / packet completeness
- For transfers and referrals, enumerate the required document types from the template.
- Compare against documents returned by the API; flag any missing.
- Check document freshness: each document type may have a
freshness_limit_days in the template. If received_date is older than that limit, flag as stale.
3.5 Authorization status
- Check the authorization field on each referral.
- Map to the template's auth status enum (
pending, denied, not_submitted).
- A denied or not-submitted authorization is a blocker.
3.6 Capacity and scheduling feasibility
- For transfers: compare
requested_start date against facility chair capacity.
- Map to the capacity/feasibility enum in the template.
3.7 Chart activation readiness
- For referrals moving to scheduling: check whether the patient's chart exists and contains all required artifacts (demographics, active problems, medications, allergies, vitals, labs, consent).
- Chart action is
create_chart, update_chart, or no_chart_action depending on what's missing.
3.8 Risk stratification
- When the template includes risk fields (
lifestyle_risk, overall_risk), assess from patient chart data: vitals, labs, diagnoses, recent utilization, social history.
- Map to the template's
low / medium / high enum.
3.9 Program eligibility
- For enrollment panels: each candidate is eligible (boolean) based on whether they meet the program's target condition criteria, have an active chart, and have not declined consent.
- Map to
enroll / hold / reject based on eligibility + completeness.
- Assign reason codes, follow-up cadence, outreach channel, and monitoring package per the template's allowed values.
Phase 4 — Assemble
4.1 Build the JSON skeleton
Start from the required_top_level_keys in the template. Populate each key in order.
4.2 Populate list fields
- Sort every list as specified by its
ordering directive.
- For unordered sets, use any stable order but treat duplicates as set membership.
- Include every item identified in Phase 3. Empty lists use
[], never null.
4.3 Populate enum fields
- Use only strings from the field's
allowed_values / allowed array.
- If a template defines
enum_or_null, use null when no value applies (do not invent a placeholder string).
4.4 Build cohort summaries
Compute counts after all per-item results are finalized. Every count must reconcile with the item-level data. Common summary structures:
counts_by_<dimension> — an object whose keys are enum values and values are integer counts.
total_<entity> — the cardinality of the batch.
- Cross-tabulations — for compound summaries, produce the Cartesian product of the two dimensions, each entry with its count.
Double-check: sum of all status counts must equal total_<entity>. Sum of risk counts must equal the total. If any count does not add up, revisit the item-level data.
4.5 Include fixed fields
Copy required_value / expected_value / constant fields exactly from the template. The task_id (or equivalent identifier) must match the template's expected value.
Phase 5 — Validate
Before returning, verify:
- All
required_top_level_keys are present in the output object.
- Every
required_value / expected_value / constant matches the template exactly.
- Every enum field contains a value from its
allowed_values / allowed list (or null when enum_or_null).
- Every list is ordered as specified. Uppercase IDs match the portal exactly (do not downcase).
- All dates are in
YYYY-MM-DD format.
- Summary counts are integers and reconcile with the item-level data.
- No prose, markdown, or explanation appears outside the JSON object. The final response is the raw JSON only, unless the prompt explicitly allows wrapping.
- No extra keys beyond those defined in the template. Do not add helper fields, comments, or debug data.
Common pitfalls
- Premature output: Do not start writing JSON until all API calls are complete and all cross-references are resolved. Incomplete data leads to incorrect summaries.
- Invented codes: Never guess a reason code, status, or category. If the template does not list a value that fits, re-read the data — the correct mapping is within the allowed set.
- Wrong base URL: Always resolve
<TASK_ENV_BASE_URL> from environment_access.md. Hard-coding localhost or a different port will fail.
- ID casing: Referral IDs, patient IDs, roster IDs, and batch IDs are case-sensitive. Preserve casing exactly as returned by the API.
- SQL discovery: The
POST /query endpoint schema is not documented in advance. Use SELECT * FROM <table> LIMIT 1 to explore before writing complex joins.
- Stale freshness: When a document has a
freshness_limit_days, compute staleness as (current_date - received_date) > freshness_limit_days. Use the current date from context (today's date), not an arbitrary constant.
- List ordering mismatch: "Ascending by referral_id" means lexical sort on the ID string, not insertion order. Verify before finalizing.
- Empty vs null: An empty list is
[]. An absent value is null (only when enum_or_null or integer_or_null permits it). Do not use null for required list fields.
Supporting files
environment_access.md — base URL and allowed endpoints (project root or per-instance).
input/payloads/answer_template.json — output schema, controlled vocabularies, ordering rules.
- Additional payloads (e.g.,
target_roster.json) — task-scoped parameters referenced by the prompt.
1---2name: self-attempt-02-543description: Cedar Ridge Intake Coordination — Agent Operating Procedure4---5# Cedar Ridge Intake Coordination — Agent Operating Procedure67## Purpose89This skill covers the reusable workflow for completing Cedar Ridge healthcare intake coordination tasks. Each task instance provides a natural-language prompt, an answer template JSON schema, and optionally additional input payloads. The agent queries a REST + SQL API to gather records, reconciles data across endpoints, applies business rules encoded in the template's controlled vocabularies, and returns a single JSON object conforming exactly to the template.1011Do **not** hard-code task-specific values (roster IDs, batch IDs, patient lists, program codes, dates). Read them from the prompt and template. All tasks follow the same skeleton; this document describes the skeleton.1213---1415## Phase 1 — Orient1617### 1.1 Read the environment manifest1819Read `environment_access.md` (project root, or at the path noted in the prompt). It supplies:2021- `base_url` — the root of the coordination portal API.22- `allowed_endpoints` — the exact HTTP method + path combinations available.23- Any credential or access notes.2425Substitute every occurrence of `<TASK_ENV_BASE_URL>` in the prompt and any payload with the `base_url` from this file. No other base URLs are valid.2627### 1.2 Read the prompt2829The prompt (`prompt.txt`, or the path given) names:3031- The task type (access verification, referral audit, transfer review, enrollment panel, referral-to-chart activation, etc.).32- The target batch/roster/cohort identifier.33- Any extra input payloads (e.g., a roster file or candidate list path).34- The output template path (`input/payloads/answer_template.json` or as specified).3536### 1.3 Read the answer template3738The answer template is the **source of truth** for every field, type, allowed value, ordering, and required key in the final output. Read it before querying the API — it tells you what to look for.3940Pay attention to:4142| Template feature | How to apply |43|---|---|44| `required_top_level_keys` | Every key in this list must appear in the final object. |45| `type: "enum"` with `allowed_values` / `allowed` | Only these exact strings may appear in that field. Never invent codes. |46| `type: "list"` with `ordering` | Sort as specified: `ascending <field>`, `alphabetical by <field>`, or `unordered set` (any order, no duplicates). |47| `required_value` / `expected_value` / `constant` | The field must hold this exact value. Copy it verbatim. |48| `format: "YYYY-MM-DD"` | All dates must use ISO-8601 calendar-date strings. |49| `numeric_precision: "integer counts"` | Summary counts are integers, never floats. |50| `type: "boolean"` | Use JSON `true` / `false` (not strings). |51| `type: "integer_or_null"` | The field is either a whole number or JSON `null`. |52| `type: "enum_or_null"` | The field is one of the allowed strings or JSON `null`. |53| `item_required_keys` | Every element in a list of objects must include these keys. |5455### 1.4 Read additional input payloads5657If the prompt or template references extra payload files (e.g., `target_roster.json`), read them. They may supply the target patient/referral list, service dates, or other task-scoped parameters. Incorporate those values when assembling the output (e.g., `requested_service_date` from the roster record).5859---6061## Phase 2 — Gather6263### 2.1 Choose endpoints6465From `environment_access.md`, the standard endpoints are:6667| Method | Path | Typical use |68|---|---|---|69| `GET` | `/` | Health check / portal root. |70| `GET` | `/patients` | List all patients. |71| `GET` | `/patients/{patient_id}` | Single patient profile, insurance, demographics. |72| `GET` | `/referrals` | List all referrals (specialty intake batches). |73| `GET` | `/referrals/{referral_id}` | Single referral: ICD codes, urgency, status, documents, authorizations. |74| `GET` | `/transfers` | List all transfers (dialysis, facility transfers). |75| `GET` | `/transfers/{transfer_id}` | Single transfer: packet documents, requested start, patient, receiving facility. |76| `GET` | `/documents` | List all documents. Filter or correlate with patient/transfer IDs from other endpoints. |77| `GET` | `/chart/{patient_id}` | Patient chart: active problems, vitals, labs, medications, allergies, consent status. |78| `GET` | `/programs/{program_code}/candidates` | Candidates for a chronic-care program identified by program code. |79| `GET` | `/icd/{code}` | ICD-10 code metadata: chapter, description, laterality when applicable. |80| `GET` | `/pharmacies` | Pharmacy directory with network status. |81| `POST` | `/query` | Read-only SQL endpoint. Send `{"query": "<SQL>"}`. Use for cross-entity reconciliation when REST endpoints alone are insufficient. |8283Only use endpoints listed in the manifest. Do not guess URLs.8485### 2.2 Fan-out strategy86871. **Fetch the batch-level collection first** (e.g., `GET /referrals`, `GET /transfers`, `GET /programs/{code}/candidates`, `GET /patients`). Filter client-side to the target batch/roster.882. **Drill into each record** — for each referral, transfer, or patient in the batch, fetch its detail endpoint and its associated chart (`GET /chart/{patient_id}`).893. **Resolve code metadata** — for every ICD-10 code encountered, call `GET /icd/{code}` to retrieve chapter and laterality.904. **Resolve pharmacy data** — when insurance or prescription benefit checks require network status, consult `GET /pharmacies`.915. **Pull documents** — `GET /documents` and correlate by patient_id, transfer_id, or referral_id to assess completeness.9293### 2.3 Use POST /query for reconciliation9495When you need to join across entities or verify consistency, use the SQL endpoint:9697```98POST /query99{"query": "SELECT ..."}100```101102This is especially useful for:103- Finding referrals that share the same insurance policy across different patients.104- Listing documents associated with transfers or referrals.105- Checking for duplicate referrals (same patient, same specialty, overlapping dates).106107The exact query syntax depends on the portal's schema. Explore with `SELECT * FROM <table> LIMIT 1` first to discover column names.108109---110111## Phase 3 — Reconcile112113Apply business rules derived from the template's controlled vocabularies and the task prompt. These are the **reusable rule categories**; the specific codes and thresholds come from the template.114115### 3.1 Insurance and benefits verification116117- Compare each patient's insurance fields against the `valid` / `invalid` / `missing` enum in the template.118- Check prescription benefit (PBM) validity using the template's reason codes.119- Cross-reference the patient's pharmacy against the `/pharmacies` directory to determine `in_network` / `out_of_network` / `unknown`.120121### 3.2 Clinical coding and narrative consistency122123- For each referral, compare its ICD-10 codes against:124 - The ICD metadata (`/icd/{code}`) — chapter should match the referring specialty.125 - The referral narrative/description — the condition described should be consistent with the codes.126 - Laterality — if the code has a laterality component, it must match the narrative and the body site.127- Flag discrepancies using the issue codes from the template.128129### 3.3 Duplicate detection130131- Group referrals by patient + specialty + overlapping date windows.132- For each group, decide `consolidate_to_primary` vs `keep_separate` based on whether they are true duplicates or distinct episodes of care.133- Include a `primary_referral_id` (the one to keep) in each group.134135### 3.4 Document / packet completeness136137- For transfers and referrals, enumerate the required document types from the template.138- Compare against documents returned by the API; flag any missing.139- Check document freshness: each document type may have a `freshness_limit_days` in the template. If `received_date` is older than that limit, flag as stale.140141### 3.5 Authorization status142143- Check the authorization field on each referral.144- Map to the template's auth status enum (`pending`, `denied`, `not_submitted`).145- A denied or not-submitted authorization is a blocker.146147### 3.6 Capacity and scheduling feasibility148149- For transfers: compare `requested_start` date against facility chair capacity.150- Map to the capacity/feasibility enum in the template.151152### 3.7 Chart activation readiness153154- For referrals moving to scheduling: check whether the patient's chart exists and contains all required artifacts (demographics, active problems, medications, allergies, vitals, labs, consent).155- Chart action is `create_chart`, `update_chart`, or `no_chart_action` depending on what's missing.156157### 3.8 Risk stratification158159- When the template includes risk fields (`lifestyle_risk`, `overall_risk`), assess from patient chart data: vitals, labs, diagnoses, recent utilization, social history.160- Map to the template's `low` / `medium` / `high` enum.161162### 3.9 Program eligibility163164- For enrollment panels: each candidate is eligible (boolean) based on whether they meet the program's target condition criteria, have an active chart, and have not declined consent.165- Map to `enroll` / `hold` / `reject` based on eligibility + completeness.166- Assign reason codes, follow-up cadence, outreach channel, and monitoring package per the template's allowed values.167168---169170## Phase 4 — Assemble171172### 4.1 Build the JSON skeleton173174Start from the `required_top_level_keys` in the template. Populate each key in order.175176### 4.2 Populate list fields177178- Sort every list as specified by its `ordering` directive.179- For unordered sets, use any stable order but treat duplicates as set membership.180- Include every item identified in Phase 3. Empty lists use `[]`, never `null`.181182### 4.3 Populate enum fields183184- Use **only** strings from the field's `allowed_values` / `allowed` array.185- If a template defines `enum_or_null`, use `null` when no value applies (do not invent a placeholder string).186187### 4.4 Build cohort summaries188189Compute counts after all per-item results are finalized. Every count must reconcile with the item-level data. Common summary structures:190191- `counts_by_<dimension>` — an object whose keys are enum values and values are integer counts.192- `total_<entity>` — the cardinality of the batch.193- Cross-tabulations — for compound summaries, produce the Cartesian product of the two dimensions, each entry with its count.194195Double-check: sum of all status counts must equal `total_<entity>`. Sum of risk counts must equal the total. If any count does not add up, revisit the item-level data.196197### 4.5 Include fixed fields198199Copy `required_value` / `expected_value` / `constant` fields exactly from the template. The `task_id` (or equivalent identifier) must match the template's expected value.200201---202203## Phase 5 — Validate204205Before returning, verify:2062071. **All `required_top_level_keys` are present** in the output object.2082. **Every `required_value` / `expected_value` / `constant` matches** the template exactly.2093. **Every enum field** contains a value from its `allowed_values` / `allowed` list (or `null` when `enum_or_null`).2104. **Every list is ordered** as specified. Uppercase IDs match the portal exactly (do not downcase).2115. **All dates** are in `YYYY-MM-DD` format.2126. **Summary counts are integers** and reconcile with the item-level data.2137. **No prose, markdown, or explanation** appears outside the JSON object. The final response is the raw JSON only, unless the prompt explicitly allows wrapping.2148. **No extra keys** beyond those defined in the template. Do not add helper fields, comments, or debug data.215216---217218## Common pitfalls219220- **Premature output**: Do not start writing JSON until all API calls are complete and all cross-references are resolved. Incomplete data leads to incorrect summaries.221- **Invented codes**: Never guess a reason code, status, or category. If the template does not list a value that fits, re-read the data — the correct mapping is within the allowed set.222- **Wrong base URL**: Always resolve `<TASK_ENV_BASE_URL>` from `environment_access.md`. Hard-coding `localhost` or a different port will fail.223- **ID casing**: Referral IDs, patient IDs, roster IDs, and batch IDs are case-sensitive. Preserve casing exactly as returned by the API.224- **SQL discovery**: The `POST /query` endpoint schema is not documented in advance. Use `SELECT * FROM <table> LIMIT 1` to explore before writing complex joins.225- **Stale freshness**: When a document has a `freshness_limit_days`, compute staleness as `(current_date - received_date) > freshness_limit_days`. Use the current date from context (today's date), not an arbitrary constant.226- **List ordering mismatch**: "Ascending by referral_id" means lexical sort on the ID string, not insertion order. Verify before finalizing.227- **Empty vs null**: An empty list is `[]`. An absent value is `null` (only when `enum_or_null` or `integer_or_null` permits it). Do not use `null` for required list fields.228229---230231## Supporting files232233- `environment_access.md` — base URL and allowed endpoints (project root or per-instance).234- `input/payloads/answer_template.json` — output schema, controlled vocabularies, ordering rules.235- Additional payloads (e.g., `target_roster.json`) — task-scoped parameters referenced by the prompt.