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 | 1x 1x 1x 2x 2x 10x 10x 10x 10x 10x 1x 9x 9x 8x 1x 7x 7x 10x 10x 10x 59x 19x 7x 25x 22x 2x 2x 7x 1x 1x 21x 21x 19x 19x 2x 2x 1x 1x 1x 1x 1x 1x 1x 17x | import { NextResponse } from "next/server";
import { runQuery } from "@/lib/neo4j";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
export const dynamic = "force-dynamic";
/**
* User-friendly property labels per node type.
* Keys are Neo4j property names, values are display labels.
* Properties not listed here are still returned but with auto-formatted keys.
*/
const PROPERTY_LABELS: Record<string, Record<string, string>> = {
Participant: {
participantId: "ID",
name: "Name",
legalName: "Legal Name",
participantType: "Type",
jurisdiction: "Country",
role: "Role",
did: "DID",
},
DataProduct: {
productId: "ID",
name: "Name",
title: "Title",
productType: "Type",
sensitivity: "Sensitivity",
},
Contract: {
contractId: "Contract ID",
name: "Name",
agreementDate: "Agreement Date",
validUntil: "Valid Until",
usagePurpose: "Purpose",
accessType: "Access Type",
},
DataTransfer: {
id: "Transfer ID",
name: "Name",
status: "Status",
},
TransferEvent: {
name: "Description",
consumerDid: "Data Consumer",
providerDid: "Data Provider",
contractId: "Contract",
datasetId: "Dataset",
purpose: "Purpose",
endpoint: "Endpoint",
method: "Method",
protocol: "Protocol",
contentType: "Content Type",
resultCount: "Results",
responseBytes: "Response Size (bytes)",
duration: "Duration (ms)",
timestamp: "Timestamp",
statusCode: "Status Code",
errorMessage: "Error",
eventId: "Event ID",
},
VerifiableCredential: {
credentialId: "Credential ID",
credentialType: "Type",
issuerDid: "Issuer",
subjectDid: "Subject",
status: "Status",
format: "Format",
issuedAt: "Issued",
expiresAt: "Expires",
participantRole: "Participant Role",
purpose: "Purpose",
permittedUses: "Permitted Uses",
prohibitedUses: "Prohibited Uses",
completeness: "Completeness",
conformance: "Conformance",
timeliness: "Timeliness",
jurisdiction: "Jurisdiction",
ehdsArticle: "EHDS Article",
},
HealthDataset: {
datasetId: "Dataset ID",
name: "Name",
title: "Title",
healthSensitivity: "Sensitivity",
permittedPurpose: "Permitted Purposes",
license: "License",
publisher: "Publisher",
},
Distribution: {
distributionId: "Distribution ID",
name: "Name",
title: "Title",
format: "Format",
conformsTo: "Conforms To",
accessUrl: "Access URL",
},
HDABApproval: {
approvalId: "Approval ID",
name: "Name",
applicationId: "Application ID",
approvedAt: "Approved At",
validUntil: "Valid Until",
permittedPurpose: "Purpose",
conditions: "Conditions",
hdabOfficer: "Officer",
legalBasisArticle: "Legal Basis",
},
AccessApplication: {
applicationId: "Application ID",
name: "Name",
applicantId: "Applicant",
datasetId: "Dataset",
requestedPurpose: "Purpose",
submittedAt: "Submitted",
status: "Status",
justification: "Justification",
},
ContractNegotiation: {
id: "Negotiation ID",
name: "Name",
status: "Status",
},
Patient: {
resourceId: "Resource ID",
patientId: "Patient ID",
name: "Name",
birthDate: "Birth Date",
gender: "Gender",
city: "City",
country: "Country",
},
Condition: {
resourceId: "Resource ID",
code: "Code",
display: "Diagnosis",
onset: "Onset Date",
},
Observation: {
resourceId: "Resource ID",
code: "Code",
display: "Measurement",
value: "Value",
unit: "Unit",
effectiveDate: "Date",
},
MedicationRequest: {
resourceId: "Resource ID",
medicationCode: "Code",
display: "Medication",
},
Encounter: {
resourceId: "Resource ID",
encounterDate: "Date",
class: "Class",
status: "Status",
},
SnomedConcept: {
conceptId: "SNOMED ID",
code: "Code",
display: "Term",
},
ICD10Code: {
code: "ICD-10 Code",
display: "Description",
},
LoincCode: {
code: "LOINC Code",
display: "Description",
},
RxNormConcept: {
code: "RxNorm Code",
display: "Drug Name",
name: "Name",
},
TrustCenter: {
name: "Name",
did: "DID",
jurisdiction: "Jurisdiction",
},
SPESession: {
sessionId: "Session ID",
studyId: "Study ID",
status: "Status",
createdAt: "Created",
},
PatientConsent: {
consentId: "Consent ID",
studyId: "Study ID",
status: "Status",
revoked: "Revoked",
grantedAt: "Granted",
},
ResearchPseudonym: {
rpsnId: "Pseudonym ID",
studyId: "Study ID",
revoked: "Revoked",
},
OMOPPerson: {
personId: "Person ID",
name: "Name",
genderConceptId: "Gender",
yearOfBirth: "Year of Birth",
},
};
/** Properties to hide from display (internal Neo4j metadata). */
const HIDDEN_PROPERTIES = new Set(["elementId", "__typename", "_labels"]);
/**
* Auto-format a camelCase property key into a human-readable label.
* e.g. "senderDid" → "Sender Did", "contractId" → "Contract Id"
*/
function autoLabel(key: string): string {
return key
.replace(/([A-Z])/g, " $1")
.replace(/^./, (s) => s.toUpperCase())
.trim();
}
/**
* GET /api/graph/node?id=<elementId>
*
* Returns all properties of a single node plus its label and
* user-friendly property metadata for the detail panel.
*/
export async function GET(req: Request) {
const auth = await requireAuth();
Iif (isAuthError(auth)) return auth;
const { searchParams } = new URL(req.url);
const nodeId = searchParams.get("id");
if (!nodeId) {
return NextResponse.json(
{ error: "Missing ?id= parameter" },
{ status: 400 },
);
}
try {
const rows = await runQuery<{
labels: string[];
props: Record<string, unknown>;
}>(
`MATCH (n)
WHERE elementId(n) = $nodeId
RETURN labels(n) AS labels, properties(n) AS props`,
{ nodeId },
);
if (rows.length === 0) {
return NextResponse.json({ error: "Node not found" }, { status: 404 });
}
const { labels, props } = rows[0];
const primaryLabel = labels[0] ?? "Node";
const labelMap = PROPERTY_LABELS[primaryLabel] ?? {};
// Build formatted properties array
const properties: Array<{
key: string;
label: string;
value: string;
}> = [];
// First add properties in the defined order for this label type
for (const [propKey, displayLabel] of Object.entries(labelMap)) {
if (props[propKey] != null) {
properties.push({
key: propKey,
label: displayLabel,
value: formatValue(props[propKey]),
});
}
}
// Then add remaining properties not yet included
for (const [key, value] of Object.entries(props)) {
if (HIDDEN_PROPERTIES.has(key)) continue;
if (labelMap[key]) continue; // already added above
Iif (value == null) continue;
properties.push({
key,
label: autoLabel(key),
value: formatValue(value),
});
}
return NextResponse.json({
id: nodeId,
labels,
primaryLabel,
properties,
});
} catch (err) {
console.error("GET /api/graph/node error:", err);
return NextResponse.json({ error: "Neo4j unavailable" }, { status: 502 });
}
}
function formatValue(v: unknown): string {
Iif (v == null) return "";
if (Array.isArray(v)) return v.join(", ");
Iif (typeof v === "boolean") return v ? "Yes" : "No";
if (typeof v === "object") {
const obj = v as Record<string, unknown>;
// Neo4j integer objects have .low/.high properties
if ("low" in obj && "high" in obj) return String(obj.low);
// Neo4j DateTime objects
Eif ("year" in obj && "month" in obj && "day" in obj) {
const y = obj.year,
m = obj.month,
d = obj.day;
const h = obj.hour ?? 0,
min = obj.minute ?? 0;
return `${y}-${String(m).padStart(2, "0")}-${String(d).padStart(
2,
"0",
)} ${String(h).padStart(2, "0")}:${String(min).padStart(2, "0")}`;
}
return JSON.stringify(v);
}
return String(v);
}
|