@hippo-digital/hippocampus 2.9.0 → 2.10.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/lib/schema.js CHANGED
@@ -18,6 +18,40 @@ const isoDate = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Use YYYY-MM-DD dates')
18
18
  // package accepts either and says nothing about it.
19
19
  const person = nonEmptyString.optional()
20
20
 
21
+ // Who did each step to a record, so a trace can show it and a check can find a
22
+ // step nobody did. Git says what changed and when; these say who. Every record
23
+ // type takes them and none is required: a project that wants them enforced turns
24
+ // on the stricter checks. A link is a record too - it is a claim someone made.
25
+ //
26
+ // draftedBy - who or what wrote it: a person, a role, or an agent
27
+ // reviewedBy - someone other than the drafter checked it against its source
28
+ // signedOffBy - the accountable person accepted it (for a hazard or a severity
29
+ // rating, the clinical safety officer)
30
+ const review = {
31
+ draftedBy: person,
32
+ reviewedBy: person,
33
+ reviewedOn: isoDate.optional(),
34
+ signedOffBy: person,
35
+ signedOffOn: isoDate.optional()
36
+ }
37
+
38
+ // Where the chain carries on outside the knowledge base: a Jira ticket, a test,
39
+ // a release, a guidance page. Software requirements and tests stay in the
40
+ // production repositories; this is how a record points at them, so the trace
41
+ // does not stop at the screen.
42
+ const outsideReferences = z.array(z.object({
43
+ system: nonEmptyString,
44
+ id: nonEmptyString,
45
+ url: z.string().url().optional(),
46
+ kind: nonEmptyString.optional()
47
+ }).passthrough()).optional()
48
+
49
+ // On evidence and research rounds: the people quoted confirmed the write-up.
50
+ const sourceConfirmed = {
51
+ sourceConfirmedBy: person,
52
+ sourceConfirmedOn: isoDate.optional()
53
+ }
54
+
21
55
  // How much a finding matters - a different question from how sure we are of it,
22
56
  // which is `confidence`. A finding can be critical and only weakly evidenced;
23
57
  // folding the two together makes the most severe item in a log read as middling.
@@ -69,7 +103,23 @@ const ProjectSchema = z.object({
69
103
  prototypeSlice: id,
70
104
  // What people call the service day to day ("NCRS"). The linter treats it
71
105
  // as naming the system when it turns up inside a user need.
72
- shortName: nonEmptyString.optional()
106
+ shortName: nonEmptyString.optional(),
107
+ // The project's own risk scales, from its clinical safety officer's hazard
108
+ // log. The package ships none: a severity word means what the project's
109
+ // matrix says it means, and a default would be a clinical decision made in a
110
+ // code review. Hazard ratings are checked against these when they are set.
111
+ riskScales: z.object({
112
+ severity: stringList,
113
+ likelihood: stringList,
114
+ // The rating each value stands for, lowest first: { "1": "Acceptable", ... }.
115
+ risk: z.record(z.string().regex(/^\d+$/), nonEmptyString),
116
+ // The rating a severity and likelihood give: matrix[likelihood][severity].
117
+ matrix: z.record(z.string(), z.record(z.string(), z.number().int().positive())).optional(),
118
+ source: nonEmptyString.optional()
119
+ }).passthrough().optional(),
120
+ // Turns the traceability gaps into warnings, so `validate --strict` fails on
121
+ // them. For a project that has decided its trace has to be complete.
122
+ strictTraceability: z.boolean().optional()
73
123
  }).passthrough()
74
124
 
75
125
  const ProjectContextUserSchema = z.object({
@@ -163,7 +213,8 @@ const UserSchema = z.object({
163
213
  userGroupId: id.optional(),
164
214
  environment: EnvironmentSchema.optional(),
165
215
  resources: stringList.optional(),
166
- reference
216
+ reference,
217
+ ...review
167
218
  }).passthrough()
168
219
 
169
220
  // What a user wants to achieve - the intended outcome of a task. A need says
@@ -172,7 +223,8 @@ const GoalSchema = z.object({
172
223
  id,
173
224
  userId: id,
174
225
  statement: nonEmptyString,
175
- reference
226
+ reference,
227
+ ...review
176
228
  }).passthrough()
177
229
 
178
230
  // A user story derived from the need it belongs to. In the workbooks teams keep,
@@ -197,7 +249,8 @@ const NeedSchema = z.object({
197
249
  goalId: id.optional(),
198
250
  qualityDimension: qualityDimension.optional(),
199
251
  reference,
200
- story: NeedStorySchema.optional()
252
+ story: NeedStorySchema.optional(),
253
+ ...review
201
254
  }).passthrough()
202
255
 
203
256
  const LocationSearchSchema = z.object({
@@ -227,7 +280,14 @@ const ScenarioSchema = z.object({
227
280
  environment: EnvironmentSchema.optional(),
228
281
  resources: stringList.optional(),
229
282
  locationSearch: LocationSearchSchema.optional(),
230
- reference
283
+ // IEC 62366-1 5.5: which hazard-related scenarios go to summative
284
+ // evaluation, and why. Saying a scenario was left out, and why, counts too.
285
+ summative: z.object({
286
+ selected: z.boolean(),
287
+ reason: nonEmptyString
288
+ }).optional(),
289
+ reference,
290
+ ...review
231
291
  }).passthrough()
232
292
 
233
293
  const PainPointSchema = z.object({
@@ -270,7 +330,8 @@ const JourneySchema = z.object({
270
330
  entryPoint: nonEmptyString,
271
331
  exitPoint: nonEmptyString,
272
332
  steps: z.array(JourneyStepSchema).min(1),
273
- reference
333
+ reference,
334
+ ...review
274
335
  }).passthrough()
275
336
 
276
337
  const ScreenSchema = z.object({
@@ -285,7 +346,8 @@ const ScreenSchema = z.object({
285
346
  // to render, so the route smoke test skips these instead of failing on them.
286
347
  external: z.boolean().optional(),
287
348
  sourcePath: nonEmptyString.optional(),
288
- reference
349
+ reference,
350
+ ...review
289
351
  }).passthrough()
290
352
 
291
353
  const EvidenceSchema = z.object({
@@ -297,7 +359,9 @@ const EvidenceSchema = z.object({
297
359
  sourcePath: nonEmptyString.optional(),
298
360
  quotes: z.array(nonEmptyString).optional(),
299
361
  reference,
300
- impact
362
+ impact,
363
+ ...review,
364
+ ...sourceConfirmed
301
365
  }).passthrough()
302
366
 
303
367
  // Who decided, and when, used to be a sentence appended to the consequence. A
@@ -312,14 +376,17 @@ const DecisionSchema = z.object({
312
376
  decidedBy: person,
313
377
  decidedOn: isoDate.optional(),
314
378
  owner: person,
315
- reference
379
+ reference,
380
+ outsideReferences,
381
+ ...review
316
382
  }).passthrough()
317
383
 
318
384
  const AssumptionSchema = z.object({
319
385
  id,
320
386
  statement: nonEmptyString,
321
387
  risk: z.enum(['high', 'medium', 'low']),
322
- reference
388
+ reference,
389
+ ...review
323
390
  }).passthrough()
324
391
 
325
392
  // An intended outcome for the people who will use the service, set while
@@ -330,7 +397,8 @@ const QualityObjectiveSchema = z.object({
330
397
  dimension: qualityDimension,
331
398
  statement: nonEmptyString,
332
399
  criteria: stringList.optional(),
333
- reference
400
+ reference,
401
+ ...review
334
402
  }).passthrough()
335
403
 
336
404
  // How a quantitative requirement is measured. The numbers are usually a
@@ -369,7 +437,9 @@ const RequirementSchema = z.object({
369
437
  measure: RequirementMeasureSchema.optional(),
370
438
  qualityDimension: qualityDimension.optional(),
371
439
  status: z.enum(['draft', 'agreed', 'retired']).optional(),
372
- reference
440
+ reference,
441
+ outsideReferences,
442
+ ...review
373
443
  }).passthrough()
374
444
 
375
445
  // Guidance a design follows: an interaction principle, a heuristic, a design
@@ -384,7 +454,8 @@ const PrincipleSchema = z.object({
384
454
  statement: nonEmptyString,
385
455
  source: nonEmptyString.optional(),
386
456
  sourcePath: nonEmptyString.optional(),
387
- reference
457
+ reference,
458
+ ...review
388
459
  }).passthrough()
389
460
 
390
461
  // How a round was run. A list, because most rounds mix methods - an interview
@@ -425,7 +496,9 @@ const ResearchRoundSchema = z.object({
425
496
  // tasks safely (summative). Most rounds are formative; saying so is what
426
497
  // makes a summative round stand out as the one the evidence rests on.
427
498
  evaluation: z.enum(['formative', 'summative']).optional(),
428
- reference
499
+ reference,
500
+ ...review,
501
+ ...sourceConfirmed
429
502
  }).passthrough()
430
503
 
431
504
  const ParticipantSchema = z.object({
@@ -441,7 +514,8 @@ const ParticipantSchema = z.object({
441
514
  // They are not research participants, and counting them as such inflates
442
515
  // how much research a finding rests on.
443
516
  kind: z.enum(['research-participant', 'reviewer']).optional(),
444
- reference
517
+ reference,
518
+ ...review
445
519
  }).passthrough()
446
520
 
447
521
  const InsightSchema = z.object({
@@ -462,8 +536,14 @@ const InsightSchema = z.object({
462
536
  signedOffBy: nonEmptyString.optional(),
463
537
  signedOffOn: isoDate.optional(),
464
538
  qualityDimension: qualityDimension.optional(),
539
+ // IEC 62366-1 5.9: what the user did wrong, and why. A summative round has to
540
+ // say both for every use error it observed; a root cause is what decides
541
+ // whether a control needs changing or a hazard has been missed.
542
+ useError: nonEmptyString.optional(),
543
+ rootCause: nonEmptyString.optional(),
465
544
  reference,
466
- impact
545
+ impact,
546
+ ...review
467
547
  }).passthrough()
468
548
 
469
549
  const DesignActionSchema = z.object({
@@ -474,7 +554,118 @@ const DesignActionSchema = z.object({
474
554
  rationale: nonEmptyString,
475
555
  insightIds: z.array(id).min(1),
476
556
  owner: person,
477
- reference
557
+ reference,
558
+ ...review
559
+ }).passthrough()
560
+
561
+ // What the product is for, in the terms MHRA asks a manufacturer to state it
562
+ // (Crafting an intended purpose in the context of SaMD, 2023), plus "must not
563
+ // do": the functions that would change what it is. Kept with its history - each
564
+ // version is a record, and an agreed one names the version it supersedes - so
565
+ // every change can be shown to have been checked against the boundary. Useful
566
+ // even when the answer is "not a medical device".
567
+ const IntendedPurposeSchema = z.object({
568
+ id,
569
+ title: nonEmptyString,
570
+ version: nonEmptyString,
571
+ status: z.enum(['draft', 'agreed', 'superseded']),
572
+ statement: nonEmptyString,
573
+ indications: nonEmptyString.optional(),
574
+ structureAndFunction: nonEmptyString.optional(),
575
+ population: z.object({
576
+ included: nonEmptyString,
577
+ excluded: nonEmptyString.optional()
578
+ }).optional(),
579
+ userIds: z.array(id).optional(),
580
+ useEnvironment: nonEmptyString.optional(),
581
+ foreseeableMisuse: z.array(nonEmptyString).optional(),
582
+ mustNotDo: z.array(nonEmptyString).optional(),
583
+ agreedBy: person,
584
+ agreedOn: isoDate.optional(),
585
+ supersedes: id.optional(),
586
+ reference,
587
+ ...review
588
+ }).passthrough()
589
+
590
+ // A risk as the hazard log rates it. The words come from the project's own
591
+ // scales (project.riskScales); the package checks them against those and
592
+ // against its matrix, and holds no scale of its own.
593
+ const RiskSchema = z.object({
594
+ severity: nonEmptyString,
595
+ likelihood: nonEmptyString,
596
+ risk: z.number().int().positive(),
597
+ justification: nonEmptyString.optional()
598
+ }).passthrough()
599
+
600
+ // A hazard: what could go wrong for a patient, why, and how bad it is. For a
601
+ // project whose clinical safety officer keeps the hazard log elsewhere, a
602
+ // hazard here is a reference to it - its number and words at a stated version,
603
+ // plus the links the log does not have - and the log stays the master.
604
+ //
605
+ // Only a named person sets a risk. A hazard written by a designer or an agent
606
+ // is "proposed", with no rating, until the clinical safety officer accepts it.
607
+ const HazardSchema = z.object({
608
+ id,
609
+ title: nonEmptyString,
610
+ logNumber: z.union([z.number().int().positive(), nonEmptyString]).optional(),
611
+ dateAdded: isoDate.optional(),
612
+ effect: nonEmptyString.optional(),
613
+ hazard: nonEmptyString,
614
+ harm: nonEmptyString,
615
+ // Numbered as the log numbers them, so a link can say "hazard 1, cause 10".
616
+ causes: z.array(z.object({
617
+ number: z.union([z.number().int().positive(), nonEmptyString]),
618
+ statement: nonEmptyString
619
+ }).passthrough()).optional(),
620
+ initialRisk: RiskSchema.optional(),
621
+ residualRisk: RiskSchema.optional(),
622
+ assessedBy: person,
623
+ assessedOn: isoDate.optional(),
624
+ status: z.enum(['proposed', 'open', 'closed', 'transferred']),
625
+ owner: person,
626
+ reference,
627
+ outsideReferences,
628
+ ...review
629
+ }).passthrough()
630
+
631
+ // What is done to reduce a hazard's risk. The log's three kinds; a test is
632
+ // not a kind of control but the proof one works, so it is a verified-by link
633
+ // to the finding.
634
+ const ControlSchema = z.object({
635
+ id,
636
+ statement: nonEmptyString,
637
+ kind: z.enum(['hit-design', 'user-training', 'business-process']),
638
+ // Existing controls are counted in the initial risk; additional ones are
639
+ // what takes it to the residual risk.
640
+ stage: z.enum(['existing', 'additional']),
641
+ status: z.enum(['proposed', 'in-place', 'verified']),
642
+ owner: person,
643
+ reference,
644
+ outsideReferences,
645
+ ...review
646
+ }).passthrough()
647
+
648
+ // A prototype component: a Nunjucks macro file, or one macro in it, that a
649
+ // production team ports. Screens are as far down as the knowledge base used to
650
+ // go, so "why did this card change?" had no record to answer it. A component is
651
+ // what a decision, requirement or finding is `realised-in`, and the production
652
+ // side reads `productionPath` and `portedFromCommit` to compare its copy with
653
+ // the prototype since the port.
654
+ const ComponentSchema = z.object({
655
+ id,
656
+ title: nonEmptyString,
657
+ // The component's file in the prototype, from the project root.
658
+ prototypePath: nonEmptyString,
659
+ macros: z.array(nonEmptyString).optional(),
660
+ // Its usage guide, from the project root.
661
+ guide: nonEmptyString.optional(),
662
+ screenIds: z.array(id).optional(),
663
+ // Where production keeps its port, and the prototype commit it was ported
664
+ // from. Either may be unknown, and usually is until the port happens.
665
+ productionPath: nonEmptyString.optional(),
666
+ portedFromCommit: z.string().regex(/^[0-9a-f]{7,40}$/, 'Use a git commit hash').optional(),
667
+ reference,
668
+ ...review
478
669
  }).passthrough()
479
670
 
480
671
  const RelationshipSchema = z.object({
@@ -522,12 +713,34 @@ const RelationshipSchema = z.object({
522
713
  // or finding that weakens it - "supported-by" for a contradiction reads
523
714
  // as the opposite of what it means.
524
715
  'rests-on', // design action, decision or requirement -> assumption
525
- 'challenged-by' // assumption, decision or requirement -> evidence or insight
716
+ 'challenged-by', // assumption, decision or requirement -> evidence or insight
717
+ // What changed a component, and why. Points from the reason to the
718
+ // component, with the commit or pull request that made the change, so a
719
+ // production team comparing its port can ask why the prototype moved.
720
+ 'realised-in', // decision, requirement, design action or insight -> component
721
+ // Intended purpose, hazards and controls (release 3). Each points from
722
+ // the record that depends to the one it depends on, like the rest.
723
+ 'bounded-by', // requirement -> intended purpose it keeps the product inside
724
+ 'assessed-against-purpose', // decision -> intended purpose (assessment)
725
+ 'identified-from', // hazard -> finding, evidence or scenario it was found in
726
+ 'mitigates', // control -> hazard (cause)
727
+ // A design action counts: it is how work on a control is tracked before
728
+ // anything is decided or built.
729
+ 'implemented-by' // control -> requirement, decision, design action, screen or component
526
730
  ]),
527
731
  to: id,
528
732
  // How a decision fares against a requirement, or what an evaluation found.
529
733
  outcome: z.enum(['meets', 'partly', 'fails', 'not-assessed']).optional(),
530
- note: nonEmptyString.optional()
734
+ note: nonEmptyString.optional(),
735
+ // On an assessed-against-purpose link: the decision is within the intended
736
+ // purpose, changes it, or falls outside it.
737
+ assessment: z.enum(['within', 'changes', 'outside']).optional(),
738
+ // On a mitigates or identified-from link: which of the hazard's causes.
739
+ cause: z.union([z.number().int().positive(), nonEmptyString]).optional(),
740
+ // On a realised-in link: the change that did it.
741
+ commit: z.string().regex(/^[0-9a-f]{7,40}$/, 'Use a git commit hash').optional(),
742
+ pr: nonEmptyString.optional(),
743
+ ...review
531
744
  }).passthrough()
532
745
 
533
746
  const ResearchImportDraftSchema = z.object({
@@ -591,6 +804,10 @@ const KnowledgeSchema = z.object({
591
804
  qualityObjectives: z.array(QualityObjectiveSchema).default([]),
592
805
  requirements: z.array(RequirementSchema).default([]),
593
806
  principles: z.array(PrincipleSchema).default([]),
807
+ components: z.array(ComponentSchema).default([]),
808
+ intendedPurposes: z.array(IntendedPurposeSchema).default([]),
809
+ hazards: z.array(HazardSchema).default([]),
810
+ controls: z.array(ControlSchema).default([]),
594
811
  relationships: z.array(RelationshipSchema).default([])
595
812
  }).strict()
596
813
 
@@ -615,6 +832,10 @@ const recordSchemas = {
615
832
  qualityObjectives: QualityObjectiveSchema,
616
833
  requirements: RequirementSchema,
617
834
  principles: PrincipleSchema,
835
+ components: ComponentSchema,
836
+ intendedPurposes: IntendedPurposeSchema,
837
+ hazards: HazardSchema,
838
+ controls: ControlSchema,
618
839
  relationships: RelationshipSchema
619
840
  }
620
841