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
2277 UUID #2360
2277 UUID #2360
Changes from all commits
27a05b2
3d5d30e
084f78a
e7dbb82
8603487
447b171
7b9bce0
da2d3da
9e4b045
21b6c9a
e4e800e
e6d79c4
ce1d576
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
/** | ||
* Utility class for Uuid creation. | ||
* | ||
* @package OpenEMR | ||
* @link http://www.open-emr.org | ||
* @author Gerhard Brink <gjdbrink@gmail.com> | ||
* @copyright Copyright (c) 2019 Gerhard Brink <gjdbrink@gmail.com> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
namespace OpenEMR\Common\Utils; | ||
|
||
use Ramsey\Uuid\Uuid; | ||
|
||
class UuidUtils | ||
{ | ||
|
||
const MAX_TRIES = 100; | ||
|
||
/** | ||
* @param string $table | ||
* | ||
* @return string | ||
* @throws \Exception | ||
*/ | ||
public static function createUuid(string $table): string | ||
{ | ||
$uuid4 = Uuid::uuid4(); | ||
|
||
$try = 1; | ||
while (self::findCollision($table, $uuid4)) { | ||
if ($try > self::MAX_TRIES) { | ||
throw new \Exception('Reached maximum amount of tries (max amount: '.self::MAX_TRIES.')'); | ||
} | ||
|
||
$uuid4 = Uuid::uuid4(); | ||
$try++; | ||
} | ||
|
||
return $uuid4->toString(); | ||
} | ||
|
||
/** | ||
* @param $table | ||
* @param $uuid | ||
* | ||
* @return bool | ||
*/ | ||
public static function findCollision(string $table, string $uuid): bool | ||
{ | ||
$query = "SELECT uuid FROM ".$table." WHERE uuid = ?"; | ||
|
||
if (sqlQuery($query, $uuid)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param string $table | ||
* | ||
* @throws \Exception | ||
*/ | ||
public static function createMissingUuids(string $table) | ||
{ | ||
$query = "SELECT id FROM ".$table." WHERE uuid = ''"; | ||
|
||
$resultSet = sqlStatement($query); | ||
|
||
while ($row = sqlFetchArray($resultSet)) { | ||
|
||
$uuid = self::createUuid($table); | ||
|
||
$updateQuery = "UPDATE ".$table." SET uuid = ? WHERE id = ?"; | ||
|
||
sqlQuery($updateQuery, [$uuid, $row['id']]); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @param string $table | ||
* | ||
* @return bool | ||
*/ | ||
public static function tableNeedsUuidCreation(string $table): bool | ||
{ | ||
$query = "SELECT count(id) as total FROM ".$table." WHERE uuid = ''"; | ||
|
||
$resultSet = sqlQuery($query); | ||
|
||
if ($resultSet['total'] > 0) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -866,6 +866,14 @@ function upgradeFromSqlFile($filename) | |
if ($skipping) { | ||
echo "<font color='green'>Skipping section $line</font><br />\n"; | ||
} | ||
} else if (preg_match('/^#IfUuidUpdatePatientsNeeded/', $line)) { | ||
|
||
if ( \OpenEMR\Common\Utils\UuidUtils::tableNeedsUuidCreation('patient_data')) { | ||
\OpenEMR\Common\Utils\UuidUtils::createMissingUuids('patient_data'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this here:
|
||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this here:
|
||
echo "<font color='green'>Skipping section $line</font><br />\n"; | ||
} | ||
|
||
} else if (preg_match('/^#ConvertLayoutProperties/', $line)) { | ||
if ($skipping) { | ||
echo "<font color='green'>Skipping section $line</font><br />\n"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,10 @@ | |
-- arguments: none | ||
-- behavior: can take a long time. | ||
|
||
-- #IfUuidUpdatePatientsNeeded | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the bottom of this script, add the following lines:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And at the bottom of the script above the lines above, create the following block:
|
||
-- desc: populate patient table with uuids | ||
-- arguments: none | ||
|
||
UPDATE `background_services` SET `require_once`='/library/MedEx/MedEx_background.php' WHERE `name`='MedEx'; | ||
|
||
#IfNotRow2Dx2 list_options list_id proc_type option_id fgp title Custom Favorite Group | ||
|
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.
add this here: