const fs = require('fs'); const rules = require('./conditional-rules.js'); const answers = { "family_background.number_of_siblings": { value: 2, option_id: null }, "family_background.parents_survival_status": { value: "both_parents_are_alive", option_id: "family_background.parents_survival_status.both_parents_are_alive" }, "family_background.do_you_currently_have_an_ongoing_financial_caregiving_or_guardianship_responsibility_for_a_family_member": { value: "i_am_responsible_for_caring_for_my_parent(s)_(father,_mother,_or_both).", option_id: "family_background.do_you_currently_have_an_ongoing_financial_caregiving_or_guardianship_responsibility_for_a_family_member.i_am_responsible_for_caring_for_my_parent_s_father_mother_or_both" }, "family_background.family_s_religious_and_ideological_atmosphere": { value: "religious_(observant_of_obligations)", option_id: "family_background.family_s_religious_and_ideological_atmosphere.religious_observant_of_obligations" }, "family_background.family_economic_status": { value: "prosperous", option_id: "family_background.family_economic_status.prosperous" } }; const questions = JSON.parse(fs.readFileSync('api_questions.json', 'utf8')); const context = { age: 25, gender: 'male' }; for (const q of questions) { const mapped = { id: q.id, type: q.type, title: q.title, required: q.is_required !== undefined ? q.is_required : q.required, baseRequired: q.required, isVisible: q.is_visible, conditionalRule: q.conditional_rule || q.visibility || q.logic || undefined, visibility: q.visibility || q.conditional_rule || undefined, logic: q.logic || undefined, requiredWhen: q.required_when || undefined }; const isVis = rules.isQuestionVisible(mapped, answers, context); const isReq = rules.isQuestionRequired(mapped, answers, context); console.log(`Q: ${q.id} | Visible: ${isVis} | Required: ${isReq}`); }