Skip to content

Commit bb5d920

Browse files
scriptcodedclaude
andcommitted
staff-dietary: add child form diet schema + consent gates
The child form (43854) had dietary questions enabled after the initial build, with its own question IDs — the code wrongly assumed it reused the staff form's IDs, so children surfaced no dietary info. Add a dedicated CHILD_DIET schema (discovered from the live questions endpoint) and route children to it. Both the staff (43853) and child forms now also carry a kost-consent question, so gate diet on consent for all three populations (staff 90431, child 90437, leader-staff 90424), matching the existing leader-staff behaviour — dietary info is hidden unless consent is given. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 78ba775 commit bb5d920

3 files changed

Lines changed: 62 additions & 8 deletions

File tree

CLAUDE.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ Project API — **owns no data, has no database.**
5757
- `presence.ts` — staff/child period model: `presentDays = ⋃(selected-period
5858
days) − ⋃(absence days of checked periods)`; **child `91058` is positive**
5959
(attend-days, not absence); leader-staff fixed **25 Jul–1 Aug**.
60-
- `diet.ts` — allergens/prefs unified by Swedish label across the two form
61-
schemas; section gates; consent `90424` gates diet **only for leader-staff**
62-
(staff/child forms have no consent question).
60+
- `diet.ts` — allergens/prefs unified by Swedish label across **three** form
61+
schemas (`STAFF_DIET` 43853, `CHILD_DIET` 43854, `PARTICIPANT_DIET` 43844 —
62+
each has its own question IDs); section gates; consent gates diet for **all
63+
three** populations — staff `90431`, child `90437`, leader-staff `90424`
64+
(diet hidden unless consent is "1").
6365
- `core.ts` — server-only orchestration (`runStaffDietaryReport`): fetch →
6466
classify → dedupe → presence+diet → filter → aggregates. **Not** a server fn,
6567
so both `report.ts` and `export.ts` reuse it.

src/reports/staff-dietary/constants.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ export interface DietSchema {
201201
consent?: string;
202202
}
203203

204-
/** Staff form 43853 — also used by children (form 43854 reuses these IDs). */
204+
/**
205+
* Staff form 43853. Children answer a *different* form (43854) with its own IDs
206+
* — see CHILD_DIET; do not reuse this schema for them. Consent (90431) gates
207+
* diet, same as the child and leader-staff forms.
208+
*/
205209
export const STAFF_DIET: DietSchema = {
206210
allergens: {
207211
"88271": "Fisk",
@@ -229,7 +233,43 @@ export const STAFF_DIET: DietSchema = {
229233
allergenGate: "88258",
230234
preferenceGate: "89331",
231235
freeText: "88286",
232-
// No consent question on the staff/child forms.
236+
consent: "90431",
237+
};
238+
239+
/**
240+
* Child form 43854 — its own dietary question IDs, distinct from the staff
241+
* form. Dietary info was enabled on this form after the initial build, so these
242+
* were discovered from the live form def (questions endpoint, form_id=43854).
243+
* The consent question (90437) gates diet, mirroring the leader-staff form.
244+
*/
245+
export const CHILD_DIET: DietSchema = {
246+
allergens: {
247+
"88331": "Fisk",
248+
"88264": "Ägg",
249+
"88262": "Laktos",
250+
"88261": "Mjölkprotein",
251+
"88288": "Soja",
252+
"88313": "Blötdjur",
253+
"88338": "Gluten",
254+
"88330": "Kräftdjur",
255+
"89346": "Nötter",
256+
"89347": "Sesam",
257+
"89348": "Selleri",
258+
"89349": "Senap",
259+
"89350": "Sulfit",
260+
},
261+
preferences: {
262+
"89351": "Äter ej nötkött",
263+
"89352": "Äter ej fläskkött",
264+
"89353": "Halal",
265+
"89354": "Vegan",
266+
"89355": "Lakto-ovo-vegetarian",
267+
"89356": "Pescetarian",
268+
},
269+
allergenGate: "88267",
270+
preferenceGate: "89345",
271+
freeText: "88270",
272+
consent: "90437",
233273
};
234274

235275
/** Participants form 43844 — used by leader-staff. */

src/reports/staff-dietary/diet.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { type DietSchema, PARTICIPANT_DIET, STAFF_DIET } from "./constants";
1+
import {
2+
CHILD_DIET,
3+
type DietSchema,
4+
PARTICIPANT_DIET,
5+
STAFF_DIET,
6+
} from "./constants";
27
import type { ClassifiedPerson } from "./populations";
38
import { asBool, asText, type QuestionMap } from "./values";
49

@@ -13,9 +18,16 @@ export interface DietInfo {
1318
other: string;
1419
}
1520

16-
/** staff + child answer the staff form; leader-staff answer the participant form. */
21+
/** Each population answers its own form: staff 43853, child 43854, leader 43844. */
1722
function schemaFor(person: ClassifiedPerson): DietSchema {
18-
return person.population === "leader-staff" ? PARTICIPANT_DIET : STAFF_DIET;
23+
switch (person.population) {
24+
case "leader-staff":
25+
return PARTICIPANT_DIET;
26+
case "child":
27+
return CHILD_DIET;
28+
default:
29+
return STAFF_DIET;
30+
}
1931
}
2032

2133
export function computeDiet(person: ClassifiedPerson): DietInfo {

0 commit comments

Comments
 (0)