diff --git a/config/reports/change-events-report.js b/config/reports/change-events-report.js new file mode 100644 index 0000000..903ba8b --- /dev/null +++ b/config/reports/change-events-report.js @@ -0,0 +1,135 @@ +import {generateReportFromData, batchedQuery} from "../helpers.js"; +import {PREFIXES} from "./utils"; + +export default { + cronPattern: "0 00 3 * * *", + name: "changeEvents", + execute: async () => { + const reportData = { + title: "change events", + description: + "List of change events", + filePrefix: "exports/change-events", + }; + + console.log("Generating change events report"); + + const queryString = ` + ${PREFIXES} + +PREFIX skos: +PREFIX org: +PREFIX regorg: +PREFIX dct: +PREFIX m8g: +PREFIX eli: +PREFIX foaf: +PREFIX prov: +PREFIX dossier: +PREFIX ch: + +SELECT DISTINCT + ?organisatie + ?organisatieLabel + ?classificatieLabel + ?statusLabel + ?resulterendeOrganisatie + ?resulterendeOrganisatieLabel + ?resulterendeClassificatieLabel + ?resulterendeStatusLabel + ?veranderingsgebeurtenisTypeLabel + ?beschrijving + ?linkNaarBesluit + ?datumMinisterieelBesluit + ?datumPublicatieBS + ?datumVeranderingsgebeurtenis +WHERE { + { + SELECT DISTINCT ?organisatie ?organisatieLabel ?veranderingsgebeurtenis + WHERE { + ?organisatie a ; + skos:prefLabel ?organisatieLabel . + + ?veranderingsgebeurtenis a org:ChangeEvent ; + org:originalOrganization ?organisatie . + } + } + + OPTIONAL { ?organisatie org:classification/skos:prefLabel ?classificatieLabel . } + OPTIONAL { ?organisatie regorg:orgStatus/skos:prefLabel ?statusLabel . } + + OPTIONAL { + ?veranderingsgebeurtenis org:resultingOrganization ?resulterendeOrganisatie . + OPTIONAL { ?resulterendeOrganisatie skos:prefLabel ?resulterendeOrganisatieLabel . } + OPTIONAL { ?resulterendeOrganisatie org:classification/skos:prefLabel ?resulterendeClassificatieLabel . } + OPTIONAL { ?resulterendeOrganisatie regorg:orgStatus/skos:prefLabel ?resulterendeStatusLabel . } + } + + OPTIONAL { ?veranderingsgebeurtenis ch:typeWijziging/skos:prefLabel ?veranderingsgebeurtenisTypeLabel . } + OPTIONAL { ?veranderingsgebeurtenis dct:description ?beschrijving . } + OPTIONAL { ?veranderingsgebeurtenis dct:date ?datumVeranderingsgebeurtenis . } + + OPTIONAL { + ?veranderingsgebeurtenis m8g:hasFormalFramework ?besluit . + OPTIONAL { ?besluit foaf:page ?linkNaarBesluit . } + OPTIONAL { ?besluit eli:date_publication ?datumPublicatieBS . } + OPTIONAL { + ?beslissingsactiviteit prov:generated ?besluit ; + dossier:Activiteit.einddatum ?datumMinisterieelBesluit . + } + } + +} +ORDER BY ?organisatieLabel ?datumVeranderingsgebeurtenis + `; + + const queryResponse = await batchedQuery(queryString); + + const data = queryResponse.results.bindings.map((row) => ({ + organisatie: getSafeValue(row, "organisatie"), + organisatieLabel: getSafeValue(row, "organisatieLabel"), + classificatieLabel: getSafeValue(row, "classificatieLabel"), + statusLabel: getSafeValue(row, "statusLabel"), + resulterendeOrganisatie: getSafeValue(row, "resulterendeOrganisatie"), + resulterendeOrganisatieLabel: getSafeValue(row, "resulterendeOrganisatieLabel"), + resulterendeClassificatieLabel: getSafeValue(row, "resulterendeClassificatieLabel"), + resulterendeStatusLabel: getSafeValue(row, "resulterendeStatusLabel"), + veranderingsgebeurtenisTypeLabel: getSafeValue(row, "veranderingsgebeurtenisTypeLabel"), + beschrijving: getSafeValue(row, "beschrijving"), + linkNaarBesluit: getSafeValue(row, "linkNaarBesluit"), + datumMinisterieelBesluit: getSafeValue(row, "datumMinisterieelBesluit"), + datumPublicatieBS: getSafeValue(row, "datumPublicatieBS"), + datumVeranderingsgebeurtenis: getSafeValue(row, "datumVeranderingsgebeurtenis"), + })); + + await generateReportFromData( + data, + [ + "organisatie", + "organisatieLabel", + "classificatieLabel", + "statusLabel", + "resulterendeOrganisatie", + "resulterendeOrganisatieLabel", + "resulterendeClassificatieLabel", + "resulterendeStatusLabel", + "veranderingsgebeurtenisTypeLabel", + "beschrijving", + "linkNaarBesluit", + "datumMinisterieelBesluit", + "datumPublicatieBS", + "datumVeranderingsgebeurtenis", + ], + 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}\"`; +} diff --git a/config/reports/index.js b/config/reports/index.js index ed712fd..a24f3da 100644 --- a/config/reports/index.js +++ b/config/reports/index.js @@ -4,6 +4,7 @@ import KboOrganizationsReport from './kbo-organizations-report' import OrganizationsDetailReport from './organizations-detail-report' import OrganizationsPlatformReport from './organizations-platform-report' import AdministrativeUnitsReport from "./administrative-units-report"; +import ChangeEventsReport from "./change-events-report"; export default [ OrganizationsReport, @@ -11,5 +12,6 @@ export default [ KboOrganizationsReport, OrganizationsDetailReport, OrganizationsPlatformReport, - AdministrativeUnitsReport + AdministrativeUnitsReport, + ChangeEventsReport, ];