Problem with functions

Hi,
Iam new to commcare and Iam facing some problems.
My app is structured as follow:
Module I

  1. Registration form: I register cases of type A and B
  2. Update form: I update cases. In this form, a case can change from A to B or vice- versa
    Module II
  3. Follow-up form for case A
  • Here a chw has to visit case A twice. The first visit is immediately after registration and the second visit is after 30 days and I have a hidden value that calculates the number of days
    Second_day_visit: if(format-date(date(today () + 30), “%a”) = “Sun” or format-date(date(today() + 30), “%a”) = “Sat”, date(today() + 32), date(today() + 30))
  1. Follow-up for case B
  • Here a chw also has to visit case B twice. The first visit is immediately after registration and the second visit is after 45 days and I have a hidden value that calculates the number of days
    Second_visit_date: if(format-date(date(today () + 45), “%a”) = “Sun” or format-date(date(today() + 45), “%a”) = “Sat”, date(today() + 47), date(today() + 45))

I have saved the hidden value as a case property and I have used it in the case details so that the chw can see the number of days for the second visit; until here things work well, but the problem is that when case A changes to B or vice-versa in the update form, the Second_visit_date is not cleared automatically so that it only shows days after first visit follow-up, i.e. the field second_visit_date should not still show 32 days after Case A changes to B, but it should empty the field so that it shows 45 days after registering the first visit.
I do not know if I have made myself understood. Looking for solution because Iam stuck.

I didn’t quite follow all of that, but you wrote:

the problem is that when case A changes to B or vice-versa in the update form, the Second_visit_date is not cleared automatically

Why don’t you modify the update form to clear Second_visit_date when changing A to B? Would that solve this need?

@Ethan_Soergel

How would this be configured in the update form?

Hi, Ethan.

Could you help me with some ideas as regards to how these modifications should be in the update form?

Thanks

i’m not aware of any functionality that allows you to change a case type

but, you can probably close case 1 of type A, and copy what you need to a new case of type B. but it won’t be case 1.

HTH

Mazz

It sounds like the update form makes a modification to the case changing it from A to B. I assume this doesn’t actually change the CommCare case_type (that’s not possible, as @Mazz says), but updates for example a “category” property indicating it is a different sort of case of the same case_type.

You can make a hidden value in the update form with a calculate that’s
""
And then in the form’s case management tab, set the second_visit_date property to that hidden value, thus emptying the field.

Though if there’s no other place where second_visit_date is set, I suspect clearing it isn’t actually what you want. You may instead need the update form to recalculate the second_visit_date based on the date of registration (you’ll need to have date of registration saved to the case too for this to work).