Reports
A report definition in SanteDB's BI services framework represents an asset which is ultimately rendered to one or more output formats (like HTML, XLS, etc.).
Data sources for reports can be either a view or a query which can be referenced or inline with the report definition itself.

Report Definition Files

Report definition files define one or more data sources (query or view), metadata (including permission), and one or more views. These views represent different ways of representing data. For example you may have a report with a tabular view and a chart view.
1
<?xml version="1.0" encoding="utf-8" ?>
2
<BiReportDefinition xmlns="http://santedb.org/bi" id="org.santedb.bi.sample.reports.eventType" label="ui.bi.sample.reports.eventType">
3
<meta>
4
<authors>
5
<add>SanteSuite Contributors</add>
6
</authors>
7
<annotation>
8
<div xmlns="http://www.w3.org/1999/xhtml">
9
<p>A simple report</p>
10
</div>
11
</annotation>
12
</meta>
13
<dataSources>
14
<view ref="org.santedb.bi.core.view.audit.date" name="main-date"/>
15
</dataSources>
16
<views>
17
<add id="org.santedb.bi.sample.reports.eventType.main" label="ui.bi.reports.main" name="chart">
18
<div xmlns="http://www.w3.org/1999/xhtml"
19
xmlns:bi="http://santedb.org/bi/view">
20
<!-- Report Content -->
21
22
</div>
23
</add>
24
</views>
25
</BiReportDefinition>
Copied!
The view contents are defined using XHTML and the content is generated using view components defined in the http://santedb.org/bi/view namespace.

Report View Components

There are several built-in view components which you can use for creating your report. They are:
Component
Description
<bi:aggregate>
Aggregate one of the reports data sources
<bi:locale>
Render a localized string into the report
<bi:repeat>
Repeat the contents of for each row contained in the data source
<bi:switch>
Conditional rendering of report components
<bi:value>
Bind the contents to a particular column in the current row.
<bi:chart>
Render a pie, line, bar, radar, donut or combination chart.

Aggregate Component

The aggregate component is used to aggregate a particular data source. This is useful for showing totals, averages, counts, etc.
1
<bi:aggregate source="dataSourceName"
2
fn="aggregationFunction"
3
format="numberFormat">fieldOrExpression</bi:aggregate>
Copied!
The aggregation functions currently supported are:
Function
Description
sum
Adds the particular field or expression together
count
Counts the number of non-null values
count-distinct
Counts the unique instances of a value or expression
min
The minimum value for the value or expression in the dataset
max
The maximum value
avg
Average value
You can either aggregate a field, or an expression, for exam
1
<tfoot>
2
<tr>
3
<th><bi:locale>ui.total</bi:locale></th>
4
<td><bi:aggregate source="main" fn="sum" format="#,###">n_patients</bi:aggregate>
5
</tr>
6
<tr>
7
<th><bi:locale>ui.somecalc</bi:locale></th>
8
<td><bi:aggregate source="main" fn="avg" format="#,###">n_patients / cohort</bi:aggregate>
9
</tfoot>
Copied!

Locale Component

The locale component will replace the value of the element with the correct string from the current locale.
1
<bi:locale>ui.welcome</bi:locale>
Copied!

Repeat Component

The repeat component is an iterator which opens a dataset and repeats until the rows in the data source are exhausted.
1
<bi:repeat source="dataSourceName">
2
<!-- HTML HERE -->
3
</bi:repeat>
Copied!
The contents of the repeat element is any content, for example, this component is used to create tables:
1
<table border="1">
2
<thead>
3
<tr><bi:locale>ui.date</bi:locale></tr>
4
<tr><bi:locale>ui.name</bi:locale></tr>
5
</thead>
6
<tbody>
7
<bi:repeat source="main">
8
<tr>
9
<td><bi:value>date</bi:value></td>
10
<td><bi:value>name</bi:value></td>
11
</tr>
12
</bi:repeat>
13
</tbody>
14
<tfoot>
15
<tr>
16
<th>Total Patients</th>
17
<th><bi:aggregate fn="count" source="main">name</bi:aggregate>
18
</tr>
19
</tfoot>
20
</table>
Copied!

Switch Component

The switch component is used to provide conditional rendering of components.
1
<bi:switch value="valueOrExpression">
2
<bi:when op="eq|lt|lte|gt|gte" value="valueOrExpression" not="true|false">
3
<!-- HTML HERE -->
4
</bi:when>
5
<bi:default>
6
<!-- HTML HERE -->
7
</bi:default>
8
</bi:switch>
Copied!
For example, the switch statement can be used to provide iconography:
1
<bi:switch value="this_month">
2
<bi:when op="lt" value="last_month">
3
<i class="fas fa-arrow-down"></i>
4
</bi:when>
5
<bi:when op="gt" value="last_month">
6
<i class="fas fa-arrow-up"></i>
7
</bi:when>
8
<bi:default>
9
<i class="fas fa-equals"></i>
10
</bi:default>
11
</bi:switch>
Copied!

Value Component

The value component allows the rendering of report data elements or expressions.
1
<bi:value when="[changed]" format="formatString">expressionOrField</bi:value>
Copied!
The when changed indicates that the value should only be emitted when the previous rows' value is not equal to this row's value. For example:
1
<table>
2
<thead>
3
<tr>
4
<th><bi:locale>ui.patient</bi:locale></th>
5
<th><bi:locale>ui.visitDate</bi:locale></th>
6
</tr>
7
</thead>
8
<tbody>
9
<bi:repeat source="patientVisits">
10
<tr>
11
<td><bi:value when="changed">name</bi:value></td>
12
<td><bi:value format="yyyy-MM-dd">visitDate</bi:value>
13
</tr>
14
</bi:repeat>
15
</tbody>
16
<tfoot>
17
<tr>
18
<td><bi:aggregate fn="count-distinct">name</bi:aggregate> <bi:locale>ui.patients.total</bi:locale></td>
19
<td><bi:aggregate fn="count">visitDate</bi:aggregate></td>
20
</tr>
21
</tfoot>
22
</table>
Copied!
This may output a table such as:
ui.patient
ui.visitDate
SMITH, JOHN
2019-03-11
2019-04-11
JONES, JENNIFER
2019-11-01
2 ui.patients.total
3

Chart Component

The charting component allows for quick creation of basic charts using the data found in the data source.
1
<bi:chart type="pie|line|radar|donut|bar" source="dataSourceName">
2
<bi:title>title of chart</bi:title>
3
<bi:labels data="categoryField" format="formatString"/>
4
<!-- Axis Series (allows multiple) -->
5
<bi:axis type="linear|time" data="categoryOrField" label="label" format="formatString"/>
6
<!-- One or more datasets -->
7
<bi:dataset label="datasetLabel" backgroundColor="rgba()"
8
borderColor="rgba()" type="bar|line" fill="true|false"
9
aggregate="count|sum|avg|min|max|first|last">fieldOrExpression</bi:dataset>
10
</bi:chart>
Copied!
For example, to create a simple pie chart:
1
<bi:chart type="pie" source="main">
2
<bi:title>Patients By Gender</bi:title>
3
<bi:labels data="gender"/>
4
<bi:dataset label="# of Patients" fill="true" aggregate="sum">id</bi:dataset>
5
</bi:chart>
Copied!
It is also possible to create composite charts
1
<bi:chart source="main" type="bar">
2
<bi:title>Patient Trends<bi:title>
3
<bi:axis type="time" data="date" format="yyyy-MM" label="Month"/>
4
<bi:dataset label="Males" aggregate="sum" fill="true"
5
backgroundColor="rgba(0,0,255,0.5)">gender == 'M' ? 1 : 0</bi:dataset>
6
<bi:dataset label="Females" aggregate="sum" fill="true"
7
backgroundColor="rgba(0,255,0,0.5)">gender == 'F' ? 1 : 0</bi:dataset>
8
</bi:chart>
Copied!