Toggle menu

Simple Digest Example

Imagine that each history with labelc="binOperationsTask" represents one case where waste bins had to be delivered, repaired or replaced, and that an example history looks like this.

{
    "labela": "Bin Operations Task",
    "labelb": "3226-5911-2348-4316",
    "labelc": "binOperationsTask"
    "events": [{
            "pos": [1,5],
            "event": {
                "binTypes": {
                    "quantity": 1,
                    "charge": 35,
                    "binType": "Garden Waste 240L",
                    "serviceChannel": "online",
                    "whatPartLost": "",
                    "whyReplacing": "Stolen",
                    "whatPartStolen": "",
                    "binNameWithQty": "1x Garden Waste 240L",
                    "howDamaged": "",
                    "reviewed": true,
                    "typeRequired": "Replacement",
                    "displayCharge": "35",
                    "formattedBinType": "Garden waste"
                }
            }
        }, {
            "pos": [2,5],
            "event": {
                "binTypes": {
                    "quantity": 1,
                    "charge": 35,
                    "binType": "Residual 240L",
                    "serviceChannel": "online",
                    "whatPartLost": "",
                    "whyReplacing": "Stolen",
                    "whatPartStolen": "",
                    "binNameWithQty": "1x Residual 240L",
                    "howDamaged": "",
                    "reviewed": true,
                    "typeRequired": "Replacement",
                    "displayCharge": "35",
                    "formattedBinType": "Household waste"
                }
            }
        }, {
            "pos": [3,5],
            "event": {
                "binTypes": {
                    "quantity": 1,
                    "charge": 25,
                    "binType": "Recycling Blue With Inner Caddy 240L",
                    "serviceChannel": "online",
                    "whatPartLost": "The main bin and caddy",
                    "whyReplacing": "Lost",
                    "whatPartStolen": "",
                    "binNameWithQty": "1x Recycling Blue With Inner Caddy 240L",
                    "howDamaged": "",
                    "reviewed": true,
                    "typeRequired": "Replacement",
                    "displayCharge": "25",
                    "formattedBinType": "Recycling"
                }
            }
        }, {
            "pos": [4,5],
            "event": {
                "uprn": "100000057135",
                "private": false,
                "loc_location": {
                    "coordinates": [
                        "-1.590066",
                        "54.955294"
                    ],
                    "type": "Point"
                },
                "address": "5 St Edmunds Court, Sunderland Road, Gateshead",
                "slotSize": 1,
                "slotType": "Replacement",
                "serviceChannel": "online",
                "loc_lon": -1.590066,
                "loc_area": "Central",
                "assignedToCrew": "true",
                "postcode": "NE8 3PF",
                "description": "Form: [Order a replacement bin] submitted.",
                "loc_lat": 54.955294,
                "loc_ward": "BRIDGES",
                "taskDate": "2021-01-12",
                "caseSubType": "Replacement",
                "processType": "Replacement bins",
                "event": "Form Submission",
                "userRole": "PUBLIC"
            }
        }, {
            "pos": [5,5],
            "event": {
                "caseClosed": "true"
            }
            "timestamp": 1611916728263
        }
    ]
}

Events 1, 2, and 3 show the different bins that were replaced. Event 4 shows what was done with the bins and at which address. Event 5 shows the case being closed.

This simple example digester collects the final value of address and description. In the history above both of those fields are present in Event 4.

{
    "id": 1001,
    "method": "registerdigest",
    "params": {
        "name": "binaddress",
        "filter": {
            "AND": [
                {
                    "key": "labela",
                    "EQ": "Bin Operations Task"
                },
                {
                    "key": "labelc",
                    "EQ": "binOperationsTask"
                }
            ]
        },
        "columns": [
            {
                "name": "BusinessKey",
                "type": "varchar",
                "size": 50,
                "operation": "label",
                "key": "labelb"
            },
            {
                "name": "Description",
                "type": "varchar",
                "size": 50,
                "operation": "lastvalue",
                "key": "description"
            },
            {
                "name": "Address",
                "type": "varchar",
                "size": 250,
                "operation": "lastvalue",
                "key": "address"
            }
        ]
    }
}

The digest is called "binaddress" and it only considers histories that have labela="Bin Operations Task" and labelc="binOperationsTask". It keeps the business key from labelb in a column called "BusinessKey" and the last value from any fields called "description" and "address" in columns called "Description" and "Address". Registering the digester would create a new view in the database called "dh_binaddress_vw" and querying the view would get data like this.

-- have a look at the (simplified) bin addresses digest
SELECT *
FROM dh_binaddress_vw

PublicIDbusinesskeydescriptionaddress
20F05D46-FD09-41C0-B8DF-9A57ACBE2A5E"5114-4663-2318-2554""Form: [Additional Bins] submitted.""2 Carnforth Gardens, Beacon Lough, Gateshead"
21B11B34-A14D-4C60-AD78-9689DEB41A08"2935-0979-7631-4324""Form: [Additional Bins] submitted.""2 Carnforth Gardens, Beacon Lough, Gateshead"
B5687D8A-5C4B-47E4-83FC-FB02FD40E52B"4685-1401-9195-3015""Form: [Order a replacement bin] submitted.""3 Carnforth Gardens, Beacon Lough, Gateshead"
E7AD90D3-4DBD-4ED0-91E9-38461BC3DB64"5426-9429-3666-0236""Form: [Order a replacement bin] submitted.""3 Carnforth Gardens, Beacon Lough, Gateshead"
4772107B-EC61-4EA4-9FE4-6AF991FDCD78"4514-6770-8489-7020""Form: [Additional Bins] submitted.""6 Raylees Gardens, Dunston Hill, Gateshead"
2C720AEE-7905-49C5-B9CD-05B92CC254CD"6292-8744-1200-6828""Form: [Additional Bins] submitted.""6 Raylees Gardens, Dunston Hill, Gateshead"
53A48699-5382-42E5-B2E9-1F1378DCCEA3"2053-7118-5239-8177""Form: [Additional Bins] submitted.""10 Raylees Gardens, Dunston Hill, Gateshead"
B1E65AD3-0B81-4B7F-AA0F-7A5C076373F3"3716-2191-4905-4557""Form: [Additional Bins] submitted.""11 Raylees Gardens, Dunston Hill, Gateshead"
C7026430-3257-40C0-A104-E995BBEFE285"5820-9573-9713-4407""Form: [Additional Bins] submitted."    "11 Raylees Gardens, Dunston Hill, Gateshead"
Many rows omitted for clarity 

Bear in mind that this is test data so the repeated and clustered addresses are not a concern.

Last modified on November 18, 2022

Share this page

Facebook icon Twitter icon email icon

Print

print icon