Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The visit form will need to have two hidden values. You can call them whatever you want, but here is one simple approach:value

previous_visit_ pull in the value of visit_count that was calculated last time the form was filled outThis hidden value will hold the value of visit_count from the case, so there will not be a condition
Hidden value name
Description
Calculate Condition
Explanation of Calculation Condition
countEach time the form is opened, this hidden value will (empty) calculate visit_countEach time the form is opened, this hidden value will calculate how many times the form has been filled outcoalesce(#case/data/previous_visit_count, 0) + 1

This hidden value will use coalesce to determine whether previous_the case property visit_count has any value. If it does, it will add 1 to it, if it does not then it will take 0 and add 1 to that.

You can imagine the first time the form is completed it will add 1 to 0 = 1

The second time it will take the previous case property value (1) and add 1 = 2

And so on...

Your form should have these hidden values:

Image Removed

...

CommCare Functions: Coalesce

Icon

This example uses a function

...

called coalesce. You can read more

...

...

 but here is the basic information about how this function works:

coalesce

  • Behavior Useful for choosing which of two values to return.  Will return the non-empty value.  If both are not null, will return the first argument.  
  • Return: One of the values
  • Arguments:  The two values to be coalesced
  • Syntax: coalesce(value_1, value_2).  
  • Example:  This is useful if you want to use a default value when referring to a question which may or may not have been answered.  Ex. coalesce(#form/

...

  • my_question, "my default value"). 

Set up the Case Management

After you form is set up you will need to link your case properties. You will want to take the value of home_visits each time, add one, and save it to the case , and then when you fill out the form again use home_visits as the value for previous_home_visit.

You can think of it like this:

Image Removed

When you set up your case management it will look like this:

Image Removed

Example: Counting ANC Visits

Let's take an example of Ante Natal Care (ANC) visits. In this example the form has these hidden values:

...

  • Create a hidden value (anc_number) to compute the current ANC number by adding 1 to /data/previous_to the case property anc_number
  • Since data/previous_the case property anc_number can be blank in the case of a first ANC, we need a more complicated Calculate Condition of coalesce(/data/previous_to use the coalesce function: coalesce(#case/anc_number, 0) + 1
  • We then save  /data/anc_number to the case, using the case property name /data/anc_number

Explained Step by Step

To count or keep track of ANC visits in follow-up forms, do this…

  1. Create Hidden Value /data/previous_Value anc_number Create Hidden Value data/
  2. Set up your case management to save anc_number to the case
  3. In /data/the form question anc_number, in the display condition, type: coalesce(#case/data/previous_anc_number,0)+1
  4. Go to the Case Management tab for this form
  5. Under Save data to the following case properties, save both /data/previous_anc_number  and /data/anc_number
  6. Under Load the following case properties into the form, load /data/anc_number as the Case Property and /data/previous_anc_number  as the Question

 Why do it like this?

  • The hidden value, /data/previous_anc_number gives the number of ANC already received by the beneficiary. For example, if the beneficiary is experiencing her third ANC, this value would be 2.  This value is loaded from the case property anc_number, ie the number visit number saved during the beneficiary’s last consultation.
  • The hidden value (/data/anc_number) is used to compute the current ANC number by adding 1 to/data/previous_anc_number
  • Since data/previous_anc_number can be blank in the case of a first ANC, we need a more complicated Calculate Condition of coalesce(/data/previous_anc_number, 0) + 1.  Therefore, during the first visit, when previous_and_number does not have a value, it will be replaced by 0.
  • We then save  /data/anc_number to the case, using the case property name /data/anc_number