Skip to content

Commit

Permalink
LIMS-40: Remove concat(concat(concat( functions (#608)
Browse files Browse the repository at this point in the history
* LIMS-40: Remove concat(concat(concat( functions

* Remove dangling bracket

Co-authored-by: Matthew Pritchard <46708056+MattPrit@users.noreply.github.com>

---------

Co-authored-by: Mark Williams <mark.williams@diamond.ac.uk>
Co-authored-by: Matthew Pritchard <46708056+MattPrit@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent 2da5639 commit 9b5bd86
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 92 deletions.
6 changes: 3 additions & 3 deletions api/src/Model/Services/AssignData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getContainer($visitId, $containerId)
INNER JOIN shipping s ON s.shippingid = d.shippingid
INNER JOIN blsession bl ON bl.proposalid = s.proposalid
INNER JOIN proposal p ON s.proposalid = p.proposalid
WHERE CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), bl.visit_number) LIKE :1
WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', bl.visit_number) LIKE :1
AND c.containerid=:2", array($visitId, $containerId));
}

Expand Down Expand Up @@ -65,7 +65,7 @@ function getDewar($dewarId, $proposalId, $visitId)
$arg = $proposalId;
if ($visitId)
{
$where = "CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), bl.visit_number) LIKE :1";
$where = "CONCAT(p.proposalcode, p.proposalnumber, '-', bl.visit_number) LIKE :1";
$arg = $visitId;
}

Expand Down Expand Up @@ -113,4 +113,4 @@ function getContainerBarcodesForProposal($proposalId)
INNER JOIN containerregistry_has_proposal crhp ON crhp.containerregistryid = cr.containerregistryid
WHERE crhp.proposalid = :1", array($proposalId));
}
}
}
8 changes: 4 additions & 4 deletions api/src/Model/Services/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ function getUsers($getCount, $isStaffMember, $stringMatch, $page, $sortBy = null
INNER JOIN proposal pr ON pr.proposalid = s.proposalid
LEFT OUTER JOIN session_has_person shp2 ON p.personid = shp2.personid
LEFT OUTER JOIN blsession ses ON ses.sessionid = shp2.sessionid AND ses.startdate < s.startdate';
$where .= " AND shp.remote IS NOT NULL AND CONCAT(CONCAT(CONCAT(pr.proposalcode,pr.proposalnumber), '-'), s.visit_number) LIKE :" . (sizeof($args) + 1);
$where .= " AND shp.remote IS NOT NULL AND CONCAT(pr.proposalcode, pr.proposalnumber, '-', s.visit_number) LIKE :" . (sizeof($args) + 1);
$group = 'GROUP BY p.personid, p.givenname, p.familyname, p.login';
array_push($args, $visitName);
}
else if ($pjid)
{
$join = 'INNER JOIN project_has_person php ON p.personid = php.personid';
$where .= ' AND php.projectid=:' . (sizeof($args) + 1);
$extc = "CONCAT(CONCAT(p.personid, '-'), php.projectid) as ppid,";
$extc = "CONCAT(p.personid, '-', php.projectid) as ppid,";
array_push($args, $pjid);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ function getUsers($getCount, $isStaffMember, $stringMatch, $page, $sortBy = null
}
}

$rows = $this->db->paginate("SELECT $extc p.personid, p.givenname, p.familyname, CONCAT(CONCAT(p.givenname, ' '), p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country
$rows = $this->db->paginate("SELECT $extc p.personid, p.givenname, p.familyname, CONCAT(p.givenname, ' ', p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country
FROM person p
LEFT OUTER JOIN proposalhasperson prhp ON prhp.personid = p.personid
LEFT OUTER JOIN labcontact lc ON lc.personid = p.personid
Expand Down Expand Up @@ -253,7 +253,7 @@ function getUsersForProposal($where, $getCount, $page, $sortBy, $proposalid, $cu
}
}

$extc = "p.personid, p.givenname, p.familyname, CONCAT(CONCAT(p.givenname, ' '), p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country";
$extc = "p.personid, p.givenname, p.familyname, CONCAT(p.givenname, ' ', p.familyname) as fullname, p.login, p.emailaddress, p.phonenumber, l.name as labname, l.address, l.city, '' as postcode, l.country";
$rows = $this->db->paginate("(SELECT $extc
FROM person p
LEFT OUTER JOIN ProposalHasPerson prhp ON prhp.personid = p.personid
Expand Down
16 changes: 8 additions & 8 deletions api/src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function auth($require_staff)
}
else
{
$rows = $this->db->pq("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis
$rows = $this->db->pq("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis
FROM proposal p
INNER JOIN blsession s ON p.proposalid = s.proposalid
INNER JOIN session_has_person shp ON shp.sessionid = s.sessionid
Expand Down Expand Up @@ -315,15 +315,15 @@ function auth($require_staff)

if ($table == 'datacollectiongroup')
{
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis
FROM blsession s
INNER JOIN proposal p ON (p.proposalid = s.proposalid)
INNER JOIN datacollectiongroup dcg ON s.sessionid = dcg.sessionid
INNER JOIN datacollection dc ON dcg.datacollectiongroupid = dc.datacollectiongroupid WHERE dc.datacollectionid = :1", array($this->arg('id')));
}
else
{
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis
$vis = $this->db->pq("SELECT p.proposalid, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis
FROM blsession s
INNER JOIN proposal p ON (p.proposalid = s.proposalid)
INNER JOIN $table dc ON s.sessionid = dc.sessionid WHERE dc.$col = :1", array($this->arg('id')));
Expand All @@ -339,7 +339,7 @@ function auth($require_staff)
{
$vis = $this->arg('visit');

$visp = $this->db->pq("SELECT p.proposalid FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) LIKE :1", array($this->arg('visit')));
$visp = $this->db->pq("SELECT p.proposalid FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) LIKE :1", array($this->arg('visit')));

if (sizeof($visp))
$this->proposalid = $visp[0]['PROPOSALID'];
Expand All @@ -348,7 +348,7 @@ function auth($require_staff)
}
else if ($this->has_arg('prop'))
{
$viss = $this->db->pq("SELECT p.proposalid, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber) LIKE :1", array($this->arg('prop')));
$viss = $this->db->pq("SELECT p.proposalid, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber) LIKE :1", array($this->arg('prop')));

$vis = array();
foreach ($viss as $v)
Expand Down Expand Up @@ -780,8 +780,8 @@ function blsr_visits()
if (!$b)
return array();

$visits = $this->db->pq("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE TIMESTAMPDIFF('DAY', s.startdate, CURRENT_TIMESTAMP) < 1 AND TIMESTAMPDIFF('DAY', CURRENT_TIMESTAMP, s.enddate) < 2 AND s.beamlinename LIKE :1 ORDER BY s.startdate", array($b));
$v = $this->db->paginate("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE p.proposalcode LIKE 'cm' AND s.beamlinename LIKE :1 AND s.enddate <= CURRENT_TIMESTAMP ORDER BY s.startdate DESC", array($b, 0, 1));
$visits = $this->db->pq("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE TIMESTAMPDIFF('DAY', s.startdate, CURRENT_TIMESTAMP) < 1 AND TIMESTAMPDIFF('DAY', CURRENT_TIMESTAMP, s.enddate) < 2 AND s.beamlinename LIKE :1 ORDER BY s.startdate", array($b));
$v = $this->db->paginate("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, TO_CHAR(s.startdate, 'DD-MM-YYYY HH24:MI') as st, TO_CHAR(s.enddate, 'DD-MM-YYYY HH24:MI') as en,s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE p.proposalcode LIKE 'cm' AND s.beamlinename LIKE :1 AND s.enddate <= CURRENT_TIMESTAMP ORDER BY s.startdate DESC", array($b, 0, 1));
$visits = array_merge($visits, $v);
return $visits;
}
Expand Down Expand Up @@ -1137,4 +1137,4 @@ protected function haltIfLackingPermission($permission)
{
$this->user->can($permission, $this->app);
}
}
}
4 changes: 2 additions & 2 deletions api/src/Page/Cal.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ function _export_ics() {
array_push($args, $hash['CKEY']);
}

$visits = $this->db->pq("SELECT s.beamlineoperator as lc, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis, CONCAT(p.proposalcode, p.proposalnumber) as prop, s.beamlinename as bl, TO_CHAR(s.startdate, 'DD-MM-YYYY') as d, TO_CHAR(s.enddate, 'DD-MM-YYYY') as e, TO_CHAR(s.startdate, 'HH24:MI') as st, TO_CHAR(s.enddate, 'HH24:MI') as en, s.sessionid
$visits = $this->db->pq("SELECT s.beamlineoperator as lc, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis, CONCAT(p.proposalcode, p.proposalnumber) as prop, s.beamlinename as bl, TO_CHAR(s.startdate, 'DD-MM-YYYY') as d, TO_CHAR(s.enddate, 'DD-MM-YYYY') as e, TO_CHAR(s.startdate, 'HH24:MI') as st, TO_CHAR(s.enddate, 'HH24:MI') as en, s.sessionid
FROM blsession s
INNER JOIN proposal p ON (p.proposalid = s.proposalid)
WHERE s.startdate > TO_DATE(:1,'YYYY') $where ORDER BY s.startdate, s.beamlinename", $args);


$user_tmp = $this->db->pq("SELECT s.sessionid, pe.login, CONCAT(CONCAT(pe.givenname, ' '), pe.familyname) as fullname, shp.role
$user_tmp = $this->db->pq("SELECT s.sessionid, pe.login, CONCAT(pe.givenname, ' ', pe.familyname) as fullname, shp.role
FROM person pe
INNER JOIN session_has_person shp ON shp.personid = pe.personid
INNER JOIN blsession s ON s.sessionid = shp.sessionid
Expand Down
4 changes: 2 additions & 2 deletions api/src/Page/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function _cells($output = true)
if ($tot % $pp != 0)
$pgs++;

$rows = $this->db->paginate("SELECT s.sessionid, api.autoprocprogramid, api.autoprocintegrationid, sqrt(power(ap.refinedcell_a-:13,2)+power(ap.refinedcell_b-:14,2)+power(ap.refinedcell_c-:15,2)+power(ap.refinedcell_alpha-:16,2)+power(ap.refinedcell_beta-:17,2)+power(ap.refinedcell_gamma-:18,2)) as dist, s.beamlinename as bl, app.processingcommandline as type, apss.ntotalobservations as ntobs, apss.ntotaluniqueobservations as nuobs, apss.resolutionlimitlow as rlow, apss.resolutionlimithigh as rhigh, apss.scalingstatisticstype as shell, apss.rmerge, apss.completeness, apss.multiplicity, apss.meanioversigi as isigi, ap.spacegroup as sg, ap.refinedcell_a as cell_a, ap.refinedcell_b as cell_b, ap.refinedcell_c as cell_c, ap.refinedcell_alpha as cell_al, ap.refinedcell_beta as cell_be, ap.refinedcell_gamma as cell_ga, dc.datacollectionid as id, TO_CHAR(dc.starttime, 'DD-MM-YYYY HH24:MI:SS') as st, dc.imagedirectory as dir, dc.filetemplate, CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as visit, dc.numberofimages as numimg, dc.axisrange, dc.axisstart, dc.wavelength, dc.transmission, dc.exposuretime, IFNULL(dc.rotationaxis, 'Omega') as rotationaxis
$rows = $this->db->paginate("SELECT s.sessionid, api.autoprocprogramid, api.autoprocintegrationid, sqrt(power(ap.refinedcell_a-:13,2)+power(ap.refinedcell_b-:14,2)+power(ap.refinedcell_c-:15,2)+power(ap.refinedcell_alpha-:16,2)+power(ap.refinedcell_beta-:17,2)+power(ap.refinedcell_gamma-:18,2)) as dist, s.beamlinename as bl, app.processingcommandline as type, apss.ntotalobservations as ntobs, apss.ntotaluniqueobservations as nuobs, apss.resolutionlimitlow as rlow, apss.resolutionlimithigh as rhigh, apss.scalingstatisticstype as shell, apss.rmerge, apss.completeness, apss.multiplicity, apss.meanioversigi as isigi, ap.spacegroup as sg, ap.refinedcell_a as cell_a, ap.refinedcell_b as cell_b, ap.refinedcell_c as cell_c, ap.refinedcell_alpha as cell_al, ap.refinedcell_beta as cell_be, ap.refinedcell_gamma as cell_ga, dc.datacollectionid as id, TO_CHAR(dc.starttime, 'DD-MM-YYYY HH24:MI:SS') as st, dc.imagedirectory as dir, dc.filetemplate, CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as visit, dc.numberofimages as numimg, dc.axisrange, dc.axisstart, dc.wavelength, dc.transmission, dc.exposuretime, IFNULL(dc.rotationaxis, 'Omega') as rotationaxis
FROM autoprocintegration api
INNER JOIN autoprocscaling_has_int aph ON api.autoprocintegrationid = aph.autoprocintegrationid
INNER JOIN autoprocscaling aps ON aph.autoprocscalingid = aps.autoprocscalingid
Expand Down Expand Up @@ -470,4 +470,4 @@ function _proxy_pdbs()
$this->app->contentType('text/plain');
$this->app->response()->body($response);
}
}
}
8 changes: 4 additions & 4 deletions api/src/Page/DC.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function _data_collections($single = null)
$info = array();
# Visits
if ($this->has_arg('visit')) {
$info = $this->db->pq("SELECT TO_CHAR(s.startdate, 'HH24') as sh, TO_CHAR(s.startdate, 'DDMMYYYY') as dmy, s.sessionid, s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) LIKE :1", array($this->arg('visit')));
$info = $this->db->pq("SELECT TO_CHAR(s.startdate, 'HH24') as sh, TO_CHAR(s.startdate, 'DDMMYYYY') as dmy, s.sessionid, s.beamlinename as bl FROM blsession s INNER JOIN proposal p ON (p.proposalid = s.proposalid) WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) LIKE :1", array($this->arg('visit')));

if (!sizeof($info)) {
$this->_error('No such visit');
Expand Down Expand Up @@ -225,8 +225,8 @@ function _data_collections($single = null)
array('project_has_xfefspectrum', 'xrf', 'xfefluorescencespectrumid'),
);

$extc = "CONCAT(CONCAT(CONCAT(prop.proposalcode,prop.proposalnumber), '-'), ses.visit_number) as vis, CONCAT(prop.proposalcode, prop.proposalnumber) as prop, ";
$extcg = "max(CONCAT(CONCAT(CONCAT(prop.proposalcode,prop.proposalnumber), '-'), ses.visit_number)) as vis, max(CONCAT(prop.proposalcode, prop.proposalnumber)) as prop, ";
$extc = "CONCAT(prop.proposalcode, prop.proposalnumber, '-', ses.visit_number) as vis, CONCAT(prop.proposalcode, prop.proposalnumber) as prop, ";
$extcg = "max(CONCAT(prop.proposalcode, prop.proposalnumber, '-', ses.visit_number)) as vis, max(CONCAT(prop.proposalcode, prop.proposalnumber)) as prop, ";
if ($this->has_arg('dcg'))
$extcg = $extc;

Expand Down Expand Up @@ -1063,7 +1063,7 @@ function _chk_image()
return;
}

$dct = $this->db->pq("SELECT CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) as vis, dc.datacollectionid as id, dc.startimagenumber, dc.filetemplate, dc.xtalsnapshotfullpath1 as x1, dc.xtalsnapshotfullpath2 as x2, dc.xtalsnapshotfullpath3 as x3, dc.xtalsnapshotfullpath4 as x4,dc.imageprefix as imp, dc.datacollectionnumber as run, dc.imagedirectory as dir, s.visit_number
$dct = $this->db->pq("SELECT CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) as vis, dc.datacollectionid as id, dc.startimagenumber, dc.filetemplate, dc.xtalsnapshotfullpath1 as x1, dc.xtalsnapshotfullpath2 as x2, dc.xtalsnapshotfullpath3 as x3, dc.xtalsnapshotfullpath4 as x4,dc.imageprefix as imp, dc.datacollectionnumber as run, dc.imagedirectory as dir, s.visit_number
FROM datacollection dc
INNER JOIN datacollectiongroup dcg ON dcg.datacollectiongroupid = dc.datacollectiongroupid
INNER JOIN blsession s ON s.sessionid = dcg.sessionid
Expand Down
2 changes: 1 addition & 1 deletion api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function _csv_report()
if (!$this->has_arg('visit'))
$this->_error('No visit specified', 'You must specify a visit to download a report for');

$vis = $this->db->pq("SELECT s.sessionid,s.beamlinename,TO_CHAR(s.startdate, 'DD_MM_YYYY') as st FROM blsession s INNER JOIN proposal p ON p.proposalid = s.proposalid WHERE CONCAT(CONCAT(CONCAT(p.proposalcode, p.proposalnumber), '-'), s.visit_number) LIKE :1", array($this->arg('visit')));
$vis = $this->db->pq("SELECT s.sessionid,s.beamlinename,TO_CHAR(s.startdate, 'DD_MM_YYYY') as st FROM blsession s INNER JOIN proposal p ON p.proposalid = s.proposalid WHERE CONCAT(p.proposalcode, p.proposalnumber, '-', s.visit_number) LIKE :1", array($this->arg('visit')));

if (!sizeof($vis))
$this->_error('No such visit', 'The specified visit doesnt exist');
Expand Down
Loading

0 comments on commit 9b5bd86

Please sign in to comment.