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

Move FFQ's from sample to source #459

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f21eaf9
Move FFQ's from sample to source
SyedAli-789 Sep 19, 2022
6ac01df
Move FFQ's from sample to source
SyedAli-789 Sep 29, 2022
8c08b70
test fix
SyedAli-789 Oct 3, 2022
4c8b06d
test fix
SyedAli-789 Oct 3, 2022
7ea64f7
test integration file changes
SyedAli-789 Oct 11, 2022
50588ff
merge conflict resolved
SyedAli-789 Oct 11, 2022
8ce863c
PR comment changes
SyedAli-789 Oct 17, 2022
8c3e68d
lint fix
SyedAli-789 Oct 17, 2022
8213605
lint fix
SyedAli-789 Oct 17, 2022
2ec55e6
lint fix
SyedAli-789 Oct 17, 2022
908bf30
PR comment changes
SyedAli-789 Oct 25, 2022
55a37a3
lint fix
SyedAli-789 Oct 25, 2022
626c901
added parameter
SyedAli-789 Oct 26, 2022
bed5f7a
lint fix
SyedAli-789 Oct 26, 2022
d5acabc
lint fix
SyedAli-789 Oct 26, 2022
e1319bc
lint fix
SyedAli-789 Oct 26, 2022
496c48c
vioscreen session implementation
SyedAli-789 Oct 27, 2022
0c714a9
PR comments addresses
SyedAli-789 Oct 28, 2022
a5ecb04
PR comment changes
SyedAli-789 Oct 28, 2022
fe1f8af
adressed PR comments
SyedAli-789 Oct 29, 2022
bb12051
lintfix
SyedAli-789 Oct 29, 2022
98db063
addressed PR comments
SyedAli-789 Oct 31, 2022
f734bab
updated the remote survey url
SyedAli-789 Oct 31, 2022
e185172
activation_code to registration_code
SyedAli-789 Nov 1, 2022
17dcca3
test fix
SyedAli-789 Nov 1, 2022
e54e44a
lint fix
SyedAli-789 Nov 1, 2022
fd3b6aa
test error fix
SyedAli-789 Nov 1, 2022
81ce521
URL fix
SyedAli-789 Nov 2, 2022
1cb21d9
lint fix
SyedAli-789 Nov 2, 2022
230efb6
.
SyedAli-789 Nov 2, 2022
84650f5
params required false
SyedAli-789 Nov 2, 2022
bffb901
chadged params to optional
SyedAli-789 Nov 2, 2022
e4dc6a1
test fix
SyedAli-789 Nov 2, 2022
4ace98a
test error fix
SyedAli-789 Nov 2, 2022
b2ca0e7
sample-vioscreen changes
SyedAli-789 Nov 11, 2022
97eb2fe
merge conflict resolved
SyedAli-789 Nov 14, 2022
75cc25a
.
SyedAli-789 Nov 14, 2022
02bfdaf
test fix changes
SyedAli-789 Nov 14, 2022
27f131b
reverting the changes
SyedAli-789 Nov 15, 2022
9c1d3f3
reverting as per review comments
SyedAli-789 Nov 15, 2022
827c2a1
.
SyedAli-789 Nov 15, 2022
87d4f25
addressed reviw comments
SyedAli-789 Nov 16, 2022
ecdfeb7
testcase added
SyedAli-789 Nov 30, 2022
8c46eee
conflict resolved
SyedAli-789 Nov 30, 2022
5147c5f
unit test updated
SyedAli-789 Dec 1, 2022
3f8aaaa
test fix
SyedAli-789 Dec 1, 2022
bcd996e
test fix
SyedAli-789 Dec 1, 2022
5cde512
test fix
SyedAli-789 Dec 1, 2022
1bcae76
test fix
SyedAli-789 Dec 1, 2022
ec5e9f8
unite test replaced
SyedAli-789 Dec 1, 2022
d54fc81
test fix
SyedAli-789 Dec 5, 2022
7f69b45
test fix
SyedAli-789 Dec 5, 2022
a33654c
syntax fix
SyedAli-789 Dec 5, 2022
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
32 changes: 17 additions & 15 deletions microsetta_private_api/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
)

from ._vioscreen import (
read_sample_vioscreen_session, read_sample_vioscreen_percent_energy,
read_sample_vioscreen_dietary_score, read_sample_vioscreen_supplements,
read_sample_vioscreen_food_components,
read_sample_vioscreen_eating_patterns,
read_sample_vioscreen_mpeds, read_sample_vioscreen_food_consumption,
read_vioscreen_session, read_vioscreen_percent_energy,
read_vioscreen_dietary_score, read_vioscreen_supplements,
read_vioscreen_food_components,
read_vioscreen_eating_patterns,
read_vioscreen_mpeds, read_vioscreen_food_consumption,
get_vioscreen_dietary_scores_by_component,
get_vioscreen_dietary_scores_descriptions,
get_vioscreen_food_components_by_code,
get_vioscreen_food_components_descriptions
get_vioscreen_food_components_descriptions,
get_vioscreen_sessions
)

from ._campaign import (
Expand Down Expand Up @@ -98,20 +99,21 @@
'verify_jwt',
'get_preparations',
'check_activation',
'read_sample_vioscreen_session',
'read_sample_vioscreen_percent_energy',
'read_sample_vioscreen_dietary_score',
'read_sample_vioscreen_supplements',
'read_sample_vioscreen_food_components',
'read_sample_vioscreen_eating_patterns',
'read_sample_vioscreen_mpeds',
'read_sample_vioscreen_food_consumption',
'read_vioscreen_session',
'read_vioscreen_percent_energy',
'read_vioscreen_dietary_score',
'read_vioscreen_supplements',
'read_vioscreen_food_components',
'read_vioscreen_eating_patterns',
'read_vioscreen_mpeds',
'read_vioscreen_food_consumption',
'get_vioscreen_dietary_scores_by_component',
'get_vioscreen_dietary_scores_descriptions',
'get_vioscreen_food_components_by_code',
'get_vioscreen_food_components_descriptions',
'get_campaign_information',
'create_interested_user',
'get_interested_user_address_update',
'put_interested_user_address_update'
'put_interested_user_address_update',
'get_vioscreen_sessions'
]
28 changes: 16 additions & 12 deletions microsetta_private_api/api/_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ def read_survey_templates(account_id, source_id, language_tag, token_info):

def _remote_survey_url_vioscreen(transaction, account_id, source_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this function to accept either vioscreen_ext_sample_id or registration_code. While we'll be using registration_code going forward, we can't assume that all legacy Vioscreen FFQs have been completed, so we need to support vioscreen_ext_sample_id as well. That should have a couple of changes:

  1. Add both parameters to the function definition, both being optional
  2. Try vioscreen_ext_sample_id first
  3. If vioscreen_ext_sample_id is None, try registration_code
  4. If that fails, return a ValueError

language_tag, survey_redirect_url,
vioscreen_ext_sample_id):
sample_id=None,
registration_code=None):
# assumes an instance of Transaction is already available
acct_repo = AccountRepo(transaction)
survey_template_repo = SurveyTemplateRepo(transaction)

if vioscreen_ext_sample_id:
# User is about to start a vioscreen survey for this sample
# record this in the database.
db_vioscreen_id = survey_template_repo.create_vioscreen_id(
account_id, source_id, vioscreen_ext_sample_id
)
else:
raise ValueError("Vioscreen Template requires "
"vioscreen_ext_sample_id parameter.")
if sample_id is None and registration_code is None:
return jsonify(code=400, message="Please pass sample id"
"or registration code"), 400

# User is about to start a vioscreen survey
# record this in the database.
db_vioscreen_id = \
survey_template_repo.create_vioscreen_id(account_id, source_id,
sample_id,
registration_code)

(birth_year, gender, height, weight) = \
survey_template_repo.fetch_user_basic_physiology(
Expand Down Expand Up @@ -171,7 +173,8 @@ def _remote_survey_url_spain_ffq(transaction, account_id, source_id):

def read_survey_template(account_id, source_id, survey_template_id,
language_tag, token_info, survey_redirect_url=None,
vioscreen_ext_sample_id=None):
vioscreen_ext_sample_id=None,
registration_code=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, we need to support both vioscreen_ext_sample_id and registration_code in this funciton.

_validate_account_access(token_info, account_id)

with Transaction() as t:
Expand All @@ -188,7 +191,8 @@ def read_survey_template(account_id, source_id, survey_template_id,
source_id,
language_tag,
survey_redirect_url,
vioscreen_ext_sample_id)
vioscreen_ext_sample_id,
registration_code)
elif survey_template_id == SurveyTemplateRepo.MYFOODREPO_ID:
url = _remote_survey_url_myfoodrepo(t,
account_id,
Expand Down
147 changes: 103 additions & 44 deletions microsetta_private_api/api/_vioscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.repo.survey_template_repo import SurveyTemplateRepo
from microsetta_private_api.repo.vioscreen_repo import (
VioscreenSessionRepo, VioscreenPercentEnergyRepo,
VioscreenRepo, VioscreenSessionRepo, VioscreenPercentEnergyRepo,
VioscreenDietaryScoreRepo, VioscreenSupplementsRepo,
VioscreenFoodComponentsRepo, VioscreenEatingPatternsRepo,
VioscreenMPedsRepo, VioscreenFoodConsumptionRepo
)


def _get_session_by_account_details(account_id, source_id, sample_id):
def _get_session_by_account_details(account_id, source_id,
SyedAli-789 marked this conversation as resolved.
Show resolved Hide resolved
sample_id=None,
registration_code=None,
timestamp=None):
with Transaction() as t:
surv_temp = SurveyTemplateRepo(t)
vio_sess = VioscreenSessionRepo(t)

vio_username = surv_temp.get_vioscreen_id_if_exists(account_id,
source_id,
sample_id)
vio_username = \
surv_temp.get_vioscreen_id_if_exists(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if vio_username is None:
return True, (jsonify(code=404, message="Username not found"), 404)

Expand All @@ -29,26 +35,36 @@ def _get_session_by_account_details(account_id, source_id, sample_id):
return False, vioscreen_session


def read_sample_vioscreen_session(account_id, source_id,
sample_id, token_info):
def read_vioscreen_session(account_id, source_id, token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

return jsonify(vioscreen_session[0].to_api()), 200


def read_sample_vioscreen_percent_energy(account_id, source_id,
sample_id, token_info):
def read_vioscreen_percent_energy(account_id, source_id, token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand All @@ -63,13 +79,18 @@ def read_sample_vioscreen_percent_energy(account_id, source_id,
return jsonify(vioscreen_percent_energy.to_api()), 200


def read_sample_vioscreen_dietary_score(account_id, source_id,
sample_id, token_info):
def read_vioscreen_dietary_score(account_id, source_id, token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand All @@ -84,13 +105,18 @@ def read_sample_vioscreen_dietary_score(account_id, source_id,
return jsonify([vds.to_api() for vds in vioscreen_dietary_scores]), 200


def read_sample_vioscreen_supplements(account_id, source_id,
sample_id, token_info):
def read_vioscreen_supplements(account_id, source_id, token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand All @@ -105,13 +131,19 @@ def read_sample_vioscreen_supplements(account_id, source_id,
return jsonify(vioscreen_supplements.to_api()), 200


def read_sample_vioscreen_food_components(account_id, source_id,
sample_id, token_info):
def read_vioscreen_food_components(account_id, source_id,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't sample_id, registration_code, and timestamp all be optional parameters here?

token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand All @@ -126,13 +158,18 @@ def read_sample_vioscreen_food_components(account_id, source_id,
return jsonify(vioscreen_food_components.to_api()), 200


def read_sample_vioscreen_eating_patterns(account_id, source_id,
sample_id, token_info):
def read_vioscreen_eating_patterns(account_id, source_id, token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand All @@ -147,12 +184,17 @@ def read_sample_vioscreen_eating_patterns(account_id, source_id,
return jsonify(vioscreen_eating_patterns.to_api()), 200


def read_sample_vioscreen_mpeds(account_id, source_id, sample_id, token_info):
def read_vioscreen_mpeds(account_id, source_id, token_info,
sample_id=None, registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand All @@ -166,13 +208,18 @@ def read_sample_vioscreen_mpeds(account_id, source_id, sample_id, token_info):
return jsonify(vioscreen_mpeds.to_api()), 200


def read_sample_vioscreen_food_consumption(account_id, source_id,
sample_id, token_info):
def read_vioscreen_food_consumption(account_id, source_id, token_info,
sample_id=None,
registration_code=None,
timestamp=None):
_validate_account_access(token_info, account_id)

is_error, vioscreen_session = _get_session_by_account_details(account_id,
source_id,
sample_id)
is_error, vioscreen_session = \
_get_session_by_account_details(account_id,
source_id,
sample_id,
registration_code,
timestamp)
if is_error:
return vioscreen_session

Expand Down Expand Up @@ -240,3 +287,15 @@ def get_vioscreen_food_components_descriptions(token_info):
return jsonify(code=404, message="Food Components not found"), 404

return jsonify(descriptions)


def get_vioscreen_sessions(account_id, source_id):
"""Obtain vioscreen sessions if it exists"""
with Transaction() as t:
vio_session = VioscreenRepo(t)
vioscreen_session = vio_session.get_vioscreen_sessions(account_id,
source_id)
if vioscreen_session is None or len(vioscreen_session) == 0:
return jsonify(code=404, message="No vioscreens found"), 404
else:
return jsonify({"vioscreens": vioscreen_session})
Loading