Skip to content

Commit 0842e69

Browse files
ndg63276Mark Williams
andauthored
LIMS-1956: Add dewar names and serial nos to shipment requests (#1000)
* LIMS-1956: Add dewar names and serial nos to shipment requests * LIMS-1956: Use visit number 0 if not set --------- Co-authored-by: Mark Williams <[email protected]>
1 parent a565211 commit 0842e69

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

api/config_sample.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@
264264
$use_shipping_service_incoming_shipments = null;
265265
$use_shipping_service_redirect = null;
266266
$use_shipping_service_redirect_incoming_shipments = null;
267-
$shipping_service_api_url = null;
268267
$shipping_service_api_user = null;
269268
$shipping_service_api_password = null;
270269
$shipping_service_app_url = null;

api/src/Page/Shipment.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ function _transfer_dewar()
10171017
function _create_dewars_shipment_request(
10181018
array $dewars,
10191019
string $proposal,
1020+
int $session_number,
10201021
int $external_id,
10211022
int $shipping_id,
10221023
string $callback_url=""
@@ -1026,6 +1027,8 @@ function _create_dewars_shipment_request(
10261027
foreach (array_values($dewars) as $dew) {
10271028
$package = [
10281029
"external_id" => (int) $dew['DEWARID'],
1030+
"container_name" => $dew['NAME'],
1031+
"serial_number" => $dew['MANUFACTURERSERIALNUMBER'],
10291032
"shippable_item_type" => "CRYOGENIC_DRY_SHIPPER_CASE",
10301033
"line_items" => [
10311034
[
@@ -1064,6 +1067,7 @@ function _create_dewars_shipment_request(
10641067
$protocol = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
10651068
$shipment_request_info = array(
10661069
"proposal" => $proposal,
1070+
"session_number" => $session_number,
10671071
"external_id" => $external_id,
10681072
"origin_url" => "{$protocol}://{$_SERVER['SERVER_NAME']}{$server_port}/shipments/sid/{$shipping_id}",
10691073
"packages" => $packages
@@ -1084,6 +1088,7 @@ function _dispatch_dewar_shipment_request($dewar)
10841088

10851089
$dewars = [$dewar];
10861090
$proposal = $dewar['PROPOSAL'];
1091+
$session_number = $dewar['VIS'];
10871092
$external_id = (int) $dewar['DEWARID'];
10881093
$shipping_id = (int) $dewar['SHIPPINGID'];
10891094
$token = Utils::generateRandomMd5();
@@ -1093,7 +1098,7 @@ function _dispatch_dewar_shipment_request($dewar)
10931098
);
10941099

10951100
$callback_url = "/api/shipment/dewars/confirmdispatch/did/{$external_id}/token/{$token}";
1096-
$external_shipping_id = $this->_create_dewars_shipment_request($dewars, $proposal, $external_id, $shipping_id, $callback_url);
1101+
$external_shipping_id = $this->_create_dewars_shipment_request($dewars, $proposal, $session_number, $external_id, $shipping_id, $callback_url);
10971102

10981103
$this->db->pq(
10991104
"UPDATE dewar SET externalShippingIdFromSynchrotron=:1 WHERE dewarid=:2",
@@ -1111,11 +1116,7 @@ function _dispatch_dewar_in_shipping_service($dispatch_info, $dewar)
11111116
global $facility_country;
11121117
global $facility_phone;
11131118
global $facility_contact;
1114-
global $shipping_service_api_url;
11151119
global $facility_email;
1116-
if (!isset($shipping_service_api_url)) {
1117-
throw new Exception("Could not send request to shipping service: shipping_service_api_url not set");
1118-
}
11191120

11201121
# Create shipment
11211122
$shipment_data = array(
@@ -1138,7 +1139,12 @@ function _dispatch_dewar_in_shipping_service($dispatch_info, $dewar)
11381139
"shipment_reference" => $dispatch_info['VISIT'],
11391140
"external_id" => (int) $dispatch_info['DEWARID'],
11401141
"journey_type" => ShippingService::JOURNEY_FROM_FACILITY,
1141-
"packages" => array(array("external_id" => (int) $dispatch_info['DEWARID']))
1142+
"packages" => array(
1143+
array(
1144+
"external_id" => (int) $dispatch_info['DEWARID'],
1145+
"container_name" => $dewar['NAME'],
1146+
)
1147+
)
11421148
);
11431149

11441150
# Split up address. Necessary as address is a single field in ispyb
@@ -1195,12 +1201,18 @@ function _dispatch_dewar()
11951201
}
11961202

11971203
$dew = $this->db->pq(
1198-
"SELECT d.dewarid, d.barcode, d.storagelocation, d.dewarstatus, d.externalShippingIdFromSynchrotron, s.shippingid, p.proposalcode, CONCAT(p.proposalcode, p.proposalnumber) as proposal, count(distinct c.containerId) as num_pucks, count(b.blsampleId) as num_samples
1204+
"SELECT d.dewarid, d.barcode, d.storagelocation, d.dewarstatus, d.externalShippingIdFromSynchrotron,
1205+
s.shippingid, p.proposalcode, CONCAT(p.proposalcode, p.proposalnumber) as proposal,
1206+
count(distinct c.containerId) as num_pucks, count(b.blsampleId) as num_samples,
1207+
ifnull(bls.visit_number, 0) as vis, IF(d.facilitycode, d.facilitycode, d.code) as name,
1208+
dr.manufacturerserialnumber
11991209
FROM dewar d
12001210
INNER JOIN shipping s ON s.shippingid = d.shippingid
12011211
INNER JOIN proposal p ON p.proposalid = s.proposalid
12021212
LEFT JOIN container c on c.dewarid = d.dewarid
12031213
LEFT JOIN BLSample b on b.containerId = c.containerId
1214+
LEFT JOIN blsession bls ON bls.sessionid = d.firstexperimentid
1215+
LEFT JOIN dewarregistry dr ON dr.dewarregistryid = d.dewarregistryid
12041216
WHERE d.dewarid=:1 and p.proposalid=:2",
12051217
array($this->arg('DEWARID'), $this->proposalid)
12061218
);
@@ -3308,10 +3320,15 @@ function _book_shipment_in_shipping_service($user, $shipment, $dewars, $journey_
33083320
"contact_email" => trim($user["email"])
33093321
);
33103322
$shipment_data = array(
3311-
"shipment_reference" => $shipment["PROP"],
3323+
"shipment_reference" => $shipment["PROP"] . '-' . ($shipment["session_number"] ?? 0),
33123324
"external_id" => $shipment['SHIPPINGID'],
33133325
"packages" => array_map(
3314-
function($dewar) {return array("external_id" => $dewar["DEWARID"]);},
3326+
function($dewar) {
3327+
return array(
3328+
"external_id" => $dewar["DEWARID"],
3329+
"container_name" => $dewar["NAME"],
3330+
);
3331+
},
33153332
$dewars
33163333
)
33173334
);
@@ -3365,6 +3382,7 @@ function _create_shipment_shipment_request($shipment, array $dewars): int
33653382
$external_shipping_id = $this->_create_dewars_shipment_request(
33663383
$dewars,
33673384
$shipment['PROP'],
3385+
isset($shipment['session_number']) ? $shipment['session_number'] : 0,
33683386
$shipping_id,
33693387
$shipping_id,
33703388
$callback_url
@@ -3409,15 +3427,25 @@ function _create_awb()
34093427
$args = array_merge(array($ship['SHIPPINGID']), $this->arg('DEWARS'));
34103428

34113429
$dewars = $this->db->pq(
3412-
"SELECT d.dewarid, d.weight, IF(d.facilitycode, d.facilitycode, d.code) as name, count(distinct c.containerId) as num_pucks, count(b.blsampleId) as num_samples
3430+
"SELECT d.dewarid, d.weight, IF(d.facilitycode, d.facilitycode, d.code) as name,
3431+
count(distinct c.containerId) as num_pucks, count(b.blsampleId) as num_samples,
3432+
bls.visit_number, dr.manufacturerserialnumber
34133433
FROM dewar d
34143434
LEFT JOIN container c on c.dewarid = d.dewarid
34153435
LEFT JOIN BLSample b on b.containerId = c.containerId
3436+
LEFT JOIN blsession bls on bls.sessionid = d.firstexperimentid
3437+
LEFT JOIN dewarregistry dr on dr.dewarregistryid = d.dewarregistryid
34163438
WHERE d.shippingid=:1 AND d.dewarid IN (:" . implode(',:', $ids) . ")
34173439
GROUP BY d.dewarid",
34183440
$args
34193441
);
34203442

3443+
foreach ($dewars as $d) {
3444+
if ($d['VISIT_NUMBER']) {
3445+
$ship['session_number'] = $d['VISIT_NUMBER'];
3446+
}
3447+
}
3448+
34213449
if (
34223450
Utils::getValueOrDefault($use_shipping_service_incoming_shipments)
34233451
&& in_array($this->arg('COUNTRY'), $facility_courier_countries)

api/src/Shipment/ShippingService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ function _build_headers()
4040

4141
function __construct()
4242
{
43-
global $shipping_service_api_url;
4443
global $shipping_service_app_url;
45-
$this->shipping_api_url = $shipping_service_api_url;
4644
$this->shipping_app_url = $shipping_service_app_url;
45+
$this->shipping_api_url = $shipping_service_app_url . "/api";
4746
}
4847

4948

0 commit comments

Comments
 (0)