Skip to content

Commit

Permalink
Specimen Upload
Browse files Browse the repository at this point in the history
- Integrate omoccuridentifiers table into specimen upload option to match on other identifiers
  • Loading branch information
egbot committed Jan 11, 2022
1 parent d83b5e5 commit cce3f21
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 60 deletions.
13 changes: 13 additions & 0 deletions classes/OccurrenceSesar.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,19 @@ public function syncIGSN($occid,$catalogNumber,$igsn){
}
$rs->free();

$sql = 'SELECT identifierValue FROM omoccuridentifiers WHERE occid = '.$occid;
$rs = $this->conn->query($sql);
while($r = $rs->fetch_object()){
if($r->identifierValue != $catalogNumber && $r->identifierValue != $catalogNumber){
$retArr['errCode'] = 2;
$catNum = $r->identifierValue;
if(isset($retArr['catNum'])) $catNum .= ', '.$retArr['catNum'];
$retArr['catNum'] = $catNum;
$ok = false;
}
}
$rs->free();

if($ok){
$sqlUpdate = 'UPDATE omoccurrences SET occurrenceid = "'.$this->cleanInStr($igsn).'" WHERE occid = '.$occid;
if($this->conn->query($sqlUpdate)){
Expand Down
27 changes: 9 additions & 18 deletions classes/OccurrenceSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,21 @@ public function getOccurrenceList($collid, $catalogNumber, $otherCatalogNumbers,
$retArr = Array();
if(!$catalogNumber && !$otherCatalogNumbers && !$recordedBy && !$recordNumber) return $retArr;
$sqlWhere = "";
if($collid){
$sqlWhere .= "AND (o.collid = ".$collid.") ";
}
if($catalogNumber){
$sqlWhere .= 'AND (o.catalognumber = "'.$catalogNumber.'") ';
}
if($otherCatalogNumbers){
$sqlWhere .= 'AND (o.othercatalognumbers = "'.$otherCatalogNumbers.'") ';
}
if($collid) $sqlWhere .= "AND (o.collid = ".$collid.") ";
if($catalogNumber) $sqlWhere .= 'AND (o.catalognumber = "'.$catalogNumber.'") ';
if($otherCatalogNumbers) $sqlWhere .= 'AND (o.othercatalognumbers = "'.$otherCatalogNumbers.'" OR i.identifiervalue = "'.$otherCatalogNumbers.'") ';
if($recordedBy){
if(strlen($recordedBy) < 4 || in_array(strtolower($recordedBy),array('best','little'))){
//Need to avoid FULLTEXT stopwords interfering with return
$sqlWhere .= 'AND (o.recordedby LIKE "%'.$recordedBy.'%") ';
}
else{
$sqlWhere .= 'AND (MATCH(f.recordedby) AGAINST("'.$recordedBy.'")) ';
}
}
if($recordNumber){
$sqlWhere .= 'AND (o.recordnumber = "'.$recordNumber.'") ';
else $sqlWhere .= 'AND (MATCH(f.recordedby) AGAINST("'.$recordedBy.'")) ';
}
$sql = 'SELECT o.occid, o.recordedby, o.recordnumber, o.eventdate, CONCAT_WS("; ",o.stateprovince, o.county, o.locality) AS locality '.
'FROM omoccurrences o LEFT JOIN omoccurrencesfulltext f ON o.occid = f.occid '.
'WHERE '.substr($sqlWhere,4);
if($recordNumber) $sqlWhere .= 'AND (o.recordnumber = "'.$recordNumber.'") ';
$sql = 'SELECT o.occid, o.recordedby, o.recordnumber, o.eventdate, CONCAT_WS("; ",o.stateprovince, o.county, o.locality) AS locality
FROM omoccurrences o LEFT JOIN omoccurrencesfulltext f ON o.occid = f.occid ';
if($otherCatalogNumbers) $sql .= 'LEFT JOIN omoccuridentifiers i ON o.occid = i.occid ';
$sql .= 'WHERE '.substr($sqlWhere,4);
//echo $sql;
$rs = $this->conn->query($sql);
while($row = $rs->fetch_object()){
Expand Down
75 changes: 38 additions & 37 deletions classes/SpecUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ public function validateSecurityKey($k){
$sql = 'SELECT collid FROM omcollections WHERE securitykey = "'.$k.'"';
//echo $sql;
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$this->setCollId($r->collid);
}
else{
return false;
}
if($r = $rs->fetch_object()){
$this->setCollId($r->collid);
}
else{
return false;
}
$rs->free();
}
elseif(!isset($this->collMetadataArr["securitykey"])){
Expand Down Expand Up @@ -246,7 +246,8 @@ private function getPendingImportSql($searchVariables){
if($searchVariables == 'matchappend'){
$sql = 'SELECT DISTINCT u.occid, u.dbpk, u.'.implode(',u.',$occFieldArr).' '.
'FROM uploadspectemp u INNER JOIN omoccurrences o ON u.collid = o.collid '.
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.catalogNumber = o.catalogNumber OR u.othercatalogNumbers = o.othercatalogNumbers) ';
'LEFT JOIN omoccuridentifiers i ON o.occid = i.occid '.
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.catalogNumber = o.catalogNumber OR u.othercatalogNumbers = o.othercatalogNumbers OR u.othercatalogNumbers = i.identifiervalue) ';
}
elseif($searchVariables == 'sync'){
$sql = 'SELECT DISTINCT u.occid, u.dbpk, u.'.implode(',u.',$occFieldArr).' '.
Expand Down Expand Up @@ -317,38 +318,38 @@ public function getUploadCount(){
}

//Profile management
public function readUploadParameters(){
if($this->uspid){
public function readUploadParameters(){
if($this->uspid){
$sql = 'SELECT usp.collid, usp.title, usp.Platform, usp.server, usp.port, usp.Username, usp.Password, usp.SchemaName, '.
'usp.code, usp.path, usp.pkfield, usp.querystr, usp.cleanupsp, cs.uploaddate, usp.uploadtype '.
'usp.code, usp.path, usp.pkfield, usp.querystr, usp.cleanupsp, cs.uploaddate, usp.uploadtype '.
'FROM uploadspecparameters usp LEFT JOIN omcollectionstats cs ON usp.collid = cs.collid '.
'WHERE (usp.uspid = '.$this->uspid.')';
'WHERE (usp.uspid = '.$this->uspid.')';
//echo $sql;
$result = $this->conn->query($sql);
if($row = $result->fetch_object()){
if(!$this->collId) $this->collId = $row->collid;
$this->title = $row->title;
$this->platform = $row->Platform;
$this->server = $row->server;
$this->port = $row->port;
$this->username = $row->Username;
$this->password = $row->Password;
$this->schemaName = $row->SchemaName;
$this->code = $row->code;
if(!$this->path) $this->path = $row->path;
$this->pKField = strtolower($row->pkfield);
$this->queryStr = $row->querystr;
$this->storedProcedure = $row->cleanupsp;
$this->lastUploadDate = $row->uploaddate;
$this->uploadType = $row->uploadtype;
if(!$this->lastUploadDate) $this->lastUploadDate = date('Y-m-d H:i:s');
}
$result->free();
}
}

public function editUploadProfile($profileArr){
$sql = 'UPDATE uploadspecparameters SET title = "'.$this->cleanInStr($profileArr['title']).'"'.
if($row = $result->fetch_object()){
if(!$this->collId) $this->collId = $row->collid;
$this->title = $row->title;
$this->platform = $row->Platform;
$this->server = $row->server;
$this->port = $row->port;
$this->username = $row->Username;
$this->password = $row->Password;
$this->schemaName = $row->SchemaName;
$this->code = $row->code;
if(!$this->path) $this->path = $row->path;
$this->pKField = strtolower($row->pkfield);
$this->queryStr = $row->querystr;
$this->storedProcedure = $row->cleanupsp;
$this->lastUploadDate = $row->uploaddate;
$this->uploadType = $row->uploadtype;
if(!$this->lastUploadDate) $this->lastUploadDate = date('Y-m-d H:i:s');
}
$result->free();
}
}

public function editUploadProfile($profileArr){
$sql = 'UPDATE uploadspecparameters SET title = "'.$this->cleanInStr($profileArr['title']).'"'.
', platform = '.($profileArr['platform']?'"'.$profileArr['platform'].'"':'NULL').
', server = '.($profileArr['server']?'"'.$profileArr['server'].'"':'NULL').
', port = '.($profileArr['port']?$profileArr['port']:'NULL').
Expand All @@ -369,7 +370,7 @@ public function editUploadProfile($profileArr){
return true;
}

public function createUploadProfile($profileArr){
public function createUploadProfile($profileArr){
$sql = 'INSERT INTO uploadspecparameters(collid, uploadtype, title, platform, server, port, code, path, '.
'pkfield, username, password, schemaname, cleanupsp, querystr) VALUES ('.$this->collId.','.
$profileArr['uploadtype'].',"'.$this->cleanInStr($profileArr['title']).'",'.
Expand All @@ -394,7 +395,7 @@ public function createUploadProfile($profileArr){
}
}

public function deleteUploadProfile($uspid){
public function deleteUploadProfile($uspid){
$sql = 'DELETE FROM uploadspecparameters WHERE (uspid = '.$uspid.')';
if(!$this->conn->query($sql)){
$this->errorStr = '<div>Error Adding Upload Parameters: '.$this->conn->error.'</div><div>'.$sql.'</div>';
Expand Down
19 changes: 14 additions & 5 deletions classes/SpecUploadBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,20 @@ protected function cleanUpload(){
}
if($this->matchOtherCatalogNumbers){
//Match records based on other Catalog Numbers fields
$sql2 = 'UPDATE uploadspectemp u INNER JOIN omoccurrences o ON (u.otherCatalogNumbers = o.otherCatalogNumbers) AND (u.collid = o.collid) '.
$sql2 = 'UPDATE uploadspectemp u INNER JOIN omoccurrences o ON u.collid = o.collid '.
'SET u.occid = o.occid '.
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.othercatalogNumbers IS NOT NULL) AND (o.othercatalogNumbers IS NOT NULL) ';
if($this->collMetadataArr['colltype'] == 'General Observations' && $this->observerUid) $sql .= ' AND o.observeruid = '.$this->observerUid;
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.otherCatalogNumbers = o.otherCatalogNumbers) ';
if($this->collMetadataArr['colltype'] == 'General Observations' && $this->observerUid) $sql2 .= ' AND o.observeruid = '.$this->observerUid;
if(!$this->conn->query($sql2)){
$this->outputMsg('<li><span style="color:red;">Warning: unable to match on other catalog numbers: '.$this->conn->error.'</span></li>');
$this->outputMsg('<li><span style="color:red;">Warning: unable to match on otherCatalogNumbers: '.$this->conn->error.'</span></li>');
}
$sql2b = 'UPDATE uploadspectemp u INNER JOIN omoccurrences o ON u.collid = o.collid '.
'INNER JOIN omoccuridentifiers i ON o.occid = i.occid '.
'SET u.occid = o.occid '.
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.othercatalogNumbers = i.identifiervalue) ';
if($this->collMetadataArr['colltype'] == 'General Observations' && $this->observerUid) $sql2b .= ' AND o.observeruid = '.$this->observerUid;
if(!$this->conn->query($sql2b)){
$this->outputMsg('<li><span style="color:red;">Warning: unable to match on omoccuridentifiers: '.$this->conn->error.'</span></li>');
}
}
}
Expand Down Expand Up @@ -703,7 +711,8 @@ public function getTransferReport(){
//Records that can be matched on Catalog Number, but will be appended
$sql = 'SELECT count(o.occid) AS cnt '.
'FROM uploadspectemp u INNER JOIN omoccurrences o ON u.collid = o.collid '.
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.catalogNumber = o.catalogNumber OR u.othercatalogNumbers = o.othercatalogNumbers) ';
'LEFT JOIN omoccuridentifiers i ON o.occid = i.occid '.
'WHERE (u.collid IN('.$this->collId.')) AND (u.occid IS NULL) AND (u.catalogNumber = o.catalogNumber OR u.othercatalogNumbers = o.othercatalogNumbers OR u.othercatalogNumbers = i.identifierValue) ';
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$reportArr['matchappend'] = $r->cnt;
Expand Down

0 comments on commit cce3f21

Please sign in to comment.