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 | 1x 3x 3x 3x 3x 3x 1x 3x 3x 3x 7x 7x 3x 3x 5x 5x 3x 5x 5x | import { NextResponse } from "next/server";
import { runQuery } from "@/lib/neo4j";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
export const dynamic = "force-dynamic";
/**
* The EEHRxF priority categories (EHDS Art. 14(1)), the HL7 Europe profiles
* the hub tracks, and how the hub's FHIR resources fare against them (#1144).
*
* `coverage` is a validation result, written by scripts/eehrxf/build.py from
* the HL7 FHIR Validator's report: full = every tested resource passes,
* partial = some do, none = none do, untested = the hub ingests nothing of
* that type. It is readiness evidence against the guides, not EHDS
* conformity. `resourceCount` is the number of graph nodes of the base type,
* shown for context only.
*/
interface EEHRxFProfile {
profileId: string;
name: string;
igName: string;
igPackage: string;
fhirVersion: string;
status: string;
canonical: string;
url: string;
baseResource: string;
coverage: string;
tested: number;
passed: number;
failed: number;
topIssues: string[];
resourceCount: number;
}
interface EEHRxFCategory {
categoryId: string;
name: string;
article: string;
description: string;
ehdsDeadline: string;
ehdsGroup: number;
status: string;
totalResources: number;
profileCount: number;
tested: number;
passed: number;
profiles: EEHRxFProfile[];
}
interface PlannedGuide {
guideId: string;
name: string;
igPackage: string;
status: string;
url: string;
issue: number | null;
scope: string;
}
interface ValidationRun {
validatorVersion: string;
terminology: string;
passRule: string;
maxPerSource: number;
igs: string[];
igUrls: string[];
validatorUrl: string;
sources: string[];
inputsDigest: string;
}
export async function GET() {
const auth = await requireAuth();
Iif (isAuthError(auth)) return auth;
const [categories, profiles, runs, planned, resourceCounts] =
await Promise.all([
runQuery<Omit<EEHRxFCategory, "profiles">>(
`MATCH (c:EEHRxFCategory) WHERE c.categoryId IS NOT NULL
RETURN c.categoryId AS categoryId,
c.name AS name,
coalesce(c.article, '') AS article,
c.description AS description,
c.ehdsDeadline AS ehdsDeadline,
c.ehdsGroup AS ehdsGroup,
c.status AS status,
coalesce(c.totalResources, 0) AS totalResources,
coalesce(c.profileCount, 0) AS profileCount,
coalesce(c.tested, 0) AS tested,
coalesce(c.passed, 0) AS passed
ORDER BY c.ehdsGroup, c.categoryId`,
),
runQuery<EEHRxFProfile & { categoryId: string }>(
`MATCH (p:EEHRxFProfile)-[:PART_OF_CATEGORY]->(c:EEHRxFCategory)
WHERE p.profileId IS NOT NULL
RETURN p.profileId AS profileId,
p.name AS name,
p.igName AS igName,
coalesce(p.igPackage, '') AS igPackage,
p.fhirVersion AS fhirVersion,
p.status AS status,
coalesce(p.canonical, '') AS canonical,
coalesce(p.url, '') AS url,
p.baseResource AS baseResource,
coalesce(p.coverage, 'untested') AS coverage,
coalesce(p.tested, 0) AS tested,
coalesce(p.passed, 0) AS passed,
coalesce(p.failed, 0) AS failed,
coalesce(p.topIssues, []) AS topIssues,
coalesce(p.resourceCount, 0) AS resourceCount,
c.categoryId AS categoryId
ORDER BY c.ehdsGroup, c.categoryId, p.profileId`,
),
runQuery<ValidationRun>(
`MATCH (v:EEHRxFValidationRun {runId: 'current'})
RETURN v.validatorVersion AS validatorVersion,
v.terminology AS terminology,
v.passRule AS passRule,
v.maxPerSource AS maxPerSource,
v.igs AS igs,
coalesce(v.igUrls, []) AS igUrls,
coalesce(v.validatorUrl, '') AS validatorUrl,
v.sources AS sources,
v.inputsDigest AS inputsDigest`,
),
// HL7 Europe drafts the hub plans to track, not validated yet (#1145).
runQuery<PlannedGuide>(
`MATCH (g:EEHRxFPlannedGuide)
RETURN g.guideId AS guideId,
g.name AS name,
g.igPackage AS igPackage,
g.status AS status,
g.url AS url,
g.issue AS issue,
g.scope AS scope
ORDER BY g.guideId`,
),
runQuery<{ label: string; count: number }>(
`MATCH (p:Patient) WITH 'Patient' AS label, count(p) AS count RETURN label, count
UNION ALL
MATCH (e:Encounter) WITH 'Encounter' AS label, count(e) AS count RETURN label, count
UNION ALL
MATCH (o:Observation) WITH 'Observation' AS label, count(o) AS count RETURN label, count
UNION ALL
MATCH (mr:MedicationRequest) WITH 'MedicationRequest' AS label, count(mr) AS count RETURN label, count
UNION ALL
MATCH (pr:Procedure) WITH 'Procedure' AS label, count(pr) AS count RETURN label, count
UNION ALL
MATCH (c:Condition) WITH 'Condition' AS label, count(c) AS count RETURN label, count`,
),
]);
const countMap: Record<string, number> = {};
for (const rc of resourceCounts) {
countMap[rc.label] = rc.count;
}
const profilesByCategory: Record<string, EEHRxFProfile[]> = {};
const distinct = new Map<string, EEHRxFProfile>();
for (const { categoryId, ...p } of profiles) {
(profilesByCategory[categoryId] ??= []).push(p);
distinct.set(p.profileId, p);
}
const result: EEHRxFCategory[] = categories.map((c) => ({
...c,
profiles: profilesByCategory[c.categoryId] ?? [],
}));
// A profile belongs to up to three categories; count each once.
const unique = [...distinct.values()];
const resourcesTested = unique.reduce((n, p) => n + p.tested, 0);
const resourcesPassed = unique.reduce((n, p) => n + p.passed, 0);
return NextResponse.json({
categories: result,
summary: {
totalCategories: categories.length,
totalProfiles: unique.length,
testedProfiles: unique.filter((p) => p.tested > 0).length,
passingProfiles: unique.filter((p) => p.coverage === "full").length,
resourcesTested,
resourcesPassed,
passRatePercent:
resourcesTested > 0
? Math.round((resourcesPassed / resourcesTested) * 100)
: 0,
resourceCounts: countMap,
},
validation: runs[0] ?? null,
planned,
});
}
|