Dashboard > DHIS Documentation > ... > System documentation > Database API
  DHIS Documentation Log In | Sign Up   View a printable version of the current page.  
  Database API
Added by Hans S. Tømmerholt, last edited by Hans S. Tømmerholt on Apr 11, 2007  (view change)
Labels: 
(None)

Database API

This document describes the database structure which lies under DHIS 2. Note that the application itself is database independent. It is recommended to interact with the database through the DHIS 2 Java API.

Table of contents

Name and type conventions

  • All table and column names shall be in lower case.
  • When organisationunit is suffixed by something (except for id), the abbreviation shall be orgunit used. Example: orgunitgroupset.
  • Each table shall have an id prefixed with the table name. Example: datasetid.
  • Each foreign key shall have the exact name of the field it refers to. Example: datavalue.dataelementid > dataelement.dataelementid.
  • No other field shall use the table name as a prefix. This is inferred from the table name and the id.
  • Name fields shall have a length of 160 characters.
  • Description fields shall have a length of 360 characters.
  • Each short name and code shall have a length of 25 characters.
  • Each type field shall contain a word rather than an an integer constant. It's length shall be 16. This is because the constant is only known to Java. Example: dataelement.aggregationoperator. In the Java code 1 is "sum" and 2 is "average". In the database, the actual names "sum" and "average" should appear.

Best practices

Do not use SELECT * FROM table;

If you do, you should at least make sure it can handle any future columns being added to the table without breaking your code.
Specify all column names that you need properly:

SELECT table.columnone, table.columntwo FROM table;

All references to column names should be qualified by an alias or the full table name, ESPECIALLY IN JOINS:

SELECT users.surname, users.firstname, usersettings.name FROM users, usersettings;

OR something like this with aliases:

SELECT u.surname, u.firstname, us.name FROM users u, usersettings us;

But NOT:

SELECT surname, firstname, name FROM users, usersettings;

Alphabetic list of tables

Core tables

dataelement

Data elements are the defitiontions of what users can register data for. For each data element a set of data values can be registered. For example "Number of polio vaccinations" or "Total population in district".

Name MySQL type PostgreSQL type Special Description Changes
dataelementid int(11)   NOT NULL auto_increment Id of this data element. dataelementid
name varchar(160)   NOT NULL Name of this dataelement. varchar(160)
shortname varchar(25)   default NULL Short name of this dataelement. shortname varchar(25) NOT NULL
description varchar(360)   default NULL Description of this data element. varchar(360)
active bit(1)   default NULL Wether or not this data element is currently in use. default true
valuetype varchar(16)   NOT NULL The type of data that can be registered for this data element. String, Bool or Int. valuetype varchar(16) NOT NULL
aggregationtype varchar(16)   NOT NULL How values for this data element shall be aggregated. 'sum', 'average' or 'count'. aggregationtype varchar(16) NOT NULL
parentid int(11)   default NULL Id of the parent data element of this data element. parentid/DELETE DISCUSS
alternativeName varchar(255)   default NULL Alternative name of this data element. Used for different languages. alternativename varchar(160)/DELETE
code varchar(25)   default NULL The formal code of this dataelement. varchar(25)

dataelementgroup

A group represents a logical grouping of data elements, for example all data elements related to births .

Name MySQL type PostgreSQL type Special Description Changes
dataelementgroupid int(11)   NOT NULL auto_increment Id of this data element group dataelementgroupid
name varchar(160)   NOT NULL Name of this data element group varchar(160)
NEW description varchar(360)   default NULL Description of this dataelement group NEW

dataelementgroupmembers

Which data elements are connected to which groups.

Name MySQL type PostgreSQL type Special Description Changes
dataelementgroupid int(11)   NOT NULL Id of the data element group the data element is a member of dataelementgroupid
dataelementid int(11)   NOT NULL Id of the data element which is a member of the group  

period

Periods define a time period between a start and end date, for example 1. of January to 31. of January. Each period is connected to a period type, defining what sort of period this is.

Name MySQL type PostgreSQL type Special Description Changes
periodid int(11)   NOT NULL auto_increment Id of this period. periodid
periodtypeid int(11)   NOT NULL Id of the period type of this period. periodtypeid NOT NULL
startdate date   NOT NULL Start date of this period. startdate NOT NULL
enddate date   NOT NULL End date of this period. enddate NOT NULL

periodtype

Period types are for example "monthly", "quarterly", "yearly", etc. The rows in this table mirror specific Java classes, MonthlyPeriodType, YearlyPeriodType, etc. Do not add, delete or change rows in this table unless you also alter the PeriodType definitions and bean mappings in the system.

Name MySQL type PostgreSQL type Special Description Changes
periodtypeid int(11)   NOT NULL auto_increment   periodtypeid
name varchar(30)   NOT NULL    

source

A source represents something that can store a data value. The clearest example is an organisation unit, which is described in later tables. Other subtypes of this table may be "patient", "bus", "facility", "house" or anything else that data might apply to. This table thus represents an abstraction over it's subtypes and doesn't lock DHIS 2 down to strictly using organisation units.

Name MySQL type PostgreSQL type Special Description Changes
sourceid int(11)   NOT NULL auto_increment Id of this source sourceid
NEW name varchar(160)   NOT NULL Name of this source NEW DISCUSS

datavalue

Datavalues are the actual values registered in the system. Each value is registered for a specific data set, a period and a source. An example is: The number of polio vaccinations administered for Clinic A in March 2006 was 10, where 10 is the actual datavalue. Each value is stored with meta information on who registered it, when it was last updated and an optional comment.

Name MySQL type PostgreSQL type Special Description Changes
dataelementid int(11)   NOT NULL Id of the data element of this datavalue dataelementid
periodid int(11)   NOT NULL Id of the period of this datavalue periodid
sourceid int(11)   NOT NULL Id of the source of this datavalue sourceid
value varchar(255)   default NULL The actual value, either a String, Int or Bool, as defined by dataelement.valueType  
storedby varchar(31)   NOT NULL Who stored the lastest value of this data value storedby varchar(31) NOT NULL
lastupdated datetime   NOT NULL When the last value of this datavalue was stored. lastupdated NOT NULL
comment varchar(255)   default NULL Optional comment explaining (deviations in) the value  

Organisation units

organisationunit

An organisation unit is a type of source. Organisation units are ordered in a hierarchy through a parent property. An organisation unit may specify the date when it was opened and when it was closed.

Name MySQL type PostgreSQL type Special Description Changes
organisationunitid int(11)   NOT NULL Id of this organisation unit (source). sourceid/organisationunitid DISCUSS
name varchar(160)   NOT NULL Name of this organisation unit. varchar(160)
parentid int(11)   default NULL Id of the parent organisation unit of this organisation unit. parentid
shortname varchar(25)   NOT NULL Short name of this organisation unit. varchar(25) NOT NULL
code varchar(25)   default NULL Formal code of this organisation unit. code varchar(25)
openingdate datetime   NOT NULL Optional opening date of this organisation unit. openingdate NOT NULL
closeddate datetime   default NULL Optional closing date of this organisation unit. closeddate
active bit(1)   default NULL Wether or not this organisation unit is currently active. default true
comment varchar(360)   default NULL Free text comment on this organisation unit. varchar(360)

orgunitgroup

WAS: organisationunitgroup

Organisation unit groups represent logical groupings of organisation units. Example include all organisation units near a water source, ...

Name MySQL type PostgreSQL type Special Description Changes
orgunitgroupid int(11)   NOT NULL auto_increment Id of this organisation unit group. orgunitgroupid
name varchar(160)   NOT NULL Name of this organisation unit group. varchar(160)
NEW ! description varchar(360)   NOT NULL Description of this organisation unit group. varchar(160)

orgunitgroupmembers

WAS: organisationunitgroupmembers
NEW NAME: orgunitgroupmembers

Which organisation units are members of which organisation unit groups.

Name MySQL type PostgreSQL type Special Description Changes
orgunitgroupid int(11)   NOT NULL   orgunitgroupid
organisationunitid int(11)   NOT NULL    

orgunitgroupset

WAS: organisationunitgroupset

Name MySQL type PostgreSQL type Special Description Changes
orgunitgroupsetid int(11)   NOT NULL auto_increment   orgunitgroupsetid
name varchar(160)   NOT NULL   varchar(160)
description varchar(360)   default NULL   varchar(360)
compulsory bit(1)   default NULL   default false
exclusive bit(1)   default NULL   default false

orgunitgroupsetmembers

WAS: groupsetmembers

Which organisation unit groups are members of which organisation unit group sets.

Name MySQL type PostgreSQL type Special Description Changes
orgunitgroupsetid int(11)   NOT NULL Id of the the groupset the group is a member of. orgunitgroupsetid
orgunitgroupid int(11)   NOT NULL Id of the group which is a member of the group set. orgunitgroupid

Data sets

dataset

Datasets are collections of data elements one captures data for in the same session, usually the same as paper forms. It is presented as one screen in the Data Entry module in the application. Each dataset has a reporting frequency, identified by the reference to a period type. This frequency tells you how often the sources using these datasets are supposed to register and report data upward in the hierarchy,

Name MySQL type PostgreSQL type Special Description Changes
datasetid int(11)   NOT NULL auto_increment Id of this dataset datasetid
name varchar(160)   default NULL Name of this dataset varchar(160) NOT NULL
periodtypeid int(11)   NOT NULL Id of the period type for this dataset periodtypeid
type int(11)   NOT NULL   Deprecated. To be deleted. The period type is the type.
NEW description varchar(360) Description of this dataset default NULL   NEW

datasetmembers

Which data elements are connected to which datasets.

Name MySQL type PostgreSQL type Special Description Changes
datasetid int(11)   NOT NULL Id of the dataset that the data element is a part of  
dataelementid int(11)   NOT NULL Id of the data element which is a part of the dataset  

datasetsource

WAS: dataregisteringassociation

Which sources register data for which datasets. Datasets can be created independently of who are supposed to register data for them. This association allows users to add a connection between a source, for example an organisation unit and a dataset, saying that this source is expected to report data for this dataset.

Name MySQL type PostgreSQL type Special Description Changes
sourceid int(11)   NOT NULL Id of the source that stores data for the dataset sourceid
datasetid int(11)   NOT NULL Id of the dataset the source stores data for datasetid

frequencyoverrideassociation

NEW NAME: ???

Which registering frequencies for which datasets that apply to different sources. The dataset defines a basic registering frequency, for example monthly, meaning how often the source is supposed to register and report data upwards in the hiearchy. This table allows sources to override how often they register data for a given dataset. It is expected that the new registering frequency is always shorter than the original frequency. For example, if Dataset A has a frequency of monthly, Source B can choose to register data for it on a weekly basis. Data would still be reported upward on a monthly basis, but Source B can choose to make use of more detailed data in it's operation.

Name MySQL type PostgreSQL type Special Description Changes
sourceid int(11)   NOT NULL Id of the source using a new registering frequency. sourceid
datasetid int(11)   NOT NULL Id of the dataset the registering frequency applies to. datasetid
periodtypeid int(11)   default NULL If of the period type denoting the new frequency. periodtypeid NOT NULL

Validation

minmaxdataelement

This table stores the minimum and maximum values allowed for data values that are registered for a certain data element in a particular organisation unit. The numbers are often a result of looking at long term trends for the data element and is used to prevent registering erroneously high or low values. Sometimes a value will in fact break the min and max constraints, and in such case the comment field of the data value is typically used to explain the deviation.

Name MySQL type PostgreSQL type Special Description Changes
minmaxdataelementid int(11)   NOT NULL auto_increment Id of this min/max constraint. minmaxdataelementid
dataelementid int(11)   NOT NULL Id of the data element this constraint applies to. dataelementid NOT NULL
minvalue int(11)   default NULL Minimum value of this constraint.  
maxvalue int(11)   default NULL Maximum value of this constraint.  
generated bit(1)   default NULL Wether or not this constraint is automatically generated. If adjusted manually after a time, it will be 0. default false
organisationunitid int(11)   default NULL Id of the organisation unit this constraint applies to. organisationunitid/sourceid DISCUSS NOT NULL

Indicators

indicator

Where data elements represent one type of data, indicators show relationships between different data elements. For example, based on the data elements "Number of people vaccinated for " and "Total population in district", one can create an indicator called " vaccination coverage for district." In this example, the denominator formula would be the id of the population data element while the numerator forumula would be the id of the data element for number of vaccinated people. The aggregation operator for the denominator would be average, averaging different population counts over a period of time, while the operator for the numerator would be sum, summing together the different number of vaccinations over the same period of time. Formulas can be complex, using mathemathical operators between the parts, for example "de1 + de 2".

Name MySQL type PostgreSQL type Special Description Changes
indicatorid int(11)   NOT NULL auto_increment Id of this indicator. indicatorid
name varchar(160)   NOT NULL Name of this indicator. varchar(160)
description varchar(360)   default NULL Description of this indicator. varchar(360)
indicatortypeid int(11)   NOT NULL Id of the indicator type of this indicator. indicatortypeid NOT NULL
numerator varchar(512)   default NULL Numerator formula for this indicator  
numeratordescription varchar(255)   default NULL Textual description of the numerator formula numeratordescription varchar(360)
numeratoraggregationtype varchar(16)   default NULL Aggregation operator to use on the numerator. 'average', 'sum' and 'count'. numeratoraggregationoperator char(16)
denominator varchar(512)   default NULL Denominator formula for this indicator.  
denominatordescription varchar(360) Textual description of the denominator formula default NULL   denominatordescription varchar(360)
denominatoraggregationtype varchar(16) Aggregation operator to use on the denominator. Average or Sum. default NULL   denominatoraggregationoperator varhar(16)
shortname varchar(25) Short name of this indicator. NOT NULL   shortname varchar(25) NOT NULL
code varchar(25) Formal code of this indicator default NULL   varchar(25)
alternativeName varchar(255) Alternative name of this indicator. default NULL   alternativename varchar(160)/DELETE

indicatortype

The indicator type defines how the end result of an indicator calculation (a number between 0 and 1) shall be presented using the factor property. An example is "Percentage", where the factor would be 100. An indicator value of 0.5 would then become 50%.

Name MySQL type PostgreSQL type Special Description Changes
indicatorid int(11)   NOT NULL auto_increment Id of this indicator type indicatortypeid
name varchar(160)   NOT NULL Name of this indicator type varchar(160)
indicatorfactor int(11)   NOT NULL Factor of this indicator type, for example 100 for percent. indicatorfactor NOT NULL

indicatorgroup

Indicator groups represent logical grouping of indicators, for example .

Name MySQL type PostgreSQL type Special Description Changes
indicatorgroupid int(11)   NOT NULL auto_increment If of this indicator group indicatorgroupid
name varchar(160)   NOT NULL Name of this indicator group. varchar(160)
NEW! description varchar(360) Description of this indicator group. NOT NULL   NEW! varchar(160)

indicatorgroupmembers

Which indicators are members of which indicator groups.

Name MySQL type PostgreSQL type Special Description Changes
indicatorgroupid int(11)   NOT NULL Id of the indicator group the indicator is a member of. indicatorgroupid
indicatorid int(11)   NOT NULL Id of the indicator which is a member of the indicator group.  

Aggregation

aggregateddatavalue

This table holds all aggregated data values when they have been exported to the datamart. It's used to speed up the use of aggregated values.

Name MySQL type PostgreSQL type Special Description Changes
dataelementid int(11)   NOT NULL   dataelementid
periodid int(11)   NOT NULL   periodid NOT NULL
periodtypeid int(11)   NOT NULL   periodtypeid NOT NULL
organisationunitid int(11)   NOT NULL   organisationunitid NOT NULL
level int(11)   default NULL   short
value double   default NULL   NOT NULL

aggregatedindicatorvalue

This table holds all aggregated values for indicators when they have been exported to datamart. It's used to speed up the use of aggregated values.

Name MySQL type PostgreSQL type Special Description Changes
indicatorid int(11)   NOT NULL   indicatorid
periodid int(11)   NOT NULL   periodid NOT NULL
periodtypeid int(11)   NOT NULL   periodtypeid NOT NULL
organisationunitid int(11)   NOT NULL   organisationunitid NOT NULL
level int(11)   default NULL   short
value double   default NULL   NOT NULL
numeratorvalue double   NOT NULL   NOT NULL
denominatorvalue double   NOT NULL   NOT NULL
factor double   NOT NULL   NOT NULL

orgunithierarchy

WAS: organisationhierarchy

Organisationunit hierarchies represent snapshots of how the organisation units in the system are organised at any given time. This table should be updated everytime an organisation unit is added, updated , moved or deleted.

Name MySQL type PostgreSQL type Special Description Changes
orgunithierarchyid int(11)   NOT NULL auto_increment Id of this organisation unit hierarchy. orgunithierarchyid
date date   default NULL Timestamp of when this hierarchy was saved. startdate/startingdate/snapshotdate/timestamp, something. DISCUSS

structure

This table holds the actual structure refered to by the orgunithierarchy.

Name MySQL type PostgreSQL type Special Description Changes
orgunithierarchyid int(11)   NOT NULL    
elt int(11)   default NULL    
idx int(11)   NOT NULL    

orgunitstructure

WAS: organisationunitstructure

This table represents a "flattening" of the organisation unit hierarchy. Each graph from a unit to it's parent is stored as a row in this table. It can be used for pivot tables.

(Questions on wether this table could be made dynamic (generated every time) instead of locked to seven levels.)

Name MySQL type PostgreSQL type Special Description Changes
orgunitstructureid int(11)   NOT NULL auto_increment Id of this organisation unit structure. orgunitstructureid
level int(11)   default NULL    
organisationunitid int(11)   default NULL    
idlevel1 int(11)   default NULL    
idlevel2 int(11)   default NULL    
idlevel3 int(11)   default NULL    
idlevel4 int(11)   default NULL    
idlevel5 int(11)   default NULL    
idlevel6 int(11)   default NULL    
idlevel7 int(11)   default NULL    

orgunitgroupsetstructure

WAS: groupsetstructure

This table "flattens" the relationships netweem groups, org units and group sets. Can be used in pivot tables.

Name MySQL type PostgreSQL type Special Description Changes
orgunitgroupsetstructureid int(11)   NOT NULL auto_increment Id of this organisation unit group set structure.  
organisationunitname varchar(255)   default NULL    
orgunitgroupname varchar(255)   default NULL    
orgunitgroupsetname varchar(255)   default NULL    
organisationunitid int(11)   default NULL    
orgunitgroupId int(11)   default NULL    
orgunitgroupsetid int(11)   default NULL    

Users and authorities

userinfo

WAS: users

This table holds general information about users, like their names and addresses. A user may be connected to a specific organisation unit. This connection may used to specify the user's authority priveliges.

Name MySQL type PostgreSQL type Special Description Changes
userinfoid int(11)   NOT NULL auto_increment Id of this user. userid
surname varchar(160)   NOT NULL Surname of this user. varchar(160)/LESS
firstname varchar(160)   NOT NULL First name of this user. varchar(160)/LESS
email varchar(160)   default NULL E-mail address of this user. varchar(160)
organisationunitid int(11)   default NULL Optional id of the organisation unit this user is attached to. organisationunitid

users

WAS: usercredentials

This table holds login information for users.

Name MySQL type PostgreSQL type Special Description Changes
userid int(11)   NOT NULL Id of the user. usercredentialsid
username varchar(255)   NOT NULL Username of this user. varchar(32)
password varchar(255)   NOT NULL Password of this user. varchar(32)

userrole

WAS: userauthoritygroup

Name MySQL type PostgreSQL type Special Description Changes
userroleid int(11)   NOT NULL auto_increment Id of this user authority group. userauthoritygroupid
name varchar(160)   NOT NULL Name of this user authority group. varchar(160)/less DISCUSS

userrolemembers

WAS: userauthoritygroupmembers

Which users are members of which user roles.

Name MySQL type PostgreSQL type Special Description Changes
userroleid int(11)   NOT NULL Id of the user authority group the user is a member of. userauthoritygroupid
userid int(11)   NOT NULL Id of the user login information which is connected to the user authority group. usercredentialsid

userroleauthorities

WAS: userauthoritygroupauthorities

Name MySQL type PostgreSQL type Special Description Changes
userroleid int(11)   NOT NULL   userauthoritygroupid
authority varchar(255)   default NULL    

userroledataset

WAS: userauthoritygroupdataset

Name MySQL type PostgreSQL type Special Description Changes
userauthoritygroup int(11)   NOT NULL   userauthoritygroupid
datasetid int(11)   NOT NULL   datesetid

usersetting

Configuration settings and options for different users.

Name MySQL type PostgreSQL type Special Description Changes
userid int(11)   NOT NULL Id of the user who owns the setting.  
name varchar(160)   NOT NULL Name of the setting the user owns. varchar(160)/LESS
value tinyblob,     Value of the setting.  

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators