A DHIS2 Tracker plugin for calculating antenatal care (ANC) contact dates based on gestational age and WHO guidelines.
- 🗓️ 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
- Build the plugin:
yarn install
yarn build- Deploy to DHIS2:
yarn deployOr upload the bundle from build/bundle/ directory through the DHIS2 App Management interface.
The plugin can be configured via:
- Local config file:
ancContacts.config.json - DHIS2 dataStore:
dataStore/ancContacts/config
{
"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"
}
}- 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")
The plugin automatically:
- Reads gestational age from the enrollment
- Identifies the first contact date
- Calculates all 8 recommended contact dates
- Allows scheduling of future contacts directly in DHIS2
Can also be used as a standalone calculator without tracker integration.
- Node.js 16+
- Yarn 1.22+
- DHIS2 instance (for testing)
yarn installyarn startyarn ts-checkyarn lint
yarn lint:fixyarn testsrc/
├── 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)
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
- Internal calculations: All calculations use JavaScript Date objects (Gregorian)
- Display: Dates are converted to the target calendar for display only
- 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
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.
The plugin uses DHIS2's standard i18n approach with @dhis2/d2-i18n.
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 })Run the extraction command to generate the .pot file:
yarn extract-translationsThis 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"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.
- Use the generated
i18n/en.potfile with translation tools (Transifex, POEditor, etc.) - Translators work with the
.potfile to create.pofiles for each language - DHIS2 platform handles loading the appropriate translations at runtime
The project uses strict TypeScript configuration:
- No implicit
any - Strict null checks
- No unused variables/parameters
- Consistent casing
Configured with:
- React best practices
- TypeScript-specific rules
- React Hooks rules
- Accessibility checks
- 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
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
BSD-3-Clause
For issues and questions:
- DHIS2 Community: https://community.dhis2.org/
- Developer Email: edvin@devotta.com
- Based on WHO ANC guidelines
- Built with DHIS2 Platform and UI components
- Ethiopian calendar support via Intl.DateTimeFormat API