Skip to content

Commit

Permalink
Merge pre-release/2025-R1.2 into master (#904)
Browse files Browse the repository at this point in the history
* LIMS-1590: Dont allow name editing for lab contacts when login is set (#887)

* LIMS-1558: Add functionality for SMILES code for any sample (#880)

* LIMS-1490: Use callback URL for incoming dewars via shipping service (#852)

* LIMS-1570: Remove unused app file (#874)

* LIMS-1537: Add more options to reprocessing (#876)

* LIMS-1466: Disable dispatch form validation when using the shipping service (#891)
  • Loading branch information
ndg63276 authored and RichB-DLS committed Feb 11, 2025
1 parent f7000bd commit f83cec1
Show file tree
Hide file tree
Showing 37 changed files with 274 additions and 20,174 deletions.
2 changes: 1 addition & 1 deletion api/src/Controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function checkAuthRequiredForSpecificSituations($parts): bool
($parts[0] == 'shipment' && $parts[1] == 'containers' && $parts[2] == 'history' && in_array($_SERVER["REMOTE_ADDR"], $bcr)) ||

# Allow shipping service to update dewar status
($parts[0] == 'shipment' && $parts[1] == 'dewars' && $parts[2] == 'confirmdispatch')
($parts[0] == 'shipment' && $parts[1] == 'dewars' && ($parts[2] == 'confirmdispatch' || $parts[2] == 'confirmpickup'))
)
{
$need_auth = false;
Expand Down
1 change: 0 additions & 1 deletion api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ function auth($require_staff)
if ($require_staff)
{
$auth = $this->staff;

}
// Barcode Scanners
else if ($this->bcr() && !$this->user->loginId)
Expand Down
27 changes: 13 additions & 14 deletions api/src/Page/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class Contact extends Page
# Get List of Lab Contacts
function _get_contacts() {
if (!$this->has_arg('prop')) $this->_error('No proposal specified');

$args = array($this->proposalid);
$where = 'WHERE c.proposalid = :1';

if ($this->has_arg('cid')) {
$where .= ' AND c.labcontactid=:'.(sizeof($args)+1);
array_push($args, $this->arg('cid'));
Expand All @@ -63,37 +63,36 @@ function _get_contacts() {
$pp = $this->has_arg('per_page') ? $this->arg('per_page') : 15;
$start = 0;
$end = $pp;

if ($this->has_arg('page')) {
$pg = $this->arg('page') - 1;
$start = $pg*$pp;
$end = $pg*$pp+$pp;
}

$st = sizeof($args)+1;
$en = $st + 1;
array_push($args, $start);
array_push($args, $end);

$order = 'c.labcontactid DESC';
$rows = $this->db->paginate("SELECT c.labcontactid, c.cardname, pe.givenname, pe.familyname, pe.phonenumber, l.name as labname, l.address, l.city, l.country, c.courieraccount, c.billingreference, c.defaultcourriercompany, c.dewaravgcustomsvalue, c.dewaravgtransportvalue, pe.emailaddress, l.postcode, l.country

$rows = $this->db->paginate("SELECT c.labcontactid, c.cardname, pe.givenname, pe.familyname, pe.phonenumber, IF(pe.login IS NOT NULL, pe.login, IF(pe.externalid IS NOT NULL, 'External', NULL)) AS login, l.name as labname, l.address, l.city, l.country, c.courieraccount, c.billingreference, c.defaultcourriercompany, c.dewaravgcustomsvalue, c.dewaravgtransportvalue, pe.emailaddress, l.postcode, l.country
FROM labcontact c
INNER JOIN person pe ON c.personid = pe.personid
INNER JOIN laboratory l ON l.laboratoryid = pe.laboratoryid
INNER JOIN proposal p ON p.proposalid = c.proposalid
$where ORDER BY $order", $args);

if ($this->has_arg('cid')) {
if (sizeof($rows))$this->_output($rows[0]);
else $this->_error('No such contact');

} else $this->_output(array('total' => $tot,
'data' => $rows,
));
} else {
$this->_output(array('total' => $tot, 'data' => $rows));
}
}


# ------------------------------------------------------------------------
# Update field for lab contact
function _update_contact() {
Expand Down
84 changes: 78 additions & 6 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Shipment extends Page
'TOKEN' => '\w+',
'tracking_number' => '\w+',
'AWBURL' => '[\w\:\/\.\-]+',
'pickup_confirmation_code' => '\w+',

'manifest' => '\d',
'currentuser' => '\d',
Expand Down Expand Up @@ -200,6 +201,7 @@ class Shipment extends Page
array('/dewars/transfer', 'post', '_transfer_dewar'),
array('/dewars/dispatch', 'post', '_dispatch_dewar'),
array('/dewars/confirmdispatch/did/:did/token/:TOKEN', 'post', '_dispatch_dewar_confirmation'),
array('/dewars/confirmpickup/sid/:sid/token/:TOKEN', 'post', '_pickup_dewar_confirmation'),

array('/dewars/tracking(/:DEWARID)', 'get', '_get_dewar_tracking'),

Expand Down Expand Up @@ -1444,7 +1446,70 @@ function _dispatch_dewar_confirmation()
$this->_output(1);
}

function _pickup_dewar_confirmation()
{
if (!$this->has_arg('sid'))
$this->_error('No shipment specified');
if (!$this->has_arg('TOKEN'))
$this->_error('No token specified');
if (!$this->has_arg('tracking_number'))
$this->_error('No tracking number specified');

// Check token against each dewar
$dewars = $this->db->pq(
"SELECT d.dewarid,
json_unquote(json_extract(d.extra, '$.token')) as token
FROM dewar d
WHERE d.shippingid=:1",
array($this->arg('sid'))
);

foreach ($dewars as $dew) {
if ($this->arg('TOKEN') !== $dew['TOKEN']) {
$this->_error('Incorrect token');
}
}

$this->db->pq("UPDATE shipping set shippingstatus='awb created' WHERE shippingid=:1", array($this->arg('sid')));

foreach ($dewars as $dew) {
// Update the dewar status and storage location
$this->db->pq(
"UPDATE dewar
set dewarstatus='awb created', storagelocation='off-site', trackingnumbertosynchrotron=:2
WHERE dewarid=:1",
array($dew['DEWARID'], $this->arg('tracking_number'))
);

// Update dewar transport history
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'awb created','off-site',CURRENT_TIMESTAMP)
RETURNING dewartransporthistoryid INTO :id",
array($dew['DEWARID'])
);
}

if ($this->has_arg('pickup_confirmation_code')) {

$this->db->pq("UPDATE shipping set shippingstatus='pickup booked' WHERE shippingid=:1", array($this->arg('sid')));

foreach ($dewars as $dew) {
// Update the dewar status
$this->db->pq("UPDATE dewar set dewarstatus='pickup booked' WHERE dewarid=:1", array($dew['DEWARID']));

// Update dewar transport history (plus 1s so history appears in order)
$this->db->pq(
"INSERT INTO dewartransporthistory (dewartransporthistoryid,dewarid,dewarstatus,storagelocation,arrivaldate)
VALUES (s_dewartransporthistory.nextval,:1,'pickup booked','off-site',CURRENT_TIMESTAMP+1)
RETURNING dewartransporthistoryid INTO :id",
array($dew['DEWARID'])
);
}
}

$this->_output(1);
}

function _get_dewar_tracking()
{
Expand Down Expand Up @@ -3086,20 +3151,27 @@ function($package, $index) {return array("piecenumber" => $index+1, "licenseplat
function _create_shipment_shipment_request($shipment, array $dewars): int
{

// if (!is_null($shipment['EXTERNALSHIPPINGIDTOSYNCHROTRON'])) {
// return $shipment['EXTERNALSHIPPINGIDTOSYNCHROTRON'];
// }
$shipping_id = (int) $shipment['SHIPPINGID'];

$token = md5(openssl_random_pseudo_bytes(7));
$this->db->pq(
"UPDATE dewar SET extra = JSON_SET(IFNULL(extra, '{}'), '$.token', :1 ) WHERE shippingid=:2",
array($token, $shipping_id)
);

$callback_url = "/api/shipment/dewars/confirmpickup/sid/{$shipping_id}/token/{$token}";

$external_shipping_id = $this->_create_dewars_shipment_request(
$dewars,
$shipment['PROP'],
(int) $shipment['SHIPPINGID'],
(int) $shipment['SHIPPINGID']
$shipping_id,
$shipping_id,
$callback_url
);

$this->db->pq(
"UPDATE shipping SET externalShippingIdToSynchrotron=:1 WHERE shippingId=:2",
array($external_shipping_id, $shipment['SHIPPINGID'])
array($external_shipping_id, $shipping_id)
);
return $external_shipping_id;
}
Expand Down
Loading

0 comments on commit f83cec1

Please sign in to comment.