def get(self): open_humans = self.get_secure_cookie('open-humans') # If the user isn't authenticated render the page to allow them to # authenticate if not open_humans: ag_login_id = ag_data.get_user_for_kit(self.current_user) human_participants = ag_data.getHumanParticipants(ag_login_id) survey_ids = {} for participant_name in human_participants: survey_id = ag_data.get_survey_id(ag_login_id, participant_name) if survey_id: survey_ids[participant_name] = survey_id self.render('open-humans.html', skid=self.current_user, survey_ids=survey_ids, access_token=None, origin=self.coerce_origin(), open_humans_home_url=self._HOME_URL, open_humans_research_url=self._RESEARCH_URL, open_humans_api_url=self._API_URL) return open_humans = escape.json_decode(open_humans) self.open_humans_request( '/american-gut/user-data/', self._on_user_data_cb, access_token=open_humans['access_token'])
def post(self, participant_name): text = text_locale['participant_overview.html'] participant_name = participant_name.strip('/') # for nginx skid = self.current_user ag_login_id = ag_data.get_user_for_kit(skid) barcodes = ag_data.getParticipantSamples(ag_login_id, participant_name) if barcodes: ebi_submitted = any(ag_data.is_deposited_ebi(b['barcode']) for b in barcodes) else: ebi_submitted = False # Check if we have to remove the participant participant_to_remove = self.get_argument("remove", None) if participant_to_remove and not ebi_submitted: barcodes = ag_data.getParticipantSamples( ag_login_id, participant_to_remove) # Remove all the samples attached to the participant for bc in barcodes: ag_data.deleteSample(bc['barcode'], ag_login_id) # Remove the participant ag_data.deleteAGParticipantSurvey( ag_login_id, participant_to_remove) # Redirect to portal self.redirect(media_locale['SITEBASE'] + "/authed/portal/") return participant_type = self.get_argument('participant_type') vioscreen_status = None vioscreen_text = '' survey_id = ag_data.get_survey_id(ag_login_id, participant_name) if survey_id is None: raise HTTPError(404, "Could not retrieve survey details for " "participant '%s'" % participant_name) else: vioscreen_status = ag_data.get_vioscreen_status(survey_id) url = ("https://vioscreen.com/remotelogin.aspx?Key=%s" "&RegCode=KLUCB" % url_escape(encrypt_key(survey_id))) # Magic number 3 is the vioscreen code for complete survey if vioscreen_status is not None and vioscreen_status != 3: vioscreen_text = text['VIOSCREEN_CONTINUE'] % url elif vioscreen_status is not None: vioscreen_text = text['VIOSCREEN_COMPLETE'] else: vioscreen_text = text['VIOSCREEN_START'] % url # Get the list of samples for this participant samples = ag_data.getParticipantSamples(ag_login_id, participant_name) self.render('participant_overview.html', skid=skid, participant_name=participant_name, survey_id=survey_id, participant_type=participant_type, samples=samples, vioscreen_text=vioscreen_text, ebi_submitted=ebi_submitted)
def _on_user_data_cb(self, user_data): open_humans = escape.json_decode(self.get_secure_cookie('open-humans')) try: link_survey_id = escape.json_decode( escape.url_unescape(self.get_cookie('link-survey-id'))) except AttributeError: link_survey_id = None ag_login_id = ag_data.get_user_for_kit(self.current_user) human_participants = ag_data.getHumanParticipants(ag_login_id) survey_ids = {} if link_survey_id: self.open_humans_request( '/american-gut/user-data/', self._on_post_user_data_cb, method='PATCH', body={'data': {'surveyIds': link_survey_id}}, access_token=open_humans['access_token']) return for participant_name in human_participants: survey_id = ag_data.get_survey_id(ag_login_id, participant_name) if survey_id: survey_ids[participant_name] = survey_id self.render('open-humans.html', skid=self.current_user, survey_ids=survey_ids, access_token=open_humans['access_token'], origin=self.coerce_origin(), open_humans_home_url=self._HOME_URL, open_humans_research_url=self._RESEARCH_URL, open_humans_api_url=self._API_URL)