Skip to content

dev-otta/antenatal-visits-plugin

Repository files navigation

ANC Contact Date Calculator

A DHIS2 Tracker plugin for calculating antenatal care (ANC) contact dates based on gestational age and WHO guidelines.

Features

  • 🗓️ Calculates recommended dates for all 8 ANC contacts
  • 🌍 Supports multiple calendar systems (Gregorian, Ethiopian)
  • 📱 Responsive design with DHIS2 UI components
  • 🌐 Full internationalization (i18n) support
  • ♿ Accessibility compliant
  • 🔧 Configurable via DHIS2 dataStore
  • 📊 Automatic schedule calculation from tracker data
  • ✅ Automatic event scheduling in DHIS2 Tracker

Installation

  1. Build the plugin:
yarn install
yarn build
  1. Deploy to DHIS2:
yarn deploy

Or upload the bundle from build/bundle/ directory through the DHIS2 App Management interface.

Configuration

The plugin can be configured via:

  1. Local config file: ancContacts.config.json
  2. DHIS2 dataStore: dataStore/ancContacts/config

Configuration Schema

{
  "metadata": {
    "dataElements": {
      "gestationalAge": "DATA_ELEMENT_ID",
      "ancContactNumber": "DATA_ELEMENT_ID"
    },
    "programStages": {
      "firstContact": "PROGRAM_STAGE_ID",
      "followUpContact": "PROGRAM_STAGE_ID"
    }
  },
  "settings": {
    "autoCalculate": true,
    "dateFormat": "yyyy/MM/dd",
    "numberOfContacts": 8,
    "calendar": "gregory"
  }
}

Configuration Parameters

  • gestationalAge: Data element ID for gestational age in weeks
  • ancContactNumber: Data element ID for ANC contact number
  • firstContact: Program stage ID for the first ANC contact
  • followUpContact: Program stage ID for follow-up ANC contacts
  • dateFormat: Date format string (e.g., "yyyy/MM/dd", "dd/MM/yyyy")
  • calendar: Calendar system ("gregory" or "ethiopic")

Usage

As a Tracker Dashboard Widget

The plugin automatically:

  1. Reads gestational age from the enrollment
  2. Identifies the first contact date
  3. Calculates all 8 recommended contact dates
  4. Allows scheduling of future contacts directly in DHIS2

Standalone App

Can also be used as a standalone calculator without tracker integration.

Development

Prerequisites

  • Node.js 16+
  • Yarn 1.22+
  • DHIS2 instance (for testing)

Setup

yarn install

Development Server

yarn start

Type Checking

yarn ts-check

Linting

yarn lint
yarn lint:fix

Testing

yarn test

Project Structure

src/
├── components/                    # React components
│   ├── LmpInput.tsx              # Gestational age input
│   ├── PluginInputs.tsx          # Plugin input fields
│   ├── ResultsTable.tsx          # Contact schedule table
│   ├── ScheduleButton.tsx        # Schedule contacts button
│   └── ContactScheduleDisplay.tsx # Contact schedule notice box
├── hooks/                         # Custom React hooks
│   ├── useAutoCalculation.ts     # Auto-calculation from enrollment
│   ├── useEnrollmentData.ts      # Enrollment data fetching
│   ├── useEventScheduling.ts     # Event scheduling logic
│   ├── usePluginConfig.ts        # Plugin configuration
│   └── useContactCalculation.ts  # Contact calculation state
├── utils/                         # Utility functions
│   ├── ancCalculation.ts         # Main calculation exports
│   ├── calendarFormatter.ts      # Calendar formatting
│   ├── dateAdjustments.ts        # Weekday adjustments
│   ├── dateUtils.ts              # Date utilities
│   ├── dhis2Utils.ts             # DHIS2 helpers
│   ├── enrollmentDataExtractor.ts # Data extraction
│   ├── eventScheduler.ts         # Event scheduling helpers
│   ├── gestationalAgeCalculator.ts # GA calculations
│   ├── scheduleRuleFinder.ts     # Schedule rule matching
│   └── contactScheduleCalculator.ts # Contact date calculations
├── data/                          # Static data
│   └── scheduleRules.ts          # ANC schedule rules (WHO)
├── types.ts                       # TypeScript type definitions
├── App.tsx                        # Standalone app
└── Plugin.tsx                     # Tracker plugin (169 lines)

Calendar Support

Ethiopian Calendar

The plugin should fully supports the Ethiopian calendar system (ዓ/ም). When configured with calendar: "ethiopic":

  • Dates are formatted according to Ethiopian calendar conventions
  • Calendar detection is automatic based on system/DHIS2 settings
  • Fallback to Gregorian calendar if Ethiopian is not supported

How Calendar Conversion Works

  1. Internal calculations: All calculations use JavaScript Date objects (Gregorian)
  2. Display: Dates are converted to the target calendar for display only
  3. API communication: DHIS2 API always receives Gregorian dates (ISO 8601)

This approach ensures:

  • Accurate calculations regardless of calendar system
  • Proper display in user's preferred calendar
  • Compatibility with DHIS2's date handling

Contact Schedule Rules

The plugin implements WHO ANC guidelines with the following logic:

  • Contact 1: At initial enrollment (any gestational age)
  • Contact 2-8: Scheduled based on current gestational age at previous contact

Schedule intervals vary based on gestational age:

  • Early pregnancy (< 20 weeks): 8-week intervals
  • Mid pregnancy (20-31 weeks): 6-week intervals
  • Late pregnancy (32-38 weeks): 2-week intervals
  • Near term (39+ weeks): Weekly contacts

See src/data/scheduleRules.ts for complete schedule matrix.

Internationalization

The plugin uses DHIS2's standard i18n approach with @dhis2/d2-i18n.

How It Works

All translatable strings are written in English directly in the code:

import i18n from '@dhis2/d2-i18n';

// Simple translation
i18n.t('Contact Number')

// With variables
i18n.t('ANC {{number}}', { number: contactNumber })
i18n.t('Based on GA at first contact: {{weeks}} weeks', { weeks: 12 })

Extracting Translations

Run the extraction command to generate the .pot file:

yarn extract-translations

This scans your code and creates i18n/en.pot with all translatable strings in the standard gettext format:

msgid "Contact Number"
msgstr "Contact Number"

msgid "Recommended Contact Date"
msgstr "Recommended Contact Date"

Generated Files (Auto-Generated)

The DHIS2 build process automatically generates:

  • src/locales/ folder - Auto-generated translation loader (gitignored)
  • i18n/en.pot - Extracted translation strings for translators

Note: The src/locales/ folder is auto-generated by d2-app-scripts during build/start and should not be manually edited or committed to git.

Adding Translations for Other Languages

  1. Use the generated i18n/en.pot file with translation tools (Transifex, POEditor, etc.)
  2. Translators work with the .pot file to create .po files for each language
  3. DHIS2 platform handles loading the appropriate translations at runtime

Code Quality

TypeScript

The project uses strict TypeScript configuration:

  • No implicit any
  • Strict null checks
  • No unused variables/parameters
  • Consistent casing

ESLint

Configured with:

  • React best practices
  • TypeScript-specific rules
  • React Hooks rules
  • Accessibility checks

Code Organization

  • Single Responsibility: Each file has one clear purpose
  • No Comments Policy: Code should be self-documenting
  • Functional Programming: Prefer pure functions
  • Type Safety: Full TypeScript coverage

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

License

BSD-3-Clause

Support

For issues and questions:

Acknowledgments

  • Based on WHO ANC guidelines
  • Built with DHIS2 Platform and UI components
  • Ethiopian calendar support via Intl.DateTimeFormat API

About

A DHIS2 Tracker plugin for calculating antenatal care (ANC) visit dates based on gestational age and WHO guidelines.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages