From 5b2a1b1ac6ee8592a9b278d9d58adbec788123e0 Mon Sep 17 00:00:00 2001 From: Damon Date: Wed, 22 Apr 2026 10:17:03 +0200 Subject: [PATCH] OP-3774: added new query/report for organizations shown in frontend --- CHANGELOG.md | 1 + config/reports/index.js | 2 + .../organizations-in-frontend-report.js | 102 ++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 config/reports/organizations-in-frontend-report.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 5beca2b..3bede03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Add column to query organizations in Dashboard [OP-3758] - Query list change events of organisations in Dashboard [OP-3760] - Disable SPARQL endpoint +- Create new query 'organisations shown in OP frontend' in Dashboard [OP-3774] ### Deploy notes ``` diff --git a/config/reports/index.js b/config/reports/index.js index a24f3da..b085078 100644 --- a/config/reports/index.js +++ b/config/reports/index.js @@ -5,6 +5,7 @@ import OrganizationsDetailReport from './organizations-detail-report' import OrganizationsPlatformReport from './organizations-platform-report' import AdministrativeUnitsReport from "./administrative-units-report"; import ChangeEventsReport from "./change-events-report"; +import OrganizationsInFrontendReport from "./organizations-in-frontend-report"; export default [ OrganizationsReport, @@ -14,4 +15,5 @@ export default [ OrganizationsPlatformReport, AdministrativeUnitsReport, ChangeEventsReport, + OrganizationsInFrontendReport ]; diff --git a/config/reports/organizations-in-frontend-report.js b/config/reports/organizations-in-frontend-report.js new file mode 100644 index 0000000..543aea3 --- /dev/null +++ b/config/reports/organizations-in-frontend-report.js @@ -0,0 +1,102 @@ +import { generateReportFromData, batchedQuery } from "../helpers.js"; +import { PREFIXES } from "./utils"; + +export default { + cronPattern: "0 00 23 * * *", + name: "organizationsInFrontend", + execute: async () => { + const reportData = { + title: "organisations in frontend", + description: "List of the Organisations shown in the frontend", + filePrefix: "exports/organizations InFrontend", + }; + + console.log("Generating organizations in frontend report"); + + const queryString = ` + ${PREFIXES} + PREFIX org: + PREFIX adms: + PREFIX generiek: + PREFIX skos: + PREFIX geosparql: + PREFIX dct: + SELECT DISTINCT + ?bestuur + ?label + ?classification + ?typeEredienst + ?provincie + ?status + WHERE { + ?bestuur a org:Organization . + OPTIONAL { + ?bestuur ?site. + ?site ?address. + ?address ?provincie + } + OPTIONAL {?bestuur ?typeEredienst.} + OPTIONAL {?bestuur skos:prefLabel ?label} + OPTIONAL { + ?bestuur ?org_classification . + ?org_classification skos:prefLabel ?classification + } + OPTIONAL { + ?bestuur ?org_status. + ?org_status skos:prefLabel ?status. + } + + FILTER( + NOT EXISTS { + ?bestuur org:classification + } + || + EXISTS { + ?bestuur besluit:werkingsgebied ?werkingsgebied . + ?werkingsgebied geosparql:sfWithin ?parent . + } + ) + + FILTER( + NOT EXISTS { + ?bestuur org:classification + } + + ) + } + `; + + const queryResponse = await batchedQuery(queryString); + + const data = queryResponse.results.bindings.map((row) => ({ + "bestuur": getSafeValue(row, "bestuur"), + "label": getSafeValue(row, "label"), + "classification": getSafeValue(row, "classification"), + "typeEredienst": getSafeValue(row, "typeEredienst"), + "provincie": getSafeValue(row, "provincie"), + "status": getSafeValue(row, "status"), + })); + + await generateReportFromData( + data, + [ + "bestuur", + "label", + "classification", + "typeEredienst", + "provincie", + "status", + ], + 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}\"`; +}