diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.01-take-in-place.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.01-take-in-place.json.snap new file mode 100644 index 000000000..6ce397312 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.01-take-in-place.json.snap @@ -0,0 +1,408 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "", + "units": 1, + "item_ids": [ + "" + ], + "auto_opened": 1 + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "29", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.02-skip-flip.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.02-skip-flip.json.snap new file mode 100644 index 000000000..f264ae601 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.02-skip-flip.json.snap @@ -0,0 +1,423 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "", + "units": 1, + "item_ids": [ + "" + ] + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.03-move-by-band.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.03-move-by-band.json.snap new file mode 100644 index 000000000..cef0085b9 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.03-move-by-band.json.snap @@ -0,0 +1,420 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "idempotencyKey": null, + "scheduledFor": "2026-10-14T20:00:00.000Z", + "source": "WEB", + "createdAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.04-pin-free-slot.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.04-pin-free-slot.json.snap new file mode 100644 index 000000000..292c4f3a2 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.04-pin-free-slot.json.snap @@ -0,0 +1,457 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "idempotencyKey": null, + "scheduledFor": "2026-10-12T20:00:00.000Z", + "source": "WEB", + "createdAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.05-pin-not-a-slot.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.05-pin-not-a-slot.json.snap new file mode 100644 index 000000000..c6e364cd5 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.05-pin-not-a-slot.json.snap @@ -0,0 +1,442 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "forceSlotInstant is not a scheduled slot of this medication", + "meta": { + "errorCode": "medications.intake.force_slot.invalid", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": { + "name": "medication.intake.force_slot.invalid" + }, + "meta": { + "medication_id": "", + "event_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.06-pin-occupied.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.06-pin-occupied.json.snap new file mode 100644 index 000000000..5e081753f --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.06-pin-occupied.json.snap @@ -0,0 +1,442 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "forceSlotInstant already carries a recorded dose action", + "meta": { + "errorCode": "medications.intake.force_slot.occupied", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": { + "name": "medication.intake.force_slot.occupied" + }, + "meta": { + "medication_id": "", + "event_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.07-unpin.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.07-unpin.json.snap new file mode 100644 index 000000000..99fba82d2 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.07-unpin.json.snap @@ -0,0 +1,494 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "idempotencyKey": null, + "scheduledFor": "2026-10-13T20:00:00.000Z", + "source": "WEB", + "createdAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.08-explicit-slot.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.08-explicit-slot.json.snap new file mode 100644 index 000000000..8ca547dfa --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.08-explicit-slot.json.snap @@ -0,0 +1,533 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "idempotencyKey": null, + "scheduledFor": "2026-10-14T08:00:00.000Z", + "source": "WEB", + "createdAt": "" + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.09-before-start.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.09-before-start.json.snap new file mode 100644 index 000000000..84475f2d0 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.09-before-start.json.snap @@ -0,0 +1,518 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "takenAt is before the medication's start date", + "meta": { + "errorCode": "medications.intake.taken_at.before_start", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": { + "name": "medications.intake.event.update.before-start-date" + }, + "meta": { + "medication_id": "", + "event_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.10-invalid.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.10-invalid.json.snap new file mode 100644 index 000000000..e78d84965 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.10-invalid.json.snap @@ -0,0 +1,534 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "Validation failed", + "details": { + "issues": [ + { + "path": "takenAt", + "code": "invalid_format", + "message": "Invalid ISO datetime" + }, + { + "path": "skipped", + "code": "invalid_type", + "message": "Invalid input: expected boolean, received string" + } + ] + }, + "meta": { + "errorCode": "http.invalid", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": { + "name": "medications.intake.event.update.validation-failed" + }, + "meta": { + "issue_count": 2, + "medication_id": "", + "event_id": "", + "rejected_attempt": "medications.intake.event.update.validation-failed" + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.11a-tombstoned.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.11a-tombstoned.json.snap new file mode 100644 index 000000000..7a2824812 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.11a-tombstoned.json.snap @@ -0,0 +1,513 @@ +{ + "status": 404, + "body": { + "data": null, + "error": "Intake not found", + "meta": { + "errorCode": "http.not_found", + "requestId": "" + } + }, + "events": [ + { + "status": 404, + "action": null, + "meta": null, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.11b-other-medication.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.11b-other-medication.json.snap new file mode 100644 index 000000000..7a2824812 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.11b-other-medication.json.snap @@ -0,0 +1,513 @@ +{ + "status": 404, + "body": { + "data": null, + "error": "Intake not found", + "meta": { + "errorCode": "http.not_found", + "requestId": "" + } + }, + "events": [ + { + "status": 404, + "action": null, + "meta": null, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.12a-writer.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.12a-writer.json.snap new file mode 100644 index 000000000..5cc86ab63 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.12a-writer.json.snap @@ -0,0 +1,518 @@ +{ + "status": 403, + "body": { + "data": null, + "error": "Account access denied", + "meta": { + "errorCode": "sharing.access.denied", + "requestId": "" + } + }, + "events": [ + { + "status": 403, + "action": null, + "meta": { + "sharing_refusal": "insufficient_access" + }, + "warnings": null, + "error": { + "type": "SharingAccessDeniedError", + "message": "Account access denied" + } + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.12b-manager.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.12b-manager.json.snap new file mode 100644 index 000000000..d3b8934ca --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.12b-manager.json.snap @@ -0,0 +1,561 @@ +{ + "status": 200, + "body": { + "data": { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.update", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.13-anonymous.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.13-anonymous.json.snap new file mode 100644 index 000000000..a1e963e0d --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.13-anonymous.json.snap @@ -0,0 +1,532 @@ +{ + "status": 401, + "body": { + "data": null, + "error": "Not authenticated", + "meta": { + "errorCode": "auth.missing", + "requestId": "" + } + }, + "events": [ + { + "status": 401, + "action": null, + "meta": null, + "warnings": null, + "error": { + "type": "HttpError", + "message": "Not authenticated" + } + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.21-delete.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.21-delete.json.snap new file mode 100644 index 000000000..4658173e8 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.21-delete.json.snap @@ -0,0 +1,553 @@ +{ + "status": 200, + "body": { + "data": { + "deleted": true + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.delete", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": false, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.22-delete-one-shot.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.22-delete-one-shot.json.snap new file mode 100644 index 000000000..7bc6ba40a --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.22-delete-one-shot.json.snap @@ -0,0 +1,572 @@ +{ + "status": 200, + "body": { + "data": { + "deleted": true + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.oneShot.reconciled" + }, + "meta": { + "medication_id": "", + "action": "activate" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + }, + { + "action": "medication.oneShot.reconciled", + "userId": "", + "actorUserId": null, + "details": { + "medicationId": "", + "action": "activate" + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.23-other-medication.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.23-other-medication.json.snap new file mode 100644 index 000000000..c7950a1eb --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.23-other-medication.json.snap @@ -0,0 +1,559 @@ +{ + "status": 404, + "body": { + "data": null, + "error": "Intake not found", + "meta": { + "errorCode": "http.not_found", + "requestId": "" + } + }, + "events": [ + { + "status": 404, + "action": null, + "meta": null, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + }, + { + "action": "medication.oneShot.reconciled", + "userId": "", + "actorUserId": null, + "details": { + "medicationId": "", + "action": "activate" + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.24a-writer.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.24a-writer.json.snap new file mode 100644 index 000000000..9ae53c9b8 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.24a-writer.json.snap @@ -0,0 +1,564 @@ +{ + "status": 403, + "body": { + "data": null, + "error": "Account access denied", + "meta": { + "errorCode": "sharing.access.denied", + "requestId": "" + } + }, + "events": [ + { + "status": 403, + "action": null, + "meta": { + "sharing_refusal": "insufficient_access" + }, + "warnings": null, + "error": { + "type": "SharingAccessDeniedError", + "message": "Account access denied" + } + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + }, + { + "action": "medication.oneShot.reconciled", + "userId": "", + "actorUserId": null, + "details": { + "medicationId": "", + "action": "activate" + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.24b-manager.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.24b-manager.json.snap new file mode 100644 index 000000000..32e1401fb --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.24b-manager.json.snap @@ -0,0 +1,583 @@ +{ + "status": 200, + "body": { + "data": { + "deleted": true + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medication.intake.delete", + "entity_type": "intake_event", + "entity_id": "" + }, + "meta": { + "medication_id": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + }, + { + "action": "medication.oneShot.reconciled", + "userId": "", + "actorUserId": null, + "details": { + "medicationId": "", + "action": "activate" + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-event.25-anonymous.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-event.25-anonymous.json.snap new file mode 100644 index 000000000..9d3d932eb --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-event.25-anonymous.json.snap @@ -0,0 +1,572 @@ +{ + "status": 401, + "body": { + "data": null, + "error": "Not authenticated", + "meta": { + "errorCode": "auth.missing", + "requestId": "" + } + }, + "events": [ + { + "status": 401, + "action": null, + "meta": null, + "warnings": null, + "error": { + "type": "HttpError", + "message": "Not authenticated" + } + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Parity one-shot", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": true, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Parity tablet", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": "2026-10-01T00:00:00.000Z", + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "ORAL", + "trackInjectionSites": false, + "allowedInjectionSites": [], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + } + ], + "schedules": [ + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": "Morning", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "09:00", + "windowEnd": "11:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": "Evening", + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [], + "reminderGraceMinutes": null, + "rrule": null, + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-10T09:00:00.000Z", + "takenAt": "2026-10-10T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T08:00:00.000Z", + "takenAt": "2026-10-11T08:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-11T20:00:00.000Z", + "takenAt": "2026-10-11T20:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "2026-10-12T09:00:00.000Z" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T08:40:00.000Z", + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:15:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T20:00:00.000Z", + "takenAt": "2026-10-13T20:50:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:45:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "WEB", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": "" + } + ], + "doseChanges": [], + "inventoryItems": [ + { + "id": "", + "userId": "", + "medicationId": "", + "state": "IN_USE", + "containerType": "OTHER", + "unitsTotal": "30", + "unitsRemaining": "30", + "firstUseAt": "2026-10-13T08:40:00.000Z", + "expiresAt": null, + "printedExpiry": null, + "purchasedAt": "2026-10-01T06:00:00.000Z", + "manufacturer": null, + "doseStrength": null, + "notes": null, + "notesEncrypted": null, + "createdAt": "", + "updatedAt": "" + } + ], + "inventoryEvents": [], + "categories": [], + "ingredients": [], + "audit": [ + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.delete", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "" + }, + "ipAddress": "unknown" + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": "", + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": "2026-10-13T20:15:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T08:00:00.000Z", + "takenAt": "2026-10-14T08:10:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor", + "takenAt" + ], + "previous": { + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:30:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-12T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "scheduledFor" + ], + "previous": { + "scheduledFor": "2026-10-13T20:00:00.000Z" + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "skipped" + ], + "previous": { + "skipped": false + } + }, + "ipAddress": null + }, + { + "action": "medication.intake.update", + "userId": "", + "actorUserId": null, + "details": { + "eventId": "", + "medicationId": "", + "fields": [ + "takenAt" + ], + "previous": { + "takenAt": null + } + }, + "ipAddress": null + }, + { + "action": "medication.oneShot.reconciled", + "userId": "", + "actorUserId": null, + "details": { + "medicationId": "", + "action": "activate" + }, + "ipAddress": null + } + ], + "idempotency": [] + } +} diff --git a/tests/integration/routes/parity/medication-intake-event.parity.test.ts b/tests/integration/routes/parity/medication-intake-event.parity.test.ts new file mode 100644 index 000000000..415422a60 --- /dev/null +++ b/tests/integration/routes/parity/medication-intake-event.parity.test.ts @@ -0,0 +1,384 @@ +/** + * Parity for `PUT` and `DELETE /api/medications/{id}/intake/{eventId}` while + * the dose correction moves into `src/lib/medications/`. + * + * One record walks through the corrections the route tells apart, in order, + * each request seeing what the earlier ones stored: a take recorded in place, + * a take flipped to a skip, a correction that moves the dose to another slot + * (tombstone and converge), a pin onto a free slot, the two pin refusals, an + * unpin, an explicit slot, a take before the start day, a body the schema + * refuses, the not-found answers, and the same correction from a delegate who + * may only write and one who may manage. Then the deletes: the owner's, one + * that reactivates a one-shot medication, the not-found answer, and both + * delegates again. After each request the snapshot holds the response, the + * wide event, the recorded tails and every medication row of the accounts. + * + * The clock is pinned (`Date` only), so the snapshot is the same on every + * day it runs. + */ +import { afterAll, beforeAll, describe, it, vi } from "vitest"; + +import { DELETE, PUT } from "@/app/api/medications/[id]/intake/[eventId]/route"; + +import { anonymous, type RouteAuth } from "../../../kit/call-route"; +import { makeMedication, makeSession, makeUser } from "../../../kit/factories"; +import { getPrismaClient, truncateAllTables } from "../../setup"; +import { delegateOf, parityStep } from "./medication-state"; + +vi.mock("@/lib/logging/transports", async (importOriginal) => { + const actual = + await importOriginal(); + const { wideEventRecorder: recorder } = await import("../../../kit/parity"); + return { + ...actual, + emitIfSampled: (event: (typeof recorder.events)[number]) => { + recorder.events.push(event); + }, + }; +}); + +// The cross-device push the route queues on a timer, recorded instead of run +// (see `effectRecorder`). +vi.mock( + "@/lib/notifications/medication-intake-sync", + async (importOriginal) => { + const actual = + await importOriginal< + typeof import("@/lib/notifications/medication-intake-sync") + >(); + const { effectRecorder } = await import("../../../kit/parity"); + return { + ...actual, + queueMedicationIntakeSync: (...args: unknown[]) => { + effectRecorder.record("queueMedicationIntakeSync", args); + }, + }; + }, +); + +const prisma = getPrismaClient(); +const NOW = new Date("2026-10-15T12:00:00.000Z"); +const ROUTE = "/api/medications/{id}/intake/{eventId}"; +/** + * A correction that moves the dose answers with the row the shared slot write + * returns, which carries fewer fields than the registered event resource. The + * parity snapshot pins that answer as it is; the contract check is the + * route's own tests' business. + */ +const SLOT_MOVE_ANSWER = { + skip: "a slot move answers with the narrower slot-write row", +}; + +let ownerId: string; +let userIds: string[]; +let owner: RouteAuth; +let writer: { auth: RouteAuth; headers: Record }; +let manager: { auth: RouteAuth; headers: Record }; +let medicationId: string; +let oneShotId: string; +const events: Record = {}; + +async function put( + name: string, + eventId: string, + body: unknown, + options: { + auth?: RouteAuth; + headers?: Record; + medicationId?: string; + contract?: { skip: string }; + } = {}, +) { + return parityStep({ + name: `medication-intake-event.${name}`, + handler: PUT, + options: { + method: "PUT", + route: ROUTE, + params: { id: options.medicationId ?? medicationId, eventId }, + body, + auth: options.auth ?? owner, + headers: options.headers, + contract: options.contract, + }, + userIds, + now: NOW, + }); +} + +async function del( + name: string, + eventId: string, + options: { + auth?: RouteAuth; + headers?: Record; + medicationId?: string; + } = {}, +) { + return parityStep({ + name: `medication-intake-event.${name}`, + handler: DELETE, + options: { + method: "DELETE", + route: ROUTE, + params: { id: options.medicationId ?? medicationId, eventId }, + auth: options.auth ?? owner, + headers: options.headers, + }, + userIds, + now: NOW, + }); +} + +async function intake( + medication: string, + key: string, + data: { + scheduledFor: string; + takenAt?: string | null; + skipped?: boolean; + deletedAt?: string; + }, +) { + const row = await prisma.medicationIntakeEvent.create({ + data: { + userId: ownerId, + medicationId: medication, + scheduledFor: new Date(data.scheduledFor), + takenAt: data.takenAt ? new Date(data.takenAt) : null, + skipped: data.skipped ?? false, + deletedAt: data.deletedAt ? new Date(data.deletedAt) : null, + }, + }); + events[key] = row.id; +} + +beforeAll(async () => { + vi.useFakeTimers({ toFake: ["Date"], now: NOW }); + await truncateAllTables(prisma); + const user = await makeUser({ timezone: "UTC" }); + ownerId = user.id; + owner = await makeSession(user); + const created = new Date("2026-10-01T06:00:00.000Z"); + const medication = await makeMedication( + user, + { + name: "Parity tablet", + startsOn: new Date("2026-10-01"), + createdAt: created, + unitsPerDose: 1, + }, + [ + { windowStart: "08:00", windowEnd: "10:00", label: "Morning" }, + { windowStart: "20:00", windowEnd: "22:00", label: "Evening" }, + ], + ); + medicationId = medication.id; + await prisma.medicationInventoryItem.create({ + data: { + userId: ownerId, + medicationId, + unitsTotal: 30, + unitsRemaining: 30, + purchasedAt: created, + }, + }); + const oneShot = await makeMedication( + user, + { + name: "Parity one-shot", + startsOn: new Date("2026-10-01"), + createdAt: created, + oneShot: true, + active: false, + }, + [{ windowStart: "09:00", windowEnd: "11:00" }], + ); + oneShotId = oneShot.id; + + await intake(medicationId, "pending", { + scheduledFor: "2026-10-13T08:00:00.000Z", + }); + await intake(medicationId, "legacyTaken", { + scheduledFor: "2026-10-13T20:00:00.000Z", + takenAt: "2026-10-13T20:15:00.000Z", + }); + await intake(medicationId, "morningTaken", { + scheduledFor: "2026-10-14T08:00:00.000Z", + takenAt: "2026-10-14T08:10:00.000Z", + }); + await intake(medicationId, "eveningSkipped", { + scheduledFor: "2026-10-14T20:00:00.000Z", + skipped: true, + }); + await intake(medicationId, "tombstoned", { + scheduledFor: "2026-10-12T08:00:00.000Z", + takenAt: "2026-10-12T08:05:00.000Z", + deletedAt: "2026-10-12T09:00:00.000Z", + }); + await intake(medicationId, "forDelete", { + scheduledFor: "2026-10-11T08:00:00.000Z", + takenAt: "2026-10-11T08:20:00.000Z", + }); + await intake(medicationId, "forManagerDelete", { + scheduledFor: "2026-10-11T20:00:00.000Z", + takenAt: "2026-10-11T20:20:00.000Z", + }); + await intake(oneShotId, "oneShotDose", { + scheduledFor: "2026-10-10T09:00:00.000Z", + takenAt: "2026-10-10T09:30:00.000Z", + }); + + const w = await delegateOf(prisma, user, "WRITE"); + const m = await delegateOf(prisma, user, "MANAGE"); + writer = { auth: w.auth, headers: w.headers }; + manager = { auth: m.auth, headers: m.headers }; + userIds = [ownerId, w.delegate.id, m.delegate.id]; +}); + +afterAll(() => { + vi.useRealTimers(); +}); + +describe("PUT /api/medications/{id}/intake/{eventId} parity", () => { + it("01 a pending dose taken inside its own window", async () => { + await put("01-take-in-place", events.pending, { + takenAt: "2026-10-13T08:40:00.000Z", + }); + }); + + it("02 the same dose flipped to a skip", async () => { + await put("02-skip-flip", events.pending, { skipped: true }); + }); + + it("03 a take corrected into the other window, onto a skipped slot", async () => { + const res = await put( + "03-move-by-band", + events.morningTaken, + { takenAt: "2026-10-14T20:30:00.000Z" }, + { contract: SLOT_MOVE_ANSWER }, + ); + events.moved = (res.data as { id: string }).id; + }); + + it("04 a legacy take pinned onto a free slot", async () => { + const res = await put( + "04-pin-free-slot", + events.legacyTaken, + { forceSlotInstant: "2026-10-12T20:00:00.000Z" }, + { contract: SLOT_MOVE_ANSWER }, + ); + events.pinned = (res.data as { id: string }).id; + }); + + it("05 a pin onto an instant that is no slot", async () => { + await put("05-pin-not-a-slot", events.moved, { + forceSlotInstant: "2026-10-12T15:00:00.000Z", + }); + }); + + it("06 a pin onto a slot another dose holds", async () => { + await put("06-pin-occupied", events.moved, { + forceSlotInstant: "2026-10-12T20:00:00.000Z", + }); + }); + + it("07 an unpin", async () => { + const res = await put( + "07-unpin", + events.pinned, + { forceSlotInstant: null }, + { contract: SLOT_MOVE_ANSWER }, + ); + events.pinned = (res.data as { id: string }).id; + }); + + it("08 an explicit slot in the body", async () => { + const res = await put( + "08-explicit-slot", + events.moved, + { + scheduledFor: "2026-10-14T08:00:00.000Z", + takenAt: "2026-10-14T08:45:00.000Z", + }, + { contract: SLOT_MOVE_ANSWER }, + ); + events.moved = (res.data as { id: string }).id; + }); + + it("09 a take before the start day", async () => { + await put("09-before-start", events.pinned, { + takenAt: "2026-09-20T08:00:00.000Z", + }); + }); + + it("10 a body the schema refuses", async () => { + await put("10-invalid", events.pinned, { + takenAt: "yesterday", + skipped: "no", + }); + }); + + it("11 a tombstoned dose, and a dose under another medication", async () => { + await put("11a-tombstoned", events.tombstoned, { skipped: true }); + await put( + "11b-other-medication", + events.pinned, + { skipped: true }, + { medicationId: oneShotId }, + ); + }); + + it("12 a delegate who may write, and one who may manage", async () => { + await put( + "12a-writer", + events.pinned, + { takenAt: "2026-10-13T20:50:00.000Z" }, + writer, + ); + await put( + "12b-manager", + events.pinned, + { takenAt: "2026-10-13T20:50:00.000Z" }, + manager, + ); + }); + + it("13 no credentials", async () => { + await put( + "13-anonymous", + events.pinned, + { skipped: true }, + { + auth: anonymous, + }, + ); + }); +}); + +describe("DELETE /api/medications/{id}/intake/{eventId} parity", () => { + it("21 the owner undoes a dose", async () => { + await del("21-delete", events.forDelete); + }); + + it("22 undoing the only dose of a one-shot medication", async () => { + await del("22-delete-one-shot", events.oneShotDose, { + medicationId: oneShotId, + }); + }); + + it("23 a dose under another medication", async () => { + await del("23-other-medication", events.forManagerDelete, { + medicationId: oneShotId, + }); + }); + + it("24 a delegate who may write, and one who may manage", async () => { + await del("24a-writer", events.forManagerDelete, writer); + await del("24b-manager", events.forManagerDelete, manager); + }); + + it("25 no credentials", async () => { + await del("25-anonymous", events.forDelete, { auth: anonymous }); + }); +}); diff --git a/tests/integration/routes/parity/medication-state.ts b/tests/integration/routes/parity/medication-state.ts new file mode 100644 index 000000000..1103d75fa --- /dev/null +++ b/tests/integration/routes/parity/medication-state.ts @@ -0,0 +1,226 @@ +/** + * What a medication route leaves in the database, read back for a parity + * snapshot (see `tests/kit/parity.ts`). + * + * Whole rows, not a hand-picked select: a parity snapshot is meant to notice + * a column the moved code stops writing, and a select names only the columns + * somebody thought of. Two kinds of value are rewritten before the snapshot + * sees them, because their bytes differ between two runs of the same code: + * ciphertext (a fresh IV per write) reads as `` or ``, and + * a Prisma `Decimal` reads as its decimal string. + * + * Rows come back in an order decided by their content with generated ids + * blanked, never by the ids themselves, so two runs list them alike. + */ +import { Prisma, type User } from "@/generated/prisma/client"; +import type { AccountGrantAccess } from "@/generated/prisma/enums"; + +import { expect } from "vitest"; + +import { callRoute, type CallRouteOptions } from "../../../kit/call-route"; +import type { SessionFixture } from "../../../kit/factories"; +import { makeGrant, makeSession, makeUser } from "../../../kit/factories"; +import { + effectRecorder, + eventFacts, + expectParity, + stable, + wideEventRecorder, +} from "../../../kit/parity"; +import { getPrismaClient } from "../../setup"; + +type Client = ReturnType; + +/** + * A second account holding a grant of `access` over `owner`'s record, with + * its session switched onto that record and the headers a switched browser + * sends with every request. + */ +export async function delegateOf( + prisma: Client, + owner: Pick, + access: AccountGrantAccess, +): Promise<{ + delegate: User; + auth: SessionFixture; + headers: Record; +}> { + const delegate = await makeUser({ timezone: "UTC" }); + await makeGrant(owner, delegate, { access }); + const auth = await makeSession(delegate); + const switched = await prisma.session.update({ + where: { id: auth.sessionId }, + data: { actingAsUserId: owner.id }, + }); + return { + delegate, + auth, + headers: { + "x-healthlog-record-epoch": String(switched.recordEpoch), + "x-healthlog-record-scope": owner.id, + }, + }; +} + +const GENERATED_ID = + /^(c[a-z0-9]{24}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/; +/** Audit rows the record guard writes without awaiting them. */ +const GUARD_TRAIL_ACTIONS = [ + "sharing.record.accessed", + "sharing.access.denied", +] as const; +const ORDER_BLIND_KEYS = new Set(["createdAt", "updatedAt", "syncVersion"]); + +/** A copy with ciphertext and decimals replaced by stable stand-ins. */ +export function plain(value: unknown): unknown { + if (value === null || value === undefined) return value; + if (value instanceof Date) return value; + if (Prisma.Decimal.isDecimal(value)) return value.toString(); + if (value instanceof Uint8Array) return ""; + if (Array.isArray(value)) return value.map(plain); + if (typeof value === "object") { + const out: Record = {}; + for (const [k, v] of Object.entries(value)) { + out[k] = /Encrypted$/.test(k) && v !== null ? "" : plain(v); + } + return out; + } + return value; +} + +function orderKey(value: unknown): string { + return JSON.stringify(value, (key, v: unknown) => { + if (ORDER_BLIND_KEYS.has(key)) return undefined; + if (typeof v === "string" && GENERATED_ID.test(v)) return ""; + return v; + }); +} + +/** Rows in content order, ids and stamps left out of the comparison. */ +export function sortRows(rows: readonly T[]): unknown[] { + return rows + .map(plain) + .map((row) => ({ row, key: orderKey(row) })) + .sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)) + .map(({ row }) => row); +} + +/** + * Every medication table a medication route writes, for the given accounts, + * plus the audit trail and the idempotency cache. The rows the record guard + * writes about a delegate (the day's access row, a refusal) are left out: the + * guard writes them fire-and-forget, so whether one has landed when the test + * reads is a race, not something the route decides. + */ +export async function medicationState(prisma: Client, userIds: string[]) { + const byUser = { userId: { in: userIds } }; + const byMedication = { medication: byUser }; + const [ + medications, + schedules, + revisions, + pauseEras, + courses, + intakes, + doseChanges, + inventoryItems, + inventoryEvents, + categories, + ingredients, + audit, + idempotency, + ] = await Promise.all([ + prisma.medication.findMany({ where: byUser }), + prisma.medicationSchedule.findMany({ where: byMedication }), + prisma.medicationScheduleRevision.findMany({ where: byMedication }), + prisma.medicationPauseEra.findMany({ where: byMedication }), + prisma.medicationCourse.findMany({ where: byMedication }), + prisma.medicationIntakeEvent.findMany({ where: byUser }), + prisma.medicationDoseChange.findMany({ where: byMedication }), + prisma.medicationInventoryItem.findMany({ where: byUser }), + prisma.medicationInventoryEvent.findMany({ where: byMedication }), + prisma.medicationCategoryAssignment.findMany({ where: byMedication }), + prisma.medicationIngredient.findMany({ where: byMedication }), + prisma.auditLog.findMany({ + where: { ...byUser, action: { notIn: [...GUARD_TRAIL_ACTIONS] } }, + select: { + action: true, + userId: true, + actorUserId: true, + details: true, + ipAddress: true, + }, + }), + prisma.idempotencyKey.findMany({ + where: byUser, + select: { + userId: true, + key: true, + method: true, + path: true, + responseStatus: true, + requestFingerprint: true, + expiresAt: true, + }, + }), + ]); + return { + medications: sortRows(medications), + schedules: sortRows(schedules), + revisions: sortRows(revisions), + pauseEras: sortRows(pauseEras), + courses: sortRows(courses), + intakes: sortRows(intakes), + doseChanges: sortRows(doseChanges), + inventoryItems: sortRows(inventoryItems), + inventoryEvents: sortRows(inventoryEvents), + categories: sortRows(categories), + ingredients: sortRows(ingredients), + audit: sortRows( + audit.map((row) => ({ + ...row, + details: row.details ? (JSON.parse(row.details) as unknown) : null, + })), + ), + idempotency: sortRows(idempotency), + }; +} + +export interface ParityCall { + /** Snapshot name, `.`. */ + name: string; + handler: Parameters[0]; + options: CallRouteOptions; + /** Accounts whose rows the snapshot reads back. */ + userIds: string[]; + /** The clock the test pinned; server stamps at or after it read ``. */ + now: Date; +} + +/** + * One request and everything it decided: the response, the wide event, the + * recorded tails and the rows read back afterwards, compared with the + * committed snapshot. Returns the response for a test that needs an id from + * it for the next case. + */ +export async function parityStep(call: ParityCall) { + wideEventRecorder.take(); + effectRecorder.take(); + const res = await callRoute(call.handler, call.options); + const events = wideEventRecorder.take(); + expect(events.length).toBeGreaterThan(0); + await expectParity( + call.name, + stable( + { + status: res.status, + body: res.body, + events: events.map(eventFacts), + effects: effectRecorder.take(), + stored: await medicationState(getPrismaClient(), call.userIds), + }, + { since: call.now }, + ), + ); + return res; +}