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 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | 2x 2x 2x 2x 2x 2x 2x 9x 9x 2x 2x 4620x 1386x 8547x 2541x 140x 68x 369x 369x 369x 369x 369x 369x 369x 369x 369x 77x 72x 72x 72x 72x 1x 369x 67x 369x 139x 139x 2x 2x 1x 160x 9x 9x 9x 9x 33x 33x 33x 33x 11x 11x 11x 11x 11x 11x 11x 10x 8x 8x 8x 8x 8x 2x 2x 2x 11x 3x 3x 2x 2x 369x 1x 45x 8x 3x 125x 18x 1x 1x 8x 3x 2x 2x 2x 2x 2x 2x | "use client";
import { fetchApi } from "@/lib/api";
import { Suspense, useCallback, useEffect, useState } from "react";
import { useSearchParams } from "next/navigation";
import {
Loader2,
Save,
Plus,
Trash2,
Edit3,
BookOpen,
CheckCircle2,
AlertCircle,
Download,
ExternalLink,
} from "lucide-react";
import PageIntro from "@/components/PageIntro";
/* ── Types ─────────────────────────────────────────── */
interface DatasetEntry {
id: string;
title: string;
description: string;
license: string;
conformsTo: string;
publisher: string;
theme: string;
datasetType: string;
legalBasis: string;
recordCount: number | null;
// Extended HealthDCAT-AP fields
personalData?: boolean;
sensitiveData?: boolean;
purpose?: string;
populationCoverage?: string;
numberOfUniqueIndividuals?: number | null;
healthCategory?: string;
minTypicalAge?: number | null;
maxTypicalAge?: number | null;
publisherType?: string;
language?: string;
spatial?: string;
}
type Tab = "browse" | "create";
const EMPTY_ENTRY: Omit<DatasetEntry, "id"> = {
title: "",
description: "",
license: "CC-BY-4.0",
conformsTo: "http://hl7.org/fhir/R4",
publisher: "",
theme: "",
datasetType: "",
legalBasis: "EHDS Article 53 Secondary Use",
recordCount: null,
personalData: false,
sensitiveData: false,
purpose: "",
populationCoverage: "",
numberOfUniqueIndividuals: null,
healthCategory: "",
minTypicalAge: null,
maxTypicalAge: null,
publisherType: "",
language: "en",
spatial: "",
};
const DATASET_TYPES = [
"SyntheticData",
"RealWorldData",
"ClinicalTrial",
"Registry",
"AnalyticsData",
"ObservationalStudy",
"Biobank",
"AdminHealth",
];
const PUBLISHER_TYPES = ["DataHolder", "HDAB", "Researcher", "DataUser"];
const LEGAL_BASIS_OPTIONS = [
"EHDS Article 33 Primary Use",
"EHDS Article 53 Secondary Use",
"GDPR Article 6(1)(a) Consent",
"GDPR Article 9(2)(j) Research",
];
const THEMES = [
"Patient Summary",
"Clinical Research",
"Cancer Registry",
"Rare Disease",
"Genomics",
"Epidemiology",
"Drug Safety",
"Public Health",
"Medical Imaging",
"Lab & Diagnostics",
];
const LICENSES = [
"CC-BY-4.0",
"CC-BY-SA-4.0",
"CC-BY-NC-4.0",
"CC-BY-NC-SA-4.0",
"CC0-1.0",
"MIT",
];
const PUBLISHERS = [
"AlphaKlinik Berlin",
"PharmaCo Research AG",
"MedReg DE",
"Limburg Medical Centre",
"Institut de Recherche Santé",
];
/* ── Helpers ───────────────────────────────────────── */
function generateId(title: string): string {
const slug = title
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-|-$/g, "");
return `dataset:${slug || "untitled"}-${Date.now().toString(36)}`;
}
/* ── RDF Turtle export (EHDS editor compatible) ────── */
/** Escape a string for Turtle literal */
function ttlEscape(s: string): string {
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
}
/** Map legal basis label → ELI URI used by the EHDS editor */
const LEGAL_BASIS_URI: Record<string, string> = {
"EHDS Article 33 Primary Use": "http://data.europa.eu/eli/reg/2025/327/oj",
"EHDS Article 53 Secondary Use": "http://data.europa.eu/eli/reg/2025/327/oj",
"GDPR Article 6(1)(a) Consent": "http://data.europa.eu/eli/reg/2016/679/oj",
"GDPR Article 9(2)(j) Research": "http://data.europa.eu/eli/reg/2016/679/oj",
};
/** Map dataset type → EU authority table URI */
const DATASET_TYPE_URI: Record<string, string> = {
SyntheticData:
"http://publications.europa.eu/resource/authority/dataset-type/SYNTHETIC",
RealWorldData:
"http://publications.europa.eu/resource/authority/dataset-type/STATISTICAL",
ClinicalTrial:
"http://publications.europa.eu/resource/authority/dataset-type/CLINICAL_TRIAL",
Registry:
"http://publications.europa.eu/resource/authority/dataset-type/CODE_LIST",
AnalyticsData:
"http://publications.europa.eu/resource/authority/dataset-type/STATISTICAL",
ObservationalStudy:
"http://publications.europa.eu/resource/authority/dataset-type/STATISTICAL",
Biobank:
"http://publications.europa.eu/resource/authority/dataset-type/CODE_LIST",
AdminHealth:
"http://publications.europa.eu/resource/authority/dataset-type/STATISTICAL",
};
/**
* Serialize a DatasetEntry as RDF Turtle compatible with the EHDS
* HealthDCAT-AP Editor at https://ehds.healthdataportal.eu/editor2/
*/
function buildTurtle(entry: DatasetEntry): string {
const datasetUri = `<https://ehds-demo.local/dataset/${encodeURIComponent(
entry.id,
)}>`;
const lang = entry.language || "en";
const now = new Date().toISOString().split("T")[0];
const lines: string[] = [
`@prefix dcat: <http://www.w3.org/ns/dcat#> .`,
`@prefix dct: <http://purl.org/dc/terms/> .`,
`@prefix foaf: <http://xmlns.com/foaf/0.1/> .`,
`@prefix healthdcatap: <http://healthdataportal.eu/ns/health#> .`,
`@prefix dcatap: <http://data.europa.eu/r5r/> .`,
`@prefix dpv: <https://w3id.org/dpv#> .`,
`@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .`,
`@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .`,
``,
`${datasetUri} a dcat:Dataset ;`,
];
// Mandatory fields
lines.push(` dct:title "${ttlEscape(entry.title)}"@${lang} ;`);
if (entry.description) {
lines.push(
` dct:description "${ttlEscape(entry.description)}"@${lang} ;`,
);
}
lines.push(` dct:identifier "${ttlEscape(entry.id)}" ;`);
lines.push(` dct:issued "${now}"^^xsd:date ;`);
lines.push(` dct:modified "${now}"^^xsd:date ;`);
// Publisher
if (entry.publisher) {
lines.push(
` dct:publisher [ a foaf:Organization ; foaf:name "${ttlEscape(
entry.publisher,
)}"@${lang} ] ;`,
);
}
// Theme / keyword
if (entry.theme) {
lines.push(` dcat:keyword "${ttlEscape(entry.theme)}"@${lang} ;`);
lines.push(` dcat:theme "${ttlEscape(entry.theme)}" ;`);
}
// Language
if (entry.language) {
const langUri = `http://publications.europa.eu/resource/authority/language/${entry.language.toUpperCase()}`;
lines.push(` dct:language <${langUri}> ;`);
}
// Spatial coverage
if (entry.spatial) {
lines.push(
` dct:spatial <http://publications.europa.eu/resource/authority/country/${entry.spatial.toUpperCase()}> ;`,
);
}
// Conforms to
if (entry.conformsTo) {
lines.push(` dct:conformsTo <${entry.conformsTo}> ;`);
}
// License
if (entry.license) {
lines.push(
` dct:license <https://creativecommons.org/licenses/${entry.license
.toLowerCase()
.replace("cc-", "")
.replace("-4.0", "/4.0/")}> ;`,
);
}
// Dataset type
if (entry.datasetType && DATASET_TYPE_URI[entry.datasetType]) {
lines.push(` dct:type <${DATASET_TYPE_URI[entry.datasetType]}> ;`);
}
// Applicable legislation (EHDS)
const legalUri = entry.legalBasis
? LEGAL_BASIS_URI[entry.legalBasis]
: undefined;
if (legalUri) {
lines.push(` dcatap:applicableLegislation <${legalUri}> ;`);
}
// HealthDCAT-AP extensions
if (entry.healthCategory) {
lines.push(
` healthdcatap:healthCategory "${ttlEscape(
entry.healthCategory,
)}"@${lang} ;`,
);
}
if (entry.purpose) {
lines.push(
` healthdcatap:purpose "${ttlEscape(entry.purpose)}"@${lang} ;`,
);
}
if (entry.populationCoverage) {
lines.push(
` healthdcatap:populationCoverage "${ttlEscape(
entry.populationCoverage,
)}"@${lang} ;`,
);
}
if (entry.personalData != null) {
lines.push(
` dpv:hasPersonalData "${entry.personalData}"^^xsd:boolean ;`,
);
}
if (entry.recordCount != null) {
lines.push(
` healthdcatap:numberOfRecords "${entry.recordCount}"^^xsd:integer ;`,
);
}
if (entry.numberOfUniqueIndividuals != null) {
lines.push(
` healthdcatap:numberOfUniqueIndividuals "${entry.numberOfUniqueIndividuals}"^^xsd:integer ;`,
);
}
if (entry.minTypicalAge != null) {
lines.push(
` healthdcatap:minTypicalAge "${entry.minTypicalAge}"^^xsd:integer ;`,
);
}
if (entry.maxTypicalAge != null) {
lines.push(
` healthdcatap:maxTypicalAge "${entry.maxTypicalAge}"^^xsd:integer ;`,
);
}
// Close the dataset with a period (replace last semicolon)
const last = lines.length - 1;
lines[last] = lines[last].replace(/ ;$/, " .");
return lines.join("\n") + "\n";
}
/** Download a single dataset entry as RDF Turtle */
function downloadTurtle(entry: DatasetEntry) {
const ttl = buildTurtle(entry);
const blob = new Blob([ttl], { type: "text/turtle" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
const slug = entry.title
.toLowerCase()
.replace(/[^a-z0-9]+/g, "_")
.replace(/^_|_$/g, "");
a.download = `healthDCATAP_${slug || "dataset"}.ttl`;
a.click();
URL.revokeObjectURL(url);
}
/** Download all datasets as a single RDF Turtle file */
function downloadAllTurtle(entries: DatasetEntry[]) {
const ttl = entries.map((e) => buildTurtle(e)).join("\n");
const blob = new Blob([ttl], { type: "text/turtle" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
const ts = new Date()
.toISOString()
.replace(/[-:]/g, "")
.replace(/\.\d+Z/, "");
a.download = `healthDCATAP_RDF_${ts}.ttl`;
a.click();
URL.revokeObjectURL(url);
}
/* ── Components ────────────────────────────────────── */
function FormField({
label,
required,
help,
children,
}: {
label: string;
required?: boolean;
help?: string;
children: React.ReactNode;
}) {
return (
<div>
<label className="block text-xs font-semibold text-[var(--text-primary)] mb-1">
{label}
{required && <span className="text-[var(--danger-text)] ml-1">*</span>}
</label>
{children}
{help && (
<p className="text-xs text-[var(--text-secondary)] mt-0.5">{help}</p>
)}
</div>
);
}
function SelectField({
value,
onChange,
options,
placeholder,
}: {
value: string;
onChange: (v: string) => void;
options: string[];
placeholder?: string;
}) {
return (
<select
value={value}
onChange={(e) => onChange(e.target.value)}
className="w-full px-3 py-2 bg-[var(--surface-2)] border border-[var(--border-ui)] rounded text-sm text-[var(--text-primary)] outline-none focus:border-purple-500"
>
{placeholder && (
<option value="" disabled>
{placeholder}
</option>
)}
{options.map((o) => (
<option key={o} value={o}>
{o}
</option>
))}
</select>
);
}
function InputField({
value,
onChange,
placeholder,
type = "text",
}: {
value: string;
onChange: (v: string) => void;
placeholder?: string;
type?: string;
}) {
return (
<input
type={type}
value={value}
onChange={(e) => onChange(e.target.value)}
placeholder={placeholder}
className="w-full px-3 py-2 bg-[var(--surface-2)] border border-[var(--border-ui)] rounded text-sm text-[var(--text-primary)] outline-none focus:border-purple-500"
/>
);
}
/* ── Main Page ─────────────────────────────────────── */
export default function DcatApEditorPage() {
return (
<Suspense
fallback={
<div className="flex items-center gap-2 text-[var(--text-secondary)] p-10">
<Loader2 size={16} className="animate-spin" />
Loading…
</div>
}
>
<EditorContent />
</Suspense>
);
}
function EditorContent() {
const searchParams = useSearchParams();
const [tab, setTab] = useState<Tab>("browse");
const [datasets, setDatasets] = useState<DatasetEntry[]>([]);
const [loading, setLoading] = useState(true);
const [editingId, setEditingId] = useState<string | null>(null);
const [form, setForm] = useState<Omit<DatasetEntry, "id">>(EMPTY_ENTRY);
const [saving, setSaving] = useState(false);
const [result, setResult] = useState<{
ok: boolean;
message: string;
} | null>(null);
const loadCatalog = useCallback(() => {
fetchApi("/api/catalog")
.then((r) => {
Iif (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
})
.then((d) => {
setDatasets(Array.isArray(d) ? d : []);
setLoading(false);
})
.catch(() => setLoading(false));
}, []);
useEffect(() => {
loadCatalog();
}, [loadCatalog]);
// Deep-link: ?edit=<id>
useEffect(() => {
const editId = searchParams.get("edit");
if (editId && datasets.length > 0) {
const existing = datasets.find((d) => d.id === editId);
if (existing) {
startEdit(existing);
}
}
}, [searchParams, datasets]); // eslint-disable-line react-hooks/exhaustive-deps
function setField<K extends keyof Omit<DatasetEntry, "id">>(
key: K,
value: Omit<DatasetEntry, "id">[K],
) {
setForm((prev) => ({ ...prev, [key]: value }));
}
function startEdit(entry: DatasetEntry) {
setEditingId(entry.id);
setForm({
title: entry.title ?? "",
description: entry.description ?? "",
license: entry.license ?? "CC-BY-4.0",
conformsTo: entry.conformsTo ?? "",
publisher: entry.publisher ?? "",
theme: entry.theme ?? "",
datasetType: entry.datasetType ?? "",
legalBasis: entry.legalBasis ?? "",
recordCount: entry.recordCount ?? null,
personalData: entry.personalData ?? false,
sensitiveData: entry.sensitiveData ?? false,
purpose: entry.purpose ?? "",
populationCoverage: entry.populationCoverage ?? "",
numberOfUniqueIndividuals: entry.numberOfUniqueIndividuals ?? null,
healthCategory: entry.healthCategory ?? "",
minTypicalAge: entry.minTypicalAge ?? null,
maxTypicalAge: entry.maxTypicalAge ?? null,
publisherType: entry.publisherType ?? "",
language: entry.language ?? "en",
spatial: entry.spatial ?? "",
});
setTab("create");
setResult(null);
}
function startNew() {
setEditingId(null);
setForm({ ...EMPTY_ENTRY });
setTab("create");
setResult(null);
}
async function handleSave(e: React.FormEvent) {
e.preventDefault();
Iif (!form.title.trim()) return;
setSaving(true);
setResult(null);
const payload = {
...(editingId ? { id: editingId } : { id: generateId(form.title) }),
...form,
recordCount: form.recordCount ? Number(form.recordCount) : null,
numberOfUniqueIndividuals: form.numberOfUniqueIndividuals
? Number(form.numberOfUniqueIndividuals)
: null,
minTypicalAge: form.minTypicalAge ? Number(form.minTypicalAge) : null,
maxTypicalAge: form.maxTypicalAge ? Number(form.maxTypicalAge) : null,
};
try {
const res = await fetchApi("/api/catalog", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (res.ok) {
setResult({
ok: true,
message: editingId
? "Dataset metadata updated successfully."
: "Dataset metadata created successfully.",
});
setEditingId(null);
setForm({ ...EMPTY_ENTRY });
loadCatalog();
setTimeout(() => setTab("browse"), 1500);
} else {
const body = await res.text();
setResult({ ok: false, message: body || "Failed to save." });
}
} catch (err) {
setResult({
ok: false,
message: `Network error: ${
err instanceof Error ? err.message : String(err)
}`,
});
} finally {
setSaving(false);
}
}
async function handleDelete(id: string) {
try {
const res = await fetchApi(`/api/catalog?id=${encodeURIComponent(id)}`, {
method: "DELETE",
});
Eif (res.ok) {
loadCatalog();
}
} catch {
/* ignore */
}
}
return (
<div className="min-h-screen bg-[var(--bg)]">
<div className="max-w-5xl mx-auto px-6 py-10">
<PageIntro
title="HealthDCAT-AP Editor"
icon={BookOpen}
description="Create and edit HealthDCAT-AP metadata entries for EHDS secondary-use datasets. This editor follows the HealthDCAT-AP 3.0 profile — an application profile of DCAT-AP extending W3C DCAT 3 with health-domain extensions required by the EHDS Regulation."
prevStep={{ href: "/catalog", label: "Dataset Catalog" }}
nextStep={{ href: "/data/discover", label: "Discover Data" }}
infoText="Fields marked with * are mandatory per the HealthDCAT-AP specification. The editor generates unique dataset identifiers and stores metadata in the Neo4j graph database."
docLink={{
href: "https://healthdcat-ap.github.io/",
label: "HealthDCAT-AP Specification",
external: true,
}}
/>
{/* Tabs + Export actions */}
<div className="flex items-center gap-2 mb-6 flex-wrap">
<button
onClick={() => setTab("browse")}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
tab === "browse"
? "bg-purple-600 text-white"
: "bg-[var(--surface-2)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
}`}
>
Browse ({datasets.length})
</button>
<button
onClick={startNew}
className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors inline-flex items-center gap-1.5 ${
tab === "create" && !editingId
? "bg-purple-600 text-white"
: "bg-[var(--surface-2)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
}`}
>
<Plus size={14} />
New Entry
</button>
<div className="flex-1" />
{datasets.length > 0 && (
<button
onClick={() => downloadAllTurtle(datasets)}
className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-[var(--badge-active-bg)] text-[var(--badge-active-text)] border border-[var(--badge-active-border)] hover:opacity-80 transition-colors"
title="Export all entries as RDF Turtle for the EHDS editor"
>
<Download size={14} />
Export All (.ttl)
</button>
)}
<a
href="https://ehds.healthdataportal.eu/editor2/"
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-[var(--surface-2)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
title="Open the official EHDS HealthDCAT-AP editor"
>
<ExternalLink size={14} />
EHDS Editor
</a>
</div>
{/* Browse Tab */}
{tab === "browse" && (
<div>
{loading ? (
<div className="flex items-center gap-2 text-[var(--text-secondary)]">
<Loader2 size={16} className="animate-spin" />
Loading catalog…
</div>
) : datasets.length === 0 ? (
<p className="text-[var(--text-secondary)]">
No HealthDCAT-AP entries yet.{" "}
<button
onClick={startNew}
className="text-[var(--accent)] hover:underline"
>
Create one
</button>
</p>
) : (
<div className="grid gap-3">
{datasets.map((d, idx) => (
<div
key={d.id ?? `entry-${idx}`}
className="border border-[var(--border)] rounded-xl p-4 hover:border-purple-500/50 transition-colors group"
>
<div className="flex items-start justify-between gap-3">
<div className="flex-1 min-w-0">
<h3 className="font-semibold text-[var(--accent)] truncate">
{d.title || d.id}
</h3>
<p className="text-xs text-[var(--text-secondary)] mt-0.5 line-clamp-2">
{d.description}
</p>
<div className="flex flex-wrap gap-3 mt-2 text-xs text-[var(--text-secondary)]">
{d.publisher && <span>{d.publisher}</span>}
{d.theme && (
<span className="bg-purple-100 dark:bg-purple-900/30 text-purple-800 dark:text-purple-300 px-1.5 py-0.5 rounded">
{d.theme}
</span>
)}
{d.datasetType && (
<span className="bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-200 px-1.5 py-0.5 rounded">
{d.datasetType}
</span>
)}
{d.recordCount != null && (
<span>
{Number(d.recordCount).toLocaleString()} records
</span>
)}
</div>
</div>
<div className="flex gap-2 shrink-0 opacity-50 group-hover:opacity-100 transition-opacity">
<button
onClick={() => downloadTurtle(d)}
className="p-1.5 rounded hover:bg-[var(--surface-2)] text-[var(--text-secondary)] hover:text-green-300"
title="Download as RDF Turtle (.ttl) for EHDS editor"
>
<Download size={14} />
</button>
<button
onClick={() => startEdit(d)}
className="p-1.5 rounded hover:bg-[var(--surface-2)] text-[var(--text-secondary)] hover:text-[var(--accent)]"
title="Edit entry"
>
<Edit3 size={14} />
</button>
<button
onClick={() => handleDelete(d.id)}
className="p-1.5 rounded hover:bg-[var(--surface-2)] text-[var(--text-secondary)] hover:text-[var(--danger-text)]"
title="Delete entry"
>
<Trash2 size={14} />
</button>
</div>
</div>
</div>
))}
</div>
)}
</div>
)}
{/* Create / Edit Tab */}
{tab === "create" && (
<form onSubmit={handleSave} className="space-y-6">
{editingId && (
<div className="text-xs text-[var(--text-secondary)] bg-[var(--surface-2)]/50 rounded px-3 py-2">
Editing:{" "}
<span className="text-[var(--text-primary)]">{editingId}</span>
</div>
)}
{/* Section: DCAT-AP Mandatory */}
<fieldset className="space-y-4">
<legend className="text-sm font-semibold text-[var(--accent)] border-b border-[var(--border)] pb-1 mb-2">
DCAT-AP Mandatory Fields
</legend>
<FormField label="Title" required>
<InputField
value={form.title}
onChange={(v) => setField("title", v)}
placeholder="e.g. Synthetic FHIR R4 Patient Cohort"
/>
</FormField>
<FormField label="Description">
<textarea
value={form.description}
onChange={(e) => setField("description", e.target.value)}
placeholder="Describe the dataset contents, coverage and purpose…"
rows={3}
className="w-full px-3 py-2 bg-[var(--surface-2)] border border-[var(--border-ui)] rounded text-sm text-[var(--text-primary)] outline-none focus:border-purple-500 resize-y"
/>
</FormField>
<div className="grid grid-cols-2 gap-4">
<FormField label="Publisher" required>
<SelectField
value={form.publisher}
onChange={(v) => setField("publisher", v)}
options={PUBLISHERS}
placeholder="Select publisher…"
/>
</FormField>
<FormField
label="Theme"
help="EuroVoc health theme classification"
>
<SelectField
value={form.theme}
onChange={(v) => setField("theme", v)}
options={THEMES}
placeholder="Select theme…"
/>
</FormField>
</div>
<FormField
label="Language"
help="ISO 639-1 code (e.g. en, de, nl, fr)"
>
<InputField
value={form.language ?? ""}
onChange={(v) => setField("language", v)}
placeholder="en"
/>
</FormField>
</fieldset>
{/* Section: DCAT-AP Recommended */}
<fieldset className="space-y-4">
<legend className="text-sm font-semibold text-[var(--accent)] border-b border-[var(--border)] pb-1 mb-2">
DCAT-AP Recommended Fields
</legend>
<div className="grid grid-cols-2 gap-4">
<FormField
label="Conforms To"
help="Standard URI (e.g. http://hl7.org/fhir/R4)"
>
<InputField
value={form.conformsTo}
onChange={(v) => setField("conformsTo", v)}
placeholder="http://hl7.org/fhir/R4"
/>
</FormField>
<FormField
label="Spatial Coverage"
help="ISO 3166 country code (e.g. DE, NL, FR)"
>
<InputField
value={form.spatial ?? ""}
onChange={(v) => setField("spatial", v)}
placeholder="DE"
/>
</FormField>
</div>
<FormField label="License">
<SelectField
value={form.license}
onChange={(v) => setField("license", v)}
options={LICENSES}
/>
</FormField>
</fieldset>
{/* Section: HealthDCAT-AP Extensions */}
<fieldset className="space-y-4">
<legend className="text-sm font-semibold text-[var(--accent)] border-b border-[var(--border)] pb-1 mb-2">
HealthDCAT-AP Extensions
</legend>
<div className="grid grid-cols-2 gap-4">
<FormField label="Dataset Type">
<SelectField
value={form.datasetType}
onChange={(v) => setField("datasetType", v)}
options={DATASET_TYPES}
placeholder="Select type…"
/>
</FormField>
<FormField label="Publisher Type">
<SelectField
value={form.publisherType ?? ""}
onChange={(v) => setField("publisherType", v)}
options={PUBLISHER_TYPES}
placeholder="Select role…"
/>
</FormField>
</div>
<FormField label="Legal Basis for Access">
<SelectField
value={form.legalBasis}
onChange={(v) => setField("legalBasis", v)}
options={LEGAL_BASIS_OPTIONS}
/>
</FormField>
<FormField label="Purpose" help="Permitted purpose description">
<InputField
value={form.purpose ?? ""}
onChange={(v) => setField("purpose", v)}
placeholder="e.g. Secondary use for public health research"
/>
</FormField>
<FormField label="Population Coverage">
<InputField
value={form.populationCoverage ?? ""}
onChange={(v) => setField("populationCoverage", v)}
placeholder="e.g. Adult patients (18+) in Berlin region"
/>
</FormField>
<FormField
label="Health Category"
help="EEHRxF priority category"
>
<InputField
value={form.healthCategory ?? ""}
onChange={(v) => setField("healthCategory", v)}
placeholder="e.g. Patient Summary, ePrescription"
/>
</FormField>
<div className="grid grid-cols-2 gap-4">
<FormField label="Contains Personal Data">
<div className="flex items-center gap-2 mt-1">
<input
type="checkbox"
checked={form.personalData ?? false}
onChange={(e) =>
setField("personalData", e.target.checked)
}
className="w-4 h-4 rounded bg-[var(--surface-2)] border-[var(--border-ui)]"
/>
<span className="text-sm text-[var(--text-primary)]">
Yes
</span>
</div>
</FormField>
<FormField label="Contains Sensitive Data">
<div className="flex items-center gap-2 mt-1">
<input
type="checkbox"
checked={form.sensitiveData ?? false}
onChange={(e) =>
setField("sensitiveData", e.target.checked)
}
className="w-4 h-4 rounded bg-[var(--surface-2)] border-[var(--border-ui)]"
/>
<span className="text-sm text-[var(--text-primary)]">
Yes
</span>
</div>
</FormField>
</div>
</fieldset>
{/* Section: Statistics */}
<fieldset className="space-y-4">
<legend className="text-sm font-semibold text-[var(--accent)] border-b border-[var(--border)] pb-1 mb-2">
Statistics
</legend>
<div className="grid grid-cols-2 gap-4">
<FormField label="Number of Records">
<InputField
value={form.recordCount?.toString() ?? ""}
onChange={(v) =>
setField("recordCount", v ? parseInt(v, 10) : null)
}
placeholder="e.g. 10000"
type="number"
/>
</FormField>
<FormField label="Unique Individuals">
<InputField
value={form.numberOfUniqueIndividuals?.toString() ?? ""}
onChange={(v) =>
setField(
"numberOfUniqueIndividuals",
v ? parseInt(v, 10) : null,
)
}
placeholder="e.g. 500"
type="number"
/>
</FormField>
</div>
<div className="grid grid-cols-2 gap-4">
<FormField label="Min Typical Age">
<InputField
value={form.minTypicalAge?.toString() ?? ""}
onChange={(v) =>
setField("minTypicalAge", v ? parseInt(v, 10) : null)
}
placeholder="e.g. 18"
type="number"
/>
</FormField>
<FormField label="Max Typical Age">
<InputField
value={form.maxTypicalAge?.toString() ?? ""}
onChange={(v) =>
setField("maxTypicalAge", v ? parseInt(v, 10) : null)
}
placeholder="e.g. 90"
type="number"
/>
</FormField>
</div>
</fieldset>
{/* Result message */}
{result && (
<div
className={`flex items-center gap-2 p-3 rounded text-sm ${
result.ok
? "bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300"
: "bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-300"
}`}
>
{result.ok ? (
<CheckCircle2 size={16} />
) : (
<AlertCircle size={16} />
)}
{result.message}
</div>
)}
{/* Actions */}
<div className="flex gap-3">
<button
type="submit"
disabled={saving || !form.title.trim()}
className="inline-flex items-center gap-2 px-5 py-2.5 bg-purple-600 hover:bg-purple-700 disabled:opacity-50 text-white rounded-lg text-sm font-medium transition-colors"
>
{saving ? (
<Loader2 size={14} className="animate-spin" />
) : (
<Save size={14} />
)}
{editingId ? "Update Entry" : "Create Entry"}
</button>
<button
type="button"
onClick={() => {
setTab("browse");
setEditingId(null);
setForm({ ...EMPTY_ENTRY });
setResult(null);
}}
className="px-5 py-2.5 bg-gray-700 hover:bg-gray-600 text-[var(--text-primary)] rounded-lg text-sm transition-colors"
>
Cancel
</button>
</div>
</form>
)}
</div>
</div>
);
}
|