Validation based on case type

We have an xform that is being shared across three modules (or case types).
We would like to apply validation on one of the form fields, "clinical
code", that depends on the case type.
(ie. the range of valid clinical codes will be different when case_type is
"pregnant_mother" or "infant")

Question: is is possible to refer to the case_type in the validation
logic and, if so, can you provide some example syntax?

Thanks, Ray

Ray,

In CommCare 2.0, this is part of the casedb instance model
https://bitbucket.org/commcare/commcare/wiki/casedb
as

casedb/case/@case_type

Unfortunately, I don't believe this was exposed in any way in Commcare 1.3.

-Clayton

··· On Wed, May 9, 2012 at 11:41 AM, Ray Brunsting wrote:

We have an xform that is being shared across three modules (or case
types). We would like to apply validation on one of the form fields,
"clinical code", that depends on the case type.
(ie. the range of valid clinical codes will be different when case_type is
"pregnant_mother" or "infant")

Question: is is possible to refer to the case_type in the validation
logic and, if so, can you provide some example syntax?

Thanks, Ray

Clayton,

We've started creating a CC 2.0 version of our application to evaluate. I
would like to reference the case_type in my skip logic and/or constraints.
The following binds illustrate how I may do this using multiple form
properties.,,


A couple of questions/observations:

  1. I've hacked in "case_type='pregnant_mother'" for illustration
    purposes. Is this where I would reference the casedb instance and, if so,
    can you provide the exact syntax? (I reviewed the documentation you
    referenced, but am not confident that I can get it right --- and wonder if
    the implementation may have changed)
  2. Our intention is to add another hidden form property called
    clinical_code, and use a calculation to populate it with
    the pregnancy_clinical_code or infant_clinical_code based on the case type.
    Is this a reasonable approach or, for example, would it be better to use a
    single clinical_code form property with more complex 'constraint' logic
    based on the case_type? I guess I'm not sure if the constraint can include
    if-else logic.

Thanks, Ray

··· On Wednesday, May 9, 2012 1:22:30 PM UTC-4, Clayton Sims wrote: > > Ray, > > In CommCare 2.0, this is part of the casedb instance model > https://bitbucket.org/commcare/commcare/wiki/casedb > as > > casedb/case/@case_type > > Unfortunately, I don't believe this was exposed in any way in Commcare 1.3. > > -Clayton > > On Wed, May 9, 2012 at 11:41 AM, Ray Brunsting wrote: > >> We have an xform that is being shared across three modules (or case >> types). We would like to apply validation on one of the form fields, >> "clinical code", that depends on the case type. >> (ie. the range of valid clinical codes will be different when case_type >> is "pregnant_mother" or "infant") >> >> *Question:* is is possible to refer to the case_type in the validation >> logic and, if so, can you provide some example syntax? >> >> Thanks, Ray >> >> >

Ray,

Currently the easiest way to reference a value is the same as in CommCare
1.3. Load the data from the case into the UI with HQ, and then reference
that node in your form.

If you need to reference it manually, you can follow
the outlined instructions at
http://confluence.dimagi.com/display/commcarepublic/CommCare+2.0+XForms+Introduction

As for your second question: you certainly could use an if expression for
these nodes, but I tend to feel like the best idea is to structure it the
way that you have. It's much cleaner, easier to modify in the future, and
the simplified constraints make it possible for CommCare to figure out the
boundaries, and restrict inputs accordingly.

-Clayton

··· On Wed, May 30, 2012 at 7:10 PM, Ray Brunsting wrote:

Clayton,

We've started creating a CC 2.0 version of our application to evaluate. I
would like to reference the case_type in my skip logic and/or constraints.
The following binds illustrate how I may do this using multiple form
properties.,,


A couple of questions/observations:

  1. I've hacked in "case_type='pregnant_mother'" for illustration
    purposes. Is this where I would reference the casedb instance and, if so,
    can you provide the exact syntax? (I reviewed the documentation you
    referenced, but am not confident that I can get it right --- and wonder if
    the implementation may have changed)
  2. Our intention is to add another hidden form property called
    clinical_code, and use a calculation to populate it with
    the pregnancy_clinical_code or infant_clinical_code based on the case type.
    Is this a reasonable approach or, for example, would it be better to use a
    single clinical_code form property with more complex 'constraint' logic
    based on the case_type? I guess I'm not sure if the constraint can include
    if-else logic.

Thanks, Ray

On Wednesday, May 9, 2012 1:22:30 PM UTC-4, Clayton Sims wrote:

Ray,

In CommCare 2.0, this is part of the casedb instance model
https://bitbucket.org/**commcare/commcare/wiki/casedbhttps://bitbucket.org/commcare/commcare/wiki/casedb
as

casedb/case/@case_type

Unfortunately, I don't believe this was exposed in any way in Commcare
1.3.

-Clayton

On Wed, May 9, 2012 at 11:41 AM, Ray Brunsting wrote:

We have an xform that is being shared across three modules (or case
types). We would like to apply validation on one of the form fields,
"clinical code", that depends on the case type.
(ie. the range of valid clinical codes will be different when case_type
is "pregnant_mother" or "infant")

Question: is is possible to refer to the case_type in the validation
logic and, if so, can you provide some example syntax?

Thanks, Ray

Clayton.
That's great. I'm now able to successfully reference the case_type from
within the form. We'll proceed using multiple form attributes.
Thanks, Ray

··· On Thursday, May 31, 2012 1:35:09 AM UTC-4, Clayton Sims wrote: > > Ray, > > Currently the easiest way to reference a value is the same as in CommCare > 1.3. Load the data from the case into the UI with HQ, and then reference > that node in your form. > > If you need to reference it manually, you can follow > the outlined instructions at > http://confluence.dimagi.com/display/commcarepublic/CommCare+2.0+XForms+Introduction > > > As for your second question: you certainly could use an if expression for > these nodes, but I tend to feel like the best idea is to structure it the > way that you have. It's much cleaner, easier to modify in the future, and > the simplified constraints make it possible for CommCare to figure out the > boundaries, and restrict inputs accordingly. > > -Clayton > > On Wed, May 30, 2012 at 7:10 PM, Ray Brunsting wrote: > >> Clayton, >> >> We've started creating a CC 2.0 version of our application to evaluate. >> I would like to reference the case_type in my skip logic and/or >> constraints. The following binds illustrate how I may do this using >> multiple form properties.,, >> >> > constraint=".>= 1 and .<= 296" relevant="* >> case_type='pregnant_mother'*" >> jr:constraintMsg="jr:itext('clinical_code_error')" required="true()"/> >> > constraint=".>= 296 and .<= 320" relevant="*case_type='infant'*" >> jr:constraintMsg="jr:itext('clinical_code_error')" required="true()"/> >> >> A couple of questions/observations: >> >> 1. I've hacked in "*case_type='pregnant_mother'*" for illustration >> purposes. Is this where I would reference the casedb instance and, if so, >> can you provide the exact syntax? (I reviewed the documentation you >> referenced, but am not confident that I can get it right --- and wonder if >> the implementation may have changed) >> 2. Our intention is to add another hidden form property called >> clinical_code, and use a calculation to populate it with >> the pregnancy_clinical_code or infant_clinical_code based on the case type. >> Is this a reasonable approach or, for example, would it be better to use a >> single clinical_code form property with more complex 'constraint' logic >> based on the case_type? I guess I'm not sure if the constraint can include >> if-else logic. >> >> Thanks, Ray >> >> On Wednesday, May 9, 2012 1:22:30 PM UTC-4, Clayton Sims wrote: >> >>> Ray, >>> >>> In CommCare 2.0, this is part of the casedb instance model >>> https://bitbucket.org/**commcare/commcare/wiki/casedb >>> as >>> >>> casedb/case/@case_type >>> >>> Unfortunately, I don't believe this was exposed in any way in Commcare >>> 1.3. >>> >>> -Clayton >>> >>> On Wed, May 9, 2012 at 11:41 AM, Ray Brunsting wrote: >>> >>>> We have an xform that is being shared across three modules (or case >>>> types). We would like to apply validation on one of the form fields, >>>> "clinical code", that depends on the case type. >>>> (ie. the range of valid clinical codes will be different when case_type >>>> is "pregnant_mother" or "infant") >>>> >>>> *Question:* is is possible to refer to the case_type in the validation >>>> logic and, if so, can you provide some example syntax? >>>> >>>> Thanks, Ray >>>> >>>> >>> >