All files / src/app/information page.tsx

96.15% Statements 25/26
75.75% Branches 50/66
100% Functions 13/13
100% Lines 24/24

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 5171x                                                                                                                                       3x       1x   1x     1x                                   42x 42x                               6x 6x 6x   6x 3x   3x 3x 1x   2x       1x       6x   6x                                                                                                                                                                                                                                                                         2x                                                                                                                                   1x                                                                                                                         1x                                                                                                                                                     8x   6x                                                                                            
"use client";
 
import { fetchApi } from "@/lib/api";
import { PURPOSE_LABELS, type Purpose } from "@/lib/permits";
import { useEffect, useState } from "react";
import Link from "next/link";
import { Info, ShieldCheck, AlertCircle } from "lucide-react";
import { T, useT } from "@/lib/i18n/translate";
 
/**
 * What the health data access body tells the public about secondary use,
 * Regulation (EU) 2025/327 Art. 58(1): (a) the legal basis, (b) the
 * safeguards, (c) the rights of natural persons, (d) how to exercise them,
 * (e) the body and how to reach it, (f) who has access to which datasets and
 * why, (g) the results of the projects. Any signed-in participant reads it
 * (ADR-044). Issue #206, M6.
 */
 
interface Body {
  name: string;
  did: string;
  country: string | null;
  contactName: string | null;
  contactEmail: string | null;
}
 
interface Access {
  permitId: string;
  applicant: string | null;
  applicantCountry: string | null;
  datasetId: string | null;
  datasetTitle: string | null;
  holder: string | null;
  purpose: string | null;
  validFrom: string | null;
  validUntil: string | null;
  status: string;
  resultsDue: string | null;
}
 
interface Result {
  resultId: string;
  applicantName: string | null;
  datasetTitle: string | null;
  kind: string;
  title: string;
  summary: string | null;
  url: string | null;
  communicatedAt: string | null;
}
 
interface Information {
  generatedAt: string;
  bodies: Body[];
  access: Access[];
  results: Result[];
  optOut: { optedOut: number; patients: number };
  retention: { months: number };
  fees: {
    currency: string;
    body: { assessment: number; perDataset: number; spePerMonth: number };
    holder: { pseudonymised: number; anonymised: number };
    requestEur: number;
    reductions: Record<string, number>;
  };
}
 
function shortDate(iso: string | null | undefined): string {
  return iso ? iso.slice(0, 10) : "—";
}
 
function purposeLabel(p: string | null, t: (s: string) => string): string {
  Iif (!p) return "—";
  const label = (PURPOSE_LABELS as Record<string, string>)[p as Purpose];
  return label ? t(label) : p;
}
 
const REDUCTION_WORDS: Record<string, string> = {
  PUBLIC_SECTOR: "public sector bodies and Union institutions",
  ACADEMIC: "universities and academic researchers",
  MICRO_ENTERPRISE: "micro-enterprises",
  COMMERCIAL: "other legal persons",
};
 
function Item({
  letter,
  title,
  children,
  testId,
}: {
  letter: string;
  title: string;
  children: React.ReactNode;
  testId: string;
}) {
  const t = useT("public");
  return (
    <section
      className="rounded-lg border border-(--border) bg-(--surface) p-4"
      data-testid={testId}
    >
      <h2 className="text-sm font-semibold mb-2 text-(--text-primary)">
        ({letter}) {t(title)}
      </h2>
      <div className="text-sm text-(--text-secondary) space-y-2">
        {children}
      </div>
    </section>
  );
}
 
export default function InformationPage() {
  const [info, setInfo] = useState<Information | null>(null);
  const [error, setError] = useState<string | null>(null);
  const t = useT("public");
 
  useEffect(() => {
    fetchApi("/api/information")
      .then(async (r) => {
        const body = await r.json();
        if (!r.ok || body?.error) {
          throw new Error(body?.detail || body?.error || `HTTP ${r.status}`);
        }
        return body as Information;
      })
      .then(setInfo)
      .catch((e: unknown) =>
        setError(e instanceof Error ? e.message : String(e)),
      );
  }, []);
 
  const issued = (info?.access ?? []).filter((a) => a.status === "APPROVED");
 
  return (
    <div className="min-h-screen bg-(--bg)">
      <div className="max-w-5xl mx-auto px-6 py-10">
        <div className="mb-8">
          <h1 className="page-header flex items-center gap-2">
            <Info size={28} />
            {t("Secondary use of health data: what you should know")}
          </h1>
          <p className="text-(--text-secondary) text-lg mt-1">
            {t(
              "Regulation (EU) 2025/327, Art. 58(1) · published by the health data access body",
            )}
          </p>
        </div>
 
        {error && (
          <div className="rounded-lg border border-(--border) bg-(--surface) p-4 text-sm flex items-start gap-2 mb-6">
            <AlertCircle size={16} className="mt-0.5" />
            <span>
              {t(
                "The parts of this page that come from the graph are unavailable: {error}",
                { error },
              )}
            </span>
          </div>
        )}
 
        <div className="grid grid-cols-1 gap-4">
          <Item
            letter="a"
            title="The legal basis on which access is granted"
            testId="info-a"
          >
            <p>
              {t(
                "Electronic health data are made available for secondary use only for the purposes of Art. 53(1) of Regulation (EU) 2025/327: public health, policy making, official statistics, education, scientific research, the improvement of care, and the development of products and services in the field of health. Access is granted by a data permit of the health data access body (Art. 68) or, for anonymised statistics, by a decision on a health data request (Art. 69). The processing rests on Art. 6(1)(e) and Art. 9(2)(h), (i) and (j) of the GDPR, as Art. 53 and Art. 68 of the Regulation provide. Uses listed in Art. 54 are prohibited: no decisions detrimental to a person, no advertising, no insurance or credit decisions, no re-identification.",
              )}
            </p>
          </Item>
 
          <Item
            letter="b"
            title="The technical and organisational measures protecting the data"
            testId="info-b"
          >
            <ul className="list-disc list-inside space-y-1">
              <li>
                {t(
                  "Data are made available only in a secure processing environment (Art. 73); no record leaves it. Outputs are aggregate, and counts below five are suppressed.",
                )}
              </li>
              <li>
                {t(
                  "Data are pseudonymised by the trust centre before they reach the environment (Art. 66); anonymised where the purpose allows.",
                )}
              </li>
              <li>
                {t(
                  "Every access and activity in the environment is logged with the permit it ran under and kept at least {months} months (Art. 73(1)(e)).",
                  { months: info?.retention.months ?? 12 },
                )}
              </li>
              <li>
                {t(
                  "A data user that does not comply is investigated and may lose its permit, be excluded or be fined (Art. 63, Art. 64); the measures are public.",
                )}
              </li>
            </ul>
          </Item>
 
          <Item
            letter="c"
            title="Your rights in relation to secondary use"
            testId="info-c"
          >
            <ul className="list-disc list-inside space-y-1">
              <li>
                {t(
                  "To opt out of the secondary use of your personal electronic health data, at any time and without giving reasons (Art. 71).",
                )}
              </li>
              <li>
                {t(
                  "To be informed, through this page, which data are used, by whom and for what (Art. 58(1)(f)), and what came of it (Art. 58(1)(g)).",
                )}
              </li>
              <li>
                {t(
                  "The rights of Chapter III of the GDPR: information, access, rectification, erasure and objection, as they apply to pseudonymised data (Art. 15 to 22 GDPR).",
                )}
              </li>
            </ul>
            {info && (
              <p data-testid="info-opt-out">
                {t(
                  "Persons who have opted out on this platform: {optedOut} of {patients}.",
                  {
                    optedOut: info.optOut.optedOut,
                    patients: info.optOut.patients,
                  },
                )}
              </p>
            )}
          </Item>
 
          <Item letter="d" title="How to exercise them" testId="info-d">
            <p>
              <T
                area="public"
                tags={{
                  a: (
                    <Link
                      href="/patient/research"
                      className="font-bold text-(--accent) hover:underline"
                    />
                  ),
                }}
              >
                {
                  "Sign in to your <a>health record</a> and use the secondary-use opt-out there; it takes effect at once for every future permit. For the GDPR rights, write to the access body named below or to the data holder that keeps your record; the body answers within one month (Art. 12(3) GDPR). A complaint may be lodged with the data protection supervisory authority."
                }
              </T>
            </p>
          </Item>
 
          <Item
            letter="e"
            title="The health data access body and how to reach it"
            testId="info-e"
          >
            {info && info.bodies.length > 0 ? (
              <ul className="space-y-1">
                {info.bodies.map((b) => (
                  <li key={b.did}>
                    <span className="font-medium text-(--text-primary)">
                      {b.name}
                    </span>
                    {b.country ? ` (${b.country})` : ""}
                    {b.country && (
                      <>
                        {" · "}
                        <Link
                          href={`/jurisdictions#${b.country.toLowerCase()}`}
                          className="text-(--accent) underline"
                        >
                          {t("national rules")}
                        </Link>
                      </>
                    )}
                    {b.contactName || b.contactEmail
                      ? ` · ${[b.contactName, b.contactEmail]
                          .filter(Boolean)
                          .join(", ")}`
                      : ""}
                    <span className="font-mono text-xs"> · {b.did}</span>
                  </li>
                ))}
              </ul>
            ) : (
              <p>MedReg DE (fictional), did:web:medreg.de:hdab</p>
            )}
            <p className="text-xs">
              {t(
                "All organisations on this platform are fictional; no real access body operates it.",
              )}
            </p>
          </Item>
 
          <Item
            letter="f"
            title="Who has been granted access to which datasets, and for what purpose"
            testId="info-f"
          >
            {issued.length === 0 ? (
              <p>{t("No data permit is in force.")}</p>
            ) : (
              <div className="overflow-x-auto rounded-lg border border-(--border)">
                <table className="text-xs w-full border-collapse">
                  <thead>
                    <tr className="bg-(--bg) text-(--text-secondary)">
                      <th className="text-left px-3 py-2 font-medium">
                        {t("Data user")}
                      </th>
                      <th className="text-left px-3 py-2 font-medium">
                        {t("Dataset")}
                      </th>
                      <th className="text-left px-3 py-2 font-medium">
                        {t("Held by")}
                      </th>
                      <th className="text-left px-3 py-2 font-medium">
                        {t("Purpose")}
                      </th>
                      <th className="text-left px-3 py-2 font-medium">
                        {t("Valid")}
                      </th>
                    </tr>
                  </thead>
                  <tbody>
                    {issued.map((a) => (
                      <tr
                        key={a.permitId}
                        className="border-t border-(--border)"
                        data-testid="access-row"
                      >
                        <td className="px-3 py-2 text-(--text-primary)">
                          {a.applicant ?? "—"}
                          {a.applicantCountry ? ` (${a.applicantCountry})` : ""}
                        </td>
                        <td className="px-3 py-2">
                          {a.datasetTitle ?? a.datasetId ?? "—"}
                        </td>
                        <td className="px-3 py-2">{a.holder ?? "—"}</td>
                        <td className="px-3 py-2">
                          {purposeLabel(a.purpose, t)}
                        </td>
                        <td className="px-3 py-2 whitespace-nowrap">
                          {t("{from} to {until}", {
                            from: shortDate(a.validFrom),
                            until: shortDate(a.validUntil),
                          })}
                        </td>
                      </tr>
                    ))}
                  </tbody>
                </table>
              </div>
            )}
            <p className="text-xs">
              <T
                area="public"
                tags={{
                  a: (
                    <Link
                      href="/permits"
                      className="font-bold text-(--accent) hover:underline"
                    />
                  ),
                }}
              >
                {
                  "Every application, decision, revocation and measure is on the <a>public register</a>."
                }
              </T>
            </p>
          </Item>
 
          <Item
            letter="g"
            title="The results or outcomes of the projects"
            testId="info-g"
          >
            {!info || info.results.length === 0 ? (
              <p>
                {t(
                  "No data user has communicated results yet. A data user has 18 months after the end of its processing to do so (Art. 61(4)).",
                )}
              </p>
            ) : (
              <ul className="space-y-1">
                {info.results.map((r) => (
                  <li key={r.resultId} data-testid="info-result">
                    <span className="font-medium text-(--text-primary)">
                      {r.url ? (
                        <a
                          href={r.url}
                          className="text-(--accent) hover:underline"
                          rel="noopener noreferrer"
                          target="_blank"
                        >
                          {r.title}
                        </a>
                      ) : (
                        r.title
                      )}
                    </span>
                    {r.applicantName ? ` · ${r.applicantName}` : ""}
                    {r.datasetTitle ? ` · ${r.datasetTitle}` : ""}
                    {r.communicatedAt
                      ? ` · ${shortDate(r.communicatedAt)}`
                      : ""}
                    {r.summary ? (
                      <div className="text-xs">{r.summary}</div>
                    ) : null}
                  </li>
                ))}
              </ul>
            )}
          </Item>
 
          <section
            className="rounded-lg border border-(--border) bg-(--surface) p-4"
            data-testid="info-fees"
          >
            <h2 className="text-sm font-semibold mb-2 text-(--text-primary) flex items-center gap-2">
              <ShieldCheck size={14} />
              {t("Fees, Art. 62")}
            </h2>
            <div className="text-sm text-(--text-secondary) space-y-2">
              <p>
                {t(
                  "Fees cover the cost of making the data available and are split between the access body and the data holder. The schedule is the demo's own and fictional.",
                )}
              </p>
              {info && (
                <ul className="list-disc list-inside space-y-1 text-xs">
                  <li>
                    {t(
                      "Access body: assessment {assessment} {currency}, {perDataset} per dataset, {spe} per month of the secure processing environment.",
                      {
                        assessment: info.fees.body.assessment,
                        currency: info.fees.currency,
                        perDataset: info.fees.body.perDataset,
                        spe: info.fees.body.spePerMonth,
                      },
                    )}
                  </li>
                  <li>
                    {t(
                      "Data holder: {pseudonymised} {currency} per pseudonymised extraction, {anonymised} per anonymised one.",
                      {
                        pseudonymised: info.fees.holder.pseudonymised,
                        currency: info.fees.currency,
                        anonymised: info.fees.holder.anonymised,
                      },
                    )}
                  </li>
                  <li>
                    {t("Health data request (Art. 69): {amount} {currency}.", {
                      amount: info.fees.requestEur,
                      currency: info.fees.currency,
                    })}
                  </li>
                  <li>
                    {t("Reduced fees (Art. 62(3)): {list}.", {
                      list: Object.entries(info.fees.reductions)
                        .filter(([, r]) => r > 0)
                        .map(([c, r]) =>
                          t("{percent}% off for {who}", {
                            percent: Math.round(r * 100),
                            who: REDUCTION_WORDS[c] ? t(REDUCTION_WORDS[c]) : c,
                          }),
                        )
                        .join("; "),
                    })}
                  </li>
                </ul>
              )}
            </div>
          </section>
        </div>
 
        <p className="mt-6 text-xs text-(--text-secondary)">
          <T
            area="public"
            tags={{
              a: (
                <Link
                  href="/permits"
                  className="text-(--accent) hover:underline"
                />
              ),
              r: (
                <Link
                  href="/activity-report"
                  className="text-(--accent) hover:underline"
                />
              ),
            }}
          >
            {
              "See also the <a>public register</a> (Art. 57(1)(j)) and the <r>activity report</r> (Art. 59)."
            }
          </T>
          {info?.generatedAt
            ? ` ${t("Read on {time} UTC.", {
                time: info.generatedAt.slice(0, 19).replace("T", " "),
              })}`
            : ""}
        </p>
      </div>
    </div>
  );
}