Skip to content

Report Concepts

This page explains the concepts 4HSE reports are built on. To write a report see Coding Reports; to use the tool it is written with see Report Editor.

A report turns 4HSE data into a printable document: a data sheet, a register, a certificate, a list. Users run it from the print button of a record or of a list (and from the file manager); the report loads its own data and renders it with an HTML + Handlebars template. The document can be saved as HTML (viewable in a browser, convertible to PDF or Word) or, for some reports, as CSV or plain text. How a user chooses and prints a report is in the user guide: Printing and exporting.

A report is a JSON file with the .ht extension.

A report is made of five parts: metadata, script, template, helpers and partials.

The metadata tell when and where the report is offered:

MetadataWhat it says
Name and descriptionhow the report presents itself in the picker
Tagslabels to filter the list of reports
Launch pointsthe places in the app the report can be printed from
Country and languagefor people working in which country and language the report is offered
Output typethe format of the document: HTML, CSV or plain text

Every place in the app from which a report can be printed is a launch point, identified by a target. The picker shows only the reports whose target contains the current launch point, so a report must list every launch point it supports. A report with no launch points never appears in a picker. How users see them in the list of reports: Search for a report.

KindExamplesThe item the report receives
Recordoffice, person, equipment, substance, work_environment, incident, supplier, supplier_office, org_safety, hgroup, job, work_place, ppe, ppe_itemthat record
Action familyaction_<type>, action_session_<type>, action_session_date_<type>, action_subscription_<type>, action_session_subscription_<type>, certificate_<type> with <type> = training, health, maintenance, per, checkthat record
List in a scopeoffice.equipment_list, office.person_list, office.ppe_list, project.person_list, project.supplier_list…the office or the project, not the rows: the report loads the list itself
Global listperson_list, supplier_list, project_listnone

country and lang are filters the user can change in the picker (by default: the country of the context and the user’s language). They are permissive: a report with an empty country matches every country, one with an empty lang matches every language. The filters in the picker are described in Search for a report.

The script is the JavaScript that loads the data: it defines the onInit function, which reads the data from 4HSE and returns an object. That object is the context of the template.

The template is the document: HTML (or text, according to the output type) with Handlebars expressions between double braces, {{...}}. Its context is the object returned by onInit. Handlebars is deliberately poor in logic: prepare the data in the script and leave the layout to the template.

A helper is a function the template calls to format or compute a value. There are two kinds: the built-in ones of 4HSE (for example dateFormat, t, qr, eachSort), available in every report, and the report-specific ones, written in the helpers field and valid only in that report.

A partial is a piece of template kept in a separate file and reused by one or more reports, so you write it once: a common header with the logo and the company data, a signature block, a table that appears in several documents. Changing the partial changes every report that includes it.

A partial is declared with an alias (the name used in the template) mapped to a file, and included in the template with {{> alias}}. It has no data of its own: it uses the data returned by the script of the report that includes it.

When the user picks a report and the preview opens, 4HSE runs these steps in order:

  1. Partials: every file declared in partials is read and kept as text.
  2. onInit runs and returns the data.
  3. Helpers: the code in helpers is evaluated and its helpers object is added to Handlebars.
  4. Template: it is compiled and rendered with the data. The result is the document.

The steps run in this order every time the report is generated.

The three code fields do not share variables. What script declares stays inside the script, helpers is evaluated in the global scope of the page, and template only sees the data: whatever the template needs has to be returned by onInit.

If a step fails, the run stops and the error tells where it happened (script, helpers or template).

The debug entity is the item a report is tested with in the editor. A report is always generated for a given item (a piece of equipment, an office…), so to see it in the preview you choose one, together with the launch point you imagine it launched from. The report sees them as this.runtime.context and this.runtime.target.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.