# openhie/openhim-mediator-timr-dhis2-tz architecture

> Architecture diagram of the GitHub repository openhie/openhim-mediator-timr-dhis2-tz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openhie/openhim-mediator-timr-dhis2-tz
- Repository: https://github.com/openhie/openhim-mediator-timr-dhis2-tz

## Overview

This is an OpenHIM mediator synchronizing Tanzania Immunization Registry (TImR) data with DHIS2. The visible workflow starts at HTTP sync routes in index.js, which coordinate DHIS2 mapping, TImR warehouse queries, facility lookups, and data submission. Separate clients implement TImR API and OpenInfoMan access; the excerpts do not show how those clients are wired into the routes. Mapping files and age-group translation support the synchronization. The graph follows shown calls and requests; unsampled subsystem connections are omitted or marked unverified.

Main entry points: [`index.js`](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/index.js) (HTTP sync routes), [`dhis2.js`](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/dhis2.js) (DHIS2 client), [`timr.js`](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/timr.js) (TImR API client), [`utils.js`](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/utils.js) (Request orchestration records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Sync orchestration"]
  node_routes["HTTP sync routes<br/>[index.js]"]
end

subgraph group_connectors["External connectors"]
  node_warehouse["Warehouse queries<br/>[middleware.js]"]
  node_timr_client["TImR API client<br/>[timr.js]"]
  node_dhis_client["DHIS2 client<br/>[dhis2.js]"]
  node_fhir_client["FHIR facility lookup<br/>[fhir.js]"]
  node_openinfoman_client["OpenInfoMan lookup<br/>[openinfoman.js]"]
end

subgraph group_mapping["Mapping and translation"]
  node_age_translation["Age translation<br/>[mixin.js]"]
  node_sync_mappings["Sync mappings"]
  node_terminologies["Terminology maps"]
end

subgraph group_operations["Operations"]
  node_orchestration_log["Request orchestration records<br/>[utils.js]"]
  node_email["Email notifications<br/>[send_email.js]"]
  node_process_monitor["Process monitor<br/>[start.js]"]
end

node_caller(("Sync caller"))
node_timr_warehouse[("TImR PostgreSQL")]
node_timr_service["TImR service"]
node_dhis_service["DHIS2 service"]
node_fhir_service["FHIR server"]
node_openinfoman_service["OpenInfoMan service"]
node_mongo[("MongoDB")]
node_smtp["SMTP service"]

node_caller -->|"calls sync"| node_routes
node_routes -->|"queries data"| node_warehouse
node_routes -->|"gets mappings"| node_dhis_client
node_routes -->|"looks up facilities"| node_fhir_client
node_routes -->|"translates ages"| node_age_translation
node_warehouse -->|"queries"| node_timr_warehouse
node_timr_client -->|"requests data"| node_timr_service
node_dhis_client -->|"reads and submits"| node_dhis_service
node_fhir_client -->|"fetches facilities"| node_fhir_service
node_openinfoman_client -->|"requests facility data"| node_openinfoman_service
node_dhis_client -->|"loads operations"| node_sync_mappings
node_dhis_client -->|"uses concept maps"| node_terminologies
node_timr_client -->|"loads operations"| node_sync_mappings
node_timr_client -->|"uses concept maps"| node_terminologies
node_dhis_client -->|"builds records"| node_orchestration_log
node_fhir_client -->|"builds records"| node_orchestration_log
node_openinfoman_client -->|"builds records"| node_orchestration_log
node_timr_client -->|"builds records"| node_orchestration_log
node_orchestration_log -->|"alerts on empty response"| node_email
node_process_monitor -->|"sends restart alerts"| node_email
node_email -->|"reads settings"| node_mongo
node_email -->|"sends mail"| node_smtp
node_routes -.->|"may use client"| node_timr_client
node_routes -.->|"may use lookup"| node_openinfoman_client

click node_routes "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/index.js"
click node_warehouse "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/middleware.js"
click node_timr_client "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/timr.js"
click node_dhis_client "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/dhis2.js"
click node_fhir_client "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/fhir.js"
click node_openinfoman_client "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/openinfoman.js"
click node_age_translation "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/mixin.js"
click node_sync_mappings "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/tree/master/config"
click node_terminologies "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/tree/master/terminologies"
click node_orchestration_log "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/utils.js"
click node_email "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/send_email.js"
click node_process_monitor "https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/start.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_routes toneBlue
class node_warehouse,node_timr_client,node_dhis_client,node_fhir_client,node_openinfoman_client,node_timr_warehouse,node_mongo toneAmber
class node_age_translation,node_sync_mappings,node_terminologies,node_fhir_service toneMint
class node_orchestration_log,node_email,node_process_monitor toneRose
class node_caller,node_timr_service,node_dhis_service,node_openinfoman_service,node_smtp toneIndigo
```

## Components

### Sync orchestration

- [HTTP sync routes](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/index.js): `index.js`

### External connectors

- [Warehouse queries](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/middleware.js): `middleware.js`
- [TImR API client](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/timr.js): `timr.js`
- [DHIS2 client](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/dhis2.js): `dhis2.js`
- [FHIR facility lookup](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/fhir.js): `fhir.js`
- [OpenInfoMan lookup](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/openinfoman.js): `openinfoman.js`

### Mapping and translation

- [Age translation](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/mixin.js): `mixin.js`
- [Sync mappings](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/tree/master/config): `config`
- [Terminology maps](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/tree/master/terminologies): `terminologies`

### Operations

- [Request orchestration records](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/utils.js): `utils.js`
- [Email notifications](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/send_email.js): `send_email.js`
- [Process monitor](https://github.com/openhie/openhim-mediator-timr-dhis2-tz/blob/master/start.js): `start.js`

### Other components

- **Sync caller**
- **TImR PostgreSQL**
- **TImR service**
- **DHIS2 service**
- **FHIR server**
- **OpenInfoMan service**
- **MongoDB**
- **SMTP service**

## Connections

- Sync caller → HTTP sync routes: calls sync
- HTTP sync routes → Warehouse queries: queries data (evidence: `index.js`)
- HTTP sync routes → DHIS2 client: gets mappings (evidence: `index.js`)
- HTTP sync routes → FHIR facility lookup: looks up facilities (evidence: `index.js`)
- HTTP sync routes → Age translation: translates ages (evidence: `index.js`)
- Warehouse queries → TImR PostgreSQL: queries (evidence: `middleware.js`)
- TImR API client → TImR service: requests data (evidence: `timr.js`)
- DHIS2 client → DHIS2 service: reads and submits (evidence: `dhis2.js`)
- FHIR facility lookup → FHIR server: fetches facilities (evidence: `fhir.js`)
- OpenInfoMan lookup → OpenInfoMan service: requests facility data (evidence: `openinfoman.js`)
- DHIS2 client → Sync mappings: loads operations (evidence: `dhis2.js`)
- DHIS2 client → Terminology maps: uses concept maps (evidence: `dhis2.js`)
- TImR API client → Sync mappings: loads operations (evidence: `timr.js`)
- TImR API client → Terminology maps: uses concept maps (evidence: `timr.js`)
- DHIS2 client → Request orchestration records: builds records (evidence: `dhis2.js`)
- FHIR facility lookup → Request orchestration records: builds records (evidence: `fhir.js`)
- OpenInfoMan lookup → Request orchestration records: builds records (evidence: `openinfoman.js`)
- TImR API client → Request orchestration records: builds records (evidence: `timr.js`)
- Request orchestration records → Email notifications: alerts on empty response (evidence: `utils.js`)
- Process monitor → Email notifications: sends restart alerts (evidence: `start.js`)
- Email notifications → MongoDB: reads settings (evidence: `send_email.js`)
- Email notifications → SMTP service: sends mail (evidence: `send_email.js`)
- HTTP sync routes → TImR API client: may use client
- HTTP sync routes → OpenInfoMan lookup: may use lookup
