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}\"`; }