diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.01-mixed.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.01-mixed.json.snap new file mode 100644 index 000000000..436ec3020 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.01-mixed.json.snap @@ -0,0 +1,701 @@ +{ + "status": 200, + "body": { + "data": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": [ + { + "index": 0, + "reason": "medication_not_found" + }, + { + "index": 1, + "reason": "intake_not_tracked" + }, + { + "index": 2, + "reason": "unstable_external_id" + }, + { + "index": 5, + "reason": "force_slot_invalid" + }, + { + "index": 6, + "reason": "force_slot_occupied" + }, + { + "index": 12, + "reason": "injection_site_not_allowed" + }, + { + "index": 16, + "reason": "unstable_external_id" + } + ], + "entries": [ + { + "index": 0, + "status": "skipped", + "reason": "medication_not_found" + }, + { + "index": 1, + "status": "skipped", + "reason": "intake_not_tracked" + }, + { + "index": 2, + "status": "skipped", + "reason": "unstable_external_id" + }, + { + "index": 3, + "status": "updated", + "id": "" + }, + { + "index": 4, + "status": "inserted", + "id": "" + }, + { + "index": 5, + "status": "skipped", + "reason": "force_slot_invalid" + }, + { + "index": 6, + "status": "skipped", + "reason": "force_slot_occupied" + }, + { + "index": 7, + "status": "inserted", + "id": "" + }, + { + "index": 8, + "status": "duplicate", + "id": "" + }, + { + "index": 9, + "status": "inserted", + "id": "" + }, + { + "index": 10, + "status": "inserted", + "id": "" + }, + { + "index": 11, + "status": "duplicate", + "id": "" + }, + { + "index": 12, + "status": "skipped", + "reason": "injection_site_not_allowed" + }, + { + "index": 13, + "status": "inserted", + "id": "" + }, + { + "index": 14, + "status": "duplicate", + "id": "" + }, + { + "index": 15, + "status": "inserted", + "id": "" + }, + { + "index": 16, + "status": "skipped", + "reason": "unstable_external_id" + }, + { + "index": 17, + "status": "updated", + "id": "" + } + ] + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medications.intake.bulk.ingest" + }, + "meta": { + "write_bucket": "own", + "medication_id": "", + "units": 0, + "item_ids": [], + "auto_opened": 0, + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7, + "extra_doses_unscheduled": 1, + "external_id_rejected": 2, + "external_id_shapes": "object_description", + "external_id_surface": "medication.intake.bulk", + "sync_checkpoint_at": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + }, + { + "effect": "countOutstandingDosesToday", + "args": [ + "", + "UTC" + ] + }, + { + "effect": "dispatchMedicationIntakeWebClearBulk", + "args": [ + { + "userId": "", + "slots": [ + { + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z" + } + ], + "badgeCount": 2 + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "foreground", + "lastNewSampleAt": "", + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.02-mixed-again.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.02-mixed-again.json.snap new file mode 100644 index 000000000..3cb7d5b8a --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.02-mixed-again.json.snap @@ -0,0 +1,702 @@ +{ + "status": 200, + "body": { + "data": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": [ + { + "index": 0, + "reason": "medication_not_found" + }, + { + "index": 1, + "reason": "intake_not_tracked" + }, + { + "index": 2, + "reason": "unstable_external_id" + }, + { + "index": 5, + "reason": "force_slot_invalid" + }, + { + "index": 6, + "reason": "force_slot_occupied" + }, + { + "index": 12, + "reason": "injection_site_not_allowed" + }, + { + "index": 16, + "reason": "unstable_external_id" + } + ], + "entries": [ + { + "index": 0, + "status": "skipped", + "reason": "medication_not_found" + }, + { + "index": 1, + "status": "skipped", + "reason": "intake_not_tracked" + }, + { + "index": 2, + "status": "skipped", + "reason": "unstable_external_id" + }, + { + "index": 3, + "status": "updated", + "id": "" + }, + { + "index": 4, + "status": "updated", + "id": "" + }, + { + "index": 5, + "status": "skipped", + "reason": "force_slot_invalid" + }, + { + "index": 6, + "status": "skipped", + "reason": "force_slot_occupied" + }, + { + "index": 7, + "status": "updated", + "id": "" + }, + { + "index": 8, + "status": "duplicate", + "id": "" + }, + { + "index": 9, + "status": "updated", + "id": "" + }, + { + "index": 10, + "status": "duplicate", + "id": "" + }, + { + "index": 11, + "status": "duplicate", + "id": "" + }, + { + "index": 12, + "status": "skipped", + "reason": "injection_site_not_allowed" + }, + { + "index": 13, + "status": "duplicate", + "id": "" + }, + { + "index": 14, + "status": "duplicate", + "id": "" + }, + { + "index": 15, + "status": "duplicate", + "id": "" + }, + { + "index": 16, + "status": "skipped", + "reason": "unstable_external_id" + }, + { + "index": 17, + "status": "updated", + "id": "" + } + ] + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medications.intake.bulk.ingest" + }, + "meta": { + "write_bucket": "own", + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7, + "extra_doses_unscheduled": 0, + "external_id_rejected": 2, + "external_id_shapes": "object_description", + "external_id_surface": "medication.intake.bulk", + "sync_checkpoint_at": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + }, + { + "effect": "countOutstandingDosesToday", + "args": [ + "", + "UTC" + ] + }, + { + "effect": "dispatchMedicationIntakeWebClearBulk", + "args": [ + { + "userId": "", + "slots": [ + { + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z" + }, + { + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z" + } + ], + "badgeCount": 2 + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "foreground", + "lastNewSampleAt": "", + "lastBackgroundAt": null, + "lastSeenDuplicateAt": "" + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.03a-background.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.03a-background.json.snap new file mode 100644 index 000000000..eebf4724a --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.03a-background.json.snap @@ -0,0 +1,607 @@ +{ + "status": 200, + "body": { + "data": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": [], + "entries": [ + { + "index": 0, + "status": "inserted", + "id": "" + } + ] + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medications.intake.bulk.ingest" + }, + "meta": { + "write_bucket": "own", + "medication_id": "", + "units": 0, + "item_ids": [], + "auto_opened": 0, + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0, + "extra_doses_unscheduled": 0, + "sync_checkpoint_at": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + }, + { + "effect": "countOutstandingDosesToday", + "args": [ + "", + "UTC" + ] + }, + { + "effect": "dispatchMedicationIntakeWebClearBulk", + "args": [ + { + "userId": "", + "slots": [ + { + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z" + } + ], + "badgeCount": 2 + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.03b-backfill.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.03b-backfill.json.snap new file mode 100644 index 000000000..628b2b978 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.03b-backfill.json.snap @@ -0,0 +1,648 @@ +{ + "status": 200, + "body": { + "data": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": [], + "entries": [ + { + "index": 0, + "status": "inserted", + "id": "" + } + ] + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medications.intake.bulk.ingest" + }, + "meta": { + "write_bucket": "own", + "medication_id": "", + "units": 0, + "item_ids": [], + "auto_opened": 0, + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0, + "extra_doses_unscheduled": 0 + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + }, + { + "effect": "countOutstandingDosesToday", + "args": [ + "", + "UTC" + ] + }, + { + "effect": "dispatchMedicationIntakeWebClearBulk", + "args": [ + { + "userId": "", + "slots": [ + { + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z" + } + ], + "badgeCount": 2 + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04a-too-large.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04a-too-large.json.snap new file mode 100644 index 000000000..3b6ab3db5 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04a-too-large.json.snap @@ -0,0 +1,595 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "Batch exceeds the 500-entry limit", + "meta": { + "errorCode": "medications.intake.bulk.too_large", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": null, + "meta": { + "write_bucket": "own" + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04b-invalid.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04b-invalid.json.snap new file mode 100644 index 000000000..4d2dad010 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04b-invalid.json.snap @@ -0,0 +1,630 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "Validation failed", + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small", + "message": "Too small: expected string to have >=1 characters" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format", + "message": "Invalid ISO datetime" + } + ] + }, + "meta": { + "errorCode": "medications.intake.bulk.invalid", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": { + "name": "medications.intake.bulk.validation-failed" + }, + "meta": { + "write_bucket": "own", + "issue_count": 2 + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.validation-failed", + "userId": "", + "actorUserId": null, + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format" + } + ] + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04c-apple-not-mirrored.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04c-apple-not-mirrored.json.snap new file mode 100644 index 000000000..4249b41f7 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.04c-apple-not-mirrored.json.snap @@ -0,0 +1,613 @@ +{ + "status": 422, + "body": { + "data": null, + "error": "An APPLE_HEALTH entry may only target a medication mirrored from Apple Health", + "meta": { + "errorCode": "medications.intake.bulk.apple_health_not_mirrored", + "requestId": "" + } + }, + "events": [ + { + "status": 422, + "action": null, + "meta": { + "write_bucket": "own" + }, + "warnings": null, + "error": null + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "28", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.validation-failed", + "userId": "", + "actorUserId": null, + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format" + } + ] + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05a-native.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05a-native.json.snap new file mode 100644 index 000000000..6656a318d --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05a-native.json.snap @@ -0,0 +1,708 @@ +{ + "status": 200, + "body": { + "data": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": [], + "entries": [ + { + "index": 0, + "status": "inserted", + "id": "" + } + ] + }, + "error": null + }, + "events": [ + { + "status": 200, + "action": { + "name": "medications.intake.bulk.ingest" + }, + "meta": { + "write_bucket": "own", + "medication_id": "", + "units": 1, + "item_ids": [ + "" + ], + "auto_opened": 0, + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0, + "extra_doses_unscheduled": 0, + "sync_checkpoint_at": "" + }, + "warnings": null, + "error": null + } + ], + "effects": [ + { + "effect": "queueMedicationIntakeSync", + "args": [ + { + "userId": "", + "originDeviceToken": null + } + ] + }, + { + "effect": "countOutstandingDosesToday", + "args": [ + "", + "UTC" + ] + }, + { + "effect": "dispatchMedicationIntakeWebClearBulk", + "args": [ + { + "userId": "", + "slots": [ + { + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z" + } + ], + "badgeCount": 2 + } + ] + } + ], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "27", + "firstUseAt": "2026-10-15T08:30: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": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.validation-failed", + "userId": "", + "actorUserId": null, + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format" + } + ] + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05b-narrow-token.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05b-narrow-token.json.snap new file mode 100644 index 000000000..216e2e279 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05b-narrow-token.json.snap @@ -0,0 +1,663 @@ +{ + "status": 403, + "body": { + "data": null, + "error": "Insufficient permissions", + "meta": { + "errorCode": "auth.scope.insufficient", + "requestId": "" + } + }, + "events": [ + { + "status": 403, + "action": null, + "meta": null, + "warnings": null, + "error": { + "type": "HttpError", + "message": "Insufficient permissions" + } + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "27", + "firstUseAt": "2026-10-15T08:30: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": "auth.bearer.failure", + "userId": "", + "actorUserId": null, + "details": { + "reason": "undeclared_scope", + "tokenId": "" + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.validation-failed", + "userId": "", + "actorUserId": null, + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format" + } + ] + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05c-delegate.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05c-delegate.json.snap new file mode 100644 index 000000000..ef83ea41b --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05c-delegate.json.snap @@ -0,0 +1,665 @@ +{ + "status": 403, + "body": { + "data": null, + "error": "This endpoint cannot be used while acting on another account", + "meta": { + "errorCode": "sharing.not_permitted", + "requestId": "" + } + }, + "events": [ + { + "status": 403, + "action": null, + "meta": { + "sharing_refusal": "undeclared_mode" + }, + "warnings": null, + "error": { + "type": "SharingNotPermittedError", + "message": "This endpoint cannot be used while acting on another account" + } + } + ], + "effects": [], + "stored": { + "medications": [ + { + "id": "", + "userId": "", + "name": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "27", + "firstUseAt": "2026-10-15T08:30: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": "auth.bearer.failure", + "userId": "", + "actorUserId": null, + "details": { + "reason": "undeclared_scope", + "tokenId": "" + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.validation-failed", + "userId": "", + "actorUserId": null, + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format" + } + ] + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05d-anonymous.json.snap b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05d-anonymous.json.snap new file mode 100644 index 000000000..8fff49289 --- /dev/null +++ b/tests/integration/routes/parity/__snapshots__/medication-intake-bulk.05d-anonymous.json.snap @@ -0,0 +1,663 @@ +{ + "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": "Apple mirror", + "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": "APPLE_HEALTH", + "externalId": "hk-concept-0001", + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "As-needed pen", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": true, + "trackIntake": true, + "autoMarkTaken": false, + "autoMarkTakenSince": null, + "deliveryForm": "INJECTION", + "trackInjectionSites": true, + "allowedInjectionSites": [ + "ABDOMEN_LEFT", + "ABDOMEN_RIGHT" + ], + "liveActivityEnabled": false, + "criticalAlarmEnabled": false, + "atcCode": null, + "rxNormCode": null, + "lowStockNotifiedAt": null, + "lowStockNotifiedThresholdDays": null, + "reorderLeadDays": null, + "externalSource": null, + "externalId": null, + "createdAt": "", + "updatedAt": "" + }, + { + "id": "", + "userId": "", + "name": "Record only", + "dose": "10mg", + "treatmentClass": "GENERIC", + "dosesPerUnit": null, + "unitsPerDose": "1", + "active": true, + "notificationsEnabled": true, + "pausedAt": null, + "snoozedUntil": null, + "startsOn": null, + "endsOn": null, + "oneShot": false, + "asNeeded": false, + "trackIntake": false, + "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": "Twice daily", + "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": "07:00", + "windowEnd": "08:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "07:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "08:00", + "windowEnd": "10:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "08:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "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": [ + "09:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + }, + { + "id": "", + "medicationId": "", + "windowStart": "20:00", + "windowEnd": "22:00", + "label": null, + "dose": null, + "unitsPerDose": null, + "daysOfWeek": null, + "timesOfDay": [ + "20:00" + ], + "reminderGraceMinutes": null, + "rrule": "FREQ=DAILY", + "rollingIntervalDays": null, + "scheduleType": "SCHEDULED", + "cyclicOnWeeks": null, + "cyclicOffWeeks": null, + "doseWindows": null + } + ], + "revisions": [], + "pauseEras": [], + "courses": [], + "intakes": [ + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T08:00:00.000Z", + "takenAt": "2026-10-12T08:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-12T09:00:00.000Z", + "takenAt": "2026-10-12T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0004", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T08:00:00.000Z", + "takenAt": "2026-10-13T11:00:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "USER_PIN", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-13T09:00:00.000Z", + "takenAt": "2026-10-13T09:10:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0003", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:00:00.000Z", + "takenAt": "2026-10-14T09:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": "hk-dose-0000", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T09:30:00.000Z", + "takenAt": "2026-10-14T09:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0002", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-14T20:00:00.000Z", + "takenAt": "2026-10-14T20:05:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T08:00:00.000Z", + "takenAt": "2026-10-15T08:30:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "REMINDER", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [ + { + "units": 1, + "itemId": "" + } + ], + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T09:00:00.000Z", + "takenAt": "2026-10-15T09:20:00.000Z", + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "APPLE_HEALTH", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": [], + "externalId": "hk-dose-0001", + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T10:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": "bulk-key-0001", + "createdAt": "", + "injectionSite": "ABDOMEN_LEFT", + "doseTaken": "0.5 pen", + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-15T20:00:00.000Z", + "takenAt": null, + "skipped": true, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "idempotencyKey": null, + "createdAt": "", + "injectionSite": null, + "doseTaken": null, + "inventoryConsumption": null, + "externalId": null, + "updatedAt": "", + "syncVersion": "", + "deletedAt": null + }, + { + "id": "", + "userId": "", + "medicationId": "", + "scheduledFor": "2026-10-16T08:00:00.000Z", + "takenAt": null, + "skipped": false, + "autoMissed": false, + "autoRecorded": false, + "attributionSource": "AUTO", + "source": "API", + "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": "27", + "firstUseAt": "2026-10-15T08:30: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": "auth.bearer.failure", + "userId": "", + "actorUserId": null, + "details": { + "reason": "undeclared_scope", + "tokenId": "" + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 1, + "inserted": 1, + "updated": 0, + "duplicates": 0, + "skipped": 0 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 0, + "updated": 5, + "duplicates": 6, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.ingest", + "userId": "", + "actorUserId": null, + "details": { + "processed": 18, + "inserted": 6, + "updated": 2, + "duplicates": 3, + "skipped": 7 + }, + "ipAddress": null + }, + { + "action": "medications.intake.bulk.validation-failed", + "userId": "", + "actorUserId": null, + "details": { + "issues": [ + { + "path": "entries.0.medicationId", + "code": "too_small" + }, + { + "path": "entries.0.takenAt", + "code": "invalid_format" + } + ] + }, + "ipAddress": null + } + ], + "idempotency": [] + }, + "extra": { + "lastSyncedAt": "", + "arrivals": [ + { + "type": "MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": "background", + "lastNewSampleAt": "", + "lastBackgroundAt": "", + "lastSeenDuplicateAt": "" + }, + { + "type": "backfill:MEDICATION_DOSE", + "lastReceivedAt": "", + "lastTrigger": null, + "lastNewSampleAt": null, + "lastBackgroundAt": null, + "lastSeenDuplicateAt": null + } + ] + } +} diff --git a/tests/integration/routes/parity/medication-intake-bulk.parity.test.ts b/tests/integration/routes/parity/medication-intake-bulk.parity.test.ts new file mode 100644 index 000000000..ec3fc649b --- /dev/null +++ b/tests/integration/routes/parity/medication-intake-bulk.parity.test.ts @@ -0,0 +1,450 @@ +/** + * Parity for `POST /api/medications/intake/bulk` while the batch ingest moves + * into `src/lib/medications/`. + * + * One record walks through the cases the route tells apart, in order, each + * request seeing what the earlier ones stored. A first mixed batch carries + * one entry per per-entry outcome: an unknown medication, a record-only one, + * an unstable idempotency key and an unstable external id, a take inside its + * band, a pinned take and both pin refusals, a skip on a named slot, a + * pending echo onto a recorded dose and one onto a fresh slot, a standalone + * take with a site, a dose override and a key, its replay, a disallowed + * site, an Apple dose and its repeat inside the batch, an Apple dose whose + * slot another dose holds, and a skip that converges onto the standalone + * dose. Then the same batch again, a background and a backfill sync, the + * refusals (too large, a body the schema refuses, an Apple entry on a native + * medication), a native client, a narrow token, a delegate and nobody. + * + * After each request the snapshot holds the response, the wide event, the + * recorded tails, every medication row of the accounts, and the sync + * checkpoint and Apple Health arrival rows the batch writes. 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 { POST } from "@/app/api/medications/intake/bulk/route"; + +import { anonymous, type RouteAuth } from "../../../kit/call-route"; +import { + makeMedication, + makeSession, + makeToken, + 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 tails the route starts without awaiting them (the cross-device push, +// the web-push dose clear with its badge count), 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); + }, + }; + }, +); +vi.mock("@/lib/notifications/web-push-clear", async (importOriginal) => { + const actual = + await importOriginal(); + const { effectRecorder } = await import("../../../kit/parity"); + return { + ...actual, + dispatchMedicationIntakeWebClearBulk: async (...args: unknown[]) => { + effectRecorder.record("dispatchMedicationIntakeWebClearBulk", args); + }, + }; +}); +vi.mock("@/lib/medications/outstanding-doses", async (importOriginal) => { + const actual = + await importOriginal< + typeof import("@/lib/medications/outstanding-doses") + >(); + const { effectRecorder } = await import("../../../kit/parity"); + return { + ...actual, + countOutstandingDosesToday: async (...args: unknown[]) => { + effectRecorder.record("countOutstandingDosesToday", args); + return 2; + }, + }; +}); + +const prisma = getPrismaClient(); +const NOW = new Date("2026-10-15T12:00:00.000Z"); +const ROUTE = "/api/medications/intake/bulk"; +const INVALID_ACTION = "medications.intake.bulk.validation-failed"; + +let ownerId: string; +let userIds: string[]; +let owner: RouteAuth; +let ownerBearer: RouteAuth; +let narrowBearer: RouteAuth; +let writer: { auth: RouteAuth; headers: Record }; +const med: Record = {}; + +type Caller = { auth?: RouteAuth; headers?: Record }; + +/** The sync checkpoint and the Apple Health arrival rows of the owner. */ +async function syncState() { + const [user, arrivals] = await Promise.all([ + prisma.user.findUniqueOrThrow({ + where: { id: ownerId }, + select: { lastSyncedAt: true }, + }), + prisma.healthKitTypeSync.findMany({ + where: { userId: ownerId }, + orderBy: { type: "asc" }, + select: { + type: true, + lastReceivedAt: true, + lastTrigger: true, + lastNewSampleAt: true, + lastBackgroundAt: true, + lastSeenDuplicateAt: true, + }, + }), + ]); + return { lastSyncedAt: user.lastSyncedAt, arrivals }; +} + +/** + * An audit row a refusal writes without awaiting it: the schema refusal's + * own, and the narrow token's `auth.bearer.failure`. + */ +async function auditRows(action: string, count: number): Promise { + // Polled on the real timer: the pinned clock stamps the rows read back, + // and nothing here may move it. + for (let attempt = 0; attempt < 250; attempt += 1) { + const rows = await prisma.auditLog.count({ where: { action } }); + if (rows >= count) return; + await new Promise((resolve) => setTimeout(resolve, 20)); + } + throw new Error(`fewer than ${count} ${action} rows landed`); +} + +async function post( + name: string, + body: unknown, + options: Caller & { settle?: () => Promise } = {}, +) { + await parityStep({ + name: `medication-intake-bulk.${name}`, + handler: POST, + options: { + method: "POST", + route: ROUTE, + body, + auth: options.auth ?? owner, + headers: options.headers, + }, + userIds, + now: NOW, + settle: options.settle, + extra: syncState, + }); +} + +async function intake( + medicationId: string, + data: { + scheduledFor: string; + takenAt?: string; + source?: "REMINDER" | "APPLE_HEALTH"; + externalId?: string; + }, +) { + await prisma.medicationIntakeEvent.create({ + data: { + userId: ownerId, + medicationId, + scheduledFor: new Date(data.scheduledFor), + takenAt: data.takenAt ? new Date(data.takenAt) : null, + source: data.source ?? "REMINDER", + externalId: data.externalId ?? null, + createdAt: new Date("2026-10-01T06:00:00.000Z"), + }, + }); +} + +const daily = (time: string, windowEnd: string) => ({ + windowStart: time, + windowEnd, + timesOfDay: [time], + rrule: "FREQ=DAILY", +}); + +/** One entry per per-entry outcome the loop tells apart. */ +function mixedBatch() { + return { + syncTrigger: "foreground", + entries: [ + { medicationId: med.foreign, takenAt: "2026-10-15T08:10:00.000Z" }, + { medicationId: med.recordOnly, takenAt: "2026-10-15T07:10:00.000Z" }, + { + medicationId: med.daily, + takenAt: "2026-10-15T08:20:00.000Z", + idempotencyKey: "", + }, + { medicationId: med.daily, takenAt: "2026-10-15T08:30:00.000Z" }, + { + medicationId: med.daily, + takenAt: "2026-10-13T11:00:00.000Z", + forceSlotInstant: "2026-10-13T08:00:00.000Z", + }, + { + medicationId: med.daily, + takenAt: "2026-10-13T16:00:00.000Z", + forceSlotInstant: "2026-10-13T15:00:00.000Z", + }, + { + medicationId: med.daily, + takenAt: "2026-10-14T23:00:00.000Z", + forceSlotInstant: "2026-10-14T20:00:00.000Z", + }, + { + medicationId: med.daily, + skipped: true, + scheduledFor: "2026-10-15T20:00:00.000Z", + }, + { medicationId: med.daily, scheduledFor: "2026-10-14T20:00:00.000Z" }, + { medicationId: med.daily, scheduledFor: "2026-10-16T08:00:00.000Z" }, + { + medicationId: med.pen, + takenAt: "2026-10-15T10:00:00.000Z", + injectionSite: "ABDOMEN_LEFT", + doseTaken: "0.5 pen", + idempotencyKey: "bulk-key-0001", + }, + { + medicationId: med.pen, + takenAt: "2026-10-15T10:00:00.000Z", + idempotencyKey: "bulk-key-0001", + }, + { + medicationId: med.pen, + takenAt: "2026-10-15T10:30:00.000Z", + injectionSite: "ABDOMEN_RIGHT", + }, + { + medicationId: med.apple, + takenAt: "2026-10-15T09:20:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0001", + }, + { + medicationId: med.apple, + takenAt: "2026-10-15T09:20:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0001", + }, + { + medicationId: med.apple, + takenAt: "2026-10-14T09:30:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0002", + }, + { + medicationId: med.apple, + takenAt: "2026-10-14T10:00:00.000Z", + source: "APPLE_HEALTH", + externalId: "", + }, + { + medicationId: med.pen, + skipped: true, + scheduledFor: "2026-10-15T10:00:00.000Z", + }, + ], + }; +} + +beforeAll(async () => { + vi.useFakeTimers({ toFake: ["Date"], now: NOW }); + await truncateAllTables(prisma); + const user = await makeUser({ + timezone: "UTC", + globalExcludedInjectionSites: ["ABDOMEN_RIGHT"], + }); + ownerId = user.id; + owner = await makeSession(user); + ownerBearer = await makeToken(user, { name: "kit-phone" }); + narrowBearer = await makeToken(user, { + name: "kit-ingest", + permissions: ["medication:ingest"], + }); + const created = new Date("2026-10-01T06:00:00.000Z"); + + const dailyMed = await makeMedication( + user, + { + name: "Twice daily", + startsOn: new Date("2026-10-01"), + createdAt: created, + snoozedUntil: new Date("2026-10-15T12:30:00.000Z"), + }, + [daily("08:00", "10:00"), daily("20:00", "22:00")], + ); + med.daily = dailyMed.id; + await prisma.medicationInventoryItem.create({ + data: { + userId: ownerId, + medicationId: dailyMed.id, + unitsTotal: 30, + unitsRemaining: 30, + purchasedAt: created, + }, + }); + await intake(dailyMed.id, { scheduledFor: "2026-10-15T08:00:00.000Z" }); + await intake(dailyMed.id, { + scheduledFor: "2026-10-14T20:00:00.000Z", + takenAt: "2026-10-14T20:05:00.000Z", + }); + + med.pen = ( + await makeMedication( + user, + { + name: "As-needed pen", + createdAt: created, + asNeeded: true, + deliveryForm: "INJECTION", + trackInjectionSites: true, + allowedInjectionSites: ["ABDOMEN_LEFT", "ABDOMEN_RIGHT"], + }, + [], + ) + ).id; + + const apple = await makeMedication( + user, + { + name: "Apple mirror", + startsOn: new Date("2026-10-01"), + createdAt: created, + externalSource: "APPLE_HEALTH", + externalId: "hk-concept-0001", + }, + [daily("09:00", "11:00")], + ); + med.apple = apple.id; + await intake(apple.id, { + scheduledFor: "2026-10-14T09:00:00.000Z", + takenAt: "2026-10-14T09:05:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0000", + }); + + med.recordOnly = ( + await makeMedication( + user, + { name: "Record only", createdAt: created, trackIntake: false }, + [daily("07:00", "08:00")], + ) + ).id; + + const stranger = await makeUser({ timezone: "UTC" }); + med.foreign = (await makeMedication(stranger, { name: "Not yours" })).id; + + const w = await delegateOf(prisma, user, "WRITE"); + writer = { auth: w.auth, headers: w.headers }; + userIds = [ownerId, w.delegate.id]; +}); + +afterAll(() => { + vi.useRealTimers(); +}); + +describe("POST /api/medications/intake/bulk parity", () => { + it("01 a mixed first batch", async () => { + await post("01-mixed", mixedBatch()); + }); + + it("02 the same batch again", async () => { + await post("02-mixed-again", mixedBatch()); + }); + + it("03 a background sync and a backfill", async () => { + await post("03a-background", { + syncTrigger: "background", + entries: [ + { + medicationId: med.apple, + takenAt: "2026-10-13T09:10:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0003", + }, + ], + }); + await post("03b-backfill", { + syncTrigger: "backfill", + entries: [ + { + medicationId: med.apple, + takenAt: "2026-10-12T09:10:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0004", + }, + ], + }); + }); + + it("04 the batch refusals", async () => { + await post("04a-too-large", { + entries: Array.from({ length: 501 }, () => ({ + medicationId: med.daily, + })), + }); + await post( + "04b-invalid", + { entries: [{ medicationId: "", takenAt: "never" }] }, + { settle: () => auditRows(INVALID_ACTION, 1) }, + ); + await post("04c-apple-not-mirrored", { + entries: [ + { + medicationId: med.daily, + takenAt: "2026-10-12T08:10:00.000Z", + source: "APPLE_HEALTH", + externalId: "hk-dose-0005", + }, + ], + }); + }); + + it("05 a native client, a narrow token, a delegate and nobody", async () => { + const batch = { + entries: [ + { medicationId: med.daily, takenAt: "2026-10-12T08:10:00.000Z" }, + ], + }; + await post("05a-native", batch, { auth: ownerBearer }); + await post("05b-narrow-token", batch, { + auth: narrowBearer, + settle: () => auditRows("auth.bearer.failure", 1), + }); + await post("05c-delegate", batch, writer); + await post("05d-anonymous", batch, { auth: anonymous }); + }); +});