EMS

Ex officio withdrawal (baixa d’ofici)

Issue #726. A student who stops coming to the centre loses their place after a term set by the regulation (Resolució EDF/293/2026, point 8.6) and the centre’s communication plan (Pla de comunicació, table “Baixes d’alumnat”). EMS keeps one case file per student that walks every step of that protocol, with who did it and when.

Implemented in phases (see the issue). This page describes what exists now.

Circuits

Every level says which educational stage it belongs to, as the regulation sets it: ems.level.education_stage (compulsory / post_compulsory), part of EMS’s catalog (data/cat/ems.level.csv, re-applied on every upgrade) and read-only on the level’s form. EMS decides with it what applies to the level’s students; for this protocol, the case file picks its circuit from the stage of the level the student is enrolled in (CIRCUIT_BY_STAGE, _ems_circuit_for_level(), the student’s main group: its study’s level, or the group’s own), and keeps it (circuit) for the rest of the procedure.

Level Educational stage, circuit
CFGB, ESO Compulsory
CFGM, CFGS, EFPS, PFI, BTX Post-compulsory

A level with no stage gets no case files.

Steps and deadlines

The steps are a catalog in code (STEP_CATALOG, models/contacts/ex_officio_withdrawal.py), one tuple per circuit, created when the procedure starts. Every deadline counts from the first day of absence (D0) and is computed in one place, ems.ex_officio_withdrawal._ems_due_date():

Example: D0 = Tuesday 15 December 2026 with the Christmas break from 21 December to 7 January: the 15th school day is 22 January 2027.

The protocol’s waits are always kept. Those are the protocol’s days (planned_date). A step accepted later than its day moves the pending ones (_ems_shift_pending_steps(), called by Accept and continue): each pending step is due (due_date) on the later of its protocol day and the previous step’s day plus the protocol’s wait between them (_ems_after_wait()), counted from the day the step is accepted in EMS (never from a tick box’s day, which can be backdated). The wait is the difference of their school days in a school-day circuit, the calendar days between their protocol days otherwise; two steps on the same protocol day (Social Services and the notice to the family; the withdrawal and Direction’s green light) have no wait between them. So a tutor who contacts the family a month late does not let the Secretariat warn it the same day, nor Direction approve the withdrawal: each still gets its own wait.

Example (post-compulsory, D0 17 December 2041, break 23 December to 7 January): the tutor’s step, due 8 January, accepted on Monday 20 January moves the Secretariat to 27 January (5 school days) and Direction and the withdrawal to 3 February (5 more).

Post-compulsory

Step Responsible Day Confirms
Contact with the family Tutor 5 school days Phone call, email to the family
Ex officio withdrawal warning Secretariat 10 school days Email to the family, eNotum
Green light from Direction Direction 15 school days Green light
Withdrawal Secretariat 15 school days Esfera, SAGA, eNotum, email to the family

Compulsory

Step Responsible Day Confirms
Contact with the family Tutor 7 days Phone call (how it went)
Contact by Coexistence COCOBE / management team 15 days Phone call (how it went)
Notice to the family Secretariat 1 month Email to the family
Notice to Social Services COCOBE / management team 1 month Email to Social Services
Ex officio withdrawal warning Secretariat 1.5 months Email to the family, eNotum
Direction approval Direction 2 months Green light, email to the Inspection
Withdrawal Secretariat 2 months Esfera

A phone call wherever the protocol asks to contact the family (it is mandatory, as Direction decided); an email to the family wherever it asks to write to them. The emails are sent by hand for now: phase 3 sends them from templates.

Case file

stateDiagram-v2
    [*] --> proposal: tutor opens it (manual)
    proposal --> in_progress: Start the procedure (steps created)
    proposal --> cancelled: Dismiss (reason)
    in_progress --> direction: Accept and continue (current step is Direction's)
    direction --> secretariat: Direction accepts (green light; expected withdrawal)
    direction --> cancelled: Close without a withdrawal (came back / justified)
    secretariat --> done: Process the withdrawal (withdrawal wizard, ex officio)
    in_progress --> cancelled: the student leaves otherwise (voluntary / expelled)
    direction --> cancelled
    secretariat --> cancelled

The state follows the current step (the first one not done, current_step_id): direction while it is Direction’s green light, secretariat while it is the withdrawal, in_progress otherwise (STATE_BY_STEP, _ems_move_on()).

Advancing and tasks

Responsible Task goes to
Tutor The student’s tutor
Coexistence The Coexistence coordinator (ems.role_coexistence) under the tutor’s Head or Deputy Head of Studies (hr.employee._ems_coexistence_coordinators(), shared with strikes); every coordinator when none is
Secretariat The whole secretariat, the administrators left out (ems.base.secretariat_task_users(), shared with convalidations)
Direction The Director (ems.role_director, ems.base.role_task_users())

Detection in the roll-calls (phase 5)

The hourly cron _cron_ems_detect() opens a proposal (origin = 'detected') for every student who has missed DETECTION_DAYS (5) whole school days in a row; the first of them is the first day of absence, and the proposal’s task goes to the tutor, like a case file opened by hand. The chatter logs how many days and which. It only counts up to yesterday, so a day whose roll-calls are still being taken never counts, and it is idempotent (students with an open case file are skipped): the first run after midnight opens the proposals, the others find nothing new.

_ems_absence_runs(since, until) does the counting, over the roll-call lines of the last DETECTION_WINDOW_DAYS (70, more than the compulsory circuit’s two months), in one query grouped by student and day:

A day where the student’s active lines are… Effect on the run
every one an unjustified miss counts
any attended, minor delay, issue or severe delay breaks it: counting starts again after it
any justified miss (all or some), and none attended skipped: neither counts nor breaks
none (no roll-call taken) skipped

Only the days after the student’s last closed case file (closed_date) count, so a dismissed proposal or a cancelled case file needs a new run of 5 days. Left out: students whose level has no circuit (_ems_circuit_student_domain(), also the new-file student picker’s), with an open case file, an expected withdrawal or an exit.

Measured on the dev database (~62k lines, 556 students, 2026-11-04): the query 56 ms cold, a first run opening 8 proposals 0.43 s, an hourly run finding nothing new 48 ms. The existing indexes are enough.

Roll-calls during the case file (phase 6)

A roll-call of the case file’s days (from the first day of absence on) that says otherwise becomes an ems.ex_officio_withdrawal.review (case file, roll-call line, kind, state), one per line and kind (line_kind_unique). _ems_collect_reviews() finds them in one search over the lines of every open case file, only from sessions already over (a line is attended by default until its teacher takes the roll-call). It runs hourly with the detection, when a case file is created and when its first day of absence changes. A pending review whose line no longer says so (the teacher corrected the roll-call, or the first day of absence moved past it) is removed.

kind Line What happens The tutor’s buttons
attendance attended, minor delay, issue, severe delay Task Check an attendance to the tutor; the case file stops: Start, Accept and Process the withdrawal are refused (_ems_check_no_attendance_pending(), attendance_pending) They did come (action_came_back): cancelled came_back. It was a mistake (action_mark_absent): the line becomes a miss (sudo), with a note naming the case file and who corrected it
justification justified miss Task Review justified absences; nothing stops Close: the absences are justified (action_cancel_justified): cancelled justified. Go on (action_keep_justified): reviews kept

Applies to proposals too, so a case file opened by hand with attendances after its first day of absence can’t start until they are checked (or the first day moves past them). Who reviews: can_review = _ems_user_acts_as('tutor') (the tutor scope, the Head of Studies, the administrators), checked again on the server; everybody else sees a one-line notice while an attendance is pending. _ems_sync_review_tasks() keeps one task per kind while any is pending and removes it once none is. A correction to a miss goes through the line’s own write(), so the attendance notifications behave as when a teacher corrects the roll-call.

Measured on the dev database (11 open case files, 2026-11-04): 37 ms cold.

Emails, texts to copy and the case file PDF (phase 3)

Access

Role Sees Does
Tutor (and the chain above them: tutor_scope_user_ids) Their students’ case files Opens one for their students, starts or dismisses it, their steps, reviews the roll-calls
Coexistence (COCOBE), Guidance All Read; the Coexistence coordinator does its steps
Head of Studies / Deputy, Director All Open one only within their own chain (tutor scope); start, dismiss, review the roll-calls and do the tutor’s and Coexistence’s steps of any case file; the Director, Direction’s
Secretariat All Its steps; processes the withdrawal
Academic administrator, Settings administrator (base.group_system) All Everything, deletion included; processing the withdrawal needs the withdrawal wizard (academic administrator)
Other teachers None -

Record rules: security/rules/ex_officio_withdrawal.xml (tutor scope for ems.group_tutor, read and write, not create, for ems.group_student_data_reader and ems.group_secretary, and everything for ems.group_academic_admin and base.group_system). Who may open one: _ems_user_may_open_for() (the request button, the new-file picker); who may start or dismiss a proposal or review its roll-calls: can_decide_proposal, can_review (non-stored, depends_context('uid'), _ems_user_acts_as('tutor')), checked again on the server. The administrators: _ems_user_is_admin(). Audited 2026-11-04 with one user per role of tests/common.py against every button the case file offers: 0 mismatches.

Screens