Skip to Content
SDK 1.14 is out with per-user product usage and typed API errors. Read the changelog →
ConsultationTemplates

Templates

Define the structure of consultation outputs by creating templates. This lets you map Squire’s output directly to your system’s data format.

Creating templates

Using the API (server side)

Create and store templates via the Template API  on the server.

A custom template can set content_format to plain (the default) or markdown for rich text. See Content format.

Once created, you can use the template in your recording sessions:

await squire.startRecording({ templateId: 'your-template-id' });

Using the SDK (client side)

The template schema can also be passed when calling startRecording. This will create the template if it doesn’t exist yet, or update it if it does.

await squire.startRecording({ templateId: 'your-template-id', templateSchema: schema, });

When passing a templateSchema, you should also provide a templateId. This can be any string (for example, your own internal ID). The templateId will be shown in the Portal, which helps with identification and debugging.

Content format

A template is either plain text or rich text, and the reports generated from it take the same format. Rich text is currently written as Markdown; more rich text formats may be added later. Set it with contentFormat alongside the templateSchema:

await squire.startRecording({ templateId: 'your-template-id', templateSchema: schema, contentFormat: 'markdown', });
ValueMeaning
plainThe template’s text fields, and the report generated from it, are plain text.
markdownRich text: the template’s text fields use Markdown for formatting, and the report’s text fields come back as Markdown.
  • A new template defaults to plain.
  • When you omit contentFormat, an existing template keeps the format it already has, so a template that was switched to rich text elsewhere (for example in the app) is not flipped back.
  • contentFormat only applies to a templateSchema. Passing it without one throws contentFormat requires a templateSchema, since there is no template to set it on.

Every summary reports the format it was generated in as content_format. Read it to decide how to render the text. See Content format.

In a Markdown template, a backslash marks a character as literal text rather than formatting (for example \* or 1\.). The report keeps those backslashes, so render it with a Markdown renderer rather than displaying the raw text.

Template schema

Templates consist of fields. Each field has an id, name, and a valueType defining the data type for the expected value.

Optionally, a description can be provided for each field to improve understanding and accuracy of each field.

Nested fields can be defined using the fields property. This is useful for creating fields where values are related to each other.

Field Properties

PropertyRequiredDescription
idYesUnique identifier (e.g., ‘symptoms_start’)
nameYesDisplay name (e.g., ‘Onset Date’)
valueTypeYesOne of: text, options, date, boolean
valueOptionsFor options typeArray of {value: string, description?: string}
descriptionNoAdditional context or unit information. A hint about the content, not a structure the value must follow
textPatternNoOnly for text fields. A pattern the value must follow. See Text pattern
fieldsNoArray of nested fields

Field Types

TypeUsage
textFree text output
optionsFixed choices, as defined in the valueOptions property
dateDate value, in the YYYY-MM-DD format
booleantrue or false output

Schema Example

const schema = { fields: [ { id: 'symptoms_start', name: 'Onset Date', valueType: 'date', description: 'First occurrence of symptoms' }, { id: 'severity', name: 'Severity', valueType: 'options', valueOptions: [ { value: 'mild', description: 'Mild' }, { value: 'moderate', description: 'Moderate' }, { value: 'severe', description: 'Severe' } ] }, { id: 'has_allergies', name: 'Has allergies?', valueType: 'boolean', description: 'Does the patient have any allergies?', fields: [ { id: 'allergy_details', name: 'Allergy details', valueType: 'text', description: 'If yes, specify the allergens (e.g., pollen, peanuts, medications)' } ] } ] };

Text pattern

A text field can carry a textPattern: a fill-in-the-blanks template the generated value must follow. Where description is only a hint about what belongs in the field, a textPattern fixes the structure of the value itself.

The pattern works with these rules:

  • Plain text stays as written. Headings, labels, punctuation and line breaks are copied into the value unchanged.
  • Square brackets mark fields to fill in. [reason for referral] is replaced with the matching content from the consultation.
  • Round brackets right after a field give styling details for that field: [medication](bulleted list, include dosage).
{ id: 'referral_letter', name: 'Referral letter', valueType: 'text', description: 'Letter to the specialist the patient is referred to', textPattern: `Dear colleague, I am referring [patient name](first name only) for [reason for referral](one sentence). Relevant history: [medical history](short bulleted list) Current medication: [medication](bulleted list, include dosage) Kind regards,`, }

Which generates a value such as:

Dear colleague, I am referring Anna for persistent lower back pain radiating to the left leg. Relevant history: - Hypertension - Lumbar disc herniation in 2019 Current medication: - Amlodipine 5 mg, once daily Kind regards,

textPattern is only allowed on text fields: a template that sets it on an options, date or boolean field is rejected. In a rich text template, the pattern can use Markdown, and the formatting is carried into the report.

Processing Results

The summary object in the summary-ready event contains the values as extracted by Squire. The SDK provides a Template utility class to help you work with these results.

Using the Template utility

The Template class offers convenient methods for working with template results:

squire.on('summary-ready', (summary) => { if (summary.data) { // Create a Template instance from the API response const template = Squire.Template.fromResponse(summary.data); // Get all field values as a Record<id, value> const values = template.getFieldValues(); console.log(values['severity']); // Or get a specific field by id const severityField = template.getFieldById('severity'); console.log(severityField?.value); } });

The Template class provides these main methods:

MethodDescription
fromResponse(response)Creates a Template instance from an API response
getFieldValues()Returns a flat map of all field IDs and their values
getFieldById(id)Searches for a specific field by ID, including nested fields
Last updated on