@htilabs/platform-common-models 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/index.cjs +1379 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/index.d.cts +528 -0
- package/dist/constants/index.d.ts +528 -0
- package/dist/constants/index.js +1252 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/index.cjs +2138 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1986 -0
- package/dist/index.js.map +1 -0
- package/dist/models/index.cjs +661 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.d.cts +204 -0
- package/dist/models/index.d.ts +204 -0
- package/dist/models/index.js +636 -0
- package/dist/models/index.js.map +1 -0
- package/dist/schemas/index.cjs +1405 -0
- package/dist/schemas/index.cjs.map +1 -0
- package/dist/schemas/index.d.cts +312 -0
- package/dist/schemas/index.d.ts +312 -0
- package/dist/schemas/index.js +1353 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/scoring-rule-BOkG46I3.d.cts +1179 -0
- package/dist/scoring-rule-BOkG46I3.d.ts +1179 -0
- package/dist/types/index.cjs +19 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +81 -0
- package/src/constants/ic.ts +1630 -0
- package/src/constants/index.ts +11 -0
- package/src/index.ts +30 -0
- package/src/models/formModel.ts +30 -0
- package/src/models/index.ts +72 -0
- package/src/models/questionModel.ts +30 -0
- package/src/models/scoringRuleModel.ts +33 -0
- package/src/models/sectionModel.ts +30 -0
- package/src/schemas/common.ts +118 -0
- package/src/schemas/form.ts +125 -0
- package/src/schemas/index.ts +70 -0
- package/src/schemas/question.ts +297 -0
- package/src/schemas/scoring-rule.ts +169 -0
- package/src/schemas/section.ts +158 -0
- package/src/types/index.ts +47 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Question Schema
|
|
3
|
+
*
|
|
4
|
+
* Individual form fields with validation, choices, visibility rules, and scoring.
|
|
5
|
+
* Questions support static and dynamic choices, conditional visibility, and IC code mapping.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Schema } from "mongoose";
|
|
9
|
+
import type { InferRawDocType } from "mongoose";
|
|
10
|
+
|
|
11
|
+
// ─── Choice Sub-Schema ───────────────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
export const choiceSchema = new Schema(
|
|
14
|
+
{
|
|
15
|
+
val: { type: Schema.Types.Mixed, required: true },
|
|
16
|
+
text: { type: String, required: true },
|
|
17
|
+
tip: { type: String },
|
|
18
|
+
trigger: { type: [String] },
|
|
19
|
+
},
|
|
20
|
+
{ _id: false },
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export type Choice = InferRawDocType<typeof choiceSchema>;
|
|
24
|
+
|
|
25
|
+
// ─── Visibility Rule Sub-Schema ──────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
export const visibilityRuleSchema = new Schema(
|
|
28
|
+
{
|
|
29
|
+
dependsOn: { type: String, required: true },
|
|
30
|
+
condition: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
enum: ["equals", "not_equals", "any_of", "in_range"],
|
|
34
|
+
},
|
|
35
|
+
values: { type: [Schema.Types.Mixed], required: true },
|
|
36
|
+
source: {
|
|
37
|
+
type: String,
|
|
38
|
+
enum: ["form", "session"],
|
|
39
|
+
default: "form",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{ _id: false },
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export type VisibilityRule = InferRawDocType<typeof visibilityRuleSchema>;
|
|
46
|
+
|
|
47
|
+
// ─── Layout Sub-Schema ───────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
export const layoutSchema = new Schema(
|
|
50
|
+
{
|
|
51
|
+
columns: { type: Number, default: 1, min: 1, max: 4 },
|
|
52
|
+
collapsible: { type: Boolean, default: false },
|
|
53
|
+
groupKey: { type: String },
|
|
54
|
+
},
|
|
55
|
+
{ _id: false },
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export type Layout = InferRawDocType<typeof layoutSchema>;
|
|
59
|
+
|
|
60
|
+
// ─── Question Schema ─────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
export const questionSchemaDefinition = {
|
|
63
|
+
_schemaVersion: {
|
|
64
|
+
type: Number,
|
|
65
|
+
required: true,
|
|
66
|
+
default: 1,
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// Audit fields
|
|
70
|
+
createdUser: {
|
|
71
|
+
type: Schema.Types.ObjectId,
|
|
72
|
+
required: true,
|
|
73
|
+
index: true,
|
|
74
|
+
},
|
|
75
|
+
updatedUser: {
|
|
76
|
+
type: Schema.Types.ObjectId,
|
|
77
|
+
index: true,
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
// Versioning
|
|
81
|
+
key: {
|
|
82
|
+
type: String,
|
|
83
|
+
required: true,
|
|
84
|
+
},
|
|
85
|
+
version: {
|
|
86
|
+
type: String,
|
|
87
|
+
required: true,
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// Question definition
|
|
91
|
+
index: {
|
|
92
|
+
type: Number,
|
|
93
|
+
required: true,
|
|
94
|
+
},
|
|
95
|
+
text: {
|
|
96
|
+
type: String,
|
|
97
|
+
required: true,
|
|
98
|
+
},
|
|
99
|
+
format: {
|
|
100
|
+
type: String,
|
|
101
|
+
required: true,
|
|
102
|
+
},
|
|
103
|
+
sectionId: {
|
|
104
|
+
type: String,
|
|
105
|
+
required: true,
|
|
106
|
+
},
|
|
107
|
+
required: {
|
|
108
|
+
type: Boolean,
|
|
109
|
+
default: false,
|
|
110
|
+
},
|
|
111
|
+
allowMultiple: {
|
|
112
|
+
type: Boolean,
|
|
113
|
+
default: false,
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
// Nesting
|
|
117
|
+
isNested: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
default: false,
|
|
120
|
+
},
|
|
121
|
+
nested: {
|
|
122
|
+
type: [String],
|
|
123
|
+
default: [],
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
// Trigger logic
|
|
127
|
+
isTriggered: {
|
|
128
|
+
type: Boolean,
|
|
129
|
+
default: false,
|
|
130
|
+
},
|
|
131
|
+
triggersWhenAnswered: {
|
|
132
|
+
type: [String],
|
|
133
|
+
default: [],
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// Display
|
|
137
|
+
header: { type: String },
|
|
138
|
+
directions: { type: String },
|
|
139
|
+
tip: { type: String },
|
|
140
|
+
|
|
141
|
+
// Dynamic choices
|
|
142
|
+
hasDynamicChoices: {
|
|
143
|
+
type: Boolean,
|
|
144
|
+
default: false,
|
|
145
|
+
},
|
|
146
|
+
dynamicChoiceSet: { type: String },
|
|
147
|
+
group: { type: String },
|
|
148
|
+
|
|
149
|
+
// Static choices
|
|
150
|
+
choices: {
|
|
151
|
+
type: [choiceSchema],
|
|
152
|
+
default: [],
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
// UI rendering hints
|
|
156
|
+
componentProps: {
|
|
157
|
+
type: Schema.Types.Mixed,
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
// Autofill
|
|
161
|
+
autofillRules: {
|
|
162
|
+
type: Schema.Types.Mixed,
|
|
163
|
+
default: [],
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
// Classification
|
|
167
|
+
formType: {
|
|
168
|
+
type: [String],
|
|
169
|
+
enum: ["screening", "intake", "assessment", "demographics"],
|
|
170
|
+
default: [],
|
|
171
|
+
},
|
|
172
|
+
icCode: {
|
|
173
|
+
type: String,
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
// Lifecycle
|
|
177
|
+
status: {
|
|
178
|
+
type: String,
|
|
179
|
+
required: true,
|
|
180
|
+
enum: ["draft", "active", "deprecated"],
|
|
181
|
+
default: "draft",
|
|
182
|
+
index: true,
|
|
183
|
+
},
|
|
184
|
+
supersedes: {
|
|
185
|
+
type: String,
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
// Entity mapping (dual-write bridge)
|
|
189
|
+
targetEntity: {
|
|
190
|
+
type: String,
|
|
191
|
+
enum: [
|
|
192
|
+
"caseSession",
|
|
193
|
+
"protectedPerson",
|
|
194
|
+
"perpetratorPerson",
|
|
195
|
+
"personnelPerson",
|
|
196
|
+
"caseRecord",
|
|
197
|
+
"serviceInstance",
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
targetField: {
|
|
201
|
+
type: String,
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// Conditional visibility
|
|
205
|
+
visibilityRule: {
|
|
206
|
+
type: visibilityRuleSchema,
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
// Layout hints
|
|
210
|
+
layout: {
|
|
211
|
+
type: layoutSchema,
|
|
212
|
+
},
|
|
213
|
+
microcopy: {
|
|
214
|
+
type: String,
|
|
215
|
+
},
|
|
216
|
+
sensitivity: {
|
|
217
|
+
type: String,
|
|
218
|
+
enum: ["standard", "sensitive", "highly_sensitive"],
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
// Scoring group
|
|
222
|
+
scoringGroup: {
|
|
223
|
+
type: String,
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
// PAVE-aligned optional fields
|
|
227
|
+
groups: {
|
|
228
|
+
type: [String],
|
|
229
|
+
default: undefined,
|
|
230
|
+
},
|
|
231
|
+
rephrasingSelector: {
|
|
232
|
+
type: Schema.Types.Mixed,
|
|
233
|
+
},
|
|
234
|
+
textSelector: {
|
|
235
|
+
type: Schema.Types.Mixed,
|
|
236
|
+
},
|
|
237
|
+
tipSelector: {
|
|
238
|
+
type: Schema.Types.Mixed,
|
|
239
|
+
},
|
|
240
|
+
sortChoices: {
|
|
241
|
+
type: Boolean,
|
|
242
|
+
},
|
|
243
|
+
isAllRequired: {
|
|
244
|
+
type: Boolean,
|
|
245
|
+
},
|
|
246
|
+
itemLabel: {
|
|
247
|
+
type: String,
|
|
248
|
+
},
|
|
249
|
+
prompts: {
|
|
250
|
+
type: [String],
|
|
251
|
+
default: undefined,
|
|
252
|
+
},
|
|
253
|
+
rephrasing: {
|
|
254
|
+
type: String,
|
|
255
|
+
},
|
|
256
|
+
dynamicChoiceTrigger: {
|
|
257
|
+
type: String,
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export const questionSchemaOptions = {
|
|
262
|
+
timestamps: {
|
|
263
|
+
createdAt: "createdTime",
|
|
264
|
+
updatedAt: "updatedTime",
|
|
265
|
+
},
|
|
266
|
+
collection: "questions",
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Build the Question schema.
|
|
271
|
+
* @returns Mongoose Schema for Question
|
|
272
|
+
*/
|
|
273
|
+
export function buildQuestionSchema(): Schema {
|
|
274
|
+
const schema = new Schema(questionSchemaDefinition, questionSchemaOptions);
|
|
275
|
+
|
|
276
|
+
// Compound unique: only one version of a given key
|
|
277
|
+
schema.index({ key: 1, version: 1 }, { unique: true });
|
|
278
|
+
|
|
279
|
+
// Partial unique: only one "active" document per key
|
|
280
|
+
schema.index(
|
|
281
|
+
{ key: 1 },
|
|
282
|
+
{ unique: true, partialFilterExpression: { status: "active" } },
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Lookup by section + order
|
|
286
|
+
schema.index({ sectionId: 1, index: 1 });
|
|
287
|
+
|
|
288
|
+
// IC code lookup (sparse — many questions won't have an IC code)
|
|
289
|
+
schema.index({ icCode: 1 }, { sparse: true });
|
|
290
|
+
|
|
291
|
+
return schema;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Pre-built schema for type inference
|
|
295
|
+
const _questionSchema = buildQuestionSchema();
|
|
296
|
+
|
|
297
|
+
export type Question = InferRawDocType<typeof _questionSchema>;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Scoring Rule Schema
|
|
3
|
+
*
|
|
4
|
+
* Evaluation rules for screening and assessment instruments.
|
|
5
|
+
* Defines conditions to evaluate, score thresholds, and risk level recommendations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Schema } from "mongoose";
|
|
9
|
+
import type { InferRawDocType } from "mongoose";
|
|
10
|
+
|
|
11
|
+
// ─── Scoring Condition Sub-Schema ────────────────────────────────────────────
|
|
12
|
+
|
|
13
|
+
export const scoringConditionSchema = new Schema(
|
|
14
|
+
{
|
|
15
|
+
questionKey: { type: String, required: true },
|
|
16
|
+
operator: {
|
|
17
|
+
type: String,
|
|
18
|
+
required: true,
|
|
19
|
+
enum: ["eq", "ne", "in", "not_in", "gt", "gte", "lt", "lte"],
|
|
20
|
+
},
|
|
21
|
+
value: { type: Schema.Types.Mixed, required: true },
|
|
22
|
+
weight: { type: Number, required: true },
|
|
23
|
+
},
|
|
24
|
+
{ _id: false },
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export type ScoringCondition = InferRawDocType<typeof scoringConditionSchema>;
|
|
28
|
+
|
|
29
|
+
// ─── Scoring Threshold Sub-Schema ────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
export const scoringThresholdSchema = new Schema(
|
|
32
|
+
{
|
|
33
|
+
minScore: { type: Number, required: true },
|
|
34
|
+
maxScore: { type: Number, required: true },
|
|
35
|
+
riskLevel: { type: String, required: true },
|
|
36
|
+
label: { type: String, required: true },
|
|
37
|
+
},
|
|
38
|
+
{ _id: false },
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export type ScoringThreshold = InferRawDocType<typeof scoringThresholdSchema>;
|
|
42
|
+
|
|
43
|
+
// ─── Scoring Recommendation Sub-Schema ───────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
export const scoringRecommendationSchema = new Schema(
|
|
46
|
+
{
|
|
47
|
+
riskLevel: { type: String, required: true },
|
|
48
|
+
action: { type: String, required: true },
|
|
49
|
+
description: { type: String, required: true },
|
|
50
|
+
},
|
|
51
|
+
{ _id: false },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
export type ScoringRecommendation = InferRawDocType<
|
|
55
|
+
typeof scoringRecommendationSchema
|
|
56
|
+
>;
|
|
57
|
+
|
|
58
|
+
// ─── Scoring Rule Schema ─────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
export const scoringRuleSchemaDefinition = {
|
|
61
|
+
_schemaVersion: {
|
|
62
|
+
type: Number,
|
|
63
|
+
required: true,
|
|
64
|
+
default: 1,
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
// Audit fields
|
|
68
|
+
createdUser: {
|
|
69
|
+
type: Schema.Types.ObjectId,
|
|
70
|
+
required: true,
|
|
71
|
+
index: true,
|
|
72
|
+
},
|
|
73
|
+
updatedUser: {
|
|
74
|
+
type: Schema.Types.ObjectId,
|
|
75
|
+
index: true,
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// Reference to Form (cross-db string, not ObjectId)
|
|
79
|
+
formId: {
|
|
80
|
+
type: String,
|
|
81
|
+
required: true,
|
|
82
|
+
},
|
|
83
|
+
formVersion: {
|
|
84
|
+
type: String,
|
|
85
|
+
required: true,
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
// Rule info
|
|
89
|
+
name: {
|
|
90
|
+
type: String,
|
|
91
|
+
required: true,
|
|
92
|
+
},
|
|
93
|
+
version: {
|
|
94
|
+
type: String,
|
|
95
|
+
required: true,
|
|
96
|
+
},
|
|
97
|
+
appScope: {
|
|
98
|
+
type: [String],
|
|
99
|
+
enum: ["thread", "pave", "both"],
|
|
100
|
+
default: [],
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// Lifecycle
|
|
104
|
+
status: {
|
|
105
|
+
type: String,
|
|
106
|
+
required: true,
|
|
107
|
+
enum: ["draft", "active", "deprecated"],
|
|
108
|
+
default: "draft",
|
|
109
|
+
index: true,
|
|
110
|
+
},
|
|
111
|
+
effectiveDate: {
|
|
112
|
+
type: Date,
|
|
113
|
+
},
|
|
114
|
+
deprecatedDate: {
|
|
115
|
+
type: Date,
|
|
116
|
+
},
|
|
117
|
+
replacedBy: {
|
|
118
|
+
type: String,
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
// Scoring logic
|
|
122
|
+
conditions: {
|
|
123
|
+
type: [scoringConditionSchema],
|
|
124
|
+
default: [],
|
|
125
|
+
},
|
|
126
|
+
thresholds: {
|
|
127
|
+
type: [scoringThresholdSchema],
|
|
128
|
+
default: [],
|
|
129
|
+
},
|
|
130
|
+
recommendations: {
|
|
131
|
+
type: [scoringRecommendationSchema],
|
|
132
|
+
default: [],
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const scoringRuleSchemaOptions = {
|
|
137
|
+
timestamps: {
|
|
138
|
+
createdAt: "createdTime",
|
|
139
|
+
updatedAt: "updatedTime",
|
|
140
|
+
},
|
|
141
|
+
collection: "scoringrules",
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Build the ScoringRule schema.
|
|
146
|
+
* @returns Mongoose Schema for ScoringRule
|
|
147
|
+
*/
|
|
148
|
+
export function buildScoringRuleSchema(): Schema {
|
|
149
|
+
const schema = new Schema(
|
|
150
|
+
scoringRuleSchemaDefinition,
|
|
151
|
+
scoringRuleSchemaOptions,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// Compound unique: one rule name per form version
|
|
155
|
+
schema.index(
|
|
156
|
+
{ formId: 1, formVersion: 1, version: 1, name: 1 },
|
|
157
|
+
{ unique: true },
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Lookup active rules for a form
|
|
161
|
+
schema.index({ formId: 1, formVersion: 1, status: 1 });
|
|
162
|
+
|
|
163
|
+
return schema;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Pre-built schema for type inference
|
|
167
|
+
const _scoringRuleSchema = buildScoringRuleSchema();
|
|
168
|
+
|
|
169
|
+
export type ScoringRule = InferRawDocType<typeof _scoringRuleSchema>;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — Section Schema
|
|
3
|
+
*
|
|
4
|
+
* Logical grouping of questions within a form.
|
|
5
|
+
* Sections contain ordered references to questions with display metadata.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Schema } from "mongoose";
|
|
9
|
+
import type { InferRawDocType } from "mongoose";
|
|
10
|
+
|
|
11
|
+
// ─── Section Question Reference Sub-Schema ───────────────────────────────────
|
|
12
|
+
|
|
13
|
+
export const sectionQuestionRefSchema = new Schema(
|
|
14
|
+
{
|
|
15
|
+
questionId: { type: String, required: true },
|
|
16
|
+
questionVersion: { type: String, required: true },
|
|
17
|
+
index: { type: Number, required: true },
|
|
18
|
+
},
|
|
19
|
+
{ _id: false },
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export type SectionQuestionRef = InferRawDocType<
|
|
23
|
+
typeof sectionQuestionRefSchema
|
|
24
|
+
>;
|
|
25
|
+
|
|
26
|
+
// ─── Guidance Sub-Schema ─────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
export const guidanceSchema = new Schema(
|
|
29
|
+
{
|
|
30
|
+
type: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
enum: ["tip", "warning", "prompt"],
|
|
34
|
+
},
|
|
35
|
+
text: { type: String, required: true },
|
|
36
|
+
},
|
|
37
|
+
{ _id: false },
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export type Guidance = InferRawDocType<typeof guidanceSchema>;
|
|
41
|
+
|
|
42
|
+
// ─── Section Schema ──────────────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
export const sectionSchemaDefinition = {
|
|
45
|
+
_schemaVersion: {
|
|
46
|
+
type: Number,
|
|
47
|
+
required: true,
|
|
48
|
+
default: 1,
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// Audit fields
|
|
52
|
+
createdUser: {
|
|
53
|
+
type: Schema.Types.ObjectId,
|
|
54
|
+
required: true,
|
|
55
|
+
index: true,
|
|
56
|
+
},
|
|
57
|
+
updatedUser: {
|
|
58
|
+
type: Schema.Types.ObjectId,
|
|
59
|
+
index: true,
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// Versioning
|
|
63
|
+
key: {
|
|
64
|
+
type: String,
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
version: {
|
|
68
|
+
type: String,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// Section info
|
|
73
|
+
name: {
|
|
74
|
+
type: String,
|
|
75
|
+
required: true,
|
|
76
|
+
},
|
|
77
|
+
directions: {
|
|
78
|
+
type: String,
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
// Typed guidance items
|
|
82
|
+
guidance: {
|
|
83
|
+
type: [guidanceSchema],
|
|
84
|
+
default: [],
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// Ordered question refs
|
|
88
|
+
questions: {
|
|
89
|
+
type: [sectionQuestionRefSchema],
|
|
90
|
+
default: [],
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
// Template visibility
|
|
94
|
+
templateScope: {
|
|
95
|
+
type: [String],
|
|
96
|
+
default: undefined,
|
|
97
|
+
},
|
|
98
|
+
collapsible: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: false,
|
|
101
|
+
},
|
|
102
|
+
defaultCollapsed: {
|
|
103
|
+
type: Boolean,
|
|
104
|
+
default: false,
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
// Lifecycle
|
|
108
|
+
status: {
|
|
109
|
+
type: String,
|
|
110
|
+
required: true,
|
|
111
|
+
enum: ["draft", "active", "deprecated"],
|
|
112
|
+
default: "draft",
|
|
113
|
+
index: true,
|
|
114
|
+
},
|
|
115
|
+
supersedes: {
|
|
116
|
+
type: String,
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// PAVE-aligned optional fields
|
|
120
|
+
rephrasing: {
|
|
121
|
+
type: String,
|
|
122
|
+
},
|
|
123
|
+
script: {
|
|
124
|
+
type: String,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const sectionSchemaOptions = {
|
|
129
|
+
timestamps: {
|
|
130
|
+
createdAt: "createdTime",
|
|
131
|
+
updatedAt: "updatedTime",
|
|
132
|
+
},
|
|
133
|
+
collection: "sections",
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Build the Section schema.
|
|
138
|
+
* @returns Mongoose Schema for Section
|
|
139
|
+
*/
|
|
140
|
+
export function buildSectionSchema(): Schema {
|
|
141
|
+
const schema = new Schema(sectionSchemaDefinition, sectionSchemaOptions);
|
|
142
|
+
|
|
143
|
+
// Compound unique: only one version of a given key
|
|
144
|
+
schema.index({ key: 1, version: 1 }, { unique: true });
|
|
145
|
+
|
|
146
|
+
// Partial unique: only one "active" document per key
|
|
147
|
+
schema.index(
|
|
148
|
+
{ key: 1 },
|
|
149
|
+
{ unique: true, partialFilterExpression: { status: "active" } },
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return schema;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Pre-built schema for type inference
|
|
156
|
+
const _sectionSchema = buildSectionSchema();
|
|
157
|
+
|
|
158
|
+
export type Section = InferRawDocType<typeof _sectionSchema>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models - Types
|
|
3
|
+
*
|
|
4
|
+
* Shared TypeScript types for HTI Labs applications.
|
|
5
|
+
* Type definitions are co-located with constants and exported from here.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Re-export all types from constants
|
|
9
|
+
export type {
|
|
10
|
+
DataQualityValue,
|
|
11
|
+
IC5Value,
|
|
12
|
+
IC13Value,
|
|
13
|
+
IC13Category,
|
|
14
|
+
RelationshipDynamicValue,
|
|
15
|
+
RelationshipConcernValue,
|
|
16
|
+
IC49Value,
|
|
17
|
+
IC56Value,
|
|
18
|
+
IC57Value,
|
|
19
|
+
IC58Value,
|
|
20
|
+
IC59Value,
|
|
21
|
+
IC49ReferralOutcomeValue,
|
|
22
|
+
IC49ReferralVerificationValue,
|
|
23
|
+
SessionStateValue,
|
|
24
|
+
RecordStateValue,
|
|
25
|
+
InteractionTypeValue,
|
|
26
|
+
IncidentInvolvementRoleValue,
|
|
27
|
+
PersonRoleValue,
|
|
28
|
+
IC4Value,
|
|
29
|
+
IC22Value,
|
|
30
|
+
IC23Value,
|
|
31
|
+
IC24Value,
|
|
32
|
+
IC25Value,
|
|
33
|
+
AccommodationValue,
|
|
34
|
+
MinorAdultStatusValue,
|
|
35
|
+
ApparentAgeValue,
|
|
36
|
+
AgeBinReportingValue,
|
|
37
|
+
QuickStartTemplateId,
|
|
38
|
+
SubmissionStateValue,
|
|
39
|
+
FormStatusValue,
|
|
40
|
+
QuestionFormatValue,
|
|
41
|
+
AppScopeValue,
|
|
42
|
+
FormTypeValue,
|
|
43
|
+
UserStatusValue,
|
|
44
|
+
IncidentParticipationRoleValue,
|
|
45
|
+
PersonDisplayCategoryValue,
|
|
46
|
+
PersonTypeValue,
|
|
47
|
+
} from "../constants/ic.js";
|