Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIMS-59: Never write null to DewarTransportHistory.storageLocation #597

Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 8 additions & 4 deletions api/src/Model/Services/AssignData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SynchWeb\Model\Services;

use SynchWeb\Utils;

class AssignData
{
private $db;
Expand Down Expand Up @@ -85,9 +87,10 @@ function updateDewar($dewarId, $status)

function deactivateDewar($dewarId)
{
$this->updateDewarHistory($dewarId, 'unprocessing');
$location = $this->db->pq("SELECT storagelocation FROM dewar WHERE dewarid=:1", array($dewarId));
John-Holt-Tessella marked this conversation as resolved.
Show resolved Hide resolved
$this->updateDewarHistory($dewarId, 'unprocessing', $location[0]['STORAGELOCATION']);

$conts = $this->db->pq("SELECT containerid as id FROM container WHERE dewarid=:1", array($dewarId));
$conts = $this->db->pq("SELECT containerid FROM container WHERE dewarid=:1", array($dewarId));
foreach ($conts as $container)
{
$this->updateContainerAndHistory($container['CONTAINERID'], 'at facility', '', '');
Expand All @@ -99,9 +102,10 @@ function updateDewarHistory($did, $status, $beamline = null, $additionalStatusDe
$st = $status;
if ($additionalStatusDetail)
$st .= ' (' . $additionalStatusDetail . ')';
$loc = Utils::getValueOrDefault($beamline, '');
$this->db->pq("INSERT INTO dewartransporthistory
(dewarid, dewarstatus, storagelocation, arrivaldate)
VALUES (:1, :2, :3, CURRENT_TIMESTAMP)", array($did, $st, $beamline));
VALUES (:1, :2, :3, CURRENT_TIMESTAMP)", array($did, $st, $loc));

$this->updateDewar($did, $status);
}
Expand All @@ -113,4 +117,4 @@ function getContainerBarcodesForProposal($proposalId)
INNER JOIN containerregistry_has_proposal crhp ON crhp.containerregistryid = cr.containerregistryid
WHERE crhp.proposalid = :1", array($proposalId));
}
}
}
31 changes: 17 additions & 14 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ function _transfer_dewar()
global $transfer_email;
if (!$this->has_arg('DEWARID'))
$this->_error('No dewar specified');
if (!$this->has_arg('LOCATION'))
$this->_error('No location specified');

$dew = $this->db->pq("SELECT d.dewarid,s.shippingid
FROM dewar d
Expand Down Expand Up @@ -1049,7 +1051,7 @@ function _dispatch_dewar()
$dewar_location = $last_history['STORAGELOCATION'];
} else {
// Use the current location of the dewar instead if no history
$dewar_location = $dew['STORAGELOCATION'];
$dewar_location = Utils::getValueOrDefault($dew['STORAGELOCATION'], '');
}
}
// Check if the last history storage location is an EBIC prefix or not
Expand Down Expand Up @@ -1562,16 +1564,16 @@ function _send_shipment()
}

$this->db->pq("UPDATE shipping SET shippingstatus='sent to facility' where shippingid=:1", array($ship['SHIPPINGID']));
$this->db->pq("UPDATE dewar SET dewarstatus='sent to facility' where shippingid=:1", array($ship['SHIPPINGID']));
$this->db->pq("UPDATE dewar SET dewarstatus='sent to facility', storagelocation='off-site' where shippingid=:1", array($ship['SHIPPINGID']));
John-Holt-Tessella marked this conversation as resolved.
Show resolved Hide resolved

$dewars = $this->db->pq("SELECT d.dewarid, s.visit_number as vn, s.beamlinename as bl, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as startdate
FROM dewar d
LEFT OUTER JOIN blsession s ON s.sessionid = d.firstexperimentid
WHERE d.shippingid=:1", array($ship['SHIPPINGID']));
foreach ($dewars as $d) {
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'sent to facility',CURRENT_TIMESTAMP) RETURNING dewartransporthistoryid INTO :id",
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'sent to facility','off-site',CURRENT_TIMESTAMP) RETURNING dewartransporthistoryid INTO :id",
array($d['DEWARID'])
);
}
Expand Down Expand Up @@ -2798,11 +2800,11 @@ function _create_awb()
continue;

$p = $awb['pieces'][$i];
$this->db->pq("UPDATE dewar SET $tno=:1, deliveryAgent_barcode=:2, dewarstatus='awb created' WHERE dewarid=:3", array($awb['awb'], $p['licenseplate'], $d['DEWARID']));
$this->db->pq("UPDATE dewar SET $tno=:1, deliveryAgent_barcode=:2, dewarstatus='awb created', storagelocation='off-site' WHERE dewarid=:3", array($awb['awb'], $p['licenseplate'], $d['DEWARID']));

$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'awb created',CURRENT_TIMESTAMP) RETURNING dewartransporthistoryid INTO :id",
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'awb created','off-site',CURRENT_TIMESTAMP) RETURNING dewartransporthistoryid INTO :id",
array($d['DEWARID'])
);
}
Expand Down Expand Up @@ -2955,10 +2957,10 @@ function _do_request_pickup($options)
WHERE shippingid=:4", array($pickup['confirmationnumber'], $pickup['readybytime'], $pickup['callintime'], $options['shippingid']));

foreach ($options['dewars'] as $i => $d) {
$this->db->pq("UPDATE dewar SET dewarstatus='pickup booked' WHERE dewarid=:1", array($d['DEWARID']));
$this->db->pq("UPDATE dewar SET dewarstatus='pickup booked', storagelocation='off-site' WHERE dewarid=:1", array($d['DEWARID']));
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'pickup booked',CURRENT_TIMESTAMP) RETURNING dewartransporthistoryid INTO :id",
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'pickup booked','off-site',CURRENT_TIMESTAMP) RETURNING dewartransporthistoryid INTO :id",
array($d['DEWARID'])
);
}
Expand Down Expand Up @@ -3090,7 +3092,7 @@ function _cancel_pickup()
$this->_error('No such lab contact');
$cont = $cont[0];

$dewars = $this->db->pq("SELECT d.dewarid
$dewars = $this->db->pq("SELECT d.dewarid, d.storagelocation
Copy link
Contributor

Choose a reason for hiding this comment

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

could the dewar storage location not be null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a check for null on line 3116

FROM dewar d
WHERE d.shippingid=:1 AND d.deliveryagent_barcode IS NOT NULL", array($this->arg('sid')));

Expand All @@ -3111,10 +3113,11 @@ function _cancel_pickup()

foreach ($dewars as $i => $d) {
$this->db->pq("UPDATE dewar SET dewarstatus='pickup cancelled' WHERE dewarid=:1", array($d['DEWARID']));
$loc = Utils::getValueOrDefault($d['STORAGELOCATION'], '');
$this->db->pq(
"INSERT INTO dewartransporthistory (dewarid,dewarstatus,arrivaldate)
VALUES (:1,'pickup cancelled',CURRENT_TIMESTAMP)",
array($d['DEWARID'])
"INSERT INTO dewartransporthistory (dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (:1,'pickup cancelled',:2,CURRENT_TIMESTAMP)",
array($d['DEWARID'], $loc)
);
}
} catch (\Exception $e) {
Expand Down
Loading