# Review clinical orders

Have a verified clinician review an AI agent's proposed prescription, lab or referral and its reasoning, and authorize it with a passkey before your system places it.

Use clinician ordering when an AI agent proposes a prescription, lab or referral that a licensed clinician must approve. The agent submits the order with its reasoning, and the clinician reviews both and authorizes with a passkey. You get a signed record of who authorized exactly what, when, with which verified credential. Your system then places the order.

**Before you begin:** export the sandbox Enterprise key. Its account has a seeded prescriber whose NPI is verified.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
```

**Limitations:** Provenance authorizes and records; it doesn't place orders, make clinical decisions or check drug interactions. It isn't certified for electronic prescribing of controlled substances (EPCS), so a controlled order is authorized for the record and your system transmits it under its own authority.

## 1. Register the prescriber

Register each clinician with `POST /v1/authorize/prescribers`. Provenance checks the credentials itself and assigns a tier; a tier sent by the client is ignored.

| `tier` | Confirmed by |
| --- | --- |
| `self_attested` | Nothing yet: a name on file |
| `npi_verified` | A valid NPI whose name matches the CMS NPPES registry |
| `license_verified` | An active state license with no disciplinary action, from a credential vendor |
| `dea_verified` | A valid DEA registration, from a credential vendor |

A match on a federal exclusion list sets `excluded: true`, and that prescriber's orders are refused whatever their tier.

**curl**

```bash
curl $PROVENANCE_API/v1/authorize/prescribers \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "full_name": "Jane Doe, MD", "npi": "1234567893", "license_state": "MA" }'
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const prescriber = await prov.authorize.prescribers.create({ fullName: "Jane Doe, MD", npi: "1234567893", licenseState: "MA" });
```

**Python**

```python
import os
import httpx

api, headers = os.environ["PROVENANCE_API"], {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
prescriber = httpx.post(f"{api}/v1/authorize/prescribers", json={"full_name": "Jane Doe, MD", "npi": "1234567893", "license_state": "MA"}, headers=headers).json()
```

The response, trimmed:

```json
{
  "id": "presc_01M5Q2ZT9RZK82MNZTBANQV36H",
  "object": "prescriber",
  "full_name": "Jane Doe, MD",
  "npi": "1234567893",
  "excluded": false,
  "exclusion_checked": false
}
```

The `tier` field shows the result, and `evidence` lists each credential source and what it found. A source that isn't set up on the server says so, and the tier stops below it: without a credential vendor, the highest tier is `npi_verified`.

## 2. Check which orders need which tier

The `clinical_order` [policy](https://provenanceauth.com/docs/concepts/policies.md) sets the tier each kind of order needs, and which need a second clinician. Read it with [`GET /v1/mandate/policies`](https://provenanceauth.com/docs/api/policies.md#get-v1-mandate-policies):

**curl**

```bash
curl "$PROVENANCE_API/v1/authorize/clinical_order_policies" \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const policy = await prov.mandate.policies.get({ domain: "clinical_order" });
```

**Python**

```python
policy = httpx.get(f"{api}/v1/mandate/policies", params={"domain": "clinical_order"}, headers=headers).json()
```

```json
{
  "object": "policy",
  "domain": "clinical_order",
  "document": {
    "rules": [
      { "id": "controlled-substance", "match": { "controlled": true }, "required_tier": "dea_verified", "cosign": true },
      { "id": "prescription", "match": { "order_type": "rx" }, "required_tier": "npi_verified" }
    ],
    "default_required_tier": "self_attested"
  },
  "is_default": true
}
```

By default a controlled substance needs a `dea_verified` prescriber and a second clinician's co-sign, and a prescription needs `npi_verified`. Change it with `PUT /v1/authorize/clinical_order_policies`.

## 3. Submit the agent's order

The agent submits the order with `POST /v1/authorize/clinical_orders`. The `payload` is bound by hash, so the order placed can't differ from the one authorized. The `reasoning` is the agent's own account, bound into the record and shown to the clinician labelled as agent-supplied.

**curl**

```bash
curl -s $PROVENANCE_API/v1/authorize/clinical_orders \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prescriber_id": "presc_00000000000000000000000048",
    "order_type": "rx",
    "payload": { "drug": "amoxicillin", "dose": "500mg", "route": "PO", "quantity": 30, "frequency": "TID" },
    "reasoning": { "diagnosis": "strep pharyngitis", "rapid_strep": "positive" }
  }' | tee order.json
export ORDER_ID=$(jq -r .id order.json)
```

**Node**

```ts
const order = await prov.authorize.clinicalOrders.create({
  prescriberId: "presc_00000000000000000000000048",
  orderType: "rx",
  payload: { drug: "amoxicillin", dose: "500mg", route: "PO", quantity: 30, frequency: "TID" },
  reasoning: { diagnosis: "strep pharyngitis", rapid_strep: "positive" },
});
```

**Python**

```python
order = httpx.post(f"{api}/v1/authorize/clinical_orders", json={
    "prescriber_id": "presc_00000000000000000000000048",
    "order_type": "rx",
    "payload": {"drug": "amoxicillin", "dose": "500mg", "route": "PO", "quantity": 30, "frequency": "TID"},
    "reasoning": {"diagnosis": "strep pharyngitis", "rapid_strep": "positive"},
}, headers=headers).json()
```

The response, trimmed:

```json
{
  "id": "ord_01M5Q30H0NRZKYZAC2SGFRGVRX",
  "object": "order",
  "status": "pending_review",
  "order_type": "rx",
  "controlled": false,
  "clinical_summary": "amoxicillin · 500mg · PO · 30 · TID",
  "prescriber": { "full_name": "Jane Doe, MD", "npi": "1234567893", "tier": "npi_verified", "excluded": false },
  "required_tier": "npi_verified",
  "approvals_needed": 1,
  "policy": { "id": "pol_3F9A1C7E52B04D8E6A1F27C9B4", "version": null, "rule": { "id": "prescription", "name": null, "phase": "assess", "action": "review", "conditions": [] } }
}
```

Orders wait 24 hours for review, then expire.

## 4. The clinician reviews and decides

Show the clinician the order and its reasoning, in your EHR with the [`<provenance-clinical-order>` embed](https://provenanceauth.com/docs/embeds.md) or on your own screen. They authorize with a passkey, as in [biometric approval](https://provenanceauth.com/docs/mandate/guides/biometric-approval.md), through `POST /v1/authorize/clinical_orders/{id}/approve`. Re-sending the payload checks that it hasn't changed.

**curl**

```bash norun
curl $PROVENANCE_API/v1/authorize/clinical_orders/$ORDER_ID/approve \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"device_id\": \"$DEVICE_ID\",
    \"biometric_challenge\": \"$BIOMETRIC_CHALLENGE\",
    \"biometric_assertion\": $(cat assertion.json),
    \"action_payload\": { \"drug\": \"amoxicillin\", \"dose\": \"500mg\", \"route\": \"PO\", \"quantity\": 30, \"frequency\": \"TID\" }
  }"
```

**Node**

```ts
const decided = await prov.authorize.clinicalOrders.authorize(order.id, {
  deviceId,
  biometricChallenge,
  biometricAssertion,
  actionPayload: { drug: "amoxicillin", dose: "500mg", route: "PO", quantity: 30, frequency: "TID" },
});
```

**Python**

```python
decided = httpx.post(f"{api}/v1/authorize/clinical_orders/{order['id']}/approve", json={
    "device_id": device_id,
    "biometric_challenge": biometric_challenge,
    "biometric_assertion": biometric_assertion,
    "action_payload": {"drug": "amoxicillin", "dose": "500mg", "route": "PO", "quantity": 30, "frequency": "TID"},
}, headers=headers).json()
```

```json
{
  "id": "ord_01M5Q30H0NRZKYZAC2SGFRGVRX",
  "object": "order",
  "status": "authorized",
  "authorized_tier": "npi_verified",
  "outcome": "authorized"
}
```

To refuse, the clinician declines with `POST /v1/authorize/clinical_orders/{id}/decline`. A decided order can't be decided again.

**curl**

```bash
curl $PROVENANCE_API/v1/authorize/clinical_orders/$ORDER_ID/decline \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "reason": "Penicillin allergy on file" }'
```

**Node**

```ts
await prov.authorize.clinicalOrders.decline(order.id, "Penicillin allergy on file");
```

**Python**

```python
httpx.post(f"{api}/v1/authorize/clinical_orders/{order['id']}/decline", json={"reason": "Penicillin allergy on file"}, headers=headers)
```

```json
{
  "id": "ord_01M5Q30H0NRZKYZAC2SGFRGVRX",
  "object": "order",
  "status": "declined",
  "decline_reason": "Penicillin allergy on file",
  "outcome": "declined"
}
```

## 5. Place the authorized order

Subscribe a [webhook](https://provenanceauth.com/docs/integrate/webhooks.md) to `authorize.clinical_order.authorized`; your system places the order when it arrives. Read the order to confirm the status rather than trusting a browser event. For the record, `GET /v1/authorize/clinical_orders/{id}/receipt` returns an ES256-signed receipt with the prescriber's tier and the sealed reasoning, verifiable offline against the [published keys](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md).

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `outcome: "denied"`, `reason: "prescriber_tier_insufficient"` | The prescriber's tier is below what the policy requires | Verify more credentials, or route to a qualified prescriber. |
| `outcome: "denied"`, `reason: "prescriber_excluded"` | The prescriber is on a federal exclusion list | The order can't be authorized by this prescriber. |
| `outcome: "cosign_pending"`, `reason: "controlled_substance_cosign_required"` | A controlled order needs a second clinician | Have a second clinician authorize too. |
| `400` [`approval_biometric_required`](https://provenanceauth.com/docs/platform/errors.md#approval_biometric_required) | Authorize was sent without a passkey assertion | Have the clinician confirm with a passkey. |
| `payload_hash_mismatch` | The payload sent at authorize differs from the one submitted | Send the order's payload unchanged. |

## See also

- [Biometric approval](https://provenanceauth.com/docs/mandate/guides/biometric-approval.md)
- [Execution binding](https://provenanceauth.com/docs/mandate/guides/execution-binding.md)
- [Embeds](https://provenanceauth.com/docs/embeds.md)
