From ccd40a1e6f55c98aafb0608e70abd3d8f02ccde2 Mon Sep 17 00:00:00 2001 From: Pauline Date: Wed, 30 Jun 2021 16:25:11 +1000 Subject: [PATCH 01/14] psuh for biao to debug locally - not to merge --- ...stcodeOverlayReportConfig-modifies-data.js | 75 +++++ ...ntFeverOverlayFlutracking-modifies-data.js | 81 ++++++ packages/report-server/examples.http | 275 ++++++++++++++++-- .../src/reportBuilder/functions/basic.ts | 74 ++--- .../src/reportBuilder/functions/index.ts | 42 +-- .../src/reportBuilder/functions/math.ts | 45 ++- .../src/apiV1/measureBuilders/index.js | 1 + .../apiV1/measureBuilders/useReportServer.js | 14 + .../src/apiV1/measureData.js | 158 +++++----- .../export/requestFromTupaiaConfigServer.js | 5 +- 10 files changed, 607 insertions(+), 163 deletions(-) create mode 100644 packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js create mode 100644 packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js create mode 100644 packages/web-config-server/src/apiV1/measureBuilders/useReportServer.js diff --git a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js new file mode 100644 index 0000000000..3640133ecc --- /dev/null +++ b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js @@ -0,0 +1,75 @@ +'use strict'; + +import { generateId, insertObject } from '../utilities'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function (options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +const permissionGroupNameToId = async (db, name) => { + const record = await db.runSql(`SELECT id FROM permission_group WHERE name = '${name}'`); + return record.rows[0] && record.rows[0].id; +}; + +const REPORT = { + id: generateId(), + code: 'AU_Flutracking_Postcode_Percent_Report', + config: { + fetch: { + aggregations: [ + { + type: 'RAW', + config: { + dataSourceEntityType: 'postcode', + }, + }, + ], + dataElements: ['FWV_PC_004', 'FWV_PC_003'], + dataGroups: ['FP'], + }, + transform: [ + { + transform: 'select', + "'numerator'": '$row.FWV_PC_004', + "'denominator'": '$row.FWV_PC_003', + "'organisationUnitCode'": '$row.orgUnit', + }, + { + transform: 'aggregate', + numerator: 'sum', + denominator: 'sum', + organisationUnitCode: 'group', + }, + { + transform: 'select', + "'value'": 'divide($row.numerator, $row.denominator)', + '...': ['organisationUnitCode'], + }, + ], + }, +}; + +exports.up = async function (db) { + const permissionGroupId = await permissionGroupNameToId(db, 'Admin'); + await insertObject(db, 'report', { ...REPORT, permission_group_id: permissionGroupId }); +}; + +exports.down = async function (db) { + return db.runSql(` + DELETE FROM "report" WHERE code = '${REPORT.code}'; + `); +}; + +exports._meta = { + version: 1, +}; diff --git a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js new file mode 100644 index 0000000000..63f13bcdfa --- /dev/null +++ b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js @@ -0,0 +1,81 @@ +'use strict'; + +import { insertObject, generateId } from '../utilities'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function (options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +const MAP_OVERLAY = { + id: 'AU_Flutracking_Postcode_Fever_Percent', + name: '% fever and cough by postcode', + userGroup: 'Admin', + dataElementCode: 'value', + isDataRegional: true, + measureBuilder: 'useReportServer', + measureBuilderConfig: { + dataSourceType: 'custom', + reportCode: 'AU_Flutracking_Postcode_Percent_Report', + }, + presentationOptions: { + values: [{ color: 'grey', value: null }], + // displayType: 'icon', + // "measureLevel": "Postcode", + hideFromPopup: false, + scaleType: 'performance', + valueType: 'percentage', + scaleColorScheme: 'default', + type: 'shaded-spectrum', + hideFromMenu: false, + hideFromLegend: false, + }, + countryCodes: '{"AU"}', + projectCodes: '{covidau}', +}; + +const getMapOverlayGroupId = async function (db, code) { + const results = await db.runSql(`select "id" from "map_overlay_group" where "code" = '${code}';`); + + if (results.rows.length > 0) { + return results.rows[0].id; + } + + throw new Error('MapOverlayGroup not found'); +}; + +const mapOverlayGroupRelation = groupId => ({ + id: generateId(), + map_overlay_group_id: groupId, + child_id: MAP_OVERLAY.id, + child_type: 'mapOverlay', + sort_order: 0, +}); + +const MAP_OVERLAY_GROUP_CODE = 'Flutracking_Australia'; + +exports.up = async function (db) { + await insertObject(db, 'mapOverlay', MAP_OVERLAY); + const mapOverlayGroupId = await getMapOverlayGroupId(db, MAP_OVERLAY_GROUP_CODE); + await insertObject(db, 'map_overlay_group_relation', mapOverlayGroupRelation(mapOverlayGroupId)); +}; + +exports.down = function (db) { + return db.runSql(` + delete from "map_overlay_group_relation" where "child_id" = '${MAP_OVERLAY.id}'; + delete from "mapOverlay" where "id" = '${MAP_OVERLAY.id}'; + `); +}; + +exports._meta = { + version: 1, +}; diff --git a/packages/report-server/examples.http b/packages/report-server/examples.http index 0dfaa9c75a..493c5ea911 100644 --- a/packages/report-server/examples.http +++ b/packages/report-server/examples.http @@ -7,10 +7,19 @@ @authorization = Basic {{email}}:{{password}} ### Fetch PSSS Weekly Report -GET {{baseUrl}}/fetchReport/PSSS_Weekly_Report?organisationUnitCodes=TO&hierarchy=psss&period=2020 HTTP/1.1 +GET {{baseUrl}}/fetchReport/AU_Flutracking_Postcode_Percent_Report?organisationUnitCodes=AU&hierarchy=covidau HTTP/1.1 content-type: {{contentType}} Authorization: {{authorization}} +# STRIVE_FIS_Village_Percent_mRDT_Positive_Mixed_In_Week -map overlay id +# "value": 0.5117647058823529 // format this into percent * 100 +# organisationUnitCode: "postcode_code" + +# FWV_PC_003 Total number of participants +# FWV_PC_004 Number of participants with fever and cough +# 1400: Strive Lab Confirmed Positive Results Bar Chart #2624 +# https://github.com/beyondessential/tupaia/pull/2624/files + ### Fetch Report With Test Config POST {{baseUrl}}/testFetchReport/xx?organisationUnitCodes=TO&hierarchy=psss&period=2020 HTTP/1.1 content-type: {{contentType}} @@ -20,43 +29,247 @@ Authorization: {{authorization}} "testConfig": { "fetch": { "dataElements": [ - "BCD46", - "BCD47", - "BCD48", - "BCD48a", - "BCD48b", - "BCD49", - "BCD50", - "BCD50", - "BCD51", - "BCD52", - "BCD53", - "BCD54", - "BCD55" + "FWV_PC_004", + "FWV_PC_003" ], - "aggregations": ["MOST_RECENT"] + "aggregations": ["RAW"] }, "transform": [ - "keyValueByDataElementName", { - "transform": "select", - "'Doctors'": "$row.BCD46", - "'Midwives'": "$row.BCD47", - "'Nurses'": "sum([$row.BCD48, $row.BCD48a, $row.BCD48b])", - "'Aides'": "$row.BCD49", - "'Others'": "sum([$row.BCD50, $row.BCD51, $row.BCD52, $row.BCD53, $row.BCD54, $row.BCD55])", - "...": ["period", "organisationUnit"] + "transform": "select", + "'numerator'": "$row.FWV_PC_004", + "'denominator'": "$row.FWV_PC_003", + "'organisationUnitCode'": "$row.orgUnit" }, { "transform": "aggregate", - "organisationUnit": "group", - "period": "group", - "Doctors": "sum", - "Midwives": "sum", - "Nurses": "sum", - "Aides": "sum", - "Others": "sum" + "numerator": "sum", + "denominator": "sum", + "organisationUnitCode": "group" + }, + { + "transform": "select", + "'value'": "divide($row.numerator, $row.denominator)", + "...": ["organisationUnitCode"] } ] - } + }, + "testData": [ + { + "FWV_PC_004":0, + "FWV_PC_003":2, + "event":"60dbcb1b813f432699004d66", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NT_0875", + "orgUnitName":"0875" + }, + { + "FWV_PC_004":2, + "FWV_PC_003":186, + "event":"60dbcb1b813f432699004d45", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NT_0870", + "orgUnitName":"0870" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":1, + "event":"60dbcb1b813f432699004cfd", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NT_0846", + "orgUnitName":"0846" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":24, + "event":"60dbcb1b813f432699004c6a", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NT_0822", + "orgUnitName":"0822" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":1, + "event":"60dbcb1b813f432699004ccb", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NT_0837", + "orgUnitName":"0837" + }, + { + "FWV_PC_004":1, + "FWV_PC_003":65, + "event":"60dbcb1b813f4326990065db", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_ACT_2903", + "orgUnitName":"2903" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":24, + "event":"60dbcb1b813f4326990057fa", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2319", + "orgUnitName":"2319" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":5, + "event":"60dbcb1b813f4326990064ad", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2835", + "orgUnitName":"2835" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":4, + "event":"60dbcb1b813f432699008277", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_QLD_4346", + "orgUnitName":"4346" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":16, + "event":"60dbcb1b813f432699005547", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2220", + "orgUnitName":"2220" + }, + { + "FWV_PC_003":3, + "FWV_PC_004":0, + "event":"60dbcb1b813f4326990064cd", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2842", + "orgUnitName":"2842" + }, + { + "FWV_PC_003":2, + "FWV_PC_004":0, + "event":"60dbcb1b813f4326990064c3", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2840", + "orgUnitName":"2840" + }, + { + "FWV_PC_003":324, + "FWV_PC_004":4, + "event":"60dbcb1b813f432699005f66", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_ACT_2615", + "orgUnitName":"2615" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":16, + "event":"60dbcb1b813f432699005d1b", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2535", + "orgUnitName":"2535" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":1, + "event":"60dbcb1b813f432699007454", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_VIC_3584", + "orgUnitName":"3584" + }, + { + "FWV_PC_003":7, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699005b68", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2463", + "orgUnitName":"2463" + }, + { + "FWV_PC_003":11, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699007ead", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_QLD_4112", + "orgUnitName":"4112" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":7, + "event":"60dbcb1b813f432699006304", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2776", + "orgUnitName":"2776" + }, + { + "FWV_PC_003":11, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699005e62", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2578", + "orgUnitName":"2578" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":49, + "event":"60dbcb1b813f432699006b4f", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_VIC_3141", + "orgUnitName":"3141" + }, + { + "FWV_PC_003":30, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699006649", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_VIC_3003", + "orgUnitName":"3003" + }, + { + "FWV_PC_003":67, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699004f1b", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_NSW_2042", + "orgUnitName":"2042" + }, + { + "FWV_PC_003":26, + "FWV_PC_004":0, + "event":"60dbcb1b813f43269900802d", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_QLD_4169", + "orgUnitName":"4169" + }, + { + "FWV_PC_003":13, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699006767", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_VIC_3034", + "orgUnitName":"3034" + }, + { + "FWV_PC_003":7, + "FWV_PC_004":0, + "event":"60dbcb1b813f432699007e7c", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_QLD_4107", + "orgUnitName":"4107" + }, + { + "FWV_PC_004":0, + "FWV_PC_003":1, + "event":"60dbcb1b813f432699007b97", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_VIC_3951", + "orgUnitName":"3951" + }, + { + "FWV_PC_003":1, + "FWV_PC_004":0, + "event":"60dbcb1b813f4326990068fb", + "eventDate":"2020-02-23T00:00:00", + "orgUnit":"AU_VIC_3075", + "orgUnitName":"3075" + } + ] } diff --git a/packages/report-server/src/reportBuilder/functions/basic.ts b/packages/report-server/src/reportBuilder/functions/basic.ts index ad53f09e50..657e4aed70 100644 --- a/packages/report-server/src/reportBuilder/functions/basic.ts +++ b/packages/report-server/src/reportBuilder/functions/basic.ts @@ -3,40 +3,40 @@ * Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd */ -import { FieldValue } from '../types'; - -export const value = (valueGiven: FieldValue): FieldValue => { - return valueGiven; -}; - -export const last = (values: FieldValue[]): FieldValue => { - if (!Array.isArray(values)) { - throw new Error(`Function 'last' expected an array, but got: ${values}`); - } - - if (values.length < 1) { - return undefined; - } - - return values[values.length - 1]; -}; - -export const eq = (value1, value2): boolean => { - return value1 === value2; -}; - -export const notEq = (value1, value2): boolean => { - return value1 !== value2; -}; - -export const gt = (value1, value2): boolean => { - return value1 > value2; -}; - -export const exists = (value: FieldValue): boolean => { - return value !== undefined; -}; - -export const notExists = (value: FieldValue): boolean => { - return value === undefined; -}; + import { FieldValue } from '../types'; + + export const value = (valueGiven: FieldValue): FieldValue => { + return valueGiven; + }; + + export const last = (values: FieldValue[]): FieldValue => { + if (!Array.isArray(values)) { + throw new Error(`Function 'last' expected an array, but got: ${values}`); + } + + if (values.length < 1) { + return undefined; + } + + return values[values.length - 1]; + }; + + export const eq = (val1: any, val2: any): boolean => { + return val1 === val2; + }; + + export const notEq = (val1: any, val2: any): boolean => { + return val1 !== val2; + }; + + export const gt = (val1: any, val2: any): boolean => { + return val1 > val2; + }; + + export const exists = (val: any): boolean => { + return val !== undefined; + }; + + export const notExists = (val: FieldValue): boolean => { + return val === undefined; + }; \ No newline at end of file diff --git a/packages/report-server/src/reportBuilder/functions/index.ts b/packages/report-server/src/reportBuilder/functions/index.ts index bf266d9e40..aab2f68f8f 100644 --- a/packages/report-server/src/reportBuilder/functions/index.ts +++ b/packages/report-server/src/reportBuilder/functions/index.ts @@ -3,21 +3,27 @@ * Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd */ -import { value, last, eq, notEq, exists, notExists, gt } from './basic'; -import { convertToPeriod, dateStringToPeriod, periodToTimestamp, periodToDisplayString } from './utils'; -import { sum } from './math'; - -export const functions = { - value, - last, - sum, - eq, - notEq, - gt, - exists, - notExists, - convertToPeriod, - dateStringToPeriod, - periodToTimestamp, - periodToDisplayString, -}; + import { value, last, eq, notEq, exists, notExists, gt } from './basic'; + import { + convertToPeriod, + dateStringToPeriod, + periodToTimestamp, + periodToDisplayString, + } from './utils'; + import { sum, divide } from './math'; + + export const functions = { + value, + last, + eq, + notEq, + gt, + exists, + notExists, + convertToPeriod, + dateStringToPeriod, + periodToTimestamp, + periodToDisplayString, + sum, + divide, + }; \ No newline at end of file diff --git a/packages/report-server/src/reportBuilder/functions/math.ts b/packages/report-server/src/reportBuilder/functions/math.ts index 3f576ac117..bb726809fe 100644 --- a/packages/report-server/src/reportBuilder/functions/math.ts +++ b/packages/report-server/src/reportBuilder/functions/math.ts @@ -3,12 +3,41 @@ * Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd */ -import { sum as mathjsSum, Matrix, filter } from 'mathjs'; + import { sum as mathjsSum, divide as mathjsDivide } from 'mathjs'; -export const sum = (numbers?: Matrix): number | undefined => { - if (numbers === undefined) { - return undefined; - } - - return mathjsSum(filter(numbers, number => number !== undefined)); -}; + const isDefined = (value: T): value is Exclude => value !== undefined; + + export const sum = ( + ...args: (number | undefined | (number | undefined)[])[] + ): number | undefined => { + const numbers = args.flat(); + const validNumbers = numbers.filter(isDefined); + + if (validNumbers.length === 0) { + return undefined; + } + + return mathjsSum(validNumbers); + }; + + export const divide = ( + ...args: (number | undefined | (number | undefined)[])[] + ): number | undefined => { + const numbers = args.flat(); + + if (numbers.some(number => !isDefined(number))) { + return undefined; + } + + const validNumbers = numbers.filter(isDefined); + + if (validNumbers.length === 0) { + return undefined; + } + + if (validNumbers.length === 1) { + return validNumbers[0]; + } + + return validNumbers.reduce((numerator, denominator) => mathjsDivide(numerator, denominator)); + }; \ No newline at end of file diff --git a/packages/web-config-server/src/apiV1/measureBuilders/index.js b/packages/web-config-server/src/apiV1/measureBuilders/index.js index 54767e9ae5..789511bcf1 100644 --- a/packages/web-config-server/src/apiV1/measureBuilders/index.js +++ b/packages/web-config-server/src/apiV1/measureBuilders/index.js @@ -11,3 +11,4 @@ export { groupData } from './groupData'; export { getStringsFromBinaryData } from './getStringsFromBinaryData'; export { selectUniqueValueFromEventsPerOrgUnit } from './selectUniqueValueFromEventsPerOrgUnit'; export { checkMultiConditionsByOrgUnit } from './checkMultiConditionsByOrgUnit'; +export { useReportServer } from './useReportServer'; diff --git a/packages/web-config-server/src/apiV1/measureBuilders/useReportServer.js b/packages/web-config-server/src/apiV1/measureBuilders/useReportServer.js new file mode 100644 index 0000000000..1b24c27ecb --- /dev/null +++ b/packages/web-config-server/src/apiV1/measureBuilders/useReportServer.js @@ -0,0 +1,14 @@ +import { ReportServerBuilder } from '/apiV1/dataBuilders/generic/reportServer/reportServerDataBuilder'; + +export const useReportServer = async ( + models, + aggregator, + dhisApi, + query, + measureBuilderConfig = {}, + entity, + req, +) => { + const builder = new ReportServerBuilder(req, models, measureBuilderConfig, query, entity); + return builder.build(); +}; diff --git a/packages/web-config-server/src/apiV1/measureData.js b/packages/web-config-server/src/apiV1/measureData.js index 6071bbd8c2..05c15f09a6 100644 --- a/packages/web-config-server/src/apiV1/measureData.js +++ b/packages/web-config-server/src/apiV1/measureData.js @@ -7,6 +7,9 @@ import { getDateRange, getAggregatePeriod } from './utils'; import { DataAggregatingRouteHandler } from './DataAggregatingRouteHandler'; import { MapOverlayPermissionsChecker } from './permissions'; import { DATA_SOURCE_TYPES } from './dataBuilders/dataSourceTypes'; +import { response } from 'express'; + +const ADD_TO_ALL_KEY = '$all'; // NOTE: does not allow for actual number value measure, will be added when // all binary are added as optionSet @@ -34,14 +37,58 @@ const accessDeniedForMeasure = { }, }; -const buildMeasureData = (overlays, measureDataResponsesByMeasureId) => { +/* Data arrives as an array of responses (one for each measure) containing an array of org + * units. We need to rearrange it so that it's a 1D array of objects with the values + * assigned to the appropriate keys, and replace the keys with the ids of the overlay + * they came from (this is to avoid duplicate 'value' keys which causes a bug) + * + * measureDataResponsesByMeasureId: { + * measure_id_1: { + * data: [ + * { organisationUnitCode: 'OrgA', measureZ: 0 }, + * { organisationUnitCode: 'OrgB', measureZ: 1 }, + * ], + * period: { + * latestAvailable: '20200301', + * earliestAvailable: '20190501', + * requested: '201901;201902;201903...', + * } + * } + * measure_id_2: { + * data: [ + * { organisationUnitCode: 'OrgA', measureY: 100 }, + * { organisationUnitCode: 'OrgB', measureY: -100 }, + * ], + * period: { + * latestAvailable: '20200401', + * earliestAvailable: '20190501', + * requested: '201901;201902;201903...', + * } + * } + * } + * + * measureData: [ + * { organisationUnitCode: 'OrgA', measure_id_2: 100, measure_id_1: 0 }, + * { organisationUnitCode: 'OrgB', measure_id_2: -100, measure_id_1: 1 }, + * ] + * period: { + * latestAvailable: '20200401', + * earliestAvailable: '20190501', + * requested: '201901;201902;201903...', + * } + */ +const buildMeasureData = (overlays, resultData) => { + const measureDataResponsesByMeasureId = resultData.reduce((dataResponse, current) => ({ + ...dataResponse, + ...current, + })); const measureDataResponses = overlays.map(({ id, dataElementCode }) => { - const { data: measureDataResponse } = measureDataResponsesByMeasureId[id]; - measureDataResponse.forEach(obj => { - obj[id] = obj[dataElementCode]; - delete obj[dataElementCode]; + const { data } = measureDataResponsesByMeasureId[id]; + + return data.map(obj => { + const { [dataElementCode]: value, ...restData } = obj; + return { [id]: value, ...restData }; }); - return measureDataResponse; }); /** @@ -73,7 +120,7 @@ const buildMeasureData = (overlays, measureDataResponsesByMeasureId) => { }); return { - data: Object.values(measureDataByOrgUnit), + measureData: Object.values(measureDataByOrgUnit), period: getAggregatePeriod( Object.values(measureDataResponsesByMeasureId).map(({ period }) => period), ), @@ -152,69 +199,14 @@ export default class extends DataAggregatingRouteHandler { } }), ); - - // start fetching options - const optionsTasks = overlays.map(o => this.fetchMeasureOptions(o, this.query)); // start fetching actual data const shouldFetchSiblings = this.query.shouldShowAllParentCountryResults === 'true'; - const dataTasks = overlays.map(o => this.fetchMeasureData(o, shouldFetchSiblings)); - - // wait for fetches to complete - const measureOptions = await Promise.all(optionsTasks); - const measureDataResponsesByMeasureId = ( - await Promise.all(dataTasks) - ).reduce((dataResponse, current) => ({ ...dataResponse, ...current })); - - /* Data arrives as an array of responses (one for each measure) containing an array of org - * units. We need to rearrange it so that it's a 1D array of objects with the values - * assigned to the appropriate keys, and replace the keys with the ids of the overlay - * they came from (this is to avoid duplicate 'value' keys which causes a bug) - * - * measureDataResponsesByMeasureId: { - * measure_id_1: { - * data: [ - * { organisationUnitCode: 'OrgA', measureZ: 0 }, - * { organisationUnitCode: 'OrgB', measureZ: 1 }, - * ], - * period: { - * latestAvailable: '20200301', - * earliestAvailable: '20190501', - * requested: '201901;201902;201903...', - * } - * } - * measure_id_2: { - * data: [ - * { organisationUnitCode: 'OrgA', measureY: 100 }, - * { organisationUnitCode: 'OrgB', measureY: -100 }, - * ], - * period: { - * latestAvailable: '20200401', - * earliestAvailable: '20190501', - * requested: '201901;201902;201903...', - * } - * } - * } - * - * measureData: [ - * { organisationUnitCode: 'OrgA', measure_id_2: 100, measure_id_1: 0 }, - * { organisationUnitCode: 'OrgB', measure_id_2: -100, measure_id_1: 1 }, - * ] - * period: { - * latestAvailable: '20200401', - * earliestAvailable: '20190501', - * requested: '201901;201902;201903...', - * } - */ - - const { period, data: measureData } = buildMeasureData( - overlays, - measureDataResponsesByMeasureId, + const responseData = await Promise.all( + overlays.map(o => this.fetchMeasureData(o, shouldFetchSiblings)), ); - - measureOptions - .filter(mo => mo.displayedValueKey) - .filter(mo => !mo.disableRenameLegend) - .map(mo => updateLegendFromDisplayedValueKey(mo, measureData)); + console.log(responseData); + const { period, measureData } = buildMeasureData(overlays, responseData); + const measureOptions = await this.fetchMeasureOptions(overlays, measureData); return { measureId: overlays @@ -229,7 +221,36 @@ export default class extends DataAggregatingRouteHandler { }; }; - async fetchMeasureOptions(mapOverlay) { + async fetchMeasureOptions(mapOverlays, measureData) { + const measureOptions = await Promise.all(mapOverlays.map(o => this.fetchMeasureOption(o))); + measureOptions + .filter(mo => mo.displayedValueKey) + .filter(mo => !mo.disableRenameLegend) + .map(mo => updateLegendFromDisplayedValueKey(mo, measureData)); + + const getOtherMeasureOptionKeys = mainMeasureOptionKey => { + const otherLinkMeasureKeySet = new Set(); + measureData.forEach(data => { + Object.keys(data).forEach(key => otherLinkMeasureKeySet.add(key)); + }); + otherLinkMeasureKeySet.delete('organisationUnitCode'); + otherLinkMeasureKeySet.delete(mainMeasureOptionKey); + return Array.from(otherLinkMeasureKeySet); + }; + + // Config 'measureConfig' only works for report server builder + const { measureConfig, ...mainMeasureOption } = measureOptions[0]; + if (measureConfig) { + const { [ADD_TO_ALL_KEY]: configForAllKeys, ...restOfConfig } = measureConfig; + getOtherMeasureOptionKeys(mainMeasureOption.key).forEach(key => { + measureOptions.push({ ...configForAllKeys, key, name: key, ...restOfConfig[key] }); + }); + measureOptions[0] = mainMeasureOption; + } + return measureOptions; + } + + async fetchMeasureOption(mapOverlay) { const { id, groupName, @@ -337,6 +358,7 @@ export default class extends DataAggregatingRouteHandler { { ...this.query, dataElementCode }, { ...measureBuilderConfig, dataServices }, entity, + this.req, ); } } diff --git a/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js b/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js index 11bc5f1884..e291ed7b25 100644 --- a/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js +++ b/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js @@ -23,7 +23,10 @@ export const requestFromTupaiaConfigServer = async ( const headers = { cookie: `${sessionCookieName}=${sessionCookie}`, }; - + console.log( + '@TODO DELETE', + `${BASE_URL}/${endpoint}${queryParametersToString(queryParameters)}`, + ); const response = await fetchWithTimeout( `${BASE_URL}/${endpoint}${queryParametersToString(queryParameters)}`, { headers }, From bb726b7ab9ef1220d8968a531333f53a45263bdc Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 11:44:22 +1000 Subject: [PATCH 02/14] commit but do not merge --- ...codePercentFeverOverlayFlutracking-modifies-data.js | 10 ++++++++++ packages/report-server/examples.http | 2 ++ 2 files changed, 12 insertions(+) diff --git a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js index 63f13bcdfa..7e9985d529 100644 --- a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js +++ b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js @@ -38,6 +38,16 @@ const MAP_OVERLAY = { type: 'shaded-spectrum', hideFromMenu: false, hideFromLegend: false, + “scaleBounds”: { + “left”: { + “max”: 0, + “min”: 0 + }, + “right”: { + “max”: 1, + “min”: 1 + } + } }, countryCodes: '{"AU"}', projectCodes: '{covidau}', diff --git a/packages/report-server/examples.http b/packages/report-server/examples.http index 493c5ea911..93da58c72c 100644 --- a/packages/report-server/examples.http +++ b/packages/report-server/examples.http @@ -19,6 +19,8 @@ Authorization: {{authorization}} # FWV_PC_004 Number of participants with fever and cough # 1400: Strive Lab Confirmed Positive Results Bar Chart #2624 # https://github.com/beyondessential/tupaia/pull/2624/files +# 2911&2346 create overlays with report servers #2681 +# https://github.com/beyondessential/tupaia/pull/2681/files ### Fetch Report With Test Config POST {{baseUrl}}/testFetchReport/xx?organisationUnitCodes=TO&hierarchy=psss&period=2020 HTTP/1.1 From 2be758d22efd1ae3a6d75294be3531716a3ba4a7 Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 11:49:34 +1000 Subject: [PATCH 03/14] Update examples.http --- packages/report-server/examples.http | 279 +++------------------------ 1 file changed, 32 insertions(+), 247 deletions(-) diff --git a/packages/report-server/examples.http b/packages/report-server/examples.http index 93da58c72c..8e949402d7 100644 --- a/packages/report-server/examples.http +++ b/packages/report-server/examples.http @@ -7,21 +7,10 @@ @authorization = Basic {{email}}:{{password}} ### Fetch PSSS Weekly Report -GET {{baseUrl}}/fetchReport/AU_Flutracking_Postcode_Percent_Report?organisationUnitCodes=AU&hierarchy=covidau HTTP/1.1 +GET {{baseUrl}}/fetchReport/PSSS_Weekly_Report?organisationUnitCodes=TO&hierarchy=psss&period=2020 HTTP/1.1 content-type: {{contentType}} Authorization: {{authorization}} -# STRIVE_FIS_Village_Percent_mRDT_Positive_Mixed_In_Week -map overlay id -# "value": 0.5117647058823529 // format this into percent * 100 -# organisationUnitCode: "postcode_code" - -# FWV_PC_003 Total number of participants -# FWV_PC_004 Number of participants with fever and cough -# 1400: Strive Lab Confirmed Positive Results Bar Chart #2624 -# https://github.com/beyondessential/tupaia/pull/2624/files -# 2911&2346 create overlays with report servers #2681 -# https://github.com/beyondessential/tupaia/pull/2681/files - ### Fetch Report With Test Config POST {{baseUrl}}/testFetchReport/xx?organisationUnitCodes=TO&hierarchy=psss&period=2020 HTTP/1.1 content-type: {{contentType}} @@ -31,247 +20,43 @@ Authorization: {{authorization}} "testConfig": { "fetch": { "dataElements": [ - "FWV_PC_004", - "FWV_PC_003" + "BCD46", + "BCD47", + "BCD48", + "BCD48a", + "BCD48b", + "BCD49", + "BCD50", + "BCD50", + "BCD51", + "BCD52", + "BCD53", + "BCD54", + "BCD55" ], - "aggregations": ["RAW"] + "aggregations": ["MOST_RECENT"] }, "transform": [ + "keyValueByDataElementName", { - "transform": "select", - "'numerator'": "$row.FWV_PC_004", - "'denominator'": "$row.FWV_PC_003", - "'organisationUnitCode'": "$row.orgUnit" + "transform": "select", + "'Doctors'": "$row.BCD46", + "'Midwives'": "$row.BCD47", + "'Nurses'": "sum([$row.BCD48, $row.BCD48a, $row.BCD48b])", + "'Aides'": "$row.BCD49", + "'Others'": "sum([$row.BCD50, $row.BCD51, $row.BCD52, $row.BCD53, $row.BCD54, $row.BCD55])", + "...": ["period", "organisationUnit"] }, { "transform": "aggregate", - "numerator": "sum", - "denominator": "sum", - "organisationUnitCode": "group" - }, - { - "transform": "select", - "'value'": "divide($row.numerator, $row.denominator)", - "...": ["organisationUnitCode"] + "organisationUnit": "group", + "period": "group", + "Doctors": "sum", + "Midwives": "sum", + "Nurses": "sum", + "Aides": "sum", + "Others": "sum" } ] - }, - "testData": [ - { - "FWV_PC_004":0, - "FWV_PC_003":2, - "event":"60dbcb1b813f432699004d66", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NT_0875", - "orgUnitName":"0875" - }, - { - "FWV_PC_004":2, - "FWV_PC_003":186, - "event":"60dbcb1b813f432699004d45", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NT_0870", - "orgUnitName":"0870" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":1, - "event":"60dbcb1b813f432699004cfd", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NT_0846", - "orgUnitName":"0846" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":24, - "event":"60dbcb1b813f432699004c6a", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NT_0822", - "orgUnitName":"0822" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":1, - "event":"60dbcb1b813f432699004ccb", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NT_0837", - "orgUnitName":"0837" - }, - { - "FWV_PC_004":1, - "FWV_PC_003":65, - "event":"60dbcb1b813f4326990065db", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_ACT_2903", - "orgUnitName":"2903" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":24, - "event":"60dbcb1b813f4326990057fa", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2319", - "orgUnitName":"2319" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":5, - "event":"60dbcb1b813f4326990064ad", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2835", - "orgUnitName":"2835" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":4, - "event":"60dbcb1b813f432699008277", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_QLD_4346", - "orgUnitName":"4346" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":16, - "event":"60dbcb1b813f432699005547", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2220", - "orgUnitName":"2220" - }, - { - "FWV_PC_003":3, - "FWV_PC_004":0, - "event":"60dbcb1b813f4326990064cd", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2842", - "orgUnitName":"2842" - }, - { - "FWV_PC_003":2, - "FWV_PC_004":0, - "event":"60dbcb1b813f4326990064c3", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2840", - "orgUnitName":"2840" - }, - { - "FWV_PC_003":324, - "FWV_PC_004":4, - "event":"60dbcb1b813f432699005f66", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_ACT_2615", - "orgUnitName":"2615" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":16, - "event":"60dbcb1b813f432699005d1b", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2535", - "orgUnitName":"2535" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":1, - "event":"60dbcb1b813f432699007454", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_VIC_3584", - "orgUnitName":"3584" - }, - { - "FWV_PC_003":7, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699005b68", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2463", - "orgUnitName":"2463" - }, - { - "FWV_PC_003":11, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699007ead", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_QLD_4112", - "orgUnitName":"4112" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":7, - "event":"60dbcb1b813f432699006304", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2776", - "orgUnitName":"2776" - }, - { - "FWV_PC_003":11, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699005e62", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2578", - "orgUnitName":"2578" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":49, - "event":"60dbcb1b813f432699006b4f", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_VIC_3141", - "orgUnitName":"3141" - }, - { - "FWV_PC_003":30, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699006649", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_VIC_3003", - "orgUnitName":"3003" - }, - { - "FWV_PC_003":67, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699004f1b", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_NSW_2042", - "orgUnitName":"2042" - }, - { - "FWV_PC_003":26, - "FWV_PC_004":0, - "event":"60dbcb1b813f43269900802d", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_QLD_4169", - "orgUnitName":"4169" - }, - { - "FWV_PC_003":13, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699006767", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_VIC_3034", - "orgUnitName":"3034" - }, - { - "FWV_PC_003":7, - "FWV_PC_004":0, - "event":"60dbcb1b813f432699007e7c", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_QLD_4107", - "orgUnitName":"4107" - }, - { - "FWV_PC_004":0, - "FWV_PC_003":1, - "event":"60dbcb1b813f432699007b97", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_VIC_3951", - "orgUnitName":"3951" - }, - { - "FWV_PC_003":1, - "FWV_PC_004":0, - "event":"60dbcb1b813f4326990068fb", - "eventDate":"2020-02-23T00:00:00", - "orgUnit":"AU_VIC_3075", - "orgUnitName":"3075" - } - ] -} + } +} \ No newline at end of file From c90713fa8cd3342bf2b586266b143c21b20e1bdf Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 12:13:58 +1000 Subject: [PATCH 04/14] Update requestFromTupaiaConfigServer.js --- .../src/export/requestFromTupaiaConfigServer.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js b/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js index e291ed7b25..832f87f6e6 100644 --- a/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js +++ b/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js @@ -23,10 +23,6 @@ export const requestFromTupaiaConfigServer = async ( const headers = { cookie: `${sessionCookieName}=${sessionCookie}`, }; - console.log( - '@TODO DELETE', - `${BASE_URL}/${endpoint}${queryParametersToString(queryParameters)}`, - ); const response = await fetchWithTimeout( `${BASE_URL}/${endpoint}${queryParametersToString(queryParameters)}`, { headers }, From 2eeeeb07d456247a1d18d88592d9fc3864d25439 Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 12:45:22 +1000 Subject: [PATCH 05/14] Update requestFromTupaiaConfigServer.js --- .../src/export/requestFromTupaiaConfigServer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js b/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js index 832f87f6e6..11bc5f1884 100644 --- a/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js +++ b/packages/web-config-server/src/export/requestFromTupaiaConfigServer.js @@ -23,6 +23,7 @@ export const requestFromTupaiaConfigServer = async ( const headers = { cookie: `${sessionCookieName}=${sessionCookie}`, }; + const response = await fetchWithTimeout( `${BASE_URL}/${endpoint}${queryParametersToString(queryParameters)}`, { headers }, From e217f4f5b493349f9febdee08d2e7ed93a4e7d41 Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 12:48:11 +1000 Subject: [PATCH 06/14] Update measureData.js --- packages/web-config-server/src/apiV1/measureData.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/web-config-server/src/apiV1/measureData.js b/packages/web-config-server/src/apiV1/measureData.js index 56799b68c7..2798bf9397 100644 --- a/packages/web-config-server/src/apiV1/measureData.js +++ b/packages/web-config-server/src/apiV1/measureData.js @@ -7,9 +7,6 @@ import { getDateRange, getAggregatePeriod } from './utils'; import { DataAggregatingRouteHandler } from './DataAggregatingRouteHandler'; import { MapOverlayPermissionsChecker } from './permissions'; import { DATA_SOURCE_TYPES } from './dataBuilders/dataSourceTypes'; -import { response } from 'express'; - -const ADD_TO_ALL_KEY = '$all'; const ADD_TO_ALL_KEY = '$all'; From a4441fcf035d99a1fdbb1c5c87f92a3277924c2a Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 12:48:40 +1000 Subject: [PATCH 07/14] Update index.ts --- packages/report-server/src/reportBuilder/functions/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/report-server/src/reportBuilder/functions/index.ts b/packages/report-server/src/reportBuilder/functions/index.ts index 88f0fa1021..b91df29b01 100644 --- a/packages/report-server/src/reportBuilder/functions/index.ts +++ b/packages/report-server/src/reportBuilder/functions/index.ts @@ -27,6 +27,5 @@ export const functions = { periodToDisplayString, sum, divide, - formatAsFractionAndPercentage, - divide + formatAsFractionAndPercentage }; From 0e414fca12bbe57b01e5648482906f051c54e213 Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 12:48:59 +1000 Subject: [PATCH 08/14] Update index.ts --- packages/report-server/src/reportBuilder/functions/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/report-server/src/reportBuilder/functions/index.ts b/packages/report-server/src/reportBuilder/functions/index.ts index b91df29b01..166aa02da6 100644 --- a/packages/report-server/src/reportBuilder/functions/index.ts +++ b/packages/report-server/src/reportBuilder/functions/index.ts @@ -27,5 +27,5 @@ export const functions = { periodToDisplayString, sum, divide, - formatAsFractionAndPercentage + formatAsFractionAndPercentage, }; From c6ef73e37be6c8a6cd65b886e7b04fc66f8f7de2 Mon Sep 17 00:00:00 2001 From: Pauline Date: Fri, 9 Jul 2021 13:18:21 +1000 Subject: [PATCH 09/14] Update 20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js --- ...entFeverOverlayFlutracking-modifies-data.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js index 7e9985d529..56241bf899 100644 --- a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js +++ b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js @@ -38,16 +38,16 @@ const MAP_OVERLAY = { type: 'shaded-spectrum', hideFromMenu: false, hideFromLegend: false, - “scaleBounds”: { - “left”: { - “max”: 0, - “min”: 0 + scaleBounds: { + left: { + max: 0, + min: 0, }, - “right”: { - “max”: 1, - “min”: 1 - } - } + right: { + max: 1, + min: 1, + }, + }, }, countryCodes: '{"AU"}', projectCodes: '{covidau}', From ce62f2e9b6cbda557365da00be05ee387653594f Mon Sep 17 00:00:00 2001 From: Pauline Date: Wed, 21 Jul 2021 16:50:47 +1000 Subject: [PATCH 10/14] Add flu by postcode overlay via reports server --- ...stcodeOverlayReportConfig-modifies-data.js | 11 +++++-- ...ntFeverOverlayFlutracking-modifies-data.js | 33 ++++++++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js index 3640133ecc..0f785c30eb 100644 --- a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js +++ b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js @@ -35,7 +35,7 @@ const REPORT = { }, ], dataElements: ['FWV_PC_004', 'FWV_PC_003'], - dataGroups: ['FP'], + dataGroups: ['FPWV'], }, transform: [ { @@ -53,6 +53,13 @@ const REPORT = { { transform: 'select', "'value'": 'divide($row.numerator, $row.denominator)', + "'Total respondents'": '$row.denominator', + "'Respondents reporting fever & cough'": '$row.numerator', + '...': ['organisationUnitCode'], + }, + { + transform: 'filter', + where: "$row.value > '0.01'", '...': ['organisationUnitCode'], }, ], @@ -60,7 +67,7 @@ const REPORT = { }; exports.up = async function (db) { - const permissionGroupId = await permissionGroupNameToId(db, 'Admin'); + const permissionGroupId = await permissionGroupNameToId(db, 'Public'); await insertObject(db, 'report', { ...REPORT, permission_group_id: permissionGroupId }); }; diff --git a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js index 56241bf899..f91dc53f78 100644 --- a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js +++ b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js @@ -19,7 +19,7 @@ exports.setup = function (options, seedLink) { const MAP_OVERLAY = { id: 'AU_Flutracking_Postcode_Fever_Percent', name: '% fever and cough by postcode', - userGroup: 'Admin', + userGroup: 'Public', dataElementCode: 'value', isDataRegional: true, measureBuilder: 'useReportServer', @@ -28,24 +28,33 @@ const MAP_OVERLAY = { reportCode: 'AU_Flutracking_Postcode_Percent_Report', }, presentationOptions: { - values: [{ color: 'grey', value: null }], - // displayType: 'icon', - // "measureLevel": "Postcode", - hideFromPopup: false, - scaleType: 'performance', + hideByDefault: { + null: true, + }, + icon: 'circle', + displayType: 'shaded-spectrum', + measureLevel: 'Postcode', valueType: 'percentage', + scaleType: 'performance', scaleColorScheme: 'default', - type: 'shaded-spectrum', + hideFromPopup: false, hideFromMenu: false, hideFromLegend: false, + linkedMeasures: null, + periodGranularity: 'one_week_at_a_time', scaleBounds: { + right: { + max: 0.05, + }, left: { - max: 0, - min: 0, + max: 0.01, }, - right: { - max: 1, - min: 1, + }, + measureConfig: { + $all: { + type: 'popup-only', + hideFromLegend: true, + measureLevel: 'Postcode', }, }, }, From bd321d64fab5565095fbac0d6e573b10f7bc95d0 Mon Sep 17 00:00:00 2001 From: Pauline Date: Thu, 22 Jul 2021 10:20:31 +1000 Subject: [PATCH 11/14] Adjust back to 0 percent min threshold --- ...116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js | 2 +- ...-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js index 0f785c30eb..454dea2e5b 100644 --- a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js +++ b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js @@ -59,7 +59,7 @@ const REPORT = { }, { transform: 'filter', - where: "$row.value > '0.01'", + where: "$row.value > '0'", '...': ['organisationUnitCode'], }, ], diff --git a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js index f91dc53f78..cf0de8bf52 100644 --- a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js +++ b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js @@ -46,9 +46,6 @@ const MAP_OVERLAY = { right: { max: 0.05, }, - left: { - max: 0.01, - }, }, measureConfig: { $all: { From 91517b17ad6831600e8dcdd03aab0850bfbace9e Mon Sep 17 00:00:00 2001 From: Pauline Date: Mon, 26 Jul 2021 11:54:57 +1000 Subject: [PATCH 12/14] Update yarn.lock --- yarn.lock | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/yarn.lock b/yarn.lock index 3646bce02b..a2b98fe1bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8612,17 +8612,7 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^2.10.0", "@typescript-eslint/eslint-plugin@^2.25.0": - version "2.34.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz#6f8ce8a46c7dea4a6f1d171d2bb8fbae6dac2be9" - integrity sha512-4zY3Z88rEE99+CNvTbXSyovv2z9PNOVffTWD2W8QF5s2prBQtwN2zadqERcrHpcR7O/+KMI3fcTAmUUhK/iQcQ== - dependencies: - "@typescript-eslint/experimental-utils" "2.34.0" - functional-red-black-tree "^1.0.1" - regexpp "^3.0.0" - tsutils "^3.17.1" - -"@typescript-eslint/eslint-plugin@^4.18.0", "@typescript-eslint/eslint-plugin@^4.5.0": +"@typescript-eslint/eslint-plugin@^2.10.0", "@typescript-eslint/eslint-plugin@^2.25.0", "@typescript-eslint/eslint-plugin@^4.18.0", "@typescript-eslint/eslint-plugin@^4.5.0": version "4.18.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.18.0.tgz#50fbce93211b5b690895d20ebec6fe8db48af1f6" integrity sha512-Lzkc/2+7EoH7+NjIWLS2lVuKKqbEmJhtXe3rmfA8cyiKnZm3IfLf51irnBcmow8Q/AptVV0XBZmBJKuUJTe6cQ== From 582d83d742bd8b8c4a60ec67cda5c14a4a20d82b Mon Sep 17 00:00:00 2001 From: Pauline Date: Wed, 28 Jul 2021 17:32:11 +1000 Subject: [PATCH 13/14] Update 20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js --- ...3-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js index cf0de8bf52..600bf8f335 100644 --- a/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js +++ b/packages/database/src/migrations/20210630053253-AddPostcodePercentFeverOverlayFlutracking-modifies-data.js @@ -32,7 +32,7 @@ const MAP_OVERLAY = { null: true, }, icon: 'circle', - displayType: 'shaded-spectrum', + displayType: 'spectrum', measureLevel: 'Postcode', valueType: 'percentage', scaleType: 'performance', From 723b74e4fd224225671dda9433f0481bd0eb305f Mon Sep 17 00:00:00 2001 From: Pauline Date: Wed, 28 Jul 2021 17:34:34 +1000 Subject: [PATCH 14/14] Update 20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js --- ...6-FlutrackingPostcodeOverlayReportConfig-modifies-data.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js index 454dea2e5b..c84c295bad 100644 --- a/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js +++ b/packages/database/src/migrations/20210630015116-FlutrackingPostcodeOverlayReportConfig-modifies-data.js @@ -57,11 +57,6 @@ const REPORT = { "'Respondents reporting fever & cough'": '$row.numerator', '...': ['organisationUnitCode'], }, - { - transform: 'filter', - where: "$row.value > '0'", - '...': ['organisationUnitCode'], - }, ], }, };