This feature (Automatically Close Cases) is only available to CommCare users with a Pro Plan or higher. For more details, see the CommCare Software Plan page.
This feature allows users with Edit Data access (see CommCareHQ Web Users) to configure updates to cases, including the ability to close cases. Without this feature the only ways to close cases are by filling out a form which closes a case, finding the case in the Case List and manually using the Close Case button, or by using the Importing Cases Using Excel tool.
Here are some examples of when this is useful:
Automatically closing and removing stale cases from users phones
Regularly closing cases that have a specified combination of case properties (for example, a case updated by two apps where both users' protocols are completed)
Cases are closed by creating rules.
The basic process of defining a rule is:
Define all of the criteria for the cases you want to match.
Choose all of the actions to apply to the cases that match the criteria.
Navigating to Data -> Automatically Close Cases you will see a list of all rules for the project along with the last time the rule has run to completion. If "Last Run" is not updated, it means that the rule has not yet run or did not run to completion on its last run. The completion could not have succeeded due to exceeding of the maximum number of automatic updates per day (10,000), due to exceeding the max run time (24 hours), or that there was an error during the run.
You can create a rule by navigating to Data -> Automatically Close Cases:
For example, imagine that you want to close any "person" cases which have not been updated in a year. You want to do this to reduce the case load on the users' phones and to keep the reports accurate.
The first step is to click on Add Automatic Close Rule and fill out the basic information by giving the rule a name you can use to remember what it's for:
Next, add your filter criteria which define the cases that the rule will apply to. The criteria pictured below say to match all cases with case type "person" that have not been modified in 365 days:
And lastly, specify the actions that will be applied to the cases that match these criteria. These actions say to close the case and update case property "close_reason", setting it to the value "automatic".
The following filter criteria are available for matching cases:
NB: It is possible to reference parent/master case properties in any of the case property filters. The syntax follows the convention of "parent/<case_property>" or "host/<case_property>". Possible use case: Close the growth monitoring case when the parent (i.e person case) turns 6.5 years old.
The following actions can be performed on cases which match the filter criteria:
Rules run automatically every day at Midnight GMT. You cannot choose when a rule is run.
You can update, delete, or deactivate a rule at anytime from the list of rules.
In addition to the dynamic case properties created by your app(s), you can reference the following case properties in automatic update rule criteria:
|name||The case's name|
|owner_id||The system identifier for the case's owner|
|opened_on||The timestamp that the case was opened|
|opened_by||The system identifier for the case's opener|
|modified_on||The timestamp that the case was last modified on mobile|
|server_modified_on||The timestamp that the case was last modified on the server|
|external_id||An optional external id your app may assign to the case|
Parent cases may also be referenced in the automatic update rule criteria by prefixing the property name with "parent/". So, for example, parent/name references the parent case's name.
The case close action shows up the case history as a form submission. You can view the form that closed the case by looking in the Submit History report or the Manage Forms tool. The form will also show up in the Case History of any cases closed by a rule. In the case history for the form name will show up as "Unknown" and the user as "system":
If a rule ran and closed cases and you want to undo that action, you should go to Manage Forms or Submit History report, locate the form submission that closed the cases, and archive it. This will restore the case to its prior status. For more information on archiving forms, please see Archive Forms.
To find the forms you will want to use the following filters:
You can add the filter options in the following order: