Xplain.Db.GroupBy

Xplain.Db.GroupBy(settings)

This class represents an Xplain groupBy. Use this class to define a groupBy which later on can be used within an Xplain.Db.Query.

The following example depicts how to use a GroupBy within a query. This would add a GroupBy along over attribute ATC in dimension Prescriptions (and object Patient). GroupByLevel is optional. As used in this example, the group by would take place over “ATC Level 2” of the corresponding attribute. includeUpperLevels is also optional. If true, upper levels (level above the level defined in groupByLevel) would be included.:

{
    attribute: "Patient.Prescriptions.ATC",
    includeUpperLevels: true,
    groupByLevel: "ATC Level 2"
}

A GroupBy is a query property - more details can be [found here](https://docs.xplain-data.de/xplaindoc/interfaces/xplainjs/xplainDb/Query.html).

getAttribute

getAttribute()

If metadata has already been fetched, i.e. if you already loaded a configuration, this method will return an instance of Xplain.Db.Attribute representing the attribute of this groupBy. If metadata has not been fetched yet, the name of the attribute of this groupBy will be returned.

Returns

attribute {Xplain.Db.Attribute|string} the attribute or name of the attribute

getAttributeAsObj

getAttributeAsObj()

Return this groupBy’s attribute as object with the keys object, dimension and attribute

Returns

attr {object, dimension, attribute} the attribute of this groupBy

getDimension

getDimension()

If metadata has already been fetched, i.e. if you already loaded a configuration, this method will return an instance of Xplain.Db.Dimension representing the dimension of this groupBy. If metadata has not been fetched yet, the name of the dimension of this groupBy will be returned.

Returns

dimension {Xplain.Db.Dimension|string} the dimension or name of the dimension

getGroupByLevel

getGroupByLevel()

Returns the Level on which the groupBy will be build as string.

Returns

lvl {string} the name of the level

getGroupByStates

getGroupByStates([implicitToo])

With a GroupBy you define the states along which data should be aggregated. You define these states either explicitly (using a “groupByStates”) or implicitly. This method returns all these states as array of strings. By default only the explicitly defined ones will be returned. If you set implicitToo to true, all implicitly defined states are also returned. For instance, if you have the following query:

var q = new Xplain.Db.Query({
    id: "myQuery",
    groupBys: [
        {
            attribute: "Person.Age.AgeGroup",
            includeUpperLevels: true,
            groupByLevel: 'Level 2'
        },
        {
            attribute: "Person.Gender.Gender",
            groupByStates: ["M", "F"],
            includeUpperLevels: true
        }
    ],
    aggregations: [{
        measure: "Person",
        id:"# Person",
        type: "COUNT"
    }]
});

After you executed or opened this query, the following statements will return the following data:

// fetch the two groupBys
var gp1 = q.getGroupBys().toArray()[0];
var gp2 = q.getGroupBys().toArray()[1];

// all explicitly defined states of gp1
// returns: []
var x11 = gp1.getGroupByStates();

// all explicitly or implicitly defined states of gp1
// returns ["0-5", "6-10", "11-15", ...]
var x12 = gp1.getGroupByStates(true);

// all explicitly defined states of gp2
// returns: ["M", "F"]
var x21 = gp2.getGroupByStates();

// all explicitly or implicitly defined states of gp1
// returns: ["M", "F"]
var x22 = gp2.getGroupByStates(true);
Parameters

(optional) (boolean implicitToo) – If false only explicitly defined states will be returned. Set to true to get all explicitly or implicitly defined states. Defaults to false.

Returns

states {Array} An array of strings that consists of all states comprised by this groupBy.

getId

getId()

return the ID of this GroupBy

Returns

ID {string}

getIncludeUpperLevels

getIncludeUpperLevels()

Getter for includeUpperLevels

Returns

includeUpperLevels {boolean} the value of includeUpperLevels

getObject

getObject()

If metadata has already been fetched, i.e. if you already loaded a configuration, this method will return an instance of Xplain.Db.Object representing the object of this groupBy. If metadata has not been fetched yet, the name of the object of this groupBy will be returned.

Returns

object {Xplain.Db.Object|string} the object or name of the object

toJson

toJson(q)

generates a part of the openQuery/executeQuery method the backend expects for this groupBy

Parameters

q (Xplain.Db.Query) – the corresponding query

Returns

{Object} an object representing this groupBy’s ajax request.

toString

toString()

converts this groupBy to a string which reflects the definition of this groupBy.

Returns

{string} the definition of this groupBy as string