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";
|
2024-06-05 10:27:27 +02:00
|
|
|
import { ContexteEntreeDC } from "./ContexteEntreeDC";
|
|
|
|
|
import { EvenementFamille } from "./EvenementFamille";
|
2024-12-08 15:00:58 +01:00
|
|
|
import {
|
|
|
|
|
statutExResistant,
|
|
|
|
|
StatutFamille,
|
|
|
|
|
statutResistant,
|
|
|
|
|
} from "./StatutFamille";
|
2024-09-08 11:55:11 +02:00
|
|
|
import { StatutSocial } from "./StatutSocial";
|
|
|
|
|
import { StatutPenal } from "./StatutPenal";
|
2025-01-16 14:42:28 +01:00
|
|
|
import { Mission } from "./Mission";
|
2025-05-30 00:06:05 +02:00
|
|
|
import { Contact } from "./Contact";
|
2024-06-03 21:56:35 +02:00
|
|
|
|
2024-09-06 13:33:16 +02:00
|
|
|
export type Famille = Readonly<{
|
2024-06-03 21:56:35 +02:00
|
|
|
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;
|
2024-09-08 11:55:11 +02:00
|
|
|
Penal: StatutPenal;
|
|
|
|
|
Social: StatutSocial;
|
2024-10-14 17:42:57 +02:00
|
|
|
Departement: string | null;
|
2024-12-16 12:51:50 +01:00
|
|
|
// Tous Evenements triés par date asc
|
|
|
|
|
// Inclus aussi les evenements sans date
|
2024-06-03 21:56:35 +02:00
|
|
|
Evenements: EvenementFamille[];
|
2024-12-16 12:51:50 +01:00
|
|
|
|
2025-06-15 09:12:47 +02:00
|
|
|
// Tous Evenements triés par date asc
|
|
|
|
|
// Inclus aussi les evenements sans date
|
|
|
|
|
EvenementsDates: EvenementFamille[];
|
|
|
|
|
|
2024-12-16 12:51:50 +01:00
|
|
|
// Evenements durant la période EL triés par date asc
|
|
|
|
|
EvenementsEL: EvenementFamille[];
|
|
|
|
|
|
|
|
|
|
// Evenements hors période EL triés par date asc
|
|
|
|
|
EvenementsAvantEL: EvenementFamille[];
|
|
|
|
|
EvenementsApresEL: EvenementFamille[];
|
|
|
|
|
|
2024-09-07 15:45:52 +02:00
|
|
|
DerniereModification: Date;
|
2025-01-16 14:42:28 +01:00
|
|
|
Missions: Mission[];
|
2025-05-30 00:06:05 +02:00
|
|
|
Contacts: Contact[];
|
2024-09-06 13:33:16 +02:00
|
|
|
}>;
|
2024-06-03 21:56:35 +02:00
|
|
|
|
|
|
|
|
export function periodOfResistance(
|
|
|
|
|
family: Famille,
|
|
|
|
|
atDate: Date = new Date(Date.now())
|
|
|
|
|
): Period | null {
|
2024-12-08 15:00:58 +01:00
|
|
|
if (
|
|
|
|
|
family.Statut !== statutResistant &&
|
|
|
|
|
family.Statut !== statutExResistant
|
|
|
|
|
) {
|
2024-06-03 21:56:35 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
2024-06-04 21:55:38 +02:00
|
|
|
if (!family.Integration || family.Integration > atDate) {
|
2024-06-03 21:56:35 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
start: family.Integration,
|
|
|
|
|
end:
|
2024-06-04 21:55:38 +02:00
|
|
|
family.Sortie !== null && family.Sortie < atDate ? family.Sortie : atDate,
|
2024-06-03 21:56:35 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2024-06-04 21:55:38 +02:00
|
|
|
return por !== null && por.end < date;
|
2024-06-03 21:56:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|