@gouvfr-anct/mednum
Version:
✨ Permet de transformer une source de données vers le schéma des lieux de mediation numerique
46 lines (45 loc) • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processAutresFormationsLabels = void 0;
const input_1 = require("../../input");
const isAllowedTerm = (choice, sourceValue) => choice.sauf?.every((forbidden) => !sourceValue.includes(forbidden)) ?? true;
const isTermFound = (sourceValue, choice) => (found, term) => found || (sourceValue.includes(term.toLowerCase()) && isAllowedTerm(choice, sourceValue));
const containsOneOfTheTerms = (choice, sourceValue = '') => choice.termes == null ? sourceValue !== '' : choice.termes.reduce(isTermFound(sourceValue.toLowerCase(), choice), false);
const appendAutreFormationLabel = (autresFormationsLabels, autreFormationLabel) => [
...autresFormationsLabels,
...(autreFormationLabel == null ? [] : [autreFormationLabel])
];
const isDefault = (choice) => choice.colonnes == null;
const findAndAppendAutresFormationsLabels = (choice, source) => (autresFormationsLabels, colonne) => containsOneOfTheTerms(choice, source[colonne]?.toString())
? appendAutreFormationLabel(autresFormationsLabels, choice.cible)
: autresFormationsLabels;
const autresFormationsLabelsForTerms = (choice, source) => (autresFormationsLabels, colonne) => isDefault(choice)
? appendAutreFormationLabel(autresFormationsLabels, choice.cible)
: findAndAppendAutresFormationsLabels(choice, source)(autresFormationsLabels, colonne);
const toAutreFormationLabelFrom = (source) => (columnName) => source[columnName]?.toString();
const onlyDefined = (valueToBeDefined) => valueToBeDefined != null;
const extractAutresFormationsLabelsFromSource = (source, colonnes = []) => colonnes.map(toAutreFormationLabelFrom(source)).filter(onlyDefined);
const autresFormationsLabelsCibleMatchingTerms = (autresFormationsLabels, choice, source) => [
...autresFormationsLabels,
...(choice.colonnes ?? (0, input_1.cibleAsDefault)(choice)).reduce(autresFormationsLabelsForTerms(choice, source), [])
];
const appendAutresFormationsLabels = (source) => (autresFormationsLabels, choice) => choice.cible == null
? extractAutresFormationsLabelsFromSource(source, choice.colonnes)
: autresFormationsLabelsCibleMatchingTerms(autresFormationsLabels, choice, source);
const shouldAddQPV = (isInQpv) => (adresse, localisation) => adresse?.code_insee != null && localisation != null && isInQpv(adresse.code_insee, localisation);
const shouldAddZRR = (isInZrr) => (adresse) => adresse?.code_insee != null && isInZrr(adresse.code_insee);
const labelsToAdd = (isInQpv, isInZrr) => (adresse, localisation) => [
...(shouldAddQPV(isInQpv)(adresse, localisation) ? ['QPV'] : []),
...(shouldAddZRR(isInZrr)(adresse) ? ['ZRR'] : [])
];
const appendExtraLabels = (isInQpv, isInZrr) => (autresFormationsLabels, adresse, localisation) => [
...labelsToAdd(isInQpv, isInZrr)(adresse, localisation),
...autresFormationsLabels
];
const onlyNonEmptyLabels = (label) => label !== '';
const labelsFromSource = (matching, source) => Array.from(new Set(matching.autres_formations_labels?.reduce(appendAutresFormationsLabels(source), []))).filter(onlyNonEmptyLabels);
const labelWithPipe = (label) => label.split('|');
const processAutresFormationsLabels = (source, matching, isInQpv, isInZrr, adresse, localisation) => [
...Array.from(new Set(appendExtraLabels(isInQpv, isInZrr)(labelsFromSource(matching, source).flatMap(labelWithPipe), adresse, localisation)))
];
exports.processAutresFormationsLabels = processAutresFormationsLabels;