Working with Building Blocks
This guide provides detailed techniques for creating and configuring the core components that make up OpenMRS reports.
Reports are built from fundamental building blocks—cohort queries that define patient groups, indicators that perform calculations, dimensions that categorize results, and parameters that make reports flexible. This guide goes beyond basic creation to show you how to build robust, reusable components including effective cohort query patterns, reliable indicator calculations, strategic use of dimensions for data breakdown, and advanced parameter techniques that make your reports more powerful and user-friendly.
Table of contents
Creating Effective Cohort Queries
Common Cohort Types
Gender-based Cohorts
Use: Gender Query
Parameters: Male = True/False, Female = True/False, Unknown = True/False
Tip: Set one as fixed value, other as parameter for flexibility
Age-based Cohorts
Use: Age Range Cohort Query
Parameters: Min age, Max age
Example: Pediatric patients (0-14 years)
Program Enrollment Cohorts
Use: In Program Query
Parameters: Program, Enrollment date range, Effective date
Tip: Use expressions like
endDate-1mfor relative dates
Observation-based Cohorts
Use: Coded Observation Query
Parameters: Concept, Values, Date range
Example: Patients with TB diagnosis
SQL-based Cohorts
Use: SQL Cohort Query
Format: Must return
patient_idcolumnParameters: Use
:parameterNamesyntaxExample:
SELECT DISTINCT p.patient_id
FROM patient p
JOIN encounter e ON p.patient_id = e.patient_id
WHERE e.encounter_datetime >= :startDate
AND e.encounter_datetime <= :endDate
AND e.location_id = :locationCohort Query Best Practices
✅ Do:
Use descriptive names that explain the criteria
Test with preview function before saving
Document complex logic in description
Use parameters for reusability
Consider performance with large datasets
❌ Avoid:
Overly complex single queries (break into smaller ones)
Hardcoded values when parameters would be better
Missing null/void checks in SQL queries
Duplicate logic across multiple cohorts
Building Robust Indicators
Indicator Types Explained
Count Indicators
Purpose: Simple counting of cohort members
Result: Whole numbers (e.g., 45 patients)
Use for: Total enrollments, active patients, new cases
Fraction Indicators
Purpose: Calculate percentages and ratios
Components: Numerator cohort ÷ Denominator cohort
Result: Decimal (displayed as percentage)
Use for: Completion rates, coverage percentages
Logic Indicators
Purpose: Complex calculations using multiple inputs
Components: Multiple cohorts with mathematical operations
Result: Calculated values
Use for: Rates per population, complex ratios
Creating Fraction Indicators
Example: TB Treatment Success Rate
Numerator Cohort: Patients who completed TB treatment
Denominator Cohort: All patients who started TB treatment
Result: Completion rate as percentage
Configuration Steps:
Create numerator cohort (completed treatment)
Create denominator cohort (started treatment)
Create fraction indicator
Map both cohorts with appropriate parameters
Test with known data
Parameter Mapping in Indicators
Standard Parameters:
startDate- Beginning of reporting periodendDate- End of reporting periodlocation- Geographic/facility filter
Parameter Expressions:
endDate-1m- One month before end datestartDate+2w- Two weeks after start dateendDate-1y- One year before end date
Mapping Examples:
Indicator Parameter → Cohort Parameter
endDate → effectiveDate
startDate → enrollmentStartDate
endDate-6m → treatmentStartDateWorking with Dimensions
A dimension is a way to break down or group an indicator. It does not produce a number on its own; instead, it adds context to an indicator.
Indicator: What number do you want?
Dimension: How do you want to slice that number?
When to Use Dimensions
Use Dimensions When:
You want to break down indicators by categories
The same indicator applies to different groups
You need cross-tabulation (age × gender breakdowns)
Don't Use Dimensions When:
Categories are mutually exclusive and need separate indicators
Logic differs significantly between groups
Performance would be impacted by complex breakdowns
Creating Dimension Categories
Age Group Dimension Example:
Create cohorts for each age group:
Age 0-4cohortAge 5-14cohortAge 15+cohort
Create dimension definition
Add each cohort as dimension option
Apply to relevant indicators
Location Dimension Example:
Create cohorts for each location
Or use location parameter directly
Apply to multi-site reports
Advanced Parameter Techniques
Parameter Types and Uses
Collection Parameters:
List: Multiple values of same type
Set: Unique values only
Use for: Multiple locations, multiple programs
Advanced Configuration:
Coded Options: Predefined choices for string parameters
Option Headers: Custom dropdown labels
Question Concepts: Limit concept choices to specific answers
Expression Examples
Date Calculations:
${now} - Current date/time
${start_of_today} - Midnight today
${end_of_last_month} - Last day of previous month
${start_of_today-30d} - 30 days ago
${end_of_today-1y+6m} - 6 months ago last yearParameter References:
endDate-3m - Three months before end parameter
startDate+1w - One week after start parameter