Skip to content

hisptz/one-health-toolkit-notification

Repository files navigation

One Health toolkit Notification

Introduction

The One Health Toolkit Notification Script facilitates the triggering of notifications using validation rules after executing predictors, as well as counting all notifications dispatched within a surveillance system. Developed with TypeScript and modern web development tools, this script is efficient, reliable, and easy to maintain. It includes features such as automated notification triggering, predictor integration, and thorough notification counting and reporting. This guide offers comprehensive instructions on prerequisites, setup, configuration, and operation, ensuring seamless implementation and deployment for both new installations and existing systems.

Pre-requisites for the Script

To successfully clone and run the script, the following are required:

  • GIT
  • Node v12+
  • npm v6+
  • Typescript v4+

Typescript is mainly used for building source code into bundled JavaScript files.

Getting Started with the Script

To start, clone or download the source code. It's recommended to understand the source code structure before setting up for development or running the script.

Clone the App: Ensure you have the GIT command line installed, then run the following command in the terminal:

git clone https://github.com/hisptz/one-health-toolkit-notification.git

Source Code Structure

After downloading or cloning, the script structure is as follows:

one-health-toolkit-notification
|-- dist
|-- node_modules
|-- resources
|-- src
|   |-- app
|   |-- configs
|   |-- constants
|   |-- models
|   |-- utils
|   |-- index.ts
|-- .gitignore
|-- .prettierrc
|-- build-script.sh
|-- LICENSE
|-- package-lock.json
|-- package.json
|-- README.md
|-- run-notification-script.sh
|-- tsconfig.json

Folder Descriptions

  • dist: Auto-generated folder containing compiled JavaScript bundled files from all TypeScript files in the src directory.
  • node_modules: Auto-generated folder for all installed packages required to run the script. It is generated upon installing all dependencies.
  • resources: Auto-generated by the script, containing generated log files during the process for trigger and counting notifications.
  • src: Main source code directory, with index.ts as the main entry file. It contains the following subdirectories:
    • app: Contains the main processes of the app, including running validation rules, triggering notifications, and counting triggered notifications.
    • configs: Contains configurations for the script, including access to the DHIS2 instance and other constants necessary for triggering notifications.
    • models: Contains models/interfaces for script metadata necessary for the notification script.
    • utils: Contains utility functions or classes necessary for running processes during notification triggers and counting notifications.

Setup & Configurations

Before running the script, configure it by setting up access credentials to the DHIS2 instance and other constants necessary for triggering notifications.

Create a file named app-config.ts in src/configs with the following content:

import { AppConfigModel, Dhis2NotificationMapping } from '../models';

export const appSourceConfig: AppConfigModel = {
  username: 'dhis_username',
  password: 'dhis_password',
  baseUrl: 'dhis_base_url'
};

export const DHIS2_ORGANISATION_UNIT_CONSTANT = {
  validationRuleOuLevel: 1 // level for organizational units, ouId will be fetched by level
};

export const DHIS2_PREDICTOR_CONSTANT = {
  predictorGroups: [] // ids for predictor groups
};

export const DHIS2_VALIDATION_RULE_CONSTANT = {
  validationRuleGroups: [], // ids for validation rule groups for notifications
  defaultNumberOfDays: 2 // number of months including the current month for getting the end date
};

export const DHIS2_MESSAGE_CONVERSATION_CONSTANT = {
  caseIdReference: '', // Case ID Prefix from notification template e.g., caseIdReference: 'Event ID:'
  program: '', // program ID reference
  filterAttribute: '' // attributes to filter
};

export const DHIS2_NOTIFICATION_MAPPING_CONSTANT: Dhis2NotificationMapping[] = [
  {
    dataElement: '', // ID for data element
    notificationSubjectPattern: '', // notification's subject pattern
    diseasePattern: '' // disease pattern
  }
];

Installation

Run the following command to install necessary packages:

npm install

Script Operation

After setting up and installing dependencies, you can run the app for development or deployment.

For Development:

To track changes while developing, run the following command:

npm run dev

For Deployment:

First, build the script into a performant version, then run it. To build the script, run:

sh build-script.sh

This command generates one-health-toolkit-notification.zip in the dist folder, containing the compiled script. Extract the zipped file to use the script.

Run the Script:

To manually run the script on a specific date (e.g., 2024-06-24) to count and trigger notifications for the last seven days, use the command:

sh run-notification-script.sh 2024-06-24

Note: If no specific date is provided, the script uses the current date to deduce the last seven days.

View Script Logs:

To view script logs during or after execution, run the following command inside the extracted zip folder:

tail -f resources/logs/logs.txt