All checks were successful
## What & why First sub-slice of **S-11 · Withdrawal (Flow 3)** (#12). A zorgprofessional can withdraw a still-open registration ("trek aanvraag in"); this sub-slice delivers the **domain transition + endpoint**, mirroring how S-12a shipped the beoordeling decision model on its own (#82). - `RegistrationStatus.Ingetrokken` (terminal). - `Registration.Withdraw()` — allowed from INGEDIEND or IN_BEHANDELING, needs no zaak, idempotent, and rejected once the registration has been decided (INGESCHREVEN/AFGEWEZEN). - `WithdrawRegistration` application handler (load → withdraw → persist; repeated withdrawal is a no-op). - `POST /registrations/{id}/withdraw` on the domain API. Demoable: `POST /registrations/{id}/withdraw` → `GET /registrations/{id}` shows `INGETROKKEN`. Refs #12 (not closing — see below). ## Scope / follow-ups S-11 is bigger than one slice, so it is split (CLAUDE.md §13), like S-12 was: - **S-11a (this PR)** — domain withdrawal transition + endpoint. - **S-11b** — cancel the running Flowable process via a BPMN message event, so a withdrawn case leaves the behandelaar's werkbak. - **S-11c** — owner-scoped BFF self-service withdraw endpoint + "trek aanvraag in" button + e2e. Cancelling the Flowable process is deliberately deferred (documented in `WithdrawRegistration`), exactly as the beoordeling's rejection deferred its zaak propagation. #12 stays open until S-11c. ## Definition of Done - [x] Linked Gitea issue (#12). - [x] Failing test committed before the implementation. - [x] Implementation makes the test pass. - [x] Conventional Commits referencing the issue (`refs #12`). - [ ] CI green — all Gitea Actions jobs. - [x] `docker compose up` unaffected (no infra/contract change). - [x] Docs — none needed for this backend sub-slice; the user-visible demo note lands with S-11c. - [x] No ADR needed — mirrors existing aggregate/handler/endpoint patterns; no boundary change. ## Notes for reviewers - Verified locally: `Big.Tests` 89/89 pass; `Big.Api` builds clean. - The domain trusts its callers (§8.3); owner-scoping by the caller's bsn is enforced at the BFF in S-11c. Reviewed-on: #88
138 lines
5.9 KiB
C#
138 lines
5.9 KiB
C#
namespace Big.Domain;
|
|
|
|
/// <summary>
|
|
/// The Registration aggregate root (CLAUDE.md §2.2): a zorgprofessional's submission to the BIG
|
|
/// register. It owns its lifecycle invariants — it starts <see cref="RegistrationStatus.Ingediend"/>
|
|
/// on submission, remembers the Flowable process that drives it, and records the zaak the ACL opens.
|
|
/// </summary>
|
|
public sealed class Registration
|
|
{
|
|
private Registration(RegistrationId id, string bsn)
|
|
{
|
|
Id = id;
|
|
Bsn = bsn;
|
|
Status = RegistrationStatus.Ingediend;
|
|
}
|
|
|
|
public RegistrationId Id { get; }
|
|
|
|
/// <summary>The citizen-service number of the submitting zorgprofessional. Handed to the ACL
|
|
/// as the domain payload; the domain never constructs ZGW concepts from it (§8.1).</summary>
|
|
public string Bsn { get; }
|
|
|
|
public RegistrationStatus Status { get; private set; }
|
|
|
|
/// <summary>The Flowable process instance driving this registration, once started.</summary>
|
|
public string? ProcessInstanceId { get; private set; }
|
|
|
|
/// <summary>The zaak the ACL opened for this registration, once the external task has run.</summary>
|
|
public Uri? ZaakUrl { get; private set; }
|
|
|
|
/// <summary>Submit a new registration. It begins in <see cref="RegistrationStatus.Ingediend"/>.</summary>
|
|
public static Registration Submit(string bsn)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(bsn);
|
|
return new Registration(RegistrationId.New(), bsn);
|
|
}
|
|
|
|
/// <summary>Record that the registratie workflow process has been started for this registration.</summary>
|
|
public void RecordProcessStarted(string processInstanceId)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(processInstanceId);
|
|
ProcessInstanceId = processInstanceId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attach the zaak the ACL opened. The external-task worker may deliver the same job more than
|
|
/// once (at-least-once), so re-attaching the identical URL is a no-op; a different URL signals a
|
|
/// genuine conflict and is rejected. The status stays <see cref="RegistrationStatus.Ingediend"/>:
|
|
/// opening the zaak does not advance the registration's lifecycle in this slice.
|
|
/// </summary>
|
|
public void AttachZaak(Uri zaakUrl)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(zaakUrl);
|
|
|
|
if (ZaakUrl is not null)
|
|
{
|
|
if (ZaakUrl != zaakUrl)
|
|
throw new InvalidOperationException(
|
|
$"Registration {Id} already has zaak {ZaakUrl}; cannot attach a different zaak {zaakUrl}.");
|
|
// Stryker disable once Statement : equivalent — re-assigning the identical URL below is a
|
|
// no-op, so removing this early return is behaviourally indistinguishable.
|
|
return;
|
|
}
|
|
|
|
ZaakUrl = zaakUrl;
|
|
}
|
|
|
|
/// <summary>
|
|
/// A behandelaar picks the registration up for beoordeling. Advances
|
|
/// <see cref="RegistrationStatus.Ingediend"/> → <see cref="RegistrationStatus.InBehandeling"/>.
|
|
/// Re-taking one already <see cref="RegistrationStatus.InBehandeling"/> is a no-op (the same or
|
|
/// another behandelaar re-opens it); a decided registration can no longer be taken into behandeling.
|
|
/// </summary>
|
|
public void TakeIntoBehandeling()
|
|
{
|
|
if (Status == RegistrationStatus.InBehandeling)
|
|
return;
|
|
|
|
if (Status != RegistrationStatus.Ingediend)
|
|
throw new InvalidOperationException(
|
|
$"Registration {Id} is {Status}; only an INGEDIEND registration can be taken into behandeling.");
|
|
|
|
Status = RegistrationStatus.InBehandeling;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Approve the registration — the behandelaar's decision to enter it in the register. Advances a
|
|
/// submitted or in-behandeling registration to <see cref="RegistrationStatus.Ingeschreven"/>.
|
|
/// Requires an opened zaak (the approval sets that zaak's status via the ACL); a registration that
|
|
/// has already been decided cannot be approved again.
|
|
/// </summary>
|
|
public void Approve()
|
|
{
|
|
if (ZaakUrl is null)
|
|
throw new InvalidOperationException(
|
|
$"Registration {Id} has no zaak yet; it cannot be approved before its zaak is opened.");
|
|
|
|
RequireOpenForDecision(nameof(Approve));
|
|
Status = RegistrationStatus.Ingeschreven;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reject the registration — the behandelaar's decision not to enter it in the register. Advances a
|
|
/// submitted or in-behandeling registration to <see cref="RegistrationStatus.Afgewezen"/>. Unlike
|
|
/// approval this needs no zaak: a registration can be rejected before or after its zaak is opened.
|
|
/// A registration that has already been decided cannot be rejected again.
|
|
/// </summary>
|
|
public void Reject()
|
|
{
|
|
RequireOpenForDecision(nameof(Reject));
|
|
Status = RegistrationStatus.Afgewezen;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Withdraw the registration — the zorgprofessional pulls their own submission back (S-11). Allowed
|
|
/// while it is still open (INGEDIEND or IN_BEHANDELING) and needs no zaak; a registration that has
|
|
/// already been decided (INGESCHREVEN/AFGEWEZEN) can no longer be withdrawn. Re-withdrawing one
|
|
/// already <see cref="RegistrationStatus.Ingetrokken"/> is a no-op.
|
|
/// </summary>
|
|
public void Withdraw()
|
|
{
|
|
if (Status == RegistrationStatus.Ingetrokken)
|
|
return;
|
|
|
|
RequireOpenForDecision(nameof(Withdraw));
|
|
Status = RegistrationStatus.Ingetrokken;
|
|
}
|
|
|
|
// A decision (or withdrawal) is only valid while the registration is still open (INGEDIEND or
|
|
// IN_BEHANDELING).
|
|
private void RequireOpenForDecision(string decision)
|
|
{
|
|
if (Status is not (RegistrationStatus.Ingediend or RegistrationStatus.InBehandeling))
|
|
throw new InvalidOperationException(
|
|
$"Registration {Id} is {Status}; only an INGEDIEND or IN_BEHANDELING registration can be decided ({decision}).");
|
|
}
|
|
}
|