diff --git a/go-app-ussd_tb_check.js b/go-app-ussd_tb_check.js index 1a8dfaf4..317568c1 100644 --- a/go-app-ussd_tb_check.js +++ b/go-app-ussd_tb_check.js @@ -240,7 +240,9 @@ go.app = function () { study_completed: response.data.activation, }; - if (activation === "tb_study_a" && response.data.activation === "tb_study_a") { + if ((activation === "tb_study_a" || activation === "tb_study_b" || activation === "tb_study_c") && + (response.data.activation === "tb_study_a" || response.data.activation === "tb_study_b" || + response.data.activation === "tb_study_c")) { return self.states.create("state_study_already_completed"); } @@ -257,7 +259,7 @@ go.app = function () { // If it's 404, new user if (_.get(e, "response.code") === 404) { self.im.user.answers = { returning_user: false, activation: activation }; - return self.states.create("state_welcome"); + return self.states.create("state_terms"); } // Go to error state after 3 failed HTTP requests opts.http_error_count = _.get(opts, "http_error_count", 0) + 1; @@ -300,7 +302,7 @@ go.app = function () { }); }); - self.add("state_terms", function (name) { + self.states.add("state_terms", function (name) { var next = "state_send_privacy_policy_sms"; if (self.im.user.answers.returning_user) { return self.states.create(next); @@ -337,7 +339,7 @@ go.app = function () { }); }); - self.add("state_more_info_pg1", function (name) { + self.states.add("state_more_info_pg1", function (name) { return new MenuState(name, { question: $( "TB HealthCheck does not replace medical advice, diagnosis or treatment. Get" + @@ -348,7 +350,7 @@ go.app = function () { }); }); - self.add("state_more_info_pg2", function (name) { + self.states.add("state_more_info_pg2", function (name) { return new MenuState(name, { question: $( "You use this info at your own risk. This tool cannot replace medical advice. " + @@ -410,7 +412,7 @@ go.app = function () { }); self.states.add("state_core_language", function (name) { - var next_state = "state_age"; + var next_state = "state_welcome"; if (self.im.user.answers.state_language) { return self.im.user.set_lang(self.im.user.answers.state_language) @@ -444,7 +446,7 @@ go.app = function () { }); self.states.add("state_language", function (name) { - var next_state = "state_age"; + var next_state = "state_welcome"; if (self.im.user.answers.state_language) { return self.im.user.set_lang(self.im.user.answers.state_language) @@ -475,7 +477,7 @@ go.app = function () { }); }); - self.add("state_research_consent", function(name) { + self.states.add("state_research_consent", function(name) { if (self.im.user.answers.state_age === "<18"){ return self.states.create("state_gender"); } @@ -497,7 +499,7 @@ go.app = function () { }); }); - self.add("state_age", function (name) { + self.states.add("state_age", function (name) { var activation = self.im.user.answers.activation; var next_state = "state_gender"; @@ -534,7 +536,7 @@ go.app = function () { }); }); - self.add("state_gender", function (name) { + self.states.add("state_gender", function (name) { var activation = self.im.user.answers.activation; var next = "state_province"; @@ -566,7 +568,7 @@ go.app = function () { }); }); - self.add("state_province", function (name) { + self.states.add("state_province", function (name) { var next_state = "state_suburb_name"; if (self.im.user.answers.state_age === "<18"){ @@ -594,7 +596,7 @@ go.app = function () { }); }); - self.add("state_street_name", function (name) { + self.states.add("state_street_name", function (name) { if ((_.toUpper(self.im.user.answers.state_confirm_city)) != "STATE_STREET_NAME") { if (self.im.user.answers.state_street_name && @@ -602,7 +604,7 @@ go.app = function () { return self.states.create("state_city"); } } - + var question = $( "Please type the name of the street where you live." ); @@ -618,14 +620,14 @@ go.app = function () { }); }); - self.add("state_suburb_name", function (name) { + self.states.add("state_suburb_name", function (name) { if ((_.toUpper(self.im.user.answers.state_confirm_city)) != "STATE_STREET_NAME") { if (self.im.user.answers.state_suburb_name) { return self.states.create("state_city"); } } - + var question = $( "Please type the name of the suburb/township/village where you live." ); @@ -641,7 +643,7 @@ go.app = function () { }); }); - self.add("state_city", function (name) { + self.states.add("state_city", function (name) { if ( self.im.user.answers.state_suburb_name && self.im.user.answers.state_city && @@ -676,7 +678,7 @@ go.app = function () { }); }); - self.add("state_google_places_lookup", function (name, opts) { + self.states.add("state_google_places_lookup", function (name, opts) { var street_name = self.im.user.answers.state_street_name; var suburb = self.im.user.answers.state_suburb_name; var city_trunc = self.im.user.answers.state_city; @@ -724,7 +726,7 @@ go.app = function () { ); }); - self.add("state_confirm_city", function (name, opts) { + self.states.add("state_confirm_city", function (name, opts) { var state_city = (self.im.user.answers.state_city).slice(0, 36); var no_next_state = "state_suburb_name"; @@ -759,7 +761,7 @@ go.app = function () { return sign + _.padStart(int, places, "0") + "." + dec; }; - self.add("state_place_details_lookup", function (name, opts) { + self.states.add("state_place_details_lookup", function (name, opts) { var answers = self.im.user.answers; return new JsonApi(self.im) @@ -801,7 +803,7 @@ go.app = function () { ); }); - self.add("state_cough", function (name) { + self.states.add("state_cough", function (name) { var question = $( "Let's see how you're feeling today. Do you have a cough?" ); @@ -820,7 +822,7 @@ go.app = function () { }); }); - self.add("state_fever", function (name) { + self.states.add("state_fever", function (name) { return new ChoiceState(name, { question: $( "Do you have a fever? (when you touch your forehead, does it feel hot?)" @@ -837,7 +839,7 @@ go.app = function () { }); }); - self.add("state_sweat", function (name) { + self.states.add("state_sweat", function (name) { return new ChoiceState(name, { question: $("Are you sweating more than usual at night?"), error: $("Please use numbers from list. Are you sweating more than usual at night?"), @@ -847,7 +849,7 @@ go.app = function () { }); }); - self.add("state_weight", function (name) { + self.states.add("state_weight", function (name) { return new ChoiceState(name, { question: $("Have you been losing weight without trying?"), error: $("Please use numbers from list. Have you been losing weight without trying?"), @@ -857,7 +859,7 @@ go.app = function () { }); }); - self.add("state_exposure", function (name) { + self.states.add("state_exposure", function (name) { var next_state = "state_tracing"; var activation = self.im.user.answers.activation; @@ -884,7 +886,7 @@ go.app = function () { }); }); - self.add("state_tracing", function (name) { + self.states.add("state_tracing", function (name) { var next_state = "state_opt_in"; var question = $( @@ -912,7 +914,7 @@ go.app = function () { }); }); - self.add("state_study_tracing", function (name) { + self.states.add("state_study_tracing", function (name) { var next_state = "state_opt_in"; var activation = self.im.user.answers.activation; @@ -966,7 +968,7 @@ go.app = function () { }); }); - self.add("state_submit_data", function (name, opts) { + self.states.add("state_submit_data", function (name, opts) { var answers = self.im.user.answers; var msisdn = utils.normalize_msisdn(self.im.user.addr, "ZA"); var activation = self.get_activation(); @@ -980,7 +982,7 @@ go.app = function () { msisdn: msisdn, source: "USSD", language: answers.state_language, - province: answers.state_province ? answers.state_province : null, + province: answers.state_province ? answers.state_province : "", city: answers.state_city ? answers.state_city : "", age: answers.state_age, gender: answers.state_gender, @@ -1051,7 +1053,7 @@ go.app = function () { text = $("Okay thanks, you won't get any follow-up messages."); } - if (activation === "tb_study_a"){ + if (activation === "tb_study_a" || activation === "tb_study_b" || activation === "tb_study_c"){ text = $("Thanks for your answers. Your result will be sent soon by SMS."); } @@ -1149,7 +1151,7 @@ go.app = function () { }); }); - self.add("state_clinic_visit_day", function (name) { + self.states.add("state_clinic_visit_day", function (name) { return new ChoiceState(name, { question: $( "When will you go for your test? Reply with the day" @@ -1254,7 +1256,7 @@ go.app = function () { }); }); - self.add("state_survey_start", function (name) { + self.states.add("state_survey_start", function (name) { var end = "state_survey_double_participation"; var survey_complete = _.toUpper(_.get(self.im.user.get_answer("contact"), "fields.survey_complete", $("None"))); if (survey_complete === "TRUE") { @@ -1279,7 +1281,7 @@ go.app = function () { }); }); - self.add("state_submit_tb_check_efficacy_option", function (name) { + self.states.add("state_submit_tb_check_efficacy_option", function (name) { var activation = self.get_activation(); var next = "state_submit_clinic_delay"; @@ -1305,7 +1307,7 @@ go.app = function () { }); }); - self.add("state_submit_clinic_delay", function (name) { + self.states.add("state_submit_clinic_delay", function (name) { return new ChoiceState(name, { question: $( "I did not go to the clinic for a TB test because " + @@ -1326,7 +1328,7 @@ go.app = function () { }); }); - self.add("state_submit_clinic_proximity", function (name) { + self.states.add("state_submit_clinic_proximity", function (name) { return new ChoiceState(name, { question: $( "I did not go to the clinic for a TB test because " + @@ -1347,7 +1349,7 @@ go.app = function () { }); }); - self.add("state_submit_trauma", function (name) { + self.states.add("state_submit_trauma", function (name) { return new ChoiceState(name, { question: $( "I did not go to the clinic for a TB test because " + @@ -1369,7 +1371,7 @@ go.app = function () { }); }); - self.add("state_submit_clinic_feedback", function (name) { + self.states.add("state_submit_clinic_feedback", function (name) { return new FreeText(name, { question: $( "Are there any other reasons why you did not go " + @@ -1385,7 +1387,7 @@ go.app = function () { }); }); - self.add("state_trigger_rapidpro_survey_flow", function(name, opts) { + self.states.add("state_trigger_rapidpro_survey_flow", function(name, opts) { var msisdn = utils.normalize_msisdn(self.im.user.addr, "ZA"); var answers = self.im.user.answers; var activation = self.get_activation(); @@ -1407,8 +1409,8 @@ go.app = function () { }; return self.rapidpro .start_flow( - self.im.config.rapidpro.tbcheck_survey_flow_uuid, - null, + self.im.config.rapidpro.tbcheck_survey_flow_uuid, + null, "whatsapp:" + _.trim(msisdn, "+"), data) .then(function() { return self.states.create("state_survey_thanks_airtime"); @@ -1425,7 +1427,7 @@ go.app = function () { }); }); - self.add("state_survey_thanks_airtime", function (name) { + self.states.add("state_survey_thanks_airtime", function (name) { return new MenuState(name, { question: $( "Thank you for taking part in the survey. " + @@ -1470,7 +1472,7 @@ go.app = function () { }); }); - self.add("state_sms_complete", function (name) { + self.states.add("state_sms_complete", function (name) { var activation = self.get_activation(); var choice_list = [ @@ -1497,7 +1499,7 @@ go.app = function () { }); }); - self.add("state_faq_metrics", function (name) { + self.states.add("state_faq_metrics", function (name) { self.im.log("Logging FAQ metrics"); var sessionID = self.sessionID(); var msisdn = utils.normalize_msisdn( @@ -1507,7 +1509,7 @@ go.app = function () { return self.states.create("state_faq"); }); - self.add("state_faq", function (name) { + self.states.add("state_faq", function (name) { return new MenuState(name, { question: $( "What would you like to know?" @@ -1526,7 +1528,7 @@ go.app = function () { }); }); - self.add("state_faq_2", function (name) { + self.states.add("state_faq_2", function (name) { return new MenuState(name, { question: $( "What would you like to know?" @@ -1544,47 +1546,47 @@ go.app = function () { }); }); - self.add("state_faq_research", function (name) { + self.states.add("state_faq_research", function (name) { self.im.user.answers.faq = "state_faq_research"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_information", function (name) { + self.states.add("state_faq_information", function (name) { self.im.user.answers.faq = "state_faq_information"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_sms", function (name) { + self.states.add("state_faq_sms", function (name) { self.im.user.answers.faq = "state_faq_sms"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_next_steps", function (name) { + self.states.add("state_faq_next_steps", function (name) { self.im.user.answers.faq = "state_faq_next_steps"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_midway", function (name) { + self.states.add("state_faq_midway", function (name) { self.im.user.answers.faq = "state_faq_midway"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_risks", function (name) { + self.states.add("state_faq_risks", function (name) { self.im.user.answers.faq = "state_faq_risks"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_privacy", function (name) { + self.states.add("state_faq_privacy", function (name) { self.im.user.answers.faq = "state_faq_privacy"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_unhappy", function (name) { + self.states.add("state_faq_unhappy", function (name) { self.im.user.answers.faq = "state_faq_unhappy"; return self.states.create("state_send_faq_sms"); }); - self.add("state_survey_sort", function (name) { + self.states.add("state_survey_sort", function (name) { var end = "state_survey_end"; var start = "state_survey_start"; var survey_complete = _.toUpper(_.get(self.im.user.get_answer("contact"), "fields.survey_complete", $("None"))); @@ -1619,7 +1621,7 @@ go.app = function () { }); }); - self.add("state_encouraged_to_test", function (name) { + self.states.add("state_encouraged_to_test", function (name) { return new ChoiceState(name, { question: $( "Did TB HealthCheck encourage you to get tested?" @@ -1639,7 +1641,7 @@ go.app = function () { }); }); - self.add("state_tested_without_tbcheck", function (name) { + self.states.add("state_tested_without_tbcheck", function (name) { return new ChoiceState(name, { question: $( "Would you have tested without TB HealthCheck?" @@ -1659,7 +1661,7 @@ go.app = function () { }); }); - self.add("state_further_delayed", function (name) { + self.states.add("state_further_delayed", function (name) { return new ChoiceState(name, { question: $( "Would you have further delayed testing without TB HealthCheck?" @@ -1679,7 +1681,7 @@ go.app = function () { }); }); - self.add("state_clinic_waiting_time", function (name) { + self.states.add("state_clinic_waiting_time", function (name) { return new ChoiceState(name, { question: $([ "The waiting times at the clinic were too long.", @@ -1701,7 +1703,7 @@ go.app = function () { }); }); - self.add("state_clinic_experience", function (name) { + self.states.add("state_clinic_experience", function (name) { return new ChoiceState(name, { question: $( "How was your experience at the clinic?" @@ -1721,7 +1723,7 @@ go.app = function () { }); }); - self.add("state_clinic_experience_feedback", function (name) { + self.states.add("state_clinic_experience_feedback", function (name) { return new FreeText(name, { question: $( "Was it difficult to get access to a TB test? "+ @@ -1736,7 +1738,7 @@ go.app = function () { }); }); - self.add("state_reason_for_testing", function (name) { + self.states.add("state_reason_for_testing", function (name) { return new FreeText(name, { question: $( "Why did you go to the clinic for a TB test?" @@ -1750,7 +1752,7 @@ go.app = function () { }); }); - self.add("state_contact_for_more_info", function (name) { + self.states.add("state_contact_for_more_info", function (name) { return new ChoiceState(name, { question: $( "Can we phone you to get more information?" diff --git a/src/ussd_tb_check.js b/src/ussd_tb_check.js index f85173ac..814f5a0d 100644 --- a/src/ussd_tb_check.js +++ b/src/ussd_tb_check.js @@ -123,7 +123,9 @@ go.app = function () { study_completed: response.data.activation, }; - if (activation === "tb_study_a" && response.data.activation === "tb_study_a") { + if ((activation === "tb_study_a" || activation === "tb_study_b" || activation === "tb_study_c") && + (response.data.activation === "tb_study_a" || response.data.activation === "tb_study_b" || + response.data.activation === "tb_study_c")) { return self.states.create("state_study_already_completed"); } @@ -140,7 +142,7 @@ go.app = function () { // If it's 404, new user if (_.get(e, "response.code") === 404) { self.im.user.answers = { returning_user: false, activation: activation }; - return self.states.create("state_welcome"); + return self.states.create("state_terms"); } // Go to error state after 3 failed HTTP requests opts.http_error_count = _.get(opts, "http_error_count", 0) + 1; @@ -183,7 +185,7 @@ go.app = function () { }); }); - self.add("state_terms", function (name) { + self.states.add("state_terms", function (name) { var next = "state_send_privacy_policy_sms"; if (self.im.user.answers.returning_user) { return self.states.create(next); @@ -220,7 +222,7 @@ go.app = function () { }); }); - self.add("state_more_info_pg1", function (name) { + self.states.add("state_more_info_pg1", function (name) { return new MenuState(name, { question: $( "TB HealthCheck does not replace medical advice, diagnosis or treatment. Get" + @@ -231,7 +233,7 @@ go.app = function () { }); }); - self.add("state_more_info_pg2", function (name) { + self.states.add("state_more_info_pg2", function (name) { return new MenuState(name, { question: $( "You use this info at your own risk. This tool cannot replace medical advice. " + @@ -293,7 +295,7 @@ go.app = function () { }); self.states.add("state_core_language", function (name) { - var next_state = "state_age"; + var next_state = "state_welcome"; if (self.im.user.answers.state_language) { return self.im.user.set_lang(self.im.user.answers.state_language) @@ -327,7 +329,7 @@ go.app = function () { }); self.states.add("state_language", function (name) { - var next_state = "state_age"; + var next_state = "state_welcome"; if (self.im.user.answers.state_language) { return self.im.user.set_lang(self.im.user.answers.state_language) @@ -358,7 +360,7 @@ go.app = function () { }); }); - self.add("state_research_consent", function(name) { + self.states.add("state_research_consent", function(name) { if (self.im.user.answers.state_age === "<18"){ return self.states.create("state_gender"); } @@ -380,7 +382,7 @@ go.app = function () { }); }); - self.add("state_age", function (name) { + self.states.add("state_age", function (name) { var activation = self.im.user.answers.activation; var next_state = "state_gender"; @@ -417,7 +419,7 @@ go.app = function () { }); }); - self.add("state_gender", function (name) { + self.states.add("state_gender", function (name) { var activation = self.im.user.answers.activation; var next = "state_province"; @@ -449,7 +451,7 @@ go.app = function () { }); }); - self.add("state_province", function (name) { + self.states.add("state_province", function (name) { var next_state = "state_suburb_name"; if (self.im.user.answers.state_age === "<18"){ @@ -477,7 +479,7 @@ go.app = function () { }); }); - self.add("state_street_name", function (name) { + self.states.add("state_street_name", function (name) { if ((_.toUpper(self.im.user.answers.state_confirm_city)) != "STATE_STREET_NAME") { if (self.im.user.answers.state_street_name && @@ -485,7 +487,7 @@ go.app = function () { return self.states.create("state_city"); } } - + var question = $( "Please type the name of the street where you live." ); @@ -501,14 +503,14 @@ go.app = function () { }); }); - self.add("state_suburb_name", function (name) { + self.states.add("state_suburb_name", function (name) { if ((_.toUpper(self.im.user.answers.state_confirm_city)) != "STATE_STREET_NAME") { if (self.im.user.answers.state_suburb_name) { return self.states.create("state_city"); } } - + var question = $( "Please type the name of the suburb/township/village where you live." ); @@ -524,7 +526,7 @@ go.app = function () { }); }); - self.add("state_city", function (name) { + self.states.add("state_city", function (name) { if ( self.im.user.answers.state_suburb_name && self.im.user.answers.state_city && @@ -559,7 +561,7 @@ go.app = function () { }); }); - self.add("state_google_places_lookup", function (name, opts) { + self.states.add("state_google_places_lookup", function (name, opts) { var street_name = self.im.user.answers.state_street_name; var suburb = self.im.user.answers.state_suburb_name; var city_trunc = self.im.user.answers.state_city; @@ -607,7 +609,7 @@ go.app = function () { ); }); - self.add("state_confirm_city", function (name, opts) { + self.states.add("state_confirm_city", function (name, opts) { var state_city = (self.im.user.answers.state_city).slice(0, 36); var no_next_state = "state_suburb_name"; @@ -642,7 +644,7 @@ go.app = function () { return sign + _.padStart(int, places, "0") + "." + dec; }; - self.add("state_place_details_lookup", function (name, opts) { + self.states.add("state_place_details_lookup", function (name, opts) { var answers = self.im.user.answers; return new JsonApi(self.im) @@ -684,7 +686,7 @@ go.app = function () { ); }); - self.add("state_cough", function (name) { + self.states.add("state_cough", function (name) { var question = $( "Let's see how you're feeling today. Do you have a cough?" ); @@ -703,7 +705,7 @@ go.app = function () { }); }); - self.add("state_fever", function (name) { + self.states.add("state_fever", function (name) { return new ChoiceState(name, { question: $( "Do you have a fever? (when you touch your forehead, does it feel hot?)" @@ -720,7 +722,7 @@ go.app = function () { }); }); - self.add("state_sweat", function (name) { + self.states.add("state_sweat", function (name) { return new ChoiceState(name, { question: $("Are you sweating more than usual at night?"), error: $("Please use numbers from list. Are you sweating more than usual at night?"), @@ -730,7 +732,7 @@ go.app = function () { }); }); - self.add("state_weight", function (name) { + self.states.add("state_weight", function (name) { return new ChoiceState(name, { question: $("Have you been losing weight without trying?"), error: $("Please use numbers from list. Have you been losing weight without trying?"), @@ -740,7 +742,7 @@ go.app = function () { }); }); - self.add("state_exposure", function (name) { + self.states.add("state_exposure", function (name) { var next_state = "state_tracing"; var activation = self.im.user.answers.activation; @@ -767,7 +769,7 @@ go.app = function () { }); }); - self.add("state_tracing", function (name) { + self.states.add("state_tracing", function (name) { var next_state = "state_opt_in"; var question = $( @@ -795,7 +797,7 @@ go.app = function () { }); }); - self.add("state_study_tracing", function (name) { + self.states.add("state_study_tracing", function (name) { var next_state = "state_opt_in"; var activation = self.im.user.answers.activation; @@ -849,7 +851,7 @@ go.app = function () { }); }); - self.add("state_submit_data", function (name, opts) { + self.states.add("state_submit_data", function (name, opts) { var answers = self.im.user.answers; var msisdn = utils.normalize_msisdn(self.im.user.addr, "ZA"); var activation = self.get_activation(); @@ -863,7 +865,7 @@ go.app = function () { msisdn: msisdn, source: "USSD", language: answers.state_language, - province: answers.state_province ? answers.state_province : null, + province: answers.state_province ? answers.state_province : "", city: answers.state_city ? answers.state_city : "", age: answers.state_age, gender: answers.state_gender, @@ -934,7 +936,7 @@ go.app = function () { text = $("Okay thanks, you won't get any follow-up messages."); } - if (activation === "tb_study_a"){ + if (activation === "tb_study_a" || activation === "tb_study_b" || activation === "tb_study_c"){ text = $("Thanks for your answers. Your result will be sent soon by SMS."); } @@ -1032,7 +1034,7 @@ go.app = function () { }); }); - self.add("state_clinic_visit_day", function (name) { + self.states.add("state_clinic_visit_day", function (name) { return new ChoiceState(name, { question: $( "When will you go for your test? Reply with the day" @@ -1137,7 +1139,7 @@ go.app = function () { }); }); - self.add("state_survey_start", function (name) { + self.states.add("state_survey_start", function (name) { var end = "state_survey_double_participation"; var survey_complete = _.toUpper(_.get(self.im.user.get_answer("contact"), "fields.survey_complete", $("None"))); if (survey_complete === "TRUE") { @@ -1162,7 +1164,7 @@ go.app = function () { }); }); - self.add("state_submit_tb_check_efficacy_option", function (name) { + self.states.add("state_submit_tb_check_efficacy_option", function (name) { var activation = self.get_activation(); var next = "state_submit_clinic_delay"; @@ -1188,7 +1190,7 @@ go.app = function () { }); }); - self.add("state_submit_clinic_delay", function (name) { + self.states.add("state_submit_clinic_delay", function (name) { return new ChoiceState(name, { question: $( "I did not go to the clinic for a TB test because " + @@ -1209,7 +1211,7 @@ go.app = function () { }); }); - self.add("state_submit_clinic_proximity", function (name) { + self.states.add("state_submit_clinic_proximity", function (name) { return new ChoiceState(name, { question: $( "I did not go to the clinic for a TB test because " + @@ -1230,7 +1232,7 @@ go.app = function () { }); }); - self.add("state_submit_trauma", function (name) { + self.states.add("state_submit_trauma", function (name) { return new ChoiceState(name, { question: $( "I did not go to the clinic for a TB test because " + @@ -1252,7 +1254,7 @@ go.app = function () { }); }); - self.add("state_submit_clinic_feedback", function (name) { + self.states.add("state_submit_clinic_feedback", function (name) { return new FreeText(name, { question: $( "Are there any other reasons why you did not go " + @@ -1268,7 +1270,7 @@ go.app = function () { }); }); - self.add("state_trigger_rapidpro_survey_flow", function(name, opts) { + self.states.add("state_trigger_rapidpro_survey_flow", function(name, opts) { var msisdn = utils.normalize_msisdn(self.im.user.addr, "ZA"); var answers = self.im.user.answers; var activation = self.get_activation(); @@ -1290,8 +1292,8 @@ go.app = function () { }; return self.rapidpro .start_flow( - self.im.config.rapidpro.tbcheck_survey_flow_uuid, - null, + self.im.config.rapidpro.tbcheck_survey_flow_uuid, + null, "whatsapp:" + _.trim(msisdn, "+"), data) .then(function() { return self.states.create("state_survey_thanks_airtime"); @@ -1308,7 +1310,7 @@ go.app = function () { }); }); - self.add("state_survey_thanks_airtime", function (name) { + self.states.add("state_survey_thanks_airtime", function (name) { return new MenuState(name, { question: $( "Thank you for taking part in the survey. " + @@ -1353,7 +1355,7 @@ go.app = function () { }); }); - self.add("state_sms_complete", function (name) { + self.states.add("state_sms_complete", function (name) { var activation = self.get_activation(); var choice_list = [ @@ -1380,7 +1382,7 @@ go.app = function () { }); }); - self.add("state_faq_metrics", function (name) { + self.states.add("state_faq_metrics", function (name) { self.im.log("Logging FAQ metrics"); var sessionID = self.sessionID(); var msisdn = utils.normalize_msisdn( @@ -1390,7 +1392,7 @@ go.app = function () { return self.states.create("state_faq"); }); - self.add("state_faq", function (name) { + self.states.add("state_faq", function (name) { return new MenuState(name, { question: $( "What would you like to know?" @@ -1409,7 +1411,7 @@ go.app = function () { }); }); - self.add("state_faq_2", function (name) { + self.states.add("state_faq_2", function (name) { return new MenuState(name, { question: $( "What would you like to know?" @@ -1427,47 +1429,47 @@ go.app = function () { }); }); - self.add("state_faq_research", function (name) { + self.states.add("state_faq_research", function (name) { self.im.user.answers.faq = "state_faq_research"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_information", function (name) { + self.states.add("state_faq_information", function (name) { self.im.user.answers.faq = "state_faq_information"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_sms", function (name) { + self.states.add("state_faq_sms", function (name) { self.im.user.answers.faq = "state_faq_sms"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_next_steps", function (name) { + self.states.add("state_faq_next_steps", function (name) { self.im.user.answers.faq = "state_faq_next_steps"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_midway", function (name) { + self.states.add("state_faq_midway", function (name) { self.im.user.answers.faq = "state_faq_midway"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_risks", function (name) { + self.states.add("state_faq_risks", function (name) { self.im.user.answers.faq = "state_faq_risks"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_privacy", function (name) { + self.states.add("state_faq_privacy", function (name) { self.im.user.answers.faq = "state_faq_privacy"; return self.states.create("state_send_faq_sms"); }); - self.add("state_faq_unhappy", function (name) { + self.states.add("state_faq_unhappy", function (name) { self.im.user.answers.faq = "state_faq_unhappy"; return self.states.create("state_send_faq_sms"); }); - self.add("state_survey_sort", function (name) { + self.states.add("state_survey_sort", function (name) { var end = "state_survey_end"; var start = "state_survey_start"; var survey_complete = _.toUpper(_.get(self.im.user.get_answer("contact"), "fields.survey_complete", $("None"))); @@ -1502,7 +1504,7 @@ go.app = function () { }); }); - self.add("state_encouraged_to_test", function (name) { + self.states.add("state_encouraged_to_test", function (name) { return new ChoiceState(name, { question: $( "Did TB HealthCheck encourage you to get tested?" @@ -1522,7 +1524,7 @@ go.app = function () { }); }); - self.add("state_tested_without_tbcheck", function (name) { + self.states.add("state_tested_without_tbcheck", function (name) { return new ChoiceState(name, { question: $( "Would you have tested without TB HealthCheck?" @@ -1542,7 +1544,7 @@ go.app = function () { }); }); - self.add("state_further_delayed", function (name) { + self.states.add("state_further_delayed", function (name) { return new ChoiceState(name, { question: $( "Would you have further delayed testing without TB HealthCheck?" @@ -1562,7 +1564,7 @@ go.app = function () { }); }); - self.add("state_clinic_waiting_time", function (name) { + self.states.add("state_clinic_waiting_time", function (name) { return new ChoiceState(name, { question: $([ "The waiting times at the clinic were too long.", @@ -1584,7 +1586,7 @@ go.app = function () { }); }); - self.add("state_clinic_experience", function (name) { + self.states.add("state_clinic_experience", function (name) { return new ChoiceState(name, { question: $( "How was your experience at the clinic?" @@ -1604,7 +1606,7 @@ go.app = function () { }); }); - self.add("state_clinic_experience_feedback", function (name) { + self.states.add("state_clinic_experience_feedback", function (name) { return new FreeText(name, { question: $( "Was it difficult to get access to a TB test? "+ @@ -1619,7 +1621,7 @@ go.app = function () { }); }); - self.add("state_reason_for_testing", function (name) { + self.states.add("state_reason_for_testing", function (name) { return new FreeText(name, { question: $( "Why did you go to the clinic for a TB test?" @@ -1633,7 +1635,7 @@ go.app = function () { }); }); - self.add("state_contact_for_more_info", function (name) { + self.states.add("state_contact_for_more_info", function (name) { return new ChoiceState(name, { question: $( "Can we phone you to get more information?" diff --git a/test/ussd_tb_check.test.js b/test/ussd_tb_check.test.js index 66bec08c..835e2b4a 100644 --- a/test/ussd_tb_check.test.js +++ b/test/ussd_tb_check.test.js @@ -71,7 +71,7 @@ describe("ussd_tb_check app", function () { }) .input({ session_event: "new", to_addr: "*123*123*8#" }) .check.user.answer("activation", "tb_soccer_1_2022") - .check.user.state("state_welcome") + .check.user.state("state_terms") .run(); }); it("should set activation for returning user", function() { @@ -97,7 +97,7 @@ describe("ussd_tb_check app", function () { } }); }) - .input({ session_event: "new", to_addr: "*123*123*8#" }) + .input({ session_event: "resume", to_addr: "*123*123*8#" }) .check.user.answer("activation", "tb_soccer_1_2022") .check.user.state("state_welcome") .run(); @@ -123,7 +123,7 @@ describe("ussd_tb_check app", function () { }) .input({ session_event: "new", to_addr: "*123*123*0#" }) .check.user.answer("activation", null) - .check.user.state("state_welcome") + .check.user.state("state_terms") .run(); }); it("should set activation for new user to skip location", function() { @@ -144,7 +144,7 @@ describe("ussd_tb_check app", function () { }) .input({ session_event: "new", to_addr: "*123*123*6#" }) .check.user.answer("activation", "skip_location_2022") - .check.user.state("state_welcome") + .check.user.state("state_terms") .run(); }); it("should set activation for new user using school activation", function() { @@ -165,7 +165,7 @@ describe("ussd_tb_check app", function () { }) .input({ session_event: "new", to_addr: "*123*123*11#" }) .check.user.answer("activation", "tb_school_1") - .check.user.state("state_welcome") + .check.user.state("state_terms") .run(); }); it("should set school activation for returning user", function() { @@ -329,8 +329,7 @@ describe("ussd_tb_check app", function () { describe("state_timed_out", function () { it("should ask the user if they want to continue", function () { return tester.setup.user - .state("state_terms") - .start() + .state("state_timed_out") .check.interaction({ state: "state_timed_out", reply: [ @@ -344,8 +343,8 @@ describe("ussd_tb_check app", function () { }); it("should repeat question on invalid input", function () { return tester.setup.user - .state("state_terms") - .inputs({ session_event: "new" }, "A") + .state("state_timed_out") + .inputs({ session_event: "resume" }, "A") .check.interaction({ state: "state_timed_out", reply: [ @@ -444,7 +443,7 @@ describe("ussd_tb_check app", function () { return tester.setup.user .state("state_language") .input("1") - .check.user.state("state_age") + .check.user.state("state_welcome") .run(); }); it("should go to state_age for in lang of the valid option", function () { @@ -452,7 +451,7 @@ describe("ussd_tb_check app", function () { .state("state_language") .input("2") .check.user.lang("zul") - .check.user.state("state_age") + .check.user.state("state_welcome") .run(); }); it("should go to state_terms for english lang option", function () { @@ -460,14 +459,11 @@ describe("ussd_tb_check app", function () { .state("state_language") .input("1") .check.interaction({ - state: "state_age", + state: "state_welcome", reply: [ - "How old are you?", - "1. under 18", - "2. 18-39", - "3. 40-65", - "4. over 65", - ].join("\n"), + "The National Department of Health thanks you for helping to protect "+ + "the health of all SA citizens. Stop the spread of TB.", + "1. START"].join("\n"), char_limit: 160, }) .run(); @@ -476,7 +472,7 @@ describe("ussd_tb_check app", function () { return tester.setup.user .state("state_language") .setup.user.answer("state_language", "eng") - .check.user.state("state_age") + .check.user.state("state_welcome") .run(); }); }); @@ -1078,7 +1074,7 @@ describe("ussd_tb_check app", function () { .run(); }); }); - it("should ask for the city", function () { + it("should ask for the street name", function () { return tester.setup.user .state("state_street_name") .input(" \t\n") @@ -1090,7 +1086,7 @@ describe("ussd_tb_check app", function () { }) .run(); }); - it("should ask again for invalid input", function () { + it("should ask again for suburb invalid input", function () { return tester.setup.user .state("state_suburb_name") .input(" \t\n") @@ -1102,7 +1098,7 @@ describe("ussd_tb_check app", function () { }) .run(); }); - it("should ask again for invalid input", function () { + it("should ask again for state city invalid input", function () { return tester.setup.user .state("state_city") .input(" \t\n") @@ -1622,7 +1618,7 @@ describe("ussd_tb_check app", function () { .check.user.state("state_tracing") .run(); }); - it("should go to state_tracing for tb_study_a", function () { + it("should go to state_study_tracing for tb_study_a", function () { return tester.setup.user .state("state_exposure") .setup.user.answer("activation", "tb_study_a") @@ -2547,7 +2543,7 @@ describe("ussd_tb_check app", function () { msisdn: "+27123456789", source: "USSD", language: "eng", - province: null, + province: "", city: "JHB", age: "<18", gender: "male",