# Step 4 · Build the kiosk app

Canonical page: https://docs.ovok.com/guides/staffed-kiosk/build-the-kiosk-app

A web app for a ward tablet: one sign-in per shift, then scan, check, record and hand over, patient after patient.

## Before you begin [#before-you-begin]

- The function from step 3, running.
- `@ovok/core` 0.4.58 or newer. The example pins 0.4.58.

## Configure the kiosk [Client-side] [#configure-the-kiosk-client-side]

~~~dotenv title=".env.local"
VITE_OVOK_API_BASE_URL=https://api.sandbox.ovok.com
VITE_OVOK_TENANT_CODE={{TENANT_CODE}}
VITE_SUPABASE_URL=http://127.0.0.1:54321
VITE_STATION_NAME=Ward 3 measurement station
~~~

These are browser-visible settings, not secrets. The kiosk holds no Supabase key: the function is its only way into the register.

## Sign the nurse in [Client-side] [#sign-the-nurse-in-client-side]

Create one [Ovok client](/web-sdk/core/getting-started) and [sign the nurse in](/web-sdk/core/guides/sign-in) as a practitioner. Keeping the session in `sessionStorage` survives a reload mid-shift and ends when the tab closes.

~~~ts title="src/lib/ovok.ts"
export const ovok = new Ovok({
  baseUrl: config.ovokBaseUrl,
  tenantCode: config.tenantCode,
  fhirPath: "/fhir/R4/",
  storage: window.sessionStorage,
  timeoutMs: 15_000,
});
~~~

~~~ts title="src/components/SignIn.tsx"
const result = await ovok.auth.login({ profileType: "Practitioner", email, password });
if (result.status === "mfa-required") setChallenge(result.challenge);
~~~

The function needs the same token. Read it from the session, and let the SDK renew it first when it is about to expire:

~~~ts title="src/lib/ovok.ts"
export async function accessToken(): Promise<string> {
  const session = await ovok.session.current();
  if (!session) throw new SignedOutError();
  if (session.expiresAt - Date.now() > TOKEN_MARGIN_MS) return session.accessToken;

  await ovok.auth.me();
  const renewed = await ovok.session.current();
  if (!renewed) throw new SignedOutError();
  return renewed.accessToken;
}
~~~

## Look the patient up [Client-side] [#look-the-patient-up-client-side]

A barcode scanner types the card code and presses Enter, so the scan field is an ordinary form. The kiosk posts the code to the function with the nurse's token:

~~~ts title="src/lib/patients.ts"
const response = await fetch(`${config.supabaseUrl}/functions/v1/patients/_search`, {
  method: "POST",
  headers: { authorization: `Bearer ${await accessToken()}`, "content-type": "application/json" },
  body: JSON.stringify({ cardCode }),
});
~~~

A `404` means nobody has the card; the kiosk offers to register it, which posts the new patient to `/functions/v1/patients`.

## Check identity, then save [Client-side] [#check-identity-then-save-client-side]

The kiosk shows the name and date of birth in large type and unlocks the reading form only after the nurse confirms both with the patient. Then it saves the reading for that patient's Ovok Patient:

~~~ts title="src/lib/readings.ts"
const measurement: BloodPressureMeasurement = {
  measurementTypeKey: MeasurementTypeKey.bloodPressure,
  systolic: entry.systolic,
  diastolic: entry.diastolic,
  ...(entry.pulse === null ? {} : { heartRate: entry.pulse }),
};
const result = await ovok.measurements.save({
  patientId: ovokPatientId,
  sourceId: readingId,
  effectiveDateTime: new Date(),
  measurement,
});
~~~

- `patientId` is the `ovokPatientId` the function returned, not the register's id.
- `sourceId` is generated once per form, so a retry after a dropped connection finds the first save instead of storing the reading twice. See [ovok.measurements](/web-sdk/core/namespaces/measurements).
- `result.status` is `queued` when the tablet is offline; tell the nurse the reading is kept on the tablet.

## Show recent readings [Client-side] [#show-recent-readings-client-side]

Each saved reading is a blood-pressure panel (LOINC `85354-9`) and a heart rate (`8867-4`) that share a reading identifier. The kiosk reads both with one [FHIR search](/web-sdk/core/namespaces/fhir) and pairs them:

~~~ts title="src/lib/readings.ts"
const page = await ovok.fhir.search("Observation", {
  subject: `Patient/${ovokPatientId}`,
  code: "http://loinc.org|85354-9,http://loinc.org|8867-4",
  _sort: "-date",
  _count: 6,
});
~~~

## Show the shift on the home board [Client-side] [#show-the-shift-on-the-home-board-client-side]

The kiosk's home is a station board: the scan card beside a tile for each patient measured this shift. Names stay hidden until the nurse taps **Show names**, and the list lives only in memory, so it is gone when the shift ends.

The board also shows how many blood-pressure readings the project has today, with a count-only FHIR search:

~~~ts title="src/lib/readings.ts"
const page = await ovok.fhir.search("Observation", {
  code: "http://loinc.org|85354-9",
  date: `ge${midnight.toISOString()}`,
  _summary: "count",
});
return page.total;
~~~

## Clear the station [Client-side] [#clear-the-station-client-side]

The next person at the station must never see the last patient. "Next patient" is the main action after a save, and the kiosk returns to scanning after 90 seconds without a touch or key press.

## Verify your integration [#verify-your-integration]

1. Start the kiosk with `npm run dev` and sign in as a nurse.
2. Scan or type `WARD-0042` and register the patient when the kiosk offers to.
3. Confirm the identity and save `124/79`, pulse `66`.

The reading appears under "Recent readings in Ovok". If it doesn't:

1. A `403` on save means the nurse's access policy lacks Observation create.
2. `Kept on this tablet` means the save was queued; check the tablet's connection.
3. A register error names the problem; see the function's troubleshooting in step 3.

## Next step [#next-step]

Continue to [step 5: run it on the ward](/guides/staffed-kiosk/run-it-on-the-ward).
