fix(medications): make import replay results honest

This commit is contained in:
Marc-André Bombeck committed 2026-07-29 16:11:45 +02:00
1 parent 5b695f43ea
commit 271f0ed28a
25 files changed
+607 -27

No files matched your search

@@ -249,11 +249,13 @@ describe("POST /api/medications/[id]/intake/import — durable kickoff", () => {
idempotencyKey: `import-m1-${Date.parse("2026-01-01T07:00:00")}`,
scheduledFor: expect.any(String),
takenAt: expect.any(String),
sourceLine: 1,
},
{
idempotencyKey: `import-m1-${Date.parse("2026-01-01T19:00:00")}`,
scheduledFor: expect.any(String),
takenAt: expect.any(String),
sourceLine: 2,
},
],
},
@@ -261,6 +263,8 @@ describe("POST /api/medications/[id]/intake/import — durable kickoff", () => {
processed: 0,
imported: 0,
skippedByReason: {},
skipDetails: [],
skippedDetailsOmitted: 0,
total: 2,
}),
}),
@@ -175,6 +175,8 @@ export const POST = apiHandler(
total: normalized.entries.length,
imported: 0,
skippedByReason: {},
skipDetails: [],
skippedDetailsOmitted: 0,
touchedDays: [],
rollupProcessed: 0,
};
@@ -154,12 +154,14 @@ describe("POST /api/medications/intake/dose-history-import", () => {
scheduledFor: "2024-12-31T21:30:00.000Z",
takenAt: "2024-12-31T21:50:00.000Z",
idempotencyKey: `import-med-1-${Date.parse("2024-12-31T21:30:00.000Z")}`,
sourceLine: 2,
},
{
medicationId: "med-1",
scheduledFor: "2025-01-01T21:30:00.000Z",
takenAt: "2025-01-01T21:35:00.000Z",
idempotencyKey: `import-med-1-${Date.parse("2025-01-01T21:30:00.000Z")}`,
sourceLine: 3,
// 0.5 against a scheduled 1.0 — a real deviation, so it is kept.
doseTaken: "0.5",
},
@@ -171,6 +173,8 @@ describe("POST /api/medications/intake/dose-history-import", () => {
imported: 0,
// Seeded, so the count at the end of the run covers the whole file.
skippedByReason: { status_no_dose_information: 1 },
skipDetails: [{ line: 4, reason: "status_no_dose_information" }],
skippedDetailsOmitted: 0,
touchedDays: [],
rollupProcessed: 0,
},
@@ -183,6 +183,8 @@ export const POST = apiHandler(async (request: NextRequest) => {
total: plan.entries.length,
imported: 0,
skippedByReason: plan.skippedByReason,
skipDetails: plan.skipDetails,
skippedDetailsOmitted: plan.skippedDetailsOmitted,
touchedDays: [],
rollupProcessed: 0,
};