# 6. Projections¶

Projections are used to select particular attributes from a previously filtered set, and possibly modify the attributes value. Projections define:

• the human readable name of a dataset column and its description
• how a dataset column should be transformed before it can be displayed
• what aggregation expressions are possible

## 6.1. General structure¶

Projections are defined in config/projections.py using a dictionary of the following form:

from pyramid.i18n import TranslationString as _
attributes = {
'projectionid1' : {},
'projectionid2' : {},
}


With projectionid1 and projectionid2 construction detailed below. Note that the projectionids themselves must be unique across all projections. Non-unique names will overwrite previous projection definitions.

## 6.2. Projection definition¶

A projection is constructed from a projection definition. The following attributes may be used in the projection definition:

• name – presentation name as displayed to the end-user. Typically constructed using the i18n _ functioncall to allow for internationalisation.
• expr – SQL expression that performs the projection. For selecting single column names, this will revert to just the columnname.
• align – HTML alignment of a projected column. Can be left, right or center.
• aggs – Python array of aggregates that are available for group and pivot queries using this projection.
• description – presentation description as displayed to the end-user. Typically constructed using the i18n _ functioncall.
• groupexpr – SQL expression that is performed on the projection before the value is presented to the user. This can be used to unnest if the projected value is an array.

Some projection examples:

from pyramid.i18n import TranslationString as _
attributes = {
'preferencedate' : {
'name': _(u"Reference Date"),
'expr': "reference_date",
'align': "center",
'aggs': ['count'],
'description':_("""The reference date is used to show the situation as
it was on a particular date.  On each reference
date, the latest values for each patients are
calculated and shown.  The reference date is usually
the first filter that's selected."""),
'is_array': 'False',
'groupexpr': ''},

'ppatientnumber': {
'name': _(u"Patient ID (HIS)"),
'expr': "patient_id_his",
'align': "right",
'aggs': ['count', 'sum', 'max', 'min', 'var_pop', 'var_samp',
'variance', 'stddev_pop', 'stddev_samp', 'stddev'],
'description':_("""The patient number from the HIS, the system that the
general practitioner uses."""),
'is_array': 'False',
'groupexpr': ''},

'pclusters_diabetes':{
'name':_(u"Organization Clusters, Diabetes"),
'expr': "array_to_string(clusters_diabetes,',')",
'align': "left",
'aggs':['count'],
'description':_("""Cluster the patient belongs to for his/her diabetes
treatment. The clusters can be defined and
maintained in the Portavita KIS indicator
screen"""),
'is_array': 'True',
'groupexpr': "unnest(clusters_diabetes)"},
}