> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usehasp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Example: Patient Intake & Triage

> A UI-backed workflow that collects patient intake data, runs a PHI-aware risk classifier, and routes to the on-call clinician. The canonical healthcare Studio example.

This example walks through building a complete patient intake and clinical triage system in AI Studio — a UI-backed workflow with a public intake form, AI-powered risk classification, and a role-gated clinician dashboard.

## What you're building

| Resource             | Description                                                              |
| -------------------- | ------------------------------------------------------------------------ |
| **App** (Public)     | Patient intake form at `/intake` — no login required                     |
| **App** (Role-gated) | Clinical triage board at `/triage` — clinical staff only                 |
| **Workflow**         | Intake submission → PHI-aware risk classifier → conditional notification |
| **Entity**           | `patient` — intake record with risk level                                |
| **Setting**          | `on_call_clinician_email`                                                |
| **Integration**      | Email over SMTP (`email_smtp`) — notifications                           |

## Step 1: Create the project

In AI Studio, click **New Project**. Name it *Patient Intake v1*.

## Step 2: Describe what you want

In chat:

> *"I need a patient intake form that patients can fill out without logging in. It should collect their name, date of birth, chief complaint, and whether they have any known allergies. When they submit, an AI should classify the urgency as low, medium, or high. If high, page the on-call clinician immediately. The clinician should see a dashboard with all recent intakes sorted by urgency."*

The system responds:

* Creates a `patient` entity with fields: `name`, `date_of_birth`, `chief_complaint`, `known_allergies`, `risk_level`
* Creates a **Public** app (intake form) at `/intake`
* Creates a **Role-gated** app (clinical triage board) at `/triage` with audience: clinical staff
* Creates an intake workflow with trigger: form submission
* Compiles a workflow with steps: receive payload → PHI detection → risk classifier (AI inference) → conditional branch → notification

## Step 3: Review the contract

Open the contract view (right panel). The intake workflow contract shows:

```
Trigger: user_interaction (form submission, app: patient-intake)

Steps:
  1. phi_scan        — scan payload for PHI; anonymize for inference
  2. risk_classify   — AI inference: classify urgency from chief_complaint
                       output: { risk_level: enum[low, medium, high] }
  3. entity_write    — write patient record with risk_level
  4. condition       — if risk_level == "high"
     ├─ true:  notify_oncall — email integration → on_call_clinician_email
     └─ false: (no action)

PHI policy: strict
```

## Step 4: Add the email integration

The system flags that an email integration is needed. In chat:

> *"Use our SMTP server for the email. I'll add the credentials now."*

Go to **Settings → Integrations → Add Integration → Email (SMTP)**. Enter your SMTP credentials. The integration is now available to the workflow.

## Step 5: Configure the setting

In the Settings resource section, add:

```
on_call_clinician_email = oncall@acme-health.com
```

The notification step already references this setting by name.

## Step 6: Test the intake form

The center pane shows the **live intake form** running in sandbox mode. Fill it out:

* Name: *Jane Doe*
* Date of birth: *1985-03-15*
* Chief complaint: *Severe chest pain radiating to left arm, shortness of breath*
* Known allergies: *Penicillin*

Click **Submit**. Watch the trace appear in real time.

## Step 7: Inspect the trace

The trace shows:

1. `phi_scan` — detected PHI in `name`, `date_of_birth`. Anonymized for inference.
2. `risk_classify` — AI classified `risk_level: high` (confidence: 0.97). Inference ran on anonymized payload; re-identified for record write.
3. `entity_write` — patient record created. Record ID: `pat_01JA7QG2...`
4. `condition` — `risk_level == "high"` → true
5. `notify_oncall` — **sandbox:** *"would have sent email to [oncall@acme-health.com](mailto:oncall@acme-health.com) with subject: High-risk intake: chest pain."*

Integration call was edge-sandboxed. No real email was sent.

## Step 8: Test the triage board

Switch center pane to the triage app (`/triage`). The board shows the intake you just submitted, sorted by risk level, with the urgency badge visible. Click the record to see the full intake summary.

## Step 9: Release

Click **Release**. Review:

* **Summary**: *"First release: patient intake form, clinical triage board, and high-risk notification workflow."*
* **Diff**: 2 new apps, 1 new workflow, 1 new entity (6 fields), 1 new integration, 1 new setting.
* No schema migrations needed (first release).

Confirm and publish. The intake form is now live at `acme.usehasp.run/intake`. The triage board is live at `acme.usehasp.run/triage` (access-controlled to clinical staff).

## What happens in production

1. A real patient submits the intake form.
2. PHI detection scans the payload. PHI is anonymized before the AI inference call.
3. The risk classifier runs. Output: `risk_level: high`.
4. Patient record is written with `risk_level: high`. PHI is stored encrypted in the entity record.
5. The email integration sends the real alert to `oncall@acme-health.com`.
6. The clinician opens the triage board. The new intake appears at the top, risk badge: **High**.
7. The full trace is available in the audit log. PHI-redacted view for standard users; PHI-view role required for raw data.

## Extending the example

Common follow-ons:

* **Add a follow-up workflow** triggered when the clinician marks the intake as *reviewed* (data-change event on `patient.status`).
* **Add a discharge summary workflow** triggered on discharge — AI generates a summary and posts to the billing system.
* **Add appointment scheduling** — integration with a scheduling system, triggered after clinician review.
* **Require 2 approvers for all releases** — set in Settings → Release Policy (or as the org floor).
