# Athena Upload Button — Implementation Note

## What

Wire up the empty "Athena" button in `pdf_gen_widget.dart` (~line 504) to upload the balance test PDF to athenaOne. The server endpoint already exists and is tested — this is app-side only.

## How It Should Work

1. User taps the **Athena** button after a test is scored
2. If `realPatientid` is empty → show error dialog: **"No athenaOne patient ID linked to this patient. Set the Real Patient ID in patient settings first."** Stop here.
3. Show confirmation dialog: **"Upload balance test results to athenaOne for {firstName} {lastName}?"** with Cancel / Upload buttons
4. On Upload:
   - Show a loading spinner
   - Generate the PDF (same as the existing Generate PDF / Email PDF flow — `pdf.save()` → `Uint8List`)
   - Base64 encode the PDF bytes: `base64Encode(pdfBytes)`
   - POST JSON to `https://kinometric.com/back_athena_send.php`
5. On success → green snackbar: **"Uploaded to athenaOne (Document #{clinicaldocumentid})"**
6. On error → red snackbar with the error message from the server

## API Call

**Endpoint:** `POST https://kinometric.com/back_athena_send.php`

**Request body (JSON):**
```json
{
  "user_id": <FFAppState().userId>,
  "encryption_key": <FFAppState().encryptionKey>,
  "athena_patient_id": <FFAppState().realPatientid>,
  "patient": "<firstName> <lastName>",
  "pdf": "<base64 encoded PDF bytes>"
}
```

Note: `department_id` is optional — the server uses a configured default if omitted. No need to add a department picker in the app.

**Success response:**
```json
{
  "success": true,
  "clinicaldocumentid": 212361,
  "message": "Document uploaded to athenaOne successfully."
}
```

**Error response:**
```json
{
  "success": false,
  "error": "reason here"
}
```

## Pattern to Follow

This is the same pattern as the existing **Email PDF** button — generate PDF in memory, base64 encode, POST to a `back_*.php` endpoint, show result. The only differences are:
- Different endpoint (`back_athena_send.php` instead of `back_mail_pdf.php`)
- Different fields (`athena_patient_id` + `patient` instead of `emailAddress`)
- No email address input needed

## Edge Cases

- **No realPatientid** → block the upload with an error (this is the main guard rail)
- **Network error / timeout** → show the error, don't retry automatically
- **Server returns `success: false`** → show the `error` field from the response
