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

Conversation

SyedAli-789
Copy link
Contributor

No description provided.

@@ -540,8 +538,7 @@ def get_vioscreen_sample_to_user(self):
WHERE vio_id IS NOT NULL""")
return {r[0]: r[1] for r in cur.fetchall()}

def create_vioscreen_id(self, account_id, source_id,
vioscreen_ext_sample_id):
def create_vioscreen_id(self, 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 to adjust the logic on this function, since a given source can have more than one vioscreen ID associated. Since users will unlock access using a registration code, go ahead and add activation_code as a column to the vioscreen_registry table (column type = varchar). Then, you need to pass the registration_code into get_vioscreen_id_if_exists. If it doesn't, create the new record in vioscreen_registry, including the registration_code.

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):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update all of the functions in _vioscreen.py that call get_vioscreen_id_if_exists to include the new optional parameters (both in how they call that function and their own function definition) so we can update the full stack of functions to work with the intended logic. Also, please update the parameters in the YAML file accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

Given that a source can have multiple sessions, will this function now return an iterable? If so then the functions which call it most likely all need to be updated to handle multiple sessions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, it should be updated to to use the switching logic between sample_id, registration_code, timestamp, or default to most recent.

microsetta_private_api/repo/vioscreen_repo.py Outdated Show resolved Hide resolved
microsetta_private_api/api/_vioscreen.py Outdated Show resolved Hide resolved
microsetta_private_api/api/microsetta_private_api.yaml Outdated Show resolved Hide resolved
Copy link
Member

@wasade wasade left a comment

Choose a reason for hiding this comment

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

Added a few comments

@cassidysymons, is there going to be a need to migrate existing data in anyway?

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):
Copy link
Member

Choose a reason for hiding this comment

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

Given that a source can have multiple sessions, will this function now return an iterable? If so then the functions which call it most likely all need to be updated to handle multiple sessions.



def get_vioscreens(account_id, source_id):
"""Obtain a vioscreen ID if it exists"""
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should note that multiple vioscreen IDs may be returned

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. @SyedAli-789 please clarify the comment for this function.

microsetta_private_api/api/microsetta_private_api.yaml Outdated Show resolved Hide resolved
application/json:
schema:
type:
object
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is inaccurate, isn't the return an array of object?

if rows is None or len(rows) == 0:
return None
else:
return rows
Copy link
Member

Choose a reason for hiding this comment

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

Can this return instances of the VioscreenSession model?

@cassidysymons
Copy link
Collaborator

Added a few comments

@cassidysymons, is there going to be a need to migrate existing data in anyway?

@wasade Not that I'm aware of. We're leaving the sample_id column in place and providing a way to search for Vioscreen sessions for historical records using that column.

@wasade
Copy link
Member

wasade commented Oct 28, 2022

@cassidysymons, thanks. We currently pull out sample <-> vioscreen ID associations to construct FFQ metadata suitable for analysis (see #461) -- it's going to be important that that method remain correct in light of the changes here.

@wasade wasade closed this Oct 28, 2022
@wasade wasade reopened this Oct 28, 2022
@wasade
Copy link
Member

wasade commented Oct 28, 2022

Ah sorry, clicked the wrong button

microsetta_private_api/api/_survey.py Outdated Show resolved Hide resolved
microsetta_private_api/api/_survey.py Outdated Show resolved Hide resolved
microsetta_private_api/api/_survey.py Outdated Show resolved Hide resolved
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):
Copy link
Collaborator

Choose a reason for hiding this comment

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

No, it should be updated to to use the switching logic between sample_id, registration_code, timestamp, or default to most recent.

microsetta_private_api/api/_vioscreen.py Outdated Show resolved Hide resolved
microsetta_private_api/api/_vioscreen.py Outdated Show resolved Hide resolved
microsetta_private_api/api/_vioscreen.py Outdated Show resolved Hide resolved
microsetta_private_api/api/_vioscreen.py Outdated Show resolved Hide resolved


def get_vioscreens(account_id, source_id):
"""Obtain a vioscreen ID if it exists"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. @SyedAli-789 please clarify the comment for this function.

microsetta_private_api/api/microsetta_private_api.yaml Outdated Show resolved Hide resolved
Comment on lines 1846 to 1849
if now.month > 10:
delta = relativedelta(month=1, year=now.year+1)
else:
delta = relativedelta(month=now.month+2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please back out this change, the code as is - delta = relativedelta(months=now.month+2) - is a more concise approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted the changes

"GROUP BY vioscreen_registry.vio_id, "
"ag_login_surveys.creation_time "
"ORDER BY ag_login_surveys.creation_time DESC ",
(account_id, source_id))
rows = cur.fetchall()
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a fetchone?

"AND vioscreen_registry.source_id = %s "
"AND deleted=false "
"AND ag_login_surveys.creation_time >= %s"
"GROUP BY vioscreen_registry.vio_id, "
Copy link
Member

@wasade wasade Nov 16, 2022

Choose a reason for hiding this comment

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

Since we're returning the most recent survey below, is the GROUP BY needed?

"WHERE vioscreen_registry.account_id = %s "
"AND vioscreen_registry.source_id = %s "
"AND deleted=false "
"GROUP BY vioscreen_registry.vio_id, "
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@@ -1656,3 +1656,24 @@ def _get_vioscreen_status(self, survey_id):
if row is None:
return None
return row[0]

def get_vioscreen_sessions(self, account_id, source_id):
Copy link
Member

Choose a reason for hiding this comment

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

Can a unit test for this method be added?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@SyedAli-789 Please add unit tests for this function to repo/test/test_vioscreen.py. There should be one test that reflects the result of no rows being found and one test that reflects the result of one or more results being found.

Comment on lines 1665 to 1670
cur.execute("SELECT * FROM vioscreen_sessions WHERE"
"username IN"
"(SELECT vio_id FROM vioscreen_registry WHERE "
"account_id=%s AND "
"source_id=%s)",
(account_id, source_id))
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the same as

SELECT vs.*
FROM vioscreen_sessions vs 
JOIN vioscreen_registry vr ON vs.username = vr.vio_id
WHERE account_id=%s AND source_id=%s

@cassidysymons cassidysymons mentioned this pull request Nov 28, 2022
@cassidysymons cassidysymons merged commit bd04cf1 into biocore:master-overhaul Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants