def test_scan_barcode_success(self):
        with Transaction() as t:
            # TODO FIXME HACK:  Need to build mock barcodes rather than using
            #  these fixed ones

            TEST_BARCODE = '000000001'
            TEST_STATUS = "sample-has-inconsistencies"
            TEST_NOTES = "THIS IS A UNIT TEST"
            admin_repo = AdminRepo(t)

            # check that before doing a scan, no scans are recorded for this
            diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE)
            self.assertEqual(len(diag['scans_info']), 0)

            # do a scan
            admin_repo.scan_barcode(TEST_BARCODE, {
                "sample_status": TEST_STATUS,
                "technician_notes": TEST_NOTES
            })

            # show that now a scan is recorded for this barcode
            diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE)
            self.assertEqual(len(diag['scans_info']), 1)
            first_scan = diag['scans_info'][0]
            self.assertEqual(first_scan['technician_notes'], TEST_NOTES)
            self.assertEqual(first_scan['sample_status'], TEST_STATUS)
 def test_retrieve_diagnostics_by_barcode_nonexistent(self):
     with Transaction() as t:
         admin_repo = AdminRepo(t)
         # Uhh, should this return a 404 not found or just an empty
         # diagnostic object...?
         diag = admin_repo.retrieve_diagnostics_by_barcode('NotABarcode :D')
         self.assertIsNone(diag)
def search_barcode(token_info, sample_barcode):
    validate_admin_access(token_info)

    with Transaction() as t:
        admin_repo = AdminRepo(t)
        diag = admin_repo.retrieve_diagnostics_by_barcode(sample_barcode)
        if diag is None:
            return jsonify(code=404, message="Barcode not found"), 404
        return jsonify(diag), 200
 def test_retrieve_diagnostics_by_barcode_nonexistent(self):
     with Transaction() as t:
         # TODO FIXME HACK:  Need to build mock barcodes rather than using
         #  these fixed ones
         admin_repo = AdminRepo(t)
         # Uhh, should this return a 404 not found or just an empty
         # diagnostic object...?
         diag = admin_repo.retrieve_diagnostics_by_barcode('NotABarcode :D')
         self.assertIsNone(diag)
 def test_retrieve_diagnostics_by_barcode_not_agp(self):
     with Transaction() as t:
         admin_repo = AdminRepo(t)
         diag = admin_repo.retrieve_diagnostics_by_barcode('000044481')
         self.assertIsNotNone(diag['barcode_info'])
         self.assertIsNone(diag['account'])
         self.assertIsNone(diag['source'])
         self.assertIsNone(diag['sample'])
         self.assertGreater(len(diag['scans_info']), 0)
         self.assertGreater(len(diag['projects_info']), 0)
 def test_retrieve_diagnostics_by_barcode_wo_extra_info(self):
     with Transaction() as t:
         # TODO FIXME HACK:  Need to build mock barcodes rather than using
         #  these fixed ones
         admin_repo = AdminRepo(t)
         diag = admin_repo.retrieve_diagnostics_by_barcode('000033903')
         self.assertIsNotNone(diag['barcode_info'])
         self.assertIsNone(diag['account'])
         self.assertIsNone(diag['source'])
         self.assertIsNone(diag['sample'])
         self.assertGreater(len(diag['projects_info']), 0)
         self.assertEqual(len(diag['scans_info']), 0)
    def test_retrieve_diagnostics_by_barcode_w_scans(self):
        def make_tz_datetime(y, m, d):
            return datetime.datetime(y,
                                     m,
                                     d,
                                     0,
                                     0,
                                     tzinfo=psycopg2.tz.FixedOffsetTimezone(
                                         offset=-420, name=None))

        # Non-AGP barcode so no acct, source, or sample;
        # also no preexisting scans in test db
        test_barcode = '000004531'
        first_scan_id = 'f7fd3022-3a9c-4f79-b92c-5cebd83cba38'
        second_scan_id = '76aec821-aa28-4dea-a796-2cfd1276f78c'

        first_scan = {
            "barcode_scan_id": first_scan_id,
            "barcode": test_barcode,
            "scan_timestamp": make_tz_datetime(2017, 7, 16),
            "sample_status": 'no-registered-account',
            "technician_notes": "huh?"
        }

        second_scan = {
            "barcode_scan_id": second_scan_id,
            "barcode": test_barcode,
            "scan_timestamp": make_tz_datetime(2020, 12, 4),
            "sample_status": 'sample-is-valid',
            "technician_notes": None
        }
        try:
            add_dummy_scan(first_scan)
            add_dummy_scan(second_scan)

            with Transaction() as t:
                admin_repo = AdminRepo(t)
                diag = admin_repo.retrieve_diagnostics_by_barcode(test_barcode)
                self.assertIsNotNone(diag['barcode_info'])
                self.assertIsNone(diag['account'])
                self.assertIsNone(diag['source'])
                self.assertIsNone(diag['sample'])
                self.assertGreater(len(diag['projects_info']), 0)
                self.assertEqual(len(diag['scans_info']), 2)
                # order matters in the returned vals, so test that
                self.assertEqual(diag['scans_info'][0], first_scan)
                self.assertEqual(diag['scans_info'][1], second_scan)
                self.assertEqual(diag['latest_scan'], second_scan)
        finally:
            delete_test_scan(first_scan_id)
            delete_test_scan(second_scan_id)
Beispiel #8
0
    def test_scan_barcode(self):
        with Transaction() as t:
            # TODO FIXME HACK:  Need to build mock barcodes rather than using
            #  these fixed ones

            TEST_BARCODE = '000000001'
            TEST_STATUS = "sample-has-inconsistencies"
            TEST_NOTES = "THIS IS A UNIT TEST"
            admin_repo = AdminRepo(t)

            diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE)
            prestatus = diag['barcode_info']['status']

            admin_repo.scan_barcode(
                TEST_BARCODE,
                {
                    "sample_status": TEST_STATUS,
                    "technician_notes": TEST_NOTES
                }
            )

            diag = admin_repo.retrieve_diagnostics_by_barcode(TEST_BARCODE)
            self.assertEqual(diag['barcode_info']['technician_notes'],
                             TEST_NOTES)
            self.assertEqual(diag['barcode_info']['sample_status'],
                             TEST_STATUS)
            self.assertEqual(diag['barcode_info']['status'],
                             prestatus)

            with self.assertRaises(NotFound):
                admin_repo.scan_barcode(
                    "THIZIZNOTAREALBARCODEISWARE",
                    {
                        "sample_status": "Abc",
                        "technician_notes": "123"
                    }
                )
                self.fail("Shouldn't get here")
Beispiel #9
0
    def test_search_barcode(self):
        with Transaction() as t:
            # TODO FIXME HACK:  Need to build mock barcodes rather than using
            #  these fixed ones
            admin_repo = AdminRepo(t)
            diag = admin_repo.retrieve_diagnostics_by_barcode('000038448')
            self.assertIsNotNone(diag['barcode'])
            self.assertIsNone(diag['account'])
            self.assertIsNone(diag['source'])
            self.assertIsNotNone(diag['sample'])
            self.assertGreater(len(diag['barcode_info']['projects']), 0)

            diag = admin_repo.retrieve_diagnostics_by_barcode('000033903')
            self.assertIsNotNone(diag['barcode'])
            self.assertIsNone(diag['account'])
            self.assertIsNone(diag['source'])
            self.assertIsNone(diag['sample'])
            self.assertGreater(len(diag['barcode_info']['projects']), 0)

            # Uhh, should this return a 404 not found or just an empty
            # diagnostic object...?
            diag = admin_repo.retrieve_diagnostics_by_barcode('NotABarcode :D')
            self.assertIsNone(diag)
Beispiel #10
0
def per_sample(project, barcodes, strip_sampleid):
    summaries = []
    with Transaction() as t:
        admin_repo = AdminRepo(t)
        sample_repo = SampleRepo(t)
        template_repo = SurveyTemplateRepo(t)
        vs_repo = VioscreenSessionRepo(t)

        if project is not None:
            project_barcodes = admin_repo.get_project_barcodes(project)
        else:
            project = 'Unspecified'

        if barcodes is None:
            barcodes = project_barcodes

        for barcode in barcodes:
            diag = admin_repo.retrieve_diagnostics_by_barcode(barcode)
            if diag is None:
                raise NotFound(f"Barcode not found: {barcode}")

            sample = diag['sample']
            account = diag['account']
            source = diag['source']

            account_email = None if account is None else account.email
            source_email = None
            source_type = None if source is None else source.source_type
            vio_id = None

            if source is not None and source_type == Source.SOURCE_TYPE_HUMAN:
                source_email = source.source_data.email

                vio_id = template_repo.get_vioscreen_id_if_exists(account.id,
                                                                  source.id,
                                                                  sample.id)

            # at least one sample has been observed that "is_microsetta",
            # described in the barcodes.project_barcode table, but which is
            # unexpectedly not present in ag.ag_kit_barcodes
            if sample is None:
                sample_status = None
                sample_site = None
                ffq_complete = None
                ffq_taken = None
            else:
                sample_status = sample_repo.get_sample_status(
                    sample.barcode,
                    sample._latest_scan_timestamp
                )
                sample_site = sample.site
                ffq_complete, ffq_taken, _ = vs_repo.get_ffq_status_by_sample(
                    sample.id
                )

            summary = {
                "sampleid": None if strip_sampleid else barcode,
                "project": project,
                "source-type": source_type,
                "site-sampled": sample_site,
                "source-email": source_email,
                "account-email": account_email,
                "vioscreen_username": vio_id,
                "ffq-taken": ffq_taken,
                "ffq-complete": ffq_complete,
                "sample-status": sample_status,
                "sample-received": sample_status is not None
            }

            for status in ["sample-is-valid",
                           "no-associated-source",
                           "no-registered-account",
                           "no-collection-info",
                           "sample-has-inconsistencies",
                           "received-unknown-validity"]:
                summary[status] = sample_status == status

            summaries.append(summary)
    return summaries