Sort order in casedb XPath queries

Hi all,

In some of our forms, we have the need to pull data from different case
lists, and we are using the casedb instance method found here:
https://help.commcarehq.org/display/commcarepublic/Multiple+Choice+Questions+with+Cases+as+Choices

I am able to pull the case list based on some basic filtering, but my case
the list is about 100 alphabetical case names, and the list is not showing
up in alphabetic order. Is there a way to sort this list? Maybe a method
when I make the instance tag? or maybe something in the itemset tag itself?

For reference, here is the relevant portion of my form. (I have also tried
to change the value from @case_id to case_name to see if it was sorting
based on the value, and it still comes back in random order)

    <instance id="casedb" src="jr://instance/casedb"></instance>

    <itemset 

nodeset="instance('casedb')/casedb/case[@case_type='household'][cluster=/data/ClusterID]">


I know this isn't a Dimagi-supported feature but was hoping someone could
point me in the right direction! Thanks!

P.S. Sorry for the double post... had a typo in the subject line :slight_smile:

Hi!

Unfortunately this is a really tough issue for us to tackle for two
reasons.

A) Our XPath version by definition isn't capable of sorting (and even XPath
2.0 can only sort by awkward and tenuous iterators), so we can't sort at
the nodeset level

B) The XForms specifications for itemsets don't specify any indication of
how elements in the itemset should be sorted.

I don't remember whether it's a hard or soft expectation that an
honor the native ordering of the passed in nodeset, but we're open in
theory to extending our itemset definition to including a sort element that
would permit ordering as long as it doesn't violate the XForms
specification.

The other option would be to allow specifying the return sort order in the
casedb instance connector, but that's a much bigger lift.

-Clayton

··· On Mon, Nov 24, 2014 at 9:44 AM, wrote:

Hi all,

In some of our forms, we have the need to pull data from different case
lists, and we are using the casedb instance method found here:
Home - CommCare Public - CommCare Public
Multiple+Choice+Questions+with+Cases+as+Choices

I am able to pull the case list based on some basic filtering, but my case
the list is about 100 alphabetical case names, and the list is not showing
up in alphabetic order. Is there a way to sort this list? Maybe a method
when I make the instance tag? or maybe something in the itemset tag itself?

For reference, here is the relevant portion of my form. (I have also tried
to change the value from @case_id to case_name to see if it was sorting
based on the value, and it still comes back in random order)

    <instance id="casedb" src="jr://instance/casedb"></instance>

    <itemset nodeset="instance('casedb')/casedb/case[@case_type='

household'][cluster=/data/ClusterID]">


I know this isn't a Dimagi-supported feature but was hoping someone could
point me in the right direction! Thanks!

P.S. Sorry for the double post... had a typo in the subject line :slight_smile:

--
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 Clayton,

Thanks for the informative reply! I have found sorting via vanilla XForm
(even 2.0) very difficult and convoluted as well.

When you say 'open in theory to extending our itemset definition to
including a sort element that would permit ordering as long as it doesn't
violate the XForms specification' could you possibly point me to the
location in the code where this change may be made? I am a Django web
developer and may be able to begin working on a pull request in some spare
time :slight_smile:

Thanks again,
Caleb

··· On Wed, Nov 26, 2014 at 3:04 PM, Clayton Sims wrote:

Hi!

Unfortunately this is a really tough issue for us to tackle for two
reasons.

A) Our XPath version by definition isn't capable of sorting (and even
XPath 2.0 can only sort by awkward and tenuous iterators), so we can't sort
at the nodeset level

B) The XForms specifications for itemsets don't specify any indication of
how elements in the itemset should be sorted.

I don't remember whether it's a hard or soft expectation that an
honor the native ordering of the passed in nodeset, but we're open in
theory to extending our itemset definition to including a sort element that
would permit ordering as long as it doesn't violate the XForms
specification.

The other option would be to allow specifying the return sort order in the
casedb instance connector, but that's a much bigger lift.

-Clayton

On Mon, Nov 24, 2014 at 9:44 AM, creinkin@nd.edu wrote:

Hi all,

In some of our forms, we have the need to pull data from different case
lists, and we are using the casedb instance method found here:
Home - CommCare Public - CommCare Public
Multiple+Choice+Questions+with+Cases+as+Choices

I am able to pull the case list based on some basic filtering, but my
case the list is about 100 alphabetical case names, and the list is not
showing up in alphabetic order. Is there a way to sort this list? Maybe a
method when I make the instance tag? or maybe something in the itemset tag
itself?

For reference, here is the relevant portion of my form. (I have also
tried to change the value from @case_id to case_name to see if it was
sorting based on the value, and it still comes back in random order)

    <instance id="casedb" src="jr://instance/casedb"></instance>

    <itemset nodeset="instance('casedb')/casedb/case[@case_type='

household'][cluster=/data/ClusterID]">


I know this isn't a Dimagi-supported feature but was hoping someone could
point me in the right direction! Thanks!

P.S. Sorry for the double post... had a typo in the subject line :slight_smile:

--
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.

--
You received this message because you are subscribed to a topic in the
Google Groups "commcare-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/commcare-users/drduHMxRdm4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Caleb

There are two places this change could be made theoretically:

  1. Within the you could provide a namespaced attribute which
    could optionally be used to provided a Sort Key for model. I'm not 100%
    sure whether this is spec compliant (the spec may imply that you have to
    display the items in document order
  2. In the instance src="" connector you could in theory provide some
    information that would affect the actual static model generation.

These changes would need to be made in the JavaRosa XForms library, our
copy of which is hosted here:

-Clayton

··· On Mon, Dec 1, 2014 at 11:37 AM, Caleb Reinking wrote:

Hi Clayton,

Thanks for the informative reply! I have found sorting via vanilla XForm
(even 2.0) very difficult and convoluted as well.

When you say 'open in theory to extending our itemset definition to
including a sort element that would permit ordering as long as it doesn't
violate the XForms specification' could you possibly point me to the
location in the code where this change may be made? I am a Django web
developer and may be able to begin working on a pull request in some spare
time :slight_smile:

Thanks again,
Caleb

On Wed, Nov 26, 2014 at 3:04 PM, Clayton Sims csims@dimagi.com wrote:

Hi!

Unfortunately this is a really tough issue for us to tackle for two
reasons.

A) Our XPath version by definition isn't capable of sorting (and even
XPath 2.0 can only sort by awkward and tenuous iterators), so we can't sort
at the nodeset level

B) The XForms specifications for itemsets don't specify any indication of
how elements in the itemset should be sorted.

I don't remember whether it's a hard or soft expectation that an
honor the native ordering of the passed in nodeset, but we're
open in theory to extending our itemset definition to including a sort
element that would permit ordering as long as it doesn't violate the XForms
specification.

The other option would be to allow specifying the return sort order in
the casedb instance connector, but that's a much bigger lift.

-Clayton

On Mon, Nov 24, 2014 at 9:44 AM, creinkin@nd.edu wrote:

Hi all,

In some of our forms, we have the need to pull data from different case
lists, and we are using the casedb instance method found here:
Home - CommCare Public - CommCare Public
Multiple+Choice+Questions+with+Cases+as+Choices

I am able to pull the case list based on some basic filtering, but my
case the list is about 100 alphabetical case names, and the list is not
showing up in alphabetic order. Is there a way to sort this list? Maybe a
method when I make the instance tag? or maybe something in the itemset tag
itself?

For reference, here is the relevant portion of my form. (I have also
tried to change the value from @case_id to case_name to see if it was
sorting based on the value, and it still comes back in random order)

    <instance id="casedb" src="jr://instance/casedb"></instance>

    <itemset nodeset="instance('casedb')/casedb/case[@case_type='

household'][cluster=/data/ClusterID]">


I know this isn't a Dimagi-supported feature but was hoping someone
could point me in the right direction! Thanks!

P.S. Sorry for the double post... had a typo in the subject line :slight_smile:

--
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.

--
You received this message because you are subscribed to a topic in the
Google Groups "commcare-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/commcare-users/drduHMxRdm4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@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.