From 604e168e0a15d89917f64de3ec68064ed6ada639 Mon Sep 17 00:00:00 2001 From: David Roper Date: Wed, 20 May 2026 12:12:05 -0400 Subject: [PATCH 1/6] use negative scaling to correct order of options, negate question ranges and adjust totalscore calc --- .../index.ts" | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" index ab20277..dd3f900 100644 --- "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" +++ "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" @@ -4,12 +4,12 @@ import { z } from '/runtime/v1/zod@3.x'; const yesNoOptions = { en: { - 1: 'Yes', - 0: 'No' + '-1': 'Yes', + '0': 'No' }, fr: { - 1: 'Oui', - 0: 'Non' + '-1': 'Oui', + '0': 'Non' } }; @@ -51,16 +51,16 @@ export default defineInstrument({ }, options: { en: { - 3: 'Within 5 minutes', - 2: '6-30 minutes', - 1: '31-60 minutes', - 0: 'More than 60 minutes' + '-3': 'Within 5 minutes', + '-2': '6-30 minutes', + '-1': '31-60 minutes', + '0': 'More than 60 minutes' }, fr: { - 3: 'Dans les 5 minutes', - 2: '6 à 30 minutes', - 1: '31 à 60 minutes ', - 0: 'Plus de 60 minutes' + '-3': 'Dans les 5 minutes', + '-2': '6 à 30 minutes', + '-1': '31 à 60 minutes ', + '0': 'Plus de 60 minutes' } }, variant: 'radio' @@ -84,12 +84,12 @@ export default defineInstrument({ }, options: { en: { - 1: 'The first in the morning', - 0: 'Any other' + '-1': 'The first in the morning', + '0': 'Any other' }, fr: { - 1: 'La première du matin', - 0: 'À une autre' + '-1': 'La première du matin', + '0': 'À une autre' } }, variant: 'radio' @@ -98,21 +98,21 @@ export default defineInstrument({ disableAutoPrefix: true, kind: 'number', label: { - en: '4. How many cigarettes a do you smoke?', + en: '4. How many cigarettes a do you smoke per day?', fr: '4. Combien de cigarettes fumez-vous par jour?' }, options: { en: { - 0: '10 or less', - 1: '11 - 20', - 2: '21 - 30', - 3: '31 or more' + '0': '10 or less', + '1': '11 - 20', + '2': '21 - 30', + '3': '31 or more' }, fr: { - 0: '10 ou moins', - 1: '11 à 20', - 2: '21 à 30', - 3: '31 ou plus 3' + '0': '10 ou moins', + '1': '11 à 20', + '2': '21 à 30', + '3': '31 ou plus 3' } }, variant: 'radio' @@ -146,16 +146,17 @@ export default defineInstrument({ fr: 'Score total:' }, value: (data) => { - return sum(Object.values(data)); + const { cigaretteAmount, ...rest } = data; + return sum(Object.values(rest).map((v) => v * -1)) + (cigaretteAmount ?? 0); } } }, validationSchema: z.object({ - smokeTime: z.number().int().min(0).max(3), - difficultToRefrainSmoking: z.number().int().min(0).max(1), - cigaretteHateToGiveup: z.number().int().min(0).max(1), + smokeTime: z.number().int().min(-3).max(0), + difficultToRefrainSmoking: z.number().int().min(-1).max(0), + cigaretteHateToGiveup: z.number().int().min(-1).max(0), cigaretteAmount: z.number().int().min(0).max(3), - smokeMoreInMorning: z.number().int().min(0).max(1), - smokeWhileSickInBed: z.number().int().min(0).max(1) + smokeMoreInMorning: z.number().int().min(-1).max(0), + smokeWhileSickInBed: z.number().int().min(-1).max(0) }) }); From 79f6fcaf47943d2b535990941cce7a3e94c5a6bd Mon Sep 17 00:00:00 2001 From: David Roper Date: Thu, 4 Jun 2026 17:11:13 -0400 Subject: [PATCH 2/6] use a more simpler absolute function for the audit c score --- "lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" index dd3f900..256dea2 100644 --- "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" +++ "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" @@ -145,10 +145,7 @@ export default defineInstrument({ en: 'Total Score:', fr: 'Score total:' }, - value: (data) => { - const { cigaretteAmount, ...rest } = data; - return sum(Object.values(rest).map((v) => v * -1)) + (cigaretteAmount ?? 0); - } + value: (data) => sum(Object.values(data).map((v) => Math.abs(v ?? 0))) } }, validationSchema: z.object({ From 4e4154140069aa11be655a3790fa4add563197ad Mon Sep 17 00:00:00 2001 From: David Roper Date: Thu, 4 Jun 2026 17:17:32 -0400 Subject: [PATCH 3/6] add more typo fixes --- "lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" index 256dea2..a951c7a 100644 --- "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" +++ "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" @@ -59,7 +59,7 @@ export default defineInstrument({ fr: { '-3': 'Dans les 5 minutes', '-2': '6 à 30 minutes', - '-1': '31 à 60 minutes ', + '-1': '31 à 60 minutes', '0': 'Plus de 60 minutes' } }, @@ -98,7 +98,7 @@ export default defineInstrument({ disableAutoPrefix: true, kind: 'number', label: { - en: '4. How many cigarettes a do you smoke per day?', + en: '4. How many cigarettes do you smoke per day?', fr: '4. Combien de cigarettes fumez-vous par jour?' }, options: { @@ -112,7 +112,7 @@ export default defineInstrument({ '0': '10 ou moins', '1': '11 à 20', '2': '21 à 30', - '3': '31 ou plus 3' + '3': '31 ou plus' } }, variant: 'radio' From e331242f2d6e18aa825eb41f923cabc773a71811 Mon Sep 17 00:00:00 2001 From: David Roper Date: Thu, 4 Jun 2026 17:19:32 -0400 Subject: [PATCH 4/6] fix score name --- "lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" index a951c7a..e6d43a5 100644 --- "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" +++ "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" @@ -139,7 +139,7 @@ export default defineInstrument({ } }, measures: { - auditCScore: { + nicotineDependenceScore: { kind: 'computed', label: { en: 'Total Score:', From 27f58990ea9127bd585e19a7ee6e0c8296d1ef4e Mon Sep 17 00:00:00 2001 From: David Roper Date: Tue, 7 Jul 2026 11:32:19 -0400 Subject: [PATCH 5/6] make form question revealed if subject smokes --- .../index.ts" | 90 ++++++++++++++----- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" index e6d43a5..ab734bb 100644 --- "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" +++ "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" @@ -13,6 +13,19 @@ const yesNoOptions = { } }; +function createDependentField(field: T) { + return { + kind: 'dynamic' as const, + deps: ['smokes'] as const, + render: (data: { smokes?: unknown }) => { + if (data.smokes === true) { + return field; + } + return null; + } + }; +} + export default defineInstrument({ kind: 'FORM', language: ['en', 'fr'], @@ -42,7 +55,25 @@ export default defineInstrument({ }, content: { - smokeTime: { + smokes: { + kind: 'boolean', + label: { + en: 'Do you smoke?', + fr: 'Fumez-vous?' + }, + options: { + en: { + true: 'Yes', + false: 'No' + }, + fr: { + true: 'Oui', + false: 'Non' + } + }, + variant: 'radio' + }, + smokeTime: createDependentField({ disableAutoPrefix: true, kind: 'number', label: { @@ -64,8 +95,8 @@ export default defineInstrument({ } }, variant: 'radio' - }, - difficultToRefrainSmoking: { + }), + difficultToRefrainSmoking: createDependentField({ disableAutoPrefix: true, kind: 'number', label: { @@ -74,8 +105,8 @@ export default defineInstrument({ }, options: yesNoOptions, variant: 'radio' - }, - cigaretteHateToGiveup: { + }), + cigaretteHateToGiveup: createDependentField({ disableAutoPrefix: true, kind: 'number', label: { @@ -93,8 +124,8 @@ export default defineInstrument({ } }, variant: 'radio' - }, - cigaretteAmount: { + }), + cigaretteAmount: createDependentField({ disableAutoPrefix: true, kind: 'number', label: { @@ -116,8 +147,8 @@ export default defineInstrument({ } }, variant: 'radio' - }, - smokeMoreInMorning: { + }), + smokeMoreInMorning: createDependentField({ disableAutoPrefix: true, kind: 'number', label: { @@ -126,8 +157,8 @@ export default defineInstrument({ }, options: yesNoOptions, variant: 'radio' - }, - smokeWhileSickInBed: { + }), + smokeWhileSickInBed: createDependentField({ disableAutoPrefix: true, kind: 'number', label: { @@ -136,7 +167,7 @@ export default defineInstrument({ }, options: yesNoOptions, variant: 'radio' - } + }) }, measures: { nicotineDependenceScore: { @@ -145,15 +176,32 @@ export default defineInstrument({ en: 'Total Score:', fr: 'Score total:' }, - value: (data) => sum(Object.values(data).map((v) => Math.abs(v ?? 0))) + value: (data) => { + if (!data.smokes) { + return 0; + } + return sum( + Object.values(data) + .filter((v): v is number => typeof v === 'number') + .map((v) => Math.abs(v)) + ); + } } }, - validationSchema: z.object({ - smokeTime: z.number().int().min(-3).max(0), - difficultToRefrainSmoking: z.number().int().min(-1).max(0), - cigaretteHateToGiveup: z.number().int().min(-1).max(0), - cigaretteAmount: z.number().int().min(0).max(3), - smokeMoreInMorning: z.number().int().min(-1).max(0), - smokeWhileSickInBed: z.number().int().min(-1).max(0) - }) + validationSchema: z + .object({ + smokes: z.boolean(), + smokeTime: z.number().int().min(-3).max(0).optional(), + difficultToRefrainSmoking: z.number().int().min(-1).max(0).optional(), + cigaretteHateToGiveup: z.number().int().min(-1).max(0).optional(), + cigaretteAmount: z.number().int().min(0).max(3).optional(), + smokeMoreInMorning: z.number().int().min(-1).max(0).optional(), + smokeWhileSickInBed: z.number().int().min(-1).max(0).optional() + }) + .refine(({ smokes, ...data }) => { + if (!smokes) { + return true; + } + return Object.values(data).length === 6 && Object.values(data).every((arg) => typeof arg === 'number'); + }, 'Error: Please fill out all the questions / Erreur: Veuillez répondre à toutes les questions') }); From c2b8bcee9b3320a5b1d8d89e0f2e47702599f608 Mon Sep 17 00:00:00 2001 From: David Roper Date: Tue, 14 Jul 2026 13:27:41 -0400 Subject: [PATCH 6/6] increment edition --- "lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" index ab734bb..78f71f2 100644 --- "a/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" +++ "b/lib/forms/FAGERSTR\303\226M_NICOTINE_DEPENDENCE/index.ts" @@ -31,7 +31,7 @@ export default defineInstrument({ language: ['en', 'fr'], internal: { name: 'FAGERSTRÖM_NICOTINE_DEPENDENCE', - edition: 1 + edition: 2 }, tags: { en: ['smoking', 'addiction', 'nicotine'],