Exposing financial calculations

Cloud API supports the ability to retrieve financial calculations for a claim. This includes the following endpoints:

  • GET /claim/v1/claims/{claimId}/financial-calculations

    • This identifies the list of financial calculation expressions a given caller can access on a given claim

  • POST /claim/v1/claims/{claimId}/financial-calculations/{expression}/get-amount

    • This retrieves the result of a given financial expression, either with or without filters

For more information on how to use these endpoints, see the Cloud API Consumer Guide.

Cloud API also supports the following configurations for these endpoints:

  • Exposing base configuration ClaimCenter calculations that are not exposed in the base configuration of Cloud API

  • Exposing custom calculations

  • Configuring restrictions to specific financial calculation expressions and filters

This topic discusses how to expose new calculations to the Financial Calculations endpoints. For information on how to configure restrictions to specific financial calculation expressions and filters, see Configuring financial calculations access.

The FinancialCalculations collection resource

The GET /claim/v1/claims/{claimId}/financial-calculations endpoint returns an instance of the FinancialCalculations collection resource. This resource is implemented by the FinancialCalculationsCoreResource class and its Ext subclass.

The class defines the set of legal expressions that can be used for calculations. In the base configuration, this class defines a set of commonly used expressions. You can add additional expressions by doing the following:

  • Extending the CustomCalculations property in the appropriate Ext class.

  • Mapping the new expression names to expression objects.

A new expression name can map either to a base configuration calculation that is defined in ClaimCenter but not already exposed to Cloud API, or to a custom expression.

The expression name is used as the identifier for the child element resource. By convention, an expression name starts with the first letter of each word capitalized and everything else lowercase.

The base configuration FinancialCalculationsExtResource class

In the base configuration, the FinancialCalculationsExtResource class is empty, as shown below.
package gw.rest.ext.cc.claim.v1.claims.transactions

uses gw.rest.core.cc.claim.v1.claims.transactions.FinancialCalculationsCoreResource

@Export
class FinancialCalculationsExtResource extends FinancialCalculationsCoreResource {

}

Exposing financial expression

To expose a financial expression, you must do the following:

  1. Add a CustomCalculations getter that returns a map which associates strings to financial expressions.

  2. Add an association for the expression to be exposed.

    1. The key must be a string that names the expression.
    2. The value must be a call to the getter in FinancialsCalculationUtil that returns the appropriate FinancialsExpression.

Example: Exposing a base configuration expression

For example, the base configuration includes a financial calculation named TotalPaymentsIncludingPending. This expression is not exposed in the base configuration of Cloud API.

To expose this expression, you must modify FinancialCalculationsExtResource to appear as follows.
package gw.rest.ext.cc.claim.v1.claims.transactions

uses gw.api.financials.FinancialsExpression
uses gw.rest.core.cc.claim.v1.claims.transactions.FinancialCalculationsCoreResource
uses gw.api.financials.FinancialsCalculationUtil

@Export
class FinancialCalculationsExtResource extends FinancialCalculationsCoreResource {
  protected override property get CustomCalculations() :
  Map<String, FinancialsExpression> {
    return {"TotalPaymentsIncludingPending" ->
        FinancialsCalculationUtil.TotalPaymentsIncludingPendingExpression}
  }

}

Example: Exposing a custom expression

Suppose you have a custom expression named DoubleAvailableReservesExpression that returns an amount equal to twice the available reserves.

To expose this expression, you must modify FinancialCalculationsExtResource to appear as follows. (Typically, this type of custom expression would be declared in a separate library class for shared use. For the sake of simplicity, this example defines the expression directly in the method.)
package gw.rest.ext.cc.claim.v1.claims.transactions

uses gw.api.financials.FinancialsCalculationUtil
uses gw.api.financials.FinancialsExpression
uses gw.rest.core.cc.claim.v1.claims.transactions.
        FinancialCalculationsCoreResource
 
@Export

class FinancialCalculationsExtResource extends
                 FinancialCalculationsCoreResource {

  protected override property get CustomCalculations() : 
        Map<String, FinancialsExpression> {
    var doubleAvailableReservesExpression =
          FinancialsCalculationUtil.AvailableReservesExpression.
          plus(FinancialsCalculationUtil.AvailableReservesExpression)
    return {"DoubleAvailableReserves" -> 
          doubleAvailableReservesExpression}
  }
}