Coalesce function to record the each visit made to child /newborn

I have an app that keeps track of the number of newborn visits and child visits made to children. Newborn are children under 30 days old while child is over 30 days old and upto 24 months.

Both child and newborn are on separate modules but case name is child. The case list is using filter function to get list of newborn as well as list for child. I'm trying to use the coalesce function to be able have the display the number of each visit done to newborn or child but in each case I only get the visit 1 even after for cases where visits been done more than once. The pregnancy visits work okay but newborn and child seem to have a problem. Your support is much appreciated.

Hi Andrew

The coalesce function will check the first argument you pass for a value, and if it finds one, it will use it. otherwise, it will use the second argument as the value, regardless of whether or not it's empty. if i'm not mistaken.

the way you want to use this function is as follows: assuming your visit counter is a calculated value and it's incrementing from a case property, the default value should be the case property, the calculation should be coalesce(case property, 0) + 1 or similar
so, first time it runs, it'll look for a value in that case property and not find anything, so it will use the second argument that is "0" and then add 1. so, the visit counter will be 1. next visit, it will look for the case property and find the value 1, and then add 1. so visit counter will be 2. etc...

if this is how you've set up your calculation or similar, then just make sure you are updating the right case property. it should be the same one you're referencing in your calculation.

Hope this helps

Mazz