Day4-Analytics App-Hakathon

Analytics App - Aggregate: 

	○ Pivot tables
	○ Data visualizer
	○ GIS

Analytics App - Events:

	○ Event reports
	○ Event visualizer
	○ GIS

Dimensions:

	Fixed 
		○ Data (“dx”)
		○ Period (“pe”)
		○ Organisation unit (“ou”)

	Dynamic 
		○ Data element group sets (“group set uid”) etc…
		●	https://docs.dhis2.org/master/en/developer/html/webapi_analytics.html

Periods:

	● Fixed
		○ 2017 // 2017
		○ 201708 // August 2017
		○ 2017Q2 // April to June 2017 (second quarter)
	● Relative
		○ LAST_12_MONTHS
		○ LAST_4_QUARTERS
		○ THIS_YEAR

Details: https://docs.dhis2.org/master/en/developer/html/webapi_date_perid_format.html
	● Fixed
		○ O6uvpzGd5pu;fdc6uOvgoji;lc3eMKXaEfw; ... // organisation unit ids
	● Relative
		○ USER_ORGUNIT
		○ USER_ORGUNIT_CHILDREN
		○ USER_ORGUNIT_GRANDCHILDREN
		○ LEVEL-3 // all orgunits at level 3
		○ LEVEL-3;O6uvpzGd5pu // all orgunits at level 3 inside an area
		○ OU_GROUP-tDZVQ1WtwpA // all orgunits in a group, e.g. hospitals
		○ OU_GROUP-tDZVQ1WtwpA;O6uvpzGd5pu // all hospitals in an area
Endpoints:
	● Aggregate data: 
	
 /api/analytics 
Details: https://docs.dhis2.org/master/en/developer/html/webapi_analytics.html ● Event data:
		○ api/analytics/events 
		○ api/analytics/events/aggregate
		○ api/analytics/events/query
		
Details: https://docs.dhis2.org/master/en/developer/html/webapi_event_analytics.html
Analytics requests in d2:

	● Easy to assemble
	● Properly URL-encoded
	● Query parameters handling
	● Using fetch (either native or polyfilled)
	● Promise based response

Analytics endpoints:

	● Aggregate data
	● Base endpoint: /api/analytics
	● Additional endpoints:
		○ dataValueSet
		○ rawData
	● Events data
	● Base endpoint: /api/analytics/events/${programId}
	● Additional endpoints:
		○ query
		○ aggregate
		○ cluster
		○ count
	● Explained in detail in dev documentation:

Details: https://docs.dhis2.org/master/en/developer/html/webapi_analytics.html
● Common interface
	○ addDimension / addDimensions
	○ addFilter / addFilters
	○ addParameters
	○ get

● Specific methods
	○ getRawData, getDataValueSet, getDebugSql
	○ setProgram, getAggregate, getCluster, getCount, getQuery

Request example -01:
	d2.analytics.aggregate
	.reset()
	.addDimensions([
	“dx:fbfJHSPpUQD;cYeuwXTCPkU”,
	“pe:2017Q1;2017Q2”
	])
	.addFilter(“ou:O6uvpzGd5pu;lc3eMKXaEfw”)
	.addParameters({
	measureCriteria: “GE:10;LT:100“
	})
	.get()
	.then(data => console.log(‘Response’, data));
Request example -02:
	d2.analytics.events
	.reset()
	.setProgram(‘eBAyeGv0exc’)
	.addDimensions([
	‘dx:Uvn6LCg7dVU;OdiHJayrsKo’,
	‘pe:LAST_4_QUARTERS’,
	‘ou:lc3eMKXaEfw;PMa2VCrupOd’
	])
	.addFilter(‘ou:O6uvpzGd5pu;lc3eMKXaEfw’)
	.addParameters({
	startDate: ‘2017-10-01’,
	endDate: ‘2017-10-31’
	})
	.getAggregate()
	.then(data => console.log(‘Response’, data));
App boilerplate:
	// src/index.js
	import { init } from 'd2/lib/d2';
	init({
	baseUrl: ‘http://localhost:8080/api’,
	schemas: [],
	headers: { authorization: `Basic ${btoa(‘admin:district’)}` }
	})
	.then((d2) => {
	ReactDOM.render(
	,
	document.getElementById('root')
	);
	});

d2 usage:
	// src/api.js
	import { getInstance as getD2 } from 'd2/lib/d2';
	export const fetchData = (periodId) => {
	return getD2()
	.then((d2) => {
	return d2.analytics.aggregate
	.reset()
	.addDimensions([
	‘dx:FbKK4ofIv5R’,
	`pe:${periodId}`,
	])
	.get();
	});
	};
Analytics Plugins:

	● Create a small app that renders pivot tables and charts in a web page by using
	the analytics plugins
	● Resources
		○ CDN: http://www.dhis2-cdn.org
		○ Plugin documentation: Pivot table plugin, Chart plugin





Analytics App - Aggregate: 

	○ Pivot tables
	○ Data visualizer
	○ GIS

Analytics App - Events:

	○ Event reports
	○ Event visualizer
	○ GIS

Dimensions:

	Fixed 
		○ Data (“dx”)
		○ Period (“pe”)
		○ Organisation unit (“ou”)

	Dynamic 
		○ Data element group sets (“group set uid”) etc…
		●	https://docs.dhis2.org/master/en/developer/html/webapi_analytics.html

Periods:

	● Fixed
		○ 2017 // 2017
		○ 201708 // August 2017
		○ 2017Q2 // April to June 2017 (second quarter)
	● Relative
		○ LAST_12_MONTHS
		○ LAST_4_QUARTERS
		○ THIS_YEAR

Details: https://docs.dhis2.org/master/en/developer/html/webapi_date_perid_format.html
	● Fixed
		○ O6uvpzGd5pu;fdc6uOvgoji;lc3eMKXaEfw; ... // organisation unit ids
	● Relative
		○ USER_ORGUNIT
		○ USER_ORGUNIT_CHILDREN
		○ USER_ORGUNIT_GRANDCHILDREN
		○ LEVEL-3 // all orgunits at level 3
		○ LEVEL-3;O6uvpzGd5pu // all orgunits at level 3 inside an area
		○ OU_GROUP-tDZVQ1WtwpA // all orgunits in a group, e.g. hospitals
		○ OU_GROUP-tDZVQ1WtwpA;O6uvpzGd5pu // all hospitals in an area
Endpoints:
	● Aggregate data: 
	
 /api/analytics 
Details: https://docs.dhis2.org/master/en/developer/html/webapi_analytics.html ● Event data:
		○ api/analytics/events 
		○ api/analytics/events/aggregate
		○ api/analytics/events/query
		
Details: https://docs.dhis2.org/master/en/developer/html/webapi_event_analytics.html
Analytics requests in d2:

	● Easy to assemble
	● Properly URL-encoded
	● Query parameters handling
	● Using fetch (either native or polyfilled)
	● Promise based response

Analytics endpoints:

	● Aggregate data
	● Base endpoint: /api/analytics
	● Additional endpoints:
		○ dataValueSet
		○ rawData
	● Events data
	● Base endpoint: /api/analytics/events/${programId}
	● Additional endpoints:
		○ query
		○ aggregate
		○ cluster
		○ count
	● Explained in detail in dev documentation:

Details: https://docs.dhis2.org/master/en/developer/html/webapi_analytics.html
● Common interface
	○ addDimension / addDimensions
	○ addFilter / addFilters
	○ addParameters
	○ get

● Specific methods
	○ getRawData, getDataValueSet, getDebugSql
	○ setProgram, getAggregate, getCluster, getCount, getQuery

Request example -01:
	d2.analytics.aggregate
	.reset()
	.addDimensions([
	“dx:fbfJHSPpUQD;cYeuwXTCPkU”,
	“pe:2017Q1;2017Q2”
	])
	.addFilter(“ou:O6uvpzGd5pu;lc3eMKXaEfw”)
	.addParameters({
	measureCriteria: “GE:10;LT:100“
	})
	.get()
	.then(data => console.log(‘Response’, data));
Request example -02:
	d2.analytics.events
	.reset()
	.setProgram(‘eBAyeGv0exc’)
	.addDimensions([
	‘dx:Uvn6LCg7dVU;OdiHJayrsKo’,
	‘pe:LAST_4_QUARTERS’,
	‘ou:lc3eMKXaEfw;PMa2VCrupOd’
	])
	.addFilter(‘ou:O6uvpzGd5pu;lc3eMKXaEfw’)
	.addParameters({
	startDate: ‘2017-10-01’,
	endDate: ‘2017-10-31’
	})
	.getAggregate()
	.then(data => console.log(‘Response’, data));
App boilerplate:
	// src/index.js
	import { init } from 'd2/lib/d2';
	init({
	baseUrl: ‘http://localhost:8080/api’,
	schemas: [],
	headers: { authorization: `Basic ${btoa(‘admin:district’)}` }
	})
	.then((d2) => {
	ReactDOM.render(
	,
	document.getElementById('root')
	);
	});

d2 usage:
	// src/api.js
	import { getInstance as getD2 } from 'd2/lib/d2';
	export const fetchData = (periodId) => {
	return getD2()
	.then((d2) => {
	return d2.analytics.aggregate
	.reset()
	.addDimensions([
	‘dx:FbKK4ofIv5R’,
	`pe:${periodId}`,
	])
	.get();
	});
	};
Analytics Plugins:

	● Create a small app that renders pivot tables and charts in a web page by using
	the analytics plugins
	● Resources
		○ CDN: http://www.dhis2-cdn.org
		○ Plugin documentation: Pivot table plugin, Chart plugin