=== modified file 'src/docbkx/en/dhis2_user_man_web_api.xml' --- src/docbkx/en/dhis2_user_man_web_api.xml 2012-05-05 17:28:14 +0000 +++ src/docbkx/en/dhis2_user_man_web_api.xml 2012-06-13 18:30:00 +0000 @@ -94,20 +94,22 @@ Example: Sending data values A common use-case for system integration is the need to send a set of data values from a third-party system into DHIS. In this example we will use the DHIS 2 demo on as basis and we recommend that you follow the provided links with a web browser while reading (log in with admin/district as username/password). We assume that we have collected case-based data using a simple software client running on mobile phones for the Mortality <5 years data set in the community of Ngelehun CHC (in Badjia chiedom, Bo district) for the month of January 2012. We have now aggregated our data into a statistical report and want to send that data to the national DHIS 2 instance. The entry point for the Web API running on the demo instance is . The entry point provides a convenient HTML page with links to all of the available resources in the Web API. The resource which is most appropriate for our purpose of sending data values is the dataValueSets resource. A data value set represents a set of data values which have a logical relationship, usually from being captured off the same data entry form. We follow the link to the HTML representation which will take us to . The default representation is a HTML page which provides us with useful instructions on how to interact with this resources. It tells us that we can use the POST verb to send values using a XML format defined by the http://dhis2.org/schema/dxf/2.0 namespace: - <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="dataSetID" completeDate="ISODate" period="periodISODate" orgUnit="orgUnitID"> - <dataValue dataElement="dataElementID" value="1" /> - <dataValue dataElement="dataElementID" value="2" /> - <dataValue dataElement="dataElementID" value="3" /> + <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="dataSetID" + completeDate="date" period="period" orgUnit="orgUnitID"> + <dataValue dataElement="dataElementID" value="1"/> + <dataValue dataElement="dataElementID" value="2"/> + <dataValue dataElement="dataElementID" value="3"/> </dataValueSet> - Note: We have omitted the categoryOptionCombo attribute as it is optional and not needed for this example. + Note: We have omitted the categoryOptionCombo attribute as it is optional and not needed for this example. Please refer to the date and period section above for time formats. From the example we can see that we need to identify the period, the data set, the org unit (facility) and the data elements for which to report. The dataValueSets resource description tells us that the identifier for monthly periods should be on the format yyyyMM which means that we will use 201201 for January 2012. To obtain the identifier for the data set we return to the the entry point at and follow the embedded link pointing at the dataSets resource located at . From there we find and follow the link to the Mortality < 5 years data set which leads us to . What we did was effectively to retrieve the HTML representation of our data set of interest, and from it we can easily see the identifier, which is pBOMPrpg1QX. The resource representation for the Mortality < 5 years data set conveniently advertises links to the data elements which are members of it. From here we can follow these links and obtain the identifiers of the data elements. For brevity we will only report on three data elements: Measles with id f7n9E0hX8qk, Dysentery with id Ix2HsbDMLea and Cholera with id eY5ehpbEsB7. What remains is to get hold of the identifier of the facility (org unit). Again the dataSet representation conveniently provides link to org units which report on it so we search for Ngelehun CHC and follow the link to the HTML representation at , which tells us that the identifier of this org unit is DiszpKrYNg8. From our case-based data we assume that we have 12 cases of measles, 14 cases of dysentery and 16 cases of cholera. We have now gathered enough information to be able to put together the XML data value set message: - <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" completeDate="2012-02-03" period="201201" orgUnit="DiszpKrYNg8"> - <dataValue dataElement="f7n9E0hX8qk" value="12" /> - <dataValue dataElement="Ix2HsbDMLea" value="14" /> - <dataValue dataElement="eY5ehpbEsB7" value="16" /> + <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" + completeDate="2012-02-03" period="201201" orgUnit="DiszpKrYNg8"> + <dataValue dataElement="f7n9E0hX8qk" value="12"/> + <dataValue dataElement="Ix2HsbDMLea" value="14"/> + <dataValue dataElement="eY5ehpbEsB7" value="16"/> </dataValueSet> To perform functional testing we will use the cURL tool () which provides an easy way of transferring data using HTTP. First we save the data value set XML content in a file called datavalueset.xml . From the directory where this file resides we invoke the following from the command line: curl -d @datavalueset.xml "http://apps.dhis2.org/demo/api/dataValueSets" -H "Content-Type:application/xml" -u admin:district -v @@ -121,10 +123,10 @@ The previous example showed us how to send a set of related data values sharing the same period and organisation unit. This example will show us how to send large bulks of data values which don't necessarily are logically related. Again we will interact with the with resource. This time we will not specify the dataSet and completeDate attributes. Also, we will specify the period and orgUnit attributes on the individual data value elements instead of on the outer data value set element. This will enable us to send data values for various periods and org units: <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0"> - <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" value="12" /> - <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="FNnj3jKGS7i" value="14" /> - <dataValue dataElement="f7n9E0hX8qk" period="201202" orgUnit="DiszpKrYNg8" value="16" /> - <dataValue dataElement="f7n9E0hX8qk" period="201202" orgUnit="Jkhdsf8sdf4" value="18" /> + <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" value="12"/> + <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="FNnj3jKGS7i" value="14"/> + <dataValue dataElement="f7n9E0hX8qk" period="201202" orgUnit="DiszpKrYNg8" value="16"/> + <dataValue dataElement="f7n9E0hX8qk" period="201202" orgUnit="Jkhdsf8sdf4" value="18"/> </dataValueSet> We test by using cURL to send the data values: curl -d @datavalueset.xml "http://apps.dhis2.org/demo/api/dataValueSets" -H "Content-Type:application/xml" -u admin:district -v @@ -174,9 +176,11 @@ All parameters are optional and can be supplied as query parameters in the request URL like this: - http://apps.dhis2.org/demo/api/dataValueSets?dataElementIdScheme=code&orgUnitIdScheme=name&dryRun=true&importStrategy=new + http://apps.dhis2.org/demo/api/dataValueSets?dataElementIdScheme=code& + orgUnitIdScheme=name&dryRun=true&importStrategy=new They can also be supplied as XML attributes on the data value set element like below. XML attributes will override query string parameters. - <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataElementIdScheme="code" orgUnitIdScheme="name" dryRun="true" importStrategy="new"> + <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataElementIdScheme="code" + orgUnitIdScheme="name" dryRun="true" importStrategy="new"> .. </dataValueSet> Regarding the id schemes, by default the identifiers used in the XML messages refer to the DHIS stable object identifiers. In certain interoperability situations we might experience that the external system decides the identifiers of the objects. In that case we can use the code property of the organisation unit and data element objects to set fixed identifiers dictated by the other system. When importing data values we hence need to reference the code property instead of the uid property, and can do so using the dataElementIScheme and orgUnitIdScheme paramaters. @@ -212,15 +216,20 @@ It is assumed that we have posted data values to DHIS according to the previous section called "Sending data values". We can now put together our request and send it using cURL: - curl "http://apps.dhis2.org/demo/api/dataValueSets?dataSet=pBOMPrpg1QX&period=201201&orgUnit=DiszpKrYNg8" -H "Accept:application/xml" -u admin:district -v + curl "http://apps.dhis2.org/demo/api/dataValueSets?dataSet=pBOMPrpg1QX&period=201201&orgUnit=DiszpKrYNg8" -H "Accept:application/xml" -u admin:district -v The response will look something like this: HTTP/1.1 200 OK Content-Type: application/xml -<?xml version='1.0' encoding='UTF-8'?><dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" completeDate="2012-01-02" period="201201" orgUnit="DiszpKrYNg8"> -<dataValue dataElement="eY5ehpbEsB7" period="201201" orgUnit="DiszpKrYNg8" categoryOptionCombo="bRowv6yZOF2" value="10003"/> -<dataValue dataElement="Ix2HsbDMLea" period="201201" orgUnit="DiszpKrYNg8" categoryOptionCombo="bRowv6yZOF2" value="10002"/> -<dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" categoryOptionCombo="bRowv6yZOF2" value="10001"/> +<?xml version='1.0' encoding='UTF-8'?> +<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" + completeDate="2012-01-02" period="201201" orgUnit="DiszpKrYNg8"> +<dataValue dataElement="eY5ehpbEsB7" period="201201" orgUnit="DiszpKrYNg8" + categoryOptionCombo="bRowv6yZOF2" value="10003"/> +<dataValue dataElement="Ix2HsbDMLea" period="201201" orgUnit="DiszpKrYNg8" + categoryOptionCombo="bRowv6yZOF2" value="10002"/> +<dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" + categoryOptionCombo="bRowv6yZOF2" value="10001"/> </dataValueSet> The header tells us that the request was processed successfully and that we are receiving a response in XML format. The XML message looks familiar - it is the data values we sent in the previous section. @@ -251,9 +260,12 @@ We will now pretend to be the mobile user and read the message which was just sent by dispatching a GET request to the messageConversations resource. We supply an Accept header with application/xml as the value to indicate that we are interested in the XML resource representation and we authenticate as the mobile user: curl "http://apps.dhis2.org/demo/api/messageConversations" -H "Accept:application/xml" -u mobile:district -X GET -v In response we get the following XML: - <messageConversations xmlns="http://dhis2.org/schema/dxf/2.0" link="http://apps.dhis2.org/demo/api/messageConversations"> - <messageConversation name="Mortality data reporting" id="ZjHHSjyyeJ2" link="http://apps.dhis2.org/demo/api/messageConversations/ZjHHSjyyeJ2"/> - <messageConversation name="DHIS version 2.7 is deployed" id="GDBqVfkmnp2" link="http://apps.dhis2.org/demo/api/messageConversations/GDBqVfkmnp2"/> + <messageConversations xmlns="http://dhis2.org/schema/dxf/2.0" + link="http://apps.dhis2.org/demo/api/messageConversations"> + <messageConversation name="Mortality data reporting" id="ZjHHSjyyeJ2" + link="http://apps.dhis2.org/demo/api/messageConversations/ZjHHSjyyeJ2"/> + <messageConversation name="DHIS version 2.7 is deployed" id="GDBqVfkmnp2" + link="http://apps.dhis2.org/demo/api/messageConversations/GDBqVfkmnp2"/> </messageConversations> From the response we are able to read the identifier of the newly sent message which is ZjHHSjyyeJ2. Note that the link to the specific resource is embedded and available for consumers to use. From the description at we learned that we can reply directly to an existing message conversation once we know the URL by including the message text as the request payload (body). We are now able to construct a URL for sending our reply: curl -d "Yes the Mortality data set has been reported" "http://apps.dhis2.org/demo/api/messageConversations/ZjHHSjyyeJ2" -H "Content-Type:text/plain" -u mobile:district -X POST -v @@ -266,7 +278,8 @@ We start as usual at the Web API entrypoint at . We look for a relevant report table by following the reportTables link to . We assume that we are interested in the "District Maternal Health" report and follow the link to . This resource provides meta-data information about the report table. From here we can follow the link to the default data view of aggregated data, which leads us to . As we can see we are provided with a report table in HTML format, which is the default representation format for report tables. As stated in the introduction there are three ways of indicating which resource representation format you prefer for the response. The most suitable alternative for direct use in web pages is to append a file suffix to the URL. We assume that we are interested in the PDF representation and indicate that by appending .pdf to our URL: . Go ahead and try out all valid extensions for this resource which are .html, .pdf, .xls and .csv. The report table can be parameterized with an organisation unit and a period by supplying a ou and pe query parameter accompanied with an organisation unit identifier and period string in the URL. If not provided the Web API will use the top-most organisation unit in the hierarchy and the last period for the report table content. The organisation unit identifier can be looked up by going to the Web API entrypoint and follow the link to the organisationUnits resouce. For our example we will use Bo district whith identifier O6uvpzGd5pu as the organisation unit: . From the HTML representation we can see that the report now contains data for Bo district. These URLs can simply be used in links embedded in the web page like this: - <a href="http://apps.dhis2.org/demo/api/reportTables/xIWpSo5jjT1/data.pdf?ou=O6uvpzGd5pu">Maternal Health Bo District 2012</a> + <a href="http://apps.dhis2.org/demo/api/reportTables/xIWpSo5jjT1/data.pdf? +ou=O6uvpzGd5pu">Maternal Health Bo District 2012</a> There are many ways to authenticate over the Web and each method has its advantages and disadvantages. For this example we will use an approach where we emulate a login from the web-based login form. To help us we will use the jQuery javascript library. This javascript code should be embedded in the head section of the Web page: jQuery(document).ready(function() { $.post( "http://apps.dhis2.org/demo/dhis-web-commons-security/login.action", { @@ -305,8 +318,12 @@ Example: Embedding charts with the Visualizer Plugin In this example we will see how we can embed good-looking Ext JS charts () with data served from a DHIS back-end into a Web page. To accomplish this we will use the DHIS Visualizer plugin. The plugin is written in Javascript and depends on the Ext JS library only. A complete working example can be found at . Open the page in a web browser and view the source to see how it is set up. We start by including three required Javascript files in the header section of the HTML document. The first file is the Ext JS Javascript library (we use the Google content delivery network in this case). The third file is the Visualizer plugin. Make sure the path is pointing to your DHIS server installation. - <script type="text/javascript" src="http://extjs-public.googlecode.com/svn/tags/extjs-4.0.7/release/ext-all.js"></script> -<script type="text/javascript" src="http://apps.dhis2.org/demo/dhis-web-visualizer/app/plugin/plugin.js"></script> + <script type="text/javascript" + src="http://extjs-public.googlecode.com/svn/tags/extjs-4.0.7/release/ext-all.js"> +</script> +<script type="text/javascript" + src="http://apps.dhis2.org/demo/dhis-web-visualizer/app/plugin/plugin.js"> +</script> To authenticate with the DHIS server we use the same approach as in the previous section. In the header of the HTML document we include the following Javascript inside a script element. The setLinks method will be implemented later. Make sure the base variabel is pointing to your DHIS installation. var base = 'http://apps.dhis2.org/demo/'; @@ -400,10 +417,108 @@ filter string No - data | period | organiastionunit + data | period | organisationunit Dimension to use as chart filter + orgUnitIsParent + boolean + No + false | true + Whether the chart should display the children of the selected org units + + + skipAnimation + boolean + No + false | true + Whether the initial chart animation should be displayed + + + showData + boolean + No + false | true + Whether to display data on the chart + + + trendLine + boolean + No + false | true + Whether to display trend line(s) on the chart + + + hideLegend + boolean + No + false | true + Whether to hide the chart legend + + + hideSubtitle + boolean + No + false | true + Whether to hide the chart title + + + userOrganisationUnit + boolean + No + false | true + Whether the user of the current user should be included in the chart + + + userOrganisationUnitChildren + boolean + No + false | true + Whether the child org units of the current user should be included in the chart + + + targetLineValue + double + No + + Value of target line to display on the chart + + + targetLineLabel + string + No + + Label for target line + + + baseLineValue + double + No + + Value of baseline to display on the chart + + + baseLineLabel + string + No + + Label for baseline + + + domainAxisLabel + string + No + + Label for the domain axis + + + rangeAxisLabel + string + No + + Label for the range axis + + el string Yes