Xplain.Db.Aggregation
- Xplain.Db.Aggregation(settings)
This class represents an Xplain aggregation. Use this class to define an aggregation which later on can be used within an
Xplain.Db.Query
.The following example depicts how to use an Aggregation within a query. This would aggregate the dimension
Patient.Costs
using the functionSUM
. Functions available areSUM
,AVG
,COUNT
,MIN
,MAX
,VAR
,COUNTDISTINCT
,COUNTENTITY
,VARP
,STDEV
,STDEVP
,FIRSTKEY
andQUANTILE
:var a = new Xplain.Db.Aggregation({ id: 'SUM(Costs)', measure: 'Patient.Costs', type: 'SUM' })
This would be another example for a valid aggregation with a more complex
type
:var a = new Xplain.Db.Aggregation({ measure: 'Patient.City.City', type: { name: 'COUNTDISTINCT', level: 'States' } })
Alternatively, an aggregation can also be constructed from a an object returned by the backend. E.g. you may also use the following syntax:
var a = new Xplain.Db.Aggregation({ aggregation: { aggregationName: "# Prescriptions", aggregationType: "COUNT", object: "Prescriptions", type: "COUNT" } });
An Aggregation is a query property - more details can be [found here](https://docs.xplain-data.de/xplaindoc/interfaces/xplainjs/xplainDb/Query.html).
getId
- getId()
return the ID of this Aggregation
- Returns
{string} the ID of this Aggregation
getLevel
- getLevel()
Returns the level of this aggregation (if level is set). A level may be set if you have a
COUNTDISTINCT
aggregation. @returns {string|boolean} the Name of the level orfalse
if no level is set.
getMeasure
- getMeasure([format])
returns the aggregation measure as object {object, dimension, attribute} or as string (in the form “object.dimension.attribute”)
- Parameters
(optional) (string format) – set this parameter to
string
if the attribute should be returned as string. Default =object
.- Returns
{object | string} the aggregation measure
getMeasureName
- getMeasureName()
returns the name, aka ID of this Aggregation (e.g. “# Patients” or “SUM(Costs)”)
- Returns
{string} the name of this Aggregation (e.g. “# Patients” or “SUM(Costs)”)
getType
- getType()
returns the current aggregation type, e.g. ‘COUNT’ or ‘MIN’. If type is
COUNTDISTINCT
, this method MAY return an object that consists of the a propertytype
and a propertylevel
, e.g. ‘{type:”COUNTDISTINCT”,level:”City”}’- Returns
{string|object} the aggregation type
getValidTypes
- getValidTypes()
returns an array of all valid aggregation types.
- Returns
{array} all valid aggregation types, e.g.
["SUM", "AVG", "COUNT", ``etc
]``.
setMeasure
- setMeasure(_measure)
set the aggregation measure. The measure has to be given either as string using the format
OBJECT.DIMENSION.ATTRIBUTE
orOBJECT.DIMENSION
orOBJECT
, or as object using the more verbose syntax{object: "o", dimension: "d", attribute: "a"}
- Parameters
_measure (string|object) – the aggregation measure either as string using the format
OBJECT.DIMENSION.ATTRIBUTE
(orOBJECT.DIMENSION
orOBJECT
) or an object using the more verbose syntax{object: "o", dimension: "d", attribute: "a"}
setType
- setType(_type)
set the aggregation type. You may simply want to pass the type as string, e.g. “SUM” or “COUNT”. Or pass the type as object which might consist of additional options. For instance, the
COUNTDISTINCT
type has options to define thelevel
(the name of the hierarchical level as string) and some distinctStates (an array of state names, or an array ofXplain.Db.State
instances). In this case, the type may look like this:{ name: "COUNTDISTINCT", level: "hierarchyLevel1", distinctStates: ["state1","state2","state3"] }
Valid aggregation types are
SUM
,AVG
,COUNT
,MIN
,MAX
,VAR
,COUNTDISTINCT
,COUNTENTITY
,VARP
,STDEV
,STDEVP
andFIRSTKEY
- Parameters
_type (string|object) – the aggregation type
toJson
- toJson(q)
generates the part of an openQuery/executeQuery method the backend expects for this aggregation
- Parameters
q (Xplain.Db.Query) – the corresponding query
- Returns
{Object} an object representing this aggregation’s ajax request.
toString
- toString()
converts this aggregation to a string which reflects the definition of this aggregation.
- Returns
{string} the definition of this aggregation as string