-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from 41 commits
f21eaf9
6ac01df
8c08b70
4c8b06d
7ea64f7
50588ff
8ce863c
8c3e68d
8213605
2ec55e6
908bf30
55a37a3
626c901
bed5f7a
d5acabc
e1319bc
496c48c
0c714a9
a5ecb04
fe1f8af
bb12051
98db063
f734bab
e185172
17dcca3
e54e44a
fd3b6aa
81ce521
1cb21d9
230efb6
84650f5
bffb901
e4dc6a1
4ace98a
b2ca0e7
97eb2fe
75cc25a
02bfdaf
27f131b
9c1d3f3
827c2a1
87d4f25
ecdfeb7
8c46eee
5147c5f
3f8aaaa
bcd996e
5cde512
1bcae76
ec5e9f8
d54fc81
7f69b45
a33654c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
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( | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
@@ -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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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}) |
There was a problem hiding this comment.
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: