=== modified file 'src/docbkx/en/dhis2_r.xml' --- src/docbkx/en/dhis2_r.xml 2012-08-16 08:47:19 +0000 +++ src/docbkx/en/dhis2_r.xml 2012-11-04 13:42:07 +0000 @@ -45,7 +45,7 @@ Using ODBC to retrieve data from DHIS2 into R In this example, we will use a system-wide ODBC connector which will be used to retrieve data from the DHIS2 database. There are some disadvantages with this approach, as ODBC is slower than other methods and it does raise some security concerns by providing a system-wide connector to all users. However, it is a convenient method to provide a connection to multiple users. The use of the R package RODBC will be used in this case. Other alternatives would be the use of the RPostgreSQL package, which can interface directly through the Postgresql driver described in Assuming you have already installed R from the procedure in the previous section. Invoke the following command to add the required libraries for this example. - apt-get install r-cran-odbc r-cran-lattice odbc-postgresql + apt-get install r-cran-rodbc r-cran-lattice odbc-postgresql Next, we need to configure the ODBC connection. Edit the file to suit your local situation using the following template as a guide. Lets create and edit a file called odbc.ini [dhis2] Description = DHIS2 Database @@ -71,7 +71,7 @@ From the R prompt, execute the following commands to connect to the DHIS2 database. > library(RODBC) > channel<-odbcConnect("dhis2")#Note that the name must match the ODBC connector name -> sqlTest<-c("SELECT dataeleemntid, name FROM dataelement LIMIT 10;") +> sqlTest<-c("SELECT dataelementid, name FROM dataelement LIMIT 10;") > sqlQuery(channel,sqlTest) name 1 OPD First Attendances Under 5 @@ -86,7 +86,8 @@ 10 Deaths of malaria case provided with anti-malarial treatment 1 to 5 Years > - It seems R is able to retrieve data from the DHIS2 database. As an illustrative example, lets say we have been asked to calculate the relative percentage of OPD male and female under 5 attendances for the last twelve months.First, lets create an SQL query which will provide us the basic information which will be required. + It seems R is able to retrieve data from the DHIS2 database. + As an illustrative example, lets say we have been asked to calculate the relative percentage of OPD male and female under 5 attendances for the last twelve months.First, lets create an SQL query which will provide us the basic information which will be required. OPD<-sqlQuery(channel,"SELECT p.startdate, de.name as de, sum(dv.value::double precision) FROM datavalue dv INNER JOIN period p on dv.periodid = p.periodid @@ -95,7 +96,7 @@ and p.enddate <= '2011-12-31' and de.name ~*('Attendance OPD') GROUP BY p.startdate, de.name;") - We have stored the result of the SQL query in an R data frame called OPD. Lets take a look at what the data looks like. + We have stored the result of the SQL query in an R data frame called "OPD". Lets take a look at what the data looks like. > head(OPD) startdate de sum 1 2011-12-01 Attendance OPD <12 months female 42557