def _sample_overview_renderer(self):
        barcode = self.get_argument('barcode', None)
        if barcode is None:
            self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
            return

        has_access = ag_data.check_access(self.current_user, barcode)
        if not has_access:
            self.set_status(403)
            self.render("403.html", skid=self.current_user)
            return

        sample_data = ag_data.getAGBarcodeDetails(barcode)

        if not sample_data:
            self.set_status(404)
            self.render("404.html", skid=self.current_user)
            return

        web_barcode_pdf, web_barcode_txt = _get_data_path(barcode)
        unidentified_results = _get_per_sample_results(barcode)
        per_sample_data = _get_per_sample_data(barcode)

        sample_time = sample_data['sample_time']
        sample_date = sample_data['sample_date']

        status = sample_data['status']
        if status is None:
            bgcolor = '#FFF'
            status = 'Submitted'
        elif status == 'Received':
            bgcolor = '#AFA'
        else:
            bgcolor = '#FFF'

        sample_origin = sample_data['site_sampled']
        if sample_origin is None:
            sample_origin = sample_data['environment_sampled']

        notes = sample_data['notes']
        if notes is None:
            notes = ''

        self.render('sample_overview.html', skid=self.current_user,
                    barcode_pdf=web_barcode_pdf, barcode_txt=web_barcode_txt,
                    bgcolor=bgcolor, status=status, barcode=barcode,
                    sample_origin=sample_origin, sample_date=sample_date,
                    sample_time=sample_time, notes=notes,
                    unidentified_results=unidentified_results,
                    per_sample_data=per_sample_data)
    def _sample_overview_renderer(self):
        barcode = self.get_argument('barcode', None)
        if barcode is None:
            self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
            return

        sample_data = ag_data.getAGBarcodeDetails(barcode)

        fs_base = AMGUT_CONFIG.base_data_dir
        web_base = "%s/results" % media_locale['SITEBASE']

        fs_barcode_pdf = _format_data_path(fs_base, 'pdfs', barcode, 'pdf')
        fs_barcode_txt = _format_data_path(fs_base, 'taxa-summaries', barcode,
                                        'txt')
        web_barcode_pdf = _format_data_path(web_base, 'pdfs', barcode, 'pdf')
        web_barcode_txt = _format_data_path(web_base, 'taxa-summaries',
                                            barcode, 'txt')

        if not os.path.exists(fs_barcode_pdf):
            web_barcode_pdf = None
        if not os.path.exists(fs_barcode_txt):
            web_barcode_txt = None

        sample_time = sample_data['sample_time']
        sample_date = sample_data['sample_date']

        status = sample_data['status']
        if status is None:
            bgcolor = '#FFF'
            status = 'Submitted'
        elif status == 'Received':
            bgcolor = '#AFA'
        else:
            bgcolor = '#FFF'

        sample_origin = sample_data['site_sampled']
        if sample_origin is None:
            sample_origin = sample_data['environment_sampled']

        notes = sample_data['notes']
        if notes is None:
            notes = ''

        self.render('sample_overview.html', skid=self.current_user,
                    barcode_pdf=web_barcode_pdf, barcode_txt=web_barcode_txt,
                    bgcolor=bgcolor, status=status, barcode=barcode,
                    sample_origin=sample_origin, sample_date=sample_date,
                    sample_time=sample_time, notes=notes)
Exemple #3
0
    def test_post_general(self):
        self.mock_login(
            ag_data.ut_get_supplied_kit_id(
                'd8592c74-9694-2135-e040-8a80115d6401'))
        # make sure barcode properly removed
        self.assertIn(
            '000005628',
            ag_data.getAvailableBarcodes(
                'd8592c74-9694-2135-e040-8a80115d6401'))

        # Run test
        response = self.post(
            '/authed/add_sample_general/', {
                'participant_name': 'environmental',
                'barcode': '000005628',
                'sample_site': 'Biofilm',
                'sample_date': '12/11/2014',
                'sample_time': '10:12 PM',
                'notes': 'TESTING TORNADO LOGGING GENERAL'
            })
        self.assertEqual(response.code, 200)
        self.assertTrue(response.effective_url.endswith('/authed/portal/'))

        obs = ag_data.getAGBarcodeDetails('000005628')
        exp = {
            'status': '',
            'ag_kit_barcode_id': 'db447092-620e-54d8-e040-8a80115d3637',
            'ag_kit_id': 'db447092-6209-54d8-e040-8a80115d3637',
            'barcode': '000005628',
            'site_sampled': None,
            'environment_sampled': 'Biofilm',
            'sample_date': datetime.date(2014, 12, 11),
            'sample_time': datetime.time(22, 12),
            'notes': 'TESTING TORNADO LOGGING GENERAL',
            'overloaded': None,
            'withdrawn': None,
            'other': None,
            'moldy': None,
            'refunded': None,
            'date_of_last_email': None
        }
        # only look at those fields, that are not subject to scrubbing
        self.assertEqual({k: obs[k] for k in exp}, exp)
    def test_post_general(self):
        self.mock_login('tst_LbxUH')
        # make sure barcode properly removed
        self.assertIn('000005628', ag_data.getAvailableBarcodes(
                      'd8592c74-9694-2135-e040-8a80115d6401'))

        # Run test
        response = self.post('/authed/add_sample_general/',
                             {'participant_name': 'environmental',
                              'barcode': '000005628',
                              'sample_site': 'Biofilm',
                              'sample_date': '12/11/2014',
                              'sample_time': '10:12 PM',
                              'notes': 'TESTING TORNADO LOGGING GENERAL'})
        self.assertEqual(response.code, 200)
        self.assertTrue(
            response.effective_url.endswith('/authed/portal/'))

        obs = ag_data.getAGBarcodeDetails('000005628')
        exp = {
            'status': None,
            'ag_kit_barcode_id': 'db447092-620e-54d8-e040-8a80115d3637',
            'ag_kit_id': 'db447092-6209-54d8-e040-8a80115d3637',
            'barcode': '000005628',
            'site_sampled': None,
            'environment_sampled': 'Biofilm',
            'name': 'REMOVED',
            'sample_date': datetime.date(2014, 12, 11),
            'sample_time': datetime.time(22, 12),
            'notes': 'TESTING TORNADO LOGGING GENERAL',
            'overloaded': None,
            'withdrawn': None,
            'email': 'REMOVED',
            'other': None,
            'moldy': None,
            'participant_name': None,
            'refunded': None,
            'date_of_last_email': None,
            'other_text': 'REMOVED'
        }
        self.assertDictEqual(obs, exp)
    def test_post_human(self):
        ag_login_id = 'd8592c74-9694-2135-e040-8a80115d6401'
        self.mock_login(ag_data.ut_get_supplied_kit_id(ag_login_id))
        # make sure barcode properly removed
        self.assertIn('000005628', ag_data.getAvailableBarcodes(ag_login_id))

        # Run test
        names = ag_data.ut_get_participant_names_from_ag_login_id(ag_login_id)
        response = self.post('/authed/add_sample_human/',
                             {'participant_name': names[0],
                              'barcode': '000005628',
                              'sample_site': 'Stool',
                              'sample_date': '12/13/2014',
                              'sample_time': '11:12 PM',
                              'notes': 'TESTING TORNADO LOGGING HUMAN'})
        self.assertEqual(response.code, 200)
        self.assertTrue(
            response.effective_url.endswith('/authed/portal/'))

        obs = ag_data.getAGBarcodeDetails('000005628')
        exp = {
            'status': '',
            'ag_kit_barcode_id': 'db447092-620e-54d8-e040-8a80115d3637',
            'ag_kit_id': 'db447092-6209-54d8-e040-8a80115d3637',
            'barcode': '000005628',
            'site_sampled': 'Stool',
            'environment_sampled': None,
            'sample_date': datetime.date(2014, 12, 13),
            'sample_time': datetime.time(23, 12),
            'notes': 'TESTING TORNADO LOGGING HUMAN',
            'overloaded': None,
            'withdrawn': None,
            'other': None,
            'moldy': None,
            'refunded': None,
            'date_of_last_email': None,
        }
        # only look at those fields, that are not subject to scrubbing
        self.assertEqual({k: obs[k] for k in exp}, exp)
    def _sample_overview_renderer(self):
        barcode = self.get_argument('barcode', None)
        if barcode is None:
            self.redirect(media_locale['SITEBASE'] + '/authed/portal/')
            return

        has_access = ag_data.check_access(self.current_user, barcode)
        if not has_access:
            self.set_status(403)
            self.render("403.html", skid=self.current_user)
            return

        sample_data = ag_data.getAGBarcodeDetails(barcode)

        if not sample_data:
            self.set_status(404)
            self.render("404.html", skid=self.current_user)
            return

        web_barcode_pdf, web_barcode_txt = _get_data_path(barcode)

        sequence_url = None
        biomv1_url = None
        classic_url = None
        sequence_url = None

        api_base = 'http://api.microbio.me/americangut/1/'
        req = requests.get(api_base + 'sample/%s' % barcode)
        if req.status_code == 200 and req.content != "(null)":
            bc_with_suf = json.loads(req.content)[0]
            biomv1_url = api_base + 'otu/%s/json' % bc_with_suf
            classic_url = api_base + 'otu/%s/txt' % bc_with_suf

            seq_req = requests.get(api_base + 'sequence/%s' % bc_with_suf)
            if seq_req.status_code == 200:
                sequence_url = json.loads(seq_req.content)[0]['fastq_url']

        sample_time = sample_data['sample_time']
        sample_date = sample_data['sample_date']

        status = sample_data['status']
        if status is None:
            bgcolor = '#FFF'
            status = 'Submitted'
        elif status == 'Received':
            bgcolor = '#AFA'
        else:
            bgcolor = '#FFF'

        sample_origin = sample_data['site_sampled']
        if sample_origin is None:
            sample_origin = sample_data['environment_sampled']

        notes = sample_data['notes']
        if notes is None:
            notes = ''

        self.render('sample_overview.html', skid=self.current_user,
                    barcode_pdf=web_barcode_pdf, barcode_txt=web_barcode_txt,
                    bgcolor=bgcolor, status=status, barcode=barcode,
                    sample_origin=sample_origin, sample_date=sample_date,
                    sample_time=sample_time, notes=notes,
                    sequence_url=sequence_url, biomv1_url=biomv1_url,
                    classic_url=classic_url)