# 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](https://zato.io/docs/dev/healthcare/dhis2/outbreak-alerts/notify.html) in the [Outbreak alerts](https://zato.io/docs/dev/healthcare/dhis2/outbreak-alerts/index.html) series and replaces [Alerts in DHIS2](https://zato.io/docs/dev/healthcare/dhis2/outbreak-alerts/dhis2-alert.html) 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}

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:

```ini
# 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:

```ini
[record]
service = dhis2.alerts.record-signal
```

## The record {#the-record}

The service builds the record from the mapping and creates it through the `EMS` connection:

```python
# -*- 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 {#next}

[7-1-7 register](https://zato.io/docs/dev/healthcare/dhis2/outbreak-alerts/register.html) keeps the detection and notification dates of the alert in DHIS2.

## See also {#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`

## Learn more {#learn-more}

- [Healthcare interface engine](https://zato.io/docs/dev/healthcare/) - Clinical messages, FHIR, conversion and operations
- [HL7 v2 parsing](https://zato.io/docs/dev/healthcare/hl7/v2/parsing/) - Messages as typed objects, with field access and validation
- [MLLP channels](https://zato.io/docs/dev/healthcare/hl7v2/mllp/) - Receiving and sending HL7 v2 over MLLP sockets
- [FHIR integrations](https://zato.io/docs/dev/healthcare/hl7/fhir/) - Read and write FHIR resources, with paths, bundles and extensions
- [HL7 v2 to FHIR](https://zato.io/docs/dev/healthcare/hl7/to-fhir/) - Converting v2 messages into FHIR bundles, codes and references included
- [EDIFACT](https://zato.io/docs/dev/healthcare/edifact/) - Parsing interchanges, dialects and the transports they arrive on
- [Transformation](https://zato.io/docs/dev/healthcare/transformation/) - One message in, another standard out, in ordinary Python
- [Audit log](https://zato.io/docs/dev/healthcare/audit-log.html) - Every message with its acknowledgment, searchable by patient identifier
- [AI in clinical interfaces](https://zato.io/docs/dev/healthcare/ai/) - Services calling LLMs and AI agents calling clinical services as tools
