# Create a report template

## Overview

This flow describes how to create a new [report template](https://docs.ohc.network/concepts/platform/report-template.md) for a facility in the **Template Builder**.

[Video: Create a report template](https://www.youtube.com/watch?v=JQcRVjTuSiw)

## Pre-requisites

* You work in the facility that the template is for. Care creates the template for that facility.
* You know which record the report is for: an encounter, a patient, or a billing account. This decides the report type and the context.
* You have the permissions listed below.

## Permissions

| Permission | Access |
| - | - |
| Can Create Template on Facility | Shows **Create Template** if your permissions in the facility include it. To save the new template, you must hold it in the root organization of the facility, Administration. Facility Admin, Doctor and Nurse have it by default. |
| Can Read Template | Shows **Templates** in the facility settings and lists the templates. You can hold it in any organization of the facility. Facility Admin, Administrator, Staff, Doctor, Nurse, Volunteer and Pharmacist have it by default. |
| Can View Template Schema | Loads the contexts and their fields in the **Template Builder**. You can hold it in any organization of any facility. Only Facility Admin has it by default. |
| Can Preview Template | Needed only for step 5. Lets you preview the template. You can hold it in any organization of any facility. Only Facility Admin has it by default. |

By default, only a Facility Admin in Administration has all of these permissions. A Doctor or a Nurse has Can Create Template on Facility by default, but not Can View Template Schema or Can Preview Template.

## Steps

### 1. Open the template builder

In the facility sidebar, select **Settings**.

In the settings sidebar, under **Forms**, select **Templates**. Care shows the **Templates** page.

Select **Create Template**. Care opens the **Template Builder**.

Note: If the facility has no templates, you can also select **Create Your First Template**.

![The Templates page in the facility settings, with the Create Template button outlined](/assets/images/create-a-report-template-1-3d6d964f3fea1c8da8273e2bb1c7c718.webp)

### 2. Fill in the template details

Complete these fields. All of them are required.

| Components | What it captures |
| - | - |
| Template Name | The name of the template. Enter a name. |
| Slug | The short name of the template. Care fills it from the template name. You can change it before you save. |
| Status | Draft, Active, or Retired. A new template starts as Draft. Care generates reports only from an Active template. |
| Default Format | HTML or PDF. A new template starts as HTML. If people print the report, select PDF. Only PDF reports open and print in Care. |
| Report Type | Discharge Summary, Patient Summary, or Account Report. There is no default. |

The slug must have 5 to 50 characters.

Use only letters, numbers, hyphens and underscores in the slug. Start and end the slug with a letter or a number.

The slug must be different from the slugs of the other templates of the facility. If it is not, Care shows "Slug already exists."

Note: You cannot change the slug after you save the template.

![The Template Builder with the Template Name, Slug, Status, Default Format and Report Type fields filled in and outlined](/assets/images/create-a-report-template-2-5ff08ea072beed561b1300ffd82d9509.webp)

### 3. Select the context

The context is the set of data that the template can use.

In the right panel, open **Select Context**. Select the context that matches the report type.

| Report Type | Record that the report is for | Context to select |
| - | - | - |
| Discharge Summary | An encounter | Encounter Report |
| Patient Summary | A patient | Patient Report |
| Account Report | An account | Account Report |

Always select a context, even if the **Fields** card already lists fields.

If the report type and the context do not match, Care shows "Report Type and Context are not compatible" or "Invalid report type or context" when you save.

![The Template Builder with Encounter Report selected in the outlined Select Context box, and the encounter fields in the Fields card](/assets/images/create-a-report-template-3-9ef84c9dea6fd778082ce2f30fd95443.webp)

### 4. Insert data fields into the template body

The **Template HTML** text area holds the content of the report. You write it in the Jinja2 template language.

Note: A new template starts with a sample discharge summary in **Template HTML**. Change it or replace it.

The **Fields** card lists the fields of the context that you selected.

Put the cursor in **Template HTML** at the position for the data.

Select a field in the **Fields** card. Care inserts the field at the cursor.

If a field has nested fields, select it to show or hide them.

If the field is part of a list, Care inserts it inside a loop over the list.

When Care generates a report, each field shows the data of the record at that time.

![The Template HTML box with the encounter class field inserted in the patient details, and the Encounter Class field outlined in the Fields card](/assets/images/create-a-report-template-4-8cbf3a317508f9dbf5ebfc2f22dcb48a.webp)

### 5. Check the result

Care does not check the syntax of the template body when you save it. Errors show only in a preview or when someone generates a report.

Preview the template before you save it. See [Preview a template](https://docs.ohc.network/flows/platform/report-template/preview-a-template.md).

### 6. Save the template

Select **Save Template**.

If a required field is empty, Care shows "This field is required". Complete the field and save again.

If Care cannot save the template, it shows the reason in a message.

![The Template Builder with the Save Template button outlined](/assets/images/create-a-report-template-6-7cbbeff8effbc010950b6891c4294700.webp)

![The Template Builder with the message Report template saved successfully outlined at the top](/assets/images/create-a-report-template-7-8322fdaa64296dbae7c4ffed69445d2a.webp)

## Expected Outcome

* Care shows the message "Report template saved successfully".
* Care opens the new template in the **Template Builder**, so that you can continue to change it.
* The new template shows on the **Templates** page of the facility.
* If the status is Active, Care offers the template when someone generates a report of that report type. If the status is Draft or Retired, Care does not offer it.

## Related

Concepts:

* [Report Template](https://docs.ohc.network/concepts/platform/report-template.md)

Flows:

* [View report templates](https://docs.ohc.network/flows/platform/report-template/view-report-templates.md)
* [Preview a template](https://docs.ohc.network/flows/platform/report-template/preview-a-template.md)
* [Edit a report template](https://docs.ohc.network/flows/platform/report-template/edit-a-report-template.md)
* [Generate and view a report](https://docs.ohc.network/flows/platform/report-template/generate-and-view-a-report.md)
* [Print a report](https://docs.ohc.network/flows/platform/report-template/print-a-report.md)
