Skip to content

Commit 9bc86d5

Browse files
ndg63276Mark Williamsgfrn
authored
LIMS-1818: Add ability to download CSV of dispensing positions (#1001)
* LIMS-1818: Allow download of CSV of dispensing positions * LIMS-1818: Always show CSV button * LIMS-1818: Rename file, update drop names, add blank rows * LIMS-1818: Print commas on empty lines * Fix mime type Co-authored-by: Guilherme Francisco <guilherme.de-freitas@diamond.ac.uk> * LIMS-1818: Remove empty lines entirely --------- Co-authored-by: Mark Williams <mark.williams@diamond.ac.uk> Co-authored-by: Guilherme Francisco <guilherme.de-freitas@diamond.ac.uk>
1 parent 0e148c2 commit 9bc86d5

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed

api/src/Page/Download.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Download extends Page
3535

3636
'ppl' => '\w+',
3737
'aid' => '\w+',
38+
'cid' => '\d+',
3839

3940
'filetype' => '\w+',
4041
'blsampleid' => '\d+',
@@ -49,6 +50,7 @@ class Download extends Page
4950
public static $dispatch = array(
5051
array('/plots', 'get', '_auto_processing_plots'),
5152
array('/csv/visit/:visit', 'get', '_csv_report'),
53+
array('/csv/container/:cid', 'get', '_dispensing_csv'),
5254
array('/sign', 'post', '_sign_url'),
5355
array('/data/visit/:visit', 'get', '_download_visit'),
5456
array('/attachments', 'get', '_get_attachments'),
@@ -324,6 +326,52 @@ function _csv_report()
324326
}
325327
}
326328

329+
# ------------------------------------------------------------------------
330+
# CSV Report of dispensing positions for a plate
331+
function _dispensing_csv()
332+
{
333+
if (!$this->has_arg('cid'))
334+
$this->_error('No container id specified');
335+
$rows = $this->db->pq("SELECT c.code, s.location, ct.name, ct.capacity, ct.wellperrow,
336+
bsp.posx, bsp.posy, si.imagefullpath, si.micronsperpixelx, si.micronsperpixely
337+
FROM blsample s
338+
INNER JOIN container c ON c.containerid = s.containerid
339+
INNER JOIN blsampleimage si ON si.blsampleid = s.blsampleid
340+
LEFT OUTER JOIN containertype ct ON (c.containertypeid IS NOT NULL AND c.containertypeid = ct.containertypeid) OR (c.containertypeid IS NULL AND c.containertype = ct.name)
341+
LEFT OUTER JOIN
342+
(SELECT * FROM blsampleposition bsp1 WHERE bsp1.blsamplepositionid =
343+
(SELECT MAX(blsamplepositionid) FROM blsampleposition bsp2 WHERE bsp2.blsampleid = bsp1.blsampleid AND bsp2.positiontype='dispensing')
344+
) bsp ON bsp.blsampleid = s.blsampleid
345+
WHERE c.containerid=:1
346+
ORDER BY s.location+0",
347+
array($this->arg('cid')));
348+
$plate = $rows[0];
349+
$rowNames = range("A", "H");
350+
$dropNames = range("a", "z");
351+
// SWISSCI 3 Drop have drops a/c/d
352+
if ($plate["NAME"] == "SWISSCI 3 Drop") {
353+
$dropNames = array_merge(array("a"), range("c","z"));
354+
}
355+
$dropsPerWell = $plate["CAPACITY"] / (count($rowNames) * $plate["WELLPERROW"]);
356+
$this->app->response->headers->set("Content-type", "text/csv");
357+
$this->_set_disposition_attachment($this->app->response, $plate["CODE"] . "_targets.csv");
358+
list($width, $height, $type, $attr) = getimagesize($plate['IMAGEFULLPATH']);
359+
foreach ($rows as $r) {
360+
if (!isset($r["POSX"]) || !isset($r["POSY"])) {
361+
continue; # skip empty rows
362+
}
363+
$wellNumber = intval(($r["LOCATION"] - 1) / $dropsPerWell); # 0 indexed
364+
$rowNumber = intval($wellNumber / $plate["WELLPERROW"]); # 0 indexed
365+
$row = $rowNames[$rowNumber];
366+
$column = str_pad($wellNumber - ($rowNumber * $plate["WELLPERROW"]) + 1, 2, 0, STR_PAD_LEFT); # pad with a zero if needed
367+
$dropNumber = intval($r["LOCATION"] - ($dropsPerWell * $wellNumber)); # 1 indexed
368+
$drop = $dropNames[$dropNumber-1];
369+
$xval = round(($r["POSX"] - $width/2) * $r["MICRONSPERPIXELX"]); # integers
370+
$yval = round(($height/2 - $r["POSY"]) * $r["MICRONSPERPIXELY"]); # integers
371+
print $row . $column . $drop . "," . $xval . "," . $yval . "\n";
372+
}
373+
}
374+
327375

328376
# ------------------------------------------------------------------------
329377
# Get dc attachmmnts

client/src/js/modules/shipment/views/containerplate.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ define(['marionette',
284284
'click @ui.adr': 'setAddSubsampleRegion',
285285
'click @ui.addis': 'setAddDispensing',
286286
'click @ui.deldis': 'deleteDispensing',
287+
'click a.csv_dispensing': 'downloadDispensingCSV',
287288
'click a.add_inspection': 'showAddInspection',
288289
'click a.view_sched': 'showViewSchedule',
289290
'click @ui.play': 'playInspection',
@@ -313,6 +314,33 @@ define(['marionette',
313314
'change:QUEUED': 'updatedQueued',
314315
},
315316

317+
downloadDispensingCSV: function(e) {
318+
e.preventDefault()
319+
this.signHandler(app.apiurl+'/download/csv/container/'+this.model.get('CONTAINERID'));
320+
},
321+
322+
signHandler(url) {
323+
this.sign({
324+
url: url,
325+
callback: function(resp) {
326+
window.location = url+'?token='+resp.token
327+
}
328+
})
329+
},
330+
331+
sign(options) {
332+
Backbone.ajax({
333+
url: app.apiurl+'/download/sign',
334+
method: 'POST',
335+
data: {
336+
validity: options.url.replace(app.apiurl, ''),
337+
},
338+
success: function(resp) {
339+
if (options && options.callback) options.callback(resp)
340+
}
341+
})
342+
},
343+
316344
setSampleStatusShown: function() {
317345

318346
const showCurrentScore = this.ui.sampleStatusCurrent.is(':checked')

client/src/js/templates/shipment/containerplateimage.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,23 @@ <h1 class="no_mobile">Plate Details</h1>
176176
</li>
177177
<% } %>
178178

179-
<% if (IMAGERID) { %>
180179
<li class="clearfix">
181180
<span class="label">Actions</span>
182-
181+
183182
<div class="text_table">
183+
<% if (IMAGERID) { %>
184184
<div class="queue"></div>
185185

186186
<div>
187187
<select name="INSPECTIONTYPEID"></select>
188188
<span class="adhoc"></span>
189189
</div>
190-
<div class="return"></div>
190+
<div class="return"></div><br />
191+
<% } %>
192+
<div><a href="#" class="button csv_dispensing"><i class="fa fa-file-o"></i> <span>Download Dispensing CSV</span></a></div>
191193
</div>
192194
</li>
193-
<% } %>
195+
194196

195197
<li class="clearfix">
196198
<span class="label tw-align-top">Location History</span>

0 commit comments

Comments
 (0)