Since the "home visit form" is a follow-up form and will be used multiple times over the course of a pregnancy, it doesn't make sense to ask all the same questions over and over, so we need to employ some creative logic.
Referencing Data from the Case
Here's our Home Visit form so far:
The first item in the app is a "label," which presents a screen that does not require entering any data; it is merely to provide information to the user; a counseling message or other information.
This particular label is a message that says: "Last time this woman reported she was sick! Ask her for details of her illness." But this is tricky- we do not directly ask her in this form whether or not she was sick at the last visit. We want the display condition to refer to the answer she gave at the last interaction. Wow!
We are going to do that by referencing the case property #case/feeling_sick! The property will contain the latest value of #form/feeling_sick (found in both the registration and home visit forms), which could be either "yes" or "no" based upon the choice values we defined.
We want to show the "last time..." message only if the woman answered "yes" to the question "is the woman feeling sick today?" at the last visit, which is represented by #case/feeling_sick.
Click on the "Last time..." Label Question in the Question Tree and click on the "edit" button next to the Display Condition row:
We can make a Display Condition just like we did when in the Advanced Form Logic Tutorial.
Drag the Case Property #case/feeling_sick from the Case Properties Window over to the left part of the expression. If you can't find the case property you can search for it in the top of the Case Properties Window.
On the right side of the expression type 'yes' or drag the "yes" option from the feeling_sick question.
Sometimes you won't have the option to drag the value of the case property like you do here with the "yes" - that only works here because you have the exact same question (#form/feeling_sick) that populates the case property. If that isn't true then you will just have to manually type it in. That's why it is often important to keep track of what you call things and to be consistent in how you label things. For example, if you always use 'yes' and 'no' then it is easy to remember what to type in.
Press "save" and you should see the following statement for the display condition:
The next question, "Is the woman feeling sick today," just asks whether or not the woman is sick at today's visit. We always want to ask that, so there is no need to put a display condition. However, keep in mind that later, when we are tying everything together, that the answer to this question during Visit 1 will become the answer to previous_sickness during Visit 2!
After that we have two more questions which have to do with whether the woman has made her prescribed clinic visits to have her prenatal health checked. We could just ask these at each visit, but we should be a bit more clever than that. If you have a lot of questions there is little benefit to asking again and again - after all if you had a paper form you wouldn't need to do that.
There are two clever things we want to do here:
- We want to only ask about the second visit if the woman has gone to her first visit.
- We only want to ask about a visit if she said no at the previous visit (as in, after a woman says "yes" to either of these, we should not ask that question again). In other words, we want to experience the following:
- 1st Follow-up visit: Imagine you go on the first follow-up visit and the woman says "yes" to Clinical Visit 1. It is now appropriate to ask about Clinical Visit 2, but when we ask she says No.
- 2nd Follow-up visit: It makes sense that next visit we don't have to ask about Clinical Visit 1 (we already asked last time!) but we do want to ask about Clinic Visit 2. Suppose we ask her, and this time she says yes to Clinic Visit 2.
- 3rd Follow-up visit: This woman has already gone to both of her clinic visits, so no need to ask either of those questions.
This is complex but exciting stuff, stay with us.
Notice that you already have two relevant case properties:
We didn't ask these questions about clinic visits at registration, but we do ask them at each follow-up visit until we get a "yes" answer. So instead of filling these hidden values with the answer from the registration form, we will be filling them with the answer from the last visit! We will use case management not just to link one form to another, but to link submissions of the same form at different points in time!!!
Again, we'll do that actual process later, but for now just remember that each of these contains the value from the answer to the question on the previous visit.
Go to the Display Condition for the question #form/clinic_visit_1
We want this question to always show up UNLESS the last time the question was asked (#case/clinic_visit_1) the answer was "yes." #case/clinic_visit_1 can have 3 possible values: 'yes', 'no', or blank - this is the value the first time we open the form. Given those three options we want to show this question whenever the value of #case/clinic_visit_1 is either 'no' or blank. Another way of saying that is we want to show #form/clinic_visit_1 when the value of #case/clinic_visit_1 is NOT yes. We can represent that as "show this question when #case/clinic_visit_1 is NOT 'yes.'
Take a break to let that sink in, and then let's try it out.
Let's use the Expression Editor to build the expression:
- Open the Display Condition Expression Builder by clicking on "edit" for the question #form/clinic_visit_1
- Drag over #case/clinic_visit_1 from the Case Properties Window to the left side of the expression
- Change the drop down to "is not equal to"
- Type "yes" into the right side of the expression.
- Save and you should see the following:
One more to go - for the question #form/clinic_visit_2 we want to have a similar condition to #form/clinic_visit_1- to only show the question if it was not previously answered as "yes."
So we can expect to see something like #case/clinic_visit_2 != 'yes'
But we have an additional complication - we want to show #form/clinic_visit_2 only if the answer to the #form/clinic_visit_1 was "yes" (during this visit OR ever) . This may seem easy - we just say show when #form/clinic_visit_1 = "yes". But in our scenario, the woman may have said yes during the last visit, in which case we aren't even going to ask the question #form/clinic_visit_1 this time!
So we have to say that we want to show #form/clinic_visit_2 if EITHER #form/clinic_visit_1 OR #case/clinic_visit_1 is equal to 'yes.'
We have three conditions we are interested in for the question to be displayed. We want to make sure that this is true:
- CONDITION 1: #case/clinic_visit_2 should NOT be equal to 'yes'
And we want to ensure that ONE of the following is true:
- CONDITION 2: #case/clinic_visit_1 IS EQUAL TO 'yes'
- CONDITION 3: #form/clinic_visit_1 IS EQUAL TO 'yes'
We will join these together like this:
- Show question #form/clinic_visit_2 if: CONDITION 1 AND (CONDITION 2 OR CONDITION 3)
It is possible to do part of this with the Expression Editor but you still have to edit it manually to add the parentheses, so we suggest using the Advanced Editor.
Select the Question #form/clinic_visit_2 from the Question Tree and click on "Edit" next to "Display Condition"
Then click on "Show Advanced Mode":
In the editor, using the dragging of hidden values to create the following expression:
In the future, when you go to this question and hit "edit" next to "Display Condition" you will see that you'll be immediately brought to the Advanced section because the logic is too complicated for the Expression Builder. You can also see why it is important to pay attention to the #form and #case differences, since it can get confusing when they are combined in one expression!
You are done with the Advanced Case Management Tutorial Series! Go back to the Tutorial Main Page.