Help creating links to download materialized views

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  2.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  3.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.

Hi Randy,

let me see if I get you correctly: The problem is mainly that you cannot drop your sql views in an arbitrary order since they depend on each other? Also, your views do not depend on any dhis resource table, and you completely maintain your views through the cron job.

Assuming this, would it solve the problem if we introduced a property on dhis-managed sql views which would allow you to specify whether it should be dropped and recreated by dhis (i.e. when rebuilding the resource tables) or not?

For your sql views you could then set this to not to be dropped/created and you could control those sql views like you prefer.

The advantage here is that we already have the functionality for producing dhis-managed sql views as json/xml/csv through the web api.

regards,

Lars

···

On Thu, Dec 20, 2012 at 12:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Hi Randy and Lars,

The fundemental problem is that view which they were using are linked to the resource tables. These tables need to be regenerated, and when they are regenerated, the tables are dropped and recreated. If views are linked to these tables, the resource table regeneration cannot take place, because the database forbids the table to be dropped, because there are linked views. DHIS2 fails silently and only says “Resource tables generating…” or something like that. I think we have described this problem on the list before and I am sure you are aware of it.

So, to get around this problem, we use stored procedures to materialize the views, and then as Randy indicates, users can get to them through ODBC.

I guess it could be done Randy by creating an SQL View of the materialized view. This does not really make a whole lot of sense, but it could be done. So, if you create an SQL view in DHIS2 of “SELECT * FROM _materalized view;” you will get a new materialized view available, as Lars points out, through the API. A bit wasteful really but certainly possible.

The “elegant” part which Randy mentions is that we do not define many seperate views, but dynamically define the tables based on data element groups. The views are very similar, they just differ in the data elements which should be presented to the users. So, instead of maintaining like 20 separate similar views, we have just done the same thing with one single stored procedure instead. Second option then would be to have these separate 20 (or whatever the number is) views as DHIS2 SQL views. Again, not very elegant.

Third option which I see (which I think is the best option) is to reflect SQL views out of DHIS2 without ever materializing them. I think there should be an option for “materialize” for each SQL view. If it is not checked, the view would be produced dynamically at the time of request. Again, not a very elegant solution for this problem, because we would still need 20 separate “SELECT * FROM _materialized_view1”, “SELECT * FROM _materialized_view2”, but at least we would not write the materalized view twice.

Fourth option (maybe a bit limiting) is to create the same SQL View type of functionality for tables, lets call it a table reflector, which would simply reflect a table as JSON, XML, CSV or whatever. The user could be presented with a list of tables in the system, and simply choose the one you want (in our case, one of the materialized views) and then they would be available somehow through the API.

Fifth option, is some external report. In Nigeria, we use R for this purpose actually, and it is relatively straightforward. Other things like PHP, Python or Birt could be used pretty easily as well.

Just a bit of a grab-bag, but maybe there will be some possible solution in there.

Regards,

Jason

···

On Thu, Dec 20, 2012 at 1:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Just to add to the grab bag, making the resource tables themselves available as csv or what have you would be an alternative to reconstructing them from the xml metadata export that we do currently in mydatamart. Jason has suggested this to me on occasion. I have now got a high speed dxf1 metadata parser working so its not required but in retrospect might have been a smarter way to go.

As long as a client has the resource tables then it can make whatever sense it chooses from the plain aggregated data.

···

On 20 December 2012 17:28, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Randy and Lars,

The fundemental problem is that view which they were using are linked to the resource tables. These tables need to be regenerated, and when they are regenerated, the tables are dropped and recreated. If views are linked to these tables, the resource table regeneration cannot take place, because the database forbids the table to be dropped, because there are linked views. DHIS2 fails silently and only says “Resource tables generating…” or something like that. I think we have described this problem on the list before and I am sure you are aware of it.

So, to get around this problem, we use stored procedures to materialize the views, and then as Randy indicates, users can get to them through ODBC.

I guess it could be done Randy by creating an SQL View of the materialized view. This does not really make a whole lot of sense, but it could be done. So, if you create an SQL view in DHIS2 of “SELECT * FROM _materalized view;” you will get a new materialized view available, as Lars points out, through the API. A bit wasteful really but certainly possible.

The “elegant” part which Randy mentions is that we do not define many seperate views, but dynamically define the tables based on data element groups. The views are very similar, they just differ in the data elements which should be presented to the users. So, instead of maintaining like 20 separate similar views, we have just done the same thing with one single stored procedure instead. Second option then would be to have these separate 20 (or whatever the number is) views as DHIS2 SQL views. Again, not very elegant.

Third option which I see (which I think is the best option) is to reflect SQL views out of DHIS2 without ever materializing them. I think there should be an option for “materialize” for each SQL view. If it is not checked, the view would be produced dynamically at the time of request. Again, not a very elegant solution for this problem, because we would still need 20 separate “SELECT * FROM _materialized_view1”, “SELECT * FROM _materialized_view2”, but at least we would not write the materalized view twice.

Fourth option (maybe a bit limiting) is to create the same SQL View type of functionality for tables, lets call it a table reflector, which would simply reflect a table as JSON, XML, CSV or whatever. The user could be presented with a list of tables in the system, and simply choose the one you want (in our case, one of the materialized views) and then they would be available somehow through the API.

Fifth option, is some external report. In Nigeria, we use R for this purpose actually, and it is relatively straightforward. Other things like PHP, Python or Birt could be used pretty easily as well.

Just a bit of a grab-bag, but maybe there will be some possible solution in there.

Regards,

Jason


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

On Thu, Dec 20, 2012 at 1:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Okay. So with materialized view you are referring to a plain db table, right? I thought you meant creating a view with sql something like “create materialized view” but I can see that has not been implemented directly in postgres yet.

Anyway I think creating a dhis sql view per table is a reasonable work-around. It requires you only to create 20 objects, one time.

One alternative would be to create some sort of dhis sql report. But it would be very similar in nature and require some development for 2.11. Another alternative would be just to expose database tables through the web api but that does not sound very nice or restful to me.

So if you are willing to create a sql view per table you can achieve 1.

Re 2 you can simply point directly to the sql views through the web api, for instance to the demo like this, for xml:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.xml

for csv:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.csv

I have committed and backported to 2.10 representations for Excel and HTML, you can reach them after upgrading by using the extensions .xls and .html .

For web pages you can use plain links like this:

Download as XML |

CSV | etc

For 3, yes you can easily include these as resources. Just add a new one, give it a name, select “external URL” as type and point to the sql view URLs above.

For authentication you might get some tips from here:

http://dhis2.org/doc/snapshot/en/implementer/html/ch08s02.html#d5e600

You can download 2.10 latest from here in half an hour:

http://apps.dhis2.org/ci/job/dhis-web-2.10/lastSuccessfulBuild/artifact/dhis-2/dhis-web/dhis-web-portal/target/dhis.war

···

On Thu, Dec 20, 2012 at 1:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Yes, in this context, a materialized view is simply a table which is produced from an SQL view. The advantage of course is that materialized views can be indexed, etc and are normally much faster to serve than dynamic SQL views.

The one thing I did not mention, is the refreshment of the materialized views. As Randy pointed out, we have scheduled the refresh of the views as a cron job. Ideally, this would be something which DHIS2 would do. If we were to represent the 20 or so views as normal DHIS2 SQL views, there is no native way to refresh them, and this needs to occur each night after the data mart runs. So, ideally, scheduling of the regeneration of the SQL views (and resource tables) should be an option as well. There is a work around using CURL to force the regeneration, but again ,this is a bit of a kludge as well. Hope this can get included at some point in time.

I think the real fix in this case would be.

  1. Implement scheduling of SQL views.

  2. If users want to use custom Postgresql functions, they could do this, and they could be triggered by DHIS with “SELECT my_custom_stored_procedure();” with the scheduler. This would eliminate the need for a cron job from the system.

  3. Allow for users to choose certain tables which should be available as resources, for instance, “_orgunitstructure” (Bob’s point) or “_my_custom_table”, which might be some external table or materialized view. DHIS would not do anything other than to produce JSON, HTML, Excel or whatever from this table. Not really sure why this is not RESTFUL? Isn’t this the same thing as what is being done with the SQL views themselves?

Regards,

Jason

···

On Thu, Dec 20, 2012 at 10:51 PM, Lars Helge Øverland larshelge@gmail.com wrote:

Okay. So with materialized view you are referring to a plain db table, right? I thought you meant creating a view with sql something like “create materialized view” but I can see that has not been implemented directly in postgres yet.

Anyway I think creating a dhis sql view per table is a reasonable work-around. It requires you only to create 20 objects, one time.

One alternative would be to create some sort of dhis sql report. But it would be very similar in nature and require some development for 2.11. Another alternative would be just to expose database tables through the web api but that does not sound very nice or restful to me.

So if you are willing to create a sql view per table you can achieve 1.

Re 2 you can simply point directly to the sql views through the web api, for instance to the demo like this, for xml:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.xml

for csv:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.csv

I have committed and backported to 2.10 representations for Excel and HTML, you can reach them after upgrading by using the extensions .xls and .html .

For web pages you can use plain links like this:

Download as XML |

CSV | etc

For 3, yes you can easily include these as resources. Just add a new one, give it a name, select “external URL” as type and point to the sql view URLs above.

For authentication you might get some tips from here:

http://dhis2.org/doc/snapshot/en/implementer/html/ch08s02.html#d5e600

You can download 2.10 latest from here in half an hour:

http://apps.dhis2.org/ci/job/dhis-web-2.10/lastSuccessfulBuild/artifact/dhis-2/dhis-web/dhis-web-portal/target/dhis.war

On Thu, Dec 20, 2012 at 5:28 PM, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Randy and Lars,

The fundemental problem is that view which they were using are linked to the resource tables. These tables need to be regenerated, and when they are regenerated, the tables are dropped and recreated. If views are linked to these tables, the resource table regeneration cannot take place, because the database forbids the table to be dropped, because there are linked views. DHIS2 fails silently and only says “Resource tables generating…” or something like that. I think we have described this problem on the list before and I am sure you are aware of it.

So, to get around this problem, we use stored procedures to materialize the views, and then as Randy indicates, users can get to them through ODBC.

I guess it could be done Randy by creating an SQL View of the materialized view. This does not really make a whole lot of sense, but it could be done. So, if you create an SQL view in DHIS2 of “SELECT * FROM _materalized view;” you will get a new materialized view available, as Lars points out, through the API. A bit wasteful really but certainly possible.

The “elegant” part which Randy mentions is that we do not define many seperate views, but dynamically define the tables based on data element groups. The views are very similar, they just differ in the data elements which should be presented to the users. So, instead of maintaining like 20 separate similar views, we have just done the same thing with one single stored procedure instead. Second option then would be to have these separate 20 (or whatever the number is) views as DHIS2 SQL views. Again, not very elegant.

Third option which I see (which I think is the best option) is to reflect SQL views out of DHIS2 without ever materializing them. I think there should be an option for “materialize” for each SQL view. If it is not checked, the view would be produced dynamically at the time of request. Again, not a very elegant solution for this problem, because we would still need 20 separate “SELECT * FROM _materialized_view1”, “SELECT * FROM _materialized_view2”, but at least we would not write the materalized view twice.

Fourth option (maybe a bit limiting) is to create the same SQL View type of functionality for tables, lets call it a table reflector, which would simply reflect a table as JSON, XML, CSV or whatever. The user could be presented with a list of tables in the system, and simply choose the one you want (in our case, one of the materialized views) and then they would be available somehow through the API.

Fifth option, is some external report. In Nigeria, we use R for this purpose actually, and it is relatively straightforward. Other things like PHP, Python or Birt could be used pretty easily as well.

Just a bit of a grab-bag, but maybe there will be some possible solution in there.

Regards,

Jason


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

On Thu, Dec 20, 2012 at 1:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Okay. In my opinion the real fix would be to support data element and indicator group selection in mydatamart. Then one wouldn’t have to do any of this. Anyway, scheduling of sql views and resource tables is already on the plan and will be done for 2.11. We can also extend the sql view functionality to support custom select statements like you suggest.

···

On Fri, Dec 21, 2012 at 5:47 AM, Jason Pickering jason.p.pickering@gmail.com wrote:

Yes, in this context, a materialized view is simply a table which is produced from an SQL view. The advantage of course is that materialized views can be indexed, etc and are normally much faster to serve than dynamic SQL views.

The one thing I did not mention, is the refreshment of the materialized views. As Randy pointed out, we have scheduled the refresh of the views as a cron job. Ideally, this would be something which DHIS2 would do. If we were to represent the 20 or so views as normal DHIS2 SQL views, there is no native way to refresh them, and this needs to occur each night after the data mart runs. So, ideally, scheduling of the regeneration of the SQL views (and resource tables) should be an option as well. There is a work around using CURL to force the regeneration, but again ,this is a bit of a kludge as well. Hope this can get included at some point in time.

I think the real fix in this case would be.

  1. Implement scheduling of SQL views.
  1. If users want to use custom Postgresql functions, they could do this, and they could be triggered by DHIS with “SELECT my_custom_stored_procedure();” with the scheduler. This would eliminate the need for a cron job from the system.
  1. Allow for users to choose certain tables which should be available as resources, for instance, “_orgunitstructure” (Bob’s point) or “_my_custom_table”, which might be some external table or materialized view. DHIS would not do anything other than to produce JSON, HTML, Excel or whatever from this table. Not really sure why this is not RESTFUL? Isn’t this the same thing as what is being done with the SQL views themselves?

Thanks to all of you…

I now have some great short term fixes and look forward to thinking more about the best approach over the longer term. I like the idea of using this function to create “true” views dynamically as well as the tables Jason has created. From the user perspective, the nice thing is that they can use the DHIS web interface to create useful dataelement and indicator groups – and then the function creates the views for them automatically – no need to write SQL queries. We might want to add a check box in the dataelement/indicator group definition screens that users can check if they want the a materialized view created for the group. The default would be no. Then we can change the syntax in the function to select only those groups that are checked before looping through and creating the tables/views.

As Jason notes the main issue that brought us to build these tables was that the SQL syntax in the function uses the resource tables – to create a more detailed orgunit view (all reporting entities with the names of the entire hierarchy above them (sector, sub-district, district, province). Many of the reports require these groupings of data and the pivot table drill-down/float-up capabilities are very helpful. I’m not sure how we can get around the need to drop and rebuild these tables.

Randy

···

Anyway I think creating a dhis sql view per table is a reasonable work-around. It requires you only to create 20 objects, one time.

One alternative would be to create some sort of dhis sql report. But it would be very similar in nature and require some development for 2.11. Another alternative would be just to expose database tables through the web api but that does not sound very nice or restful to me.

So if you are willing to create a sql view per table you can achieve 1.

Re 2 you can simply point directly to the sql views through the web api, for instance to the demo like this, for xml:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.xml

for csv:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.csv

I have committed and backported to 2.10 representations for Excel and HTML, you can reach them after upgrading by using the extensions .xls and .html .

For web pages you can use plain links like this:

Download as XML |

CSV | etc

For 3, yes you can easily include these as resources. Just add a new one, give it a name, select “external URL” as type and point to the sql view URLs above.

For authentication you might get some tips from here:

http://dhis2.org/doc/snapshot/en/implementer/html/ch08s02.html#d5e600

You can download 2.10 latest from here in half an hour:

http://apps.dhis2.org/ci/job/dhis-web-2.10/lastSuccessfulBuild/artifact/dhis-2/dhis-web/dhis-web-portal/target/dhis.war

On Thu, Dec 20, 2012 at 5:28 PM, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Randy and Lars,

The fundemental problem is that view which they were using are linked to the resource tables. These tables need to be regenerated, and when they are regenerated, the tables are dropped and recreated. If views are linked to these tables, the resource table regeneration cannot take place, because the database forbids the table to be dropped, because there are linked views. DHIS2 fails silently and only says “Resource tables generating…” or something like that. I think we have described this problem on the list before and I am sure you are aware of it.

So, to get around this problem, we use stored procedures to materialize the views, and then as Randy indicates, users can get to them through ODBC.

I guess it could be done Randy by creating an SQL View of the materialized view. This does not really make a whole lot of sense, but it could be done. So, if you create an SQL view in DHIS2 of “SELECT * FROM _materalized view;” you will get a new materialized view available, as Lars points out, through the API. A bit wasteful really but certainly possible.

The “elegant” part which Randy mentions is that we do not define many seperate views, but dynamically define the tables based on data element groups. The views are very similar, they just differ in the data elements which should be presented to the users. So, instead of maintaining like 20 separate similar views, we have just done the same thing with one single stored procedure instead. Second option then would be to have these separate 20 (or whatever the number is) views as DHIS2 SQL views. Again, not very elegant.

Third option which I see (which I think is the best option) is to reflect SQL views out of DHIS2 without ever materializing them. I think there should be an option for “materialize” for each SQL view. If it is not checked, the view would be produced dynamically at the time of request. Again, not a very elegant solution for this problem, because we would still need 20 separate “SELECT * FROM _materialized_view1”, “SELECT * FROM _materialized_view2”, but at least we would not write the materalized view twice.

Fourth option (maybe a bit limiting) is to create the same SQL View type of functionality for tables, lets call it a table reflector, which would simply reflect a table as JSON, XML, CSV or whatever. The user could be presented with a list of tables in the system, and simply choose the one you want (in our case, one of the materialized views) and then they would be available somehow through the API.

Fifth option, is some external report. In Nigeria, we use R for this purpose actually, and it is relatively straightforward. Other things like PHP, Python or Birt could be used pretty easily as well.

Just a bit of a grab-bag, but maybe there will be some possible solution in there.

Regards,

Jason

On Thu, Dec 20, 2012 at 1:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Randy if you really want to have the maximum database-flexible view of your data then you might also consider just creating user accounts with read only access to a copy of the production database.

Rather than having dhis transformed into a sort of phPgAdmin :slight_smile:

One possiblility which comes to mind … it would be easy enough to have a copy of the database running on your other machine (cheetah), refreshed daily. Then just create separate user accounts on that database and open it up to your users to connect with excel, access or whatever other horrible things they want to use. And you can of course still run your materialize views script.

Bob

···

On 21 December 2012 07:36, Wilson,Randy rwilson@msh.org wrote:

Thanks to all of you…

I now have some great short term fixes and look forward to thinking more about the best approach over the longer term. I like the idea of using this function to create “true” views dynamically as well as the tables Jason has created. From the user perspective, the nice thing is that they can use the DHIS web interface to create useful dataelement and indicator groups – and then the function creates the views for them automatically – no need to write SQL queries. We might want to add a check box in the dataelement/indicator group definition screens that users can check if they want the a materialized view created for the group. The default would be no. Then we can change the syntax in the function to select only those groups that are checked before looping through and creating the tables/views.

As Jason notes the main issue that brought us to build these tables was that the SQL syntax in the function uses the resource tables – to create a more detailed orgunit view (all reporting entities with the names of the entire hierarchy above them (sector, sub-district, district, province). Many of the reports require these groupings of data and the pivot table drill-down/float-up capabilities are very helpful. I’m not sure how we can get around the need to drop and rebuild these tables.

Randy

From: Lars Helge Øverland [mailto:larshelge@gmail.com]

Sent: Thursday, December 20, 2012 10:51 PM

To: Jason Pickering

Cc: Wilson,Randy; dhis2-users@lists.launchpad.net

Subject: Re: [Dhis2-users] Help creating links to download materialized views

Okay. So with materialized view you are referring to a plain db table, right? I thought you meant creating a view with sql something like “create materialized view” but I can see that has not been implemented directly in postgres yet.

Anyway I think creating a dhis sql view per table is a reasonable work-around. It requires you only to create 20 objects, one time.

One alternative would be to create some sort of dhis sql report. But it would be very similar in nature and require some development for 2.11. Another alternative would be just to expose database tables through the web api but that does not sound very nice or restful to me.

So if you are willing to create a sql view per table you can achieve 1.

Re 2 you can simply point directly to the sql views through the web api, for instance to the demo like this, for xml:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.xml

for csv:

http://apps.dhis2.org/demo/api/sqlViews/dI68mLkP1wN/data.csv

I have committed and backported to 2.10 representations for Excel and HTML, you can reach them after upgrading by using the extensions .xls and .html .

For web pages you can use plain links like this:

Download as XML |

CSV | etc

For 3, yes you can easily include these as resources. Just add a new one, give it a name, select “external URL” as type and point to the sql view URLs above.

For authentication you might get some tips from here:

http://dhis2.org/doc/snapshot/en/implementer/html/ch08s02.html#d5e600

You can download 2.10 latest from here in half an hour:

http://apps.dhis2.org/ci/job/dhis-web-2.10/lastSuccessfulBuild/artifact/dhis-2/dhis-web/dhis-web-portal/target/dhis.war

On Thu, Dec 20, 2012 at 5:28 PM, Jason Pickering jason.p.pickering@gmail.com wrote:

Hi Randy and Lars,

The fundemental problem is that view which they were using are linked to the resource tables. These tables need to be regenerated, and when they are regenerated, the tables are dropped and recreated. If views are linked to these tables, the resource table regeneration cannot take place, because the database forbids the table to be dropped, because there are linked views. DHIS2 fails silently and only says “Resource tables generating…” or something like that. I think we have described this problem on the list before and I am sure you are aware of it.

So, to get around this problem, we use stored procedures to materialize the views, and then as Randy indicates, users can get to them through ODBC.

I guess it could be done Randy by creating an SQL View of the materialized view. This does not really make a whole lot of sense, but it could be done. So, if you create an SQL view in DHIS2 of “SELECT * FROM _materalized view;” you will get a new materialized view available, as Lars points out, through the API. A bit wasteful really but certainly possible.

The “elegant” part which Randy mentions is that we do not define many seperate views, but dynamically define the tables based on data element groups. The views are very similar, they just differ in the data elements which should be presented to the users. So, instead of maintaining like 20 separate similar views, we have just done the same thing with one single stored procedure instead. Second option then would be to have these separate 20 (or whatever the number is) views as DHIS2 SQL views. Again, not very elegant.

Third option which I see (which I think is the best option) is to reflect SQL views out of DHIS2 without ever materializing them. I think there should be an option for “materialize” for each SQL view. If it is not checked, the view would be produced dynamically at the time of request. Again, not a very elegant solution for this problem, because we would still need 20 separate “SELECT * FROM _materialized_view1”, “SELECT * FROM _materialized_view2”, but at least we would not write the materalized view twice.

Fourth option (maybe a bit limiting) is to create the same SQL View type of functionality for tables, lets call it a table reflector, which would simply reflect a table as JSON, XML, CSV or whatever. The user could be presented with a list of tables in the system, and simply choose the one you want (in our case, one of the materialized views) and then they would be available somehow through the API.

Fifth option, is some external report. In Nigeria, we use R for this purpose actually, and it is relatively straightforward. Other things like PHP, Python or Birt could be used pretty easily as well.

Just a bit of a grab-bag, but maybe there will be some possible solution in there.

Regards,

Jason

On Thu, Dec 20, 2012 at 1:58 PM, Wilson,Randy rwilson@msh.org wrote:

In Rwanda we have found report tables and MyDatamart inadequate for the needs of many of the central level health programs. What they want is a dump of all the datavalues in specific dataelement and indicator groups along with the related orgunit hierarchy. We originally were doing this using SQL views, under Data Administration, however some of the views are built on one another so when the Datamart and Resource table procedures run they is unable to drop the views before re-creating them…. And consequently neither process runs.

Jason Pickering has helped us develop an elegant function that gets around the view issue, and creates materialized views for all dataelement groups: special tables that are refreshed every night through a chron job (just like the datamart). This gives us exactly what the users want – they generally link to the tables with ODBC connection using an excel pivot table – and because they are only retrieving the dataelement groups they want the file is not too big. Unfortunately, this only works on the local area network – refreshing the pivot tables over the network is likely to be too slow, and our security settings don’t enable a remote ODBC connection.

We are now beginning to explore the DHIS-2 API to create a portal for users to access DHIS-2 objects. I see that SQL views are exposed through this API, but for the reasons stated above we can’t rely on them. Here is where we need help:

  1.   Is there a way to expose other tables in the API?
    
  1.   Does anyone have some sample HTML code that we could use to list these special tables (they all start with _*view* _) in the portal and download them as xls, csv or xml?  Similar to what is shown in the DHIS-2 portal demo for downloading tables.
    
  1.   Could we include the links to these tables as resources in users’ dashboards?
    

Randy Wilson

Senior HMIS and Data Use Advisor

Rwanda/IHSSP

Management Sciences for Health

BOX 371

Kigali, Rwanda

+250788308835 (mobile)

Skype name (wilsonrandy_us)

www.msh.org

Stronger health systems. Greater health impact.


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Hi Lars,
I could not agree with you more. I think the ability of users to extract out chunks of data from the data mart based on indicator or data element groups would largely solve this problem of external views at least in Rwanda. It is a great idea, and hope it can be implemented in future releases.

Best regards,
Jason

···

On Fri, Dec 21, 2012 at 9:33 AM, Lars Helge Øverland larshelge@gmail.com wrote:

On Fri, Dec 21, 2012 at 5:47 AM, Jason Pickering jason.p.pickering@gmail.com wrote:

Yes, in this context, a materialized view is simply a table which is produced from an SQL view. The advantage of course is that materialized views can be indexed, etc and are normally much faster to serve than dynamic SQL views.

The one thing I did not mention, is the refreshment of the materialized views. As Randy pointed out, we have scheduled the refresh of the views as a cron job. Ideally, this would be something which DHIS2 would do. If we were to represent the 20 or so views as normal DHIS2 SQL views, there is no native way to refresh them, and this needs to occur each night after the data mart runs. So, ideally, scheduling of the regeneration of the SQL views (and resource tables) should be an option as well. There is a work around using CURL to force the regeneration, but again ,this is a bit of a kludge as well. Hope this can get included at some point in time.

I think the real fix in this case would be.

  1. Implement scheduling of SQL views.
  1. If users want to use custom Postgresql functions, they could do this, and they could be triggered by DHIS with “SELECT my_custom_stored_procedure();” with the scheduler. This would eliminate the need for a cron job from the system.
  1. Allow for users to choose certain tables which should be available as resources, for instance, “_orgunitstructure” (Bob’s point) or “_my_custom_table”, which might be some external table or materialized view. DHIS would not do anything other than to produce JSON, HTML, Excel or whatever from this table. Not really sure why this is not RESTFUL? Isn’t this the same thing as what is being done with the SQL views themselves?

Okay. In my opinion the real fix would be to support data element and indicator group selection in mydatamart. Then one wouldn’t have to do any of this. Anyway, scheduling of sql views and resource tables is already on the plan and will be done for 2.11. We can also extend the sql view functionality to support custom select statements like you suggest.

Hi Lars and Jason,

I agree as well. Remember the views are actually crucial for custom iReports as well – so a mydatamart only solution is not sufficient. We have extended our system with tables to manage results based financing data (dataelement tariffs and storage of banking details for orgunits). As a result we need to be able to create SQL views that include these foreign tables to be used as the datasources for standard reports.

Randy

···

Hi Lars,

I could not agree with you more. I think the ability of users to extract out chunks of data from the data mart based on indicator or data element groups would largely solve this problem of external views at least in Rwanda. It is a great idea, and hope it can be implemented in future releases.

Best regards,

Jason

On Fri, Dec 21, 2012 at 9:33 AM, Lars Helge Øverland larshelge@gmail.com wrote:

On Fri, Dec 21, 2012 at 5:47 AM, Jason Pickering jason.p.pickering@gmail.com wrote:

Yes, in this context, a materialized view is simply a table which is produced from an SQL view. The advantage of course is that materialized views can be indexed, etc and are normally much faster to serve than dynamic SQL views.

The one thing I did not mention, is the refreshment of the materialized views. As Randy pointed out, we have scheduled the refresh of the views as a cron job. Ideally, this would be something which DHIS2 would do. If we were to represent the 20 or so views as normal DHIS2 SQL views, there is no native way to refresh them, and this needs to occur each night after the data mart runs. So, ideally, scheduling of the regeneration of the SQL views (and resource tables) should be an option as well. There is a work around using CURL to force the regeneration, but again ,this is a bit of a kludge as well. Hope this can get included at some point in time.

I think the real fix in this case would be.

  1. Implement scheduling of SQL views.

  2. If users want to use custom Postgresql functions, they could do this, and they could be triggered by DHIS with “SELECT my_custom_stored_procedure();” with the scheduler. This would eliminate the need for a cron job from the system.

  3. Allow for users to choose certain tables which should be available as resources, for instance, “_orgunitstructure” (Bob’s point) or “_my_custom_table”, which might be some external table or materialized view. DHIS would not do anything other than to produce JSON, HTML, Excel or whatever from this table. Not really sure why this is not RESTFUL? Isn’t this the same thing as what is being done with the SQL views themselves?

Okay. In my opinion the real fix would be to support data element and indicator group selection in mydatamart. Then one wouldn’t have to do any of this. Anyway, scheduling of sql views and resource tables is already on the plan and will be done for 2.11. We can also extend the sql view functionality to support custom select statements like you suggest.

Okay. Hopefully the sql reports/scheduling ideas suggested above can facilitate that.

On a general note, in 2.10 you can create SQL based standard reports where you can do any SQL statement you like, as well as including dynamic report parameters in the SQL which can be selected from the user interface at report generation time:

http://dhis2.org/doc/snapshot/en/user/html/ch13s04.html#d5e2266

···

On Fri, Dec 21, 2012 at 11:14 AM, Wilson,Randy rwilson@msh.org wrote:

Hi Lars and Jason,

I agree as well. Remember the views are actually crucial for custom iReports as well – so a mydatamart only solution is not sufficient. We have extended our system with tables to manage results based financing data (dataelement tariffs and storage of banking details for orgunits). As a result we need to be able to create SQL views that include these foreign tables to be used as the datasources for standard reports.