Resource Publishing
Document Form Template Schema
A document form template pairs a fillable form with a PDF or HTML document. When a clinician completes the form, the entered values are merged into the document template and a completed document is generated.
Two variants are supported:
- Document template (
documentTemplate.xsd): includes a<variables>section that maps form fields to positions within the PDF template (useful for overlaying text onto a fixed-layout PDF). - Letter template (
letterTemplate.xsd): no<variables>section; the form data is merged into an HTML/plain-text template.
Example
<?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>
Schemas
Document template (documentTemplate.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="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>
Letter template (letterTemplate.xsd)
The letter template schema is identical to the document template schema, except that the <variables> element is absent. Use it when the template is HTML or plain text and the form values are merged inline rather than positioned on a PDF page.
<?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>
Key elements
| Element / Attribute | Required | Description |
|---|---|---|
documentType | No | The element itself is optional; if present, conceptId and description are required. |
documentType @conceptId | Required if documentType is present | SNOMED CT concept ID identifying the document type. |
documentType @description | Required if documentType is present | Human-readable label for the document type. |
documentType @descriptionId | No | SNOMED CT description ID. |
variable @name | Yes | Must match a form field @name. |
variable @xPosition | Yes | Horizontal position on the PDF page (points from left). |
variable @yPosition | Yes | Vertical position on the PDF page (points from top). |
variable @width | Yes | Field width in points. |
variable @height | Yes | Field height in points. |
variable @page | No | Page number (default 1). |
variable @fontSize | No | Font size in points (default 10). |
variable @isCheckbox | No | 1 if the field is a checkbox overlay (default 0). |
template @mimetype | Yes | MIME type of the template content (e.g. application/pdf, text/html). |
template > content | Yes | The template content. For PDF templates, this is the base64-encoded PDF. |