Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Update Barcode Scanner #632

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions database/procedures/ag_get_barcode_details.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ begin
cast(akb.ag_kit_id as varchar2(100)),
akb.barcode,
akb.site_sampled, akb.environment_sampled, akb.sample_date,
akb.sample_time, akb.participant_name, akb.notes
akb.sample_time, akb.participant_name, akb.notes, akb.refunded, akb.withdrawn,
akb.moldy, akb.other, akb.other_text, akb.date_of_last_email ,akb.overloaded, al.name
from ag_kit_barcodes akb
inner join ag_kit ak
on akb.ag_kit_id = ak.ag_kit_id
Expand All @@ -29,5 +30,3 @@ execute ag_get_barcode_details('000001029', :user_data_);
print user_data_;
*/



18 changes: 18 additions & 0 deletions database/procedures/get_barcode_details.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
create or replace procedure get_barcode_details
(
barcode_ in varchar2
, results_ out types.ref_cursor
) as
begin
open results_ for
select create_date_time, status, scan_date, sample_postmark_date, biomass_remaining, sequencing_status, obsolete
from barcode
where barcode = barcode_;
end get_barcode_details;


/*
variable user_data_ REFCURSOR;
execute get_barcode_details('000001029', :user_data_);
print user_data_;
*/
16 changes: 16 additions & 0 deletions database/procedures/get_barcode_statuses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create or replace procedure get_barcode_statuses(
statuses_ out types.ref_cursor
)as
begin
open statuses_ for
select status from barcode_status;

end get_barcode_statuses;



/*
variable results REFCURSOR;
execute get_barcode_statuses(:results);
print results;
*/
16 changes: 16 additions & 0 deletions database/procedures/get_project_group.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create or replace procedure get_project_group
(
project_name in varchar2 ,
group_name_ out types.ref_cursor
) as
begin
open group_name_ for
select g.group_name from project_groups g inner join project p on g.group_id = p.group_id
where p.project = project_name;
end get_project_group;


/*variable x REFCURSOR;
execute get_project_group('Handout Kits', :x);
print x;
*/
14 changes: 14 additions & 0 deletions database/procedures/get_sequencing_statuses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
create or replace procedure get_sequencing_statuses(
seq_statuses_ out types.ref_cursor
)as

begin
open seq_statuses_ for
select sequencing_status from BARCODE_SEQUENCING_STATUS;

end get_sequencing_statuses;

/*variable sequencing_statuses_ REFCURSOR;
execute get_sequencing_statuses(:sequencing_statuses_);
print sequencing_statuses_;
*/
46 changes: 31 additions & 15 deletions python_code/data_access/ag_data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,30 @@ def getAGBarcodeDetails(self, barcode):
results = con.cursor()
con.cursor().callproc('ag_get_barcode_details', [barcode, results])
barcode_details = results.fetchone()
row_dict = {
'email': barcode_details[0],
'ag_kit_barcode_id': barcode_details[1],
'ag_kit_id': barcode_details[2],
'barcode': barcode_details[3],
'site_sampled': barcode_details[4],
'environment_sampled': barcode_details[5],
'sample_date': barcode_details[6],
'sample_time': barcode_details[7],
'participant_name': barcode_details[8],
'notes': barcode_details[9]
}

if barcode_details is not None:
row_dict = {
'email': barcode_details[0],
'ag_kit_barcode_id': barcode_details[1],
'ag_kit_id': barcode_details[2],
'barcode': barcode_details[3],
'site_sampled': barcode_details[4],
'environment_sampled': barcode_details[5],
'sample_date': barcode_details[6],
'sample_time': barcode_details[7],
'participant_name': barcode_details[8],
'notes': barcode_details[9],
'refunded' : barcode_details[10],
'withdrawn' : barcode_details[11],
'moldy' : barcode_details[12],
'other' : barcode_details[13],
'other_text' : barcode_details[14],
'date_of_last_email' : barcode_details[15],
'overloaded' : barcode_details[16],
'kit_name' : barcode_details[17]
}
else:
#no results so return an empty dict
row_dict = {}
return row_dict

def getAGKitDetails(self, supplied_kit_id):
Expand Down Expand Up @@ -241,9 +252,14 @@ def addAGBarcode(self, ag_kit_id, barcode):
con = self.getMetadataDatabaseConnection()
con.cursor().callproc('ag_insert_barcode', [ag_kit_id, barcode])

def updateAGBarcode(self, barcode, ag_kit_id, site_sampled, environment_sampled, sample_date, sample_time, participant_name, notes):
def updateAGBarcode(self, barcode, ag_kit_id, site_sampled,
environment_sampled, sample_date, sample_time,
participant_name, notes, refunded='N', withdrawn='N'):
con = self.getMetadataDatabaseConnection()
con.cursor().callproc('ag_update_barcode', [barcode, ag_kit_id, site_sampled, environment_sampled, sample_date, sample_time, participant_name, notes])
con.cursor().callproc('ag_update_barcode', [barcode, ag_kit_id,
site_sampled, environment_sampled, sample_date,
sample_time, participant_name, notes, refunded,
withdrawn])

def addAGHumanParticipant(self, ag_login_id, participant_name):
con = self.getMetadataDatabaseConnection()
Expand Down
60 changes: 58 additions & 2 deletions python_code/data_access/qiime_data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -2963,11 +2963,14 @@ def updateSeqOtuCounts(self, sequence_prep_id, num_sequences, num_otus, otu_perc
print 'Exception caught: %s.\nThe error is: %s' % (type(e), e)
return False

def updateBarcodeStatus(self, status, postmark, scan_date, barcode):
def updateBarcodeStatus(self, status, postmark, scan_date, barcode,
biomass_remaining, sequencing_status, obsolete):
""" Updates a barcode's status
"""
con = self.getMetadataDatabaseConnection()
con.cursor().callproc('update_barcode_status', [status, postmark, scan_date, barcode])
con.cursor().callproc('update_barcode_status', [status, postmark,
scan_date, barcode, biomass_remaining,
sequencing_status, obsolete])

def getBarcodeProjType(self, barcode):
""" Get the project type of the barcode.
Expand Down Expand Up @@ -2999,4 +3002,57 @@ def getProjectNames(self):
con.cursor().callproc('get_project_names', [result])
projnames = [row[0] for row in result]
return projnames

def getSequencingStatuses(self):
"""Returns a list of sequencings statuses
"""
con = self.getMetadataDatabaseConnection()
result = con.cursor()
con.cursor().callproc('get_sequencing_statuses', [result])
seq_statuses = [row[0] for row in result]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this fail with an IndexError and should this be caught?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Even if no rows are returned seq_statuses will end up as an empty list. And unless the procedure returns a row with zero fields (I don't think this is possible), row[0] will always exist. This might be the kind of place you'd use an assert, I guess, because these tests would be for things that should not be possible

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks for the explanation.

return seq_statuses

def getBarcodeStatuses(self):
"""Returns a list of barcode statuses
"""
con = self.getMetadataDatabaseConnection()
result = con.cursor()
con.cursor().callproc('get_barcode_statuses', [result])
bar_statuses = [row[0] for row in result]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

return bar_statuses

def getProjectGroup(self, project_name):
"""Returns a project group name

project_name is the name of the project from the table project
"""
con = self.getMetadataDatabaseConnection()
result = con.cursor()
con.cursor().callproc('get_project_group', [project_name,result])
group = result.fetchone()
if group:
return group[0]
else:
return None

def getBarcodeDetails(self, barcode):
"""returns a dictionary of barcode deatails
"""
con = self.getMetadataDatabaseConnection()
results = con.cursor()
con.cursor().callproc('get_barcode_details',[barcode, results])
row = results.fetchone()
if row is not None:
barcode_details = {
'create_date' : row[0],
'status' : row[1],
'scan_date' : row[2],
'sample_postmark_date' : row[3],
'biomass_remaining' : row[4],
'sequencing_status' : row[5],
'obsolete' : row[6]
}
else:
#no results mean barcode doesn't exist
barcode_details = {}
return barcode_details
36 changes: 33 additions & 3 deletions www/wwwadmin/ag_edit_barcode.psp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if 'submit_flag' in form:
# Submit and redirect to fusebox
ag_data_access.updateAGBarcode(form['barcode'], form['ag_kit_id'], form['site_sampled'],
form['environment_sampled'], form['sample_date'], form['sample_time'],
form['participant_name'], form['notes'])
form['participant_name'], form['notes'], form['refunded'], form['withdrawn'])
req.write('<script>document.submit_data.submit();</script>')
# End if
%>
Expand All @@ -35,7 +35,6 @@ if 'submit_flag' in form:
<tr>
<td>Barcode</td>
<td>
<!--<select name="barcode" id="barcode" class="hidden" onChange="document.edit_barcode.submit();">-->
<select name="barcode" id="barcode" onChange="document.edit_barcode.submit();">
<option value="">Please Select...</a>
<%
Expand Down Expand Up @@ -72,7 +71,8 @@ if 'barcode' in form:
participant_name = '' if details['participant_name'] is \
None else details['participant_name']
notes = '' if details['notes'] is None else details['notes']

refunded = 'N' if details['refunded'] is None else details['refunded']
withdrawn = 'N' if details['withdrawn'] is None else details['withdrawn']
# Indent
%>

Expand Down Expand Up @@ -188,9 +188,39 @@ if 'barcode' in form:
<td>Notes</td>
<td><textarea name="notes" id="notes" style="width:350px;height:100px;"><%=notes%></textarea></td>
</tr>
<tr>
<td>Refunded</td><td><select name="refunded" id="refunded">
<%
if refunded == 'N':
req.write('<option value="N" selected>No</option>')
req.write('<option value="Y">Yes</option>')
else:
req.write('<option value="N">No</option>')
req.write('<option value="Y" selected>Yes</option>')
#END Indent
%>
</select>
</td></tr>
<tr>
<td>Withdrawn</td><td><select name="withdrawn" id="withdrawn">
<%
if withdrawn == 'N':
req.write('<option value="N" selected>No</option>')
req.write('<option value="Y">Yes</option>')
else:
req.write('<option value="N">No</option>')
req.write('<option value="Y" selected>Yes</option>')
#END Indent
%>
</select>
</td></tr>



<tr>
<td></td><td><input type="button" onClick="validateEditBarcode();" value="Submit"></td>
</tr>


<%
# End indent
Expand Down
16 changes: 0 additions & 16 deletions www/wwwadmin/ag_edit_kit.psp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ if 'submit_flag' in form:
# Submit and redirect to fusebox
ag_data_access.updateAGKit(form['ag_kit_id'], form['kit_id'], form['kit_password'], \
form['swabs_per_kit'], form['kit_verification_code'])
barcodes = form['barcodes'].split('-')
for barcode in barcodes:
data_access.setBarcodeProjType(form['project'], barcode)
req.write('<script>document.submit_data.submit();</script>')
# End if
%>
Expand Down Expand Up @@ -67,19 +64,6 @@ if 'ag_kit_id' in form:
<tr><td>Kit Password</td><td><input type="text" name="kit_password" id="kit_password" value="<%=details[2]%>"></td></tr>
<tr><td>Number of Swabs</td><td><input type="text" name="swabs_per_kit" id="swabs_per_kit" onkeypress='validateNumber(event)' value="<%=details[3]%>"></td></tr>
<tr><td>Kit Verification Code</td><td><input type="text" name="kit_verification_code" id="kit_verification_code" value="<%=details[4]%>"></td></tr>
<tr><td>Project</td><td><select name="project" id="project" >
<%
if barcodes:
current_project = data_access.getBarcodeProjType(barcodes[0])
barcodesstring = '-'.join(barcodes)
for project in project_names:
if project == current_project:
req.write('<option value="{0}" selected>{0}</option>'.format(project))
else:
req.write('<option value="{0}">{0}</option>'.format(project))
#end
%>
</select></td></tr>
<tr><td></td><td><input type="button" onclick="validateAGForm();" value="Submit"></td></tr>


Expand Down
Loading