mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
feat(medications): carry manufacturer and printed strength on an inventory container
The native pen list renders these two as its headline and subhead. The server held neither, so a container registered on the web could not be shown there without fabricating an empty card, and the client kept its own copy locally with no back-fill possible. Both columns are additive and nullable (migration 0255). Every existing row is truthfully NULL — the values were never collected, and a plain supply row such as a blister pack or a bottle has no use for either. Strength stays free text rather than a parsed number + unit: pens state it per dose, per ml, or per cartridge depending on the product, and forcing a numeric split would lose which of the three was printed. On PATCH an omitted field leaves the stored value untouched, the same rule notes already followed, so a client that does not know the fields cannot blank what another populated; an explicit null still clears. The web add-container form collects both for a PEN, so the columns do not ship empty forever.
This commit is contained in:
1 parent
4ddc08f784
commit
4c3cc84daf
18 files changed
+391
-28
No files matched your search
@@ -80,6 +80,8 @@ describe("buildCreateInventoryInput", () => {
|
||||
containerType: "PEN",
|
||||
printedExpiry: printed,
|
||||
purchasedAt: null,
|
||||
manufacturer: null,
|
||||
doseStrength: null,
|
||||
notes: null,
|
||||
});
|
||||
expect(input).toMatchObject({
|
||||
@@ -100,6 +102,8 @@ describe("buildCreateInventoryInput", () => {
|
||||
containerType: "OTHER",
|
||||
printedExpiry: null,
|
||||
purchasedAt: null,
|
||||
manufacturer: null,
|
||||
doseStrength: null,
|
||||
notes: null,
|
||||
});
|
||||
expect(input.expiresAt).toBeNull();
|
||||
@@ -157,3 +161,40 @@ describe("serializeInventoryItem (iOS#31)", () => {
|
||||
expect(out).toMatchObject({ id: "i5", state: "ACTIVE" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildCreateInventoryInput — carton labelling", () => {
|
||||
it("carries manufacturer + doseStrength onto the create input", () => {
|
||||
// The native pen list renders these as its headline and subhead; a
|
||||
// container created on the web carried neither, so the row could not be
|
||||
// shown there without fabricating an empty card.
|
||||
const input = buildCreateInventoryInput({
|
||||
userId: "u",
|
||||
medicationId: "m",
|
||||
unitsTotal: 4,
|
||||
containerType: "PEN",
|
||||
printedExpiry: null,
|
||||
purchasedAt: null,
|
||||
manufacturer: "Example Pharma",
|
||||
doseStrength: "5 mg/0.5 ml",
|
||||
notes: null,
|
||||
});
|
||||
expect(input.manufacturer).toBe("Example Pharma");
|
||||
expect(input.doseStrength).toBe("5 mg/0.5 ml");
|
||||
});
|
||||
|
||||
it("leaves both null for a plain supply container", () => {
|
||||
const input = buildCreateInventoryInput({
|
||||
userId: "u",
|
||||
medicationId: "m",
|
||||
unitsTotal: 30,
|
||||
containerType: "BLISTER",
|
||||
printedExpiry: null,
|
||||
purchasedAt: null,
|
||||
manufacturer: null,
|
||||
doseStrength: null,
|
||||
notes: null,
|
||||
});
|
||||
expect(input.manufacturer).toBeNull();
|
||||
expect(input.doseStrength).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -144,6 +144,8 @@ export function buildCreateInventoryInput(input: {
|
||||
containerType: MedicationContainerType;
|
||||
printedExpiry: Date | null;
|
||||
purchasedAt: Date | null;
|
||||
manufacturer: string | null;
|
||||
doseStrength: string | null;
|
||||
notes: string | null;
|
||||
}) {
|
||||
return {
|
||||
@@ -157,6 +159,8 @@ export function buildCreateInventoryInput(input: {
|
||||
printedExpiry: input.printedExpiry,
|
||||
purchasedAt: input.purchasedAt,
|
||||
expiresAt: computeExpiresAt(null, input.printedExpiry),
|
||||
manufacturer: input.manufacturer,
|
||||
doseStrength: input.doseStrength,
|
||||
// Encrypt the free-text note at rest; the plaintext column stays null.
|
||||
notesEncrypted: encryptNote(input.notes),
|
||||
notes: null,
|
||||
|
||||
@@ -314,6 +314,18 @@ export const medicationInventoryItemResource = z
|
||||
),
|
||||
printedExpiry: z.iso.datetime({ offset: true }).nullable(),
|
||||
purchasedAt: z.iso.datetime({ offset: true }).nullable(),
|
||||
manufacturer: z
|
||||
.string()
|
||||
.nullable()
|
||||
.describe(
|
||||
"Marketing-authorisation holder / maker as printed on the carton. NULL for a container registered before the field existed, and for plain supply rows that never carried one.",
|
||||
),
|
||||
doseStrength: z
|
||||
.string()
|
||||
.nullable()
|
||||
.describe(
|
||||
'Strength as printed on the container, e.g. "5 mg/0.5 ml". Free text, not split into a number + unit — pens state strength per dose, per ml, or per cartridge. NULL when unknown.',
|
||||
),
|
||||
notes: z.string().nullable(),
|
||||
createdAt: z.iso.datetime({ offset: true }),
|
||||
updatedAt: z.iso.datetime({ offset: true }),
|
||||
|
||||
@@ -54,6 +54,24 @@ export const createInventoryItemSchema = z
|
||||
.transform((s) => new Date(s))
|
||||
.nullable()
|
||||
.optional(),
|
||||
/** Carton labelling — free text, see the schema comment on the model
|
||||
* for why neither is parsed into a structured value. */
|
||||
manufacturer: z
|
||||
.string()
|
||||
.max(120)
|
||||
.nullable()
|
||||
.optional()
|
||||
.describe(
|
||||
"Marketing-authorisation holder / maker as printed on the carton. Free text, max 120 chars.",
|
||||
),
|
||||
doseStrength: z
|
||||
.string()
|
||||
.max(60)
|
||||
.nullable()
|
||||
.optional()
|
||||
.describe(
|
||||
'Strength as printed on the container, e.g. "5 mg/0.5 ml". Free text, max 60 chars — deliberately not split into a number + unit because pens state strength per dose, per ml, or per cartridge.',
|
||||
),
|
||||
notes: z.string().max(200).nullable().optional(),
|
||||
})
|
||||
.meta({
|
||||
@@ -99,6 +117,24 @@ export const updateInventoryItemSchema = z
|
||||
.describe(
|
||||
"Absolute remaining-unit correction (0–1000, fractional allowed). Clamped server-side to the item's `unitsTotal`; the canonical state machine re-derives the state (0 ⇒ USED_UP).",
|
||||
),
|
||||
/** Carton labelling — free text, see the schema comment on the model
|
||||
* for why neither is parsed into a structured value. */
|
||||
manufacturer: z
|
||||
.string()
|
||||
.max(120)
|
||||
.nullable()
|
||||
.optional()
|
||||
.describe(
|
||||
"Marketing-authorisation holder / maker as printed on the carton. Free text, max 120 chars.",
|
||||
),
|
||||
doseStrength: z
|
||||
.string()
|
||||
.max(60)
|
||||
.nullable()
|
||||
.optional()
|
||||
.describe(
|
||||
'Strength as printed on the container, e.g. "5 mg/0.5 ml". Free text, max 60 chars — deliberately not split into a number + unit because pens state strength per dose, per ml, or per cartridge.',
|
||||
),
|
||||
notes: z.string().max(200).nullable().optional(),
|
||||
})
|
||||
.meta({
|
||||
|
||||
Reference in new issue
Block a user