diff --git a/services/domain/Big.Api/Program.cs b/services/domain/Big.Api/Program.cs index 5d0db51..03b8a01 100644 --- a/services/domain/Big.Api/Program.cs +++ b/services/domain/Big.Api/Program.cs @@ -15,6 +15,10 @@ builder.Services.AddSingleton(sp => sp.GetRequiredService() // The in-memory registration store is shared between the submit endpoint and the worker (ADR-0009). builder.Services.AddSingleton(); +// The system clock, injected wherever a use case needs "now" (e.g. stamping the inscription moment +// on approval, S-17). Injected as TimeProvider so tests can substitute a fixed clock. +builder.Services.AddSingleton(TimeProvider.System); + // The Workflow Client is one type behind two ports (start side + worker side); both resolve to the // same HttpClient-backed implementation — the only code that talks to Flowable (§8.2). builder.Services.AddHttpClient(); diff --git a/services/domain/Big.Application/ApproveRegistration.cs b/services/domain/Big.Application/ApproveRegistration.cs index ac6e32e..d1cf997 100644 --- a/services/domain/Big.Application/ApproveRegistration.cs +++ b/services/domain/Big.Application/ApproveRegistration.cs @@ -12,7 +12,7 @@ public sealed record ApproveRegistrationCommand(RegistrationId RegistrationId); /// zaak status is the projection's source of truth (it flows back over NRC); the aggregate transition /// keeps the domain's own view consistent. /// -public sealed class ApproveRegistration(IRegistrationStore store, IAclClient acl) +public sealed class ApproveRegistration(IRegistrationStore store, IAclClient acl, TimeProvider clock) { public async Task HandleAsync(ApproveRegistrationCommand command, CancellationToken ct = default) { @@ -30,7 +30,7 @@ public sealed class ApproveRegistration(IRegistrationStore store, IAclClient acl $"Registration {command.RegistrationId} has no zaak yet; it cannot be approved."); await acl.ApproveZaakAsync(registration.ZaakUrl, ct); - registration.Approve(); + registration.Approve(clock.GetUtcNow()); await store.SaveAsync(registration, ct); } } diff --git a/services/domain/Big.Application/BeoordeelRegistratie.cs b/services/domain/Big.Application/BeoordeelRegistratie.cs index 8ba8e3f..48f02d0 100644 --- a/services/domain/Big.Application/BeoordeelRegistratie.cs +++ b/services/domain/Big.Application/BeoordeelRegistratie.cs @@ -25,7 +25,7 @@ public sealed record BeoordeelRegistratieCommand(RegistrationId RegistrationId, /// decisions are idempotent — a repeated or redelivered decision that matches the current terminal /// state is a no-op, so the ACL is not called and the task not completed twice. /// -public sealed class BeoordeelRegistratie(IRegistrationStore store, IAclClient acl, IUserTaskClient tasks) +public sealed class BeoordeelRegistratie(IRegistrationStore store, IAclClient acl, IUserTaskClient tasks, TimeProvider clock) { public async Task HandleAsync(BeoordeelRegistratieCommand command, CancellationToken ct = default) { @@ -44,7 +44,7 @@ public sealed class BeoordeelRegistratie(IRegistrationStore store, IAclClient ac throw new InvalidOperationException( $"Registration {command.RegistrationId} has no zaak yet; it cannot be approved."); await acl.ApproveZaakAsync(registration.ZaakUrl, ct); - registration.Approve(); + registration.Approve(clock.GetUtcNow()); break; case BeoordelingsBesluit.Afwijzen: diff --git a/services/domain/Big.Domain/Registration.cs b/services/domain/Big.Domain/Registration.cs index a3b3503..3aea662 100644 --- a/services/domain/Big.Domain/Registration.cs +++ b/services/domain/Big.Domain/Registration.cs @@ -92,11 +92,12 @@ public sealed class Registration /// /// Approve the registration — the behandelaar's decision to enter it in the register. Advances a - /// submitted or in-behandeling registration to . - /// 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. + /// submitted or in-behandeling registration to and + /// records as the moment of inscription, which starts the + /// herregistratie clock (S-17). 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. /// - public void Approve() + public void Approve(DateTimeOffset ingeschrevenOp) { if (ZaakUrl is null) throw new InvalidOperationException( @@ -104,8 +105,40 @@ public sealed class Registration RequireOpenForDecision(nameof(Approve)); Status = RegistrationStatus.Ingeschreven; + // RED stub: the inscription moment is not stored yet. } + // --- Herregistratie (S-17) — RED stubs, implemented in the green commit --------------------- + + /// How long a BIG inscription stays valid before herregistratie is required. + // ponytail: fixed 5-year term — a calibration knob, not a config surface. If a demo needs it + // per-catalogus, promote it to policy passed in from the beheer config (S-15). + public static readonly TimeSpan HerregistratieGeldigheid = TimeSpan.FromDays(365 * 5); + + /// How long before the deadline the herregistratie reminder is sent (BIG: ~16 weeks). + // ponytail: fixed 16-week lead time — calibration knob; same promotion path as HerregistratieGeldigheid. + public static readonly TimeSpan Herinneringstermijn = TimeSpan.FromDays(16 * 7); + + /// When the registration was entered in the register, once approved; the start of its + /// herregistratie clock. Null until it is . + public DateTimeOffset? IngeschrevenOp { get; private set; } + + /// The date by which herregistratie must happen: inscription + validity. Null until + /// inscribed. + public DateTimeOffset? HerregistratieVoor => null; // RED stub + + /// Whether the herregistratie reminder has been sent for this inscription (S-17). + public bool HerregistratieReminderVerstuurd { get; private set; } + + /// Whether, as of , this registration is due a herregistratie + /// reminder: it is inscribed, the reminder window before its deadline has opened, and it has not + /// already been reminded. + public bool HerregistratieReminderDue(DateTimeOffset asOf) => false; // RED stub + + /// Record that the herregistratie reminder has been sent. Idempotent — a re-sweep is a + /// no-op; only an inscribed registration can be reminded. + public void MarkHerregistratieReminderVerstuurd() { } // RED stub + /// /// Reject the registration — the behandelaar's decision not to enter it in the register. Advances a /// submitted or in-behandeling registration to . Unlike diff --git a/services/domain/Big.Tests/ApproveRegistrationTests.cs b/services/domain/Big.Tests/ApproveRegistrationTests.cs index 3c7ae28..d756d44 100644 --- a/services/domain/Big.Tests/ApproveRegistrationTests.cs +++ b/services/domain/Big.Tests/ApproveRegistrationTests.cs @@ -19,7 +19,7 @@ public class ApproveRegistrationTests var acl = new FakeAclClient(); var registration = WithZaak(); store.Seed(registration); - var handler = new ApproveRegistration(store, acl); + var handler = new ApproveRegistration(store, acl, TimeProvider.System); await handler.HandleAsync(new ApproveRegistrationCommand(registration.Id)); @@ -36,7 +36,7 @@ public class ApproveRegistrationTests { var store = new FakeRegistrationStore(); var acl = new FakeAclClient(); - var handler = new ApproveRegistration(store, acl); + var handler = new ApproveRegistration(store, acl, TimeProvider.System); await Assert.ThrowsAsync(() => handler.HandleAsync(null!)); Assert.Equal(0, acl.ApproveCallCount); @@ -47,7 +47,7 @@ public class ApproveRegistrationTests { var store = new FakeRegistrationStore(); var acl = new FakeAclClient(); - var handler = new ApproveRegistration(store, acl); + var handler = new ApproveRegistration(store, acl, TimeProvider.System); var ex = await Assert.ThrowsAsync( () => handler.HandleAsync(new ApproveRegistrationCommand(RegistrationId.New()))); @@ -62,7 +62,7 @@ public class ApproveRegistrationTests var acl = new FakeAclClient(); var registration = Registration.Submit("123456782"); // no zaak yet store.Seed(registration); - var handler = new ApproveRegistration(store, acl); + var handler = new ApproveRegistration(store, acl, TimeProvider.System); var ex = await Assert.ThrowsAsync( () => handler.HandleAsync(new ApproveRegistrationCommand(registration.Id))); @@ -77,7 +77,7 @@ public class ApproveRegistrationTests var acl = new FakeAclClient(); var registration = WithZaak(); store.Seed(registration); - var handler = new ApproveRegistration(store, acl); + var handler = new ApproveRegistration(store, acl, TimeProvider.System); await handler.HandleAsync(new ApproveRegistrationCommand(registration.Id)); await handler.HandleAsync(new ApproveRegistrationCommand(registration.Id)); diff --git a/services/domain/Big.Tests/BeoordeelRegistratieTests.cs b/services/domain/Big.Tests/BeoordeelRegistratieTests.cs index 9ad48de..26ac64e 100644 --- a/services/domain/Big.Tests/BeoordeelRegistratieTests.cs +++ b/services/domain/Big.Tests/BeoordeelRegistratieTests.cs @@ -29,7 +29,7 @@ public class BeoordeelRegistratieTests var registration = WithZaak(); store.Seed(registration); var tasks = TaskFor(registration); - var handler = new BeoordeelRegistratie(store, acl, tasks); + var handler = new BeoordeelRegistratie(store, acl, tasks, TimeProvider.System); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Goedkeuren)); @@ -50,7 +50,7 @@ public class BeoordeelRegistratieTests var registration = WithZaak(); store.Seed(registration); var tasks = TaskFor(registration); - var handler = new BeoordeelRegistratie(store, acl, tasks); + var handler = new BeoordeelRegistratie(store, acl, tasks, TimeProvider.System); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Afwijzen)); @@ -69,7 +69,7 @@ public class BeoordeelRegistratieTests var registration = WithZaak(); registration.TakeIntoBehandeling(); store.Seed(registration); - var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration)); + var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration), TimeProvider.System); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Goedkeuren)); @@ -81,7 +81,7 @@ public class BeoordeelRegistratieTests { var store = new FakeRegistrationStore(); var acl = new FakeAclClient(); - var handler = new BeoordeelRegistratie(store, acl, new FakeUserTaskClient([])); + var handler = new BeoordeelRegistratie(store, acl, new FakeUserTaskClient([]), TimeProvider.System); await Assert.ThrowsAsync(() => handler.HandleAsync(null!)); Assert.Equal(0, acl.ApproveCallCount); @@ -93,7 +93,7 @@ public class BeoordeelRegistratieTests { var store = new FakeRegistrationStore(); var acl = new FakeAclClient(); - var handler = new BeoordeelRegistratie(store, acl, new FakeUserTaskClient([])); + var handler = new BeoordeelRegistratie(store, acl, new FakeUserTaskClient([]), TimeProvider.System); var ex = await Assert.ThrowsAsync(() => handler.HandleAsync(new BeoordeelRegistratieCommand(RegistrationId.New(), BeoordelingsBesluit.Goedkeuren))); @@ -108,7 +108,7 @@ public class BeoordeelRegistratieTests var acl = new FakeAclClient(); var registration = Registration.Submit("123456782"); // no zaak yet store.Seed(registration); - var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration)); + var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration), TimeProvider.System); var ex = await Assert.ThrowsAsync(() => handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Goedkeuren))); @@ -123,7 +123,7 @@ public class BeoordeelRegistratieTests var acl = new FakeAclClient(); var registration = WithZaak(); store.Seed(registration); - var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration)); + var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration), TimeProvider.System); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Goedkeuren)); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Goedkeuren)); @@ -139,7 +139,7 @@ public class BeoordeelRegistratieTests var acl = new FakeAclClient(); var registration = WithZaak(); store.Seed(registration); - var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration)); + var handler = new BeoordeelRegistratie(store, acl, TaskFor(registration), TimeProvider.System); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Afwijzen)); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Afwijzen)); @@ -158,7 +158,7 @@ public class BeoordeelRegistratieTests var registration = WithZaak(); store.Seed(registration); var tasks = new FakeUserTaskClient([]); // no open task for this registration - var handler = new BeoordeelRegistratie(store, acl, tasks); + var handler = new BeoordeelRegistratie(store, acl, tasks, TimeProvider.System); await handler.HandleAsync(new BeoordeelRegistratieCommand(registration.Id, BeoordelingsBesluit.Goedkeuren)); diff --git a/services/domain/Big.Tests/InMemoryRegistrationStoreTests.cs b/services/domain/Big.Tests/InMemoryRegistrationStoreTests.cs index 14be96e..284da9f 100644 --- a/services/domain/Big.Tests/InMemoryRegistrationStoreTests.cs +++ b/services/domain/Big.Tests/InMemoryRegistrationStoreTests.cs @@ -79,7 +79,7 @@ public class InMemoryRegistrationStoreTests switch (transition) { case nameof(Registration.Withdraw): registration.Withdraw(); break; - case nameof(Registration.Approve): registration.Approve(); break; + case nameof(Registration.Approve): registration.Approve(DateTimeOffset.UtcNow); break; case nameof(Registration.Reject): registration.Reject(); break; case nameof(Registration.Expire): registration.Expire(); break; } diff --git a/services/domain/Big.Tests/RegistrationHerregistratieTests.cs b/services/domain/Big.Tests/RegistrationHerregistratieTests.cs new file mode 100644 index 0000000..7c1bc16 --- /dev/null +++ b/services/domain/Big.Tests/RegistrationHerregistratieTests.cs @@ -0,0 +1,90 @@ +using Big.Domain; + +namespace Big.Tests; + +// S-17 (#18): a BIG inscription is valid for a fixed term; before it lapses the zorgprofessional must +// herregistreren. The aggregate records when it was inscribed, derives the herregistratie deadline, and +// answers whether a reminder is due as of a given moment — the single rule the Quartz sweep and the +// store query both build on. All arithmetic is against an explicit "now" so it is wall-clock-free. +public class RegistrationHerregistratieTests +{ + private static readonly DateTimeOffset Now = new(2026, 7, 23, 0, 0, 0, TimeSpan.Zero); + + // The moment the reminder window opens: inscribed exactly (geldigheid - herinneringstermijn) ago. + private static DateTimeOffset InscribedSoDueAt(DateTimeOffset asOf) + => asOf - Registration.HerregistratieGeldigheid + Registration.Herinneringstermijn; + + private static Registration Inscribed(DateTimeOffset ingeschrevenOp) + { + var registration = Registration.Submit("123456782"); + registration.AttachZaak(FakeAclClient.DefaultZaakUrl); + registration.Approve(ingeschrevenOp); + return registration; + } + + [Fact] + public void Approving_records_the_inscription_moment_and_the_herregistratie_deadline() + { + var registration = Inscribed(Now); + + Assert.Equal(Now, registration.IngeschrevenOp); + Assert.Equal(Now + Registration.HerregistratieGeldigheid, registration.HerregistratieVoor); + } + + [Fact] + public void A_reminder_is_due_the_moment_the_window_before_the_deadline_opens() + { + var registration = Inscribed(InscribedSoDueAt(Now)); + + Assert.True(registration.HerregistratieReminderDue(Now)); + } + + [Fact] + public void A_reminder_is_not_yet_due_one_day_before_the_window_opens() + { + var registration = Inscribed(InscribedSoDueAt(Now) + TimeSpan.FromDays(1)); + + Assert.False(registration.HerregistratieReminderDue(Now)); + } + + [Fact] + public void A_registration_that_is_not_ingeschreven_is_never_due_and_has_no_deadline() + { + var registration = Registration.Submit("123456782"); // INGEDIEND, never inscribed + + Assert.Null(registration.IngeschrevenOp); + Assert.Null(registration.HerregistratieVoor); + Assert.False(registration.HerregistratieReminderDue(Now)); + } + + [Fact] + public void A_reminded_registration_is_no_longer_due() + { + var registration = Inscribed(InscribedSoDueAt(Now)); + + registration.MarkHerregistratieReminderVerstuurd(); + + Assert.True(registration.HerregistratieReminderVerstuurd); + Assert.False(registration.HerregistratieReminderDue(Now)); + } + + [Fact] + public void Marking_the_reminder_sent_twice_is_idempotent() + { + var registration = Inscribed(InscribedSoDueAt(Now)); + + registration.MarkHerregistratieReminderVerstuurd(); + registration.MarkHerregistratieReminderVerstuurd(); + + Assert.True(registration.HerregistratieReminderVerstuurd); + } + + [Fact] + public void Marking_a_reminder_on_a_registration_that_is_not_ingeschreven_is_rejected() + { + var registration = Registration.Submit("123456782"); + + var ex = Assert.Throws(() => registration.MarkHerregistratieReminderVerstuurd()); + Assert.Contains("INGESCHREVEN", ex.Message); + } +} diff --git a/services/domain/Big.Tests/RegistrationTests.cs b/services/domain/Big.Tests/RegistrationTests.cs index 003021e..98d134f 100644 --- a/services/domain/Big.Tests/RegistrationTests.cs +++ b/services/domain/Big.Tests/RegistrationTests.cs @@ -4,6 +4,9 @@ namespace Big.Tests; public class RegistrationTests { + // A fixed inscription moment for the approval tests; its exact value is irrelevant to them. + private static readonly DateTimeOffset Ingeschreven = new(2026, 1, 1, 0, 0, 0, TimeSpan.Zero); + [Fact] public void Submitting_a_registration_starts_in_ingediend() { @@ -103,7 +106,7 @@ public class RegistrationTests var registration = Registration.Submit("123456782"); registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); - registration.Approve(); + registration.Approve(Ingeschreven); Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status); } @@ -113,7 +116,7 @@ public class RegistrationTests { var registration = Registration.Submit("123456782"); - var ex = Assert.Throws(() => registration.Approve()); + var ex = Assert.Throws(() => registration.Approve(Ingeschreven)); Assert.Contains("no zaak", ex.Message, StringComparison.OrdinalIgnoreCase); Assert.Equal(RegistrationStatus.Ingediend, registration.Status); @@ -124,9 +127,9 @@ public class RegistrationTests { var registration = Registration.Submit("123456782"); registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); - registration.Approve(); + registration.Approve(Ingeschreven); - var ex = Assert.Throws(() => registration.Approve()); + var ex = Assert.Throws(() => registration.Approve(Ingeschreven)); Assert.Contains("only an INGEDIEND", ex.Message); Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status); } @@ -157,7 +160,7 @@ public class RegistrationTests { var registration = Registration.Submit("123456782"); registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); - registration.Approve(); + registration.Approve(Ingeschreven); var ex = Assert.Throws(() => registration.TakeIntoBehandeling()); Assert.Contains("only an INGEDIEND", ex.Message); @@ -171,7 +174,7 @@ public class RegistrationTests registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); registration.TakeIntoBehandeling(); - registration.Approve(); + registration.Approve(Ingeschreven); Assert.Equal(RegistrationStatus.Ingeschreven, registration.Status); } @@ -218,7 +221,7 @@ public class RegistrationTests var approveEx = Assert.Throws(() => { registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); - registration.Approve(); + registration.Approve(Ingeschreven); }); Assert.Contains("IN_BEHANDELING", approveEx.Message); @@ -277,7 +280,7 @@ public class RegistrationTests { var registration = Registration.Submit("123456782"); registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); - registration.Approve(); + registration.Approve(Ingeschreven); var ex = Assert.Throws(() => registration.Withdraw()); Assert.Contains("only an INGEDIEND", ex.Message); @@ -336,7 +339,7 @@ public class RegistrationTests { var registration = Registration.Submit("123456782"); registration.AttachZaak(new Uri("http://openzaak/zaken/api/v1/zaken/abc")); - registration.Approve(); + registration.Approve(Ingeschreven); var ex = Assert.Throws(() => registration.Expire()); Assert.Contains("only an INGEDIEND", ex.Message);