Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 411438a

Browse files
author
Jamie Snape
committed
Migrate dicomextractor module settings to database
1 parent 0077c8e commit 411438a

File tree

11 files changed

+302
-231
lines changed

11 files changed

+302
-231
lines changed
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
[global]
2-
; version of the module
3-
version = 1.0.0
4-
; full name
5-
fullname = DICOM Extractor
6-
; description
7-
description = Extract metadata from DICOM files
8-
; category
9-
category = DICOM
10-
; dependencies
11-
dependencies = scheduler,api,thumbnailcreator
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
122

13-
; hachoir-metadata command
14-
dcm2xml = "dcm2xml"
15-
dcmj2pnm = "dcmj2pnm --write-jpeg --min-max-window"
16-
dcmftest = "dcmftest"
17-
dcmdictpath = ""
3+
[global]
4+
fullname = "DICOM Extractor"
5+
description = "Extract metadata from DICOM files"
6+
category = "DICOM"
7+
dependencies = api,scheduler,thumbnailcreator
8+
uuid = "53ef7737-29d8-4873-97f5-d35ffb2c2200"
9+
version = "1.1.0"

modules/dicomextractor/controllers/forms/ConfigForm.php renamed to modules/dicomextractor/constant/module.php

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,11 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
/** Configuration form for the dicom extractor */
22-
class Dicomextractor_ConfigForm extends AppForm
23-
{
24-
/** create form */
25-
public function createConfigForm()
26-
{
27-
$form = new Zend_Form();
28-
29-
$form->setAction($this->webroot.'/dicomextractor/config/index')->setMethod('post');
30-
31-
$dcm2xml = new Zend_Form_Element_Text('dcm2xml');
32-
$dcmj2pnm = new Zend_Form_Element_Text('dcmj2pnm');
33-
$dcmftest = new Zend_Form_Element_Text('dcmftest');
34-
$dcmdictpath = new Zend_Form_Element_Text('dcmdictpath');
35-
36-
$submit = new Zend_Form_Element_Submit('submitConfig');
37-
$submit->setLabel('Save configuration');
38-
39-
$form->addElements(array($dcm2xml, $dcmj2pnm, $dcmftest, $dcmdictpath, $submit));
40-
41-
return $form;
42-
}
43-
}
21+
define('DICOMEXTRACTOR_DCM2XML_COMMAND_KEY', 'dcm2xml_command');
22+
define('DICOMEXTRACTOR_DCM2XML_COMMAND_DEFAULT_VALUE', 'dcm2xml');
23+
define('DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY', 'dcmj2pnm_command');
24+
define('DICOMEXTRACTOR_DCMJ2PNM_COMMAND_DEFAULT_VALUE', 'dcmj2pnm --write-jpeg --min-max-window');
25+
define('DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY', 'dcmftest_command');
26+
define('DICOMEXTRACTOR_DCMFTEST_COMMAND_DEFAULT_VALUE', 'dcmftest');
27+
define('DICOMEXTRACTOR_DCMDICTPATH_KEY', 'dcmdictpath');
28+
define('DICOMEXTRACTOR_DCMDICTPATH_DEFAULT_VALUE', '');
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the dicomextractor module. */
22+
class Dicomextractor_AdminController extends Dicomextractor_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'DICOM Extractor Module Configuration';
33+
$form = new Dicomextractor_Form_Admin();
34+
35+
if ($this->getRequest()->isPost()) {
36+
$data = $this->getRequest()->getPost();
37+
38+
if ($form->isValid($data)) {
39+
$values = $form->getValues();
40+
41+
foreach ($values as $key => $value) {
42+
if ($value !== null) {
43+
$this->Setting->setConfig($key, $value, $this->moduleName);
44+
}
45+
}
46+
}
47+
48+
$form->populate($data);
49+
} else {
50+
$elements = $form->getElements();
51+
52+
foreach ($elements as $element) {
53+
$name = $element->getName();
54+
55+
if ($name !== 'csrf' && $name !== 'submit') {
56+
$value = $this->Setting->getValueByName($name, $this->moduleName);
57+
58+
if (!is_null($value)) {
59+
$form->setDefault($name, $value);
60+
}
61+
}
62+
}
63+
}
64+
65+
$this->view->form = $form;
66+
session_start();
67+
}
68+
}

modules/dicomextractor/controllers/ConfigController.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

modules/dicomextractor/controllers/components/ExtractorComponent.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
/** Extract dicom metadata */
2424
class Dicomextractor_ExtractorComponent extends AppComponent
2525
{
26+
public $moduleName = 'dicomextractor';
27+
2628
/**
2729
* Check whether a given application is configured properly.
2830
*
2931
* @param command the command to test with
3032
* @param appName the human-readable application name
31-
* @appendVersion whether we need the --version flag
33+
* @param appendVersion whether we need the --version flag
3234
* @return an array indicating whether the app is valid or not
3335
*/
3436
public function getApplicationStatus($preparedCommand, $appName, $appendVersion = true)
@@ -76,8 +78,10 @@ private function _getExecutableArg($commandWithParams)
7678
*/
7779
private function _prependDataDict(&$command)
7880
{
79-
$modulesConfig = Zend_Registry::get('configsModules');
80-
$dictPath = $modulesConfig['dicomextractor']->dcmdictpath;
81+
/** @var SettingModel $settingModel */
82+
$settingModel = MidasLoader::loadModel('Setting');
83+
$dictPath = $settingModel->getValueByName(DICOMEXTRACTOR_DCMDICTPATH_KEY, $this->moduleName);
84+
8185
if ($dictPath != "") {
8286
$command = 'DCMDICTPATH="'.$dictPath.'" '.$command;
8387
}
@@ -88,18 +92,24 @@ private function _prependDataDict(&$command)
8892
*/
8993
public function isDCMTKWorking()
9094
{
91-
$ret = array();
92-
$modulesConfig = Zend_Registry::get('configsModules');
93-
$dcm2xmlCommand = $modulesConfig['dicomextractor']->dcm2xml;
94-
$dcmftestCommand = $modulesConfig['dicomextractor']->dcmftest;
95+
/** @var SettingModel $settingModel */
96+
$settingModel = MidasLoader::loadModel('Setting');
97+
$dcm2xmlCommand = $settingModel->getValueByName(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, $this->moduleName);
98+
$dcmftestCommand = $settingModel->getValueByName(DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY, $this->moduleName);
99+
95100
// dcmj2pnmCommand may have some params that will cause it to throw
96101
// an error when no input is given, hence for existence and configuration
97102
// testing just get the command itself, without params
98-
$dcmj2pnmCommand = $this->_getExecutableArg($modulesConfig['dicomextractor']->dcmj2pnm);
103+
$dcmj2pnmCommand = $this->_getExecutableArg($settingModel->getValueByName(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, $this->moduleName));
104+
105+
$ret = array();
99106
$ret['dcm2xml'] = $this->getApplicationStatus($dcm2xmlCommand, 'dcm2xml');
100107
$ret['dcmftest'] = $this->getApplicationStatus($dcmftestCommand, 'dcmftest', false);
101108
$ret['dcmj2pnm'] = $this->getApplicationStatus($dcmj2pnmCommand, 'dcmj2pnm');
102-
if ($modulesConfig['dicomextractor']->dcmdictpath == "") {
109+
110+
$dataDictVar = $settingModel->getValueByName(DICOMEXTRACTOR_DCMDICTPATH_KEY, $this->moduleName);
111+
112+
if ($dataDictVar == "") {
103113
if (is_readable('/usr/local/share/dcmtk/dicom.dic') || // default on OS X
104114
is_readable('/usr/share/dcmtk/dicom.dic')
105115
) { // default on Ubuntu
@@ -111,7 +121,6 @@ public function isDCMTKWorking()
111121
);
112122
}
113123
} else {
114-
$dataDictVar = $modulesConfig['dicomextractor']->dcmdictpath;
115124
$dictPaths = explode(":", $dataDictVar);
116125
$errorInDictVar = false;
117126
foreach ($dictPaths as $path) {
@@ -154,10 +163,12 @@ public function thumbnail($item)
154163
$bitstream = $bitstreams[$numBitstreams / 2];
155164

156165
// Turn the DICOM into a JPEG
157-
$modulesConfig = Zend_Registry::get('configsModules');
158166
$tempDirectory = $utilityComponent->getTempDirectory();
159167
$tmpSlice = $tempDirectory.'/'.$bitstream->getName().'.jpg';
160-
$command = $modulesConfig['dicomextractor']->dcmj2pnm;
168+
169+
/** @var SettingModel $settingModel */
170+
$settingModel = MidasLoader::loadModel('Setting');
171+
$command = $settingModel->getValueByName(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, $this->moduleName);
161172
$preparedCommand = str_replace("'", '"', $command);
162173
$preparedCommand .= ' "'.$bitstream->getFullPath().'" "'.$tmpSlice.'"';
163174
$this->_prependDataDict($preparedCommand);
@@ -183,8 +194,10 @@ public function extract($revision)
183194
return;
184195
}
185196
$bitstream = $bitstreams[0];
186-
$modulesConfig = Zend_Registry::get('configsModules');
187-
$command = $modulesConfig['dicomextractor']->dcm2xml;
197+
198+
/** @var SettingModel $settingModel */
199+
$settingModel = MidasLoader::loadModel('Setting');
200+
$command = $settingModel->getValueByName(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, $this->moduleName);
188201
$preparedCommand = str_replace("'", '"', $command);
189202
$preparedCommand .= ' "'.$bitstream->getFullPath().'"';
190203
$this->_prependDataDict($preparedCommand);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/dicomextractor/constant/module.php';
22+
23+
/** Install the dicomextractor module. */
24+
class Dicomextractor_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'dicomextractor';
28+
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, DICOMEXTRACTOR_DCM2XML_COMMAND_DEFAULT_VALUE, $this->moduleName);
35+
$settingModel->setConfig(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, DICOMEXTRACTOR_DCMJ2PNM_COMMAND_DEFAULT_VALUE, $this->moduleName);
36+
$settingModel->setConfig(DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY, DICOMEXTRACTOR_DCMFTEST_COMMAND_DEFAULT_VALUE, $this->moduleName);
37+
$settingModel->setConfig(DICOMEXTRACTOR_DCMDICTPATH_KEY, DICOMEXTRACTOR_DCMDICTPATH_DEFAULT_VALUE, $this->moduleName);
38+
}
39+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Upgrade the dicomextractor module to version 1.1.0. */
22+
class Dicomextractor_Upgrade_1_1_0 extends MIDASUpgrade
23+
{
24+
/** @var string */
25+
public $moduleName = 'dicomextractor';
26+
27+
/** Post database upgrade. */
28+
public function postUpgrade()
29+
{
30+
/** @var SettingModel $settingModel */
31+
$settingModel = MidasLoader::loadModel('Setting');
32+
$configPath = LOCAL_CONFIGS_PATH.DIRECTORY_SEPARATOR.$this->moduleName.'.local.ini';
33+
34+
if (file_exists($configPath)) {
35+
$config = new Zend_Config_Ini($configPath, 'global');
36+
$settingModel->setConfig(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, $config->get('dcm2xml', DICOMEXTRACTOR_DCM2XML_COMMAND_DEFAULT_VALUE), $this->moduleName);
37+
$settingModel->setConfig(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, $config->get('dcmj2pnm', DICOMEXTRACTOR_DCMJ2PNM_COMMAND_DEFAULT_VALUE), $this->moduleName);
38+
$settingModel->setConfig(DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY, $config->get('dcmftest', DICOMEXTRACTOR_DCMFTEST_COMMAND_DEFAULT_VALUE), $this->moduleName);
39+
$settingModel->setConfig(DICOMEXTRACTOR_DCMDICTPATH_KEY, $config->get('dcmdictpath', DICOMEXTRACTOR_DCMDICTPATH_DEFAULT_VALUE), $this->moduleName);
40+
41+
$config = new Zend_Config_Ini($configPath, null, true);
42+
unset($config->global->dcm2xml);
43+
unset($config->global->dcmj2pnm);
44+
unset($config->global->dcmftest);
45+
unset($config->global->dcmdictpath);
46+
47+
$writer = new Zend_Config_Writer_Ini();
48+
$writer->setConfig($config);
49+
$writer->setFilename($configPath);
50+
$writer->write();
51+
} else {
52+
$settingModel->setConfig(DICOMEXTRACTOR_DCM2XML_COMMAND_KEY, DICOMEXTRACTOR_DCM2XML_COMMAND_DEFAULT_VALUE, $this->moduleName);
53+
$settingModel->setConfig(DICOMEXTRACTOR_DCMJ2PNM_COMMAND_KEY, DICOMEXTRACTOR_DCMJ2PNM_COMMAND_DEFAULT_VALUE, $this->moduleName);
54+
$settingModel->setConfig(DICOMEXTRACTOR_DCMFTEST_COMMAND_KEY, DICOMEXTRACTOR_DCMFTEST_COMMAND_DEFAULT_VALUE, $this->moduleName);
55+
$settingModel->setConfig(DICOMEXTRACTOR_DCMDICTPATH_KEY, DICOMEXTRACTOR_DCMDICTPATH_DEFAULT_VALUE, $this->moduleName);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)