Can an xform field do calculations on historical values?

Hey guys,

Crazy question, but can an xform field do calculations on historical values?

For example, if we include the previous weight in the form using ‘Loads
data from the case’ (say 55kgs), when the user updates this value (to say
40kgs) can we do a calculation to evaluate whether the change is more than
10%?

Perhaps a simpler example is to say we want to flag / do a label alert for
any patient who’s weight drops over two visits. Make sense?

Any thoughts much appreciated.
Best wishes,
Kieran

··· -- Kieran Sharpey-Schafer Dimagi South Africa

not really. we originally hacked this up to store these tracked fields in a
property, so you could work with the old version, but that never worked
well, and i don’t know if that’s still supported.

clayton has done a lot of work making it easy to access outside data
sources from inside the xform, but this isn’t 100% complete; he can speak
about what the final capabilities will be.

one complication is that the old forms aren’t guaranteed to be kept around
on the phone after they’ve been sent to HQ, so the historical data simply
might not be available. the only way to guarantee the data will be present
is to store it in the case.

··· On Wed, Jan 18, 2012 at 12:48 PM, Kieran Sharpey-Schafer < ksharpey@dimagi.com> wrote:

Hey guys,

Crazy question, but can an xform field do calculations on historical
values?

For example, if we include the previous weight in the form using ‘Loads
data from the case’ (say 55kgs), when the user updates this value (to say
40kgs) can we do a calculation to evaluate whether the change is more than
10%?

Perhaps a simpler example is to say we want to flag / do a label alert for
any patient who’s weight drops over two visits. Make sense?

Any thoughts much appreciated.
Best wishes,
Kieran


Kieran Sharpey-Schafer
Dimagi South Africa

Yeah, so to flesh out what Drew said, you could easily and robustly do this
with the current tools by inserting the weight into the patient’s case so
that it’ll be there the next time you look at it. This has the problem that
you can only see their weight during the last visit (or whenever the
property was last set), but you can alter what you store to fit the
calculation you want. For example, you can store the weight of the last two
times if you need three weight data points. Whatever you do, you’re
responsible for making sure the logic for overwriting the weights with the
new correct weights is there, which you can do using CommCare HQ’s form
authoring tools. Let us know if you need any help pursuing that.

Cheers,
Danny

··· 2012/1/18 Drew Roos

not really. we originally hacked this up to store these tracked fields in
a property, so you could work with the old version, but that never worked
well, and i don’t know if that’s still supported.

clayton has done a lot of work making it easy to access outside data
sources from inside the xform, but this isn’t 100% complete; he can speak
about what the final capabilities will be.

one complication is that the old forms aren’t guaranteed to be kept around
on the phone after they’ve been sent to HQ, so the historical data simply
might not be available. the only way to guarantee the data will be present
is to store it in the case.

On Wed, Jan 18, 2012 at 12:48 PM, Kieran Sharpey-Schafer < ksharpey@dimagi.com> wrote:

Hey guys,

Crazy question, but can an xform field do calculations on historical
values?

For example, if we include the previous weight in the form using ‘Loads
data from the case’ (say 55kgs), when the user updates this value (to say
40kgs) can we do a calculation to evaluate whether the change is more than
10%?

Perhaps a simpler example is to say we want to flag / do a label alert
for any patient who’s weight drops over two visits. Make sense?

Any thoughts much appreciated.
Best wishes,
Kieran


Kieran Sharpey-Schafer
Dimagi South Africa

== everyone. Kieran: Is it clear from this thread that the [last/current]
calculation you mentioned is easy, but that N historical values isn’t yet
possible?

-Clayton

··· On Wed, Jan 18, 2012 at 5:35 PM, Daniel Roberts wrote:

Yeah, so to flesh out what Drew said, you could easily and robustly do
this with the current tools by inserting the weight into the patient’s case
so that it’ll be there the next time you look at it. This has the problem
that you can only see their weight during the last visit (or whenever the
property was last set), but you can alter what you store to fit the
calculation you want. For example, you can store the weight of the last two
times if you need three weight data points. Whatever you do, you’re
responsible for making sure the logic for overwriting the weights with the
new correct weights is there, which you can do using CommCare HQ’s form
authoring tools. Let us know if you need any help pursuing that.

Cheers,
Danny

2012/1/18 Drew Roos droos@dimagi.com

not really. we originally hacked this up to store these tracked fields in
a property, so you could work with the old version, but that never worked
well, and i don’t know if that’s still supported.

clayton has done a lot of work making it easy to access outside data
sources from inside the xform, but this isn’t 100% complete; he can speak
about what the final capabilities will be.

one complication is that the old forms aren’t guaranteed to be kept
around on the phone after they’ve been sent to HQ, so the historical data
simply might not be available. the only way to guarantee the data will be
present is to store it in the case.

On Wed, Jan 18, 2012 at 12:48 PM, Kieran Sharpey-Schafer < ksharpey@dimagi.com> wrote:

Hey guys,

Crazy question, but can an xform field do calculations on historical
values?

For example, if we include the previous weight in the form using ‘Loads
data from the case’ (say 55kgs), when the user updates this value (to say
40kgs) can we do a calculation to evaluate whether the change is more than
10%?

Perhaps a simpler example is to say we want to flag / do a label alert
for any patient who’s weight drops over two visits. Make sense?

Any thoughts much appreciated.
Best wishes,
Kieran


Kieran Sharpey-Schafer
Dimagi South Africa

Hey Clay, Thanks for the follow up,

So I’m almost there but not quite. I get that I can save the last
visit weight into a case property ‘case_weight’, and that I can load
that value from the case next time - into the same question.

However, I’m not clear on how I can use the case_weight and the newly
entered weight into a condition… oh hang on are you saying I need
to put a fancy xpath string in the expression editor that can some how
go ‘if Q1_weight < case_weight then do something’? Am I on the right
path? (excuse the pun)

any nudge in the right direction is much appreciated, and I’ll happily
write this up for the wiki (if I haven’t missed it already)

Oh and just for clarity the use case is:
Visit form opened, first visit entered including weight = 50
Visit form opened again for same patient, second visit entered
including weight = 40
Logic notices the drop in weight and then shows a label alert ‘patient
weight has dropped, do xyz’

Many thanks!
Kieran

··· On Jan 19, 6:35 pm, Clayton Sims wrote: > == everyone. Kieran: Is it clear from this thread that the [last/current] > calculation you mentioned is easy, but that N historical values isn't yet > possible? > > -Clayton > > > > > > > > On Wed, Jan 18, 2012 at 5:35 PM, Daniel Roberts wrote: > > Yeah, so to flesh out what Drew said, you could easily and robustly do > > this with the current tools by inserting the weight into the patient's case > > so that it'll be there the next time you look at it. This has the problem > > that you can only see their weight during the last visit (or whenever the > > property was last set), but you can alter what you store to fit the > > calculation you want. For example, you can store the weight of the last two > > times if you need three weight data points. Whatever you do, you're > > responsible for making sure the logic for overwriting the weights with the > > new correct weights is there, which you can do using CommCare HQ's form > > authoring tools. Let us know if you need any help pursuing that. > > > Cheers, > > Danny > > > 2012/1/18 Drew Roos > > >> not really. we originally hacked this up to store these tracked fields in > >> a property, so you could work with the old version, but that never worked > >> well, and i don't know if that's still supported. > > >> clayton has done a lot of work making it easy to access outside data > >> sources from inside the xform, but this isn't 100% complete; he can speak > >> about what the final capabilities will be. > > >> one complication is that the old forms aren't guaranteed to be kept > >> around on the phone after they've been sent to HQ, so the historical data > >> simply might not be available. the only way to guarantee the data will be > >> present is to store it in the case. > > >> On Wed, Jan 18, 2012 at 12:48 PM, Kieran Sharpey-Schafer < kshar...@dimagi.com> wrote: > > >>> Hey guys, > > >>> Crazy question, but can an xform field do calculations on historical > >>> values? > > >>> For example, if we include the previous weight in the form using 'Loads > >>> data from the case' (say 55kgs), when the user updates this value (to say > >>> 40kgs) can we do a calculation to evaluate whether the change is more than > >>> 10%? > > >>> Perhaps a simpler example is to say we want to flag / do a label alert > >>> for any patient who's weight drops over two visits. Make sense? > > >>> Any thoughts much appreciated. > >>> Best wishes, > >>> Kieran > > >>> -- > >>> Kieran Sharpey-Schafer > >>> Dimagi South Africa

Hey Clay, Thanks for the follow up,

So I’m almost there but not quite. I get that I can save the last
visit weight into a case property ‘case_weight’, and that I can load
that value from the case next time - into the same question.

However, I’m not clear on how I can use the case_weight and the newly
entered weight into a condition… oh hang on are you saying I need
to put a fancy xpath string in the expression editor that can some how
go ‘if Q1_weight < case_weight then do something’? Am I on the right
path? (excuse the pun)

any nudge in the right direction is much appreciated, and I’ll happily
write this up for the wiki (if I haven’t missed it already)

Oh and just for clarity the use case is:
Visit form opened, first visit entered including weight = 50
Visit form opened again for same patient, second visit entered
including weight = 40
Logic notices the drop in weight and then shows a label alert ‘patient
weight has dropped, do xyz’

So my understanding of how you would do this today is the following:

  1. Add a hidden question (data node) to the form and load it with the case
    property “weight”. In my example this is called “previous_weight”
  2. Ask the second question (I’ll call this “current_weight”.
  3. Add a trigger/label question saying “Patient weight has dropped”
  4. In the relevancy for that question you would have something like:
    /data/current_weight < /data/previous_weight
    The expression above could be created by dragging the "current weight"
    question into the left side, and the “previous weight” data node to the
    right side, and then choosing “less than” in the operation selector.

Let me know if this helps/works.

Cory

··· On Fri, Jan 27, 2012 at 4:23 AM, Kieran Sharpey-Schafer <ksharpey@dimagi.com wrote:

Many thanks!
Kieran

On Jan 19, 6:35 pm, Clayton Sims cs...@dimagi.com wrote:

== everyone. Kieran: Is it clear from this thread that the [last/current]
calculation you mentioned is easy, but that N historical values isn’t yet
possible?

-Clayton

On Wed, Jan 18, 2012 at 5:35 PM, Daniel Roberts drobe...@dimagi.com wrote:

Yeah, so to flesh out what Drew said, you could easily and robustly do
this with the current tools by inserting the weight into the patient’s
case

so that it’ll be there the next time you look at it. This has the
problem

that you can only see their weight during the last visit (or whenever
the

property was last set), but you can alter what you store to fit the
calculation you want. For example, you can store the weight of the
last two

times if you need three weight data points. Whatever you do, you’re
responsible for making sure the logic for overwriting the weights with
the

new correct weights is there, which you can do using CommCare HQ’s form
authoring tools. Let us know if you need any help pursuing that.

Cheers,
Danny

2012/1/18 Drew Roos dr...@dimagi.com

not really. we originally hacked this up to store these tracked
fields in

a property, so you could work with the old version, but that never
worked

well, and i don’t know if that’s still supported.

clayton has done a lot of work making it easy to access outside data
sources from inside the xform, but this isn’t 100% complete; he can
speak

about what the final capabilities will be.

one complication is that the old forms aren’t guaranteed to be kept
around on the phone after they’ve been sent to HQ, so the historical
data

simply might not be available. the only way to guarantee the data
will be

present is to store it in the case.

On Wed, Jan 18, 2012 at 12:48 PM, Kieran Sharpey-Schafer < kshar...@dimagi.com> wrote:

Hey guys,

Crazy question, but can an xform field do calculations on historical
values?

For example, if we include the previous weight in the form using
’Loads

data from the case’ (say 55kgs), when the user updates this value
(to say

40kgs) can we do a calculation to evaluate whether the change is
more than

10%?

Perhaps a simpler example is to say we want to flag / do a label
alert

for any patient who’s weight drops over two visits. Make sense?

Any thoughts much appreciated.
Best wishes,
Kieran


Kieran Sharpey-Schafer
Dimagi South Africa

So my understanding of how you would do this today is the following:

  1. Add a hidden question (data node) to the form and load it with the case
    property “weight”. In my example this is called “previous_weight”
  2. Ask the second question (I’ll call this “current_weight”.
  3. Add a trigger/label question saying “Patient weight has dropped”
  4. In the relevancy for that question you would have something like:
    /data/current_weight < /data/previous_weight
    The expression above could be created by dragging the "current weight"
    question into the left side, and the “previous weight” data node to the
    right side, and then choosing “less than” in the operation selector.

Let me know if this helps/works.

Cory

Ok got it that makes loads of sense, sorry I didn’t think of the
hidden value thing.

Unfortunately adding a ‘Data Node’ type doesn’t seem to be working for
me (and I checked with someone else too), so I’ll report the bug and
then try again thereafter.

Cheers! Kieran

··· On Jan 27, 8:35 pm, Cory Zue wrote:

Ok got it that makes loads of sense, sorry I didn’t think of the
hidden value thing.

Unfortunately adding a ‘Data Node’ type doesn’t seem to be working for
me (and I checked with someone else too), so I’ll report the bug and
then try again thereafter.

Thanks for pointing this out. This is now fixed. Sorry about the inconvenience!

Cory

··· > > Cheers! Kieran