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

survey association lock removal #318

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Changes from 5 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
16 changes: 1 addition & 15 deletions microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ def post_create_human_source(*, account_id=None, body=None):
return consent_output

session.pop(SOURCE_ID)

# Yes, "None" is coming through as a string in this instance, not as
ayobi marked this conversation as resolved.
Show resolved Hide resolved
# an actual None type.
if body["sample_ids"] != "None":
Expand Down Expand Up @@ -2768,14 +2769,6 @@ def post_claim_samples(*, account_id=None, source_id=None, body=None,
if has_error:
return survey_output

# TODO: this will have to get more nuanced when we add animal surveys?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there are still some pieces that can come out of this function, e.g. the survey_output section directly above (GitHub's UI won't let me contextually comment on lines that aren't being changed in the PR). Also, the comment above the function definition is no longer applicable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, so all we're left here now is just the reconsent if needed and claiming of a sample

for curr_sample_id in sample_ids_to_claim:
# Claim sample
has_error, sample_output, _ = ApiRequest.post(
'/accounts/{0}/sources/{1}/samples'.format(
account_id, source_id),
json={"sample_id": curr_sample_id})
if has_error:
return sample_output

# Grab all primary and covid surveys from the source and associate with
# newly claimed samples; non-human sources always have none of these
survey_ids_to_associate_with_samples = [
x['survey_id'] for x in survey_output
if x['survey_template_id'] in [1, 6]
]

# TODO: Any of these requests may fail independently, but we don't
# have a good policy to deal with partial failures. Currently, we
# abort early but that will result in some set of associations being
Expand All @@ -2790,13 +2783,6 @@ def post_claim_samples(*, account_id=None, source_id=None, body=None,
if has_error:
return sample_output

# Associate the input answered surveys with this sample.
for survey_id in survey_ids_to_associate_with_samples:
sample_survey_output = _associate_sample_to_survey(
account_id, source_id, curr_sample_id, survey_id)
if sample_survey_output is not None:
return sample_survey_output

return redirect(
"/accounts/%s/sources/%s/kits" %
(account_id, source_id)
Expand Down
Loading