From fd66c2c4262e2ef9bddee5db7709eea1e8b44e69 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Fri, 27 Sep 2024 11:30:06 +0200 Subject: [PATCH 1/4] HPC-9713: Add `serviceModality` model --- src/db/index.ts | 2 ++ src/db/models/serviceModality.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/db/models/serviceModality.ts diff --git a/src/db/index.ts b/src/db/index.ts index 18b2d2d7..1bb987c6 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -93,6 +93,7 @@ import reportDetail from './models/reportDetail'; import reportFile from './models/reportFile'; import reportingWindow from './models/reportingWindow'; import reportingWindowAssignment from './models/reportingWindowAssignment'; +import serviceModality from './models/serviceModality'; import tag from './models/tag'; import task from './models/task'; import unit from './models/unit'; @@ -218,6 +219,7 @@ const initializeTables = (masterConn: Knex, replicaConn?: Knex) => ({ reportFile: reportFile(masterConn, replicaConn), reportingWindow: reportingWindow(masterConn, replicaConn), reportingWindowAssignment: reportingWindowAssignment(masterConn, replicaConn), + serviceModality: serviceModality(masterConn, replicaConn), tag: tag(masterConn, replicaConn), task: task(masterConn, replicaConn), unit: unit(masterConn, replicaConn), diff --git a/src/db/models/serviceModality.ts b/src/db/models/serviceModality.ts new file mode 100644 index 00000000..02d64d4d --- /dev/null +++ b/src/db/models/serviceModality.ts @@ -0,0 +1,29 @@ +import * as t from 'io-ts'; + +import { brandedType } from '../../util/io-ts'; +import type { Brand } from '../../util/types'; +import { defineIDModel } from '../util/id-model'; + +export type ServiceModalityId = Brand< + number, + { readonly s: unique symbol }, + 'serviceModality.id' +>; + +export const SERVICE_MODALITY_ID = brandedType( + t.number +); + +export default defineIDModel({ + tableName: 'serviceModality', + fields: { + generated: { + id: { kind: 'branded-integer', brand: SERVICE_MODALITY_ID }, + }, + required: { + name: { kind: 'checked', type: t.string }, + }, + }, + idField: 'id', + softDeletionEnabled: false, +}); From 3b14075892382b260e5b7ba672792e978cebe6f0 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Fri, 27 Sep 2024 12:04:31 +0200 Subject: [PATCH 2/4] HPC-9713: Add `serviceModalityAssociation` model --- src/db/index.ts | 5 +++++ src/db/models/serviceModalityAssociation.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/db/models/serviceModalityAssociation.ts diff --git a/src/db/index.ts b/src/db/index.ts index 1bb987c6..1cb4a29c 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -94,6 +94,7 @@ import reportFile from './models/reportFile'; import reportingWindow from './models/reportingWindow'; import reportingWindowAssignment from './models/reportingWindowAssignment'; import serviceModality from './models/serviceModality'; +import serviceModalityAssociation from './models/serviceModalityAssociation'; import tag from './models/tag'; import task from './models/task'; import unit from './models/unit'; @@ -220,6 +221,10 @@ const initializeTables = (masterConn: Knex, replicaConn?: Knex) => ({ reportingWindow: reportingWindow(masterConn, replicaConn), reportingWindowAssignment: reportingWindowAssignment(masterConn, replicaConn), serviceModality: serviceModality(masterConn, replicaConn), + serviceModalityAssociation: serviceModalityAssociation( + masterConn, + replicaConn + ), tag: tag(masterConn, replicaConn), task: task(masterConn, replicaConn), unit: unit(masterConn, replicaConn), diff --git a/src/db/models/serviceModalityAssociation.ts b/src/db/models/serviceModalityAssociation.ts new file mode 100644 index 00000000..0575d65b --- /dev/null +++ b/src/db/models/serviceModalityAssociation.ts @@ -0,0 +1,20 @@ +import { defineSequelizeModel } from '../util/sequelize-model'; +import { GOVERNING_ENTITY_ID } from './governingEntity'; +import { SERVICE_MODALITY_ID } from './serviceModality'; + +export default defineSequelizeModel({ + tableName: 'serviceModalityAssociation', + fields: { + required: { + serviceModalityId: { + kind: 'branded-integer', + brand: SERVICE_MODALITY_ID, + }, + governingEntityId: { + kind: 'branded-integer', + brand: GOVERNING_ENTITY_ID, + }, + }, + }, + softDeletionEnabled: false, +}); From 243c3545d6388240f2747311f6a28265f547f487 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Fri, 6 Dec 2024 09:11:58 +0100 Subject: [PATCH 3/4] Add `breakdownByServiceModality` property to codec This property will store breakdown by service modality, opposed to other breakdown property that stores breakdown by global cluster --- src/db/models/json/attachment.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/db/models/json/attachment.ts b/src/db/models/json/attachment.ts index bb5698b3..2464708f 100644 --- a/src/db/models/json/attachment.ts +++ b/src/db/models/json/attachment.ts @@ -4,6 +4,15 @@ import { INDICATOR_VALUE as INDICATOR_ATTACHMENT_VALUE, } from './indicatorsAndCaseloads'; +const COST_BREAKDOWN = t.array( + t.exact( + t.type({ + objectId: t.number, + cost: t.number, + }) + ) +); + const COST_ATTACHMENT_VALUE = t.intersection([ t.exact( t.type({ @@ -22,14 +31,12 @@ const COST_ATTACHMENT_VALUE = t.intersection([ * and the total sum of the breakdown must match the overall cost when * non-empty. */ - breakdown: t.array( - t.exact( - t.type({ - objectId: t.number, - cost: t.number, - }) - ) - ), + breakdown: COST_BREAKDOWN, + /** + * Unlike global cluster breakdown, service modality breakdown + * doesn't need to add up to the total cost + */ + breakdownByServiceModality: COST_BREAKDOWN, // TODO: delete these properties once we've confirmed that they're not // needed for any code that reads cost attachments // (they seem to be produced by RPM frontend code related to other types) From 5bd468c5f71e6428ba14a21b4861716e625b76b9 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Fri, 27 Sep 2024 12:18:47 +0200 Subject: [PATCH 4/4] Rename cost breakdown to `breakdownByGlobalCluster` This is done to distinguish between breakdowns by global cluster and by service modality --- src/db/models/json/attachment.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/db/models/json/attachment.ts b/src/db/models/json/attachment.ts index 2464708f..b31ec247 100644 --- a/src/db/models/json/attachment.ts +++ b/src/db/models/json/attachment.ts @@ -22,16 +22,11 @@ const COST_ATTACHMENT_VALUE = t.intersection([ t.exact( t.partial({ /** - * When necessary, a cost breakdown can be provided with respect to a - * particular collection of objects. - * - * For example, when the object of this attachment is a governing entity, - * a breakdown needs to be provided for each of the global clusters, - * (even if the governing entity has 0 global clusters) - * and the total sum of the breakdown must match the overall cost when - * non-empty. + * When necessary, a cost breakdown can be provided for each of the global + * clusters (even if the governing entity has 0 global clusters), and the + * total sum of the breakdown must match the overall cost when non-empty. */ - breakdown: COST_BREAKDOWN, + breakdownByGlobalCluster: COST_BREAKDOWN, /** * Unlike global cluster breakdown, service modality breakdown * doesn't need to add up to the total cost