Xplain.Db.QueryData

Xplain.Db.QueryData()

Xplain.Db.QueryData provides a set of methods to get data received from the Xplain backend. Represents data for ONE query, i.e. each query will have its own instance of Xplain.Db.QueryData.

NOTE: You should not need to directly instantiate an instance of this class. Instead, use the getResult() method of an Xplain.Db.Query which returns an instance of Xplain.Db.QueryData.

getCellValue

getCellValue(vector, measure)

Use this method to find a specific cell value within this queries result. Each cell is reference by A) a vector and B) a measure. The vector represents the values of the groupBys this query is using. For instance ["male", "20-30", "1"] would find and return the measure for the groupBys along attribute “Sex”, “Age” and “EGK”.

Parameters
  • vector (object|array) – The vector represents the values of the groupBys this query is using. You may define the vector as simple array, e.g. ["male", "20-30", "1"] or as an object, e.g. {Sex: "male", Age: "20-30", EGK: "1"}. If you use the array syntax, you have to define the order of the values within this array using the method setCellValueReferenceOrder().

  • measure (string) – The measure whose value you would like to get, e.g. “# Patients” or “SUM(costs)”.

Returns

{null|number} returns the value (i.e. number) or null if this cell does not exist.

getData

getData([settings])

returns the data that the corresponding query returned. Data format may be specified in the config.

Parameters
  • (optional) (function settings.preprocessor) – A set of key/value pairs that configure how you would like to get the data. All settings are optional. If this parameter is a string, then the string will be interpreted as the format. For instance, getData('original') is short for getData({format:'original'})

  • (optional) – Defines in which format you would like to receive the data. Currently, the following formats are supported: - table: an object will be returned that consists of two attributes: * columns an array of strings. A list of all columns. * data a two-dimensional array that consists of the data. Please note that a table always returns the data “flat”, even if they are actually hierarchical. If you work with hierarchically organized data, please use the type objectlist or original as format. - original: returns the data format exactly as received from the backend. Use this format if you want all the details. - objectlist: an array of objects. Each objects depicts the data of one row. Use this format if you want the data in an easy to read format and if your result contains hierarchically organized data. - extjschart: (!experimental feature!) returns an object that contains of a) the data in a format needed by an ExtJS charting component and b) an array named cartesian which contains the cartesian product of all state-names of all attributes which are listed in the parameter yAxes. If this format is being used, the options xAxis (the name of the attribute that stores the values which should go on the xAxis of the chart, e.g. “Years”), yAxes (an array of all names of the attributes which should go on the yAxis of the chart, e.g. [“AgeGroup”,”Gender”]) and value (the name of the attribute that stores the actual numeric value, e.g. “# Patients”) have to be set.

  • (optional) – An object of objects which will be used to format the data received. Currently, only format “table” uses an option: “includeRoot” defaults to true. If set to false, the root node will not be included in the resulting table. “includeTotal”: defaults to true. If set to false, neither the total (row) nor the the root node will be included.

  • (optional) – This function will be executed before getData() returns its results. Use this function to alter the data in any way you want. The blueprint of this function looks like this:: settings.preprocessor = function(inputData) { // format of inputData equals the format specified in the format option of getData(). for (var i=0; i<inputData.length; i++) { // do something here… } // again, the format of the output parameter has to be equal to the // format specified in the format option of getData() return inputData; } Furthermore, The output must contain all fields that are also contained in the input! preprocessor option my be used in all cases except getFormat() format option is set to original, which always returns the original data an never applies the preprocessor function.

Returns

{null|Array} The resulting data of this query in the requested format.

getFieldValues

getFieldValues([attrName])

Returns the fieldValues entry returned by the backend.

Parameters

(optional) (string attrName) – Name of the attribute for which you would like to get the fieldValues. array of objects. If no fieldValues have been returned by the backend, this method returns false.

Returns

{false|Array|Object} If the attrName param is set, this method will return an array of strings. If not set, this method will return an

getGroupByStates

getGroupByStates(attribute)

returns all targetStates of an attribute used in a groupBy statement. E.g. returns something like:

{
    attribute: "Sex",
       targetStates: [
         0: "male",
         1: "female",
         2: "null"
       ]
}

Warning

This method id deprecated! Use getGroupByStates instead.

Parameters

attribute (string|Xplain.Db.Attribute) – Name of the attribute or an instance of Xplain.Db.Attribute

Returns

{object} see example above

getGroupBysStates

getGroupBysStates()

returns all states of all attributes used in all groupBy stements. E.g. returns something like:

[{
   attribute: "Sex",
   targetStates: [
      0: "male",
      1: "female",
      2: "null"
   ]
 },
 {...}
]
Returns

{array} of Objects

getMeasures

getMeasures()

returns an array of measures used in this query. E.g. [”# Customers”, “SUM(Turnover)”]

Returns

{array} of strings

getTotal

getTotal([totalName])

Get all totals. If no total could be found, false will be returned. Otherwise an array of values (one total for each measure) will be returned.

Parameters

(optional) (string totalName) – The name of the total. Defaults to &nbsp;&nbsp;&nbsp;Total

Returns

{false|Array} all values of all measures for the total

includesUpperLevels

includesUpperLevels()

Checks if all groupyBys used in this query are set to includeUpperLevels == true. If so, this method returns true. Otherwise it returns false

Returns

{boolean} returns true if all groupyBys are set to includeUpperLevels == true

setCellValueReferenceOrder

setCellValueReferenceOrder(order)

The getCellValue() method enables you to reference a cell by an array of groupBy values, e.g. ["male", "20-30", "1"]. If you use this kind of annotation, you have to define the order of values in this array in advance. For instance, you have to define that ["male", "20-30", "1"] is in the order ["Sex", "Age", "EGK"].

Parameters

order (array) – The array that defines the order.