2024-06-03 21:56:35 +02:00
|
|
|
import { differenceInDays } from "date-fns";
|
|
|
|
|
import { Period } from "../period/Period";
|
|
|
|
|
import { arePeriodsOverlaping } from "../period/arePeriodsOverlaping";
|
|
|
|
|
import { isPeriodContaining } from "../period/isPeriodContaining";
|
|
|
|
|
|
|
|
|
|
export type Famille = {
|
|
|
|
|
notionId: string;
|
|
|
|
|
Titre: string;
|
|
|
|
|
Statut: StatutFamille;
|
|
|
|
|
Integration: Date | null;
|
2024-06-04 09:29:33 +02:00
|
|
|
ContexteEntree: ContexteEntreeDC;
|
2024-06-03 21:56:35 +02:00
|
|
|
Sortie: Date | null;
|
|
|
|
|
Evenements: EvenementFamille[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type EvenementFamille = {
|
|
|
|
|
notionId: string;
|
|
|
|
|
notionIdFamille: string;
|
|
|
|
|
Évènement: string;
|
|
|
|
|
Date: Date | null;
|
|
|
|
|
Type: TypeEvenement;
|
|
|
|
|
"Enfants concernés": string;
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-04 09:29:33 +02:00
|
|
|
export type ContexteEntreeDC =
|
|
|
|
|
| "Pas de demande (Plein droit)"
|
|
|
|
|
| "Pas de demande"
|
|
|
|
|
| "Après refus"
|
|
|
|
|
| "Après mise en demeure"
|
|
|
|
|
| "Après poursuite procureur";
|
|
|
|
|
|
2024-06-03 21:56:35 +02:00
|
|
|
export type TypeEvenement =
|
|
|
|
|
| "Mise en demeure de scolarisation"
|
|
|
|
|
| "Composition pénale refusée"
|
|
|
|
|
| "Composition pénale acceptée";
|
|
|
|
|
|
|
|
|
|
export type StatutFamille =
|
|
|
|
|
| "Résistant.e"
|
|
|
|
|
| "Ex résistant·e·s"
|
|
|
|
|
| "À préciser"
|
|
|
|
|
| "Se questionne"
|
|
|
|
|
| "Désobéissence décidée"
|
|
|
|
|
| "Rédaction Déclaration"
|
|
|
|
|
| "Déclaration Validée - Attente éléments"
|
|
|
|
|
| "Abdandon"
|
|
|
|
|
| "Incompatible";
|
|
|
|
|
|
|
|
|
|
export function periodOfResistance(
|
|
|
|
|
family: Famille,
|
|
|
|
|
atDate: Date = new Date(Date.now())
|
|
|
|
|
): Period | null {
|
|
|
|
|
if (family.Statut !== "Résistant.e" && family.Statut !== "Ex résistant·e·s") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (!family.Integration || family.Integration.getTime() > atDate.getTime()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
start: family.Integration,
|
|
|
|
|
end:
|
|
|
|
|
family.Sortie !== null && family.Sortie.getTime() < atDate.getTime()
|
|
|
|
|
? family.Sortie
|
|
|
|
|
: atDate,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isResistant(
|
|
|
|
|
family: Famille,
|
|
|
|
|
date: Date = new Date(Date.now())
|
|
|
|
|
): boolean {
|
|
|
|
|
const por = periodOfResistance(family, date);
|
|
|
|
|
return por !== null && isPeriodContaining(por, date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isExResistant(
|
|
|
|
|
family: Famille,
|
|
|
|
|
date: Date = new Date(Date.now())
|
|
|
|
|
): boolean {
|
|
|
|
|
const por = periodOfResistance(family, date);
|
|
|
|
|
return por !== null && por.end.getTime() < date.getTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isResistantOverPeriod(
|
|
|
|
|
family: Famille,
|
|
|
|
|
period: Period
|
|
|
|
|
): boolean {
|
|
|
|
|
const familyPeriodResistant: Period | null = periodOfResistance(family);
|
|
|
|
|
return (
|
|
|
|
|
familyPeriodResistant !== null &&
|
|
|
|
|
arePeriodsOverlaping(familyPeriodResistant, period)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param family
|
|
|
|
|
* @param atDate
|
|
|
|
|
* @returns the duration of resistance in days or null if family was not yet in resistances at this date
|
|
|
|
|
*/
|
|
|
|
|
export function dureeResistanceInDays(
|
|
|
|
|
family: Famille,
|
|
|
|
|
atDate: Date = new Date(Date.now())
|
|
|
|
|
): number | null {
|
|
|
|
|
const period = periodOfResistance(family, atDate);
|
|
|
|
|
if (period == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return differenceInDays(period.end, period.start);
|
|
|
|
|
}
|