@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.
@@ -1,12 +1,15 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
  const { createContextOrExit } = require('../lib/context')
4
+ const { COLLECTION_FILES } = require('../lib/collections')
4
5
  const {
5
6
  CURRENT_SCHEMA_VERSION,
6
7
  META_FILENAME,
7
8
  readMeta,
8
9
  migrateInMemory,
9
- writeMeta
10
+ writeMeta,
11
+ unrecordedLevel,
12
+ recordLevelNeeded
10
13
  } = require('../lib/schema-version')
11
14
 
12
15
  // The loader migrates in memory and warns on every read. This is the command
@@ -16,43 +19,40 @@ const {
16
19
  const ctx = createContextOrExit()
17
20
  const dryRun = process.argv.includes('--dry-run')
18
21
 
19
- const collectionFiles = {
20
- users: 'users.json',
21
- needs: 'needs.json',
22
- scenarios: 'scenarios.json',
23
- journeys: 'journeys.json',
24
- screens: 'screens.json',
25
- evidence: 'evidence.json',
26
- decisions: 'decisions.json',
27
- assumptions: 'assumptions.json',
28
- researchRounds: 'research-rounds.json',
29
- participants: 'participants.json',
30
- insights: 'insights.json',
31
- designActions: 'design-actions.json',
32
- goals: 'goals.json',
33
- qualityObjectives: 'quality-objectives.json',
34
- requirements: 'requirements.json',
35
- principles: 'principles.json',
36
- relationships: 'relationships.json'
37
- }
22
+ // The same list every other command reads, minus the two single objects.
23
+ const collectionFiles = Object.fromEntries(
24
+ Object.entries(COLLECTION_FILES).filter(([key]) => key !== 'project' && key !== 'projectContext')
25
+ )
38
26
 
39
27
  function main () {
40
28
  for (const project of ctx.requireProjects()) {
41
29
  const sourceDir = path.join(project.dir, 'source')
42
30
  const meta = readMeta(sourceDir)
43
31
 
44
- if (meta.schemaVersion === CURRENT_SCHEMA_VERSION && !meta.implicit) {
45
- console.log(`${project.name}: already at schemaVersion ${CURRENT_SCHEMA_VERSION}`)
46
- continue
47
- }
48
-
49
32
  const raw = {}
50
33
  for (const [key, filename] of Object.entries(collectionFiles)) {
51
34
  const filePath = path.join(sourceDir, filename)
52
35
  raw[key] = fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath, 'utf8')) : []
53
36
  }
37
+
38
+ if (meta.schemaVersion === CURRENT_SCHEMA_VERSION && !meta.implicit) {
39
+ // Nothing to migrate, but records added by hand may need a package level
40
+ // that _meta.json does not record yet. validate points here for that.
41
+ const unrecorded = unrecordedLevel(sourceDir, raw)
42
+ if (!unrecorded) {
43
+ console.log(`${project.name}: already at schemaVersion ${CURRENT_SCHEMA_VERSION}`)
44
+ } else if (dryRun) {
45
+ console.log(`${project.name}: would record that it needs Hippocampus ${unrecorded.level} (uses ${unrecorded.features.join(', ')})`)
46
+ } else {
47
+ recordLevelNeeded(sourceDir, raw)
48
+ console.log(`${project.name}: recorded that it needs Hippocampus ${unrecorded.level} (uses ${unrecorded.features.join(', ')})`)
49
+ }
50
+ continue
51
+ }
52
+
54
53
  raw.project = JSON.parse(fs.readFileSync(path.join(sourceDir, 'project.json'), 'utf8'))
55
- raw.projectContext = JSON.parse(fs.readFileSync(path.join(sourceDir, 'project-context.json'), 'utf8'))
54
+ const contextPath = path.join(sourceDir, 'project-context.json')
55
+ raw.projectContext = JSON.parse(fs.readFileSync(contextPath, 'utf8'))
56
56
 
57
57
  const { data, version } = migrateInMemory(raw, meta)
58
58
 
@@ -69,6 +69,7 @@ function main () {
69
69
  fs.writeFileSync(filePath, JSON.stringify(data[key], null, 2) + '\n')
70
70
  }
71
71
  writeMeta(sourceDir, { generator: 'hippocampus migrate:knowledge' })
72
+ recordLevelNeeded(sourceDir, data)
72
73
  console.log(`${project.name}: migrated ${meta.schemaVersion} -> ${version}, ${META_FILENAME} stamped`)
73
74
  }
74
75
  }
@@ -7,13 +7,15 @@
7
7
  * Refuses a draft that fails any check, whose `after` drafts are not in yet,
8
8
  * or that has no reviewer. A reviewer is someone other than the draft's author:
9
9
  * if the draft names its author in `draftedBy`, the two cannot be the same.
10
- * Records who reviewed it, and when, in hippocampus/manifests/drafts.json.
10
+ * Records who reviewed it, and when, in hippocampus/manifests/drafts.json and
11
+ * on each record it adds, so a trace can show it.
11
12
  */
12
13
  const fs = require('fs')
13
14
  const path = require('path')
14
15
  const { createContextOrExit } = require('../lib/context')
15
16
  const { COLLECTION_FILES } = require('../lib/collections')
16
17
  const { recordLevelNeeded } = require('../lib/schema-version')
18
+ const { stampReview, samePerson } = require('../lib/review')
17
19
  const { analyseDraft, readManifest, writeManifest, resolveFromRoot, relative, summaryLines, parseArgs } = require('./lib/draft')
18
20
 
19
21
  const ctx = createContextOrExit()
@@ -49,9 +51,15 @@ function main () {
49
51
  throw new Error('Not promoted. Say who reviewed the draft: --reviewer "<name or role>". Nothing reaches the knowledge base without a review.')
50
52
  }
51
53
  const author = result.draft.draft.draftedBy
52
- if (author && String(author).trim().toLowerCase() === reviewer.toLowerCase()) {
54
+ if (samePerson(author, reviewer)) {
53
55
  throw new Error(`Not promoted. ${reviewer} drafted this, so cannot also be its reviewer.`)
54
56
  }
57
+ // A record can name its own drafter. The same rule holds for it.
58
+ const selfReviewed = Object.values(result.draft.records).flat()
59
+ .filter((record) => samePerson(record.draftedBy, reviewer) && !record.reviewedBy)
60
+ if (selfReviewed.length) {
61
+ throw new Error(`Not promoted. ${reviewer} drafted ${selfReviewed.map((r) => r.id).join(', ')}, so cannot also review them.`)
62
+ }
55
63
 
56
64
  if (args.dryRun) {
57
65
  console.log('\nDry run. Every check passed; nothing was written.')
@@ -63,7 +71,7 @@ function main () {
63
71
  for (const [collection, records] of Object.entries(result.draft.records)) {
64
72
  const file = path.join(dir, COLLECTION_FILES[collection])
65
73
  const current = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : []
66
- const next = [...current, ...records]
74
+ const next = [...current, ...stampReview(records, { draftedBy: result.draft.draft.draftedBy, reviewer })]
67
75
  fs.writeFileSync(file, `${JSON.stringify(next, null, 2)}\n`)
68
76
  merged[collection] = next
69
77
  }
@@ -4,6 +4,8 @@ const { spawnSync } = require('child_process')
4
4
  const { ResearchImportDraftSchema } = require('../lib/schema')
5
5
  const { readAllRecordIds } = require('../lib/collections')
6
6
  const { createContextOrExit } = require('../lib/context')
7
+ const { stampReview } = require('../lib/review')
8
+ const { recordLevelNeeded } = require('../lib/schema-version')
7
9
  const ctx = createContextOrExit()
8
10
  const { knowledgeSourceDir, researchImportsDir, researchManifestPath } = ctx.paths
9
11
 
@@ -20,7 +22,7 @@ const collections = {
20
22
  function main () {
21
23
  const args = parseArgs(process.argv.slice(2))
22
24
  if (!args.draft || args.draft === true) {
23
- throw new Error(`Usage: npx hippocampus promote research --draft ${path.relative(ctx.root, path.join(researchImportsDir, '<draft>.json'))} [--dry-run]`)
25
+ throw new Error(`Usage: npx hippocampus promote research --draft ${path.relative(ctx.root, path.join(researchImportsDir, '<draft>.json'))} [--reviewer "<name or role>"] [--dry-run]`)
24
26
  }
25
27
 
26
28
  const draftPath = resolveDraft(args.draft)
@@ -33,6 +35,16 @@ function main () {
33
35
  return
34
36
  }
35
37
 
38
+ // Optional here, unlike `draft promote`: research drafts were promoted
39
+ // without one before this existed. Given, it is written onto every record
40
+ // the draft adds, so the trace shows the finding was checked.
41
+ const reviewer = typeof args.reviewer === 'string' ? args.reviewer.trim() : ''
42
+ if (reviewer) {
43
+ for (const key of Object.keys(collections)) {
44
+ if (Array.isArray(draft[key])) draft[key] = stampReview(draft[key], { reviewer })
45
+ }
46
+ }
47
+
36
48
  const { reused, notes } = reconcileSharedRecords(current, draft)
37
49
  const proposed = mergeCollections(current, draft)
38
50
  validateNoDuplicateIds(current, draft)
@@ -52,6 +64,10 @@ function main () {
52
64
  for (const [key, filename] of Object.entries(collections)) {
53
65
  writeJson(path.join(dataDir, filename), proposed[key])
54
66
  }
67
+ // Before validation, so a package that predates what this draft uses
68
+ // refuses the knowledge base with an upgrade message, not a schema error.
69
+ const level = recordLevelNeeded(dataDir, proposed)
70
+ if (level) console.log(`This knowledge base now needs Hippocampus ${level} or later. Recorded in _meta.json.`)
55
71
 
56
72
  // Run the sibling script directly rather than `npm run <script>`. Those npm
57
73
  // scripts exist in this repo and in the demo, and in no host that installs the
@@ -65,6 +65,8 @@ function buildRoutes (basePath, knowledge) {
65
65
  `${basePath}/context`,
66
66
  `${basePath}/requirements`,
67
67
  `${basePath}/design`,
68
+ `${basePath}/components`,
69
+ `${basePath}/safety`,
68
70
  `${basePath}/evaluation`,
69
71
  `${basePath}/research?method=usability-test`,
70
72
  `${basePath}/project`,
@@ -110,7 +112,11 @@ function buildRoutes (basePath, knowledge) {
110
112
  { items: knowledge.principles, path: 'principles' },
111
113
  { items: knowledge.decisions, path: 'decisions' },
112
114
  { items: knowledge.goals, path: 'goals' },
113
- { items: knowledge.qualityObjectives, path: 'objectives' }
115
+ { items: knowledge.qualityObjectives, path: 'objectives' },
116
+ { items: knowledge.components, path: 'components' },
117
+ { items: knowledge.intendedPurposes, path: 'intended-purpose' },
118
+ { items: knowledge.hazards, path: 'hazards' },
119
+ { items: knowledge.controls, path: 'controls' }
114
120
  ]) {
115
121
  for (const item of (collection.items || []).slice(0, 3)) {
116
122
  routes.add(`${basePath}/${collection.path}/${item.id}`)
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Write the trace for a release: a readable page, the trace tables as CSV, the
4
+ * gaps, and a baseline that fingerprints every source file it was made from.
5
+ *
6
+ * npx hippocampus trace export [--release <label>] [--out <dir>]
7
+ *
8
+ * Writes to hippocampus/trace/<release or today>/ by default - a folder meant
9
+ * to be committed, and attached to a safety case. Changes nothing in source.
10
+ * Check it still describes the knowledge base later with `trace verify`.
11
+ */
12
+ const path = require('path')
13
+ const { createContextOrExit } = require('../lib/context')
14
+ const { buildTrace, buildBaseline, writeTraceExport } = require('../lib/trace')
15
+ const { version } = require('../package.json')
16
+ const { parseArgs } = require('./lib/draft')
17
+
18
+ const ctx = createContextOrExit()
19
+
20
+ function main () {
21
+ const args = parseArgs(process.argv.slice(2))
22
+ const release = typeof args.release === 'string' ? args.release.trim() : ''
23
+ if (release && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(release)) {
24
+ throw new Error('--release takes a short label such as 2026-12 or r17: letters, numbers, dots, dashes and underscores.')
25
+ }
26
+
27
+ for (const project of ctx.requireProjects()) {
28
+ const result = project.store.validateKnowledge()
29
+ if (!result.valid) {
30
+ throw new Error(`${project.name}: knowledge data is invalid, so no trace was written. Run \`npx hippocampus validate\` to see why.`)
31
+ }
32
+ const knowledge = project.store.getKnowledge()
33
+ const knowledgeSourceDir = path.join(project.dir, 'source')
34
+ const outDir = typeof args.out === 'string'
35
+ ? path.resolve(ctx.root, args.out)
36
+ : path.join(project.dir, 'trace', release || new Date().toISOString().slice(0, 10))
37
+
38
+ const trace = buildTrace(knowledge)
39
+ const baseline = buildBaseline({ knowledgeSourceDir, root: ctx.root, packageVersion: version, release })
40
+ const files = writeTraceExport({
41
+ outDir,
42
+ trace,
43
+ baseline,
44
+ title: `${knowledge.project.name}: trace${release ? ` for ${release}` : ''}`
45
+ })
46
+
47
+ const where = path.relative(ctx.root, outDir) || '.'
48
+ console.log(`${project.name}: wrote ${files.join(', ')} to ${where}`)
49
+ console.log(` ${trace.requirements.length} requirements, ${trace.components.length} components, ${trace.hazards.length} hazards, ${trace.gaps.length} gaps`)
50
+ if (baseline.git.sourceUncommitted) {
51
+ console.log(' note the knowledge base has uncommitted changes. The fingerprints in baseline.json describe what was read; commit first if the commit should too.')
52
+ }
53
+ }
54
+ }
55
+
56
+ try {
57
+ main()
58
+ } catch (error) {
59
+ console.error(error.message)
60
+ process.exit(1)
61
+ }
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Does a trace export still describe the knowledge base?
4
+ *
5
+ * npx hippocampus trace verify --baseline hippocampus/trace/<release>/baseline.json
6
+ *
7
+ * Compares the fingerprints in the baseline with the source files now. Exits 1
8
+ * and lists the files when any has changed, been added or been removed.
9
+ */
10
+ const fs = require('fs')
11
+ const path = require('path')
12
+ const { createContextOrExit } = require('../lib/context')
13
+ const { compareBaseline } = require('../lib/trace')
14
+ const { parseArgs, resolveFromRoot } = require('./lib/draft')
15
+
16
+ const ctx = createContextOrExit()
17
+
18
+ function main () {
19
+ const args = parseArgs(process.argv.slice(2))
20
+ if (!args.baseline || args.baseline === true) {
21
+ throw new Error('Usage: npx hippocampus trace verify --baseline hippocampus/trace/<release>/baseline.json')
22
+ }
23
+ const file = resolveFromRoot(ctx, args.baseline)
24
+ if (!file) throw new Error(`No baseline at ${args.baseline}.`)
25
+ const baseline = JSON.parse(fs.readFileSync(file, 'utf8'))
26
+ if (!Array.isArray(baseline.files)) throw new Error(`${args.baseline} is not a trace baseline: it lists no files.`)
27
+
28
+ const [project] = ctx.requireProjects()
29
+ const result = compareBaseline(baseline, { knowledgeSourceDir: path.join(project.dir, 'source'), root: ctx.root })
30
+ if (result.matches) {
31
+ console.log(`Matches: every source file is as it was when the trace was made (${baseline.generatedAt}).`)
32
+ return
33
+ }
34
+ console.log(`Does not match the knowledge base made on ${baseline.generatedAt}:`)
35
+ for (const name of result.changed) console.log(` changed ${name}`)
36
+ for (const name of result.added) console.log(` added ${name}`)
37
+ for (const name of result.removed) console.log(` removed ${name}`)
38
+ console.log('Export the trace again if this release should describe the knowledge base as it is now.')
39
+ process.exit(1)
40
+ }
41
+
42
+ try {
43
+ main()
44
+ } catch (error) {
45
+ console.error(error.message)
46
+ process.exit(1)
47
+ }
@@ -1,5 +1,7 @@
1
1
  const { createContextOrExit } = require('../lib/context')
2
+ const path = require('path')
2
3
  const { lintKnowledge } = require('../lib/lint-knowledge')
4
+ const { unrecordedLevel } = require('../lib/schema-version')
3
5
 
4
6
  const ctx = createContextOrExit()
5
7
  const strict = process.argv.includes('--strict')
@@ -28,6 +30,14 @@ function main () {
28
30
  console.log(`${project.name}: knowledge data is valid`)
29
31
 
30
32
  for (const warning of warnings) console.warn(` warning ${warning.message}`)
33
+
34
+ // Records added by hand bypass the commands that record the level, and an
35
+ // older package then fails on them with a schema error, not an upgrade.
36
+ const unrecorded = unrecordedLevel(path.join(project.dir, 'source'), knowledge)
37
+ if (unrecorded) {
38
+ console.warn(` warning uses ${unrecorded.features.join(', ')}, which need Hippocampus ${unrecorded.level}, but _meta.json does not say so. Older versions will fail on it instead of asking for an upgrade. Run \`npx hippocampus migrate\` to record it.`)
39
+ if (strict) failed = true
40
+ }
31
41
  if (!quiet) {
32
42
  for (const info of infos) console.log(` info ${info.message}`)
33
43
  }
@@ -61,10 +61,11 @@
61
61
  { href: "/plan", text: "Plan", match: ["/plan", "/project", "/objectives"] },
62
62
  { href: "/context", text: "Context of use", match: ["/context", "/users", "/goals", "/scenarios", "/journeys", "/handover"] },
63
63
  { href: "/requirements", text: "Requirements", match: ["/requirements", "/user-needs", "/needs"] },
64
- { href: "/design", text: "Design", match: ["/design", "/principles", "/decisions", "/screens", "/route-review"] },
64
+ { href: "/design", text: "Design", match: ["/design", "/principles", "/decisions", "/screens", "/components", "/route-review"] },
65
65
  { href: "/evaluation", text: "Evaluation", match: ["/evaluation", "/research", "/insights"] },
66
66
  { href: "/graph", text: "Graph", match: ["/graph"], secondary: true },
67
67
  { href: "/trace", text: "Trace", match: ["/trace"], secondary: true },
68
+ { href: "/safety", text: "Safety", match: ["/safety", "/intended-purpose", "/hazards", "/controls"], secondary: true },
68
69
  { href: "/docs", text: "Docs", match: ["/docs"], secondary: true }
69
70
  ] %}
70
71
  {% set target = basePath + item.href %}
@@ -0,0 +1,48 @@
1
+ {% extends "hippocampus/_layout.html" %}
2
+ {% from "hippocampus/components/_empty-state.njk" import emptyState %}
3
+ {% from "hippocampus/components/_filters.njk" import findBar, noMatches %}
4
+
5
+ {% block pageTitle %}Components{% endblock %}
6
+
7
+ {% block content %}
8
+ <h1>Components</h1>
9
+ <p class="nhsuk-lede-text">The prototype's components, and the decisions, requirements and findings that changed them.</p>
10
+
11
+ {% if knowledge.components.length %}
12
+ {{ findBar(basePath + "/components", "Search components",
13
+ "Title, file or macro name.",
14
+ query, facets, components.length, knowledge.components.length,
15
+ [1] if hasFilters else [], basePath + "/components") }}
16
+
17
+ {#
18
+ A table rather than cards: the question here is "which of these has no
19
+ recorded reason?", and that is a column read down, not a set of pictures.
20
+ #}
21
+ <table class="nhsuk-table">
22
+ <caption class="nhsuk-table__caption nhsuk-u-visually-hidden">Prototype components</caption>
23
+ <thead class="nhsuk-table__head">
24
+ <tr class="nhsuk-table__row">
25
+ <th scope="col" class="nhsuk-table__header">Component</th>
26
+ <th scope="col" class="nhsuk-table__header">Prototype file</th>
27
+ <th scope="col" class="nhsuk-table__header">In production</th>
28
+ <th scope="col" class="nhsuk-table__header">Reasons recorded</th>
29
+ </tr>
30
+ </thead>
31
+ <tbody class="nhsuk-table__body">
32
+ {% for component in components %}
33
+ <tr class="nhsuk-table__row">
34
+ <td class="nhsuk-table__cell"><a href="{{ basePath }}/components/{{ component.id }}">{{ component.title }}</a></td>
35
+ <td class="nhsuk-table__cell"><code>{{ component.prototypePath }}</code></td>
36
+ <td class="nhsuk-table__cell">{% if component.productionPath %}<code>{{ component.productionPath }}</code>{% else %}Not yet{% endif %}</td>
37
+ <td class="nhsuk-table__cell">{{ component.reasonCount if component.reasonCount else "None" }}</td>
38
+ </tr>
39
+ {% endfor %}
40
+ </tbody>
41
+ </table>
42
+ {% if not components.length %}{{ noMatches(basePath + "/components", "components") }}{% endif %}
43
+ {% else %}
44
+ {{ emptyState("No components yet",
45
+ "A component is a prototype macro file a production team ports, recorded with the decisions that changed it.",
46
+ "Add components and realised-in links through a draft. See the source model guide.") }}
47
+ {% endif %}
48
+ {% endblock %}
@@ -15,6 +15,7 @@
15
15
  {{ stat(knowledge.decisions.length, "Decisions", "Options considered, and what happened to each", "#decisions", false) }}
16
16
  {{ stat(design.principleCount, "Principles", "How the team has chosen to design", "#principles", false) }}
17
17
  {{ stat(design.screens.total, "Screens", "Prototype pages, each linked to the needs it meets", basePath + "/screens", false) }}
18
+ {{ stat(knowledge.components.length, "Components", "Prototype components, and what changed them", basePath + "/components", false) }}
18
19
  </div>
19
20
  </section>
20
21
 
@@ -0,0 +1,89 @@
1
+ {% extends "hippocampus/_layout.html" %}
2
+ {% from "hippocampus/components/_empty-state.njk" import emptyState %}
3
+
4
+ {% block pageTitle %}Safety{% endblock %}
5
+
6
+ {% block content %}
7
+ <h1>Safety</h1>
8
+ <p class="nhsuk-lede-text">What the service is for, what could harm a patient, and what is done about it.</p>
9
+
10
+ {% if not purposes.length and not hazards.length and not controls.length %}
11
+ {{ emptyState("Nothing recorded yet",
12
+ "An intended purpose says what the service is for and what it must not do. Hazards and controls come from your clinical safety officer's hazard log.",
13
+ "See the guide: Record the intended purpose, hazards and controls.") }}
14
+ {% else %}
15
+
16
+ {% if gaps.length %}
17
+ <div class="nhsuk-warning-callout">
18
+ <h2 class="nhsuk-warning-callout__label">{{ gaps.length }} gap{{ "" if gaps.length == 1 else "s" }} in the chain</h2>
19
+ <ul class="nhsuk-list nhsuk-list--bullet nhsuk-u-margin-bottom-0">
20
+ {% for gap in gaps %}<li><code>{{ gap.id }}</code>: {{ gap.message }}</li>{% endfor %}
21
+ </ul>
22
+ </div>
23
+ {% endif %}
24
+
25
+ <section class="knowledge-section" id="purpose">
26
+ <h2>Intended purpose</h2>
27
+ {% if purposes.length %}
28
+ <ul class="nhsuk-list">
29
+ {% for purpose in purposes %}
30
+ <li>
31
+ <a href="{{ basePath }}/intended-purpose/{{ purpose.id }}">{{ purpose.title }}</a>
32
+ <span class="knowledge-card__meta">version {{ purpose.version }}, {{ purpose.status }}{% if purpose.agreedBy %}, agreed by {{ purpose.agreedBy }}{% endif %}</span>
33
+ </li>
34
+ {% endfor %}
35
+ </ul>
36
+ {% else %}
37
+ <p>No intended purpose recorded.</p>
38
+ {% endif %}
39
+ </section>
40
+
41
+ <section class="knowledge-section" id="hazards">
42
+ <h2>Hazards</h2>
43
+ {% if scales and scales.source %}<p class="nhsuk-body-s">Risk ratings use the scales from {{ scales.source }}.</p>{% endif %}
44
+ {% if hazards.length %}
45
+ <table class="nhsuk-table">
46
+ <caption class="nhsuk-table__caption nhsuk-u-visually-hidden">Hazards</caption>
47
+ <thead class="nhsuk-table__head">
48
+ <tr class="nhsuk-table__row">
49
+ <th scope="col" class="nhsuk-table__header">Hazard</th>
50
+ <th scope="col" class="nhsuk-table__header">Status</th>
51
+ <th scope="col" class="nhsuk-table__header">Initial risk</th>
52
+ <th scope="col" class="nhsuk-table__header">Residual risk</th>
53
+ <th scope="col" class="nhsuk-table__header">Controls</th>
54
+ </tr>
55
+ </thead>
56
+ <tbody class="nhsuk-table__body">
57
+ {% for hazard in hazards %}
58
+ <tr class="nhsuk-table__row">
59
+ <td class="nhsuk-table__cell">
60
+ <a href="{{ basePath }}/hazards/{{ hazard.id }}">{{ hazard.title }}</a>
61
+ {% if hazard.logNumber %}<br><span class="nhsuk-body-s">Log number {{ hazard.logNumber }}</span>{% endif %}
62
+ </td>
63
+ <td class="nhsuk-table__cell">{{ hazard.status }}</td>
64
+ <td class="nhsuk-table__cell">{% if hazard.initialRisk %}{{ hazard.initialRisk.risk }} <span class="nhsuk-body-s">({{ hazard.initialRisk.severity }}, {{ hazard.initialRisk.likelihood }})</span>{% else %}Not rated{% endif %}</td>
65
+ <td class="nhsuk-table__cell">{% if hazard.residualRisk %}{{ hazard.residualRisk.risk }} <span class="nhsuk-body-s">({{ hazard.residualRisk.severity }}, {{ hazard.residualRisk.likelihood }})</span>{% else %}Not rated{% endif %}</td>
66
+ <td class="nhsuk-table__cell">{{ hazard.controls.length if hazard.controls.length else "None" }}</td>
67
+ </tr>
68
+ {% endfor %}
69
+ </tbody>
70
+ </table>
71
+ {% else %}
72
+ <p>No hazards recorded.</p>
73
+ {% endif %}
74
+ </section>
75
+
76
+ <section class="knowledge-section" id="controls">
77
+ <h2>Controls</h2>
78
+ {% if controls.length %}
79
+ <ul class="nhsuk-list">
80
+ {% for control in controls %}
81
+ <li><a href="{{ basePath }}/controls/{{ control.id }}">{{ control.statement }}</a> <span class="knowledge-card__meta">{{ control.stage }}, {{ control.status }}</span></li>
82
+ {% endfor %}
83
+ </ul>
84
+ {% else %}
85
+ <p>No controls recorded.</p>
86
+ {% endif %}
87
+ </section>
88
+ {% endif %}
89
+ {% endblock %}