Clinic protocol answer
These tasks all share one shape: a synthetic clinic exposes a read-only,
FHIR-like REST API; the prompt names one target case and requires a single
JSON object that conforms exactly to a per-task answer_template.json. The
correct output is derived by applying the applicable protocol's logic to the
facts in the case record. Your job is a faithful data-retrieval-and-mapping
task, not free clinical reasoning: read the schema, read the data, apply the
protocol, fill the template.
Do not invent values. Every scored field must be either copied from the
environment, chosen from the template's allowed_values, or computed by the
protocol's stated rule. Never assert a finding the record does not support.
Inputs to read first
For the task you are solving, read (paths are relative to the task's input dir):
prompt.txt — gives the target case id, the clinical domain, and any
hard constraints ("do not mutate", "do not place orders", "return only JSON").
payloads/answer_template.json — the authoritative output contract:
required_top_level_keys, per-field type, allowed_values (enums),
precision/unit, ordering rules, nullability (*_or_null,
["string","null"], nullable), and any required_value / expected_constant
for fixed fields. Obey this exactly — do not add or drop top-level keys.
- The separately-provided environment access file (e.g.
environment_access.md)
— the base URL, credentials, and the allowed endpoint list for this run.
Environment access
- Resolve the base URL from
GDPEVO_ENV_BASE_URL in the access file; the prompt's
<TASK_ENV_BASE_URL> placeholder refers to the same value.
- Use only the endpoints listed as allowed for the run. The API is
read-only — GET only. Do not POST orders or otherwise mutate state.
(
POST /api/query, when listed, is typically clinic-token-gated; when
credentials are "none" it returns an auth error, so rely on the GET endpoints.)
- The one call that returns everything for a case is
GET /api/cases/{case_id}. It returns a bundle with these keys:
case, patient, findings, observations, allergies, medications,
problems, imaging, care_registry, sdoh.
Standalone list endpoints (/api/patients, /api/observations,
/api/medications, /api/allergies, /api/problems, /api/imaging,
/api/care-registry, /api/sdoh) exist for cross-checking and usually accept a
patient_id query filter.
GET /api/protocols lists protocols; GET /api/protocols/{protocol_id} returns
the protocol body — the decision logic (see below).
A read-only helper, scripts/clinic.py, wraps these GET calls; see
"Helper script" at the end.
Procedure
- Fetch the case bundle:
GET /api/cases/{case_id}. Record patient_id
from case.patient_id / patient.patient_id.
- Locate the current/review time when the answer needs one: look in
findings for a current_time entry (its source_id is usually a task-clock
id). Timestamps you emit should be ISO-8601 UTC with a trailing Z.
- Select the applicable protocol. Match the case's
case_type/domain to a
protocol from GET /api/protocols, then fetch its body. The body is the
single source of truth for thresholds, code mappings, and gating. Typical
body contents:
controlled_codes — maps clinical concepts to the exact codes/enums the
template expects (test codes, NDC, LOINC, etc.). Copy these verbatim.
authoritative_statuses / status_rule — usually only status == "final"
observations count toward gates; preliminary, entered-in-error,
canceled are excluded distractors.
- thresholds and branches (e.g. target values, escalation cutoffs, red-flag
lists, dose rules, follow-up hours, ordering rules). Apply them literally.
- Gather the evidence facts. Read
findings (key/value/source_id),
observations (code, status, interpretation, value_number,
effective_time, observation_id), allergies (active vs inactive),
medications, problems, imaging (impression, status, imaging_id),
care_registry, and sdoh. Note each fact's identifier — you will cite it.
- Compute each template field by applying the protocol rule to the facts:
- Enums: pick only from that field's
allowed_values. If no rule fires, use
the template's provided "pending/none/not-eligible/no-*" style value.
- Numbers: honor
precision (e.g. one decimal, two decimals, integer) and
unit. Round exactly as the protocol's dose/rounding rule states.
- Booleans (e.g.
replacement_required, gate flags): set from the protocol
comparison against the observed value.
- Lists: include each qualifying code once (dedupe). Distinguish
present vs absent lists when the template asks for both (e.g.
red_flags vs absent_red_flags) — an "absent" list holds protocol red
flags the record explicitly rules out.
- Apply ordering rules per field. Some lists are sets ("no semantic
ordering; normalize as a set") — any order, but no duplicates. Others require
a stable sort (e.g. observations by
effective_time ascending then
observation_id ascending; evidence "case id first, then sources", or
"descending relevance"). Follow the exact note on each field.
- Fill identifiers. Set
task_id, case_id, patient_id. If the template
pins a required_value/expected_constant for a field, use it verbatim;
task_id is the task's run identifier. Otherwise take case_id/patient_id
from the prompt and case record.
- Build
evidence_ids from real resource identifiers actually used:
case_id, observation_ids, imaging_ids, and finding source_ids that
support your conclusions — ordered per the field's ordering note.
- Set
safety_checks. Each boolean asserts the answer avoided a specific
unsupported or contraindicated claim (e.g. "did not recommend a drug class the
patient is actively allergic to", "did not claim a normal image when imaging
shows a finding", "did not fabricate an absent symptom"). Verify against the
retrieved data and set true only when your answer genuinely honors the
constraint — which it should, if you followed steps 4–6 faithfully.
- Emit exactly one JSON object with only the required top-level keys, using
null only where the field spec permits it. No markdown, comments, or prose
outside the object.
Allergy- and contraindication-awareness
When the template drives a medication/replacement plan: cross-check the patient's
active allergies and any protocol contraindication/urgent branch before
choosing a strategy. Choose the strategy enum that avoids implicated classes,
populate any avoid_allergens/contraindications field from the record, and let
a contraindication or urgent branch override the routine plan (e.g. defer/hold/
escalate) when its conditions are met.
Observation-window tasks
When the task is a window retrieval: parse the window (from inclusive, to
exclusive), then partition the patient's observations. Matched = correct
target code, status == "final", effective_time within the window. Excluded
= otherwise-relevant distractors that fail on date, code, or status (e.g. a
preliminary result, a different analyte, an out-of-window date). latest_final
is the matched observation with the greatest effective_time. Set the
protocol_gate enum and repeat_lab from the protocol using that latest final
value; sort id lists as the window protocol specifies.
Validation checklist before returning
Helper script
scripts/clinic.py performs the read-only GETs (no external dependencies). Set
GDPEVO_ENV_BASE_URL (or pass --base) and run, e.g.:
export GDPEVO_ENV_BASE_URL=http://task-env:9016/
python3 scripts/clinic.py case CASE-RESP-102 # full case bundle
python3 scripts/clinic.py protocols # list protocols
python3 scripts/clinic.py protocol RESP-CAP-2026 # one protocol body
python3 scripts/clinic.py obs PAT-3303 # observations for a patient
python3 scripts/clinic.py get /api/allergies?patient_id=PAT-1002
It only issues GET requests; treat its output as read-only evidence.
1---2name: clinic-protocol-answer3description: Produce a protocol-bound clinical decision-support JSON answer for a synthetic clinic case served by a read-only FHIR-like runtime API. Use this whenever a task names a target case id (e.g. CASE-RESP-102, CASE-HEAD-207, CASE-K-303, CASE-CM-411, CASE-LAB-518), points at a runtime environment via GDPEVO_ENV_BASE_URL / <TASK_ENV_BASE_URL>, and asks for a single JSON object that conforms to an input/payloads/answer_template.json. Covers respiratory/CAP assessment, pediatric head-injury triage, potassium replacement, care-management routing, observation-window retrieval, and similar template-driven answers with controlled enums, numeric-precision fields, evidence_ids, and safety_checks.4---56# Clinic protocol answer78These tasks all share one shape: a synthetic clinic exposes a read-only,9FHIR-like REST API; the prompt names one **target case** and requires a **single10JSON object** that conforms exactly to a per-task `answer_template.json`. The11correct output is derived by applying the **applicable protocol's logic** to the12**facts in the case record**. Your job is a faithful data-retrieval-and-mapping13task, not free clinical reasoning: read the schema, read the data, apply the14protocol, fill the template.1516Do not invent values. Every scored field must be either copied from the17environment, chosen from the template's `allowed_values`, or computed by the18protocol's stated rule. Never assert a finding the record does not support.1920## Inputs to read first2122For the task you are solving, read (paths are relative to the task's input dir):23241. `prompt.txt` — gives the **target case id**, the clinical domain, and any25 hard constraints ("do not mutate", "do not place orders", "return only JSON").262. `payloads/answer_template.json` — the **authoritative output contract**:27 `required_top_level_keys`, per-field `type`, `allowed_values` (enums),28 `precision`/`unit`, `ordering` rules, nullability (`*_or_null`,29 `["string","null"]`, `nullable`), and any `required_value` / `expected_constant`30 for fixed fields. Obey this exactly — do not add or drop top-level keys.313. The separately-provided environment access file (e.g. `environment_access.md`)32 — the base URL, credentials, and the **allowed endpoint list** for this run.3334## Environment access3536- Resolve the base URL from `GDPEVO_ENV_BASE_URL` in the access file; the prompt's37 `<TASK_ENV_BASE_URL>` placeholder refers to the same value.38- Use **only** the endpoints listed as allowed for the run. The API is39 **read-only** — GET only. Do **not** POST orders or otherwise mutate state.40 (`POST /api/query`, when listed, is typically clinic-token-gated; when41 credentials are "none" it returns an auth error, so rely on the GET endpoints.)42- The one call that returns everything for a case is43 `GET /api/cases/{case_id}`. It returns a bundle with these keys:44 `case`, `patient`, `findings`, `observations`, `allergies`, `medications`,45 `problems`, `imaging`, `care_registry`, `sdoh`.46 Standalone list endpoints (`/api/patients`, `/api/observations`,47 `/api/medications`, `/api/allergies`, `/api/problems`, `/api/imaging`,48 `/api/care-registry`, `/api/sdoh`) exist for cross-checking and usually accept a49 `patient_id` query filter.50- `GET /api/protocols` lists protocols; `GET /api/protocols/{protocol_id}` returns51 the **protocol `body`** — the decision logic (see below).5253A read-only helper, `scripts/clinic.py`, wraps these GET calls; see54"Helper script" at the end.5556## Procedure57581. **Fetch the case bundle:** `GET /api/cases/{case_id}`. Record `patient_id`59 from `case.patient_id` / `patient.patient_id`.602. **Locate the current/review time** when the answer needs one: look in61 `findings` for a `current_time` entry (its `source_id` is usually a task-clock62 id). Timestamps you emit should be ISO-8601 UTC with a trailing `Z`.633. **Select the applicable protocol.** Match the case's `case_type`/domain to a64 protocol from `GET /api/protocols`, then fetch its `body`. The `body` is the65 single source of truth for thresholds, code mappings, and gating. Typical66 `body` contents:67 - `controlled_codes` — maps clinical concepts to the exact codes/enums the68 template expects (test codes, NDC, LOINC, etc.). Copy these verbatim.69 - `authoritative_statuses` / `status_rule` — usually only `status == "final"`70 observations count toward gates; `preliminary`, `entered-in-error`,71 `canceled` are excluded distractors.72 - thresholds and branches (e.g. target values, escalation cutoffs, red-flag73 lists, dose rules, follow-up hours, ordering rules). Apply them literally.744. **Gather the evidence facts.** Read `findings` (key/value/`source_id`),75 `observations` (code, `status`, `interpretation`, `value_number`,76 `effective_time`, `observation_id`), `allergies` (active vs inactive),77 `medications`, `problems`, `imaging` (`impression`, `status`, `imaging_id`),78 `care_registry`, and `sdoh`. Note each fact's identifier — you will cite it.795. **Compute each template field** by applying the protocol rule to the facts:80 - Enums: pick only from that field's `allowed_values`. If no rule fires, use81 the template's provided "pending/none/not-eligible/no-*" style value.82 - Numbers: honor `precision` (e.g. one decimal, two decimals, integer) and83 `unit`. Round exactly as the protocol's dose/rounding rule states.84 - Booleans (e.g. `replacement_required`, gate flags): set from the protocol85 comparison against the observed value.86 - Lists: include each qualifying code once (dedupe). Distinguish87 **present** vs **absent** lists when the template asks for both (e.g.88 `red_flags` vs `absent_red_flags`) — an "absent" list holds protocol red89 flags the record explicitly rules out.906. **Apply ordering rules per field.** Some lists are sets ("no semantic91 ordering; normalize as a set") — any order, but no duplicates. Others require92 a stable sort (e.g. observations by `effective_time` ascending then93 `observation_id` ascending; evidence "case id first, then sources", or94 "descending relevance"). Follow the exact note on each field.957. **Fill identifiers.** Set `task_id`, `case_id`, `patient_id`. If the template96 pins a `required_value`/`expected_constant` for a field, use it verbatim;97 `task_id` is the task's run identifier. Otherwise take `case_id`/`patient_id`98 from the prompt and case record.998. **Build `evidence_ids`** from real resource identifiers actually used:100 `case_id`, `observation_id`s, `imaging_id`s, and finding `source_id`s that101 support your conclusions — ordered per the field's ordering note.1029. **Set `safety_checks`.** Each boolean asserts the answer *avoided* a specific103 unsupported or contraindicated claim (e.g. "did not recommend a drug class the104 patient is actively allergic to", "did not claim a normal image when imaging105 shows a finding", "did not fabricate an absent symptom"). Verify against the106 retrieved data and set `true` only when your answer genuinely honors the107 constraint — which it should, if you followed steps 4–6 faithfully.10810. **Emit exactly one JSON object** with only the required top-level keys, using109 `null` only where the field spec permits it. No markdown, comments, or prose110 outside the object.111112## Allergy- and contraindication-awareness113114When the template drives a medication/replacement plan: cross-check the patient's115**active** allergies and any protocol contraindication/urgent branch *before*116choosing a strategy. Choose the strategy enum that avoids implicated classes,117populate any `avoid_allergens`/`contraindications` field from the record, and let118a contraindication or urgent branch override the routine plan (e.g. defer/hold/119escalate) when its conditions are met.120121## Observation-window tasks122123When the task is a window retrieval: parse the window (`from` inclusive, `to`124exclusive), then partition the patient's observations. **Matched** = correct125target code, `status == "final"`, `effective_time` within the window. **Excluded**126= otherwise-relevant distractors that fail on date, code, or status (e.g. a127preliminary result, a different analyte, an out-of-window date). `latest_final`128is the matched observation with the greatest `effective_time`. Set the129`protocol_gate` enum and `repeat_lab` from the protocol using that latest final130value; sort id lists as the window protocol specifies.131132## Validation checklist before returning133134- [ ] Output is a single JSON object; top-level keys == `required_top_level_keys`135 (none added, none missing).136- [ ] Every enum value is in that field's `allowed_values`.137- [ ] Numeric fields match required precision/unit; `null` only where permitted.138- [ ] List fields are deduped and ordered per each field's rule.139- [ ] `task_id`/`case_id`/`patient_id` match any pinned `required_value`.140- [ ] `evidence_ids` are real identifiers from the environment.141- [ ] `safety_checks` reflect claims actually avoided; no unsupported finding.142- [ ] No mutating requests were made; no prose outside the JSON.143144## Helper script145146`scripts/clinic.py` performs the read-only GETs (no external dependencies). Set147`GDPEVO_ENV_BASE_URL` (or pass `--base`) and run, e.g.:148149```150export GDPEVO_ENV_BASE_URL=http://task-env:9016/151python3 scripts/clinic.py case CASE-RESP-102 # full case bundle152python3 scripts/clinic.py protocols # list protocols153python3 scripts/clinic.py protocol RESP-CAP-2026 # one protocol body154python3 scripts/clinic.py obs PAT-3303 # observations for a patient155python3 scripts/clinic.py get /api/allergies?patient_id=PAT-1002156```157158It only issues GET requests; treat its output as read-only evidence.