Skip to content
Merged
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
372 changes: 126 additions & 246 deletions api/src/Page/DC.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function _auto_processing_plots()
// If we are looking for a specific plot (by attachment id) then OK...
if ($this->has_arg('aid')) {
$r['PLOTLY'] = true;
error_log('LIMS-2148 - Plotly used for autoprocprogramattachmentid ' . $this->arg('aid'));
} else {
// ..if not, we should remove this from the list of returned plots
// Autoprocessing results use the same bespoke format for charts
Expand Down
107 changes: 103 additions & 4 deletions api/src/Page/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class Sample extends Page
array('/sub/:ssid', 'get', '_get_sub_sample'),
array('/sub/:ssid', 'patch', '_update_sub_sample'),
array('/sub/:ssid', 'put', '_update_sub_sample_full'),
array('/sub/cid/:cid', 'post', '_update_container_sub_samples'),
array('/sub', 'post', '_add_sub_sample'),
array('/sub/:ssid', 'delete', '_delete_sub_sample'),
array('/sub/queue/cid/:cid', 'post', '_queue_all_sub_samples'),
Expand Down Expand Up @@ -638,13 +639,49 @@ function _queue_all_sub_samples()

$this->db->wait_rep_sync(false);

if (!sizeof($subs))
$this->_error('No subsamples found');

$sub_ids = array_column($subs, 'BLSUBSAMPLEID');
$chunks = array_chunk($sub_ids, 500);
$ret = array();
foreach ($subs as $sub) {
array_push($ret, array(
'BLSUBSAMPLEID' => $sub['BLSUBSAMPLEID'],
'CONTAINERQUEUESAMPLEID' => $this->_do_pre_q_sample(array('BLSUBSAMPLEID' => $sub['BLSUBSAMPLEID']))));

if ($this->has_arg('UNQUEUE')) {
foreach ($chunks as $chunk) {
$placeholders = implode(',', array_fill(0, count($chunk), '?'));
$this->db->pq("DELETE FROM containerqueuesample
WHERE containerqueueid IS NULL
AND blsubsampleid IN ($placeholders)", $chunk);
}

$ret = array_map(function($id) {
return array('BLSUBSAMPLEID' => $id, 'CONTAINERQUEUESAMPLEID' => null);
}, $sub_ids);

} else {
foreach ($chunks as $chunk) {
$placeholders = implode(',', array_fill(0, count($chunk), '?'));
$this->db->pq("INSERT INTO containerqueuesample (blsubsampleid)
SELECT ss.blsubsampleid
FROM blsubsample ss
INNER JOIN blsample s ON s.blsampleid = ss.blsampleid
INNER JOIN container c ON c.containerid = s.containerid
INNER JOIN dewar d ON d.dewarid = c.dewarid
INNER JOIN shipping sh ON sh.shippingid = d.shippingid
WHERE sh.proposalid = ?
AND ss.blsubsampleid IN ($placeholders)",
array_merge(array($this->proposalid), $chunk));

$chunk_ret = $this->db->pq("SELECT blsubsampleid, containerqueuesampleid
FROM containerqueuesample
WHERE blsubsampleid IN ($placeholders)
AND containerqueueid IS NULL", $chunk);

$ret = array_merge($ret, $chunk_ret);
}
}
$this->_output($ret);

}

function _sub_samples()
Expand Down Expand Up @@ -960,6 +997,68 @@ function _update_sub_sample_full()
}


function _update_container_sub_samples()
{
if (!$this->arg('cid'))
$this->_error('No container specified');

if (!$this->arg('EXPERIMENTKIND'))
$this->_error('No experiment kind provided');

$rows = $this->db->pq("SELECT DISTINCT ss.diffractionplanid
FROM blsubsample ss
INNER JOIN blsample s ON s.blsampleid = ss.blsampleid
INNER JOIN diffractionplan dp ON dp.diffractionplanid = ss.diffractionplanid
INNER JOIN containerqueuesample cqs ON cqs.blsubsampleid = ss.blsubsampleid
WHERE s.containerid=:1
AND dp.experimentkind=:2
AND ss.diffractionplanid IS NOT NULL
AND cqs.containerqueuesampleid IS NOT NULL
AND cqs.containerqueueid IS NULL",
array($this->arg('cid'), $this->arg('EXPERIMENTKIND')));

if (!sizeof($rows)) {
$this->_output(array('TOTAL_UPDATED' => 0));
return;
}

$all_ids = array_column($rows, 'DIFFRACTIONPLANID');
$set_args = array();
foreach (array(
'REQUIREDRESOLUTION', 'EXPERIMENTKIND', 'PREFERREDBEAMSIZEX', 'PREFERREDBEAMSIZEY',
'EXPOSURETIME', 'BOXSIZEX', 'BOXSIZEY', 'AXISSTART', 'AXISRANGE', 'NUMBEROFIMAGES',
'TRANSMISSION', 'ENERGY', 'MONOCHROMATOR'
) as $f) {
array_push($set_args, $this->has_arg($f) ? $this->arg($f) : null);
}

$chunks = array_chunk($all_ids, 500);
$total_updated = 0;

foreach ($chunks as $chunk) {
$start_index = sizeof($set_args) + 1;
$placeholders = array();

foreach ($chunk as $index => $id) {
array_push($placeholders, ':' . ($start_index + $index));
}

$id_placeholders_list = implode(',', $placeholders);

$combined_args = array_merge($set_args, $chunk);

$this->db->pq("UPDATE diffractionplan
SET requiredresolution=:1, experimentkind=:2, preferredbeamsizex=:3, preferredbeamsizey=:4,
exposuretime=:5, boxsizex=:6, boxsizey=:7, axisstart=:8, axisrange=:9,
numberofimages=:10, transmission=:11, energy=:12, monochromator=:13
WHERE diffractionplanid IN ($id_placeholders_list)", $combined_args);

$total_updated += sizeof($chunk);
}

$this->_output(array('TOTAL_UPDATED' => $total_updated));
}


function _add_sub_sample()
{
Expand Down
6 changes: 5 additions & 1 deletion api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2532,8 +2532,12 @@ function _get_all_containers()
'MANUAL' => 'queuedmanualsubsamples', 'AUTO' => 'queuedautosubsamples',
);
$dir = $this->has_arg('order') ? ($this->arg('order') == 'asc' ? 'ASC' : 'DESC') : 'ASC';
if (array_key_exists($this->arg('sort_by'), $cols))
if (array_key_exists($this->arg('sort_by'), $cols)) {
$order = $cols[$this->arg('sort_by')] . ' ' . $dir;
if ($this->arg('sort_by') == 'NAME') {
$order .= ', c.containerid ' . $dir;
}
}
}
// $this->db->set_debug(True);
$rows = $this->db->paginate("SELECT $select
Expand Down
Loading
Loading