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

fixed false assumption that a participant (source) has only one surve… #637

Merged
merged 4 commits into from
Feb 6, 2017
Merged
Changes from all 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
33 changes: 21 additions & 12 deletions amgut/lib/data_access/ag_data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,28 +303,34 @@ def deleteAGParticipantSurvey(self, ag_login_id, participant_name):
JOIN ag_consent USING (ag_login_id, participant_name)
WHERE ag_login_id = %s AND participant_name = %s"""
TRN.add(sql, (ag_login_id, participant_name))
survey_id, participant_email = TRN.execute_fetchindex()[0]
# collect all survey_ids and participant_names, since at least the
# former might be more than one.
survey_ids = set()
participant_emails = set()
for hit in TRN.execute_fetchindex():
survey_ids.add(hit[0])
participant_emails.add(hit[1])

sql = "DELETE FROM survey_answers WHERE survey_id = %s"
TRN.add(sql, [survey_id])
sql = "DELETE FROM survey_answers WHERE survey_id IN %s"
TRN.add(sql, [tuple(survey_ids)])

sql = "DELETE FROM survey_answers_other WHERE survey_id = %s"
TRN.add(sql, [survey_id])
sql = "DELETE FROM survey_answers_other WHERE survey_id IN %s"
TRN.add(sql, [tuple(survey_ids)])

# Reset survey attached to barcode(s)
for info in self.getParticipantSamples(ag_login_id,
participant_name):
self.deleteSample(info['barcode'], ag_login_id)

sql = "DELETE FROM promoted_survey_ids WHERE survey_id = %s"
TRN.add(sql, [survey_id])
sql = "DELETE FROM promoted_survey_ids WHERE survey_id IN %s"
TRN.add(sql, [tuple(survey_ids)])

# Delete last due to foreign keys
sql = "DELETE FROM ag_kit_barcodes WHERE survey_id = %s"
TRN.add(sql, [survey_id])
sql = "DELETE FROM ag_kit_barcodes WHERE survey_id IN %s"
TRN.add(sql, [tuple(survey_ids)])

sql = "DELETE FROM ag_login_surveys WHERE survey_id = %s"
TRN.add(sql, [survey_id])
sql = "DELETE FROM ag_login_surveys WHERE survey_id IN %s"
TRN.add(sql, [tuple(survey_ids)])

sql = """DELETE FROM ag_consent
WHERE ag_login_id = %s AND participant_name = %s"""
Expand All @@ -333,7 +339,10 @@ def deleteAGParticipantSurvey(self, ag_login_id, participant_name):
sql = """INSERT INTO ag.consent_revoked
(ag_login_id,participant_name, participant_email)
VALUES (%s, %s, %s)"""
TRN.add(sql, [ag_login_id, participant_name, participant_email])
sql_args = [[ag_login_id, participant_name, pemail]
for pemail in participant_emails]
TRN.add(sql, sql_args, many=True)
TRN.execute()

def get_withdrawn(self):
"""Gets teh list of withdrawn participants and information
Expand Down