In its basic form, the Case list and Case details definition pages only accept case properties of the module case type. However, there is an addon that allows the use of calculations in the case list/details, called Custom Calculations in Case List. In addition to calculations, the add-on also opens the possibilities beyond the module case type, allowing access to any fixture available in the user’s restore file. 

Enabling the Add-on

To turn on this feature, proceed to the Application Settings (1) -> Add-ons section (2) of the application:

Next, select the button with three-lines in the upper right hand corner and choose “Calculations” (3):

In the Calculation section, check the option “Custom Calculations in the Case List” Add-on (4) and hit save (5) to commit the changes.

Using the Feature

Once the Add-On has been enabled, a new option will appear in the Add Property dropdown list (1) in the Case List or Case Detail definition pages, selecting Calculated Property (2) will create a new field in which it’s possible to define an XPath expressions to perform calculations (3), including the use of case properties.

Writing expressions

Case properties and attributes in Calculated properties are evaluated the same way as Properties in Case List and Details, as long as they are within the scope of the current case being iterated over. For instance, if the selected property is age, Commcare will actually execute “current()/age”. For properties outside the scope, a full XPath query expression is required. See some examples below.

Calculations within the scope

Case attributesDisplays the ID of the current casecurrent()/@case_id

Case indexesDisplays the ID of the parent case of the current casecurrent()/index/parent

Case propertiesDisplays the value of the propertycurrent()/age

Mathematical CalculationReturns the estimated Date of birth according to the Age stored in the casedate(floor(today() - (current()/age * 365.25)))

Calculation beyond the scope

Calculation involving the parent caseDisplays the name of the Parent caseinstance('casedb')/casedb/case[@case_id=current()/index/parent]/case_name

Calculation involving child casesReturns the number of child casescount(instance('casedb')/casedb/case[@case_type='member'][index/parent=current()/@case_id])

Calculation involving User propertiesChecks whether the User is assigned to the same location as the patientif(instance('commcaresession')/session/user/data/commcare_location_id=village_id,"YES","NO")

Calculation involving LocationsRetrieves a location's name based on information stored in the caseinstance('locations')/locations/location[@id=current()/village_id]/name

Calculation involving Lookup tablesRetrieves a field of a Lookup table item based on information stored in the caseinstance('item-list:medicine')/medicine_list/medicine[index=current()/medication_index]/medication

  • No labels