Clara Form
Voice to form: a consultation fills the medical form while people talk
AI form filling: a simulated consultation fills a Clara Form field by field through the widget's public events, with the source sentence per value.
Loading the preview…
Simulation: no voice and no AI are involved. The replay shows what the integration does with synthetic data.
<script src="https://cdn.clara.care/form/latest.js"></script>
<main class="demo demo-split">
<section aria-labelledby="visit-h">
<div class="demo-actions">
<h2 id="visit-h">Consultation</h2>
<button type="button" id="replay">Replay simulated consultation</button>
</div>
<p class="demo-note">
Simulation: a scripted conversation with synthetic data. In production, Clara Widget
transcribes the voice and dispatches these same events.
</p>
<ol id="transcript" class="demo-transcript" aria-live="polite"></ol>
</section>
<!-- live: the form listens to the clara:* events of the page, the ones the widget publishes -->
<clara-form lang="en" live submit-label="Save visit"></clara-form>
</main>
// Inline template (same shape as GET /api/templates).
const template = {
id: 'visit-demo',
name: 'General visit',
sections: [
{
key: 'visit',
label: 'Visit',
fields: [
{ id: 'reason', type: 'text', label: 'Reason for visit', required: true },
{ id: 'history', type: 'textarea', label: 'History of present illness' },
],
},
{
key: 'vitals',
label: 'Vital signs',
fields: [
{ id: 'temperature', type: 'number', label: 'Temperature (°C)', min: 30, max: 45 },
{ id: 'blood_pressure', type: 'text', label: 'Blood pressure', placeholder: '120/80', pattern: '\\d{2,3}/\\d{2,3}' },
{ id: 'smoker', type: 'checkbox', label: 'Smoker' },
],
},
],
};
const form = document.querySelector('clara-form');
form.template = template;
form.addEventListener('clara-submit', (e) => console.log('FHIR QuestionnaireResponse', e.detail.fhir));
// ---- Simulated consultation -------------------------------------------------
// Synthetic data. Each line carries the sentence and, when it applies, the field it fills.
// Clara Widget dispatches exactly these events during a real consultation.
const consultation = [
{ who: 'Patient', text: "I've had a headache for three days and some fever.", fill: { reason: 'Headache and fever for three days' } },
{ who: 'Clinician', text: 'Did you take your temperature? What did it read?' },
{ who: 'Patient', text: 'Last night it read thirty-eight point two.', fill: { temperature: 38.2 } },
{ who: 'Clinician', text: 'Blood pressure is one twenty over eighty. Do you smoke?', fill: { blood_pressure: '120/80' } },
{ who: 'Patient', text: "No, I've never smoked.", fill: { smoker: false } },
{ who: 'Clinician', text: 'The pain started on Monday, it is constant and common painkillers do not help.', fill: { history: 'Headache since Monday, constant, no relief with common analgesics. Night fever.' } },
];
const list = document.querySelector('#transcript');
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const emit = (name, detail) => window.dispatchEvent(new CustomEvent(name, { detail }));
async function replay() {
const analysisId = 'demo-' + Date.now().toString(36);
list.textContent = '';
form.reset();
// 1) The widget starts the consultation: the form hooks onto this analysisId.
emit('clara:session-started', { analysisId });
for (const [i, line] of consultation.entries()) {
const id = 'u' + (i + 1);
const li = document.createElement('li');
const who = document.createElement('b');
who.textContent = line.who;
li.append(who, ' ' + line.text);
list.append(li);
// 2) Each transcribed sentence.
emit('clara:transcript-updated', { analysisId, messages: [{ id, role: line.who === 'Patient' ? 'patient' : 'host', content: line.text }] });
await wait(900);
// 3) The values Clara extracts from that sentence, with their provenance.
for (const [fieldName, value] of Object.entries(line.fill || {})) {
emit('clara:field-filled', { analysisId, fieldName, value, sourceUtteranceId: id, sourceText: line.text });
}
await wait(700);
}
emit('clara:session-stopped', { analysisId });
}
document.querySelector('#replay').addEventListener('click', replay);
Every value on this page is synthetic. Never paste real patient data into a public page.
How it works
Render the form in live mode
<clara-form live> listens to the page channel. Without an analysis id it waits for the widget to start a consultation and then adopts it.
The consultation starts
The widget dispatches clara:session-started with the analysisId. The form hooks onto that id and ignores events that name another consultation.
Each sentence fills a field
clara:field-filled carries fieldName, value, sourceUtteranceId and sourceText. The form converts the value to the field type and shows the phrase it came from.
The person reviews and saves
Fields edited by hand are protected from later voice values. clara-submit returns the values, the labeled JSON and the FHIR QuestionnaireResponse.
During a Clara consultation the widget listens, transcribes and writes each value into the form as soon as the sentence that supports it is spoken. The form shows the source sentence under every value, and a clinician who edits a field by hand keeps the final word: later voice values for that field are ignored.
This page replays a scripted consultation with synthetic data instead of calling the voice service. The form is the real @clara.care/form package; the events are the same ones Clara Widget dispatches on window: clara:session-started, clara:transcript-updated and clara:field-filled.
What is simulated and what is real
Real: the form, its live mode, the provenance line under each value, the manual-edit protection and the export. Simulated: the voice. The script in the JavaScript pane plays the role of the widget and dispatches the events with fixed values after fixed delays.
In production you remove that script and add Clara Widget to the page with your organization's publishable key. The form can even load the widget for you with the widget attribute, so the integration is a single script tag.
Health information stays with you
Transcripts and form values are health information. The form package never logs them and only hands them to your callbacks, your submit URL and the events you listen to. The replay on this page uses invented people and values.
Questions about this example
Is this AI form filling happening live?
No. The consultation is a script with synthetic data that replays through the same events the widget emits. Nothing is recorded and no AI service is called from this page. With Clara Widget and a publishable key the same form fills from a real conversation.
What happens when the clinician disagrees with a value?
They type over it. A field edited by hand is protected: later voice values for that field are not applied and arrive in onLiveUpdate with applied false and reason manual_edit. reset() lifts the protection.
How does the form know which consultation to follow?
With live and no analysisId it listens to the page until clara:session-started arrives, then adopts that id. If you pass analysisId yourself, events that name another consultation are ignored.
Can values arrive when the widget is on another page or device?
Yes, with a publishable key and the consultation id the form reads the consultation stream from the Clara API by server-sent events, reconnecting where it left off. That path is not used on this public page.
Which field types can be filled by voice?
Text, textarea, number, select and checkbox, plus the odontogram. Values are adapted to the type: yes and no become checkboxes, decimal commas become numbers and select options match without accents or capitals.
Planning an integration?
Tell us about your system and your forms. We run small pilots with technology partners.


