Skip to main content
Templates control the shape of the data Squire returns after each consultation. By defining a template, you tell Squire which fields to extract and how to structure the output — so you can map it directly to your EHR’s data model without additional transformation.
Passing templateSchema directly in startRecording is new in SDK v1.6.0. If you are on an earlier version, use the API approach described below.

Two ways to use templates

You can provide a template to Squire either server-side via the API or client-side via the SDK.
1

Choose your approach

Use the API approach if you manage templates centrally on your server and want to reuse them across multiple clients. Use the SDK approach if you need to define or update templates dynamically at the point of recording.
2

Create or pass the template

Create and store the template by posting to the Template API on your server. Once created, pass the returned template ID when starting a recording:
await client.startRecording({ templateId: 'your-template-id' });
3

Receive structured output

Listen for the summary-ready event and process the returned data using the Template utility class. See Processing results below.
Always provide a templateId string when passing templateSchema. This can be any string — for example, your own internal ID. The ID appears in the Squire Portal, which makes templates easier to identify and debug.

Template schema

A template schema is an object with a fields array. Each field defines one piece of data Squire should extract from the consultation.

Field properties

PropertyRequiredDescription
idYesUnique identifier for the field (e.g., "symptoms_start").
nameYesHuman-readable display name (e.g., "Onset Date").
valueTypeYesData type of the expected value. One of: text, options, date, boolean.
valueOptionsFor options typeArray of { value: string, description?: string } objects defining allowed choices.
descriptionNoAdditional context or unit information to improve extraction accuracy.
fieldsNoArray of nested fields. Use this when values are related to each other.

Field types

TypeDescription
textFree text output.
optionsFixed choices, as defined in valueOptions.
dateDate value in 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)'
        }
      ]
    }
  ]
};

Processing results

When the summary-ready event fires, use the Template utility class to extract field values from the response without manually traversing the data structure.
client.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 flat Record<id, value>
    const values = template.getFieldValues();
    console.log(values['severity']);

    // Or get a specific field by ID, including nested fields
    const severityField = template.getFieldById('severity');
    console.log(severityField?.value);
  }
});

Template utility methods

MethodDescription
Squire.Template.fromResponse(response)Creates a Template instance from the API response data.
template.getFieldValues()Returns a flat Record<id, value> map of all field IDs and their extracted values.
template.getFieldById(id)Searches for a specific field by ID, including fields nested inside other fields.