Alerts in DHIS2
Record each alert as a tracked entity in the DHIS2 alert program, enrolled and with its signal event.
This page follows District notifications in the Outbreak alerts series. When alerts are managed in DHIS2, each alert becomes a tracked entity in the alert program, registered at the district. Its enrollment holds one event on the signal stage with the disease, the week and the number of cases, and the response teams work on it in the DHIS2 Capture app from there. alerts.ini names dhis2.alerts.record-alert as the service that records alerts.
The signal event
The event carries the values of the alert as data values, each one a string:
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class RecordAlert(Service):
name = 'dhis2.alerts.record-alert'
def build_event(self, alert:'dict') -> 'dict':
program = self.config.alert_programs.alert
cases = str(alert['cases'])
data_values = [
{'dataElement': program.element_disease, 'value': alert['disease']},
{'dataElement': program.element_week, 'value': alert['week']},
{'dataElement': program.element_cases, 'value': cases},
]
event = {
'program': program.id,
'programStage': program.stage_signal,
'orgUnit': alert['district'],
'occurredAt': alert['detected'],
'status': 'COMPLETED',
'dataValues': data_values,
}
return event
The tracked entity
The tracker importer takes the tracked entity, its enrollment and the event in one nested request, so the alert is created in full or not at all:
def handle(self) -> 'None':
alert = self.request.payload
program = self.config.alert_programs.alert
event = self.build_event(alert)
# The enrollment in the alert program holds the event ..
enrollment = {
'program': program.id,
'orgUnit': alert['district'],
'enrolledAt': alert['detected'],
'events': [event],
}
# .. and the tracked entity holds the enrollment.
tracked_entity = {
'trackedEntityType': program.tracked_entity_type,
'orgUnit': alert['district'],
'enrollments': [enrollment],
}
payload = {'trackedEntities': [tracked_entity]}
params = {'async': 'false'}
conn = self.rest['DHIS2 Tracker']
response = conn.post(payload, params)
status = response.data['status']
self.logger.info('Alert for %s: %s', alert['district_name'], status)
DHIS2 rejects the whole request when any of its parts fails validation, which is what its default atomicMode of ALL means, and assigns the UIDs of the tracked entity, the enrollment and the event itself.
Next
7-1-7 register keeps the detection and notification dates of the alert.
See also
| Feature | What it does |
|---|---|
| Setup | The DHIS2 Tracker connection and alert_programs.ini |
| Write a lab result | Events written to an existing enrollment |