Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPC-9713: Add service modality models #197

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ 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 serviceModalityAssociation from './models/serviceModalityAssociation';
import tag from './models/tag';
import task from './models/task';
import unit from './models/unit';
Expand Down Expand Up @@ -218,6 +220,11 @@ const initializeTables = (masterConn: Knex, replicaConn?: Knex) => ({
reportFile: reportFile(masterConn, replicaConn),
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),
Expand Down
34 changes: 18 additions & 16 deletions src/db/models/json/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -13,23 +22,16 @@ 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: t.array(
t.exact(
t.type({
objectId: t.number,
cost: t.number,
})
)
),
breakdownByGlobalCluster: 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)
Expand Down
29 changes: 29 additions & 0 deletions src/db/models/serviceModality.ts
Original file line number Diff line number Diff line change
@@ -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<number, ServiceModalityId>(
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,
});
20 changes: 20 additions & 0 deletions src/db/models/serviceModalityAssociation.ts
Original file line number Diff line number Diff line change
@@ -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,
});
Loading