mirror of
https://github.com/temetro/temetro.git
synced 2026-08-12 19:46:53 +00:00
f0fe501d62
Add optional startDate/endDate columns to prescriptions (schema, validation, types, service) — when set, endDate drives expiry. Add a new append-only `dispenses` resource (schema, types, validation, service, route at /api/dispenses) recording who received which medication, gated on the existing inventory RBAC statement. Migration 0020. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const nonEmpty = z.string().trim().min(1);
|
|
|
|
// Payload accepted by POST/PUT /api/prescriptions. The frontend dialog omits
|
|
// prescriber / prescribedAt / status on create — the route fills the prescriber
|
|
// from the signed-in user, the DB defaults prescribedAt to today, and status
|
|
// defaults to "active".
|
|
export const prescriptionInputSchema = z.object({
|
|
fileNumber: z.string().trim().default(""),
|
|
name: nonEmpty.max(200),
|
|
initials: z.string().trim().min(1).max(4),
|
|
medication: nonEmpty.max(200),
|
|
dose: z.string().trim().max(120).default(""),
|
|
frequency: nonEmpty.max(120),
|
|
prescriber: z.string().trim().max(200).default(""),
|
|
prescribedAt: z
|
|
.string()
|
|
.regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be YYYY-MM-DD.")
|
|
.optional(),
|
|
startDate: z
|
|
.string()
|
|
.regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be YYYY-MM-DD.")
|
|
.nullish(),
|
|
endDate: z
|
|
.string()
|
|
.regex(/^\d{4}-\d{2}-\d{2}$/, "Date must be YYYY-MM-DD.")
|
|
.nullish(),
|
|
status: z.enum(["active", "completed", "expired"]).default("active"),
|
|
duration: z.string().trim().max(120).nullish(),
|
|
notes: z.string().max(5000).nullish(),
|
|
source: z.enum(["manual", "ai"]).default("manual"),
|
|
});
|
|
|
|
export type PrescriptionInput = z.infer<typeof prescriptionInputSchema>;
|