Skip to main content

Implementing %OnCompute()

Implementing %OnCompute()

For each pivot table cell where the plug-in is used, the plug-in performs either a DRILLTHROUGH or DRILLFACTS query (depending on the value of LISTINGSOURCE) and returns the fields specified by LISTINGFIELDS or %OnGetListingFields() (as applicable). It then passes the field values to the %OnCompute() method. This method has the following signature:

Method %OnCompute(pSQLRS As %SQL.StatementResult, pFactCount As %Integer) As %Status

Where:

In your implementation of this method, do the following:

  1. Iterate through the statement result. To do so, use the %Next() method of this instance.

  2. As needed, retrieve values for each row. The statement result instance (pSQLRS) provides one property for each field in the listing query; the name of the property is the same as the field name.

    For example, in the previous section, %OnGetListingFields() retrieves a single field, MxTextScore. In this case, pSQLRS has a property named MxTextScore.

  3. Perform the desired computations.

  4. Set the properties of the plug-in instance, as described in Defining Advanced KPIs. At a minimum, set the following properties:

    • %seriesCount — Specifies the number of series (rows) in this plug-in.

      InterSystems recommends that plug-ins have only one series. (For plug-ins with PLUGINTYPE equal to "Pivot", when a user drags and drops a plug-in property, the Analyzer uses only the first series.)

    • %seriesNames(n) — Specifies the name of the series n, where n is an integer.

    • %data(n,propname) — Specifies the value of the given property (propname), for the series n.

      The property name must exactly match the name of a <property> in the XData block.

For example:

 // place answer in KPI output
 set ..%seriesCount = 1
 set ..%seriesNames(1) = "PluginDemo"
 //set Count property of KPI -- just use received pFactCount
 set ..%data(1,"PatientCount") = pFactCount
 
 // iterate through result set to get HighScoreCount 
 set n = 0
 set highcount = 0
 while (pSQLRS.%Next()) {
   set n = n + 1

   set testscore = pSQLRS.MxTestScore
   if (testscore>95) {
     Set highcount = highcount + 1
  }
  if (pSQLRS.%SQLCODE < 0) {write "%Next failed:", !, "SQLCODE ", pSQLRS.%SQLCODE, ": ", pSQLRS.%Message quit}

 }
 set ..%data(1,"HighScoreCount") = highcount

This is an extract from the sample class BI.Model.KPIs.PluginDemo, which is available in the Analyzer for use with the Patients cube.

FeedbackOpens in a new tab