Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dhis2-tracker-populator

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dhis2-tracker-populator

[![Build Status](https://travis-ci.org/jembi/dhis2-tracker-populator.svg)](https://travis-ci.org/jembi/dhis2-tracker-populator)

  • 4.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

dhis2-tracker-populator

Build Status

Populate DHIS2 Tracker with individual data records read from a number of CSV files.


Install

This is a node.js application. Refer to http://nodejs.org/ for instructions on how install nodejs and NPM for your operating system.

Install the package globally using NPM.

npm install -g dhis2-tracker-populator

CSV file format

The CSV files must follow a naming convention of programID.programStageID.trackedEntityID.csv. The values that make up the filename will be used when making requests to the API. These are the uids of the program, stage and trackedEntity which can be found using api/resource calls, for example:

Program: https://apps.dhis2.org/demo/api/programs/IpHINAT79UW (shows attributes)

Stage: https://apps.dhis2.org/demo/api/programStages/A03MvHHogjR (shows data elements)

The CSV files must contain the following columns:

  • orgUnit : the uid of the organisation unit
  • programDate : yyyy-mm-dd
  • eventDate : yyyy-mm-dd

Any number of additional attributes or data elements can be specified with column headers of the following format:

  • Attributes: The uid of the attribute prepended with the string A|.
  • Data elements: The uid of the data element prepended with the string DE|.
  • Each line in the CSV corresponds to an event.
  • If the tracked entity exists already (there is a unique attribute), other attributes will not be updated
  • If the tracked entity is already enrolled into the program, the application will continue on to adding the event
  • There is no restriction on the number of events added to a program for a particular tracked entity, and multiple identical events can be added (for example if the same csv file is operated on more than once)
  • The application assumes that there is only one unique attribute per tracked entity (this is determined by the application at run time from the DHIS2 resources api)
  • The csv file can be generated from a sql query to a database, from an excel spreadsheet, or any other source, as long as it is added to the csv directory in the proper format (this must actually be comma separated)
  • Event coordinates can be added by specifying latitude and longitude columns in the csv (Note: event coordinates are only inserted and cannot be updated. Ensure that the Capture coordinates flag is set on the program stage).

e.g. file: IpHINAT79UW.A03MvHHogjR.cyl5vuJ5ETQ.csv

orgUnit,programDate,eventDate,A|dv3nChNSIxy,A|hwlRTFIFSUq,DE|UXz7xuGCEhU
sY1WN6LjmAx,2014-08-11,2014-08-11,babyfirstname,babylastname,3000

Run

Run the populator from the command line.

Usage: dhis2-tracker-populator [OPTIONS] URL

Options:
  -c, --csv        Path to the directory containing the csv files
  -d, --done       Path to the directory in which to place the done files
  -f, --fail       Path to the directory in which to place the failed files
  -t, --threshold  The minimum number of days between duplicate events

  --help      Show this help
  --version   Print the version and exit

NB: The folders specified in the options above need to be created manually

The threshold option specifies the number of days between events for the same program, stage and tracked entity instance which will cause them to be considered duplicates. For example, if set to 0 events on the same day will be considered duplicates. The default value of -1 disables duplicate checking.

The default options are:

  • csv: ./csv/
  • done: ./csvdone/
  • fail: ./csvfail/
  • threshold: -1

Example:

dhis2-tracker-populator https://username:password@apps.dhis2.org/demo

This will read data records from the CSV files found in the csv directory and make requests to the API for the given URL to populate the tracker. If an error occurs while processing a CSV file it will be moved into the csvfail directory, otherwise it will be moved to the csvdone directory on completion.

Best practice is to use ./bin/split.js to split a multi-line csv into individual files. This will give granular control and a view of exactly which files have been processed and which did not get fully added to the program.


Notes

To remove ALL tracker data from your DHIS2 database run the following sql commands in order:

delete from trackedentitydatavalue;
delete from programstageinstance;
delete from programinstance;
delete from trackedentityaudit;
delete from trackedentityattributevalue;
delete from trackedentityinstance;

WARNING: This cannot be undone


Populator Testing

How to do a basic populate into DHIS2 using the write function in the Populator (not a CSV import)

Examples below relate to the MomConnect Staging DHIS2 instance

  1. Navigate to the DHIS2 Tracker Populator directory and open a Node shell

    cd /path/to/dhis2-tracker-populator/lib
    node
    
  2. In the Node shell, import the populator module and instantiate a new populator:

    const Populator = require('./populator');
    
    const populator = new Populator({
      url: 'https://user:password@dhis2-instance-path/',
      programID: 'Program UID',
      stageID: 'Program Stage UID',
      trackedEntityID: 'Tracked Entity Attribute UID',
      duplicateThreshold: 'An integer (days)',
      uniqueDataElement: 'Data Element UID'
    });
    

    The URL in the populator requires a / on the end

    Populator OptionDescriptionExample
    urlURL and authentication details to a DHIS2 instancehttps://{user}:{password}@staging.dhis.dhmis.org/momconnect/
    programIDA DHIS2 Program ID eg: MomConnect, NurseConnect or MalariaConnect ProgramsCsKMsVrpRny (MomConnect Program)
    stageIDA DHIS2 Program Stage ID eg: Clinic Subscription, Message Change, HelpDeskAVSoW6NZOCD (Public Subscription)
    trackedEntityIDAn entity tracked by DHIS2 ie: a mother or nurse in MomConnectet3hFnvRGtX (Mother Subscription)
    uniqueAttributeID§A Tracked Entity Attribute that can be used to uniquely identify a tracked entity instance. For example the System ID in the momConnect DHIS2 system is a uuid given to each mother when they sign upHMadXWvPaS4
    duplicateThreshold§If a similar event is found but it falls outside of the duplicateThreshold number of days it won't trigger a Duplicate Event error. This option is ignored if the uniqueDataElement is provided as it is far less reliable.0 ( -1 disables duplicateThreshold check )
    uniqueElementID§A Data Element on an Event used to prevent duplicate processing of messages eg: In the MomConnect system the Event ID is a uuid given to each message from Praekelt to uniquely identify events. If a message needs to be rerun, data won't be duplicated in DHIS2 if it has already successfully been processed.VIXMHChW3mb

    § optional - defaults to backward compatible functionality if not supplied

  3. Then write some data to DHIS

    populator.write({
      parameters: {
        orgUnit: 'HxdpS7eL5hZ',
        programDate: '2019-04-16',
        eventDate: '2019-04-16'
      },
      attributes: {
        AMwD6ZTkNYJ: '+27123456789',
        HMadXWvPaS4: '{random uuid}'
      },
      dataElements: {
        u8qaP9AqGL5: '+27123456789',
        MxxPNA4C2xZ: 'en',
        rXkucI2pquj: 7,
        uIEht9XYOWS: 1,
        VIXMHChW3mb: '{random uuid}'
      }
    });
    
    PopulatorKeyDescriptionExample (String)
    ParameterorgUnitOrganisation Unit (ou) - The facility at which the encounter occurredHxdpS7eL5hZ ( Test Clinic )
    ParameterprogramDateDate of registration in the DHIS2 Tracker Capture ProgramYYYY-MM-DD
    ParametereventDateDate that the DHIS2 Event occurredYYYY-MM-DD
    AttributeAMwD6ZTkNYJMother Subscription Cell Number+27123456789
    AttributeHMadXWvPaS4System ID - a uuid generated by Praekelt to uniquely identify a mother instead of by cellphone number4afe11af-5c2c-4e83-848f-759ccd0b2e26
    Data Elementu8qaP9AqGL5MomConnect Device MSISDN+27123456789
    Data ElementMxxPNA4C2xZMomConnect Language Preferenceen
    Data ElementrXkucI2pqujSoftware Type (SWT) Provider Code4
    Data ElementuIEht9XYOWSMobile Health Application (MHA) Provider Code1
    Data ElementVIXMHChW3mbEvent ID - a uuid generated by Praekelt per message to prevent duplicate events being processedc20832f3-4ee8-4259-90e8-65b82dd3f245

    - MomConnect Staging DHIS2 specific UIDs

Software Type Provider

CodeSWT
1VUMI USSD
2VUMI SMS
3ANDROID REGISTRATION
4VUMI WHATSAPP
5COMMCARE COMMUNITY APP
6COMMCARE FACILITY APP
7VUMI USSD4WHATSAPP

Mobile Health Application Provider

CodeMHA
1Praekelt Foundation
2Dimagi
3VP
4Mobenzi
5Jembi
6WhatsApp

FAQs

Package last updated on 29 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc