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.

Overview

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 that 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.

Note that automatic update rules will only trigger on cases that are currently open. If a case has already been closed, it will not be updated by a rule, even if it otherwise matches the filter criteria.

Here are some examples of when this is useful:

Cases are closed by creating rules

The basic process of defining a rule is:

  1. Define all of the criteria for the cases you want to match. 

  2. Choose all of the actions to apply to the cases that match the criteria.

Rule List

Navigate to Data →  Automatically Updates Cases, you will see a list of all rules for the project along with the name, case type, status, and 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 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.

Rules

Creating a New Rule

For example, imagine that you want to close any "Patient" cases which have not been updated in a year. You want to do this to reduce the caseload on the users' phones and to keep the reports accurate.

  1. You can create a rule by navigating to Data → Automatically Update Cases+ Add Automatic Case Update Rule button: 



  2. Fill out the basic information by giving the rule a name you can use to remember what it's for:

  3. Choose the "Case Type" and "Run when". "ALL of the criteria are met" works when you want to apply all your filter criteria. "ANY of the criteria are met" works only when you want ANY of the filter criteria to apply in the Auto Update Cases. 

  4. Next, add your filter criteria which define the cases that the rule will apply to. Notice that the wording "AND" "OR" next to the rule filter changes with the button.

  5. 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" and save.

Case Filter Criteria

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. 

Actions

The following actions can be performed on cases that match the filter criteria:

Running a Rule

Rules run automatically every day at Midnight GMT. You cannot choose when a rule is run.

Managing Rules

You can update, delete, or deactivate a rule at any time from the list of rules.

Case References

In addition to the dynamic case properties created by your app(s), you can reference the following case properties in automatic update rule criteria:

Case PropertyDescription
nameThe case's name
owner_idThe system identifier for the case's owner
opened_onThe timestamp that the case was opened
opened_byThe system identifier for the case's opener
modified_onThe timestamp that the case was last modified on mobile
server_modified_onThe timestamp that the case was last modified on the server
external_idAn 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.

Reporting and Case Actions

The case close action shows up in 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":

Reversing a Rule

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:

  1. Choose [admin], [Web Users] and [Unknown Users]
  2. For application: select "Show all forms of this Application Type..."
  3. Run the search, and the case update rule form will be listed as "http://commcarehq.org/hq_case_update_rule"