Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul Adjustments Based on Testing #528

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions microsetta_private_api/api/_interested_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.exceptions import RepoException
from microsetta_private_api.repo.campaign_repo import CampaignRepo
from microsetta_private_api.repo.melissa_repo import MelissaRepo
from microsetta_private_api.tasks import send_email


Expand Down Expand Up @@ -95,15 +96,46 @@ def get_interested_user_address_update(interested_user_id, email):
message="Invalid user."
), 404
else:
# if the address is already valid, no reason to update
# If the address is already valid, no reason to update.
if interested_user.address_valid:
return jsonify(
code=400,
message="Address already verified."
), 400
else:
# we've determined it's a valid user and their address
# needs to be fixed, so we return a subset of their info
# We've determined it's a valid user and their address
# needs to be fixed, so we return a subset of their info.
# Certain paths into the database allow null address_2
# which causes problems, so we change it to "".
if interested_user.address_2 is None:
interested_user.address_2 = ""

# We also need to grab the reason(s) that Melissa couldn't
# verify the address.
melissa_repo = MelissaRepo(t)
melissa_result = melissa_repo.check_duplicate(
interested_user.address_1,
interested_user.address_2,
interested_user.address_3,
interested_user.postal_code,
interested_user.country
)

if isinstance(melissa_result, bool):
cassidysymons marked this conversation as resolved.
Show resolved Hide resolved
# We shouldn't reach this point, but it means the
# address wasn't actually checked
return jsonify(
code=404,
message="Address verification data missing."
), 404

result_codes = melissa_result['result_codes'].split(",")
error_codes = []
for code in result_codes:
# We're only interested in AE codes
if code[0:2] == "AE":
error_codes.append(code)

return jsonify(
interested_user_id=interested_user.interested_user_id,
email=interested_user.email,
Expand All @@ -113,7 +145,8 @@ def get_interested_user_address_update(interested_user_id, email):
city=interested_user.city,
state=interested_user.state,
postal_code=interested_user.postal_code,
country=interested_user.country
country=interested_user.country,
error_codes=error_codes
), 200


Expand Down Expand Up @@ -146,8 +179,6 @@ def put_interested_user_address_update(body):
interested_user.address_1 = body['address_1']
interested_user.address_2 = body['address_2']
interested_user.address_3 = body['address_3']
interested_user.residential_address = \
body['residential_address']
interested_user.phone = body['phone']
interested_user.city = body['city']
interested_user.state = body['state']
Expand Down
2 changes: 2 additions & 0 deletions microsetta_private_api/api/microsetta_private_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,8 @@ paths:
type: string
'country':
type: string
'error_codes':
type: array
'400':
description: Address already valid
'404':
Expand Down
87 changes: 87 additions & 0 deletions microsetta_private_api/db/patches/0127.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
-- Retire the fabric softener question
UPDATE ag.survey_question SET retired = TRUE WHERE survey_question_id = 36;

-- Add an "I use both" option for the deodorant question
INSERT INTO ag.survey_response (american, spanish, spain_spanish) VALUES ('I use both', 'Yo uso ambos', 'Yo uso ambos');
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index) VALUES (34, 'I use both', 5);

-- Re-word the question about surfing
UPDATE ag.survey_question
SET american = 'Do you swim, surf, snorkel, or do other activities where you are in the ocean on a regular basis?',
spanish = '¿Usted nada, surfea, practica esnórquel o realiza otras actividades en el mar con regularidad?',
spain_spanish = '¿Usted nada, surfea, practica esnórquel o realiza otras actividades en el mar con regularidad?'
WHERE survey_question_id = 354;

-- Add "Other" option to types of exercise
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index) VALUES (331, 'Other', 5);

-- Add "None of the above" option to COVID symptoms question
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index) VALUES (214, 'None of the above', 17);

-- Add missing note to question about non-nutritive sweeteners
UPDATE ag.survey_question
SET american = 'How often do you consume beverages with non-nutritive or low-calorie sweeteners? This includes sugar alcohols (sorbitol, mannitol, maltitol, xylitol, reduced palatinose, erythritol), synthetic sweeteners (saccharin, aspartame, acesulfame potassium, sucralose), and sugar substitutes (stevia, monk fruit).',
spanish = '¿Con qué frecuencia consume bebidas con edulcorantes no nutritivos o bajos en calorías? Esto incluye los alcoholes de azúcar (sorbitol, manitol, maltitol, xilitol, palatinosa reducida, eritritol), edulcorantes sintéticos (sacarina, aspartamo, acesulfamo de potasio, sucralosa) y sustitutos del azúcar (stevia, fruta del monje).',
spain_spanish = '¿Con qué frecuencia consume bebidas con edulcorantes no nutritivos o bajos en calorías? Esto incluye los alcoholes de azúcar (sorbitol, manitol, maltitol, xilitol, palatinosa reducida, eritritol), edulcorantes sintéticos (sacarina, aspartamo, acesulfamo de potasio, sucralosa) y sustitutos del azúcar (stevia, fruta del monje).'
WHERE survey_question_id = 157;

-- Stop "Rarely" response from triggering fermented foods sub-questions
DELETE FROM ag.survey_question_triggers WHERE survey_question_id = 165 AND triggering_response = 'Rarely (a few times/month)';

-- Move questions about producing fermented foods out of triggers
DELETE FROM ag.survey_question_triggers WHERE triggered_question IN (169, 171);
UPDATE ag.survey_question SET css_classes = 'tmi-survey-checkbox' WHERE survey_question_id IN (169, 171);

-- Add "I don't produce fermented foods" option to both production questions
INSERT INTO ag.survey_response (american, spanish, spain_spanish) VALUES ('I do not produce fermented foods', 'No produzco alimentos fermentados', 'No produzco alimentos fermentados');
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index) VALUES (169, 'I do not produce fermented foods', 22);
INSERT INTO ag.survey_question_response (survey_question_id, response, display_index) VALUES (171, 'I do not produce fermented foods', 22);

-- Trigger fermented foods increase/frequency questions based on whether user consumes fermented foods
INSERT INTO ag.survey_question_triggers (survey_question_id, triggering_response, triggered_question)
VALUES (478, 'Since infancy/childhood', 166),
(478, 'Within the last year', 166),
(478, 'Within the last 5 years', 166),
(478, 'Within the last 10 years', 166),
(478, 'Since infancy/childhood', 165),
(478, 'Within the last year', 165),
(478, 'Within the last 5 years', 165),
(478, 'Within the last 10 years', 165);

-- Update fermented foods increase/frequency questions' css classes to include "tmi-survey-triggered-question"
UPDATE ag.survey_question SET css_classes = 'tmi-survey-radio-axis tmi-survey-triggered-question' WHERE survey_question_id = 165;
UPDATE ag.survey_question SET css_classes = 'tmi-survey-radio-vertical tmi-survey-triggered-question' WHERE survey_question_id = 166;

-- Fix triggering sequence for non-nutritive food/beverage question sequence
INSERT INTO ag.survey_question_triggers (survey_question_id, triggering_response, triggered_question)
VALUES (157, 'Rarely (a few times/month)', 465),
(157, 'Occasionally (1-2 times/week)', 465),
(157, 'Regularly (3-5 times/week)', 465),
(157, 'Daily', 465),
(463, 'Rarely (a few times/month)', 465),
(463, 'Occasionally (1-2 times/week)', 465),
(463, 'Regularly (3-5 times/week)', 465),
(463, 'Daily', 465),
(465, 'Yes', 466);

-- Un-retire the "other" questions for fermented foods consumed and produced, then reorganize sequencing to fit them in to the Detailed Diet survey (survey_group -18)
UPDATE ag.survey_question SET retired = FALSE, css_classes = 'tmi-survey-text tmi-survey-triggered-question' WHERE survey_question_id IN (168, 170, 172);
DELETE FROM ag.group_questions WHERE survey_group = -10 AND survey_question_id IN (168, 170, 172);
UPDATE ag.group_questions SET display_index = 50 WHERE survey_group = -18 AND survey_question_id = 171;
UPDATE ag.group_questions SET display_index = 48 WHERE survey_group = -18 AND survey_question_id = 169;
INSERT INTO ag.group_questions (survey_group, survey_question_id, display_index)
VALUES (-18, 168, 47),
(-18, 170, 49),
(-18, 172, 51);
INSERT INTO ag.survey_question_triggers (survey_question_id, triggering_response, triggered_question)
VALUES (167, 'Other', 168),
(169, 'Other', 170),
(171, 'Other', 172);

-- Fix formatting for cancer diagnosis question
UPDATE ag.survey_question SET css_classes = 'tmi-survey-radio-vertical' WHERE survey_question_id = 507;

-- As part of the Daklapack API specs, the TMI account that orders a kit will appear on the label in the companyName field.
-- We're going to set our fulfillment account's name to Microsetta Initiative to be as descriptive and professional as possible.
-- In the long term, it would be good to see if we can discontinue use of this field.
UPDATE ag.account SET first_name = 'Microsetta', last_name = 'Initiative' WHERE id = '000fc4cd-8fa4-db8b-e050-8a800c5d81b7';
2 changes: 1 addition & 1 deletion microsetta_private_api/util/melissa.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def verify_address(address_1, address_2=None, address_3=None, city=None,

with Transaction() as t:
# The response codes we can treat as deliverable
GOOD_CODES = ["AV25", "AV24", "AV23", "AV22"]
GOOD_CODES = ["AV25", "AV24", "AV23", "AV22", "AV21"]

melissa_repo = MelissaRepo(t)

Expand Down