# Path: amgut/lib/util.py
# def survey_vioscreen(survey_id, consent_info, internal_surveys=[]):
#     """Return a formatted text block and URL for the external survey"""
#     tl = text_locale['human_survey_completed.html']
#     embedded_text = tl['SURVEY_VIOSCREEN']
#     regcode = AMGUT_CONFIG.vioscreen_regcode
#     url = ("https://vioscreen.com/remotelogin.aspx?Key=%s&RegCode=%s" %
#            (url_escape(encrypt_key(survey_id)), regcode))
#     return embedded_text % url


from datetime import datetime
from wtforms import (Form, SelectField, DateField, DateTimeField, TextField,
                     HiddenField, validators)
from tornado.web import authenticated
from tornado import escape
from future.utils import viewitems
from amgut.connections import ag_data
from amgut.lib.util import survey_vioscreen
from amgut.handlers.base_handlers import BaseHandler
from amgut import media_locale
    sample_time = DateTimeField(validators=[required("Required field")],
                                format='%I:%M %p')
    notes = TextField('notes')


class AddHumanFFQHandler(BaseHandler):
    @authenticated
    def post(self):
        self.redirect(media_locale['SITEBASE'] + '/authed/portal/')

    @authenticated
    def get(self):
        ag_login_id = ag_data.get_user_for_kit(self.current_user)
        barcode = self.get_secure_cookie('barcode')
        participant_name = self.get_secure_cookie('participant_name')
        self.clear_cookie('barcode')
        self.clear_cookie('participant_name')

        if barcode is None or participant_name is None:
            self.set_status(404)
            self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
            return
        else:
            barcode = escape.json_decode(barcode)
            participant_name = escape.json_decode(participant_name)

        new_survey_id = ag_data.get_new_survey_id()
        ag_data.associate_barcode_to_survey_id(ag_login_id, participant_name,
                                               barcode, new_survey_id)
        ag_data.updateVioscreenStatus(new_survey_id, 0)  # 0 -> not started

# Path: amgut/lib/util.py
# def survey_vioscreen(survey_id, consent_info, internal_surveys=[]):
#     """Return a formatted text block and URL for the external survey"""
#     tl = text_locale['human_survey_completed.html']
#     embedded_text = tl['SURVEY_VIOSCREEN']
#     regcode = AMGUT_CONFIG.vioscreen_regcode
#     url = ("https://vioscreen.com/remotelogin.aspx?Key=%s&RegCode=%s" %
#            (url_escape(encrypt_key(survey_id)), regcode))
#     return embedded_text % url


# Path: amgut/handlers/add_sample.py
from datetime import datetime
from wtforms import (Form, SelectField, DateField, DateTimeField, TextField,
                     HiddenField, validators)
from tornado.web import authenticated
from tornado import escape
from future.utils import viewitems
from amgut.connections import ag_data
from amgut.lib.util import survey_vioscreen
from amgut.handlers.base_handlers import BaseHandler
from amgut import media_locale

    sample_time = DateTimeField(validators=[required("Required field")],
                                format='%I:%M %p')
    notes = TextField('notes')


class AddHumanFFQHandler(BaseHandler):
    @authenticated
    def post(self):
        self.redirect(media_locale['SITEBASE'] + '/authed/portal/')

    @authenticated
    def get(self):
        ag_login_id = ag_data.get_user_for_kit(self.current_user)
        barcode = self.get_secure_cookie('barcode')
        participant_name = self.get_secure_cookie('participant_name')
        self.clear_cookie('barcode')
        self.clear_cookie('participant_name')

        if barcode is None or participant_name is None:
            self.set_status(404)
            self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
            return
        else:
            barcode = escape.json_decode(barcode)
            participant_name = escape.json_decode(participant_name)

        new_survey_id = ag_data.get_new_survey_id()
        ag_data.associate_barcode_to_survey_id(ag_login_id, participant_name,
                                               barcode, new_survey_id)
        ag_data.updateVioscreenStatus(new_survey_id, 0)  # 0 -> not started

        dat = survey_vioscreen(new_survey_id, None, None)