Skip to content

Commit

Permalink
Merge branch 'master' into improvement/LIMS-128/add-plate-view-to-que…
Browse files Browse the repository at this point in the history
…ue-page
  • Loading branch information
ndg63276 authored Oct 22, 2024
2 parents e5e7006 + f7780e9 commit 7eb49e8
Show file tree
Hide file tree
Showing 28 changed files with 315 additions and 145 deletions.
5 changes: 3 additions & 2 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"mpdf/mpdf": "8.1.2",
"ralouphie/getallheaders": "2.0.5",
"slim/slim": "2.6.2",
"stomp-php/stomp-php": "3.0.6",
"php-amqplib/php-amqplib": "^2.0",
"symfony/http-foundation": "^5.4",
"symfony/filesystem": "^5.4",
"mpdf/qrcode": "^1.2",
"mtcmedia/dhl-api": "dev-master#9b4b6315",
"maennchen/zipstream-php": "2.1.0"
"maennchen/zipstream-php": "2.1.0",
"phpseclib/bcmath_compat": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 9 additions & 7 deletions api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1109,14 +1109,16 @@ function _submit_zocalo_recipe($recipe, $parameters, $error_code = 500)
}


function _send_zocalo_message($zocalo_queue, $zocalo_message, $error_code = 500)
function _send_zocalo_message($rabbitmq_zocalo_vhost, $zocalo_message, $error_code = 500)
{
global
$zocalo_server,
$zocalo_username,
$zocalo_password;
$rabbitmq_zocalo_host,
$rabbitmq_zocalo_port,
$rabbitmq_zocalo_username,
$rabbitmq_zocalo_password,
$rabbitmq_zocalo_routing_key;

if (empty($zocalo_server) || empty($zocalo_queue))
if (empty($rabbitmq_zocalo_host) || empty($rabbitmq_zocalo_vhost))
{
$message = 'Zocalo server or queue not specified.';
error_log($message);
Expand All @@ -1129,8 +1131,8 @@ function _send_zocalo_message($zocalo_queue, $zocalo_message, $error_code = 500)
try
{
error_log("Sending message" . var_export($zocalo_message, true));
$queue = new Queue($zocalo_server, $zocalo_username, $zocalo_password);
$queue->send($zocalo_queue, $zocalo_message, true, $this->user->loginId);
$queue = new Queue($rabbitmq_zocalo_host, $rabbitmq_zocalo_port, $rabbitmq_zocalo_username, $rabbitmq_zocalo_password, $rabbitmq_zocalo_vhost);
$queue->send($zocalo_message, $rabbitmq_zocalo_routing_key);
}
catch (Exception $e)
{
Expand Down
20 changes: 12 additions & 8 deletions api/src/Page/DC.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,14 @@ function _data_collections($single = null)
$s = str_replace('_', '$_', $this->arg('s'));

$st = sizeof($args) + 1;
$where .= " AND (lower(dc.filetemplate) LIKE lower(CONCAT(CONCAT('%',:$st),'%')) ESCAPE '$' OR lower(dc.imagedirectory) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 1) . "), '%')) ESCAPE '$' OR lower(smp.name) LIKE lower(CONCAT(CONCAT('%', :" . ($st + 2) . "), '%')) ESCAPE '$')";
$where2 .= " AND (lower(es.comments) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 3) . "), '%')) ESCAPE '$' OR lower(es.element) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 4) . "), '%')) ESCAPE '$' OR lower(smp.name) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 5) . "), '%')) ESCAPE '$')";
$where .= " AND (dc.filetemplate LIKE CONCAT('%',:$st,'%') ESCAPE '$' OR dc.imagedirectory LIKE CONCAT('%',:" . ($st + 1) . ",'%') ESCAPE '$' OR smp.name LIKE CONCAT('%', :" . ($st + 2) . ",'%') ESCAPE '$')";
$where2 .= " AND (es.comments LIKE CONCAT('%',:" . ($st + 3) . ",'%') ESCAPE '$' OR es.element LIKE CONCAT('%',:" . ($st + 4) . ",'%') ESCAPE '$' OR smp.name LIKE CONCAT('%',:" . ($st + 5) . ",'%') ESCAPE '$')";
$where3 .= ' AND r.robotactionid < 0';
$where4 .= " AND (lower(xrf.filename) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 6) . "), '%')) ESCAPE '$' OR lower(smp.name) LIKE lower(CONCAT(CONCAT('%',:" . ($st + 7) . "), '%')) ESCAPE '$')";
$where4 .= " AND (xrf.filename LIKE CONCAT('%',:" . ($st + 6) . ",'%') ESCAPE '$' OR smp.name LIKE CONCAT('%',:" . ($st + 7) . ",'%') ESCAPE '$')";

for ($i = 0; $i < 8; $i++)
array_push($args, $s);

}

# Set Count field
Expand Down Expand Up @@ -440,7 +441,7 @@ function _data_collections($single = null)
dc.c2lens,
dc.objaperture,
dc.magnification,
dc.totalexposeddose as totaldose,
dose.total as totaldose,
CAST(dc.totalabsorbeddose AS DECIMAL(5, 2)) as totalabsdose,
d.detectorpixelsizehorizontal,
d.detectorpixelsizevertical,
Expand Down Expand Up @@ -511,9 +512,9 @@ function _data_collections($single = null)
// $this->db->set_debug(True);

// will want to support these too at some point
$where2 = ' AND es.energyscanid < 0';
$where3 = ' AND r.robotactionid < 0';
$where4 = ' AND xrf.xfefluorescencespectrumid < 0';
$where2 .= ' AND es.energyscanid < 0';
$where3 .= ' AND r.robotactionid < 0';
$where4 .= ' AND xrf.xfefluorescencespectrumid < 0';

if ($this->has_arg('dcg')) {
$where .= ' AND dc.datacollectiongroupid=:' . (sizeof($args) + 1);
Expand Down Expand Up @@ -574,7 +575,7 @@ function _data_collections($single = null)
max(dc.c2lens) as c2lens,
max(dc.objaperture) as objaperture,
max(dc.magnification) as magnification,
sum(dc.totalabsorbeddose) as totaldose,
dose.total as totaldose,
CAST(dc.totalabsorbeddose AS DECIMAL(5, 2)) as totalabsdose,
max(d.detectormanufacturer) as detectormanufacturer,
max(d.detectormodel) as detectormodel,
Expand Down Expand Up @@ -660,6 +661,9 @@ function _data_collections($single = null)
SELECT $extcg $fields
FROM datacollection dc
INNER JOIN datacollectiongroup dcg ON dcg.datacollectiongroupid = dc.datacollectiongroupid
INNER JOIN (
select datacollectiongroupid, sum(totalabsorbeddose) as total from datacollection group by datacollectiongroupid) dose
ON dc.datacollectiongroupid = dose.datacollectiongroupid
INNER JOIN blsession ses ON ses.sessionid = dcg.sessionid
LEFT OUTER JOIN experimenttype et on dcg.experimenttypeid = et.experimenttypeid
$sample_joins[0]
Expand Down
45 changes: 44 additions & 1 deletion api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Download extends Page

array('/ap/attachments(/:AUTOPROCPROGRAMATTACHMENTID)(/dl/:download)', 'get', '_get_autoproc_attachments'),
array('/ap/archive/:AUTOPROCPROGRAMID', 'get', '_get_autoproc_archive'),
array('/ap/log/:AUTOPROCPROGRAMID', 'get', '_get_autoproc_log'),
);


Expand Down Expand Up @@ -220,7 +221,7 @@ function __get_autoproc_attachments()
INNER JOIN datacollectiongroup dcg ON dcg.datacollectiongroupid = dc.datacollectiongroupid
INNER JOIN blsession s ON s.sessionid = dcg.sessionid
WHERE s.proposalid=:1 $where
ORDER BY importancerank"
ORDER BY importancerank, filename"
), $args);

return $rows;
Expand Down Expand Up @@ -413,6 +414,48 @@ function _get_attachment()
}
}

# ------------------------------------------------------------------------
# Get the most important log of an autoprocessing job
function _get_autoproc_log()
{

if (!$this->has_arg('prop')) {
$this->_error('No proposal specified');
}
$args = array($this->proposalid, $this->arg('AUTOPROCPROGRAMID'));

$rows = $this->db->union(array(
"SELECT app.autoprocprogramid, appa.filename, appa.filepath
FROM autoprocintegration api
INNER JOIN autoprocprogram app ON api.autoprocprogramid = app.autoprocprogramid
INNER JOIN autoprocprogramattachment appa ON appa.autoprocprogramid = app.autoprocprogramid
INNER JOIN datacollection dc ON dc.datacollectionid = api.datacollectionid
INNER JOIN datacollectiongroup dcg ON dcg.datacollectiongroupid = dc.datacollectiongroupid
INNER JOIN blsession s ON s.sessionid = dcg.sessionid
WHERE s.proposalid=:1
AND app.autoprocprogramid=:2
AND appa.importancerank=1
AND appa.filetype='Log'",
"SELECT app.autoprocprogramid, appa.filename, appa.filepath
FROM autoprocprogram app
INNER JOIN processingjob pj on pj.processingjobid = app.processingjobid
INNER JOIN autoprocprogramattachment appa ON appa.autoprocprogramid = app.autoprocprogramid
INNER JOIN datacollection dc ON dc.datacollectionid = pj.datacollectionid
INNER JOIN datacollectiongroup dcg ON dcg.datacollectiongroupid = dc.datacollectiongroupid
INNER JOIN blsession s ON s.sessionid = dcg.sessionid
WHERE s.proposalid=:1
AND app.autoprocprogramid=:2
AND appa.importancerank=1
AND appa.filetype='Log'"
), $args);

if (!sizeof($rows)) {
return $this->_error('No log file found');
}
$this->_get_file($rows[0]['AUTOPROCPROGRAMID'], $rows[0]);

}


# ------------------------------------------------------------------------
# Get an archive of an autoproc
Expand Down
11 changes: 5 additions & 6 deletions api/src/Page/Imaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ function _get_inspections()
$where .= " AND i.state='Completed'";
}

if ($this->has_arg('s')) {
$where .= " AND (CONCAT(p.proposalcode, p.proposalnumber) LIKE CONCAT('%', :" . (sizeof($args) + 1) . ", '%') OR c.code LIKE CONCAT('%', :" . (sizeof($args) + 2) . ", '%'))";
array_push($args, $this->arg('s'), $this->arg('s'));
}

$tot = $this->db->pq("SELECT count(i.containerinspectionid) as tot FROM containerinspection i
INNER JOIN container c ON c.containerid = i.containerid
INNER JOIN dewar d ON d.dewarid = c.dewarid
Expand Down Expand Up @@ -422,12 +427,6 @@ function _get_inspections()
$order = $cols[$this->arg('sort_by')] . ' ' . $dir;
}

if ($this->has_arg('s')) {
$where .= " AND (LOWER(CONCAT(p.proposalcode, p.proposalnumber)) LIKE LOWER(CONCAT(CONCAT('%', :" . (sizeof($args) + 1) . "), '%')) OR LOWER(c.code) LIKE LOWER(CONCAT(CONCAT('%', :" . (sizeof($args) + 2) . "), '%')))";
array_push($args, $this->arg('s'));
array_push($args, $this->arg('s'));
}

if ($this->has_arg('ty')) {
if ($this->arg('ty') == 'COMPLETED')
$where .= " AND i.state = 'Completed' AND i.manual=0";
Expand Down
4 changes: 2 additions & 2 deletions api/src/Page/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function _add_reprocessing_sweep($args) {

function _enqueue()
{
global $zocalo_mx_reprocess_queue;
global $rabbitmq_zocalo_vhost;

if (!$this->has_arg('PROCESSINGJOBID')) $this->_error('No processing job specified');

Expand All @@ -379,7 +379,7 @@ function _enqueue()
'ispyb_process' => intval($this->arg('PROCESSINGJOBID')),
)
);
$this->_send_zocalo_message($zocalo_mx_reprocess_queue, $message);
$this->_send_zocalo_message($rabbitmq_zocalo_vhost, $message);

$this->_output(new \stdClass);
}
Expand Down
1 change: 1 addition & 0 deletions api/src/Page/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ function _get_visits($visit = null, $output = true)
s.beamlineoperator AS lc,
s.comments,
s.scheduled,
s.riskrating,
st.typename AS sessiontype,
DATE_FORMAT(s.startdate, '%d-%m-%Y %H:%i') AS startdate,
DATE_FORMAT(s.enddate, '%d-%m-%Y %H:%i') AS enddate,
Expand Down
17 changes: 11 additions & 6 deletions api/src/Page/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1835,12 +1835,17 @@ function _distinct_proteins()
$where .= ' AND pr.externalid IS NOT NULL';
}

$has_safety_level = $this->has_arg('SAFETYLEVEL');
if ($has_safety_level && $this->arg('SAFETYLEVEL') === 'ALL') {
$where .= ' AND pr.safetyLevel IS NOT NULL';
} else if ($has_safety_level && $this->arg('SAFETYLEVEL') !== 'ALL') {
$where .= ' AND pr.safetyLevel=:' . (sizeof($args) + 1);
array_push($args, $this->arg('SAFETYLEVEL'));
if ($this->has_arg('SAFETYLEVEL')) {
if ($this->arg('SAFETYLEVEL') === 'ALL') {
$where .= ' AND pr.safetyLevel IS NOT NULL';
} else if (strtolower($this->arg('SAFETYLEVEL')) === 'yellow') {
$where .= " AND pr.safetyLevel in ('green','yellow')";
} else if (strtolower($this->arg('SAFETYLEVEL')) === 'red') {
$where .= " AND pr.safetyLevel in ('green','yellow','red')";
} else {
$where .= ' AND pr.safetyLevel=:' . (sizeof($args) + 1);
array_push($args, $this->arg('SAFETYLEVEL'));
}
}

if ($this->has_arg('term')) {
Expand Down
39 changes: 38 additions & 1 deletion api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ function _get_dewars()
$order = $cols[$this->arg('sort_by')] . ' ' . $dir;
}

$dewars = $this->db->paginate("SELECT CONCAT(p.proposalcode, p.proposalnumber) as prop, CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number) as firstexperiment, r.labcontactid, se.beamlineoperator as localcontact, se.beamlinename, TO_CHAR(se.startdate, 'HH24:MI DD-MM-YYYY') as firstexperimentst, d.firstexperimentid, s.shippingid, s.shippingname, d.facilitycode, count(c.containerid) as ccount, (case when se.visit_number > 0 then (CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number)) else '' end) as exp, d.code, d.barcode, d.storagelocation, d.dewarstatus, d.dewarid, d.trackingnumbertosynchrotron, d.trackingnumberfromsynchrotron, d.externalShippingIdFromSynchrotron, s.deliveryagent_agentname, d.weight, d.deliveryagent_barcode, GROUP_CONCAT(c.code SEPARATOR ', ') as containers, s.sendinglabcontactid, s.returnlabcontactid, pe.givenname, pe.familyname
$dewars = $this->db->paginate("SELECT CONCAT(p.proposalcode, p.proposalnumber) as prop, CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number) as firstexperiment, r.labcontactid, se.beamlineoperator as localcontact, se.beamlinename, TO_CHAR(se.startdate, 'HH24:MI DD-MM-YYYY') as firstexperimentst, d.firstexperimentid, s.shippingid, s.shippingname, d.facilitycode, count(c.containerid) as ccount, (case when se.visit_number > 0 then (CONCAT(p.proposalcode, p.proposalnumber, '-', se.visit_number)) else '' end) as exp, d.code, d.barcode, d.storagelocation, d.dewarstatus, d.dewarid, d.trackingnumbertosynchrotron, d.trackingnumberfromsynchrotron, d.externalShippingIdFromSynchrotron, s.deliveryagent_agentname, d.weight, d.deliveryagent_barcode, GROUP_CONCAT(c.code SEPARATOR ', ') as containers, s.sendinglabcontactid, s.returnlabcontactid, pe.givenname, pe.familyname, s.safetylevel as shippingsafetylevel
FROM dewar d
LEFT OUTER JOIN container c ON c.dewarid = d.dewarid
INNER JOIN shipping s ON d.shippingid = s.shippingid
Expand Down Expand Up @@ -1700,6 +1700,39 @@ function _add_dewar()
$this->_output(array('DEWARID' => $id));
}

# Check new safety level is ok
function _check_safety_level()
{
$ship = $this->db->pq("SELECT cq.containerqueueid, p.safetylevel FROM dewar d
LEFT OUTER JOIN container c on c.dewarid = d.dewarid
LEFT OUTER JOIN containerqueue cq on cq.containerid = c.containerid
LEFT OUTER JOIN blsample b ON b.containerid = c.containerid
LEFT OUTER JOIN crystal cr ON cr.crystalid = b.crystalid
LEFT OUTER JOIN protein p ON p.proteinid = cr.proteinid
WHERE d.shippingid = :1", array($this->arg('sid')));
if (strtolower($this->arg('SAFETYLEVEL')) == 'green') {
foreach ($ship as $s) {
if (strtolower($s['SAFETYLEVEL']) == 'yellow')
$this->_error('Cannot set safety level to green as one or more samples are yellow.');
if (strtolower($s['SAFETYLEVEL']) == 'red')
$this->_error('Cannot set safety level to green as one or more samples are red.');
}
} else if (strtolower($this->arg('SAFETYLEVEL')) == 'yellow') {
foreach ($ship as $s) {
if ($s['CONTAINERQUEUEID'] != null)
$this->_error('Cannot set safety level to yellow as one or more containers are queued.');
if (strtolower($s['SAFETYLEVEL']) == 'red')
$this->_error('Cannot set safety level to yellow as one or more samples are red.');
}
} else {
foreach ($ship as $s) {
if ($s['CONTAINERQUEUEID'] != null)
$this->_error('Cannot set safety level to red as one or more containers are queued.');
}
}
}


# Update shipment
function _update_shipment()
{
Expand All @@ -1721,6 +1754,9 @@ function _update_shipment()
if (in_array($f, array('DELIVERYAGENT_DELIVERYDATE', 'DELIVERYAGENT_SHIPPINGDATE'))) {
$fl = "TO_DATE(:1, 'DD-MM-YYYY')";
}
if ($f == 'SAFETYLEVEL') {
$this->_check_safety_level();
}

$this->db->pq("UPDATE shipping SET $f=$fl WHERE shippingid=:2", array($this->arg($f), $this->arg('sid')));

Expand Down Expand Up @@ -2120,6 +2156,7 @@ function _get_all_containers()
}
// $this->db->set_debug(True);
$rows = $this->db->paginate("SELECT round(TIMESTAMPDIFF('HOUR', min(ci.bltimestamp), CURRENT_TIMESTAMP)/24,1) as age, case when count(ci2.containerinspectionid) > 1 then 0 else 1 end as allow_adhoc, c.scheduleid, c.screenid, sc.name as screen, c.imagerid, i.temperature as temperature, i.name as imager, TO_CHAR(max(ci.bltimestamp), 'HH24:MI DD-MM-YYYY') as lastinspection, round(TIMESTAMPDIFF('HOUR', max(ci.bltimestamp), CURRENT_TIMESTAMP)/24,1) as lastinspectiondays, count(distinct ci.containerinspectionid) as inspections, CONCAT(p.proposalcode, p.proposalnumber) as prop, c.bltimestamp, c.samplechangerlocation, c.beamlinelocation, d.dewarstatus, c.containertype, c.capacity, c.containerstatus, c.containerid, c.code as name, d.code as dewar, sh.shippingname as shipment, d.dewarid, sh.shippingid, count(distinct s.blsampleid) as samples, cq.containerqueueid, TO_CHAR(cq.createdtimestamp, 'DD-MM-YYYY HH24:MI') as queuedtimestamp, CONCAT(p.proposalcode, p.proposalnumber, '-', ses.visit_number) as visit, ses.beamlinename, c.requestedreturn, c.requestedimagerid, c.comments, c.experimenttype, c.storagetemperature, c.barcode, reg.barcode as registry, reg.containerregistryid,
sh.safetylevel as shippingsafetylevel,
(SELECT sch.name FROM schedule sch WHERE sch.scheduleid = c.scheduleid) as schedule,
(SELECT i2.name FROM imager i2 WHERE i2.imagerid = c.requestedimagerid) as requestedimager,
(SELECT count(distinct ss.blsubsampleid) FROM blsubsample ss RIGHT OUTER JOIN blsample s2 ON s2.blsampleid = ss.blsampleid WHERE s2.containerid = c.containerid AND ss.source='manual') as subsamples,
Expand Down
Loading

0 comments on commit 7eb49e8

Please sign in to comment.