diff --git a/config/dev-migrations/20251118120821-add-status-to-bestuurseenheden.sparql b/config/dev-migrations/20251118120821-add-status-to-bestuurseenheden.sparql index 49bc2cc..04fed56 100644 --- a/config/dev-migrations/20251118120821-add-status-to-bestuurseenheden.sparql +++ b/config/dev-migrations/20251118120821-add-status-to-bestuurseenheden.sparql @@ -1,6 +1,5 @@ DELETE { GRAPH ?g { - ?s a . ?s ?status. } } diff --git a/config/reports/organizations-report.js b/config/reports/organizations-report.js index 2011077..d006c64 100644 --- a/config/reports/organizations-report.js +++ b/config/reports/organizations-report.js @@ -6,93 +6,68 @@ export default { name: "organizations", execute: async () => { const reportData = { - title: "organizations", - description: "List of the Organizations", + title: "organisations in database", + description: "List of the Organisations in the database", filePrefix: "exports/organizations", }; console.log("Generating organizations report"); - const queryStringPart1 = ` + const queryString = ` ${PREFIXES} - - SELECT DISTINCT ?bestuur ?label ?classification ?typeEredienst + PREFIX org: + PREFIX adms: + PREFIX generiek: + PREFIX skos: + SELECT DISTINCT + ?bestuur + ?label + ?classification + ?typeEredienst + ?provincie + ?status WHERE { - GRAPH ?g { - ?bestuur a org:Organization . - OPTIONAL { ?bestuur skos:prefLabel ?label. } - } - - OPTIONAL { - ?bestuur org:classification ?classificationUri . - ?classificationUri skos:prefLabel ?classification. - } - - OPTIONAL { - ?bestuur ere:typeEredienst ?typeEredienstUri. - ?typeEredienstUri skos:prefLabel ?typeEredienst. - } - - FILTER (?g IN ( , , )) - } - `; - - const queryResponsePart1 = await batchedQuery(queryStringPart1); - - const dataPart1 = queryResponsePart1.results.bindings.reduce((acc, row) => { - acc[getSafeValue(row, "bestuur")] = { - bestuur: getSafeValue(row, "bestuur"), - label: getSafeValue(row, "label"), - classification: getSafeValue(row, "classification"), - typeEredienst: getSafeValue(row, "typeEredienst"), - }; - return acc; - }, {}); - - const queryStringPart2 = ` - ${PREFIXES} - - SELECT DISTINCT ?bestuur ?provincie - WHERE { - GRAPH ?g { - ?bestuur a org:Organization . - } - - OPTIONAL { - GRAPH ?h { - ?bestuur org:hasPrimarySite ?primarySite. - + ?bestuur a org:Organization . OPTIONAL { - ?primarySite organisatie:bestaatUit ?sa. - OPTIONAL { ?sa locn:adminUnitL2 ?provincie. } + ?bestuur ?site. + ?site ?address. + ?address ?provincie } - } - FILTER (?h IN ( , )) - } - - FILTER (?g IN ( , , )) - + 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. + } } `; - const queryResponsePart2 = await batchedQuery(queryStringPart2); - const dataPart2 = queryResponsePart2.results.bindings.reduce((acc, row) => { - let dataPart = { - bestuur: getSafeValue(row, "bestuur"), - provincie: getSafeValue(row, "provincie"), - }; + const queryResponse = await batchedQuery(queryString); - acc[getSafeValue(row, "bestuur")] = Object.assign( - dataPart, - dataPart1[getSafeValue(row, "bestuur")], - ); - return acc; - }, {}); + 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( - Object.values(dataPart2), - ["bestuur", "label", "classification", "typeEredienst", "provincie"], - reportData, + data, + [ + "bestuur", + "label", + "classification", + "typeEredienst", + "provincie", + "status", + ], + reportData, ); }, };