-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Barcode Endpoint + Introduction of Specimen Sample Numbers #255
Merged
ridz1208
merged 5 commits into
aces:24.1
from
HenriRabalais:2024-05-27_updated_barcode_generation_v2
Nov 7, 2024
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
58cf90b
implemented new barcode generation and introduced specimen sample num…
HenriRabalais 4085057
added changes to label endpoint for printing
HenriRabalais d175d1a
fix typo
HenriRabalais ed442c9
added pscid drop down for specimen filtering on the pool form
HenriRabalais c91845b
added filtering on specimen type and visit label
HenriRabalais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace LORIS\biobank; | ||
|
||
use \LORIS\Http\Endpoint; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class Barcodes extends Endpoint | ||
{ | ||
protected $db; | ||
protected $user; | ||
|
||
/** | ||
* Returns true if user has access to this Endpoint. | ||
* | ||
* @param \User $user The user whose access is being checked | ||
* | ||
* @return bool | ||
*/ | ||
function _hasAccess(\User $user) : bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Return which methods are supported by this endpoint. | ||
* | ||
* @return array supported HTTP methods | ||
*/ | ||
protected function allowedMethods() : array | ||
{ | ||
return ['GET', 'OPTIONS']; | ||
} | ||
|
||
/** | ||
* This function can be overridden in a module's page to load the necessary | ||
* resources to check the permissions of a user. | ||
* | ||
* @param User $user The user to load the resources for | ||
* @param ServerRequestInterface $request The PSR15 Request being handled | ||
* | ||
* @return void | ||
*/ | ||
public function loadResources( | ||
\User $user, ServerRequestInterface $request | ||
) : void { | ||
} | ||
|
||
/** | ||
* Handles Endpoint requests | ||
* | ||
* @param ServerRequestInterface $request The incoming PSR7 request | ||
* | ||
* @return ResponseInterface The outgoing PSR7 response | ||
*/ | ||
public function handle( | ||
ServerRequestInterface $request | ||
) : ResponseInterface { | ||
$this->db = \NDB_Factory::singleton()->database(); | ||
$this->user = $request->getAttribute('user'); | ||
|
||
try { | ||
switch ($request->getMethod()) { | ||
case 'GET': | ||
return $this->_handleGET($request); | ||
case 'OPTIONS': | ||
return (new \LORIS\Http\Response()) | ||
->withHeader('Allow', $this->allowedMethods()); | ||
} | ||
} catch (\Exception $e) { | ||
$this->db->rollBack(); | ||
return new \LORIS\Http\Response\JSON\InternalServerError( | ||
$e->getMessage() | ||
); | ||
} | ||
} | ||
|
||
// NOTE: the algorithm can stay here but should | ||
/** | ||
* Handle the logic of an incoming HTTP GET request | ||
* | ||
* @param ServerRequestInterface $request The incoming PSR7 request | ||
* @return ResponseInterface | ||
*/ | ||
private function _handleGET( | ||
ServerRequestInterface $request | ||
) : ResponseInterface { | ||
$currentYear = date('y'); | ||
|
||
$queryParams = $request->getQueryParams(); | ||
$count = isset($queryParams['count']) | ||
? intval($queryParams['count']) | ||
: 1; | ||
|
||
// Query to get the largest barcode for the current year | ||
$query = "SELECT MAX(CAST(SUBSTRING(Barcode, 3, 6) AS UNSIGNED)) AS max_number | ||
FROM biobank_container | ||
WHERE SUBSTRING(Barcode, 1, 2) = :year"; | ||
$params = [':year' => $currentYear]; | ||
$maxNumber = $this->db->pselectOne($query, $params); | ||
|
||
$newNumber = $maxNumber | ||
? $maxNumber + 1 | ||
: 1; | ||
|
||
$barcodes = []; | ||
for ($i = 0; $i < $count; $i++) { | ||
$newNumberFormatted = str_pad( | ||
$newNumber + $i, | ||
6, | ||
'0', | ||
STR_PAD_LEFT | ||
); | ||
$newBarcode = $currentYear . $newNumberFormatted; | ||
$barcodes[] = $newBarcode; | ||
} | ||
|
||
return new \LORIS\Http\Response\JSON\OK(['barcodes' => $barcodes]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TYPOOOOOOO semicolon