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 | 6x 6x 2x 6x 3x 6x 4x 4x 4x 189x 4x 255x 255x 255x 4x 95x 242x 186x 186x 140x 140x 140x 140x 140x 49x 49x 13x 91x 82x 82x 9x 9x 96x 96x 332x 91x 241x 241x 266x 266x 332x 240x 96x 87x 87x 87x 87x 202x 4x 4x 5x 4x 20x 20x 4x 59x 53x 4x 59x 4x | /**
* HealthDCAT-AP Release 8 in the UI (#700, ADR-063).
*
* The neo4j-proxy writes every description (services/neo4j-proxy/src/
* healthdcat-ap.ts) and CI validates that output with the official SHACL. The
* UI does not describe datasets itself: it offers the Art. 51 categories a
* data holder states in the editor, and writes the proxy's JSON-LD as Turtle,
* the same graph in another syntax (CI checks the two are isomorphic).
*/
/** The categories of Art. 51(1) of Regulation (EU) 2025/327, as the
* HealthDCAT-AP health-category vocabulary codes them. */
import type { MetadataLanguage, Translation } from "@/lib/metadata-language";
export const HEALTH_CATEGORIES: { code: string; label: string }[] = [
{ code: "EHRS", label: "Electronic health data from EHRs" },
{
code: "DIOH",
label:
"Factors impacting on health: socio-economic, environmental, behavioural",
},
{
code: "NRPE",
label: "Aggregated data on healthcare needs, resources and expenditure",
},
{ code: "RPDG", label: "Data on pathogens that impact human health" },
{
code: "HRAD",
label: "Healthcare-related administrative data, incl. claims",
},
{ code: "HGPD", label: "Human genetic, epigenomic and genomic data" },
{ code: "HPML", label: "Other human molecular (omic) data" },
{
code: "PGEH",
label: "Personal health data generated by medical devices",
},
{ code: "WELA", label: "Data from wellness applications" },
{
code: "IDHP",
label: "Professional status and specialisation of health professionals",
},
{
code: "PHDR",
label: "Population-based health data registries (public health)",
},
{ code: "MRMR", label: "Medical registries and mortality registries" },
{
code: "EHCT",
label: "Clinical trials, studies, investigations and performance studies",
},
{ code: "EMRD", label: "Other health data from medical devices" },
{
code: "RMMD",
label: "Registries for medicinal products and medical devices",
},
{
code: "RQSH",
label: "Research cohorts, questionnaires and surveys, after publication",
},
{ code: "EINS", label: "Biobanks and associated databases" },
];
/** What a dataset row of /api/catalog carries, for the static fallback. */
export interface CatalogEntry {
id: string;
title: string;
description?: string;
license?: string;
conformsTo?: string;
publisher?: string;
theme?: string;
datasetType?: string;
legalBasis?: string;
recordCount?: number | null;
translations?: Partial<Record<MetadataLanguage, Translation>>;
}
/** A text in English and its translations, each tagged with its language,
* as the proxy's serialiser writes them (#782). */
function tagged(
en: string | undefined,
translations: CatalogEntry["translations"],
field: "title" | "description",
) {
const values = [
...(en ? [{ "@value": en, "@language": "en" }] : []),
...Object.entries(translations ?? {}).flatMap(([lang, t]) =>
t?.[field] ? [{ "@value": t[field], "@language": lang }] : [],
),
];
return values.length > 1 ? values : values[0];
}
/**
* A minimal description built in the page, for the static export, which has
* no proxy. The live hub hands over the proxy's Release 8 document instead.
*/
export function minimalDescription(d: CatalogEntry): Record<string, unknown> {
return {
"@context": {
dcat: "http://www.w3.org/ns/dcat#",
dct: "http://purl.org/dc/terms/",
// The HealthDCAT-AP namespace (Release 8, ADR-063).
healthdcatap: "http://healthdataportal.eu/ns/health#",
foaf: "http://xmlns.com/foaf/0.1/",
},
"@type": "dcat:Dataset",
"@id": d.id,
"dct:title": tagged(d.title, d.translations, "title"),
"dct:description": tagged(d.description, d.translations, "description"),
"dct:license": d.license,
"dct:conformsTo": d.conformsTo,
"dct:publisher": d.publisher
? { "@type": "foaf:Organization", "foaf:name": d.publisher }
: undefined,
"dcat:theme": d.theme,
"healthdcatap:datasetType": d.datasetType,
"healthdcatap:legalBasisForAccess": d.legalBasis,
"healthdcatap:numberOfRecords": d.recordCount,
};
}
type JsonLdNode = Record<string, unknown>;
const XSD = "http://www.w3.org/2001/XMLSchema#";
/**
* Write compacted JSON-LD as Turtle. Covers what the proxy's serialiser
* produces: prefixed keys, @id and @type, typed and language-tagged values,
* nested named nodes (written as their own subjects) and blank nodes (written
* inline). A key that is neither prefixed nor a keyword is not a term of the
* context, so JSON-LD drops it, and so does this.
*/
export function toTurtle(doc: JsonLdNode): string {
const context = (doc["@context"] ?? {}) as Record<string, string>;
const subjects = new Map<string, string[]>();
const iri = (s: string) =>
`<${s.replace(/[\u0000- <>"{}|^`\\]/g, (c) => encodeURIComponent(c))}>`;
const term = (t: string) => {
const i = t.indexOf(":");
const prefix = i > 0 ? t.slice(0, i) : "";
Eif (prefix in context && /^[A-Za-z0-9_.-]*$/.test(t.slice(i + 1))) return t;
return iri(prefix in context ? context[prefix] + t.slice(i + 1) : t);
};
const literal = (s: string) =>
`"${s
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"')
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")}"`;
const isTerm = (k: string) => k.startsWith("@") || k.includes(":");
function object(v: unknown): string | undefined {
Iif (v == null) return undefined;
if (typeof v === "string") return literal(v);
Iif (typeof v === "boolean") return String(v);
Iif (typeof v === "number") {
return Number.isInteger(v)
? String(v)
: `${literal(String(v))}^^${iri(XSD + "double")}`;
}
Iif (typeof v !== "object" || Array.isArray(v)) return undefined;
const n = v as JsonLdNode;
if (n["@value"] !== undefined && n["@value"] !== null) {
const value = literal(String(n["@value"]));
if (n["@language"]) return `${value}@${String(n["@language"])}`;
Eif (n["@type"]) return `${value}^^${term(String(n["@type"]))}`;
return value;
}
if (typeof n["@id"] === "string") {
subject(n);
return iri(n["@id"]);
}
const props = predicates(n);
return props.length ? `[ ${props.join(" ; ")} ]` : undefined;
}
function predicates(n: JsonLdNode): string[] {
const out: string[] = [];
for (const [k, v] of Object.entries(n)) {
if (k === "@context" || k === "@id" || k === "@graph" || !isTerm(k)) {
continue;
}
Iif (k.startsWith("@") && k !== "@type") continue;
const values = (Array.isArray(v) ? v : [v])
.map((x) =>
k === "@type"
? typeof x === "string"
? term(x)
: undefined
: object(x),
)
.filter((x): x is string => x !== undefined);
if (values.length) {
out.push(`${k === "@type" ? "a" : term(k)} ${values.join(", ")}`);
}
}
return out;
}
function subject(n: JsonLdNode) {
const id = iri(String(n["@id"]));
const lines = subjects.get(id) ?? [];
if (!subjects.has(id)) subjects.set(id, lines);
for (const line of predicates(n)) {
// The same triple twice is one triple; a line with a blank node is a new
// blank node each time, as it is in the JSON-LD, so it is kept.
if (line.includes("[") || !lines.includes(line)) lines.push(line);
}
}
const roots = Array.isArray(doc["@graph"])
? (doc["@graph"] as JsonLdNode[])
: [doc];
for (const root of roots) {
if (typeof root["@id"] === "string") subject(root);
else E{
const blank = object(root);
if (blank) subjects.set(blank, []);
}
}
const prefixes = Object.entries(context)
.filter(([, ns]) => typeof ns === "string")
.map(([p, ns]) => `@prefix ${p}: ${iri(ns)} .`);
const blocks = [...subjects.entries()]
.filter(([, lines]) => lines.length)
.map(([id, lines]) => `${id}\n ${lines.join(" ;\n ")} .`);
// A root without @id is written as an anonymous subject.
const anonymous = [...subjects.entries()]
.filter(([key, lines]) => !lines.length && key.startsWith("["))
.map(([key]) => `${key} .`);
return [prefixes.join("\n"), ...blocks, ...anonymous].join("\n\n") + "\n";
}
|