@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.
Files changed (48) hide show
  1. package/dist/constants/index.cjs +1379 -0
  2. package/dist/constants/index.cjs.map +1 -0
  3. package/dist/constants/index.d.cts +528 -0
  4. package/dist/constants/index.d.ts +528 -0
  5. package/dist/constants/index.js +1252 -0
  6. package/dist/constants/index.js.map +1 -0
  7. package/dist/index.cjs +2138 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +5 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.js +1986 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/models/index.cjs +661 -0
  14. package/dist/models/index.cjs.map +1 -0
  15. package/dist/models/index.d.cts +204 -0
  16. package/dist/models/index.d.ts +204 -0
  17. package/dist/models/index.js +636 -0
  18. package/dist/models/index.js.map +1 -0
  19. package/dist/schemas/index.cjs +1405 -0
  20. package/dist/schemas/index.cjs.map +1 -0
  21. package/dist/schemas/index.d.cts +312 -0
  22. package/dist/schemas/index.d.ts +312 -0
  23. package/dist/schemas/index.js +1353 -0
  24. package/dist/schemas/index.js.map +1 -0
  25. package/dist/scoring-rule-BOkG46I3.d.cts +1179 -0
  26. package/dist/scoring-rule-BOkG46I3.d.ts +1179 -0
  27. package/dist/types/index.cjs +19 -0
  28. package/dist/types/index.cjs.map +1 -0
  29. package/dist/types/index.d.cts +1 -0
  30. package/dist/types/index.d.ts +1 -0
  31. package/dist/types/index.js +1 -0
  32. package/dist/types/index.js.map +1 -0
  33. package/package.json +81 -0
  34. package/src/constants/ic.ts +1630 -0
  35. package/src/constants/index.ts +11 -0
  36. package/src/index.ts +30 -0
  37. package/src/models/formModel.ts +30 -0
  38. package/src/models/index.ts +72 -0
  39. package/src/models/questionModel.ts +30 -0
  40. package/src/models/scoringRuleModel.ts +33 -0
  41. package/src/models/sectionModel.ts +30 -0
  42. package/src/schemas/common.ts +118 -0
  43. package/src/schemas/form.ts +125 -0
  44. package/src/schemas/index.ts +70 -0
  45. package/src/schemas/question.ts +297 -0
  46. package/src/schemas/scoring-rule.ts +169 -0
  47. package/src/schemas/section.ts +158 -0
  48. package/src/types/index.ts +47 -0
@@ -0,0 +1,636 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/models/formModel.ts
8
+ var formModel_exports = {};
9
+ __export(formModel_exports, {
10
+ buildSchema: () => buildFormSchema,
11
+ compileModel: () => compileModel
12
+ });
13
+
14
+ // src/schemas/form.ts
15
+ import { Schema } from "mongoose";
16
+ var formSectionRefSchema = new Schema(
17
+ {
18
+ sectionId: { type: String, required: true },
19
+ sectionVersion: { type: String, required: true },
20
+ index: { type: Number, required: true },
21
+ isStep: { type: Boolean, default: false },
22
+ wizardStep: { type: Number },
23
+ label: { type: String },
24
+ presetsType: { type: String }
25
+ },
26
+ { _id: false }
27
+ );
28
+ var formSchemaDefinition = {
29
+ _schemaVersion: {
30
+ type: Number,
31
+ required: true,
32
+ default: 1
33
+ },
34
+ // Audit fields
35
+ createdUser: {
36
+ type: Schema.Types.ObjectId,
37
+ required: true,
38
+ index: true
39
+ },
40
+ updatedUser: {
41
+ type: Schema.Types.ObjectId,
42
+ index: true
43
+ },
44
+ // Versioning
45
+ key: {
46
+ type: String,
47
+ required: true
48
+ },
49
+ version: {
50
+ type: String,
51
+ required: true
52
+ },
53
+ // Form info
54
+ name: {
55
+ type: String,
56
+ required: true
57
+ },
58
+ description: {
59
+ type: String
60
+ },
61
+ formType: {
62
+ type: String,
63
+ index: true
64
+ },
65
+ appScope: {
66
+ type: [String],
67
+ enum: ["thread", "pave", "both"],
68
+ default: []
69
+ },
70
+ // Ordered sections
71
+ sections: {
72
+ type: [formSectionRefSchema],
73
+ default: []
74
+ },
75
+ // Lifecycle
76
+ status: {
77
+ type: String,
78
+ required: true,
79
+ enum: ["draft", "active", "deprecated"],
80
+ default: "draft",
81
+ index: true
82
+ },
83
+ supersedes: {
84
+ type: String
85
+ }
86
+ };
87
+ var formSchemaOptions = {
88
+ timestamps: {
89
+ createdAt: "createdTime",
90
+ updatedAt: "updatedTime"
91
+ },
92
+ collection: "forms"
93
+ };
94
+ function buildFormSchema() {
95
+ const schema = new Schema(formSchemaDefinition, formSchemaOptions);
96
+ schema.index({ key: 1, version: 1 }, { unique: true });
97
+ schema.index(
98
+ { key: 1 },
99
+ { unique: true, partialFilterExpression: { status: "active" } }
100
+ );
101
+ return schema;
102
+ }
103
+ var _formSchema = buildFormSchema();
104
+
105
+ // src/models/formModel.ts
106
+ function compileModel(connection, schema = buildFormSchema()) {
107
+ return connection.model("Form", schema);
108
+ }
109
+
110
+ // src/models/sectionModel.ts
111
+ var sectionModel_exports = {};
112
+ __export(sectionModel_exports, {
113
+ buildSchema: () => buildSectionSchema,
114
+ compileModel: () => compileModel2
115
+ });
116
+
117
+ // src/schemas/section.ts
118
+ import { Schema as Schema2 } from "mongoose";
119
+ var sectionQuestionRefSchema = new Schema2(
120
+ {
121
+ questionId: { type: String, required: true },
122
+ questionVersion: { type: String, required: true },
123
+ index: { type: Number, required: true }
124
+ },
125
+ { _id: false }
126
+ );
127
+ var guidanceSchema = new Schema2(
128
+ {
129
+ type: {
130
+ type: String,
131
+ required: true,
132
+ enum: ["tip", "warning", "prompt"]
133
+ },
134
+ text: { type: String, required: true }
135
+ },
136
+ { _id: false }
137
+ );
138
+ var sectionSchemaDefinition = {
139
+ _schemaVersion: {
140
+ type: Number,
141
+ required: true,
142
+ default: 1
143
+ },
144
+ // Audit fields
145
+ createdUser: {
146
+ type: Schema2.Types.ObjectId,
147
+ required: true,
148
+ index: true
149
+ },
150
+ updatedUser: {
151
+ type: Schema2.Types.ObjectId,
152
+ index: true
153
+ },
154
+ // Versioning
155
+ key: {
156
+ type: String,
157
+ required: true
158
+ },
159
+ version: {
160
+ type: String,
161
+ required: true
162
+ },
163
+ // Section info
164
+ name: {
165
+ type: String,
166
+ required: true
167
+ },
168
+ directions: {
169
+ type: String
170
+ },
171
+ // Typed guidance items
172
+ guidance: {
173
+ type: [guidanceSchema],
174
+ default: []
175
+ },
176
+ // Ordered question refs
177
+ questions: {
178
+ type: [sectionQuestionRefSchema],
179
+ default: []
180
+ },
181
+ // Template visibility
182
+ templateScope: {
183
+ type: [String],
184
+ default: void 0
185
+ },
186
+ collapsible: {
187
+ type: Boolean,
188
+ default: false
189
+ },
190
+ defaultCollapsed: {
191
+ type: Boolean,
192
+ default: false
193
+ },
194
+ // Lifecycle
195
+ status: {
196
+ type: String,
197
+ required: true,
198
+ enum: ["draft", "active", "deprecated"],
199
+ default: "draft",
200
+ index: true
201
+ },
202
+ supersedes: {
203
+ type: String
204
+ },
205
+ // PAVE-aligned optional fields
206
+ rephrasing: {
207
+ type: String
208
+ },
209
+ script: {
210
+ type: String
211
+ }
212
+ };
213
+ var sectionSchemaOptions = {
214
+ timestamps: {
215
+ createdAt: "createdTime",
216
+ updatedAt: "updatedTime"
217
+ },
218
+ collection: "sections"
219
+ };
220
+ function buildSectionSchema() {
221
+ const schema = new Schema2(sectionSchemaDefinition, sectionSchemaOptions);
222
+ schema.index({ key: 1, version: 1 }, { unique: true });
223
+ schema.index(
224
+ { key: 1 },
225
+ { unique: true, partialFilterExpression: { status: "active" } }
226
+ );
227
+ return schema;
228
+ }
229
+ var _sectionSchema = buildSectionSchema();
230
+
231
+ // src/models/sectionModel.ts
232
+ function compileModel2(connection, schema = buildSectionSchema()) {
233
+ return connection.model("Section", schema);
234
+ }
235
+
236
+ // src/models/questionModel.ts
237
+ var questionModel_exports = {};
238
+ __export(questionModel_exports, {
239
+ buildSchema: () => buildQuestionSchema,
240
+ compileModel: () => compileModel3
241
+ });
242
+
243
+ // src/schemas/question.ts
244
+ import { Schema as Schema3 } from "mongoose";
245
+ var choiceSchema = new Schema3(
246
+ {
247
+ val: { type: Schema3.Types.Mixed, required: true },
248
+ text: { type: String, required: true },
249
+ tip: { type: String },
250
+ trigger: { type: [String] }
251
+ },
252
+ { _id: false }
253
+ );
254
+ var visibilityRuleSchema = new Schema3(
255
+ {
256
+ dependsOn: { type: String, required: true },
257
+ condition: {
258
+ type: String,
259
+ required: true,
260
+ enum: ["equals", "not_equals", "any_of", "in_range"]
261
+ },
262
+ values: { type: [Schema3.Types.Mixed], required: true },
263
+ source: {
264
+ type: String,
265
+ enum: ["form", "session"],
266
+ default: "form"
267
+ }
268
+ },
269
+ { _id: false }
270
+ );
271
+ var layoutSchema = new Schema3(
272
+ {
273
+ columns: { type: Number, default: 1, min: 1, max: 4 },
274
+ collapsible: { type: Boolean, default: false },
275
+ groupKey: { type: String }
276
+ },
277
+ { _id: false }
278
+ );
279
+ var questionSchemaDefinition = {
280
+ _schemaVersion: {
281
+ type: Number,
282
+ required: true,
283
+ default: 1
284
+ },
285
+ // Audit fields
286
+ createdUser: {
287
+ type: Schema3.Types.ObjectId,
288
+ required: true,
289
+ index: true
290
+ },
291
+ updatedUser: {
292
+ type: Schema3.Types.ObjectId,
293
+ index: true
294
+ },
295
+ // Versioning
296
+ key: {
297
+ type: String,
298
+ required: true
299
+ },
300
+ version: {
301
+ type: String,
302
+ required: true
303
+ },
304
+ // Question definition
305
+ index: {
306
+ type: Number,
307
+ required: true
308
+ },
309
+ text: {
310
+ type: String,
311
+ required: true
312
+ },
313
+ format: {
314
+ type: String,
315
+ required: true
316
+ },
317
+ sectionId: {
318
+ type: String,
319
+ required: true
320
+ },
321
+ required: {
322
+ type: Boolean,
323
+ default: false
324
+ },
325
+ allowMultiple: {
326
+ type: Boolean,
327
+ default: false
328
+ },
329
+ // Nesting
330
+ isNested: {
331
+ type: Boolean,
332
+ default: false
333
+ },
334
+ nested: {
335
+ type: [String],
336
+ default: []
337
+ },
338
+ // Trigger logic
339
+ isTriggered: {
340
+ type: Boolean,
341
+ default: false
342
+ },
343
+ triggersWhenAnswered: {
344
+ type: [String],
345
+ default: []
346
+ },
347
+ // Display
348
+ header: { type: String },
349
+ directions: { type: String },
350
+ tip: { type: String },
351
+ // Dynamic choices
352
+ hasDynamicChoices: {
353
+ type: Boolean,
354
+ default: false
355
+ },
356
+ dynamicChoiceSet: { type: String },
357
+ group: { type: String },
358
+ // Static choices
359
+ choices: {
360
+ type: [choiceSchema],
361
+ default: []
362
+ },
363
+ // UI rendering hints
364
+ componentProps: {
365
+ type: Schema3.Types.Mixed
366
+ },
367
+ // Autofill
368
+ autofillRules: {
369
+ type: Schema3.Types.Mixed,
370
+ default: []
371
+ },
372
+ // Classification
373
+ formType: {
374
+ type: [String],
375
+ enum: ["screening", "intake", "assessment", "demographics"],
376
+ default: []
377
+ },
378
+ icCode: {
379
+ type: String
380
+ },
381
+ // Lifecycle
382
+ status: {
383
+ type: String,
384
+ required: true,
385
+ enum: ["draft", "active", "deprecated"],
386
+ default: "draft",
387
+ index: true
388
+ },
389
+ supersedes: {
390
+ type: String
391
+ },
392
+ // Entity mapping (dual-write bridge)
393
+ targetEntity: {
394
+ type: String,
395
+ enum: [
396
+ "caseSession",
397
+ "protectedPerson",
398
+ "perpetratorPerson",
399
+ "personnelPerson",
400
+ "caseRecord",
401
+ "serviceInstance"
402
+ ]
403
+ },
404
+ targetField: {
405
+ type: String
406
+ },
407
+ // Conditional visibility
408
+ visibilityRule: {
409
+ type: visibilityRuleSchema
410
+ },
411
+ // Layout hints
412
+ layout: {
413
+ type: layoutSchema
414
+ },
415
+ microcopy: {
416
+ type: String
417
+ },
418
+ sensitivity: {
419
+ type: String,
420
+ enum: ["standard", "sensitive", "highly_sensitive"]
421
+ },
422
+ // Scoring group
423
+ scoringGroup: {
424
+ type: String
425
+ },
426
+ // PAVE-aligned optional fields
427
+ groups: {
428
+ type: [String],
429
+ default: void 0
430
+ },
431
+ rephrasingSelector: {
432
+ type: Schema3.Types.Mixed
433
+ },
434
+ textSelector: {
435
+ type: Schema3.Types.Mixed
436
+ },
437
+ tipSelector: {
438
+ type: Schema3.Types.Mixed
439
+ },
440
+ sortChoices: {
441
+ type: Boolean
442
+ },
443
+ isAllRequired: {
444
+ type: Boolean
445
+ },
446
+ itemLabel: {
447
+ type: String
448
+ },
449
+ prompts: {
450
+ type: [String],
451
+ default: void 0
452
+ },
453
+ rephrasing: {
454
+ type: String
455
+ },
456
+ dynamicChoiceTrigger: {
457
+ type: String
458
+ }
459
+ };
460
+ var questionSchemaOptions = {
461
+ timestamps: {
462
+ createdAt: "createdTime",
463
+ updatedAt: "updatedTime"
464
+ },
465
+ collection: "questions"
466
+ };
467
+ function buildQuestionSchema() {
468
+ const schema = new Schema3(questionSchemaDefinition, questionSchemaOptions);
469
+ schema.index({ key: 1, version: 1 }, { unique: true });
470
+ schema.index(
471
+ { key: 1 },
472
+ { unique: true, partialFilterExpression: { status: "active" } }
473
+ );
474
+ schema.index({ sectionId: 1, index: 1 });
475
+ schema.index({ icCode: 1 }, { sparse: true });
476
+ return schema;
477
+ }
478
+ var _questionSchema = buildQuestionSchema();
479
+
480
+ // src/models/questionModel.ts
481
+ function compileModel3(connection, schema = buildQuestionSchema()) {
482
+ return connection.model("Question", schema);
483
+ }
484
+
485
+ // src/models/scoringRuleModel.ts
486
+ var scoringRuleModel_exports = {};
487
+ __export(scoringRuleModel_exports, {
488
+ buildSchema: () => buildScoringRuleSchema,
489
+ compileModel: () => compileModel4
490
+ });
491
+
492
+ // src/schemas/scoring-rule.ts
493
+ import { Schema as Schema4 } from "mongoose";
494
+ var scoringConditionSchema = new Schema4(
495
+ {
496
+ questionKey: { type: String, required: true },
497
+ operator: {
498
+ type: String,
499
+ required: true,
500
+ enum: ["eq", "ne", "in", "not_in", "gt", "gte", "lt", "lte"]
501
+ },
502
+ value: { type: Schema4.Types.Mixed, required: true },
503
+ weight: { type: Number, required: true }
504
+ },
505
+ { _id: false }
506
+ );
507
+ var scoringThresholdSchema = new Schema4(
508
+ {
509
+ minScore: { type: Number, required: true },
510
+ maxScore: { type: Number, required: true },
511
+ riskLevel: { type: String, required: true },
512
+ label: { type: String, required: true }
513
+ },
514
+ { _id: false }
515
+ );
516
+ var scoringRecommendationSchema = new Schema4(
517
+ {
518
+ riskLevel: { type: String, required: true },
519
+ action: { type: String, required: true },
520
+ description: { type: String, required: true }
521
+ },
522
+ { _id: false }
523
+ );
524
+ var scoringRuleSchemaDefinition = {
525
+ _schemaVersion: {
526
+ type: Number,
527
+ required: true,
528
+ default: 1
529
+ },
530
+ // Audit fields
531
+ createdUser: {
532
+ type: Schema4.Types.ObjectId,
533
+ required: true,
534
+ index: true
535
+ },
536
+ updatedUser: {
537
+ type: Schema4.Types.ObjectId,
538
+ index: true
539
+ },
540
+ // Reference to Form (cross-db string, not ObjectId)
541
+ formId: {
542
+ type: String,
543
+ required: true
544
+ },
545
+ formVersion: {
546
+ type: String,
547
+ required: true
548
+ },
549
+ // Rule info
550
+ name: {
551
+ type: String,
552
+ required: true
553
+ },
554
+ version: {
555
+ type: String,
556
+ required: true
557
+ },
558
+ appScope: {
559
+ type: [String],
560
+ enum: ["thread", "pave", "both"],
561
+ default: []
562
+ },
563
+ // Lifecycle
564
+ status: {
565
+ type: String,
566
+ required: true,
567
+ enum: ["draft", "active", "deprecated"],
568
+ default: "draft",
569
+ index: true
570
+ },
571
+ effectiveDate: {
572
+ type: Date
573
+ },
574
+ deprecatedDate: {
575
+ type: Date
576
+ },
577
+ replacedBy: {
578
+ type: String
579
+ },
580
+ // Scoring logic
581
+ conditions: {
582
+ type: [scoringConditionSchema],
583
+ default: []
584
+ },
585
+ thresholds: {
586
+ type: [scoringThresholdSchema],
587
+ default: []
588
+ },
589
+ recommendations: {
590
+ type: [scoringRecommendationSchema],
591
+ default: []
592
+ }
593
+ };
594
+ var scoringRuleSchemaOptions = {
595
+ timestamps: {
596
+ createdAt: "createdTime",
597
+ updatedAt: "updatedTime"
598
+ },
599
+ collection: "scoringrules"
600
+ };
601
+ function buildScoringRuleSchema() {
602
+ const schema = new Schema4(
603
+ scoringRuleSchemaDefinition,
604
+ scoringRuleSchemaOptions
605
+ );
606
+ schema.index(
607
+ { formId: 1, formVersion: 1, version: 1, name: 1 },
608
+ { unique: true }
609
+ );
610
+ schema.index({ formId: 1, formVersion: 1, status: 1 });
611
+ return schema;
612
+ }
613
+ var _scoringRuleSchema = buildScoringRuleSchema();
614
+
615
+ // src/models/scoringRuleModel.ts
616
+ function compileModel4(connection, schema = buildScoringRuleSchema()) {
617
+ return connection.model("ScoringRule", schema);
618
+ }
619
+
620
+ // src/models/index.ts
621
+ function createPlatformModels(connection) {
622
+ return {
623
+ FormModel: compileModel(connection),
624
+ SectionModel: compileModel2(connection),
625
+ QuestionModel: compileModel3(connection),
626
+ ScoringRuleModel: compileModel4(connection)
627
+ };
628
+ }
629
+ export {
630
+ createPlatformModels,
631
+ formModel_exports as formModel,
632
+ questionModel_exports as questionModel,
633
+ scoringRuleModel_exports as scoringRuleModel,
634
+ sectionModel_exports as sectionModel
635
+ };
636
+ //# sourceMappingURL=index.js.map