Javascript/WebAPI/Dataset Question

Hello DHIS2 developers

Quick question:

Is there a way to query the current Organization ID from a dataset? I found the following, and it works:

vuFacilityID = dhis2.de.currentOrganisationUnitId;

Is there a better variable I could poll for this information?

Reason: There is some information I want to display on the dataset that changes based on organization, and I would rather not make an individual dataset for each organization and assign them. Once I get the OrgID with the above method, I use $.getJSON to query the Web API:

$.getJSON(’…/api/organisationUnits/’+vuFacilityID+’.json’, function(FacilityData)

Then I use the results to tailor some of the information presented to the users (Data Entry Personnel)

Is there a better/simpler way to do this?

Timothy Harding
PeaceCorps Volunteer

Republic of Vanuatu

hardingt@gmail.com

+678 5955137

Hi Tim,

I assume you are doing this in the data entry module. A bit hard to say without knowing exactly what kind of information you need, but to me this looks like a perfectly viable way of retrieving org unit info. That org unit request is quite cheap.

regards,

Lars

···

On Mon, May 26, 2014 at 4:51 AM, Timothy Harding hardingt@gmail.com wrote:

Hello DHIS2 developers

Quick question:

Is there a way to query the current Organization ID from a dataset? I found the following, and it works:

vuFacilityID = dhis2.de.currentOrganisationUnitId;

Is there a better variable I could poll for this information?

Reason: There is some information I want to display on the dataset that changes based on organization, and I would rather not make an individual dataset for each organization and assign them. Once I get the OrgID with the above method, I use $.getJSON to query the Web API:

$.getJSON(’…/api/organisationUnits/’+vuFacilityID+’.json’, function(FacilityData)

Then I use the results to tailor some of the information presented to the users (Data Entry Personnel)

Is there a better/simpler way to do this?

Timothy Harding
PeaceCorps Volunteer

Republic of Vanuatu

hardingt@gmail.com

+678 5955137


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

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

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

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

Thanks Lars,

Yes, this is in the Data Entry module (I’m putting the code into the custom dataset feature).

Yup, the JSON works like a charm and I am glad I am using it correct. My worry is that in version 2.15, or 2.16 and beyond, someone might change the dhis2.de.currentOrganisationUnitId. This would break the script and prevent any queries to JSON, as I wouldn’t have access to the OrgID anymore.

The reason for all of this is to mimic the paper forms as close as possible. It might be a bit overkill, but it is also teaching me a lot about DHIS2 in the process. See the attached/inline image for a visual:

And the code sofar:

···

Timothy Harding
PeaceCorps Volunteer

Republic of Vanuatu

hardingt@gmail.com

+678 5955137

On Mon, May 26, 2014 at 8:46 PM, Lars Helge Øverland larshelge@gmail.com wrote:

Hi Tim,

I assume you are doing this in the data entry module. A bit hard to say without knowing exactly what kind of information you need, but to me this looks like a perfectly viable way of retrieving org unit info. That org unit request is quite cheap.

regards,

Lars

On Mon, May 26, 2014 at 4:51 AM, Timothy Harding hardingt@gmail.com wrote:

Hello DHIS2 developers

Quick question:

Is there a way to query the current Organization ID from a dataset? I found the following, and it works:

vuFacilityID = dhis2.de.currentOrganisationUnitId;

Is there a better variable I could poll for this information?

Reason: There is some information I want to display on the dataset that changes based on organization, and I would rather not make an individual dataset for each organization and assign them. Once I get the OrgID with the above method, I use $.getJSON to query the Web API:

$.getJSON(’…/api/organisationUnits/’+vuFacilityID+’.json’, function(FacilityData)

Then I use the results to tailor some of the information presented to the users (Data Entry Personnel)

Is there a better/simpler way to do this?

Timothy Harding
PeaceCorps Volunteer

Republic of Vanuatu

hardingt@gmail.com

+678 5955137


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

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

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

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

Thanks TIm. Looks nice.

Yes I agree this is depending on an implementation detail but we are not
likely to remove that state variable anytime soon. Will let you know if so.

regards,

Lars