Difference between revisions of "Using the single event API on DHIS2"

From mn/ifi/inf5750
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
Use /api/me to get the org unit of the logged in user. The admin user is attached to the National (Sierra Leone) org unit, where there is no single-event data to enter. The data to be entered is at the lower levels (for example Ngelehun). So to use this effectively, create a user which is attached to for example Ngelehun which you use to demo and test. When you create a user, you also need to give it access to the program and the correct permissions. The simplest is to add it to all the user roles.
+
'''Note 1: If you want to make your own programs/stages etc, use the user 'system', 'System123' when creating these programs. If not, the programs may end up being private to your admin-user and not be visible to other users. '''
  
To create a user, go to: http://apps.dhis2.org/demo/dhis-web-maintenance-user/showAddUserForm.action and enter user details. Add all availalbe roles by pressing the '>>' button on 'Available roles'. Then select a lower org-unit. For example Ngelehun CHC.
+
Some random notes:  
  
Log in with this user in Chrome. Install a JSON formatter extension to see JSON more easily. Go to http://apps.dhis2.org/demo/api/me . On the bottom, you'll see organisationUnits and you can see the id of Ngelehun (DiszpKrYNg8).  
+
Use /api/me to get the org unit of the logged in user, as well as other user-specific data.  
  
Now find the program id you want to enter (or view) data for. Go to http://apps.dhis2.org/demo/api/programs.json. This is a list of all programs the logged in user has access to. If you can't see a program here that you're expecting, it might be a permission setting for your logged in user. Find the program id. Both geolocation and survey projects are working on programs of the type: SINGLE_EVENTS_WITHOUT_REGISTRATION. Ignore the others. The "Inpatient morbidity and mortality" program for example has id eBAyeGv0exc. To see more info about this program, go to http://apps.dhis2.org/demo/api/programs/eBAyeGv0exc.json. From this JSON, you'll also see the programStages. For Single Event, there's only one programstage. You can see more info about the programstage here: http://apps.dhis2.org/demo/api/programStages/Zj7UnCAulEk.json
+
The admin user is attached to the National (Sierra Leone) org unit, where there is no single-event data to enter. The data to be entered is at the lower levels (for example Ngelehun). So to use this effectively, create a user which is attached to for example Ngelehun that you use to demo and test. When you create a user, you also need to give it access to the program and the correct permissions. The simplest is to add it to all the user roles.  
  
 +
To create a user, go to: http://apps.dhis2.org/demo/dhis-web-maintenance-user/showAddUserForm.action and enter user details. Add all availalbe roles by pressing the '>>' button on 'Available roles'. Then select a lower org-unit. For example Ngelehun CHC.
  
See the event analytics api documentation at: http://www.dhis2.org/doc/snapshot/en/user/html/ch25s22.html
+
Log in with this user in Chrome. Install a JSON formatter extension to see JSON more easily. For some tests it may also be useful to install the Postman Rest client extension to Chrome.  
  
The following URL is an example which lists a list of events (see doc-link above):
+
Go to http://apps.dhis2.org/demo/api/me . On the bottom, you'll see organisationUnits and you can see the id of Ngelehun (DiszpKrYNg8) if the user belongs to that org unit.
  
http://apps.dhis2.org/demo/api/analytics/events/query/eBAyeGv0exc?startDate=2012-01-01&endDate=2012-10-
+
Now find the program id you want to enter (or view) data for, by going to http://apps.dhis2.org/demo/api/programs.json. This is a list of all programs the logged in user has access to. If you can't see a program here that you're expecting, it might be a permission setting for your logged in user. Find the program id. Both geolocation and survey projects are working on programs of the type: SINGLE_EVENTS_WITHOUT_REGISTRATION. Ignore the others. The "Inpatient morbidity and mortality" program for example has id eBAyeGv0exc. To see more info about this program, go to http://apps.dhis2.org/demo/api/programs/eBAyeGv0exc.json. From this JSON, you'll also see the programStages. For Single Event, there's only one programstage. You can see more info about the programstage here: http://apps.dhis2.org/demo/api/programStages/Zj7UnCAulEk.json
31&dimension=ou:O6uvpzGd5pu;fdc6uOvgoji&dimension=oZg33kd9taw&dimension=qrur9Dvnyt5:EQ:18For
 
  
To extract and submit individual event data, use another api. See http://www.dhis2.org/doc/snapshot/en/user/html/ch25s07.html
+
There are two event APIs. One is the Event analytics, which is for more advanced analytics on events data, and the other is the events API. There is an important distinction. The Event Analytics API only shows events for yesterday and older. New events are NOT shown. This is very important to understand. '''Use the Events API, not the analytics API'''
  
For example, access: http://apps.dhis2.org/demo/api/events/KNDKnxPZFK6.json
+
http://www.dhis2.org/doc/snapshot/en/user/html/ch25s07.html
 +
 
 +
For example, access: http://apps.dhis2.org/demo/api/events/KNDKnxPZFK6.json  
 +
 
 +
To retrieve a list of events, do the following:
 +
 
 +
http://apps.dhis2.org/dev/api/events?orgUnit=A&program=B&startDate=2000-01-01&endDate=2013-01-01
 +
 
 +
For example:
 +
 
 +
http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=eBAyeGv0exc&startDate=2000-01-01&endDate=2013-01-01
 +
 
 +
or for a patient-based program (with programstage). This one is relevant for the embedding-apps-in-tracker, but right now there is no patient-query variable, which we are hoping to add, but it may have to be added by the group themselves.
 +
 
 +
http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=uy2gU8kT1jF&programStage=grIfo3oOf4Y&startDate=2013-01-01&endDate=2013-12-01
 +
 
 +
 
 +
 
 +
Here are two useful links to get the event data for the patient called NG-013. The data here should be gotten from the system, but you could start by hard-coding these event data in the web api call. 
 +
 
 +
eaDHS084uMp = the id for the ANC1 program stage
 +
 
 +
http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=uy2gU8kT1jF&programStage=eaDHS084uMp&startDate=2013-01-01&endDate=2013-12-01&person=fSofnQR6lAU
 +
 
 +
http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=uy2gU8kT1jF&programStage=grIfo3oOf4Y&startDate=2013-01-01&endDate=2013-12-01&person=fSofnQR6lAU
 +
 
 +
'''Some of these new features are not available on Release 2.13 (last stable release), but must be fetched from trunk. This means you need to use http://apps.dhis2.org/dev/ (not (/demo) to test them. '''
 +
 
 +
<br>
 +
 
 +
<br>
 +
 
 +
= Enabling location  =
 +
 
 +
You have to manually go into the program-&gt;edit programstage settings on dev and turn on 'Capture coordinates' for the program to capture and show coordinates. Remember that the demo and dev database is reset every night, so you have to do this every day.&nbsp;
 +
 
 +
You should use the apps.dhis2.org/dev server (not demo) when testing location.&nbsp;

Latest revision as of 15:35, 19 November 2013

Note 1: If you want to make your own programs/stages etc, use the user 'system', 'System123' when creating these programs. If not, the programs may end up being private to your admin-user and not be visible to other users. 

Some random notes:

Use /api/me to get the org unit of the logged in user, as well as other user-specific data.

The admin user is attached to the National (Sierra Leone) org unit, where there is no single-event data to enter. The data to be entered is at the lower levels (for example Ngelehun). So to use this effectively, create a user which is attached to for example Ngelehun that you use to demo and test. When you create a user, you also need to give it access to the program and the correct permissions. The simplest is to add it to all the user roles.

To create a user, go to: http://apps.dhis2.org/demo/dhis-web-maintenance-user/showAddUserForm.action and enter user details. Add all availalbe roles by pressing the '>>' button on 'Available roles'. Then select a lower org-unit. For example Ngelehun CHC.

Log in with this user in Chrome. Install a JSON formatter extension to see JSON more easily. For some tests it may also be useful to install the Postman Rest client extension to Chrome.

Go to http://apps.dhis2.org/demo/api/me . On the bottom, you'll see organisationUnits and you can see the id of Ngelehun (DiszpKrYNg8) if the user belongs to that org unit.

Now find the program id you want to enter (or view) data for, by going to http://apps.dhis2.org/demo/api/programs.json. This is a list of all programs the logged in user has access to. If you can't see a program here that you're expecting, it might be a permission setting for your logged in user. Find the program id. Both geolocation and survey projects are working on programs of the type: SINGLE_EVENTS_WITHOUT_REGISTRATION. Ignore the others. The "Inpatient morbidity and mortality" program for example has id eBAyeGv0exc. To see more info about this program, go to http://apps.dhis2.org/demo/api/programs/eBAyeGv0exc.json. From this JSON, you'll also see the programStages. For Single Event, there's only one programstage. You can see more info about the programstage here: http://apps.dhis2.org/demo/api/programStages/Zj7UnCAulEk.json

There are two event APIs. One is the Event analytics, which is for more advanced analytics on events data, and the other is the events API. There is an important distinction. The Event Analytics API only shows events for yesterday and older. New events are NOT shown. This is very important to understand. Use the Events API, not the analytics API

http://www.dhis2.org/doc/snapshot/en/user/html/ch25s07.html

For example, access: http://apps.dhis2.org/demo/api/events/KNDKnxPZFK6.json

To retrieve a list of events, do the following:

http://apps.dhis2.org/dev/api/events?orgUnit=A&program=B&startDate=2000-01-01&endDate=2013-01-01

For example:

http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=eBAyeGv0exc&startDate=2000-01-01&endDate=2013-01-01

or for a patient-based program (with programstage). This one is relevant for the embedding-apps-in-tracker, but right now there is no patient-query variable, which we are hoping to add, but it may have to be added by the group themselves.

http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=uy2gU8kT1jF&programStage=grIfo3oOf4Y&startDate=2013-01-01&endDate=2013-12-01


Here are two useful links to get the event data for the patient called NG-013. The data here should be gotten from the system, but you could start by hard-coding these event data in the web api call. 

eaDHS084uMp = the id for the ANC1 program stage

http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=uy2gU8kT1jF&programStage=eaDHS084uMp&startDate=2013-01-01&endDate=2013-12-01&person=fSofnQR6lAU

http://apps.dhis2.org/dev/api/events.json?orgUnit=DiszpKrYNg8&program=uy2gU8kT1jF&programStage=grIfo3oOf4Y&startDate=2013-01-01&endDate=2013-12-01&person=fSofnQR6lAU

Some of these new features are not available on Release 2.13 (last stable release), but must be fetched from trunk. This means you need to use http://apps.dhis2.org/dev/ (not (/demo) to test them.



Enabling location

You have to manually go into the program->edit programstage settings on dev and turn on 'Capture coordinates' for the program to capture and show coordinates. Remember that the demo and dev database is reset every night, so you have to do this every day. 

You should use the apps.dhis2.org/dev server (not demo) when testing location.