constants Module#
Constants for DHIS2 integration.
This module provides endpoint definitions, field mappings, and preset data element UIDs for common WHO/AFRO notifiable diseases.
API Endpoints#
- episia.dhis2.constants.ENDPOINTS#
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Standard field mappings#
- episia.dhis2.constants.ANALYTICS_FIELDS#
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Period type mappings#
- episia.dhis2.constants.PERIOD_TYPES#
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
WHO/AFRO data elements#
- episia.dhis2.constants.WHO_AFRO_ELEMENTS#
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Common data element UIDs for the WHO African Region:
malaria_confirmed: Confirmed malaria casesmalaria_deaths: Malaria deathsmeningitis_cases: Meningitis casescholera_cases: Cholera casesmeasles_cases: Measles cases
Usage Examples#
Using endpoints:
from episia.dhis2.constants import ENDPOINTS
# Build API URLs
analytics_url = f"https://your-dhis2.org{ENDPOINTS['analytics']}"
print(analytics_url) # /api/analytics
Using WHO AFRO elements:
from episia.dhis2.constants import WHO_AFRO_ELEMENTS
from episia.dhis2 import DHIS2Client
client = DHIS2Client(url="...", username="...", password="...")
# Fetch malaria data using preset UIDs
ds = client.to_dataset(
data_element=WHO_AFRO_ELEMENTS["malaria_confirmed"],
deaths_element=WHO_AFRO_ELEMENTS["malaria_deaths"],
period="LAST_52_WEEKS",
org_unit="ImspTQPwCqd"
)
Custom period expressions:
from episia.dhis2.constants import PERIOD_TYPES
# Map Episia frequency to DHIS2 period type
freq = "W" # Episia weekly
dhis2_period_type = PERIOD_TYPES.get("weekly", "W")
# Build period expression
period = f"2024W01:2024W52"