def post(self):
        bc_to_remove = self.get_argument("remove", None)
        if bc_to_remove:
            ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
            AG_DATA_ACCESS.deleteSample(bc_to_remove, ag_login_id)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        self._sample_overview_renderer()
Пример #2
0
    def post(self):
        bc_to_remove = self.get_argument("remove", None)
        if bc_to_remove:
            ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
            AG_DATA_ACCESS.deleteSample(bc_to_remove, ag_login_id)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        self._sample_overview_renderer()
    def post(self, participant_name):
        skid = self.current_user
        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)

        # Check if we have to remove the participant
        participant_to_remove = self.get_argument("remove", None)
        if participant_to_remove:
            barcodes = AG_DATA_ACCESS.getParticipantSamples(
                ag_login_id, participant_to_remove)
            # Remove all the samples attached to the participant
            for bc in barcodes:
                AG_DATA_ACCESS.deleteSample(bc['barcode'], ag_login_id)
            # Remove the participant
            AG_DATA_ACCESS.deleteAGParticipant(
                ag_login_id, participant_to_remove)
            # Redirect to portal
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/")

        participant_type = self.get_argument('participant_type')

        try:
            survey_details = AG_DATA_ACCESS.getAGSurveyDetails(
                ag_login_id, participant_name)
        except:
            raise HTTPError(404, "Could not retrieve survey details for "
                            "participant '%s'" % participant_name)

        # The defaults must be added to the page as hidden form inputs, in
        # case the user clicks edit survey
        defaults = {}
        for k, v in sorted(survey_details.items()):
            suffix = '_default'
            # do NOT suffix these fields
            if k in ('consent', 'parent_1_name', 'parent_2_name',
                     'deceased_parent', 'participant_email',
                     'participant_name', 'ag_login_id'):
                defaults[k] = v

            # if the name of the field ends in a number, it's a multiple, and
            # should be written out differently UNLESS it's migraine_factor_#
            # or mainfactor_other_# don't like to special-case like this, but
            # there's no other way to tell what's a multiple and what's not
            if k[-1] in map(str, range(10)) \
                    and not k.startswith('migraine_factor_') \
                    and not k.startswith('mainfactor_other_'):
                k = k.rsplit('_', 1)[0]
                defaults[k+'_default[]'] = v

        # Get the list of samples for this participant
        samples = AG_DATA_ACCESS.getParticipantSamples(ag_login_id,
                                                       participant_name)

        self.render('participant_overview.html', defaults=defaults, skid=skid,
                    participant_name=participant_name,
                    participant_type=participant_type, samples=samples)
    def post(self):
        tl = text_locale['handlers']
        deceased_parent = self.get_argument("deceased_parent", None)
        participant_name = self.get_argument("participant_name")
        is_juvenile = self.get_argument("is_juvenile", 'off')

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
        kit_email = AG_DATA_ACCESS.get_user_info(self.current_user)['email']

        # Get the list of participants attached to that login id
        participants = AG_DATA_ACCESS.getHumanParticipants(ag_login_id)

        # Check if the participant is on the exceptions list
        is_exception = (
            participant_name
            in AG_DATA_ACCESS.getParticipantExceptions(ag_login_id))

        # If the participant already exists, stop them outright
        if participant_name in participants:
            errmsg = tl['PARTICIPANT_EXISTS'] % participant_name
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'off' and is_exception:
            errmsg = ("We are expecting a survey from that juvenile user (%s)"
                      % participant_name)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'on':
            # If they aren't already an exception, we need to verify them
            if not is_exception:
                juvenile_age = self.get_argument("juvenile_age")
                parent_1_name = self.get_argument("parent_1_name")
                parent_2_name = self.get_argument("parent_2_name")

                alert_message = tl['MINOR_PARENTAL_BODY']

                subject = ("AGJUVENILE: %s (ag_login_id: %s) is a child"
                           % (participant_name, ag_login_id))

                message = MESSAGE_TEMPLATE % (participant_name, juvenile_age,
                                              parent_1_name, parent_2_name,
                                              deceased_parent,
                                              self.current_user, kit_email)

                try:
                    send_email(message, subject, sender=kit_email)
                    alert_message = tl['MESSAGE_SENT']
                except:
                    alert_message = media_locale['EMAIL_ERROR']

                self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % alert_message)

        self.redirect(media_locale['SITEBASE'] + "/authed/survey_main/")
Пример #5
0
    def get(self):
        kit_id = self.current_user
        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(kit_id)
        kit_barcodes = AG_DATA_ACCESS.getAvailableBarcodes(ag_login_id)
        participant_name = self.get_argument('participant_name',
                                             'environmetal')

        form = LogSample()
        form.barcode.choices = [(v, v) for v in kit_barcodes]
        form.sample_site.choices = self._get_sample_sites()

        self.render('add_sample.html', skid=kit_id,
                    kit_barcodes=kit_barcodes,
                    participant_name=participant_name,
                    form=form)
Пример #6
0
    def on_message(self, msg):
        tl = text_locale['handlers']
        skid = self.current_user
        participant_name = msg

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)
        human_participants = AG_DATA_ACCESS.getHumanParticipants(ag_login_id)
        animal_participants = AG_DATA_ACCESS.getAnimalParticipants(ag_login_id)

        if participant_name in (human_participants + animal_participants):
            # if the participant already exists in the system, fail nicely
            output_message = (tl['PARTICIPANT_EXISTS'] % participant_name)
        else:
            # otherwise, success!
            output_message = 'success'

        self.write_message(output_message)
Пример #7
0
    def post(self):
        tl = text_locale['handlers']
        deceased_parent = self.get_argument("deceased_parent", None)
        participant_name = self.get_argument("participant_name")
        participant_email = self.get_argument("participant_email")
        is_juvenile = self.get_argument("is_juvenile", 'off')
        parent_1_name = self.get_argument("parent_1_name", None)
        parent_2_name = self.get_argument("parent_2_name", None)

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
        kit_email = AG_DATA_ACCESS.get_user_info(self.current_user)['email']

        # Check if the participant is on the exceptions list
        is_exception = (
            participant_name
            in AG_DATA_ACCESS.getParticipantExceptions(ag_login_id))

        # If the participant already exists, stop them outright
        if AG_DATA_ACCESS.check_if_consent_exists(ag_login_id, participant_name):
            errmsg = url_escape(tl['PARTICIPANT_EXISTS'] % participant_name)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'off' and is_exception:
            errmsg = url_escape(tl["JUVENILE_CONSENT_EXPECTED"] %
                                participant_name)
            self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'on':
            # If they aren't already an exception, we need to verify them
            if not is_exception:
                alert_message = tl['MINOR_PARENTAL_BODY']

                subject = ("AGJUVENILE: %s (ag_login_id: %s) is a child"
                           % (participant_name, ag_login_id))

                message = MESSAGE_TEMPLATE % (participant_name,
                                              parent_1_name, parent_2_name,
                                              deceased_parent,
                                              self.current_user, kit_email)

                try:
                    send_email(message, subject, sender=kit_email)
                    alert_message = tl['MESSAGE_SENT']
                except:
                    alert_message = media_locale['EMAIL_ERROR']

                self.redirect(media_locale['SITEBASE'] + "/authed/portal/?errmsg=%s" % alert_message)

        human_survey_id = binascii.hexlify(os.urandom(8))
        consent= {'participant_name': participant_name,
                  'participant_email': participant_email,
                  'parent_1_name': parent_1_name,
                  'parent_2_name': parent_2_name,
                  'is_juvenile': True if is_juvenile == 'on' else False,
                  'deceased_parent': deceased_parent,
                  'login_id': ag_login_id,
                  'survey_id': human_survey_id}

        r_server.hset(human_survey_id, 'consent', dumps(consent))
        r_server.expire(human_survey_id, 86400)

        self.set_secure_cookie('human_survey_id', human_survey_id)
        self.redirect(media_locale['SITEBASE'] + "/authed/survey_main/")
Пример #8
0
    def post(self):
        tl = text_locale['handlers']
        deceased_parent = self.get_argument("deceased_parent", None)
        participant_name = self.get_argument("participant_name")
        participant_email = self.get_argument("participant_email")
        is_juvenile = self.get_argument("is_juvenile", 'off')
        parent_1_name = self.get_argument("parent_1_name", None)
        parent_2_name = self.get_argument("parent_2_name", None)

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(self.current_user)
        kit_email = AG_DATA_ACCESS.get_user_info(self.current_user)['email']

        # Check if the participant is on the exceptions list
        is_exception = (
            participant_name
            in AG_DATA_ACCESS.getParticipantExceptions(ag_login_id))

        # If the participant already exists, stop them outright
        if AG_DATA_ACCESS.check_if_consent_exists(ag_login_id,
                                                  participant_name):
            errmsg = url_escape(tl['PARTICIPANT_EXISTS'] % participant_name)
            self.redirect(media_locale['SITEBASE'] +
                          "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'off' and is_exception:
            errmsg = url_escape(tl["JUVENILE_CONSENT_EXPECTED"] %
                                participant_name)
            self.redirect(media_locale['SITEBASE'] +
                          "/authed/portal/?errmsg=%s" % errmsg)

        if is_juvenile == 'on':
            # If they aren't already an exception, we need to verify them
            if not is_exception:
                alert_message = tl['MINOR_PARENTAL_BODY']

                subject = ("AGJUVENILE: %s (ag_login_id: %s) is a child" %
                           (participant_name, ag_login_id))

                message = MESSAGE_TEMPLATE % (participant_name, parent_1_name,
                                              parent_2_name, deceased_parent,
                                              self.current_user, kit_email)

                try:
                    send_email(message, subject, sender=kit_email)
                    alert_message = tl['MESSAGE_SENT']
                except:
                    alert_message = media_locale['EMAIL_ERROR']

                self.redirect(media_locale['SITEBASE'] +
                              "/authed/portal/?errmsg=%s" % alert_message)

        human_survey_id = binascii.hexlify(os.urandom(8))
        consent = {
            'participant_name': participant_name,
            'participant_email': participant_email,
            'parent_1_name': parent_1_name,
            'parent_2_name': parent_2_name,
            'is_juvenile': True if is_juvenile == 'on' else False,
            'deceased_parent': deceased_parent,
            'login_id': ag_login_id,
            'survey_id': human_survey_id
        }

        r_server.hset(human_survey_id, 'consent', dumps(consent))
        r_server.expire(human_survey_id, 86400)

        self.set_secure_cookie('human_survey_id', human_survey_id)
        self.redirect(media_locale['SITEBASE'] + "/authed/survey_main/")
Пример #9
0
    def post(self):
        skid = self.current_user
        tl = text_locale['handlers']
        participant_name = self.get_argument('animal_name')

        # Add values to tables
        singles = {}
        singles['type'] = self.get_argument('type', default=None)
        singles['origin'] = self.get_argument('origin', default=None)
        singles['age'] = self.get_argument('age', default=None)
        singles['gender'] = self.get_argument('gender', default=None)
        singles['setting'] = self.get_argument('setting', default=None)
        singles['weight'] = self.get_argument('weight', default=None)
        singles['diet'] = self.get_argument('diet', default=None)
        singles['food_source_store'] = self.get_argument('food_source_store',
                                              default=None)
        singles['food_source_human'] = self.get_argument('food_source_human',
                                              default=None)
        singles['food_source_wild'] = self.get_argument('food_source_wild', default=None)
        singles['food_type'] = self.get_argument('food_type', default=None)
        singles['organic_food'] = self.get_argument('organic_food',
                                                    default=None)
        singles['grain_free_food'] = self.get_argument('grain_free_food',
                                                       default=None)
        singles['living_status'] = self.get_argument('living_status',
                                                     default=None)
        singles['outside_time'] = self.get_argument('outside_time',
                                                    default=None)
        singles['toilet'] = self.get_argument('toilet', default=None)
        singles['coprophage'] = self.get_argument('coprophage', default=None)
        singles['comments'] = self.get_argument('comments', default=None)

        multiples = {k: v[0] for k, v in self.request.body_arguments.items()
                     if k.startswith('human_') or k.startswith('pet_')}

        ag_login_id = AG_DATA_ACCESS.get_user_for_kit(skid)
        AG_DATA_ACCESS.deleteAGParticipant(ag_login_id, participant_name)

        for sample in AG_DATA_ACCESS.getParticipantSamples(ag_login_id,
                participant_name):
            AG_DATA_ACCESS.deleteSample(sample['barcode'], ag_login_id)

        # Create the new participant if it doesn't exist (merges)
        AG_DATA_ACCESS.addAGAnimalParticipant(ag_login_id, participant_name)

        for field, value in singles.items():
            if value is None:
                continue

            AG_DATA_ACCESS.addAGGeneralValue(ag_login_id, participant_name,
                                             field, value)
            AG_DATA_ACCESS.addAGSingle(ag_login_id, participant_name,
                                       field, value, 'ag_animal_survey')

        for field, value in multiples.items():
            if value is None:
                continue

            AG_DATA_ACCESS.addAGGeneralValue(ag_login_id, participant_name,
                                             field, value)
            AG_DATA_ACCESS.insertAGMultiple(ag_login_id, participant_name,
                                            field, value)

        message = urlencode([('errmsg', tl['SUCCESSFULLY_ADDED'] %
                              participant_name)])
        self.redirect(media_locale['SITEBASE'] + '/authed/portal/?%s' % message)