Skip to content
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

[DICOM archive] Ensure that settings necessary for anonymization exist #4165

Merged
merged 4 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions modules/dicom_archive/php/dicom_archive.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This class features the code for the menu portion
* of the Loris dicom archive.
*
* PHP Version 5
* PHP Version 7
*
* @category Behavioural
* @package Main
Expand Down Expand Up @@ -97,7 +97,6 @@ class Dicom_Archive extends \NDB_Menu_Filter
$this->addBasicText('seriesuid', 'Series UID');
}


/**
* Converts the results of this menu filter to a JSON format to be retrieved
* with ?format=json
Expand All @@ -106,6 +105,9 @@ class Dicom_Archive extends \NDB_Menu_Filter
*/
function toJSON()
{
/* Ensure that the server is well configured to prevent displaying
* data that is not properly anonmyized.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems to be out of place

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is still here

$table = (new \LORIS\Data\Table())
->withDataFrom($this->getDataProvisioner());
$arr = array_map(
Expand Down
67 changes: 66 additions & 1 deletion modules/dicom_archive/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @link https://www.github.com/aces/Loris-Trunk/
*/
namespace LORIS\dicom_archive;
use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;

/**
* Class module implements the basic LORIS module functionality
Expand All @@ -26,4 +28,67 @@ namespace LORIS\dicom_archive;
*/
class Module extends \Module
{
}
/**
* Handle a PSR7 Request for the dicom_archive endpoint. Also calls a
* validation function to ensure necessary configuration settings exist.
*
* @param ServerRequestInterface $request The PSR15 Request being handled
*
* @return ResponseInterface The PSR15 response for the page.
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
try {
$this->validateConfig();
} catch (\ConfigurationException $e) {
error_log($e);
return (new \LORIS\Middleware\PageDecorationMiddleware(
$request->getAttribute("user") ?? new \LORIS\AnonymousUser()
))->process(
$request,
new \LORIS\Router\NoopResponder(
new \LORIS\Http\Error(
$request,
500,
'Required configuration settings for DICOM ' .
'anonymization are missing. Cannot continue.'
)
)
);
}
return parent::handle($request);
}

/**
* Checks that the required configuration settings are properly set. Throws
* a ConfigurationException if not.
*
* @return void
*
* @throws \ConfigurationException
*/
function validateConfig(): void
{
/* Ensure that all required configuraton settings are properly set
* before continuing.
*/
$config = \NDB_Config::singleton()->getSetting("imaging_modules");
$configOptions = array(
'patientNameRegex',
'LegoPhantomRegex',
'LivingPhantomRegex',
'patientIDRegex',
);
$configError = 'Configuration settings missing for DICOM anonymization. ' .
'Please ensure that the following settings are configured to ' .
'be valid regular expressions: ';
foreach ($configOptions as $option) {
if (!isset($config[$option])) {
throw new \ConfigurationException(
$configError . implode(', ', $configOptions)
);
}
}
}

}