From 00ddb35f40d836913529c47a3df3b9622a92bed5 Mon Sep 17 00:00:00 2001 From: felix Date: Thu, 2 Apr 2026 17:37:24 +0200 Subject: [PATCH] Added reports --- config/reports/index.js | 2 + .../reports/organizations-platform-report.js | 123 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 config/reports/organizations-platform-report.js diff --git a/config/reports/index.js b/config/reports/index.js index 4b22474..a0d10a3 100644 --- a/config/reports/index.js +++ b/config/reports/index.js @@ -2,10 +2,12 @@ import OrganizationsReport from './organizations-report' import RelatedOrganizationsReport from './related-organizations-report' import KboOrganizationsReport from './kbo-organizations-report' import OrganizationsDetailReport from './organizations-detail-report' +import OrganizationsPlatformReport from './organizations-platform-report' export default [ OrganizationsReport, RelatedOrganizationsReport, KboOrganizationsReport, OrganizationsDetailReport, + OrganizationsPlatformReport, ]; diff --git a/config/reports/organizations-platform-report.js b/config/reports/organizations-platform-report.js new file mode 100644 index 0000000..a58fb10 --- /dev/null +++ b/config/reports/organizations-platform-report.js @@ -0,0 +1,123 @@ +import { generateReportFromData, batchedQuery } from "../helpers.js"; +import { PREFIXES } from "./utils"; + +export default { + cronPattern: "0 00 2 * * *", + name: "organizationsPlatform", + execute: async () => { + const reportData = { + title: "organizations platform", + description: "List of Organizations with digital platform information", + filePrefix: "exports/organizations-platform", + }; + + console.log("Generating organizations platform report"); + + const queryString = ` + ${PREFIXES} + PREFIX muAccount: + + SELECT + ?org + ?org_pref_label + ?org_classification_label + ?org_status_label + ?org_legal_name + ?org_alt_label + ?org_werkingsgebied_label + ?org_ovo_number + ?org_kbo_number + (COALESCE(?platforms, "Loket voor Lokale Besturen") AS ?org_digitaal_platform) + WHERE { + ?org a org:Organization . + + OPTIONAL { ?org skos:prefLabel ?org_pref_label } + OPTIONAL { ?org skos:altLabel ?org_alt_label } + + OPTIONAL { + ?org regorg:legalName ?org_legal_name . + } + + OPTIONAL { + ?org org:classification ?org_classification . + ?org_classification skos:prefLabel ?org_classification_label . + } + + OPTIONAL { + ?org regorg:orgStatus ?org_status . + ?org_status skos:prefLabel ?org_status_label . + } + + OPTIONAL { + ?org besluit:werkingsgebied ?org_werkingsgebied . + ?org_werkingsgebied rdfs:label ?org_werkingsgebied_label . + } + + OPTIONAL { + ?org adms:identifier ?identifier1 . + ?identifier1 skos:notation "KBO nummer" ; + generiek:gestructureerdeIdentificator ?id1 . + ?id1 generiek:lokaleIdentificator ?org_kbo_number . + } + + OPTIONAL { + ?org adms:identifier ?identifier2 . + ?identifier2 skos:notation "OVO-nummer" ; + generiek:gestructureerdeIdentificator ?id2 . + ?id2 generiek:lokaleIdentificator ?org_ovo_number . + } + + OPTIONAL { + SELECT ?org (GROUP_CONCAT(DISTINCT ?digitaal_platform; separator=", ") AS ?platforms) + WHERE { + ?vendor a ext:Vendor ; + muAccount:canActOnBehalfOf ?org ; + foaf:name ?digitaal_platform . + } + GROUP BY ?org + } + } + `; + + const queryResponse = await batchedQuery(queryString); + + const data = queryResponse.results.bindings.map((row) => ({ + "URI organisatie": getSafeValue(row, "org"), + "label naam": getSafeValue(row, "org_pref_label"), + "label classificatie": getSafeValue(row, "org_classification_label"), + "label status": getSafeValue(row, "org_status_label"), + "label juridische naam": getSafeValue(row, "org_legal_name"), + "label alternatieve naam": getSafeValue(row, "org_alt_label"), + "label werkingsgebied": getSafeValue(row, "org_werkingsgebied_label"), + "label OVO nummer": getSafeValue(row, "org_ovo_number"), + "label KBO nummer": getSafeValue(row, "org_kbo_number"), + "label digitaal platform": getSafeValue(row, "org_digitaal_platform"), + })); + + await generateReportFromData( + data, + [ + "URI organisatie", + "label naam", + "label classificatie", + "label status", + "label juridische naam", + "label alternatieve naam", + "label werkingsgebied", + "label OVO nummer", + "label KBO nummer", + "label digitaal platform", + ], + reportData, + ); + }, +}; + +function getSafeValue(entry, property) { + return entry[property] ? wrapInQuote(entry[property].value) : null; +} + +// Some values might contain commas; wrapping them in escapes quotes doesn't disrupt the columns. +function wrapInQuote(value) { + return `\"${value}\"`; +}