Skip to main content
Resource Publishing

Document Template Schema

A document template pairs a fillable form with an HTML or PDF document. When a clinician completes the form, the entered values are merged into the document and a completed document is generated.

There are two kinds, and the backend picks the schema from the mimetype on <template>. A template keeps its kind for life.

KindmimetypeHow the values get into the documentSchema
Letter templatetext/htmlMerged into the HTML, so the text reflows around themletter-template.xsd
Document templateapplication/pdfStamped at fixed positions on an uploaded PDF, set in <variables>document-template.xsd

The Transactional API creates letter templates. Document templates are made in Medicus by uploading a PDF.

Example​

<?xml version="1.0" encoding="UTF-8"?>
<documentTemplate>
<documentType conceptId="372471006" description="Referral letter"/>
<form>
<title>Referral Letter</title>
<heading title="Referral details">
<text-input name="patientName" label="Patient name" required="true"/>
<date name="referralDate" label="Referral date" required="true"/>
<textarea name="clinicalNotes" label="Clinical notes"/>
</heading>
</form>
<template mimetype="text/html">
<content>/* HTML template content with {{patientName}}, {{referralDate}}, {{clinicalNotes}} placeholders */</content>
</template>
</documentTemplate>

Schemas​

Letter template (letter-template.xsd)​

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="documentTemplate">
<xs:complexType>
<xs:sequence>
<xs:element ref="documentType" minOccurs="0"/>
<xs:element ref="form"/>
<xs:element ref="template"/>
</xs:sequence>
<xs:attribute name="headerId" type="xs:string"/>
<xs:attribute name="subsequentHeaderId" type="xs:string"/>
<xs:attribute name="footerId" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="documentType">
<xs:complexType>
<xs:attribute name="conceptId" type="xs:integer" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="descriptionId" type="xs:integer"/>
</xs:complexType>
</xs:element>
<!-- FORM INPUTS -->
<xs:attributeGroup name="conditionAttributes">
<xs:attribute name="else" type="xs:string"/>
<xs:attribute name="if" type="xs:string"/>
</xs:attributeGroup>
<xs:attributeGroup name="topLevelFormElementAttributes">
<xs:attributeGroup ref="conditionAttributes"/>
<xs:attribute name="required" type="xs:boolean"/>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9_-]+"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="label"/>
</xs:attributeGroup>
<xs:complexType name="topLevelFormElementType">
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
</xs:complexType>
<xs:element name="form">
<xs:complexType>
<xs:all>
<xs:element ref="title"/>
<xs:element ref="banner" minOccurs="0"/>
<xs:element ref="heading" minOccurs="0"/>
<xs:element ref="section" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:complexType name="layoutElementContainerType">
<xs:sequence>
<!-- Permit any of these tags in any order in any number -->
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="heading"/>
<xs:element ref="section"/>
<xs:element ref="checkbox"/>
<xs:element ref="checkbox-group"/>
<xs:element ref="radio-buttons"/>
<xs:element ref="select"/>
<xs:element ref="text-input"/>
<xs:element ref="textarea"/>
<xs:element ref="quantity"/>
<xs:element ref="date"/>
<xs:element ref="time"/>
<xs:element ref="drawing"/>
<xs:element ref="banner"/>
</xs:choice>
</xs:sequence>
<xs:attributeGroup ref="conditionAttributes"/>
</xs:complexType>
<xs:complexType name="headingElementType">
<xs:complexContent>
<xs:extension base="layoutElementContainerType">
<xs:attribute name="title" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="heading" type="headingElementType"/>
<xs:element name="section" type="layoutElementContainerType"/>
<xs:element name="checkbox">
<xs:complexType>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<xs:attribute name="text" use="required"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="checkbox-group">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="checkbox-option"/>
</xs:sequence>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<xs:attribute name="twoColumns" type="xs:boolean"/>
<!-- Options ticked before anyone touches the form, comma separated. -->
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="checkbox-option">
<xs:complexType>
<xs:attribute name="label" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="radioButtonsType">
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="radio-option"/>
</xs:sequence>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<!-- Lay the options out in a row rather than stacked, for a short choice like Yes/No. -->
<xs:attribute name="horizontal" type="xs:boolean"/>
<!-- The option selected before anyone touches the form. -->
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
<xs:element name="radio-buttons" type="radioButtonsType"/>
<xs:element name="radio-option">
<xs:complexType>
<xs:attribute name="label" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="selectType">
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="select-option"/>
</xs:sequence>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
</xs:complexType>
<xs:element name="select" type="selectType"/>
<xs:element name="select-option">
<xs:complexType>
<xs:attribute name="label" use="required"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="text-input">
<xs:complexType>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="textarea">
<xs:complexType>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="quantityType">
<xs:complexContent>
<xs:extension base="topLevelFormElementType">
<xs:attribute name="unit" use="required" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="quantity" type="quantityType"/>
<xs:complexType name="dateType">
<xs:complexContent>
<xs:extension base="topLevelFormElementType">
<xs:attribute name="default" type="xs:string"/>
<xs:attribute name="max-date" type="xs:string"/>
<xs:attribute name="min-date" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="date" type="dateType"/>
<xs:element name="time" type="topLevelFormElementType"/>
<xs:complexType name="drawingType">
<xs:complexContent>
<xs:extension base="topLevelFormElementType">
<xs:attribute name="backgroundImage" use="required" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="drawing" type="drawingType"/>
<xs:element name="banner">
<xs:complexType>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="text" type="xs:string"/>
</xs:complexType>
</xs:element>
<!-- TEMPLATE -->
<xs:element name="template">
<xs:complexType>
<xs:all>
<xs:element name="content" type="xs:string"/>
</xs:all>
<xs:attribute name="mimetype" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

Document template (document-template.xsd)​

The document template schema adds a required <variables> element, which places each form value at a position on a page of the PDF. It drops the header and footer IDs, the pre-fill value and horizontal attributes, and the drawing field.

<?xml version="1.0" encoding="UTF-8"?>
<documentTemplate>
<documentType conceptId="372471006" description="Referral letter"/>
<variables>
<variable name="patientName" xPosition="72" yPosition="180" width="300" height="20" page="1" fontSize="10"/>
<variable name="referralDate" xPosition="72" yPosition="200" width="150" height="20" page="1" fontSize="10"/>
<variable name="clinicalNotes" xPosition="72" yPosition="240" width="450" height="80" page="1" fontSize="10"/>
</variables>
<form>
<title>Referral Letter</title>
<heading title="Referral details">
<text-input name="patientName" label="Patient name" required="true"/>
<date name="referralDate" label="Referral date" required="true"/>
<textarea name="clinicalNotes" label="Clinical notes"/>
</heading>
</form>
<template mimetype="application/pdf">
<content>/* base64-encoded PDF content */</content>
</template>
</documentTemplate>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="documentTemplate">
<xs:complexType>
<xs:sequence>
<xs:element ref="documentType" minOccurs="0"/>
<xs:element ref="variables"/>
<xs:element ref="form"/>
<xs:element ref="template"/>
</xs:sequence>
</xs:complexType>
<xs:keyref name="variableNameKeyRef" refer="variableNameKey">
<xs:selector xpath="documentTemplate/variables/variable"/>
<xs:field xpath="@name"/>
</xs:keyref>
<xs:key name="variableNameKey">
<xs:selector xpath="form/text-input|form/textarea|form/checkbox|form/checkbox-group|form/radio-buttons|form/select|form/quantity|form/date|form/time"/>
<xs:field xpath="@name"/>
</xs:key>
</xs:element>
<xs:element name="documentType">
<xs:complexType>
<xs:attribute name="conceptId" type="xs:integer" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="descriptionId" type="xs:integer"/>
</xs:complexType>
</xs:element>
<!-- VARIABLES -->
<xs:element name="variables">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element ref="variable" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="variable">
<xs:complexType>
<xs:attribute name="name" use="required"/>
<xs:attribute name="xPosition" type="xs:positiveInteger" use="required"/>
<xs:attribute name="yPosition" type="xs:positiveInteger" use="required"/>
<xs:attribute name="width" type="xs:positiveInteger" use="required"/>
<xs:attribute name="height" type="xs:positiveInteger" use="required"/>
<xs:attribute name="page" type="xs:positiveInteger" default="1"/>
<xs:attribute name="fontSize" type="xs:positiveInteger" default="10"/>
<xs:attribute name="isCheckbox" type="xs:unsignedByte" default="0"/>
</xs:complexType>
</xs:element>
<!-- FORM INPUTS -->
<xs:attributeGroup name="conditionAttributes">
<xs:attribute name="else" type="xs:string"/>
<xs:attribute name="if" type="xs:string"/>
</xs:attributeGroup>
<xs:attributeGroup name="topLevelFormElementAttributes">
<xs:attributeGroup ref="conditionAttributes"/>
<xs:attribute name="required" type="xs:boolean"/>
<xs:attribute name="name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9_-]+"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="label"/>
</xs:attributeGroup>
<xs:complexType name="topLevelFormElementType">
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
</xs:complexType>
<xs:element name="form">
<xs:complexType>
<xs:all>
<xs:element ref="title"/>
<xs:element ref="banner" minOccurs="0"/>
<xs:element ref="heading" minOccurs="0"/>
<xs:element ref="section" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:complexType name="layoutElementContainerType">
<xs:sequence>
<!-- Permit any of these tags in any order in any number -->
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="heading"/>
<xs:element ref="section"/>
<xs:element ref="checkbox"/>
<xs:element ref="checkbox-group"/>
<xs:element ref="radio-buttons"/>
<xs:element ref="select"/>
<xs:element ref="text-input"/>
<xs:element ref="textarea"/>
<xs:element ref="quantity"/>
<xs:element ref="date"/>
<xs:element ref="time"/>
<xs:element ref="banner"/>
</xs:choice>
</xs:sequence>
<xs:attributeGroup ref="conditionAttributes"/>
</xs:complexType>
<xs:complexType name="headingElementType">
<xs:complexContent>
<xs:extension base="layoutElementContainerType">
<xs:attribute name="title" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="heading" type="headingElementType"/>
<xs:element name="section" type="layoutElementContainerType"/>
<xs:element name="checkbox">
<xs:complexType>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<xs:attribute name="text" use="required"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="checkbox-group">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="checkbox-option"/>
</xs:sequence>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
<xs:attribute name="twoColumns" type="xs:boolean"/>
</xs:complexType>
</xs:element>
<xs:element name="checkbox-option">
<xs:complexType>
<xs:attribute name="label" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="radioButtonsType">
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="radio-option"/>
</xs:sequence>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
</xs:complexType>
<xs:element name="radio-buttons" type="radioButtonsType"/>
<xs:element name="radio-option">
<xs:complexType>
<xs:attribute name="label" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="selectType">
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="select-option"/>
</xs:sequence>
<xs:attributeGroup ref="topLevelFormElementAttributes"/>
</xs:complexType>
<xs:element name="select" type="selectType"/>
<xs:element name="select-option">
<xs:complexType>
<xs:attribute name="label" use="required"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="text-input" type="topLevelFormElementType"/>
<xs:element name="textarea" type="topLevelFormElementType"/>
<xs:complexType name="quantityType">
<xs:complexContent>
<xs:extension base="topLevelFormElementType">
<xs:attribute name="unit" use="required" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="quantity" type="quantityType"/>
<xs:complexType name="dateType">
<xs:complexContent>
<xs:extension base="topLevelFormElementType">
<xs:attribute name="default" type="xs:string"/>
<xs:attribute name="max-date" type="xs:string"/>
<xs:attribute name="min-date" type="xs:string"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="date" type="dateType"/>
<xs:element name="time" type="topLevelFormElementType"/>
<xs:element name="banner">
<xs:complexType>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="text" type="xs:string"/>
</xs:complexType>
</xs:element>
<!-- TEMPLATE -->
<xs:element name="template">
<xs:complexType>
<xs:all>
<xs:element name="content" type="xs:string"/>
</xs:all>
<xs:attribute name="mimetype" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

Form fields​

<form> holds a <title> and any number of <heading>/<section> containers. <heading> (titled) and <section> (untitled) can each hold any of the field elements below, including nested headings and sections. All field elements below share name (required), label, and required.

ElementExtra attributesDescription
text-inputnoneSingle-line text input
textareanoneMulti-line text input
datedefault, min-date, max-dateDate picker
timenoneTime picker
quantityunit (required)Numeric input with a unit label
checkboxtext (required), value (required)A single checkbox
checkbox-grouptwoColumns; one or more checkbox-option children (label, value, both required)Multiple checkboxes under one field name
radio-buttonsone or more radio-option children (label, value, both required)Single choice from a set of radio buttons
selectone or more select-option children (label, value, both required)Single choice from a dropdown
bannertype, textInformational text, not a form field, carries no value and isn't merged into the document
drawingbackgroundImage (required)Letter templates only. A canvas over a background image that the user draws on. See Drawing fields

heading additionally requires a title attribute. Letter templates also take a pre-fill value on text-input, textarea, checkbox-group and radio-buttons, and horizontal on radio-buttons.

Drawing fields​

backgroundImage is a PNG or JPEG data URI of 5MB or less, embedded in the template because the PDF renderer can't fetch images by URL. The user draws on it, and the result is merged into the document as a PNG data URI. If nothing is drawn, the background image is used instead.

The value is an image, not text, so place it in the template content as an image source:

<drawing name="bodyMap" label="Body map" backgroundImage="data:image/png;base64,iVBORw0KGgo..."/>
<img class="document-drawing" src="{{ bodyMap }}" />

Key elements​

Element / AttributeRequiredDescription
documentTypeNoThe element itself is optional; if present, conceptId and description are required.
documentType @conceptIdRequired if documentType is presentSNOMED CT concept ID identifying the document type.
documentType @descriptionRequired if documentType is presentHuman-readable label for the document type.
documentType @descriptionIdNoSNOMED CT description ID.
variable @nameYesMust match a form field @name.
variable @xPositionYesHorizontal position on the PDF page (points from left).
variable @yPositionYesVertical position on the PDF page (points from top).
variable @widthYesField width in points.
variable @heightYesField height in points.
variable @pageNoPage number (default 1).
variable @fontSizeNoFont size in points (default 10).
variable @isCheckboxNo1 if the field is a checkbox overlay (default 0).
documentTemplate @headerIdNoLetter templates only. ID of the header template printed on the first page.
documentTemplate @subsequentHeaderIdNoLetter templates only. ID of the header template printed on every page after the first.
documentTemplate @footerIdNoLetter templates only. ID of the footer template printed on every page.
template @mimetypeYesMIME type of the template content (e.g. application/pdf, text/html).
template > contentYesThe template content. For PDF templates, this is the base64-encoded PDF.