From 3d7c704f76371be96fa41668142d47a815fd8cab Mon Sep 17 00:00:00 2001 From: Damon Date: Wed, 29 Apr 2026 09:31:16 +0200 Subject: [PATCH] OP-3784: added query to check missing addressregister URI's --- CHANGELOG.md | 8 ++ config/reports/index.js | 2 + .../organizations-no-address-report.js | 98 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 config/reports/organizations-no-address-report.js diff --git a/CHANGELOG.md b/CHANGELOG.md index b27a6a3..726488f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ # Changelog +## Unreleased +- Query to check missing address URI's [OP-3784] + +### Deploy notes +``` +drc restart report-generation +``` + ## 1.39.1 (2026-04-24) - OP-3771: Adds labels for: EredienstBeroepen and TypeBetrokkenheid - Bump to kbo-data-sync [OP-3765] diff --git a/config/reports/index.js b/config/reports/index.js index a24f3da..75cc0e6 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 OrganizationsNoAddressReport from "./organizations-no-address-report"; export default [ OrganizationsReport, @@ -14,4 +15,5 @@ export default [ OrganizationsPlatformReport, AdministrativeUnitsReport, ChangeEventsReport, + OrganizationsNoAddressReport, ]; diff --git a/config/reports/organizations-no-address-report.js b/config/reports/organizations-no-address-report.js new file mode 100644 index 0000000..e4ee30f --- /dev/null +++ b/config/reports/organizations-no-address-report.js @@ -0,0 +1,98 @@ +import { generateReportFromData, batchedQuery } from "../helpers.js"; +import { PREFIXES } from "./utils"; + +export default { + cronPattern: "0 00 23 * * *", + name: "organizationsNoAddressregister", + execute: async () => { + const reportData = { + title: "organisations in database with no link to Addressregister", + description: "List of the Organisations in the database with no link to Addressregister", + filePrefix: "exports/organizations-no-addressregister", + }; + + console.log("Generating organizationsNoAddressregister report"); + + const queryString = ` + ${PREFIXES} + PREFIX org: + PREFIX adms: + PREFIX generiek: + PREFIX skos: + SELECT DISTINCT + ?bestuur + ?label + ?classification + ?status + ?street + ?number + ?bus + ?postal + ?location + WHERE { + ?bestuur a org:Organization . + + OPTIONAL { + ?bestuur ?site . + ?site ?address . + OPTIONAL{?address ?adressenregister .} + OPTIONAL{?address ?street . } + OPTIONAL{?address ?number . } + OPTIONAL{?address ?bus . } + OPTIONAL{?address ?postal . } + OPTIONAL{?address ?location . } + } + + OPTIONAL {?bestuur skos:prefLabel ?label} + OPTIONAL { + ?bestuur ?org_classification . + ?org_classification skos:prefLabel ?classification . + } + OPTIONAL { + ?bestuur ?org_status . + ?org_status skos:prefLabel ?status . + } + FILTER(!BOUND(?adressenregister)) + } + `; + + const queryResponse = await batchedQuery(queryString); + + const data = queryResponse.results.bindings.map((row) => ({ + "bestuur": getSafeValue(row, "bestuur"), + "label": getSafeValue(row, "label"), + "classification": getSafeValue(row, "classification"), + "status": getSafeValue(row, "status"), + "street": getSafeValue(row, "street"), + "number": getSafeValue(row, "number"), + "bus": getSafeValue(row, "bus"), + "postal": getSafeValue(row, "postal"), + "location": getSafeValue(row, "location"), + })); + + await generateReportFromData( + data, + [ + "bestuur", + "label", + "classification", + "status", + "street", + "number", + "bus", + "postal", + "location", + ], + 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}\"`; +}