Retrieving mobile worker's location from organisation hierarchy

Hello,

I have an organisation with the following levels: Country / Zone / Province
/ District / Health Facility. I have also assigned mobile workers to these
locations.
I am now trying to retrieve the mobile worker's country and assign it to a
form variable. What would be the syntax to do so please?

Thank you,

Alex

Hello,

The syntax is quite ugly, unfortunately. Additionally, it requires that you
assign all users to the same level of the hierarchy (and depends on that
hierarchy). We are hoping to extend formbuilder to do this more seamlessly
in the future, but for the time being, the following page might help.

https://confluence.dimagi.com/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications

cheers,
Cory

··· On Sat, Oct 31, 2015 at 9:30 AM, Alexandre Vanobberghen < alexandre.vanobberghen@gmail.com> wrote:

Hello,

I have an organisation with the following levels: Country / Zone /
Province / District / Health Facility. I have also assigned mobile workers
to these locations.
I am now trying to retrieve the mobile worker's country and assign it to a
form variable. What would be the syntax to do so please?

Thank you,

Alex

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hello Cory,

Thanks for your response.
All my users are assigned to health facilities i.e. the lowest level of the
hierarchy.
I tried to use the link you sent to formulate the following syntax:

instance('locations')/countrys/country[count(zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]) >
0]/name

But I get the following error when I try to deploy:

Build Failed!
Validation Error: can't get triggers for relative references in form Danger
signs
https://india.commcarehq.org/a/icrc-almanach/apps/view/93d7648be1d8402509c2f3e877fdb95a/modules-0/forms-0/
in module "ALMANACH"

Is my syntax wrong?

Thanks,

Alex

··· Le dimanche 1 novembre 2015 11:59:54 UTC+1, Cory Zue a écrit : > > Hello, > > The syntax is quite ugly, unfortunately. Additionally, it requires that > you assign all users to the same level of the hierarchy (and depends on > that hierarchy). We are hoping to extend formbuilder to do this more > seamlessly in the future, but for the time being, the following page might > help. > > > https://confluence.dimagi.com/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications > > cheers, > Cory > > On Sat, Oct 31, 2015 at 9:30 AM, Alexandre Vanobberghen < alexandre.v...@gmail.com > wrote: > >> Hello, >> >> I have an organisation with the following levels: Country / Zone / >> Province / District / Health Facility. I have also assigned mobile workers >> to these locations. >> I am now trying to retrieve the mobile worker's country and assign it to >> a form variable. What would be the syntax to do so please? >> >> Thank you, >> >> Alex >> >> -- >> You received this message because you are subscribed to the Google Groups >> "commcare-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to commcare-user...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > >

Hey Alex,

This looks like it could be a bug on our side. I'm going to make a ticket
for the issue and someone on our team will follow up soon.

thanks,
Cory

··· On Mon, Nov 2, 2015 at 9:41 AM, Alexandre Vanobberghen < alexandre.vanobberghen@gmail.com> wrote:

Hello Cory,

Thanks for your response.
All my users are assigned to health facilities i.e. the lowest level of
the hierarchy.
I tried to use the link you sent to formulate the following syntax:

instance('locations')/countrys/country[count(zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]) >
0]/name

But I get the following error when I try to deploy:

Build Failed!
Validation Error: can't get triggers for relative references in form Danger
signs
https://india.commcarehq.org/a/icrc-almanach/apps/view/93d7648be1d8402509c2f3e877fdb95a/modules-0/forms-0/
in module "ALMANACH"

Is my syntax wrong?

Thanks,

Alex

Le dimanche 1 novembre 2015 11:59:54 UTC+1, Cory Zue a écrit :

Hello,

The syntax is quite ugly, unfortunately. Additionally, it requires that
you assign all users to the same level of the hierarchy (and depends on
that hierarchy). We are hoping to extend formbuilder to do this more
seamlessly in the future, but for the time being, the following page might
help.

https://confluence.dimagi.com/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications

cheers,
Cory

On Sat, Oct 31, 2015 at 9:30 AM, Alexandre Vanobberghen < alexandre.v...@gmail.com> wrote:

Hello,

I have an organisation with the following levels: Country / Zone /
Province / District / Health Facility. I have also assigned mobile workers
to these locations.
I am now trying to retrieve the mobile worker's country and assign it to
a form variable. What would be the syntax to do so please?

Thank you,

Alex

--
You received this message because you are subscribed to the Google
Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Cory,

The above issue was fixed by Sheel, thanks for this!

However, I still face an issue when trying to retrieve the mobile workers
location from the organisation hierarchy: (refering to
https://wiki.commcarehq.org/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications)

Having the hierarchy Country / Zone / Province / District / Health
Facility, I assigned my "test" mobile worker to a health facility.
I can get the location ID using:
instance('commcaresession')/session/user/data/commcare_location_id.
However, the following command fails:
instance('locations')/countrys/country/zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]/name
I get the following error when opening the form:

"Error occured - The problem was located in calculate expression for
/data/variables/userLocationName
XPath evaluation: type mismatch
instance('locations')/countrys/country/zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]/name
was not found"

Not sure what the issue is. Is the issur the command's syntax? Or the
actual location ID?
Any idea?

Thanks,

Alex

Hi Alex,

On your Organization levels page, can you click on the Advanced checkbox
and review the organization level codes you have. These should match what
you're using in your syntax above.

Does the actual location ID calculate correctly?

Thanks,
Sheel

··· On Tue, Nov 24, 2015 at 9:39 AM, Alexandre Vanobberghen < alexandre.vanobberghen@gmail.com> wrote:

Hi Cory,

The above issue was fixed by Sheel, thanks for this!

However, I still face an issue when trying to retrieve the mobile workers
location from the organisation hierarchy: (refering to
https://wiki.commcarehq.org/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications
)

Having the hierarchy Country / Zone / Province / District / Health
Facility, I assigned my "test" mobile worker to a health facility.
I can get the location ID using:
instance('commcaresession')/session/user/data/commcare_location_id.
However, the following command fails:
instance('locations')/countrys/country/zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]/name
I get the following error when opening the form:

"Error occured - The problem was located in calculate expression for
/data/variables/userLocationName
XPath evaluation: type mismatch
instance('locations')/countrys/country/zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]/name
was not found"

Not sure what the issue is. Is the issur the command's syntax? Or the
actual location ID?
Any idea?

Thanks,

Alex

On Monday, November 2, 2015 at 8:58:40 AM UTC+1, Cory Zue wrote:

Hey Alex,

This looks like it could be a bug on our side. I'm going to make a ticket
for the issue and someone on our team will follow up soon.

thanks,
Cory

On Mon, Nov 2, 2015 at 9:41 AM, Alexandre Vanobberghen < alexandre.v...@gmail.com> wrote:

Hello Cory,

Thanks for your response.
All my users are assigned to health facilities i.e. the lowest level of
the hierarchy.
I tried to use the link you sent to formulate the following syntax:

instance('locations')/countrys/country[count(zones/zone/provinces/province/districts/district/health_facilitys/health_facility[@id
= instance('commcaresession')/session/user/data/commcare_location_id]) >
0]/name

But I get the following error when I try to deploy:

Build Failed!
Validation Error: can't get triggers for relative references in form Danger
signs
https://india.commcarehq.org/a/icrc-almanach/apps/view/93d7648be1d8402509c2f3e877fdb95a/modules-0/forms-0/
in module "ALMANACH"

Is my syntax wrong?

Thanks,

Alex

Le dimanche 1 novembre 2015 11:59:54 UTC+1, Cory Zue a écrit :

Hello,

The syntax is quite ugly, unfortunately. Additionally, it requires that
you assign all users to the same level of the hierarchy (and depends on
that hierarchy). We are hoping to extend formbuilder to do this more
seamlessly in the future, but for the time being, the following page might
help.

https://confluence.dimagi.com/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications

cheers,
Cory

On Sat, Oct 31, 2015 at 9:30 AM, Alexandre Vanobberghen < alexandre.v...@gmail.com> wrote:

Hello,

I have an organisation with the following levels: Country / Zone /
Province / District / Health Facility. I have also assigned mobile workers
to these locations.
I am now trying to retrieve the mobile worker's country and assign it
to a form variable. What would be the syntax to do so please?

Thank you,

Alex

--
You received this message because you are subscribed to the Google
Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google
Groups "commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Sheel Shah
Project Manager | Dimagi
m: +1.781.428.5419 | skype: sheel_shah

Hi Sheel,

Thanks, this solved it.
I was in fact referring to the organisation level rather than the type
code. So I replaced "health_facility" by "health-facility" and it did the
trick.

It could be useful to add a line on the help page to say that the type code
should be used in the syntax?
(https://wiki.commcarehq.org/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications)

Thanks for your help!

Alex

Thanks Alex! I've updated that help page.

··· On Tue, Nov 24, 2015 at 11:23 AM, Alexandre Vanobberghen < alexandre.vanobberghen@gmail.com> wrote:

Hi Sheel,

Thanks, this solved it.
I was in fact referring to the organisation level rather than the type
code. So I replaced "health_facility" by "health-facility" and it did the
trick.

It could be useful to add a line on the help page to say that the type
code should be used in the syntax? (
https://wiki.commcarehq.org/display/commcarepublic/Referencing+the+Location+Hierarchy+in+Applications
)

Thanks for your help!

Alex

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Sheel Shah
Project Manager | Dimagi
m: +1.781.428.5419 | skype: sheel_shah