0

I am working on the CommCare mLabour app, which tracks women from the onset of labour through delivery via digital partograph. For the contractions graph, I need to write an instance which filters to cases whose contraction intensity is 'low'. In the app, this case property is contractions_dur = 'low'. I tried the following path, and am getting an xpath error in the app:

instance('casedb')/casedb/case[@case_type='Indicators'][index/parent=current()/@case_id][@status='open']/[contractions_dur = 'low']

The error message says invalid xpath 'expected beginning of path'

The only CommCare Help Site page I can find about instance syntax is this one about CommCare session instance paths. What is the proper syntax for an instance filtering for a specific case with a certain case property value?

  • Hi @ali-flaming, do you happen to know what the error message is that you saw? If so could you include it in the question? – Ben Rudolph Feb 13 '17 at 21:10
  • 1
    @BenRudolph I think this one would be more appropriate on Stack Overflow. Does that seem reasonable? – jonsca Feb 13 '17 at 23:46
  • @jonsca I think this actually does belong on webapps. The jargon used in this question is definitely a bit scary/programming like. However I would equate this to using a formula in excel. CommCare let's you insert small snippets of xpath to transform/manipulate your application. While this is a more advanced usage, this wholly belongs in the webapp. The platform is also opensource, in which case if you are trying to setup the website (github.com/dimagi/commcare-hq), I think that belongs on StackOverflow. What do you think? – Ben Rudolph Feb 14 '17 at 6:38
  • Also in case useful, here is a page that shows the types of advanced usage that can be done in CommCare: confluence.dimagi.com/display/commcarepublic/…. – Ben Rudolph Feb 14 '17 at 7:49
  • @BenRudolph Sounds reasonable to me in terms of leaving this one here. We treat Google Spreadsheets with basically the same provisions. I'm not completely sure about where the site setup questions should live. If users are implementing HTML-based solutions, then Stack Overflow would likely be appropriate. For hosting issues Webmasters would probably fit the bill, but it would probably go case-by-case. – jonsca Feb 14 '17 at 22:51
5

If you're filtering cases, you want an expression that ultimately returns a set of cases. The first part of the expression, instance('casedb')/casedb/case, gives you all cases on the phone.

The expressions in square brackets then filter the cases by case type, parent (you're limiting to cases that are children of the "current" case, which is the one you selected from the case list), and open/closed.

[@case_type='Indicators']
[index/parent=current()/@case_id]
[@status='open']

The /[contractions_dur = 'low'] is what's throwing the error. The / says to go another level deep, but I suspect what you want is to just add the contractions_dur as a fourth constraint, on the same level as the others. So try dropping the slash: instance('casedb')/casedb/case[@case_type='Indicators'][index/parent=current()/@case_id][@status='open'][contractions_dur = 'low']

2

IF you're using this statement in an actual "filter" (i.e. for a caselist) then you'll want to remove the square brackets and keep the slash. So the full expression would be:

instance('casedb')/casedb/case[@case_type='Indicators'][index/parent=current()/@case_id][@status='open']/contractions_dur = 'low'

If you're using the statement to populate a multiple choice answer or something like that, then yes, remove that slash and keep the brackets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.