Alerts in an EMS
Record each alert in an emergency management system built on Odoo, with the model and fields kept in configuration.
This page follows District notifications in the Outbreak alerts series and replaces Alerts in DHIS2 when the response to an alert is managed in an emergency management system built on Odoo. Each alert becomes one record of the model the EMS keeps its signals in.
The model and its fields
The model and its fields are defined by the module the EMS runs, so their names are kept in ems.ini rather than in the service. fields maps each value of the alert to the field of the model it is written to:
# config/user-conf/ems.ini
[signal]
model = x_signal
[[fields]]
disease = x_disease
district_name = x_district
week = x_week
cases = x_cases
detected = x_detected_on
notified = x_notified_on
alerts.ini names the service below as the one that records alerts:
The record
The service builds the record from the mapping and creates it through the EMS connection:
# -*- coding: utf-8 -*-
# Zato
from zato.server.service import Service
class RecordSignal(Service):
name = 'dhis2.alerts.record-signal'
def handle(self) -> 'None':
alert = self.request.payload
signal = self.config.ems.signal
# Each value of the alert goes to its field in the EMS ..
record = {}
for name, field in signal.fields.items():
record[field] = alert[name]
# .. in a new record of the signal model.
conn = self.outgoing.odoo['EMS'].conn
with conn.client() as client:
model = client.get_model(signal.model)
record_id = model.create(record)
self.logger.info('EMS record %s for %s', record_id, alert['district_name'])
create returns the ID of the new record. A field added to the model later is one more line in fields, and the service does not change.
Next
7-1-7 register keeps the detection and notification dates of the alert in DHIS2.
See also
see-also-table
columns: [Feature, What it does]
rows:
- page: docs/dev/odoo/creating-records/index
text: Creating Odoo records
note: The create method and the record it returns
- page: docs/dev/odoo/index
text: Odoo
note: Connections to Odoo and its models