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.
What is a report
Section titled “What is a report”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.
The parts of a report
Section titled “The parts of a report”A report is made of five parts: metadata, script, template, helpers and partials.
Metadata
Section titled “Metadata”The metadata tell when and where the report is offered:
| Metadata | What it says |
|---|---|
| Name and description | how the report presents itself in the picker |
| Tags | labels to filter the list of reports |
| Launch points | the places in the app the report can be printed from |
| Country and language | for people working in which country and language the report is offered |
| Output type | the format of the document: HTML, CSV or plain text |
Launch points
Section titled “Launch points”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.
| Kind | Examples | The item the report receives |
|---|---|---|
| Record | office, person, equipment, substance, work_environment, incident, supplier, supplier_office, org_safety, hgroup, job, work_place, ppe, ppe_item | that record |
| Action family | action_<type>, action_session_<type>, action_session_date_<type>, action_subscription_<type>, action_session_subscription_<type>, certificate_<type> with <type> = training, health, maintenance, per, check | that record |
| List in a scope | office.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 list | person_list, supplier_list, project_list | none |
Country and language
Section titled “Country and language”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.
Script
Section titled “Script”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.
Template
Section titled “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.
Helpers
Section titled “Helpers”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.
Partials
Section titled “Partials”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.
How a report runs
Section titled “How a report runs”When the user picks a report and the preview opens, 4HSE runs these steps in order:
- Partials: every file declared in
partialsis read and kept as text. onInitruns and returns the data.- Helpers: the code in
helpersis evaluated and itshelpersobject is added to Handlebars. - 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).
Debug entity
Section titled “Debug entity”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.