Question Type : Advanced Calculation

Updated 1 min read
On this page

This document provides guidelines for implementing and using advanced calculation question types in OPUS checklists. This question type does not accept direct inputs but displays a calculated result based on other question answers within the same checklist.

General Specification

Referencing Questions

Reference Naming: Questions used in calculations should have a specific reference name using the "reference" property.

Naming Convention: Use full words in lowercase, separated by underscores (_).

Example: For a section "Employee" and question "Enter first name of employee", the reference should be:

employee_firstname

Regular Functions

Formula Storage: The formula for the calculation is stored in the "function" property.

Reference Syntax: Use square brackets [] to include reference names in formulas.

Example: For questions with references "001", "002", and "003":

([001] + [002]) * [003]

Special Functions

  • DATEDIF Function: Used for calculating the difference between two dates.
  • Example: For date references "001" and "002", and number reference "003":

App Specific Changes

UX

Unanswered References: If referenced questions are unanswered, display the calculated question as unanswered with a prompt indicating waiting for inputs.

Answered References: Display the calculated result inside a box when all referenced questions are answered.

On Input

Dynamic Calculation: Recalculate and update the result whenever an answer to a referenced question is saved.

Nested Calculations: Allow one level deep nesting of calculated questions during checklist creation.

Making Answers Available for Calculation

Return Types: Implement a function to return values in appropriate types based on question type (e.g., DateTimeOffset for dates, decimal for numbers).


Special Calculation Functions

DATEDIF

Purpose: Calculate the difference between two dates in various units (years, months, days, hours, minutes, seconds).

Syntax:

datedif(start_date, end_date, unit)

Units:

"years"

"months"

"days"

"hours"

"minutes"

"seconds"

Example:

datedif([start_date], [end_date], 'hours')

Implementation Example

Question Definitions

Date Input:

Reference: employee_start_date

Number Input:

Reference: employee_years_of_service

Calculated Question:

Reference: total_service_years 
Function: datedif([employee_start_date], today(), 'years') 
		+ [employee_years_of_service]