All files / src/lib journey-flows.ts

100% Statements 24/24
100% Branches 4/4
100% Functions 10/10
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598                                                                                                                                                      4x 4x 4x     4x 4x 4x 4x 4x     4x   4x                                                                                                                                                                                                                                                                                                                                                                                                                                 4x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         4x       1860x                 725x 725x 725x         2x         10x 22x 21x           2x 22x 21x      
/**
 * The two journeys of the HL7 showcase deck (slides "Demo 1" and "Demo 2",
 * ui/public/presentations/hl7-showcase-2026/index.html) as data, so the start
 * page draws them with React rather than copying the deck's SVG.
 *
 * Coordinates are the deck's, in a 1600 x 650 viewBox: five lanes of 116 px,
 * boxes of 210 x 66. Every text is English and a key of the "home"
 * dictionary; __tests__/unit/components/JourneyFlows.test.tsx checks that.
 */
 
export type FlowId = "primary" | "secondary";
 
export type Point = readonly [number, number];
 
export interface FlowLane {
  /** Lines of the lane's label, top to bottom. */
  label: readonly string[];
  color: string;
}
 
export interface FlowNode {
  /** The step's number as the deck shows it ("1", "4b"); none for a step with no number. */
  step?: string;
  title: string;
  sub: string;
  /** Top-left corner of the box. */
  x: number;
  y: number;
  /** The lane the box sits in, by index; it gives the border colour. */
  lane: number;
  /** Seconds after the drawing starts. */
  delay: number;
  /** A page of the demo, or an anchor on the start page. */
  href?: string;
  /** How far the hub and the app implement the step; none for the starting
   *  point. The journey's page under /docs/ehds says why, step by step. */
  status?: StepStatus;
}
 
/** The statuses of docs/ehds/person-journey.md and researcher-journey.md:
 *  a step that is planned, not partial, has nothing to show yet. */
export type StepStatus = "implemented" | "partial" | "planned";
 
export interface FlowEdge {
  points: readonly Point[];
  delay: number;
  dashed?: boolean;
  label?: {
    text: string;
    x: number;
    y: number;
    anchor: "start" | "middle" | "end";
  };
}
 
export interface JourneyFlow {
  id: FlowId;
  eyebrow: string;
  title: string;
  tab: string;
  /** The panel's background, the deck's slide gradient. */
  background: string;
  /** Colour of the eyebrow. */
  accent: string;
  footnote: string;
  /** The flow's slide in the HL7 showcase deck. */
  deckSlide: string;
  /** The journey step by step, with what is implemented, planned and not
   *  planned: a page under /docs/ehds. */
  details: string;
  lanes: readonly FlowLane[];
  nodes: readonly FlowNode[];
  edges: readonly FlowEdge[];
}
 
export const FLOW_VIEWBOX = { width: 1600, height: 650 } as const;
export const BOX = { width: 210, height: 66 } as const;
export const LANE = { top: 20, height: 116, gap: 8 } as const;
 
/** The box's border and the lane's colour, in lane order. */
const PERSON = "#f0b27a";
const SOURCE = "#e07a5f";
const PHONE = "#7fb3e6";
const RECORD = "#7fd1bf";
const CLOUD = "#c9a0dc";
 
/** Where steps 2 to 6 of the first journey lead: the app, further down. */
const KLARBEFUND = "#klarbefund-title";
 
const PRIMARY: JourneyFlow = {
  id: "primary",
  eyebrow: "Demo 1 · primary use · the first end of the AI",
  title: "The person's journey: from a paper result to a record they control",
  tab: "Primary use: the person",
  background: "linear-gradient(135deg, #0d3b3a 0%, #14213d 70%)",
  accent: "#7fd1bf",
  footnote: "Synthetic data and invented reports; the phone app is Klarbefund.",
  deckSlide: "#/2",
  details: "/docs/ehds/person-journey",
  lanes: [
    { label: ["The person"], color: PERSON },
    { label: ["Study centre", "or laboratory"], color: SOURCE },
    { label: ["Klarbefund", "on the phone"], color: PHONE },
    { label: ["Doctor and", "patient record"], color: RECORD },
    { label: ["Dataspace", "in the cloud"], color: CLOUD },
  ],
  nodes: [
    {
      step: "1",
      title: "Result on paper",
      sub: "or as a PDF, no API",
      x: 215,
      y: 169,
      lane: 1,
      delay: 0.2,
    },
    {
      step: "2",
      title: "Scan or import",
      status: "implemented",
      sub: "read on the device",
      x: 215,
      y: 293,
      lane: 2,
      delay: 0.55,
      href: KLARBEFUND,
    },
    {
      step: "3",
      title: "Coded, checkable",
      status: "implemented",
      sub: "LOINC, UCUM, page and line",
      x: 475,
      y: 293,
      lane: 2,
      delay: 0.9,
      href: KLARBEFUND,
    },
    {
      step: "4",
      title: "Trend and band",
      status: "implemented",
      sub: "published range, sourced",
      x: 735,
      y: 293,
      lane: 2,
      delay: 1.25,
      href: KLARBEFUND,
    },
    {
      step: "5",
      title: "Export",
      status: "implemented",
      sub: "FHIR R4 bundle + PDF",
      x: 995,
      y: 293,
      lane: 2,
      delay: 1.6,
      href: KLARBEFUND,
    },
    {
      step: "6",
      title: "To the ePA, the GP",
      status: "partial",
      sub: "PDF + bundle",
      x: 995,
      y: 417,
      lane: 3,
      delay: 1.95,
      href: KLARBEFUND,
    },
    {
      step: "7",
      title: "Sign in with d-you",
      status: "partial",
      sub: "EUDI wallet, own record",
      x: 475,
      y: 45,
      lane: 0,
      delay: 2.3,
      href: "/auth/eudi-qr",
    },
    {
      step: "8",
      title: "Consent or opt out",
      status: "implemented",
      sub: "for research, revocable",
      x: 835,
      y: 45,
      lane: 0,
      delay: 2.65,
      href: "/patient/research",
    },
    {
      step: "9",
      title: "My EHDS record",
      status: "implemented",
      sub: "FHIR in the graph, coded",
      x: 1275,
      y: 541,
      lane: 4,
      delay: 3.0,
      href: "/overview",
    },
    {
      step: "10",
      title: "What came back",
      status: "implemented",
      sub: "aggregate only, k ≥ 5",
      x: 1275,
      y: 45,
      lane: 0,
      delay: 3.35,
      href: "/patient/insights",
    },
  ],
  edges: [
    {
      points: [
        [320, 235],
        [320, 285],
      ],
      delay: 0.55,
      label: { text: "hands over", x: 330, y: 254, anchor: "start" },
    },
    {
      points: [
        [425, 326],
        [467, 326],
      ],
      delay: 0.9,
    },
    {
      points: [
        [685, 326],
        [727, 326],
      ],
      delay: 1.25,
    },
    {
      points: [
        [945, 326],
        [987, 326],
      ],
      delay: 1.6,
    },
    {
      points: [
        [1100, 359],
        [1100, 409],
      ],
      delay: 1.95,
      label: { text: "the person shares", x: 1090, y: 390, anchor: "end" },
    },
    {
      points: [
        [1205, 340],
        [1228, 340],
        [1228, 592],
        [1267, 592],
      ],
      delay: 3.0,
      label: { text: "sent to my record", x: 1220, y: 503, anchor: "end" },
    },
    {
      points: [
        [685, 78],
        [827, 78],
      ],
      delay: 2.65,
    },
    {
      points: [
        [1020, 111],
        [1020, 165],
        [1250, 165],
        [1250, 556],
        [1267, 556],
      ],
      delay: 3.0,
      label: {
        text: "honoured at extraction",
        x: 1030,
        y: 190,
        anchor: "start",
      },
    },
    {
      points: [
        [1380, 541],
        [1380, 119],
      ],
      delay: 3.35,
      label: { text: "findings return", x: 1390, y: 531, anchor: "start" },
    },
  ],
};
 
const SECONDARY: JourneyFlow = {
  id: "secondary",
  eyebrow: "Demo 2 · secondary use · governance in the query path",
  title: "The researcher's journey: from registration to an audited result",
  tab: "Secondary use: the researcher",
  background: "linear-gradient(135deg, #3a2a10 0%, #14213d 70%)",
  accent: "#f0b27a",
  footnote:
    "Synthetic data, real protocols: DSP 2025-1 · DCP 1.0 · HealthDCAT-AP Release 8 · ODRL 2.2 · FHIR R4 · OMOP 5.4",
  deckSlide: "#/4",
  details: "/docs/ehds/researcher-journey",
  lanes: [
    { label: ["Registration", "and trust"], color: PERSON },
    { label: ["Data holder", "(hospital)"], color: SOURCE },
    { label: ["Data user", "(researcher)"], color: PHONE },
    { label: ["Health Data", "Access Body"], color: RECORD },
    { label: ["Secure processing", "environment"], color: CLOUD },
  ],
  nodes: [
    {
      step: "1a",
      title: "Hospital registers",
      status: "implemented",
      sub: "did:web + credential",
      x: 195,
      y: 45,
      lane: 0,
      delay: 0.2,
      href: "/onboarding",
    },
    {
      step: "1b",
      title: "Researcher registers",
      status: "implemented",
      sub: "did:web + credential",
      x: 515,
      y: 45,
      lane: 0,
      delay: 0.55,
      href: "/onboarding",
    },
    {
      step: "1c",
      title: "HDAB registers",
      status: "implemented",
      sub: "did:web + credential",
      x: 1135,
      y: 45,
      lane: 0,
      delay: 0.9,
      href: "/onboarding",
    },
    {
      step: "2",
      title: "Publish data",
      status: "implemented",
      sub: "HealthDCAT-AP catalogue",
      x: 195,
      y: 169,
      lane: 1,
      delay: 1.25,
      href: "/data/share",
    },
    {
      step: "3",
      title: "Discover data",
      status: "partial",
      sub: "federated catalogue",
      x: 515,
      y: 293,
      lane: 2,
      delay: 1.6,
      href: "/data/discover",
    },
    {
      step: "4",
      title: "Negotiate contract",
      status: "implemented",
      sub: "DSP offer, accept, finalise",
      x: 785,
      y: 293,
      lane: 2,
      delay: 1.95,
      href: "/negotiate",
    },
    {
      step: "4b",
      title: "Approve data permit",
      status: "implemented",
      sub: "Art. 68, opt-out checked",
      x: 875,
      y: 417,
      lane: 3,
      delay: 2.3,
      href: "/compliance",
    },
    {
      step: "5",
      title: "Extract and upload",
      status: "partial",
      sub: "FHIR, pseudonymised",
      x: 875,
      y: 169,
      lane: 1,
      delay: 2.65,
      href: "/data/transfer",
    },
    {
      title: "Provision SPE",
      status: "partial",
      sub: "and ingest the data",
      x: 1135,
      y: 541,
      lane: 4,
      delay: 3.0,
      href: "/data/transfer",
    },
    {
      step: "6",
      title: "Analyse in the SPE",
      status: "partial",
      sub: "OMOP, pseudonyms only",
      x: 1135,
      y: 293,
      lane: 2,
      delay: 3.35,
      href: "/analytics",
    },
    {
      step: "7",
      title: "Share results",
      status: "implemented",
      sub: "OMOP output, plain-language",
      x: 1375,
      y: 293,
      lane: 2,
      delay: 3.7,
      href: "/query",
    },
    {
      step: "8",
      title: "Audit report",
      status: "partial",
      sub: "FHIR AuditEvent, chained",
      x: 1375,
      y: 417,
      lane: 3,
      delay: 4.05,
      href: "/admin/audit",
    },
  ],
  edges: [
    {
      points: [
        [300, 111],
        [300, 161],
      ],
      delay: 1.25,
      label: { text: "registers", x: 310, y: 130, anchor: "start" },
    },
    {
      points: [
        [620, 111],
        [620, 285],
      ],
      delay: 1.6,
      label: { text: "registers", x: 630, y: 130, anchor: "start" },
    },
    {
      points: [
        [1240, 111],
        [1240, 403],
        [980, 403],
        [980, 409],
      ],
      delay: 2.3,
      label: { text: "registers", x: 1250, y: 130, anchor: "start" },
    },
    {
      points: [
        [300, 235],
        [300, 279],
        [620, 279],
        [620, 285],
      ],
      delay: 1.6,
      label: { text: "publishes DCAT", x: 310, y: 254, anchor: "start" },
    },
    {
      points: [
        [725, 326],
        [777, 326],
      ],
      delay: 1.95,
      label: { text: "requests access", x: 755, y: 377, anchor: "middle" },
    },
    {
      points: [
        [890, 359],
        [890, 409],
      ],
      delay: 2.3,
      label: { text: "requests permit", x: 900, y: 378, anchor: "start" },
    },
    {
      points: [
        [980, 417],
        [980, 243],
      ],
      delay: 2.65,
      label: { text: "authorises access", x: 990, y: 407, anchor: "start" },
    },
    {
      points: [
        [980, 235],
        [980, 527],
        [1240, 527],
        [1240, 533],
      ],
      delay: 3.0,
      label: { text: "uploads FHIR", x: 990, y: 254, anchor: "start" },
    },
    {
      points: [
        [980, 483],
        [980, 527],
        [1240, 527],
        [1240, 533],
      ],
      delay: 3.0,
      dashed: true,
      label: { text: "authorises SPE", x: 990, y: 502, anchor: "start" },
    },
    {
      points: [
        [1240, 541],
        [1240, 367],
      ],
      delay: 3.35,
      label: { text: "enables analysis", x: 1250, y: 531, anchor: "start" },
    },
    {
      points: [
        [1345, 326],
        [1367, 326],
      ],
      delay: 3.7,
      label: { text: "OMOP results", x: 1360, y: 377, anchor: "middle" },
    },
    {
      points: [
        [1480, 359],
        [1480, 409],
      ],
      delay: 4.05,
      dashed: true,
      label: { text: "reports use", x: 1490, y: 378, anchor: "start" },
    },
  ],
};
 
export const JOURNEY_FLOWS: readonly JourneyFlow[] = [PRIMARY, SECONDARY];
 
/** The SVG path through a polyline. */
export function pathOf(points: readonly Point[]): string {
  return points.map(([x, y], i) => `${i ? "L" : "M"}${x},${y}`).join(" ");
}
 
/** Where an edge ends and the angle, in degrees, of its last segment. */
export function arrowHead(points: readonly Point[]): {
  x: number;
  y: number;
  angle: number;
} {
  const [x0, y0] = points[points.length - 2];
  const [x, y] = points[points.length - 1];
  return { x, y, angle: (Math.atan2(y - y0, x - x0) * 180) / Math.PI };
}
 
/** Every text a flow shows, for the dictionaries. */
export function flowTexts(flow: JourneyFlow): string[] {
  return [
    flow.eyebrow,
    flow.title,
    flow.tab,
    flow.footnote,
    ...flow.lanes.flatMap((l) => l.label),
    ...flow.nodes.flatMap((n) => [n.title, n.sub]),
    ...flow.edges.flatMap((e) => (e.label ? [e.label.text] : [])),
  ];
}
 
/** Seconds until the last box and arrow of a flow are in. */
export function flowDuration(flow: JourneyFlow): number {
  return Math.max(
    ...flow.nodes.map((n) => n.delay + 0.5),
    ...flow.edges.map((e) => e.delay + 1.1),
  );
}