Skip to content

Api reference

components.fr_health_insurance_affiliation.public.beneficiary

check_can_be_added_as_beneficiary

check_can_be_added_as_beneficiary(
    policy_id,
    first_name,
    birth_date,
    ssn,
    enrollment_type,
    start_date,
)
Source code in components/fr_health_insurance_affiliation/public/beneficiary.py
def check_can_be_added_as_beneficiary(  # noqa: D103
    policy_id: int,
    first_name: str,
    birth_date: date,
    ssn: str | None,
    enrollment_type: EnrollmentType,
    start_date: date,
) -> None:
    BeneficiaryOnboardingService.check_can_be_added_as_beneficiary(
        policy_id=policy_id,
        first_name=first_name,
        birth_date=birth_date,
        ssn=ssn,
        start_date=start_date,
        enrollment_type=EnrollmentType(enrollment_type),
    )

components.fr_health_insurance_affiliation.public.blueprint

fr_health_insurance_affiliation_blueprint module-attribute

fr_health_insurance_affiliation_blueprint = CustomBlueprint(
    "fr_health_affiliation",
    __name__,
    cli_group="fr_affiliation",
)

record_once

record_once(_)

Recording email handler

Source code in components/fr_health_insurance_affiliation/public/blueprint.py
@fr_health_insurance_affiliation_blueprint.record_once
def record_once(_: BlueprintSetupState) -> None:
    """Recording email handler"""
    from components.fr_health_insurance_affiliation.internal.events.email_log_event_handlers import (
        register_email_log_event_handler,
    )

    register_email_log_event_handler()

components.fr_health_insurance_affiliation.public.business_logic

queries

legacy_employment

get_legacy_employment
get_legacy_employment(
    user_id,
    company_id,
    start_date,
    end_date,
    is_cancelled=False,
)

Returns the legacy employment active on effective date.

If no legacy employment is found on effective date, returns the legacy employment active on contract start date to bypass the fact that the legacy employment's start date has been truncated to match the company's contract with Alan NB: This function is mainly intended for bridging Employment Component code and legacy FR code that uses the public.employment table. Use other functions if your use case differs.

Source code in components/fr_health_insurance_affiliation/public/business_logic/queries/legacy_employment.py
def get_legacy_employment(
    user_id: str,
    company_id: str,
    start_date: date,
    end_date: date | None,
    is_cancelled: bool = False,
) -> LegacyEmployment | None:
    """
    Returns the legacy employment active on effective date.

    If no legacy employment is found on effective date, returns the legacy employment active on contract start date
    to bypass the fact that the legacy employment's start date has been truncated to match the company's contract with Alan
    NB: This function is mainly intended for bridging Employment Component code and legacy FR code that uses the public.employment table.
    Use other functions if your use case differs.
    """
    legacy_employment_on_effective_date = (
        get_user_active_employment_in_company(
            user_id=int(user_id),
            company_id=int(company_id),
            active_date=start_date,
        )
        if not is_cancelled
        else get_user_employment_in_company_including_cancelled(
            user_id=int(user_id),
            company_id=int(company_id),
            active_date=start_date,
        )
    )
    if legacy_employment_on_effective_date:
        return legacy_employment_on_effective_date

    # No legacy employment found on effective date could be due to the fact that
    # the legacy employment's start date has been truncated to match the company's contract with Alan
    # In this case, and if we're dealing with the first fragment (effective date == start date)
    # we can try to search for a legacy employment on contract start date instead of effective date

    legacy_employment_after_effective_date = (
        get_user_active_employment_in_company_on_or_after(
            user_id=int(user_id),
            company_id=int(company_id),
            active_date=start_date,
        )
        if not is_cancelled
        else get_user_active_employment_in_company_on_or_after_including_cancelled(
            user_id=int(user_id),
            company_id=int(company_id),
            active_date=start_date,
        )
    )

    if legacy_employment_after_effective_date is None:
        return None

    if (
        legacy_employment_after_effective_date.employment_contract_start_date
        == start_date
    ):
        return legacy_employment_after_effective_date

    if (
        end_date is not None
        and end_date < legacy_employment_after_effective_date.start_date
    ):
        # if the employment is ended and the legacy employment starts after the employment end date, we don't consider it as a match
        return None

    employment_contract = (
        get_eligible_health_contract()
        .from_employment(employment_id=legacy_employment_after_effective_date.id)
        .ongoing(legacy_employment_after_effective_date.start_date)
    )
    if not employment_contract:
        return None

    if (
        employment_contract.start_date
        == legacy_employment_after_effective_date.start_date
    ):
        return legacy_employment_after_effective_date

    return None
get_legacy_employment_or_raise
get_legacy_employment_or_raise(
    user_id,
    company_id,
    start_date,
    end_date,
    is_cancelled=False,
)

Returns the legacy employment active on effective date.

If no legacy employment is found on effective date, returns the legacy employment active on contract start date to bypass the fact that the legacy employment's start date has been truncated to match the company's contract with Alan.

Raises an error if no employment is found at all.

NB: This function is mainly intended for bridging Employment Component code and legacy FR code that uses the public.employment table. Use other functions if your use case differs.

Source code in components/fr_health_insurance_affiliation/public/business_logic/queries/legacy_employment.py
def get_legacy_employment_or_raise(
    user_id: str,
    company_id: str,
    start_date: date,
    end_date: date | None,
    is_cancelled: bool = False,
) -> LegacyEmployment:
    """
    Returns the legacy employment active on effective date.

    If no legacy employment is found on effective date, returns the legacy employment active on contract start date
    to bypass the fact that the legacy employment's start date has been truncated to match the company's contract with Alan.

    Raises an error if no employment is found at all.

    NB: This function is mainly intended for bridging Employment Component code and legacy FR code that uses the
    public.employment table. Use other functions if your use case differs.
    """
    legacy_employment = get_legacy_employment(
        user_id=user_id,
        company_id=company_id,
        start_date=start_date,
        end_date=end_date,
        is_cancelled=is_cancelled,
    )
    if not legacy_employment:
        raise ValueError(
            f"no legacy employment found for user {user_id} in company {company_id}, between {start_date} and {end_date}"
        )
    return legacy_employment

components.fr_health_insurance_affiliation.public.compatibility_instructions

OldStackCompatibleBackFromUnpaidLeave dataclass

OldStackCompatibleBackFromUnpaidLeave(
    unpaid_leave_id, unpaid_leave_return_date
)

Bases: OldStackCompatibleInstruction

execute

execute(commit)
Source code in components/fr_health_insurance_affiliation/public/compatibility_instructions.py
@inject
def execute(self, commit: bool) -> None:  # type: ignore[override]  # @inject makes typing a guessing game  # noqa: D102
    unpaid_leave = get_or_raise_missing_resource(UnpaidLeave, self.unpaid_leave_id)
    employment = unpaid_leave.employment
    new_stack_terminate_unpaid_leave = DeclareUnpaidLeaveReturnDate(
        employment_id=employment.id,
        unpaid_leave_return_date=self.unpaid_leave_return_date,
    )
    new_stack_terminate_unpaid_leave.execute(commit=commit)

unpaid_leave_id instance-attribute

unpaid_leave_id

unpaid_leave_return_date instance-attribute

unpaid_leave_return_date

OldStackCompatibleDeclareUnpaidLeave dataclass

OldStackCompatibleDeclareUnpaidLeave(
    policy_id,
    unpaid_leave_start_date,
    unpaid_leave_return_date,
)

Bases: OldStackCompatibleInstruction

execute

execute(commit)
Source code in components/fr_health_insurance_affiliation/public/compatibility_instructions.py
@inject
def execute(self, commit: bool) -> None:  # type: ignore[override]  # @inject makes typing a guessing game  # noqa: D102
    employment = get_policy_employment(policy_id=self.policy_id)
    if not employment:
        raise ValueError(f"No employment found for policy {self.policy_id}")
    new_stack_remove_employee = DeclareUnpaidLeave(
        employment_id=employment.id,
        unpaid_leave_start_date=self.unpaid_leave_start_date,
        unpaid_leave_return_date=self.unpaid_leave_return_date,
    )
    new_stack_remove_employee.execute(commit=commit)

policy_id instance-attribute

policy_id

unpaid_leave_return_date instance-attribute

unpaid_leave_return_date

unpaid_leave_start_date instance-attribute

unpaid_leave_start_date

OldStackCompatibleInstruction

Bases: Instruction

execute

execute(commit)
Source code in components/fr_health_insurance_affiliation/public/compatibility_instructions.py
def execute(self, commit: bool) -> None:  # type: ignore[override]  # @inject makes typing a guessing game  # noqa: D102
    raise NotImplementedError()

OldStackCompatibleInviteEmployeeWithCoverByDefault dataclass

OldStackCompatibleInviteEmployeeWithCoverByDefault(
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
    soft_onboarding_data,
    end_date=None,
    termination_type=None,
)

Bases: _OldStackCompatibleInviteEmployee

end_date class-attribute instance-attribute

end_date = None

execute

execute(commit, event_bus=None, force_logs=False)
Source code in components/fr_health_insurance_affiliation/public/compatibility_instructions.py
@inject
def execute(  # type: ignore[override]  # @inject makes typing a guessing game  # noqa: D102
    self,
    commit: bool,
    event_bus: EventBus[LifecycleEvent] | None = None,
    force_logs: bool = False,
) -> list[LifecycleEvent]:
    if not event_bus:
        event_bus = AffiliationEventBus()
    user = None
    if self.soft_onboarding_data and self.soft_onboarding_data.ssn:
        user = (
            current_session.query(User)  # noqa: ALN085
            .join(User.insurance_profile)
            .filter(InsuranceProfile.ssn == self.soft_onboarding_data.ssn)
            .one_or_none()
        )
    if not user:
        user = self._get_or_create_user_from_email()
    user.first_name = user.first_name or (
        self.soft_onboarding_data.first_name if self.soft_onboarding_data else None
    )
    user.last_name = user.last_name or (
        self.soft_onboarding_data.last_name if self.soft_onboarding_data else None
    )

    return InviteEmployeeWithCoverByDefault(
        user_id=user.id,
        company_id=self.company_id,
        start_date=self.start_date,
        invite_email=self.invite_email,
        ccn_code=self.ccn_code,
        professional_category=self.professional_category,
        ssn=self.soft_onboarding_data.ssn if self.soft_onboarding_data else None,
        ntt=self.soft_onboarding_data.ntt if self.soft_onboarding_data else None,
        end_date=self.end_date,
        termination_type=self.termination_type,
    ).execute(commit=commit, event_bus=event_bus, force_logs=force_logs)

soft_onboarding_data instance-attribute

soft_onboarding_data

termination_type class-attribute instance-attribute

termination_type = None

OldStackCompatibleInviteExEmployee dataclass

OldStackCompatibleInviteExEmployee(
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
    user_id,
)

Bases: _OldStackCompatibleInviteEmployee

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

execute

execute(commit, event_bus=None, force_logs=False)
Source code in components/fr_health_insurance_affiliation/public/compatibility_instructions.py
@inject
def execute(  # type: ignore[override]  # @inject makes typing a guessing game  # noqa: D102
    self,
    commit: bool,
    event_bus: EventBus[LifecycleEvent] | None = None,
    force_logs: bool = False,
) -> list[LifecycleEvent]:
    if not event_bus:
        event_bus = AffiliationEventBus()
    user = (
        get_or_raise_missing_resource(User, self.user_id)
        if self.user_id
        else self._get_or_create_user_from_email()
    )
    return InviteExEmployee(
        user_id=user.id,
        company_id=self.company_id,
        start_date=self.start_date,
        invite_email=self.invite_email,
        ccn_code=self.ccn_code,
        professional_category=self.professional_category,
    ).execute(commit=commit, event_bus=event_bus, force_logs=force_logs)

invite_email instance-attribute

invite_email

professional_category instance-attribute

professional_category

start_date instance-attribute

start_date

user_id instance-attribute

user_id

OldStackCompatibleInviteInUnpaidLeave dataclass

OldStackCompatibleInviteInUnpaidLeave(
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
    user_id,
    unpaid_leave_return_date,
    unpaid_leave_mandatory_coverage,
    invite_ssn,
    invite_ntt,
)

Bases: _OldStackCompatibleInviteEmployee

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

execute

execute(commit, event_bus=None, force_logs=False)
Source code in components/fr_health_insurance_affiliation/public/compatibility_instructions.py
@inject
def execute(  # type: ignore[override]  # @inject makes typing a guessing game  # noqa: D102
    self,
    commit: bool,
    event_bus: EventBus[LifecycleEvent] | None = None,
    force_logs: bool = False,
) -> list[LifecycleEvent]:
    if not event_bus:
        event_bus = AffiliationEventBus()
    user = (
        get_or_raise_missing_resource(User, self.user_id)
        if self.user_id
        else self._get_or_create_user_from_email()
    )
    return InviteInUnpaidLeave(
        user_id=user.id,
        company_id=self.company_id,
        start_date=self.start_date,
        invite_email=self.invite_email,
        ccn_code=self.ccn_code,
        professional_category=self.professional_category,
        unpaid_leave_return_date=self.unpaid_leave_return_date,
        unpaid_leave_mandatory_coverage=self.unpaid_leave_mandatory_coverage,
        invite_ssn=self.invite_ssn,
        invite_ntt=self.invite_ntt,
    ).execute(commit=commit, event_bus=event_bus, force_logs=force_logs)

invite_email instance-attribute

invite_email

invite_ntt instance-attribute

invite_ntt

invite_ssn instance-attribute

invite_ssn

professional_category instance-attribute

professional_category

start_date instance-attribute

start_date

unpaid_leave_mandatory_coverage instance-attribute

unpaid_leave_mandatory_coverage

unpaid_leave_return_date instance-attribute

unpaid_leave_return_date

user_id instance-attribute

user_id

components.fr_health_insurance_affiliation.public.employment_consumer

Note: Do not import local country code here, do it in the internal component after checking the country code.

fr_health_affiliation_employment_change_consumer

fr_health_affiliation_employment_change_consumer(
    employment_change, event_bus_orchestrator
)
Source code in components/fr_health_insurance_affiliation/public/employment_consumer.py
def fr_health_affiliation_employment_change_consumer(  # noqa: D103
    employment_change: EmploymentChange["FrExtendedValues"],
    event_bus_orchestrator: EventBusOrchestrator,
) -> None:
    if employment_change.country_code != CountryCode.fr:
        return

    from components.fr_health_insurance_affiliation.internal.employment_consumer import (
        on_employment_change as on_employment_change_internal,
    )

    on_employment_change_internal(employment_change, event_bus_orchestrator)

components.fr_health_insurance_affiliation.public.event_bus

AffiliationEventBus

AffiliationEventBus(notify=True, force_logs=False)

Bases: AbstractEventBus[LifecycleEvent]

Source code in components/fr_health_insurance_affiliation/public/event_bus.py
def __init__(
    self,
    notify: bool = True,
    force_logs: bool = False,
) -> None:
    super().__init__()
    self.notify = notify
    self.force_logs = force_logs

force_logs instance-attribute

force_logs = force_logs

notify instance-attribute

notify = notify

publish

publish(event)
Source code in components/fr_health_insurance_affiliation/public/event_bus.py
@override
def publish(self, event: LifecycleEvent) -> None:
    if self.notify is False:
        event.notify = False
    super().publish(event)

components.fr_health_insurance_affiliation.public.events

AdminInitiatedExemption dataclass

AdminInitiatedExemption(user_id, exemption_id, policy_id)

Bases: LifecycleEvent

Event triggered when an admin puts an employee in the exemption flow and wants to send the onboarding link

exemption_id instance-attribute

exemption_id

policy_id instance-attribute

policy_id

user_id instance-attribute

user_id

user_id_for_tracking property

user_id_for_tracking

AniBeneficiariesRemoved dataclass

AniBeneficiariesRemoved(
    primary_user_id,
    policy_id,
    end_date,
    removed_beneficiaries_names,
    kept_beneficiaries_names,
)

Bases: LifecycleEvent

Happens when optional beneficiaries are removed from a policy when the primary enters ANI.

end_date instance-attribute

end_date

kept_beneficiaries_names instance-attribute

kept_beneficiaries_names

policy_id instance-attribute

policy_id

primary_user_id instance-attribute

primary_user_id

removed_beneficiaries_names instance-attribute

removed_beneficiaries_names

user_id_for_tracking property

user_id_for_tracking

AniShortenedToAffiliateToNewHealthCoverage dataclass

AniShortenedToAffiliateToNewHealthCoverage(
    new_policy_id, old_policy_id, new_start_date
)

Bases: LifecycleEvent

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_policy_id instance-attribute

old_policy_id

user_id_for_tracking property

user_id_for_tracking

BeneficiaryCancelled dataclass

BeneficiaryCancelled(
    enrollment_id, policy_id, skip_claim_computation=False
)

Bases: LifecycleEvent

enrollment_id instance-attribute

enrollment_id

policy_id instance-attribute

policy_id

skip_claim_computation class-attribute instance-attribute

skip_claim_computation = False

user_id_for_tracking property

user_id_for_tracking

BeneficiaryRemoved dataclass

BeneficiaryRemoved(
    enrollment_id,
    policy_id,
    end_date,
    skip_claim_computation=False,
)

Bases: LifecycleEvent

end_date instance-attribute

end_date

enrollment_id instance-attribute

enrollment_id

policy_id instance-attribute

policy_id

skip_claim_computation class-attribute instance-attribute

skip_claim_computation = False

user_id_for_tracking property

user_id_for_tracking

BeneficiaryResumed dataclass

BeneficiaryResumed(
    enrollment_id, policy_id, skip_claim_computation=False
)

Bases: LifecycleEvent

enrollment_id instance-attribute

enrollment_id

policy_id instance-attribute

policy_id

skip_claim_computation class-attribute instance-attribute

skip_claim_computation = False

user_id_for_tracking property

user_id_for_tracking

CoveredEmployeeTransferred dataclass

CoveredEmployeeTransferred(
    old_employment_id,
    new_employment_id,
    old_policy_id,
    new_policy_id,
    new_start_date,
    old_ccn_code,
    old_professional_category,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_unpaid_leave_contract_id=None,
)

Bases: LifecycleEvent

new_employment_id instance-attribute

new_employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_ccn_code instance-attribute

old_ccn_code

old_employment_id instance-attribute

old_employment_id

old_policy_id instance-attribute

old_policy_id

old_professional_category instance-attribute

old_professional_category

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

user_id_for_tracking property

user_id_for_tracking

EmployeeAffiliatedToHealthCoverage dataclass

EmployeeAffiliatedToHealthCoverage(
    employment_id, policy_id
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

EmployeeCancelled dataclass

EmployeeCancelled(employment_id)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

user_id_for_tracking property

user_id_for_tracking

EmployeeCreatedAndExempted dataclass

EmployeeCreatedAndExempted(
    user_id, employment_id, invite_email
)

Bases: LifecycleEvent

Happens when an employee is created and directly exempted.

employment_id instance-attribute

employment_id

invite_email instance-attribute

invite_email

user_id instance-attribute

user_id

EmployeeHealthContractChanged dataclass

EmployeeHealthContractChanged(
    employment_id,
    old_policy_id,
    new_policy_id,
    new_start_date,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_unpaid_leave_contract_id=None,
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_policy_id instance-attribute

old_policy_id

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

user_id_for_tracking property

user_id_for_tracking

EmployeeInUnpaidLeaveAffiliatedToHealthCoverage dataclass

EmployeeInUnpaidLeaveAffiliatedToHealthCoverage(
    employment_id,
    old_policy_id,
    new_policy_id,
    new_start_date,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_unpaid_leave_contract_id=None,
    notify=True,
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

notify class-attribute instance-attribute

notify = True

old_policy_id instance-attribute

old_policy_id

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

user_id_for_tracking property

user_id_for_tracking

EmployeeInUnpaidLeaveResumed dataclass

EmployeeInUnpaidLeaveResumed(
    policy_id, employment_id, previous_termination_date
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

policy_id instance-attribute

policy_id

previous_termination_date instance-attribute

previous_termination_date

user_id_for_tracking property

user_id_for_tracking

EmployeeInUnpaidLeaveSoftOnboarded dataclass

EmployeeInUnpaidLeaveSoftOnboarded(
    employment_id,
    old_policy_id,
    new_policy_id,
    new_start_date,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_unpaid_leave_contract_id=None,
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_policy_id instance-attribute

old_policy_id

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

user_id_for_tracking property

user_id_for_tracking

EmployeeInvited dataclass

EmployeeInvited(
    user_id,
    company_id,
    employment_id,
    start_date,
    invite_email,
    invited_as_ex_employee,
)

Bases: LifecycleEvent

Happens when an employee is invited to join the company, or when a new invitation should be sent.

The second case can happen if we: - have covered the employee (or created the employment) - have not been able to send out an invitation due to a missing invite_email - have now received the invite_email

company_id instance-attribute

company_id

employment_id instance-attribute

employment_id

invite_email instance-attribute

invite_email

invited_as_ex_employee instance-attribute

invited_as_ex_employee

start_date instance-attribute

start_date

user_id instance-attribute

user_id

EmployeePopulationChanged dataclass

EmployeePopulationChanged(
    employment_id,
    new_start_date,
    new_policy_id,
    old_ccn_code,
    old_professional_category,
)

Bases: LifecycleEvent

Is not always synonym of a change of contract and policy. In that case, an EmployeeHealthContractChanged is published.

employment_id instance-attribute

employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_ccn_code instance-attribute

old_ccn_code

old_professional_category instance-attribute

old_professional_category

user_id_for_tracking property

user_id_for_tracking

EmployeeRemoved dataclass

EmployeeRemoved(
    employment_id,
    employee_contract_end_date,
    coverage_end_date_excluding_ani,
    policy_id,
    exemption_id,
)

Bases: LifecycleEvent

coverage_end_date_excluding_ani instance-attribute

coverage_end_date_excluding_ani

employee_contract_end_date instance-attribute

employee_contract_end_date

employment_id instance-attribute

employment_id

exemption_id instance-attribute

exemption_id

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

EmployeeResumed dataclass

EmployeeResumed(
    employment_id,
    policy_id,
    exemption_id,
    previous_termination_date,
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

exemption_id instance-attribute

exemption_id

policy_id instance-attribute

policy_id

previous_termination_date instance-attribute

previous_termination_date

user_id_for_tracking property

user_id_for_tracking

EmployeeReturnedAfterAni dataclass

EmployeeReturnedAfterAni(
    user_id,
    company_id,
    new_employment_id,
    new_policy_id,
    old_policy_id,
    new_start_date,
)

Bases: LifecycleEvent

company_id instance-attribute

company_id

new_employment_id instance-attribute

new_employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_policy_id instance-attribute

old_policy_id

user_id instance-attribute

user_id

EmployeeReturningToWorkAffiliatedToHealthCoverage dataclass

EmployeeReturningToWorkAffiliatedToHealthCoverage(
    employment_id,
    old_policy_id,
    new_policy_id,
    new_start_date,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_unpaid_leave_contract_id=None,
    notify=True,
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

notify class-attribute instance-attribute

notify = True

old_policy_id instance-attribute

old_policy_id

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

user_id_for_tracking property

user_id_for_tracking

EmployeeSoftOnboarded dataclass

EmployeeSoftOnboarded(employment_id, policy_id)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

EmployeeStartDateUpdated dataclass

EmployeeStartDateUpdated(employment_id, new_start_date)

Bases: LifecycleEvent

Happens when the start date of an employment is updated.

employment_id instance-attribute

employment_id

new_start_date instance-attribute

new_start_date

user_id_for_tracking property

user_id_for_tracking

EmployeeUncancelled dataclass

EmployeeUncancelled(
    employment_id, with_policy_id, with_exemption_id
)

Bases: LifecycleEvent

employment_id instance-attribute

employment_id

user_id_for_tracking property

user_id_for_tracking

with_exemption_id instance-attribute

with_exemption_id

with_policy_id instance-attribute

with_policy_id

EmploymentFittedToHealthAffiliation dataclass

EmploymentFittedToHealthAffiliation(employment_id)

Bases: LifecycleEvent

Happens when manipulating health affiliation coverage (exemption, policy) and we want to make the employment fit the resulting affiiation periods. We're aiming at getting rid of this.

employment_id instance-attribute

employment_id

user_id_for_tracking property

user_id_for_tracking

ExemptedEmployeeTransferred dataclass

ExemptedEmployeeTransferred(
    old_employment_id,
    new_employment_id,
    old_exemption_id,
    new_exemption_id,
    new_start_date,
    old_ccn_code,
    old_professional_category,
)

Bases: LifecycleEvent

new_employment_id instance-attribute

new_employment_id

new_exemption_id instance-attribute

new_exemption_id

new_start_date instance-attribute

new_start_date

old_ccn_code instance-attribute

old_ccn_code

old_employment_id instance-attribute

old_employment_id

old_exemption_id instance-attribute

old_exemption_id

old_professional_category instance-attribute

old_professional_category

user_id_for_tracking property

user_id_for_tracking

ExemptionCancelled dataclass

ExemptionCancelled(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionCreated dataclass

ExemptionCreated(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionEndDateUpdated dataclass

ExemptionEndDateUpdated(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionInvalidatedToSoftOnboard dataclass

ExemptionInvalidatedToSoftOnboard(
    exemption_id, rejection_reason, cancelled_by_admin
)

Bases: LifecycleEvent

cancelled_by_admin instance-attribute

cancelled_by_admin

exemption_id instance-attribute

exemption_id

rejection_reason instance-attribute

rejection_reason

user_id_for_tracking property

user_id_for_tracking

ExemptionJustificationFileUploaded dataclass

ExemptionJustificationFileUploaded(
    exemption_id, exemption_justification_id
)

Bases: LifecycleEvent

Event triggered when an exemption justification is uploaded

exemption_id instance-attribute

exemption_id

exemption_justification_id instance-attribute

exemption_justification_id

user_id_for_tracking property

user_id_for_tracking

ExemptionJustificationReviewed dataclass

ExemptionJustificationReviewed(
    exemption_id, exemption_justification_id, is_override
)

Bases: LifecycleEvent

Event triggered when an exemption justification has been reviewed. The event is published no matter whether the justification was deemed valid or not.

exemption_id instance-attribute

exemption_id

exemption_justification_id instance-attribute

exemption_justification_id

is_override instance-attribute

is_override

user_id_for_tracking property

user_id_for_tracking

ExemptionRestarted dataclass

ExemptionRestarted(exemption_id, new_exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

new_exemption_id instance-attribute

new_exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionRestartedWithoutCreation dataclass

ExemptionRestartedWithoutCreation(exemption_id)

Bases: LifecycleEvent

Hack to manage the old exemption flow where we don't create a new exemption when restarting an exemption but invalidate the justifications instead

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionResumed dataclass

ExemptionResumed(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionStartDateUpdated dataclass

ExemptionStartDateUpdated(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionStarted dataclass

ExemptionStarted(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionTerminated dataclass

ExemptionTerminated(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionUncancelled dataclass

ExemptionUncancelled(exemption_id)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

ExemptionValidityDateUpdated dataclass

ExemptionValidityDateUpdated(
    exemption_id, validity_end_date
)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

user_id_for_tracking property

user_id_for_tracking

validity_end_date instance-attribute

validity_end_date

ExistingUserAffiliatedToHealthCoverage dataclass

ExistingUserAffiliatedToHealthCoverage(user_id)

Bases: LifecycleEvent

user_id instance-attribute

user_id

HealthCoverageAffiliationCreated dataclass

HealthCoverageAffiliationCreated(policy_id, start_date)

Bases: LifecycleEvent

policy_id instance-attribute

policy_id

start_date instance-attribute

start_date

user_id_for_tracking property

user_id_for_tracking

HealthCoverageAffiliationCreatedForExEmployee dataclass

HealthCoverageAffiliationCreatedForExEmployee(policy_id)

Bases: LifecycleEvent

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

IndividualHealthCoverageCancelled dataclass

IndividualHealthCoverageCancelled(policy_id, user_id)

Bases: LifecycleEvent

policy_id instance-attribute

policy_id

user_id instance-attribute

user_id

IndividualHealthCoverageTerminated dataclass

IndividualHealthCoverageTerminated(
    user_id,
    policy_id,
    end_date,
    contract_termination_type,
    contract_termination_details,
)

Bases: LifecycleEvent

contract_termination_details instance-attribute

contract_termination_details

contract_termination_type instance-attribute

contract_termination_type

end_date instance-attribute

end_date

policy_id instance-attribute

policy_id

user_id instance-attribute

user_id

user_id_for_tracking property

user_id_for_tracking

IndividualTerminatedAndCoveredAsEmployee dataclass

IndividualTerminatedAndCoveredAsEmployee(
    old_policy_id, new_policy_id, new_start_date
)

Bases: LifecycleEvent

new_policy_id instance-attribute

new_policy_id

new_start_date instance-attribute

new_start_date

old_policy_id instance-attribute

old_policy_id

user_id_for_tracking property

user_id_for_tracking

LifecycleEvent dataclass

LifecycleEvent()

Bases: DataClassJsonMixin

__post_init__

__post_init__()
Source code in components/fr_health_insurance_affiliation/public/events.py
def __post_init__(self) -> None:  # noqa: D105
    if not hasattr(self, "notify"):
        self.notify = True

get_user_id_from_policy_id

get_user_id_from_policy_id(policy_id)
Source code in components/fr_health_insurance_affiliation/public/events.py
def get_user_id_from_policy_id(self, policy_id: int) -> int:  # noqa: D102
    from components.fr.internal.models.enrollment import (  # noqa: ALN039,ALN069
        Enrollment,
    )
    from components.fr.internal.models.insurance_profile import (  # noqa: ALN039,ALN069
        InsuranceProfile,
    )
    from components.fr.internal.models.policy import (  # noqa: ALN039,ALN069
        Policy,
    )

    policy = (
        current_session.query(Policy)  # noqa: ALN085
        .join(
            Enrollment,
            and_(
                Enrollment.policy_id == Policy.id,
                Enrollment.type == EnrollmentType.primary,
            ),
        )
        .join(Enrollment.insurance_profile)
        .options(
            contains_eager(Policy.enrollments)
            .load_only(Enrollment.id, Enrollment.insurance_profile_id)
            .contains_eager(Enrollment.insurance_profile)
            .load_only(InsuranceProfile.user_id)
        )
        .filter(Policy.id == policy_id)
        .one()
    )
    return policy.enrollments[0].insurance_profile.user_id

user_id_for_tracking property

user_id_for_tracking

OnboardingUnpaused dataclass

OnboardingUnpaused(
    unpaused_onboarding_employment_id, ended_employment_id
)

Bases: LifecycleEvent

ended_employment_id instance-attribute

ended_employment_id

unpaused_onboarding_employment_id instance-attribute

unpaused_onboarding_employment_id

user_id_for_tracking property

user_id_for_tracking

PendingExemptionUpdated dataclass

PendingExemptionUpdated(
    exemption_id,
    new_exemption_type=None,
    new_health_coverage_insurer_name=None,
    new_health_coverage_end_date=None,
    new_cdd_end_date=None,
)

Bases: LifecycleEvent

exemption_id instance-attribute

exemption_id

new_cdd_end_date class-attribute instance-attribute

new_cdd_end_date = None

new_exemption_type class-attribute instance-attribute

new_exemption_type = None

new_health_coverage_end_date class-attribute instance-attribute

new_health_coverage_end_date = None

new_health_coverage_insurer_name class-attribute instance-attribute

new_health_coverage_insurer_name = None

user_id_for_tracking property

user_id_for_tracking

PolicyCancelled dataclass

PolicyCancelled(
    policy_id,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_ani_contract_id=None,
    policy_unpaid_leave_contract_id=None,
    individual_health_contract_id=None,
)

Bases: LifecycleEvent

individual_health_contract_id class-attribute instance-attribute

individual_health_contract_id = None

policy_ani_contract_id class-attribute instance-attribute

policy_ani_contract_id = None

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_id instance-attribute

policy_id

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

user_id_for_tracking property

user_id_for_tracking

PolicyResumed dataclass

PolicyResumed(policy_id)

Bases: LifecycleEvent

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

PolicyStartDateUpdated dataclass

PolicyStartDateUpdated(policy_id)

Bases: LifecycleEvent

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

PolicyTerminated dataclass

PolicyTerminated(
    policy_id,
    employee_contract_end_date=None,
    coverage_end_date_excluding_ani=None,
    policy_option_contract_id=None,
    policy_direct_billing_contract_id=None,
    policy_ani_contract_id=None,
    policy_unpaid_leave_contract_id=None,
    previous_end_date=None,
    previous_ani_start_on=None,
    previous_max_ani_end_on=None,
    previous_termination_type=None,
    is_latest_health_affiliation_for_employee=None,
    notify=True,
)

Bases: LifecycleEvent

coverage_end_date_excluding_ani class-attribute instance-attribute

coverage_end_date_excluding_ani = None

employee_contract_end_date class-attribute instance-attribute

employee_contract_end_date = None

is_latest_health_affiliation_for_employee class-attribute instance-attribute

is_latest_health_affiliation_for_employee = None

notify class-attribute instance-attribute

notify = True

policy_ani_contract_id class-attribute instance-attribute

policy_ani_contract_id = None

policy_direct_billing_contract_id class-attribute instance-attribute

policy_direct_billing_contract_id = None

policy_id instance-attribute

policy_id

policy_option_contract_id class-attribute instance-attribute

policy_option_contract_id = None

policy_unpaid_leave_contract_id class-attribute instance-attribute

policy_unpaid_leave_contract_id = None

previous_ani_start_on class-attribute instance-attribute

previous_ani_start_on = None

previous_end_date class-attribute instance-attribute

previous_end_date = None

previous_max_ani_end_on class-attribute instance-attribute

previous_max_ani_end_on = None

previous_termination_type class-attribute instance-attribute

previous_termination_type = None

user_id_for_tracking property

user_id_for_tracking

PolicyUncancelled dataclass

PolicyUncancelled(policy_id, with_beneficiary_enrollments)

Bases: LifecycleEvent

policy_id instance-attribute

policy_id

user_id_for_tracking property

user_id_for_tracking

with_beneficiary_enrollments instance-attribute

with_beneficiary_enrollments

SecondaryBeneficiaryAdded dataclass

SecondaryBeneficiaryAdded(
    author_id,
    new_beneficiary_user_id,
    policy_id,
    beneficiary_enrollment_id,
    start_date,
    enrollment_type,
)

Bases: LifecycleEvent

author_id instance-attribute

author_id

beneficiary_enrollment_id instance-attribute

beneficiary_enrollment_id

enrollment_type instance-attribute

enrollment_type

new_beneficiary_user_id instance-attribute

new_beneficiary_user_id

policy_id instance-attribute

policy_id

start_date instance-attribute

start_date

user_id_for_tracking property

user_id_for_tracking

SignedSwornStatementFileProcessed dataclass

SignedSwornStatementFileProcessed(
    exemption_id, sworn_statement_id
)

Bases: LifecycleEvent

Event triggered when an admin or UCE uploads a signed sworn statement for an exemption or a sworn statement is signed through hellosign

exemption_id instance-attribute

exemption_id

sworn_statement_id instance-attribute

sworn_statement_id

user_id_for_tracking property

user_id_for_tracking

SwornStatementDocumentCreated dataclass

SwornStatementDocumentCreated(
    exemption_id, sworn_statement_document_id
)

Bases: LifecycleEvent

Event triggered when a sworn statement document is created

exemption_id instance-attribute

exemption_id

sworn_statement_document_id instance-attribute

sworn_statement_document_id

user_id_for_tracking property

user_id_for_tracking

UnpaidLeaveCancelled dataclass

UnpaidLeaveCancelled(unpaid_leave_id)

Bases: LifecycleEvent

unpaid_leave_id instance-attribute

unpaid_leave_id

user_id_for_tracking property

user_id_for_tracking

UnpaidLeaveDeclared dataclass

UnpaidLeaveDeclared(
    policy_id, unpaid_leave_return_date, notify=True
)

Bases: LifecycleEvent

notify class-attribute instance-attribute

notify = True

policy_id instance-attribute

policy_id

unpaid_leave_return_date instance-attribute

unpaid_leave_return_date

user_id_for_tracking property

user_id_for_tracking

UnpaidLeaveEndDateUpdated dataclass

UnpaidLeaveEndDateUpdated(
    unpaid_leave_id, new_end_date, previous_end_date
)

Bases: LifecycleEvent

new_end_date instance-attribute

new_end_date

previous_end_date instance-attribute

previous_end_date

unpaid_leave_id instance-attribute

unpaid_leave_id

user_id_for_tracking property

user_id_for_tracking

UnpaidLeaveStartDateUpdated dataclass

UnpaidLeaveStartDateUpdated(
    unpaid_leave_id, new_start_date, previous_start_date
)

Bases: LifecycleEvent

new_start_date instance-attribute

new_start_date

previous_start_date instance-attribute

previous_start_date

unpaid_leave_id instance-attribute

unpaid_leave_id

user_id_for_tracking property

user_id_for_tracking

UserAffiliatedToAlsaceMoselle dataclass

UserAffiliatedToAlsaceMoselle(
    enrollment_id, start_date, end_date
)

Bases: LifecycleEvent

end_date instance-attribute

end_date

enrollment_id instance-attribute

enrollment_id

start_date instance-attribute

start_date

user_id_for_tracking property

user_id_for_tracking

components.fr_health_insurance_affiliation.public.instructions

AddEmailToEmaillessEmployee dataclass

AddEmailToEmaillessEmployee(
    employment_id, new_invite_email
)

Bases: Instruction

employment_id instance-attribute

employment_id

new_invite_email instance-attribute

new_invite_email

AddExistingUserAsBeneficiary dataclass

AddExistingUserAsBeneficiary(
    author_id,
    user_id,
    policy_id,
    start_date,
    enrollment_type,
)

Bases: Instruction

author_id instance-attribute

author_id

enrollment_type instance-attribute

enrollment_type

policy_id instance-attribute

policy_id

start_date instance-attribute

start_date

user_id instance-attribute

user_id

AddSecondaryBeneficiary dataclass

AddSecondaryBeneficiary(
    author_id,
    first_name,
    last_name,
    birth_date,
    policy_id,
    start_date,
    enrollment_type,
    lang,
    ssn=None,
    referent_ssns=None,
    birth_ranks=None,
)

Bases: Instruction

IF the member already exists and is in ANI, we stop it and affiliate the member to the new policy

author_id instance-attribute

author_id

birth_date instance-attribute

birth_date

birth_ranks class-attribute instance-attribute

birth_ranks = None

enrollment_type instance-attribute

enrollment_type

first_name instance-attribute

first_name

lang instance-attribute

lang

last_name instance-attribute

last_name

policy_id instance-attribute

policy_id

referent_ssns class-attribute instance-attribute

referent_ssns = None

ssn class-attribute instance-attribute

ssn = None

start_date instance-attribute

start_date

AffiliateEmployeeInUnpaidLeaveToHealthCoverage dataclass

AffiliateEmployeeInUnpaidLeaveToHealthCoverage(
    unpaid_leave_id,
)

Bases: Instruction

Create a health coverage for an employee in unpaid leave

unpaid_leave_id instance-attribute

unpaid_leave_id

AffiliateEmployeeReturningToWorkToHealthCoverage dataclass

AffiliateEmployeeReturningToWorkToHealthCoverage(
    unpaid_leave_id,
)

Bases: Instruction

Create a health coverage for an employee returning to work after an unpaid leave

unpaid_leave_id instance-attribute

unpaid_leave_id

AffiliateEmployeeToAlsaceMoselle dataclass

AffiliateEmployeeToAlsaceMoselle(
    employment_id, start_date=None, end_date=None
)

Bases: Instruction

Instruction to affiliate an employee to the Alsace Moselle regime.

⚠️ This instruction bases itself on an employee: it only affiliates the primary for that employment. it is only meant to be used when we are notified of changes from the Employment component. Please use the AffiliateUserToAlsaceMoselle for any other usages

employment_id instance-attribute

employment_id

end_date class-attribute instance-attribute

end_date = None

start_date class-attribute instance-attribute

start_date = None

AffiliateExemptedEmployeeToHealthCoverage dataclass

AffiliateExemptedEmployeeToHealthCoverage(
    employment_id,
    start_date,
    previous_beneficiaries_to_keep_enrollment_ids,
    ssn=None,
    ntt=None,
)

Bases: Instruction

Terminate or cancel the exemption and affiliates the employee to health coverage If start date equals to the exemption start date, the exemption is cancelled, otherwise it's terminated

:param previous_beneficiaries_to_keep_enrollment_ids When affiliating an employee that was covered by Alan before, we can add their former beneficiaries to the new coverage Note: neither beneficiaries nor employee will receive any communication on this (SecondaryBeneficiaryAdded event is not published)

employment_id instance-attribute

employment_id

ntt class-attribute instance-attribute

ntt = None

previous_beneficiaries_to_keep_enrollment_ids instance-attribute

previous_beneficiaries_to_keep_enrollment_ids

ssn class-attribute instance-attribute

ssn = None

start_date instance-attribute

start_date

AffiliateInvitedEmployeeToHealthCoverage dataclass

AffiliateInvitedEmployeeToHealthCoverage(
    employment_id,
    ssn=None,
    ntt=None,
    previous_beneficiaries_to_keep_enrollment_ids=None,
)

Bases: Instruction

Create a health coverage for an invited employee

:param previous_beneficiaries_to_keep_enrollment_ids When affiliating an employee that was covered by Alan before, we can add their former beneficiaries to the new coverage Note: neither beneficiaries nor employee will receive any communication on this (SecondaryBeneficiaryAdded event is not published)

employment_id instance-attribute

employment_id

ntt class-attribute instance-attribute

ntt = None

previous_beneficiaries_to_keep_enrollment_ids class-attribute instance-attribute

previous_beneficiaries_to_keep_enrollment_ids = None

ssn class-attribute instance-attribute

ssn = None

AffiliateUserToAlsaceMoselle dataclass

AffiliateUserToAlsaceMoselle(
    enrollment_id, start_date=None, end_date=None
)

Bases: Instruction

Instruction to affiliate a User to the Alsace Moselle regime.

end_date class-attribute instance-attribute

end_date = None

Defines when the Alsace Moselle affiliation should end. If none is provided, the enrollment's end date will be used.

enrollment_id instance-attribute

enrollment_id

The ID of the User's enrollment we want to affiliate to Alsace Moselle.

start_date class-attribute instance-attribute

start_date = None

Defines when the Alsace Moselle affiliation should start. If none is provided, the enrollment's start date will be used.

CancelBeneficiary dataclass

CancelBeneficiary(enrollment_id)

Bases: Instruction

enrollment_id instance-attribute

enrollment_id

CancelEmployee dataclass

CancelEmployee(employment_id)

Bases: Instruction

Cancel an Employee and all related affiliations

employment_id instance-attribute

employment_id

CancelEmployeeHealthCoverage dataclass

CancelEmployeeHealthCoverage(policy_id)

Bases: Instruction

Cancel a policy, and the related employment but only if no other Exemption/Policy is linked to the Employment

policy_id instance-attribute

policy_id

CancelExemption dataclass

CancelExemption(exemption_id)

Bases: Instruction

Cancel an exemption, and the related employment but only if no other Exemption/Policy is linked to the Employment

exemption_id instance-attribute

exemption_id

CancelIndividualHealthCoverage dataclass

CancelIndividualHealthCoverage(policy_id)

Bases: Instruction

policy_id instance-attribute

policy_id

CancelInvitedEmployee dataclass

CancelInvitedEmployee(employment_id)

Bases: Instruction

Cancel an Employee, must be invited only (no affiliation, active or past). If there's a pending exemption for this employment, it'll be cancelled as well.

employment_id instance-attribute

employment_id

CancelRemoveBeneficiary dataclass

CancelRemoveBeneficiary(enrollment_id)

Bases: Instruction

enrollment_id instance-attribute

enrollment_id

CancelUnpaidLeave dataclass

CancelUnpaidLeave(unpaid_leave_id)

Bases: Instruction

Cancel unpaid leave by flagging it It cancels only if no health affiliation is linked

unpaid_leave_id instance-attribute

unpaid_leave_id

ChangeContractInCompany dataclass

ChangeContractInCompany(
    employment_id, change_date, new_contract_id
)

Bases: Instruction

Used during contract split to change employee's contracts

change_date instance-attribute

change_date

employment_id instance-attribute

employment_id

new_contract_id instance-attribute

new_contract_id

ChangePopulation dataclass

ChangePopulation(
    employment_id,
    change_date,
    new_ccn_code,
    new_professional_category,
)

Bases: Instruction

special cases: when updating population of an employee that is already ended - if the end date is in the past, we don't allow the change (raises a NotImplementedError) - if the end date is in the future - if the change date is before the end date -> we do the change - if the change date is after the end date -> we don't allow the change (raises an ErrorCode)

change_date instance-attribute

change_date

employment_id instance-attribute

employment_id

new_ccn_code instance-attribute

new_ccn_code

new_professional_category instance-attribute

new_professional_category

CoverFreelancerAsEmployee dataclass

CoverFreelancerAsEmployee(
    freelancer_policy_id,
    start_date,
    company_id,
    invite_email,
    ccn_code,
    professional_category,
    ssn,
    ntt,
    previous_beneficiaries_to_keep_enrollment_ids,
    end_date=None,
    termination_type=None,
    external_employee_id=None,
)

Bases: Instruction

⚠️ if previous_beneficiaries_to_keep_enrollment_ids is None, a missing_conditional_parameter error will be raised (this is part of the conflict solving mechanism for Marmot)

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

end_date class-attribute instance-attribute

end_date = None

external_employee_id class-attribute instance-attribute

external_employee_id = None

freelancer_policy_id instance-attribute

freelancer_policy_id

invite_email instance-attribute

invite_email

ntt instance-attribute

ntt

previous_beneficiaries_to_keep_enrollment_ids instance-attribute

previous_beneficiaries_to_keep_enrollment_ids

professional_category instance-attribute

professional_category

ssn instance-attribute

ssn

start_date instance-attribute

start_date

termination_type class-attribute instance-attribute

termination_type = None

CreateExemptionJustificationDocument dataclass

CreateExemptionJustificationDocument(
    exemption_id,
    last_override_author_id=None,
    last_overridden_at=None,
    reviewed_by_alan=None,
    status=None,
    end_date=None,
)

Bases: Instruction

Instruction to create an exemption justification document. This will be used to create an exemption justification document.

end_date class-attribute instance-attribute

end_date = None

exemption_id instance-attribute

exemption_id

last_overridden_at class-attribute instance-attribute

last_overridden_at = None

last_override_author_id class-attribute instance-attribute

last_override_author_id = None

reviewed_by_alan class-attribute instance-attribute

reviewed_by_alan = None

status class-attribute instance-attribute

status = None

CreatePendingExemption dataclass

CreatePendingExemption(
    employment_id,
    start_date,
    exemption_type=None,
    end_date=None,
    health_coverage_insurer_name=None,
    health_coverage_end_date=None,
    cdd_end_date=None,
    previous_exemption_id=None,
    is_admin_initiated_exemption=False,
)

Bases: Instruction

Create a pending exemption for a specific employment The exemption will be created with a pending status and will need to be started later on after the member has completed their onboarding

A few parameters are mandatory: - employment_id: the employment the exemption is linked to - start_date: the date the exemption will start

cdd_end_date class-attribute instance-attribute

cdd_end_date = None

employment_id instance-attribute

employment_id

end_date class-attribute instance-attribute

end_date = None

exemption_type class-attribute instance-attribute

exemption_type = None

health_coverage_end_date class-attribute instance-attribute

health_coverage_end_date = None

health_coverage_insurer_name class-attribute instance-attribute

health_coverage_insurer_name = None

is_admin_initiated_exemption class-attribute instance-attribute

is_admin_initiated_exemption = False

previous_exemption_id class-attribute instance-attribute

previous_exemption_id = None

start_date instance-attribute

start_date

CreateSwornStatementDocument dataclass

CreateSwornStatementDocument(exemption_id)

Bases: Instruction

Instruction to create a sworn statement document for an exemption. HelloSign flow will create an unsigned document.

exemption_id instance-attribute

exemption_id

DeclareUnpaidLeave dataclass

DeclareUnpaidLeave(
    employment_id,
    unpaid_leave_start_date,
    unpaid_leave_return_date=None,
    unpaid_leave_mandatory_coverage=None,
    bypass_past_date_check=False,
)

Bases: Instruction

bypass_past_date_check class-attribute instance-attribute

bypass_past_date_check = False

employment_id instance-attribute

employment_id

unpaid_leave_mandatory_coverage class-attribute instance-attribute

unpaid_leave_mandatory_coverage = None

unpaid_leave_return_date class-attribute instance-attribute

unpaid_leave_return_date = None

unpaid_leave_start_date instance-attribute

unpaid_leave_start_date

DeclareUnpaidLeaveReturnDate dataclass

DeclareUnpaidLeaveReturnDate(
    employment_id, unpaid_leave_return_date
)

Bases: Instruction

Update the end_date of the current or next UnpaidLeave

employment_id instance-attribute

employment_id

unpaid_leave_return_date instance-attribute

unpaid_leave_return_date

ExemptCoveredEmployee dataclass

ExemptCoveredEmployee(
    employment_id, start_date, exemption_type=None
)

Bases: Instruction

Create an exemption for a covered employee

employment_id instance-attribute

employment_id

exemption_type class-attribute instance-attribute

exemption_type = None

start_date instance-attribute

start_date

ExemptExistingUser dataclass

ExemptExistingUser(
    user_id,
    company_id,
    invite_email,
    start_date,
    exemption_type=None,
    professional_category=None,
    ccn_code=None,
    external_employee_id=None,
)

Bases: Instruction

Create an exemption for an existing user

ccn_code class-attribute instance-attribute

ccn_code = None

company_id instance-attribute

company_id

exemption_type class-attribute instance-attribute

exemption_type = None

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

professional_category class-attribute instance-attribute

professional_category = None

start_date instance-attribute

start_date

user_id instance-attribute

user_id

ExemptInvitedEmployee dataclass

ExemptInvitedEmployee(employment_id, exemption_type=None)

Bases: Instruction

Create an exemption for an invited employee

employment_id instance-attribute

employment_id

exemption_type class-attribute instance-attribute

exemption_type = None

FlagExemptionJustificationAsInReview dataclass

FlagExemptionJustificationAsInReview(
    exemption_justification_ids,
)

Bases: Instruction

Flag exemption justifications as in review by setting the last_in_review_at field to the current datetime

exemption_justification_ids instance-attribute

exemption_justification_ids

INSTRUCTION_HANDLERS module-attribute

INSTRUCTION_HANDLERS = {
    InviteEmployee: invite_employee,
    InviteEmployeeWithCoverByDefault: invite_employee_with_cover_by_default,
    InviteExEmployee: invite_ex_employee,
    InviteInUnpaidLeave: invite_in_unpaid_leave,
    AddEmailToEmaillessEmployee: add_email_to_emailless_employee,
    CoverFreelancerAsEmployee: invite_and_cover_freelancer_as_employee,
    RemoveEmployee: remove_employee,
    TerminateAllHealthAffiliationsFromCompany: terminate_all_health_affiliations_from_company,
    RemoveEmployeeWithoutLastCareCheck: remove_employee_without_last_care_check,
    AddSecondaryBeneficiary: add_secondary_beneficiary,
    AddExistingUserAsBeneficiary: add_existing_user_as_beneficiary,
    RemoveBeneficiary: remove_beneficiary,
    AffiliateInvitedEmployeeToHealthCoverage: affiliate_invited_employee_to_health_coverage,
    AffiliateExemptedEmployeeToHealthCoverage: affiliate_exempted_employee_to_health_coverage,
    AffiliateEmployeeInUnpaidLeaveToHealthCoverage: affiliate_employee_in_unpaid_leave_to_health_coverage,
    AffiliateEmployeeReturningToWorkToHealthCoverage: affiliate_employee_returning_to_work_to_health_coverage,
    ExemptInvitedEmployee: exempt_invited_employee,
    ExemptCoveredEmployee: exempt_covered_employee,
    ExemptExistingUser: exempt_existing_user,
    MakeEmploymentFitAffiliations: make_employment_fit_affiliations,
    CancelInvitedEmployee: cancel_invited_employee,
    CancelEmployee: cancel_employee,
    CancelExemption: cancel_exemption,
    UncancelEmployee: uncancel_employee,
    UpdateExemptionEndDate: update_exemption_end_date,
    UpdateExemptionStartDate: update_exemption_start_date,
    CreatePendingExemption: create_pending_exemption,
    UpdatePendingExemption: update_pending_exemption,
    StartExemption: start_exemption,
    UpdateExemptionValidityDate: update_exemption_validity_date,
    UpdateUnpaidLeaveStartDate: update_unpaid_leave_start_date,
    UpdateUnpaidLeaveEndDate: update_unpaid_leave_end_date,
    CancelUnpaidLeave: cancel_unpaid_leave_without_affiliation,
    UpdateHealthCoverageAffiliationEndDate: update_health_coverage_affiliation_end_date,
    UpdateHealthCoverageAffiliationStartDate: update_health_coverage_affiliation_start_date,
    UpdateEmployeeTerminationType: update_employee_termination_type,
    UpdateEmployeeStartDate: update_employee_start_date,
    CancelBeneficiary: cancel_beneficiary,
    CancelEmployeeHealthCoverage: cancel_employee_policy,
    ResumeEmployeeInUnpaidLeave: resume_employee_in_unpaid_leave,
    DeclareUnpaidLeave: declare_unpaid_leave,
    TransferEmployee: transfer_employee,
    MoveExemptedEmployeeToAnotherCompany: move_exempted_employee_to_another_company,
    MoveCoveredEmployeeToAnotherCompany: move_covered_employee_to_another_company,
    ChangeContractInCompany: change_contract_in_company,
    ChangePopulation: change_population,
    DeclareUnpaidLeaveReturnDate: declare_unpaid_leave_return_date,
    ResumeBeneficiary: resume_beneficiary,
    ResumeEmployee: resume_employee,
    SoftOnboardEmployee: soft_onboard_employee,
    SoftOnboardExemptedEmployee: soft_onboard_exempted_employee,
    ScheduleSoftOnboarding: schedule_soft_onboarding,
    ScheduleSoftOnboardingWithExemptionInvalidation: schedule_soft_onboarding_with_exemption_invalidation,
    RestartExemptionProcess: restart_exemption_process,
    TerminateIndividualHealthCoverage: terminate_individual_health_coverage,
    CancelIndividualHealthCoverage: cancel_individual_health_coverage,
    ResumeIndividualHealthCoverage: resume_individual_health_coverage,
    InviteAndAffiliateToHealthCoverageIfPossible: affiliate_or_invite_existing_user,
    SetViewedTermsAtForEmployee: set_viewed_terms_at_for_employee,
    AffiliateEmployeeToAlsaceMoselle: affiliate_employee_to_alsace_moselle,
    AffiliateUserToAlsaceMoselle: affiliate_user_to_alsace_moselle,
    CreateSwornStatementDocument: create_sworn_statement_document,
    UploadSignedSwornStatementFile: upload_signed_sworn_statement_file,
    ProcessSignedSwornStatement: process_signed_sworn_statement,
    ReviewExemptionJustification: review_exemption_justification,
    ReviewExemptionJustificationForAdmin: review_exemption_justification_for_admin,
    SetExemptionJustificationReviewEscalationLevel: set_exemption_justification_review_escalation_level,
    FlagExemptionJustificationAsInReview: flag_exemption_justification_as_in_review,
    CreateExemptionJustificationDocument: create_exemption_justification_document,
    UploadExemptionJustificationFile: upload_exemption_justification_file,
}

Instruction

Bases: DataClassJsonMixin

execute

execute(
    commit,
    event_bus=None,
    event_bus_provider=_default_event_bus_provider,
    force_logs=False,
)
Source code in components/fr_health_insurance_affiliation/public/instructions.py
@inject
def execute(  # noqa: D102
    self,
    commit: bool,
    event_bus: EventBus[LifecycleEvent] | None = None,
    event_bus_provider: (
        Callable[["Instruction"], EventBus[LifecycleEvent]] | None
    ) = _default_event_bus_provider,
    force_logs: bool = False,
) -> list[LifecycleEvent]:
    if event_bus is None:
        event_bus = mandatory(event_bus_provider)(self)

    with bound_contextvars(
        user_lifecycle={
            "instruction_name": self.__class__.__name__,
            "instruction_data": self.to_dict(),
        }
    ):
        handler = INSTRUCTION_HANDLERS[self.__class__]
        handler(self, event_bus)
        if commit or force_logs:
            current_logger.info(f"Executed instruction {self.__class__.__name__}")

        if commit:
            current_session.commit()
        else:
            current_session.flush()
        applied_events = event_bus.apply(commit=commit)
        if self._is_running_employment_component_is_set_to_true_here:
            is_running_employment_component.set(False)
        return applied_events

InstructionHandler

Bases: Protocol[T]

__call__

__call__(instruction, event_bus)
Source code in components/fr_health_insurance_affiliation/public/instructions.py
def __call__(  # noqa: D102
    self, instruction: T, event_bus: EventBus[LifecycleEvent]
) -> None: ...

InviteAndAffiliateToHealthCoverageIfPossible dataclass

InviteAndAffiliateToHealthCoverageIfPossible(
    user_id,
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
    ssn,
    ntt,
    previous_beneficiaries_to_keep_enrollment_ids,
    external_employee_id=None,
)

Bases: Instruction

Affiliates an existing user to health coverage. If we can't, only invite them.

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

ntt instance-attribute

ntt

previous_beneficiaries_to_keep_enrollment_ids instance-attribute

previous_beneficiaries_to_keep_enrollment_ids

professional_category instance-attribute

professional_category

ssn instance-attribute

ssn

start_date instance-attribute

start_date

user_id instance-attribute

user_id

InviteEmployee dataclass

InviteEmployee(
    user_id,
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
    ssn=None,
    ntt=None,
    external_employee_id=None,
)

Bases: Instruction

Does not cover the employee by default, only invites them to the company. If the employee is already covered in the company on start date, an ErrorCode is raised.

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

ntt class-attribute instance-attribute

ntt = None

professional_category instance-attribute

professional_category

ssn class-attribute instance-attribute

ssn = None

start_date instance-attribute

start_date

user_id instance-attribute

user_id

InviteEmployeeWithCoverByDefault dataclass

InviteEmployeeWithCoverByDefault(
    user_id,
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
    ssn,
    ntt,
    end_date=None,
    termination_type=None,
    external_employee_id=None,
)

Bases: Instruction

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

end_date class-attribute instance-attribute

end_date = None

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

ntt instance-attribute

ntt

professional_category instance-attribute

professional_category

ssn instance-attribute

ssn

start_date instance-attribute

start_date

termination_type class-attribute instance-attribute

termination_type = None

user_id instance-attribute

user_id

InviteExEmployee dataclass

InviteExEmployee(
    user_id,
    company_id,
    start_date,
    invite_email,
    ccn_code,
    professional_category,
)

Bases: Instruction

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

invite_email instance-attribute

invite_email

professional_category instance-attribute

professional_category

start_date instance-attribute

start_date

user_id instance-attribute

user_id

InviteInUnpaidLeave dataclass

InviteInUnpaidLeave(
    user_id,
    company_id,
    start_date,
    unpaid_leave_return_date,
    invite_email,
    ccn_code,
    professional_category,
    invite_ssn,
    invite_ntt,
    unpaid_leave_mandatory_coverage=False,
    external_employee_id=None,
)

Bases: Instruction

ccn_code instance-attribute

ccn_code

company_id instance-attribute

company_id

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

invite_ntt instance-attribute

invite_ntt

invite_ssn instance-attribute

invite_ssn

professional_category instance-attribute

professional_category

start_date instance-attribute

start_date

unpaid_leave_mandatory_coverage class-attribute instance-attribute

unpaid_leave_mandatory_coverage = False

unpaid_leave_return_date instance-attribute

unpaid_leave_return_date

user_id instance-attribute

user_id

MakeEmploymentFitAffiliations dataclass

MakeEmploymentFitAffiliations(employment_id)

Bases: Instruction

Make employment fit the affiliations

employment_id instance-attribute

employment_id

MoveCoveredEmployeeToAnotherCompany dataclass

MoveCoveredEmployeeToAnotherCompany(
    employment_id,
    destination_company_id,
    move_date,
    invite_email,
    keep_admin,
    destination_ccn_code,
    destination_professional_category,
    keep_ani,
    previous_beneficiaries_to_keep_enrollment_ids=None,
    external_employee_id=None,
)

Bases: Instruction

Move a covered employee to another company that is not necessarily part of the same group and cover member in the new company. This means it's not considered as a transfer, employee won't receive the dedicated emails nor keep their setup (options, direct billing...)

⚠️ if previous_beneficiaries_to_keep_enrollment_ids is None, a missing_conditional_parameter error will be raised (this is part of the conflict solving mechanism for Marmot)

destination_ccn_code instance-attribute

destination_ccn_code

destination_company_id instance-attribute

destination_company_id

destination_professional_category instance-attribute

destination_professional_category

employment_id instance-attribute

employment_id

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

keep_admin instance-attribute

keep_admin

keep_ani instance-attribute

keep_ani

move_date instance-attribute

move_date

previous_beneficiaries_to_keep_enrollment_ids class-attribute instance-attribute

previous_beneficiaries_to_keep_enrollment_ids = None

MoveExemptedEmployeeToAnotherCompany dataclass

MoveExemptedEmployeeToAnotherCompany(
    employment_id,
    destination_company_id,
    move_date,
    invite_email,
    destination_ccn_code,
    destination_professional_category,
    exemption_type,
    keep_admin,
    external_employee_id=None,
)

Bases: Instruction

Move an exempted employee to another company that is not necessarily part of the same group and exempt member in the new company. This means it's not considered as a transfer, employee won't receive the dedicated emails

destination_ccn_code instance-attribute

destination_ccn_code

destination_company_id instance-attribute

destination_company_id

destination_professional_category instance-attribute

destination_professional_category

employment_id instance-attribute

employment_id

exemption_type instance-attribute

exemption_type

external_employee_id class-attribute instance-attribute

external_employee_id = None

invite_email instance-attribute

invite_email

keep_admin instance-attribute

keep_admin

move_date instance-attribute

move_date

ProcessSignedSwornStatement dataclass

ProcessSignedSwornStatement(
    exemption_id, signed_sworn_statement_document_id
)

Bases: Instruction

Instruction to process a signed sworn statement for an exemption. This will start the exemption it if needed.

exemption_id instance-attribute

exemption_id

signed_sworn_statement_document_id instance-attribute

signed_sworn_statement_document_id

RemoveBeneficiary dataclass

RemoveBeneficiary(
    enrollment_id,
    end_date,
    beneficiary_termination_reason=None,
    beneficiary_termination_proof_link=None,
    allow_mandatorily_covered_removal_without_proof=False,
)

Bases: Instruction

allow_mandatorily_covered_removal_without_proof class-attribute instance-attribute

allow_mandatorily_covered_removal_without_proof = False
beneficiary_termination_proof_link = None

beneficiary_termination_reason class-attribute instance-attribute

beneficiary_termination_reason = None

end_date instance-attribute

end_date

enrollment_id instance-attribute

enrollment_id

RemoveEmployee dataclass

RemoveEmployee(
    employment_id,
    end_date,
    termination_type,
    cancel_affiliations_after_end_date=False,
)

Bases: Instruction

Terminate an employee with automated computation of ANI if relevant. end_date: termination date seen by the company

If there have been covered cares after end date, the coverage and the employment are extended until this last care. ANI computation is still based on the real end date.

If there is a new affiliation for the same (user, company) starting on end_date + 1d, by default, we will NOT terminate the employment because we merge continuous employments. To bypass this default, set cancel_affiliations_after_end_date to True, this will cancel the new affiliation and terminate the employment.

cancel_affiliations_after_end_date class-attribute instance-attribute

cancel_affiliations_after_end_date = False

employment_id instance-attribute

employment_id

end_date instance-attribute

end_date

termination_type instance-attribute

termination_type

RemoveEmployeeWithoutLastCareCheck dataclass

RemoveEmployeeWithoutLastCareCheck(
    employment_id,
    end_date,
    termination_type,
    reference_end_date_for_ani_end_computation=None,
    bypass_ani_computation_and_force_end_date=False,
    forced_max_ani_end_on=None,
)

Bases: Instruction

Terminate an employee with automated computation of ANI if relevant. end_date: termination date seen by the company reference_end_date_for_ani_end_computation: actual day the employee left the company

reference_end_date_for_ani_end_computation can be specified when we want - to start ANI later than the actual departure of the employee (this is the case when admin terminates the employee too late and the employee had reimbursed cares after they left the company) - but still end ANI based on the real departure date

In this case - end_date should be the last day before ANI starts - reference_end_date_for_ani_end_computation should be the actual day the employee left the company

note: if there's no ANI, reference_end_date_for_ani_end_computation is ignored

bypass_ani_computation_and_force_end_date class-attribute instance-attribute

bypass_ani_computation_and_force_end_date = False

employment_id instance-attribute

employment_id

end_date instance-attribute

end_date

forced_max_ani_end_on class-attribute instance-attribute

forced_max_ani_end_on = None

reference_end_date_for_ani_end_computation class-attribute instance-attribute

reference_end_date_for_ani_end_computation = None

termination_type instance-attribute

termination_type

RestartExemptionProcess dataclass

RestartExemptionProcess(exemption_id, new_start_date=None)

Bases: Instruction

The goal is to allow member going again through the exemption onboarding. This is typically used when the exemption has been signed with a wrong start date or type. It can only be used on exemptions that already have a start date.

It cancels the current exemption and re-create one with new_start_date (or the current start_date if not specified) and an empty type

Make employment fit the exemption period if needed

exemption_id instance-attribute

exemption_id

new_start_date class-attribute instance-attribute

new_start_date = None

ResumeBeneficiary dataclass

ResumeBeneficiary(enrollment_id)

Bases: Instruction

enrollment_id instance-attribute

enrollment_id

ResumeEmployee dataclass

ResumeEmployee(employment_id)

Bases: Instruction

employment_id instance-attribute

employment_id

ResumeEmployeeInUnpaidLeave dataclass

ResumeEmployeeInUnpaidLeave(employment_id, on_date)

Bases: Instruction

This instruction is used to resume an ended policy which is followed by an unpaid leave (that we will cancel)

employment_id instance-attribute

employment_id

on_date instance-attribute

on_date

ResumeIndividualHealthCoverage dataclass

ResumeIndividualHealthCoverage(policy_id)

Bases: Instruction

policy_id instance-attribute

policy_id

ReviewExemptionJustification dataclass

ReviewExemptionJustification(
    exemption_justification_id,
    status,
    exemption_justification_type,
    rejection_reason,
    rejection_reason_other_text,
    end_date,
    reviewer_id,
    reviewed_by_alan,
)

Bases: Instruction

Instruction to review an exemption justification.

end_date instance-attribute

end_date

exemption_justification_id instance-attribute

exemption_justification_id

exemption_justification_type instance-attribute

exemption_justification_type

rejection_reason instance-attribute

rejection_reason

rejection_reason_other_text instance-attribute

rejection_reason_other_text

reviewed_by_alan instance-attribute

reviewed_by_alan

reviewer_id instance-attribute

reviewer_id

status instance-attribute

status

ReviewExemptionJustificationForAdmin dataclass

ReviewExemptionJustificationForAdmin(
    exemption_justification_id,
    status,
    reviewer_id,
    reviewed_by_alan,
    rejection_reason=None,
)

Bases: Instruction

Instruction to review an exemption justification when executed by an admin from the dashboard.

It has fewer parameters than ReviewExemptionJustification because only the status can be changed from the dashboard

exemption_justification_id instance-attribute

exemption_justification_id

rejection_reason class-attribute instance-attribute

rejection_reason = None

reviewed_by_alan instance-attribute

reviewed_by_alan

reviewer_id instance-attribute

reviewer_id

status instance-attribute

status

ScheduleSoftOnboarding dataclass

ScheduleSoftOnboarding(employment_id, ssn=None, ntt=None)

Bases: Instruction

employment_id instance-attribute

employment_id

ntt class-attribute instance-attribute

ntt = None

ssn class-attribute instance-attribute

ssn = None

ScheduleSoftOnboardingWithExemptionInvalidation dataclass

ScheduleSoftOnboardingWithExemptionInvalidation(
    employment_id, ssn=None, ntt=None, rejection_reason=None
)

Bases: Instruction

employment_id instance-attribute

employment_id

ntt class-attribute instance-attribute

ntt = None

rejection_reason class-attribute instance-attribute

rejection_reason = None

ssn class-attribute instance-attribute

ssn = None

SetExemptionJustificationReviewEscalationLevel dataclass

SetExemptionJustificationReviewEscalationLevel(
    exemption_justification_id,
    escalation_level,
    escalation_operator_id,
    escalation_comment=None,
)

Bases: Instruction

Instruction to set the escalation level for an exemption review. This is used to escalate the review of an exemption justification to a higher level.

escalation_comment class-attribute instance-attribute

escalation_comment = None

escalation_level instance-attribute

escalation_level

escalation_operator_id instance-attribute

escalation_operator_id

exemption_justification_id instance-attribute

exemption_justification_id

SetViewedTermsAtForEmployee dataclass

SetViewedTermsAtForEmployee(employment_id, viewed_terms_at)

Bases: Instruction

employment_id instance-attribute

employment_id

viewed_terms_at instance-attribute

viewed_terms_at

SoftOnboardEmployee dataclass

SoftOnboardEmployee(employment_id, ssn=None, ntt=None)

Bases: Instruction

employment_id instance-attribute

employment_id

ntt class-attribute instance-attribute

ntt = None

ssn class-attribute instance-attribute

ssn = None

SoftOnboardExemptedEmployee dataclass

SoftOnboardExemptedEmployee(
    employment_id, ssn=None, ntt=None, rejection_reason=None
)

Bases: Instruction

employment_id instance-attribute

employment_id

ntt class-attribute instance-attribute

ntt = None

rejection_reason class-attribute instance-attribute

rejection_reason = None

ssn class-attribute instance-attribute

ssn = None

StartExemption dataclass

StartExemption(exemption_id)

Bases: Instruction

Start and exemption and terminate or cancel the related policies

exemption_id instance-attribute

exemption_id

T module-attribute

T = TypeVar('T', bound=Instruction, contravariant=True)

TerminateAllHealthAffiliationsFromCompany dataclass

TerminateAllHealthAffiliationsFromCompany(
    company_id, end_date, before_contract_termination=False
)

Bases: Instruction

Terminate all health affiliations from a company.

This should be called when a company churns their Health Insurance contract, and we want to make sure we terminate all Policies/Enrollments/Exemptions for that company.

When the parameter before_contract_termination is set to true

affiliations will be terminated even if there is a running contract

before_contract_termination class-attribute instance-attribute

before_contract_termination = False

company_id instance-attribute

company_id

end_date instance-attribute

end_date

TerminateIndividualHealthCoverage dataclass

TerminateIndividualHealthCoverage(
    policy_id,
    end_date,
    contract_termination_type,
    contract_termination_details,
    bypass_mandatory_termination_type_validation=False,
    beneficiary_termination_reason=None,
)

Bases: Instruction

beneficiary_termination_reason class-attribute instance-attribute

beneficiary_termination_reason = None

Termination type is mandatory for contracts that are less than one year old. But we do not ask for it from Marmot, so we accept to bypass the rule in that case.

The beneficiary_termination_reason is used to set the correct termination reason for all enrollments in the policy, enabling smart detection for dependent transfers.

bypass_mandatory_termination_type_validation class-attribute instance-attribute

bypass_mandatory_termination_type_validation = False

contract_termination_details instance-attribute

contract_termination_details

contract_termination_type instance-attribute

contract_termination_type

end_date instance-attribute

end_date

policy_id instance-attribute

policy_id

TransferEmployee dataclass

TransferEmployee(
    employment_id,
    destination_company_id,
    transfer_date,
    external_employee_id=None,
    destination_ccn_code=None,
    destination_professional_category=None,
    end_date=None,
    termination_type=None,
    keep_existing_termination=False,
)

Bases: Instruction

Special cases: when transferring an employee that is already ended in the previous company - if the end date is in the past, we don't allow the transfer - if the end date is in the future - if the transfer date is before the end date -> we update the end date (shorten the first employment) - if the transfer date is after the end date -> we don't update the initial employment (there'll be a "hole" between the 2 employments)

NB: by default, the end date and ANI period (current or future) of the employment will not be kept. See the keep_existing_termination parameter for more information.

destination_ccn_code class-attribute instance-attribute

destination_ccn_code = None

destination_company_id instance-attribute

destination_company_id

destination_professional_category class-attribute instance-attribute

destination_professional_category = None

employment_id instance-attribute

employment_id

end_date class-attribute instance-attribute

end_date = None

This is the end date of the employee in the NEW company. See https://github.com/alan-eu/alan-apps/pull/16159 ⧉ for more details

This should only be used in case you want to transfer and terminate in the new company in a single instruction. If you want to keep the termination information (end date + ANI period) of an employee when transferring them, use keep_existing_termination instead.

Mutually exclusive with keep_existing_information.

external_employee_id class-attribute instance-attribute

external_employee_id = None

keep_existing_termination class-attribute instance-attribute

keep_existing_termination = False

If set to True: - Employees currently in ANI will be transferred and keep their ANI status in the destination company. - Employees who have an end date in the original company will keep the end date in the destination company, along with the future ANI period (if any).

If set to False (default value): - Employees currently in ANI will be transferred and invited in the new company as a regular employee - The end date and future ANI period of employees in the original company will not be kept in the destination company.

Mutually exclusive with end_date/termination_type.

termination_type class-attribute instance-attribute

termination_type = None

To be used along with end_date: specifies the termination type of the employee in the new company.

Mutually exclusive with keep_existing_information.

transfer_date instance-attribute

transfer_date

UncancelEmployee dataclass

UncancelEmployee(
    employment_id,
    with_exemption_id=None,
    with_policy_id=None,
)

Bases: Instruction

Uncancel employment with the given affiliation.

For now, this instruction will only work for simple cases: one affiliation fully matching the employment. This is because complex situations are hard to handle and can lead to inconsistencies.

Exactly one of with_exemption_id and with_policy_id must be provided and it must exactly match the employment's dates.

To prevent leading to not compliant states, the exemption to uncancel must be signed.

employment_id instance-attribute

employment_id

with_exemption_id class-attribute instance-attribute

with_exemption_id = None

with_policy_id class-attribute instance-attribute

with_policy_id = None

UpdateEmployeeStartDate dataclass

UpdateEmployeeStartDate(
    employment_id,
    new_start_date,
    restart_exemption_process=False,
)

Bases: Instruction

Update the start date of the employment and related health coverage/exemption affiliations

:param: restart_exemption_process: if True, the exemption process will be restarted This means the exemption will no longer be valid and a new sworn statement will have to be signed

⚠️ A few points to note: - DO NOT USE for - invited in ANI (will raise, because it has not been tested yet) - invited in unpaid leave (will raise an error ; it should be easy to implement but in theory, it doesn't make sense to update the start date in this case as it's supposed to match the company contract start date, so until we have a use case, we won't implement it) - It does the update regardless of covered cares during the period - It doesn't adapt ANI end even if in theory the new start date would have an impact on ANI computation

employment_id instance-attribute

employment_id

new_start_date instance-attribute

new_start_date

restart_exemption_process class-attribute instance-attribute

restart_exemption_process = False

UpdateEmployeeTerminationType dataclass

UpdateEmployeeTerminationType(
    employment_id, termination_type
)

Bases: Instruction

Update the termination type of an employee. It can update the termination dates if it changes the employee's ANI status.

employment_id instance-attribute

employment_id

termination_type instance-attribute

termination_type

UpdateExemptionEndDate dataclass

UpdateExemptionEndDate(
    exemption_id,
    end_date,
    termination_type=None,
    make_employment_fit=True,
)

Bases: Instruction

Changes an exemption end date, if no conflict with other affiliation Doesn't change other affiliation

By default, after the end date update is done, the instruction will make_employment_fit_affiliations, this can be avoided by using the make_employment_fit parameter

end_date instance-attribute

end_date

exemption_id instance-attribute

exemption_id

make_employment_fit class-attribute instance-attribute

make_employment_fit = True

termination_type class-attribute instance-attribute

termination_type = None

UpdateExemptionStartDate dataclass

UpdateExemptionStartDate(
    exemption_id, start_date, make_employment_fit=True
)

Bases: Instruction

Changes an exemption start date, if no conflict with other affiliation Doesn't change other affiliation By default, after the end date update is done, the instruction will make_employment_fit_affiliations, this can be avoided by using the make_employment_fit parameter

exemption_id instance-attribute

exemption_id

make_employment_fit class-attribute instance-attribute

make_employment_fit = True

start_date instance-attribute

start_date

UpdateExemptionValidityDate dataclass

UpdateExemptionValidityDate(
    exemption_id, new_validity_end_date
)

Bases: Instruction

Update the validity date of the exemption. The exemption model has 2 validity dates: cdd_end_date & health_coverage_end_date They are mutually exclusive, and depend on the exemption type.

exemption_id instance-attribute

exemption_id

new_validity_end_date instance-attribute

new_validity_end_date

UpdateHealthCoverageAffiliationEndDate dataclass

UpdateHealthCoverageAffiliationEndDate(
    policy_id,
    end_date,
    termination_type,
    keep_admin,
    ani_start_on=None,
    max_ani_end_on=None,
    reference_end_date_for_ani_end_computation=None,
    make_employment_fit=True,
)

Bases: Instruction

Changes a health coverage affiliation end date, if no conflict with other affiliation Doesn't change other affiliation Update employment end date if needed

Some details on parameters: - basic usage is to use end_date and not ani_start_on/ max_ani_end_on - ani_start_on/ max_ani_end_on can be used to force ANI dates - end_date cannot be used with ani_start_on, unless you also specify max_ani_end_on to force the 3 dates. - if max_ani_end_on is used with end_date, it is ignored, unless you also specify ani_start_on to force the 3 dates. - reference_end_date_for_ani_end_computation is the actual day the employee left the company - by default, after the end date update is done, the instruction will make_employment_fit_affiliations, this can be avoided by using the make_employment_fit parameter

ani_start_on class-attribute instance-attribute

ani_start_on = None

end_date instance-attribute

end_date

keep_admin instance-attribute

keep_admin

make_employment_fit class-attribute instance-attribute

make_employment_fit = True

max_ani_end_on class-attribute instance-attribute

max_ani_end_on = None

policy_id instance-attribute

policy_id

reference_end_date_for_ani_end_computation class-attribute instance-attribute

reference_end_date_for_ani_end_computation = None

termination_type instance-attribute

termination_type

UpdateHealthCoverageAffiliationStartDate dataclass

UpdateHealthCoverageAffiliationStartDate(
    policy_id, start_date
)

Bases: Instruction

Changes a health coverage affiliation start date, if no conflict with other affiliation Doesn't change other affiliation ⚠️ DO NOT USE unless you specifically want to update ONLY the policy, not the related employment - it'll be up to the caller to make sure the consistency between the employment and its affiliations If you're looking for updating a covered employee's start date, use UpdateEmployeeStartDate

policy_id instance-attribute

policy_id

start_date instance-attribute

start_date

UpdatePendingExemption dataclass

UpdatePendingExemption(
    exemption_id,
    exemption_type=None,
    health_coverage_insurer_name=None,
    health_coverage_end_date=None,
    cdd_end_date=None,
)

Bases: Instruction

Update a pending exemption for a specific exemption The one or more proprieties of the exemption will be updated. The status will remain pending and the exemption will still need to be started later on after the member has completed their onboarding

Only one parameter is mandatory: - exemption_id: the id of the pending exemption to update "But at least one other parameter should be provided"

cdd_end_date class-attribute instance-attribute

cdd_end_date = None

exemption_id instance-attribute

exemption_id

exemption_type class-attribute instance-attribute

exemption_type = None

health_coverage_end_date class-attribute instance-attribute

health_coverage_end_date = None

health_coverage_insurer_name class-attribute instance-attribute

health_coverage_insurer_name = None

UpdateUnpaidLeaveEndDate dataclass

UpdateUnpaidLeaveEndDate(unpaid_leave_id, end_date)

Bases: Instruction

Changes an unpaid leave end date It also updates the following health affiliation start date

end_date instance-attribute

end_date

unpaid_leave_id instance-attribute

unpaid_leave_id

UpdateUnpaidLeaveStartDate dataclass

UpdateUnpaidLeaveStartDate(unpaid_leave_id, start_date)

Bases: Instruction

Changes an unpaid leave start date It also updates the preceding health affiliation end date and employment start if needed

start_date instance-attribute

start_date

unpaid_leave_id instance-attribute

unpaid_leave_id

UploadExemptionJustificationFile dataclass

UploadExemptionJustificationFile(
    exemption_id,
    file,
    filename,
    reviewed_by_alan=None,
    status=None,
    end_date=None,
)

Bases: Instruction

Instruction to upload an exemption justification file. This will be used to create an exemption justification document.

end_date class-attribute instance-attribute

end_date = None

exemption_id instance-attribute

exemption_id

file class-attribute instance-attribute

file = field(metadata=config(encoder=lambda x: repr(x)))

filename instance-attribute

filename

reviewed_by_alan class-attribute instance-attribute

reviewed_by_alan = None

status class-attribute instance-attribute

status = None

UploadSignedSwornStatementFile dataclass

UploadSignedSwornStatementFile(
    exemption_id,
    file,
    filename,
    signed_date,
    exemption_type=None,
)

Bases: Instruction

Instruction to upload a signed sworn statement file for an exemption. This will be used to create a sworn statement document, process the signed sworn statement file and start the exemption if needed.

exemption_id instance-attribute

exemption_id

exemption_type class-attribute instance-attribute

exemption_type = None

file class-attribute instance-attribute

file = field(metadata=config(encoder=lambda x: repr(x)))

filename instance-attribute

filename

signed_date instance-attribute

signed_date

components.fr_health_insurance_affiliation.public.side_effect_recorder

SideEffectRecordArgs module-attribute

SideEffectRecordArgs = tuple[tuple, dict]

SideEffectRecorder

force_commit_to_record_side_effect classmethod

force_commit_to_record_side_effect(function)

Intercept commit param of event handlers and set it to True if SideEffectRecorder is activated

WARNING: this should be used only for event handlers calling external functions decorated with SideEffectRecorder.record(execute_function_in_new_stack_dry_run=False) otherwise, the external function changes will be committed even in dry run mode

Source code in components/fr_health_insurance_affiliation/public/side_effect_recorder.py
@classmethod
def force_commit_to_record_side_effect(cls, function: Callable) -> Callable:
    """
    Intercept commit param of event handlers and set it to True if SideEffectRecorder is activated

    WARNING: this should be used only for event handlers calling external functions decorated with
    `SideEffectRecorder.record(execute_function_in_new_stack_dry_run=False)`
    otherwise, the external function changes will be committed even in dry run mode
    """

    @wraps(function)
    def wrapper(*args, **kwargs):
        if "commit" in kwargs and cls._new_stack_dry_run_activated:
            kwargs["commit"] = True
        return function(*args, **kwargs)

    return wrapper

record classmethod

record(
    execute_function_in_new_stack_dry_run,
    ignore_for_instructions=None,
)
Source code in components/fr_health_insurance_affiliation/public/side_effect_recorder.py
@classmethod
def record(  # noqa: D102
    cls,
    execute_function_in_new_stack_dry_run: bool,
    ignore_for_instructions: list[type] | None = None,
) -> Callable:
    def decorator(function: Callable) -> Callable:
        @wraps(function)
        def wrapper(*args, **kwargs) -> None:
            is_dry_running_new_stack = cls._new_stack_dry_run_activated
            if is_dry_running_new_stack and (
                ignore_for_instructions is None
                or cls._instruction_type not in ignore_for_instructions
            ):
                cls._user_lifecycle_side_effects.append(
                    (function.__name__, args, kwargs)
                )

            if cls._current_stack_record_side_effects_activated and (
                ignore_for_instructions is None
                or cls._instruction_type not in ignore_for_instructions
            ):
                cls._current_stack_side_effects.append(
                    (function.__name__, args, kwargs)
                )

            if (
                execute_function_in_new_stack_dry_run
                or not is_dry_running_new_stack
            ):
                return function(*args, **kwargs)
            return None

        return wrapper

    return decorator