Skip to content

Commit

Permalink
Merge pull request #750 from DiamondLightSource/pre-release/2024-R1.4
Browse files Browse the repository at this point in the history
Pre release/2024 r1.4
  • Loading branch information
gfrn authored Apr 2, 2024
2 parents 6d7bd13 + ea029f5 commit 0701128
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 53 deletions.
2 changes: 1 addition & 1 deletion api/src/Page/DC.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ function _data_collections($single = null)

// Data collections
if ($dc['TYPE'] == 'data') {
$nf = array(1 => array('AXISSTART'), 2 => array('RESOLUTION', 'TRANSMISSION', 'AXISRANGE'), 4 => array('WAVELENGTH', 'EXPOSURETIME'));
$nf = array(1 => array('AXISSTART', 'CHISTART', 'PHI', 'OVERLAP'), 2 => array('RESOLUTION', 'TRANSMISSION', 'AXISRANGE', 'TOTALDOSE'), 4 => array('WAVELENGTH', 'EXPOSURETIME'));

$dc['DIRFULL'] = $dc['DIR'];
$dc['DIR'] = preg_replace('/.*\/' . $this->arg('prop') . '-' . $dc['VN'] . '\//', '', $dc['DIR']);
Expand Down
73 changes: 32 additions & 41 deletions api/src/Page/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Sample extends Page
'UNQUEUE' => '\d',
'nodata' => '\d',
'notcompleted' => '\d',
'filter' => '\w+',

// external is a flag to indicate this protein/sample has a user office system id
// whereas externalid is the actual reference
Expand Down Expand Up @@ -594,6 +595,17 @@ function _queue_all_sub_samples()

$args = array($this->proposalid, $this->arg('cid'), $this->arg('cid'), $this->arg('cid'));
$where = ' AND c.containerid=:2 AND cq2.completedtimestamp IS NULL';

if ($this->has_arg('filter')) {
$filters = array(
'manual' => " AND ss.source='manual'",
'auto' => " AND ss.source='auto'",
'point' => " AND dp.experimentkind='SAD'",
'region' => " AND dp.experimentkind='MESH'",
);
$where .= $filters[$this->arg('filter')];
}

$first_inner_select_where = ' AND s.containerid=:3';
$second_inner_select_where = ' AND s.containerid=:4';

Expand Down Expand Up @@ -1715,12 +1727,24 @@ function _proteins()

// Only display original UAS approved proteins (not clones which have the same externalId)
if ($this->has_arg('original') && $this->arg('original') == 1) {
$group = 'pr.externalId';
$order .= ', pr.bltimeStamp DESC';
$where .= ' AND pr.proteintype = "ORIGIN:UAS"';
}

if ($this->has_arg('sort_by')) {
$cols = array('NAME' => 'pr.name', 'ACRONYM' => 'pr.acronym', 'MOLECULARMASS' => 'pr.molecularmass', 'HASSEQ' => "CASE WHEN sequence IS NULL THEN 'No' ELSE 'Yes' END");
$cols = array(
'NAME' => 'pr.name',
'ACRONYM' => 'pr.acronym',
'MOLECULARMASS' => 'pr.molecularmass',
'DENSITY' => 'pr.density',
'SEQUENCE' => 'pr.sequence',
'SAFETYLEVEL' => 'pr.safetylevel',
'HASSEQ' => "CASE WHEN sequence IS NULL THEN 'No' ELSE 'Yes' END",
'PDBS' => 'pdbs',
'CONCENTRATIONTYPE' => 'concentrationtype',
'COMPONENTTYPE' => 'componenttype',
'DCOUNT' => 'dcount',
'SCOUNT' => 'scount'
);
$dir = $this->has_arg('order') ? ($this->arg('order') == 'asc' ? 'ASC' : 'DESC') : 'ASC';
if (array_key_exists($this->arg('sort_by'), $cols))
$order = $cols[$this->arg('sort_by')] . ' ' . $dir;
Expand All @@ -1736,56 +1760,23 @@ function _proteins()
HEX(pr.externalid) as externalid,
pr.density,
count(php.proteinid) as pdbs,
pr.safetylevel
pr.safetylevel,
count(dc.datacollectionid) as dcount,
count(b.blsampleid) as scount
FROM protein pr
LEFT OUTER JOIN concentrationtype ct ON ct.concentrationtypeid = pr.concentrationtypeid
LEFT OUTER JOIN componenttype cmt ON cmt.componenttypeid = pr.componenttypeid
LEFT OUTER JOIN protein_has_pdb php ON php.proteinid = pr.proteinid
/*LEFT OUTER JOIN crystal cr ON cr.proteinid = pr.proteinid
LEFT OUTER JOIN crystal cr ON cr.proteinid = pr.proteinid
LEFT OUTER JOIN blsample b ON b.crystalid = cr.crystalid
LEFT OUTER JOIN datacollection dc ON b.blsampleid = dc.blsampleid*/
LEFT OUTER JOIN datacollection dc ON b.blsampleid = dc.blsampleid
INNER JOIN proposal p ON p.proposalid = pr.proposalid
$join
WHERE $where
GROUP BY $group
ORDER BY $order", $args);

$ids = array();
$wcs = array();
foreach ($rows as $r) {
array_push($ids, $r['PROTEINID']);
array_push($wcs, 'pr.proteinid=:' . sizeof($ids));
}

$dcs = array();
$scs = array();

if (sizeof($ids)) {
$dcst = $this->db->pq('SELECT pr.proteinid, count(dc.datacollectionid) as dcount FROM datacollection dc INNER JOIN blsample s ON s.blsampleid=dc.blsampleid INNER JOIN crystal cr ON cr.crystalid = s.crystalid INNER JOIN protein pr ON pr.proteinid = cr.proteinid WHERE ' . implode(' OR ', $wcs) . ' GROUP BY pr.proteinid', $ids);


foreach ($dcst as $d) {
$dcs[$d['PROTEINID']] = $d['DCOUNT'];
}

$scst = $this->db->pq('SELECT pr.proteinid, count(s.blsampleid) as scount FROM blsample s INNER JOIN crystal cr ON cr.crystalid = s.crystalid INNER JOIN protein pr ON pr.proteinid = cr.proteinid WHERE ' . implode(' OR ', $wcs) . ' GROUP BY pr.proteinid', $ids);

foreach ($scst as $d) {
$scs[$d['PROTEINID']] = $d['SCOUNT'];
}
}

foreach ($rows as &$r) {
$dcount = array_key_exists($r['PROTEINID'], $dcs) ? $dcs[$r['PROTEINID']] : 0;
$r['DCOUNT'] = $dcount;
$scount = array_key_exists($r['PROTEINID'], $scs) ? $scs[$r['PROTEINID']] : 0;
$r['SCOUNT'] = $scount;

if ($this->has_arg('pid'))
$r['SEQUENCE'] = $this->db->read($r['SEQUENCE']);
}

if ($this->has_arg('pid')) {
if (sizeof($rows))
$this->_output($rows[0]);
Expand Down
5 changes: 2 additions & 3 deletions api/src/Page/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,7 @@ function _add_prop_dewar()
$this->_error('No dewar specified');
if (!$this->has_arg('PROPOSALID'))
$this->_error('No proposal specified');
if (!$this->has_arg('LABCONTACTID'))
$this->_error('No lab contact specified');
$lc = $this->has_arg('LABCONTACTID') ? $this->arg('LABCONTACTID') : null;

$chk = $this->db->pq("SELECT dewarregistryid
FROM dewarregistry_has_proposal
Expand All @@ -739,7 +738,7 @@ function _add_prop_dewar()
$this->_error('That dewar is already registered to that proposal');

$this->db->pq("INSERT INTO dewarregistry_has_proposal (dewarregistryid,proposalid,personid,labcontactid)
VALUES (:1,:2,:3,:4)", array($this->arg('DEWARREGISTRYID'), $this->arg('PROPOSALID'), $this->user->personId, $this->arg('LABCONTACTID')));
VALUES (:1,:2,:3,:4)", array($this->arg('DEWARREGISTRYID'), $this->arg('PROPOSALID'), $this->user->personId, $lc));

$this->_output(array('DEWARREGISTRYHASPROPOSALID' => $this->db->id()));
}
Expand Down
Loading

0 comments on commit 0701128

Please sign in to comment.