|
| 1 | +import { defineInstrument } from '/runtime/v1/@opendatacapture/runtime-core'; |
| 2 | +import { z } from '/runtime/v1/zod@3.23.x'; |
| 3 | + |
| 4 | +const $NumberRange = z.number().int().min(0).max(4); |
| 5 | + |
| 6 | +const $InstrumentData = z |
| 7 | + .object({ |
| 8 | + isCannabisUsed: z.boolean(), |
| 9 | + cannabisFrequency: $NumberRange.optional(), |
| 10 | + stonedTime: $NumberRange.optional(), |
| 11 | + unableToStopUsage: $NumberRange.optional(), |
| 12 | + cannabisInducedFailure: $NumberRange.optional(), |
| 13 | + cannabisRelatedUsageTime: $NumberRange.optional(), |
| 14 | + cannabisMemoryConcentration: $NumberRange.optional(), |
| 15 | + cannabisHazards: $NumberRange.optional(), |
| 16 | + cannabisReduction: $NumberRange.optional() |
| 17 | + }) |
| 18 | + .refine(({ isCannabisUsed, ...data }) => { |
| 19 | + if (!isCannabisUsed) { |
| 20 | + return true; |
| 21 | + } |
| 22 | + // in case in the future you can deselect options |
| 23 | + return Object.values(data).length === 8 && Object.values(data).every((arg) => typeof arg === 'number'); |
| 24 | + }, 'Error: Please fill out all the questions / Erreur: Veuillez répondre à toutes les questions'); |
| 25 | + |
| 26 | +function createDependentField<const T>(field: T) { |
| 27 | + return { |
| 28 | + kind: 'dynamic' as const, |
| 29 | + deps: ['isCannabisUsed'] as const, |
| 30 | + render: (data: { isCannabisUsed?: unknown }) => { |
| 31 | + if (data.isCannabisUsed === true) { |
| 32 | + return field; |
| 33 | + } |
| 34 | + return null; |
| 35 | + } |
| 36 | + }; |
| 37 | +} |
| 38 | + |
| 39 | +const calculateCannabisUse = (data: { [key: string]: unknown }) => { |
| 40 | + let sum = 0; |
| 41 | + for (const key in data) { |
| 42 | + const value = data[key as keyof typeof data]; |
| 43 | + if (typeof value === 'number') { |
| 44 | + sum += value; |
| 45 | + } |
| 46 | + } |
| 47 | + return sum; |
| 48 | +}; |
| 49 | + |
| 50 | +export default defineInstrument({ |
| 51 | + kind: 'FORM', |
| 52 | + language: ['en', 'fr'], |
| 53 | + tags: { |
| 54 | + en: ['Cannabis', 'Addiction', 'Substance Abuse'], |
| 55 | + fr: ['Cannabis', 'Dépendance', 'Abus de substance'] |
| 56 | + }, |
| 57 | + internal: { |
| 58 | + edition: 1, |
| 59 | + name: 'CUDIT_R' |
| 60 | + }, |
| 61 | + clientDetails: { |
| 62 | + estimatedDuration: 10, |
| 63 | + instructions: { |
| 64 | + en: ['Please fill out answer that best describe your cannabis usage.'], |
| 65 | + fr: ['Veuillez remplir les réponses qui décrivent le mieux votre consommation de cannabis'] |
| 66 | + }, |
| 67 | + title: { |
| 68 | + en: 'Cannabis Use Disorder Identification Test - Revised (CUDIT-R)', |
| 69 | + fr: 'Teste de consommation du Cannabis (CUDIT-R)' |
| 70 | + } |
| 71 | + }, |
| 72 | + details: { |
| 73 | + description: { |
| 74 | + en: 'The CUDIT-R is an 8-item screening tool used to assess problematic cannabis use and identify individuals at risk of Cannabis Use Disorder (CUD). A score of 8 or higher suggests hazardous use, warranting further assessment or intervention.', |
| 75 | + fr: 'Le CUDIT-R est un outil de dépistage en 8 points utilisé pour évaluer la consommation problématique de cannabis et identifier les personnes présentant un risque de trouble lié à la consommation de cannabis (TCC). Un score de 8 ou plus indique une consommation dangereuse, justifiant une évaluation ou une intervention plus poussée.' |
| 76 | + }, |
| 77 | + license: 'PUBLIC-DOMAIN', |
| 78 | + title: { |
| 79 | + en: 'Cannabis Use Disorder Identification Test - Revised (CUDIT-R)', |
| 80 | + fr: "Test d'identification des troubles liés à l'usage du cannabis - version révisée (CUDIT-R)" |
| 81 | + } |
| 82 | + }, |
| 83 | + content: { |
| 84 | + isCannabisUsed: { |
| 85 | + kind: 'boolean', |
| 86 | + label: { |
| 87 | + en: 'Have you used any cannabis over the past six months?', |
| 88 | + fr: 'Avez-vous consommé du cannabis au cours des 6 derniers mois?' |
| 89 | + }, |
| 90 | + options: { |
| 91 | + en: { |
| 92 | + true: 'Yes', |
| 93 | + false: 'No' |
| 94 | + }, |
| 95 | + fr: { |
| 96 | + true: 'Oui', |
| 97 | + false: 'Non' |
| 98 | + } |
| 99 | + }, |
| 100 | + variant: 'radio' |
| 101 | + }, |
| 102 | + cannabisFrequency: createDependentField({ |
| 103 | + kind: 'number', |
| 104 | + label: { |
| 105 | + en: '1. How often do you use Cannabis?', |
| 106 | + fr: '1. A quelle fréquence tu consomme du Cannabis?' |
| 107 | + }, |
| 108 | + options: { |
| 109 | + en: { |
| 110 | + 0: 'Never', |
| 111 | + 1: 'Monthly or less', |
| 112 | + 2: '2-4 times a month', |
| 113 | + 3: '2-3 times a week', |
| 114 | + 4: '4 or more times a week' |
| 115 | + }, |
| 116 | + fr: { |
| 117 | + 0: 'Jamais', |
| 118 | + 1: '≤ 1 fois/mois', |
| 119 | + 2: '2 à 4 fois/mois', |
| 120 | + 3: '2 à 3 fois/semaine', |
| 121 | + 4: 'Plus que 4 fois/semaine' |
| 122 | + } |
| 123 | + }, |
| 124 | + variant: 'radio' |
| 125 | + }), |
| 126 | + stonedTime: createDependentField({ |
| 127 | + kind: 'number', |
| 128 | + label: { |
| 129 | + en: '2. How many hours were you "stoned" on a typical day when you were using cannabis?', |
| 130 | + fr: "2. Combien d'heures êtes-vous « défoncé » un jour typique où vous consommez du cannabis??" |
| 131 | + }, |
| 132 | + options: { |
| 133 | + en: { |
| 134 | + 0: 'Less than 1', |
| 135 | + 1: '1 or 2', |
| 136 | + 2: '3 or 4', |
| 137 | + 3: '5 or 6', |
| 138 | + 4: '7 or more' |
| 139 | + }, |
| 140 | + fr: { |
| 141 | + 0: 'Moins de 1h', |
| 142 | + 1: '1 ou 2h', |
| 143 | + 2: '3 ou 4h', |
| 144 | + 3: '5 ou 6h', |
| 145 | + 4: '7h ou plus' |
| 146 | + } |
| 147 | + }, |
| 148 | + variant: 'radio' |
| 149 | + }), |
| 150 | + unableToStopUsage: createDependentField({ |
| 151 | + kind: 'number', |
| 152 | + label: { |
| 153 | + en: '3. How often during the past 6 months did you find that you were not able to stop using cannabis once you had started?', |
| 154 | + fr: "3. Au cours des 6 derniers mois, à quelle fréquence avez-vous constaté que vous n'étiez plus capable de vous arrêter de fumer du cannabis une fois que vous aviez commencé?" |
| 155 | + }, |
| 156 | + options: { |
| 157 | + en: { |
| 158 | + 0: 'Never', |
| 159 | + 1: 'Less than monthly', |
| 160 | + 2: 'Monthly', |
| 161 | + 3: 'Weekly', |
| 162 | + 4: 'Daily or almost daily' |
| 163 | + }, |
| 164 | + fr: { |
| 165 | + 0: 'Jamais', |
| 166 | + 1: 'Moins que 1 fois/mois', |
| 167 | + 2: '2 à 4 fois/mois', |
| 168 | + 3: '2 à 3 fois/semaine', |
| 169 | + 4: 'Plus que 4 fois/semaine' |
| 170 | + } |
| 171 | + }, |
| 172 | + variant: 'radio' |
| 173 | + }), |
| 174 | + cannabisInducedFailure: createDependentField({ |
| 175 | + kind: 'number', |
| 176 | + label: { |
| 177 | + en: '4. How often during the past 6 months did you fail to do what was normally expected from you because of using cannabis?', |
| 178 | + fr: '4. Au cours des 6 derniers mois, combien de fois votre consommation de cannabis vous a-t-elle empêché de faire ce qui était normalement attendu de vous?' |
| 179 | + }, |
| 180 | + options: { |
| 181 | + en: { |
| 182 | + 0: 'Never', |
| 183 | + 1: 'Less than monthly', |
| 184 | + 2: 'Monthly', |
| 185 | + 3: 'Weekly', |
| 186 | + 4: 'Daily or almost daily' |
| 187 | + }, |
| 188 | + fr: { |
| 189 | + 0: 'Jamais', |
| 190 | + 1: 'Moins que 1 fois/mois', |
| 191 | + 2: '2 à 4 fois/mois', |
| 192 | + 3: '2 à 3 fois/semaine', |
| 193 | + 4: 'Plus que 4 fois/semaine' |
| 194 | + } |
| 195 | + }, |
| 196 | + variant: 'radio' |
| 197 | + }), |
| 198 | + cannabisRelatedUsageTime: createDependentField({ |
| 199 | + kind: 'number', |
| 200 | + label: { |
| 201 | + en: '5. How often in the past 6 months have you devoted a great deal of your time to getting, using, or recovering from cannabis?', |
| 202 | + fr: '5. Au cours des 6 derniers mois, combien de fois avez-vous passé une grande partie de votre temps à chercher à vous procurer ou consommer du cannabis, ou à vous remettre des effets du cannabis ?' |
| 203 | + }, |
| 204 | + options: { |
| 205 | + en: { |
| 206 | + 0: 'Never', |
| 207 | + 1: 'Less than monthly', |
| 208 | + 2: 'Monthly', |
| 209 | + 3: 'Weekly', |
| 210 | + 4: 'Daily or almost daily' |
| 211 | + }, |
| 212 | + fr: { |
| 213 | + 0: 'Jamais', |
| 214 | + 1: 'Moins que 1 fois/mois', |
| 215 | + 2: '2 à 4 fois/mois', |
| 216 | + 3: '2 à 3 fois/semaine', |
| 217 | + 4: 'Plus que 4 fois/semaine' |
| 218 | + } |
| 219 | + }, |
| 220 | + variant: 'radio' |
| 221 | + }), |
| 222 | + cannabisMemoryConcentration: createDependentField({ |
| 223 | + kind: 'number', |
| 224 | + label: { |
| 225 | + en: '6. How often in the past 6 months have you had a problem with your memory or concentration after using cannabis?', |
| 226 | + fr: '6. Au cours des 6 derniers mois, combien de fois avez-vous éprouvé des problèmes de mémoire ou de concentration après avoir fumé du cannabis?' |
| 227 | + }, |
| 228 | + options: { |
| 229 | + en: { |
| 230 | + 0: 'Never', |
| 231 | + 1: 'Less than monthly', |
| 232 | + 2: 'Monthly', |
| 233 | + 3: 'Weekly', |
| 234 | + 4: 'Daily or almost daily' |
| 235 | + }, |
| 236 | + fr: { |
| 237 | + 0: 'Jamais', |
| 238 | + 1: 'moins que 1fois/mois', |
| 239 | + 2: '2 à 4 fois/mois', |
| 240 | + 3: '2 à 3 fois/semaine', |
| 241 | + 4: 'plus que 4 fois/semaine' |
| 242 | + } |
| 243 | + }, |
| 244 | + variant: 'radio' |
| 245 | + }), |
| 246 | + cannabisHazards: createDependentField({ |
| 247 | + kind: 'number', |
| 248 | + label: { |
| 249 | + en: '7. How often do you use cannabis in situations that could be physically hazardous, such as driving, operating machinery, or caring for children:', |
| 250 | + fr: "7. A quelle fréquence consommez-vous du cannabis dans des situations qui pourraient entrainer un danger, par exemple conduire un véhicule, utiliser une machine, ou s'occuper d'enfants?" |
| 251 | + }, |
| 252 | + options: { |
| 253 | + en: { |
| 254 | + 0: 'Never', |
| 255 | + 1: 'Less than monthly', |
| 256 | + 2: 'Monthly', |
| 257 | + 3: 'Weekly', |
| 258 | + 4: 'Daily or almost daily' |
| 259 | + }, |
| 260 | + fr: { |
| 261 | + 0: 'Jamais', |
| 262 | + 1: 'Moins que 1 fois/mois', |
| 263 | + 2: '2 à 4 fois/mois', |
| 264 | + 3: '2 à 3 fois/semaine', |
| 265 | + 4: 'Plus que 4 fois/semaine' |
| 266 | + } |
| 267 | + }, |
| 268 | + variant: 'radio' |
| 269 | + }), |
| 270 | + cannabisReduction: createDependentField({ |
| 271 | + kind: 'number', |
| 272 | + label: { |
| 273 | + en: '8. Have you ever thought about cutting down, or stopping, your use of cannabis?', |
| 274 | + fr: "8. Avez-vous déjà envisagé de réduire ou d'arrêter votre consommation de cannabis ?" |
| 275 | + }, |
| 276 | + options: { |
| 277 | + en: { |
| 278 | + 0: 'Never', |
| 279 | + 2: 'Yes but not in the past 6 months', |
| 280 | + 4: 'Monthly' |
| 281 | + }, |
| 282 | + fr: { |
| 283 | + 0: 'Jamais', |
| 284 | + 2: 'Oui, mais pas au cours des 6 derniers mois', |
| 285 | + 4: 'Oui, au cours des 6 derniers mois' |
| 286 | + } |
| 287 | + }, |
| 288 | + variant: 'radio' |
| 289 | + }) |
| 290 | + }, |
| 291 | + validationSchema: $InstrumentData, |
| 292 | + measures: { |
| 293 | + cannabisFrequency: { |
| 294 | + kind: 'const', |
| 295 | + label: { |
| 296 | + en: 'Cannabis Frequency', |
| 297 | + fr: 'Frequence de cosommation du Cannabis' |
| 298 | + }, |
| 299 | + ref: 'cannabisFrequency' |
| 300 | + }, |
| 301 | + stonedTime: { |
| 302 | + kind: 'const', |
| 303 | + label: { |
| 304 | + en: 'Time "Stoned"', |
| 305 | + fr: 'Temps « défoncé »' |
| 306 | + }, |
| 307 | + ref: 'stonedTime' |
| 308 | + }, |
| 309 | + unableToStopUsage: { |
| 310 | + kind: 'const', |
| 311 | + label: { |
| 312 | + en: 'Usage Reduction', |
| 313 | + fr: 'Reduction du Cosummation' |
| 314 | + }, |
| 315 | + ref: 'unableToStopUsage' |
| 316 | + }, |
| 317 | + cannabisInducedFailure: { |
| 318 | + kind: 'const', |
| 319 | + label: { |
| 320 | + en: 'Cannabis induced failure', |
| 321 | + fr: 'Défaillance à cause du cannabis' |
| 322 | + }, |
| 323 | + ref: 'cannabisInducedFailure' |
| 324 | + }, |
| 325 | + cannabisRelatedUsageTime: { |
| 326 | + kind: 'const', |
| 327 | + label: { |
| 328 | + en: 'Cannabis usage time', |
| 329 | + fr: 'Temp de cosommation du Cannabis' |
| 330 | + }, |
| 331 | + ref: 'cannabisRelatedUsageTime' |
| 332 | + }, |
| 333 | + cannabisMemoryConcentration: { |
| 334 | + kind: 'const', |
| 335 | + label: { |
| 336 | + en: 'Memory and Concentration', |
| 337 | + fr: 'la memoire et la concentration' |
| 338 | + }, |
| 339 | + ref: 'cannabisMemoryConcentration' |
| 340 | + }, |
| 341 | + cannabisHazards: { |
| 342 | + kind: 'const', |
| 343 | + label: { |
| 344 | + en: 'Cannabis Hazard Score', |
| 345 | + fr: 'Score de dangerosité du cannabis' |
| 346 | + }, |
| 347 | + ref: 'cannabisHazards' |
| 348 | + }, |
| 349 | + cannabisReduction: { |
| 350 | + kind: 'const', |
| 351 | + label: { |
| 352 | + en: 'Cannabis Reduction', |
| 353 | + fr: 'Reduction de la consommation du cannabis' |
| 354 | + }, |
| 355 | + ref: 'cannabisReduction' |
| 356 | + }, |
| 357 | + cannabisScore: { |
| 358 | + kind: 'computed', |
| 359 | + hidden: true, |
| 360 | + label: { |
| 361 | + en: 'Cannabis use score', |
| 362 | + fr: 'Score de consommation de cannabis' |
| 363 | + }, |
| 364 | + value: (data) => { |
| 365 | + return calculateCannabisUse(data); |
| 366 | + } |
| 367 | + }, |
| 368 | + cannabisScoreInterpretation: { |
| 369 | + kind: 'computed', |
| 370 | + hidden: true, |
| 371 | + label: { |
| 372 | + en: 'Cannabis use score interpretation', |
| 373 | + fr: 'Score de consommation de interprétation' |
| 374 | + }, |
| 375 | + value: (data) => { |
| 376 | + const score = calculateCannabisUse(data); |
| 377 | + if (score >= 8 && score < 12) { |
| 378 | + return 'Hazardous cannabis use / Consommation dangereuse de cannabis'; |
| 379 | + } else if (score >= 12) { |
| 380 | + return "Possible cannabis use disorder / Un trouble de l'usage du cannabis est probable"; |
| 381 | + } |
| 382 | + return; |
| 383 | + } |
| 384 | + } |
| 385 | + } |
| 386 | +}); |
0 commit comments