def _get_sample_by_id(self, sample_id): """ Do not use from api layer, you must validate account and source.""" with self._transaction.cursor() as cur: cur.execute( "SELECT " "ag.ag_kit_barcodes.sample_date, " "ag.ag_kit_barcodes.sample_time, " "ag.ag_kit_barcodes.site_sampled, " "ag.ag_kit_barcodes.notes, " "barcodes.barcode.barcode, " "barcodes.barcode.scan_date " "FROM " "ag.ag_kit_barcodes " "LEFT JOIN barcodes.barcode " "ON " "ag.ag_kit_barcodes.barcode = barcodes.barcode.barcode " "LEFT JOIN source " "ON " "ag.ag_kit_barcodes.source_id = source.id " "WHERE " "ag_kit_barcodes.ag_kit_barcode_id = %s", (sample_id, )) sample_row = cur.fetchone() if sample_row is None: return None sample_barcode = sample_row[4] sample_projects = self._retrieve_projects(sample_barcode) return Sample.from_db(sample_id, *sample_row, sample_projects)
def get_sample(self, account_id, source_id, sample_id): with self._transaction.cursor() as cur: cur.execute( "SELECT " "ag.ag_kit_barcodes.sample_date, " "ag.ag_kit_barcodes.sample_time, " "ag.ag_kit_barcodes.site_sampled, " "ag.ag_kit_barcodes.notes, " "barcodes.barcode.barcode, " "barcodes.barcode.scan_date " "FROM " "ag.ag_kit_barcodes " "LEFT JOIN barcodes.barcode " "ON " "ag.ag_kit_barcodes.barcode = barcodes.barcode.barcode " "LEFT JOIN source " "ON " "ag.ag_kit_barcodes.source_id = source.id " "WHERE " "ag_kit_barcodes.ag_kit_barcode_id = %s AND " "source.id = %s AND " "source.account_id = %s", (sample_id, source_id, account_id)) sample_row = cur.fetchone() if sample_row is None: return None sample_barcode = sample_row[4] sample_projects = self._retrieve_projects(sample_barcode) return Sample.from_db(sample_id, *sample_row, sample_projects)
def _create_sample_obj(self, sample_row): if sample_row is None: return None sample_barcode = sample_row[5] sample_projects = self._retrieve_projects(sample_barcode) return Sample.from_db(*sample_row, sample_projects)
def _create_sample_obj(self, sample_row): if sample_row is None: return None sample_barcode = sample_row[5] scan_timestamp = sample_row[6] sample_projects = self._retrieve_projects(sample_barcode) sample_status = self.get_sample_status(sample_barcode, scan_timestamp) return Sample.from_db(*sample_row, sample_projects, sample_status)
def create_dummy_sample_objects(filled=False): info_dict = DUMMY_FILLED_SAMPLE_INFO if filled else DUMMY_EMPTY_SAMPLE_INFO datetime_str = info_dict["sample_datetime"] datetime_obj = None if datetime_str is None else isoparse(datetime_str) sample_info = SampleInfo( info_dict["sample_id"], datetime_obj, info_dict["sample_site"], info_dict["sample_notes"] ) sample = Sample(info_dict["sample_id"], datetime_obj, info_dict["sample_site"], info_dict["sample_notes"], info_dict["sample_barcode"], None, info_dict["sample_projects"]) return sample_info, sample
def get_samples_by_source(self, account_id, source_id): with self._transaction.cursor() as cur: acct_repo = AccountRepo(self._transaction) if acct_repo.get_account(account_id) is None: raise NotFound("No such account") source_repo = SourceRepo(self._transaction) if source_repo.get_source(account_id, source_id) is None: raise NotFound("No such source") cur.execute( "SELECT " "ag_kit_barcodes.ag_kit_barcode_id, " "ag_kit_barcodes.sample_date, " "ag_kit_barcodes.sample_time, " "ag_kit_barcodes.site_sampled, " "ag_kit_barcodes.notes, " "ag_kit_barcodes.barcode, " "barcode.scan_date " "FROM ag_kit_barcodes " "LEFT JOIN barcode " "USING (barcode) " "LEFT JOIN source " "ON ag_kit_barcodes.source_id = source.id " "WHERE " "source.account_id = %s AND " "source.id = %s " "ORDER BY barcode.barcode asc", (account_id, source_id)) samples = [] for sample_row in cur.fetchall(): barcode = sample_row[5] sample_projects = self._retrieve_projects(barcode) s = Sample.from_db(*sample_row, sample_projects) samples.append(s) return samples