Skip to main content
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

ResourceDescription
App (Public)Patient intake form at /intake — no login required
App (Role-gated)Clinical triage board at /triage — clinical staff only
WorkflowIntake submission → PHI-aware risk classifier → conditional notification
Entitypatient — intake record with risk level
Settingon_call_clinician_email
IntegrationPostmark (email 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 — Postmark integration → on_call_clinician_email
     └─ false: (no action)

PHI policy: strict

Step 4: Add the Postmark integration

The system flags that a Postmark integration is needed. In chat:
“Use Postmark for the email. I’ll add the API key now.”
Go to Settings → Integrations → Add Integration → Postmark. Enter your API key. The integration is now available to the workflow.

Step 5: Configure the setting

In the Settings resource section, add:
on_call_clinician_email = [email protected]
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. conditionrisk_level == "high" → true
  5. notify_oncallsandbox: “would have sent email to [email protected] 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. Postmark sends the real alert to [email protected].
  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).