Created
August 26, 2020 15:36
-
-
Save slibby/2ca91fbf8e2c523f8031531fad181c0f to your computer and use it in GitHub Desktop.
Example Jupyter Notebook accessing indicators from the DHIS2 Test Site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<dhis2.api.Api at 0x2033053cac8>" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from dhis2 import Api\n", | |
"api = Api('https://covid19.dhis2.org/demo/', 'COVID', 'StopCovid19!')\n", | |
"api" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"r = api.get('schemas')\n", | |
"schemas = r.json()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"attributes : /attributes\n", | |
"userRoles : /userRoles\n", | |
"users : /users\n", | |
"userGroups : /userGroups\n", | |
"externalFileResources : /externalFileResources\n", | |
"expressions : /expressions\n", | |
"sqlViews : /sqlViews\n", | |
"oAuth2Clients : /oAuth2Clients\n", | |
"constants : /constants\n", | |
"options : /options\n", | |
"jobConfigurations : /jobConfigurations\n", | |
"optionSets : /optionSets\n", | |
"optionGroupSets : /optionGroupSets\n", | |
"optionGroups : /optionGroups\n", | |
"colorSets : /colorSets\n", | |
"legendSets : /legendSets\n", | |
"organisationUnits : /organisationUnits\n", | |
"organisationUnitLevels : /organisationUnitLevels\n", | |
"organisationUnitGroups : /organisationUnitGroups\n", | |
"organisationUnitGroupSets : /organisationUnitGroupSets\n", | |
"categoryOptions : /categoryOptions\n", | |
"categoryOptionGroups : /categoryOptionGroups\n", | |
"categoryOptionGroupSets : /categoryOptionGroupSets\n", | |
"categories : /categories\n", | |
"categoryCombos : /categoryCombos\n", | |
"categoryOptionCombos : /categoryOptionCombos\n", | |
"dataElements : /dataElements\n", | |
"dataElementGroups : /dataElementGroups\n", | |
"dataElementGroupSets : /dataElementGroupSets\n", | |
"analyticsTableHooks : /analyticsTableHooks\n", | |
"indicatorTypes : /indicatorTypes\n", | |
"indicators : /indicators\n", | |
"indicatorGroups : /indicatorGroups\n", | |
"indicatorGroupSets : /indicatorGroupSets\n", | |
"dataEntryForms : /dataEntryForms\n", | |
"dataSets : /dataSets\n", | |
"dataSetNotificationTemplates : /dataSetNotificationTemplates\n", | |
"sections : /sections\n", | |
"dataApprovalLevels : /dataApprovalLevels\n", | |
"dataApprovalWorkflows : /dataApprovalWorkflows\n", | |
"validationRules : /validationRules\n", | |
"validationRuleGroups : /validationRuleGroups\n", | |
"validationNotificationTemplates : /validationNotificationTemplates\n", | |
"trackedEntityAttributes : /trackedEntityAttributes\n", | |
"trackedEntityTypes : /trackedEntityTypes\n", | |
"programTrackedEntityAttributeGroups : /programTrackedEntityAttributeGroups\n", | |
"programStageSections : /programStageSections\n", | |
"programNotificationTemplates : /programNotificationTemplates\n", | |
"smsCommands : /smsCommands\n", | |
"programStages : /programStages\n", | |
"programs : /programs\n", | |
"eventReports : /eventReports\n", | |
"eventCharts : /eventCharts\n", | |
"programSections : /programSections\n", | |
"programIndicators : /programIndicators\n", | |
"programIndicatorGroups : /programIndicatorGroups\n", | |
"programRuleVariables : /programRuleVariables\n", | |
"relationshipTypes : /relationshipTypes\n", | |
"programRuleActions : /programRuleActions\n", | |
"programRules : /programRules\n", | |
"mapViews : /mapViews\n", | |
"documents : /documents\n", | |
"validationResults : /validationResults\n", | |
"maps : /maps\n", | |
"charts : /charts\n", | |
"reportTables : /reportTables\n", | |
"reports : /reports\n", | |
"externalMapLayers : /externalMapLayers\n", | |
"predictors : /predictors\n", | |
"predictorGroups : /predictorGroups\n", | |
"dashboardItems : /dashboardItems\n", | |
"dashboards : /dashboards\n", | |
"pushAnalysis : /pushAnalysis\n", | |
"dataStores : /dataStore\n", | |
"fileResources : /fileResources\n", | |
"eventFilters : /eventFilters\n", | |
"trackedEntityAttributeValues : /trackedEntityAttributeValues\n", | |
"minMaxDataElements : /minMaxDataElements\n", | |
"programStageInstances : /programStageInstances\n", | |
"icons : /icons\n", | |
"messageConversations : /messageConversations\n", | |
"metadataVersions : /metadata/version\n", | |
"programDataElements : /programDataElements\n", | |
"interpretations : /interpretations\n", | |
"trackedEntityInstances : /trackedEntityInstances\n", | |
"programInstances : /programInstances\n", | |
"relationships : /relationships\n", | |
"dataElementOperands : /dataElementOperands\n" | |
] | |
} | |
], | |
"source": [ | |
"for i in schemas['schemas']:\n", | |
" try:\n", | |
" print(i['collectionName'], \": \", i['relativeApiEndpoint'])\n", | |
" except:\n", | |
" pass" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'pager': {'page': 1, 'pageCount': 1, 'total': 22, 'pageSize': 50},\n", | |
" 'indicators': [{'id': 'jPRgGRxHfPa',\n", | |
" 'displayName': 'CHECK_COVID-19 Cases (events) - Case fatality rate (%)'},\n", | |
" {'id': 'adeOuUvQAtC', 'displayName': 'CHECK_COVID-2019 Case fatality rate'},\n", | |
" {'id': 'zUcGi0Y384Y', 'displayName': 'COVID-19 - Active cases'},\n", | |
" {'id': 'kJoSHTinHGa', 'displayName': 'COVID-19 - All cases'},\n", | |
" {'id': 'dXAhOKiim1x', 'displayName': 'COVID-19 - Case Fatality rate (%)'},\n", | |
" {'id': 'fK1b7O6CuBV',\n", | |
" 'displayName': 'COVID-19 - Cases treated by mechanical ventilation, ECMO or ICU'},\n", | |
" {'id': 'S3Ty19GEaqn', 'displayName': 'COVID-19 - Closed cases'},\n", | |
" {'id': 'ocBlGrHZy6Q', 'displayName': 'COVID-19 - Confirmed cases'},\n", | |
" {'id': 'zozhRzInMZm',\n", | |
" 'displayName': 'COVID-19 - Confirmed cases by Transmission Classification'},\n", | |
" {'id': 'r2VxAVW1IEy', 'displayName': 'COVID-19 - Deaths'},\n", | |
" {'id': 'BmW2IAaxIBe', 'displayName': 'COVID-19 - Hospitalised Cases'},\n", | |
" {'id': 'DSQpsxxxWSq',\n", | |
" 'displayName': 'COVID-19 POE - Travellers that developed symptoms within the 14 days period of follow-up (%)'},\n", | |
" {'id': 'jHzx1zXeHzV',\n", | |
" 'displayName': 'COVID-19 - Proportion of males among confirmed cases (%)'},\n", | |
" {'id': 'UF7s1t1v6KG',\n", | |
" 'displayName': 'COVID-19 - Proportion of males among deaths(%)'},\n", | |
" {'id': 'gYt2GEAdCJK',\n", | |
" 'displayName': 'COVID-19 - Provinces/regions with Transmission pattern (Cluster cases)'},\n", | |
" {'id': 'JpRDu51rbg5',\n", | |
" 'displayName': 'COVID-19 - Provinces/regions with Transmission pattern (Community cases)'},\n", | |
" {'id': 'vECy4BgZqRF',\n", | |
" 'displayName': 'COVID-19 - Provinces/regions with Transmission pattern (No cases)'},\n", | |
" {'id': 'GszrLGBvHhg',\n", | |
" 'displayName': 'COVID-19 - Provinces/regions with Transmission pattern (Sporadic cases)'},\n", | |
" {'id': 'PkGdfHQyWWH', 'displayName': 'COVID-19 - Recovered cases'},\n", | |
" {'id': 'dsho3rAaUkr', 'displayName': 'COVID-19 - Recovery rate (%)'},\n", | |
" {'id': 'v1xKfNthU2y', 'displayName': 'COVID-2019 Female Case fatality rate'},\n", | |
" {'id': 'n87hWfKcfWL', 'displayName': 'COVID-2019 Male Case fatality rate'}]}" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"r = api.get('indicators')\n", | |
"r.json()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'lastUpdated': '2020-03-27T10:44:08.022',\n", | |
" 'id': 'PkGdfHQyWWH',\n", | |
" 'href': 'https://covid19.dhis2.org/demo/api/indicators/PkGdfHQyWWH',\n", | |
" 'created': '2020-03-18T09:46:52.459',\n", | |
" 'name': 'COVID-19 - Recovered cases',\n", | |
" 'shortName': 'Recovered cases',\n", | |
" 'displayName': 'COVID-19 - Recovered cases',\n", | |
" 'publicAccess': 'r-------',\n", | |
" 'displayShortName': 'Recovered cases',\n", | |
" 'externalAccess': False,\n", | |
" 'denominatorDescription': '1',\n", | |
" 'numeratorDescription': 'Number of cases that are recovered.',\n", | |
" 'dimensionItem': 'PkGdfHQyWWH',\n", | |
" 'numerator': '#{rvYTAOrBrtY}',\n", | |
" 'denominator': '1',\n", | |
" 'annualized': False,\n", | |
" 'favorite': False,\n", | |
" 'dimensionItemType': 'INDICATOR',\n", | |
" 'access': {'read': True,\n", | |
" 'update': False,\n", | |
" 'externalize': False,\n", | |
" 'delete': False,\n", | |
" 'write': False,\n", | |
" 'manage': False},\n", | |
" 'indicatorType': {'id': 'kHy61PbChXr'},\n", | |
" 'lastUpdatedBy': {'id': 'M2foyBloz3g'},\n", | |
" 'user': {'id': 'vUeLeQMSwhN'},\n", | |
" 'favorites': [],\n", | |
" 'translations': [{'property': 'NAME',\n", | |
" 'locale': 'fr',\n", | |
" 'value': 'COVID-19 - Affaires recouvrées'},\n", | |
" {'property': 'NAME', 'locale': 'en', 'value': 'COVID-19 - Recovered cases'},\n", | |
" {'property': 'NAME',\n", | |
" 'locale': 'es',\n", | |
" 'value': 'COVID-19 - Casos recuperados'},\n", | |
" {'property': 'SHORT_NAME', 'locale': 'en', 'value': 'Recovered cases'},\n", | |
" {'property': 'NAME',\n", | |
" 'locale': 'ru',\n", | |
" 'value': 'COVID-19 - Выздоровевшие случаи'},\n", | |
" {'property': 'SHORT_NAME', 'locale': 'es', 'value': 'Casos recuperados'},\n", | |
" {'property': 'SHORT_NAME', 'locale': 'fr', 'value': 'Cas guéris'},\n", | |
" {'property': 'NAME',\n", | |
" 'locale': 'pt',\n", | |
" 'value': 'COVID-19 - Casos Recuperados'}],\n", | |
" 'userGroupAccesses': [{'access': 'rw------',\n", | |
" 'userGroupUid': 'w4iJeNKy9br',\n", | |
" 'displayName': 'COVID19 admin',\n", | |
" 'id': 'w4iJeNKy9br'},\n", | |
" {'access': 'r-------',\n", | |
" 'userGroupUid': 'DoYehxUvmwT',\n", | |
" 'displayName': 'COVID19 access',\n", | |
" 'id': 'DoYehxUvmwT'}],\n", | |
" 'attributeValues': [],\n", | |
" 'indicatorGroups': [{'id': 'YKyPfpFUAVo'}],\n", | |
" 'userAccesses': [],\n", | |
" 'dataSets': [],\n", | |
" 'legendSets': []}" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"r = api.get('indicators/PkGdfHQyWWH')\n", | |
"#r = api.get('dataValueSets')\n", | |
"r.json()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Animal Region\n", | |
"[[[[164.6574,-67.6118],[164.7199,-67.6003],[164.7708,-67.6055],[164.7385,-67.6239],[164.7174,-67.6316],[164.6554,-67.6305],[164.6339,-67.625],[164.6574,-67.6118]]]]\n", | |
"Animal Region\n", | |
"[[[[164.6183,-67.51],[164.7239,-67.5099],[164.7206,-67.6002],[164.6574,-67.6117],[164.6591,-67.601],[164.656,-67.5903],[164.6116,-67.576],[164.6299,-67.5347],[164.6183,-67.51]]]]\n", | |
"Animal Region\n", | |
"[[[[164.5519,-67.5735],[164.5844,-67.5728],[164.6119,-67.5759],[164.656,-67.5904],[164.6591,-67.601],[164.6574,-67.612],[164.6339,-67.625],[164.6184,-67.6211],[164.6074,-67.6159],[164.6203,-67.6071],[164.6093,-67.5972],[164.5929,-67.592],[164.5686,-67.5925],[164.5607,-67.5866],[164.5566,-67.5803],[164.5519,-67.5735]]]]\n", | |
"Animal Region\n", | |
"[[[[164.5686,-67.5925],[164.5925,-67.592],[164.6095,-67.5973],[164.6205,-67.6071],[164.6074,-67.6159],[164.5872,-67.6065],[164.5805,-67.6014],[164.5686,-67.5925]]]]\n", | |
"Animal Region\n", | |
"[[[[164.6183,-67.51],[164.6299,-67.5347],[164.621,-67.5554],[164.6116,-67.576],[164.5846,-67.5726],[164.5519,-67.5735],[164.5378,-67.5524],[164.5328,-67.5205],[164.5148,-67.5097],[164.6183,-67.51]]]]\n", | |
"Animal Region\n", | |
"[[[[164.7706,-67.6056],[164.7213,-67.6005],[164.7213,-67.6003],[164.7239,-67.5099],[164.7903,-67.5091],[164.8237,-67.5516],[164.8258,-67.5705],[164.8106,-67.5826],[164.7706,-67.6056]]]]\n", | |
"Food Region\n", | |
"[[[[164.6982,-67.4731],[164.6376,-67.4493],[164.6394,-67.4412],[164.6342,-67.4358],[164.621,-67.4318],[164.612,-67.4314],[164.5999,-67.3461],[164.6185,-67.3469],[164.6529,-67.3578],[164.6796,-67.376],[164.675,-67.3973],[164.7151,-67.431],[164.6925,-67.4468],[164.6982,-67.4731]]]]\n", | |
"Food Region\n", | |
"[[[[164.621,-67.4318],[164.6342,-67.4359],[164.6393,-67.4412],[164.6375,-67.4493],[164.6266,-67.4542],[164.6124,-67.4566],[164.5942,-67.4542],[164.5834,-67.4509],[164.5771,-67.443],[164.581,-67.4382],[164.5874,-67.4343],[164.603,-67.4314],[164.612,-67.4314],[164.621,-67.4318]]]]\n", | |
"Food Region\n", | |
"[[[[164.5147,-67.5098],[164.4926,-67.496],[164.4881,-67.4878],[164.5011,-67.4582],[164.5013,-67.4515],[164.5834,-67.4509],[164.5942,-67.4542],[164.6183,-67.5099],[164.5147,-67.5098]]]]\n", | |
"Food Region\n", | |
"[[[[164.5999,-67.3461],[164.612,-67.4314],[164.6031,-67.4314],[164.5877,-67.4343],[164.5811,-67.4381],[164.5772,-67.4429],[164.5834,-67.4509],[164.5014,-67.4514],[164.5014,-67.4316],[164.492,-67.4153],[164.5387,-67.3712],[164.5784,-67.3504],[164.5999,-67.3461]]]]\n", | |
"Food Region\n", | |
"[[[[164.7151,-67.431],[164.7561,-67.4654],[164.7903,-67.5091],[164.7239,-67.5099],[164.6981,-67.4731],[164.6925,-67.4468],[164.7151,-67.431]]]]\n", | |
"Food Region\n", | |
"[[[[164.6982,-67.4731],[164.7238,-67.5099],[164.6184,-67.5099],[164.5943,-67.4543],[164.6125,-67.4567],[164.6265,-67.4543],[164.6376,-67.4493],[164.6982,-67.4731]]]]\n" | |
] | |
} | |
], | |
"source": [ | |
"r = api.get('geoFeatures', params={'ou':'ou:USER_ORGUNIT_GRANDCHILDREN', 'displayProperty':'NAME'})\n", | |
"for i in r.json():\n", | |
" print(i['pn'])\n", | |
" print(i['co'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment