Sahl Voice with a background iframe¶
Use this mode when clinicians record with the Sahl Voice desktop app instead of the panel inside your EHR. Your EHR page loads a small background iframe that has no visible UI. When the clinician finishes in Sahl Voice, the note and codes arrive at your page as the same write-back messages the panel sends. Your EHR fills the chart exactly as it does for the panel, with no screen automation.
sequenceDiagram
autonumber
actor Doc as Clinician
participant EHR as Your EHR page
participant BG as Background iframe
participant SV as Sahl Voice (desktop)
participant Sahl as Sahl AI
Doc->>EHR: Clicks "Sahl AI"
EHR->>BG: Load background iframe (patient, encounter)
BG->>Sahl: Register the open encounter
EHR->>SV: Open sahlvoice://scribe?px_id=…&ex_id=…
Note over SV: Clinician records, reviews, edits
SV->>Sahl: Finished note and codes
Sahl->>BG: Deliver to the encounter's background iframe
BG-->>EHR: Clinical note
BG-->>EHR: Codification (icd-automation)
BG->>Sahl: Delivered
Sahl-->>SV: Delivered
What you build¶
- A Sahl AI button on the encounter screen.
- On click, in this order:
- Load the background iframe for the current patient and encounter.
- Open Sahl Voice with the same patient and encounter.
- A message listener for the write-back messages. If you already integrate the panel, you can reuse your existing one.
The background iframe and Sahl Voice must get exactly the same px_id and ex_id, with the same characters and case. Sahl AI uses them to deliver the note to the right encounter. The access token in the iframe and the clinician signed in to Sahl Voice must belong to the same Sahl AI organization.
1. Load the background iframe¶
The background iframe uses the same launch modes as the panel, with /ehr-relay added to the entry point:
| Mode | Entry point |
|---|---|
| Secure handshake (recommended) | https://dev.sahl-ai.pages.dev/iframe-secure/ehr-relay |
| Access token in URL | https://dev.sahl-ai.pages.dev/iframe/ehr-relay?access_token=… (proofs of concept only) |
The Secure JWT handshake is not available for the background iframe yet. If you use PKI, contact [email protected].
<iframe id="sahl-background"
src="https://dev.sahl-ai.pages.dev/iframe-secure/ehr-relay"
aria-hidden="true"
tabindex="-1"
style="position:absolute; width:0; height:0; border:0"></iframe>
Answer the handshake exactly as for the panel. In the SAHL_IFRAME_INIT payload, px_id and ex_id are required. Without them the background iframe doesn't start.
const SAHL_ORIGIN = "https://dev.sahl-ai.pages.dev";
const background = document.getElementById("sahl-background");
window.addEventListener("message", (event) => {
if (event.origin !== SAHL_ORIGIN) return;
if (event.source !== background.contentWindow) return;
if (event.data?.type === "SAHL_IFRAME_READY") {
background.contentWindow.postMessage(
{
type: "SAHL_IFRAME_INIT",
payload: {
access_token: ACCESS_TOKEN, // required
px_id: "PATIENT_ID", // required here
ex_id: "ENCOUNTER_ID" // required here
}
},
SAHL_ORIGIN
);
return;
}
handleSahlData(event.data); // the same handler as for the panel
});
Keep in mind:
- No permissions are needed. The background iframe never records, so leave out
allow="microphone; display-capture". - Keep it mounted for the whole encounter. If the clinician finishes in Sahl Voice after you removed the iframe, the note can't be delivered. Sahl Voice keeps it, so the clinician can send it again once the encounter is open. Hide the iframe with zero size, as above, inside an element that stays on the page.
- Load it before opening Sahl Voice, so it is registered long before the note is ready.
- For another patient or encounter, reset the iframe
srcand answer the newSAHL_IFRAME_READY. - Tokens: if the access token expires while the iframe is open, the iframe stops listening. Load it with a fresh token for each encounter. Login tokens last 24 hours.
2. Open Sahl Voice¶
Open this URI from the same click, right after loading the iframe:
sahlvoice://scribe?px_id=<patient id>&ex_id=<encounter id>&ux_id=<user id>&age=<age in days>&gender=<male|female>&email=<physician email>
| Parameter | Required | Description |
|---|---|---|
px_id |
Yes | Your patient identifier (MRN). Must match the iframe's px_id. |
ex_id |
Yes | Your encounter or visit identifier. Must match the iframe's ex_id. |
ux_id |
Optional | Your user (clinician) identifier. |
age |
Optional | Patient age in days, as described in Age format. |
gender |
Optional | male or female. Leave it out for other values. |
email |
Optional | The physician's email address. |
Never put an access token or a password in this URI.
function openSahlVoice(patient, encounter, clinician) {
const params = new URLSearchParams({
px_id: patient.id,
ex_id: encounter.id,
});
if (clinician.id) params.set("ux_id", clinician.id);
if (patient.dateOfBirth) params.set("age", String(ageInDays(patient.dateOfBirth)));
if (patient.gender === "male" || patient.gender === "female") params.set("gender", patient.gender);
if (clinician.email) params.set("email", clinician.email);
// An anchor click keeps your page in place if Sahl Voice isn't installed.
const link = document.createElement("a");
link.href = `sahlvoice://scribe?${params}`;
link.click();
}
- Sahl Voice must be installed on the clinician's computer. Installing it registers the
sahlvoice://scheme. - Browsers open an app link only from a user action, so call this inside the button's click handler.
- The first time, the browser asks the clinician to allow opening Sahl Voice. They can tick Always allow for your EHR's site.
3. Receive the note¶
When the clinician sends the note from Sahl Voice, the background iframe posts the same messages as the panel, in the same order: first the clinical note, then the codification envelope when codification is enabled. Handle them with your existing write-back code.
- One note arrives once. If Sahl Voice retries after a network problem, the background iframe drops the repeat.
- A new or amended note for the same encounter arrives as a new pair of messages. Treat the latest one as current.
- If more than one background iframe is open for the same encounter, for example in two tabs, only one of them posts the note.
Checklist¶
- The iframe and Sahl Voice get identical
px_idandex_id. - The background iframe loads before Sahl Voice opens, and stays mounted for the whole encounter.
- The iframe's token and the Sahl Voice user are in the same Sahl AI organization.
- Your listener checks
event.originandevent.source. - No token or password appears in the
sahlvoice://URI. - Your Content Security Policy allows
https://dev.sahl-ai.pages.devas a frame source.