def test_get_ffq_status_by_sample(self): session_copy = VIOSCREEN_SESSION.copy() session_copy.username = VIOSCREEN_USERNAME1 with Transaction() as t: r = VioscreenSessionRepo(t) r.upsert_session(session_copy) session = r.get_sessions_by_username(VIOSCREEN_USERNAME1)[0] obs = r.get_ffq_status_by_sample(BARCODE_UUID_NOTIN_REGISTRY) self.assertEqual(obs, (False, False, None)) session.status = 'Finished' session.endDate = _to_dt(2, 1, 1970) r.upsert_session(session) # enumerate the empirically observed states from vioscreen # (is_complete, has_taken, exact_status) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (True, True, 'Finished')) session.status = 'Started' session.endDate = None r.upsert_session(session) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (False, True, 'Started')) session.status = 'New' r.upsert_session(session) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (False, False, 'New')) session.status = 'Review' r.upsert_session(session) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (False, True, 'Review'))
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