def _get_session_by_account_details(account_id, source_id, sample_id): with Transaction() as t: surv_temp = SurveyTemplateRepo(t) vio_sess = VioscreenSessionRepo(t) vio_username = surv_temp.get_vioscreen_id_if_exists( account_id, source_id, sample_id) if vio_username is None: return True, (jsonify(code=404, message="Username not found"), 404) vioscreen_session = vio_sess.get_sessions_by_username(vio_username) if vioscreen_session is None: return True, (jsonify(code=404, message="Session not found"), 404) return False, vioscreen_session
def test_get_vioscreen_id_if_exists_invalid(self): with Transaction() as t: template_repo = SurveyTemplateRepo(t) obs = template_repo.get_vioscreen_id_if_exists( TEST2_ACCOUNT_ID, TEST2_SOURCE_ID, TEST2_SAMPLE_ID) self.assertEqual(obs, None)
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