From 24bd05c0025e6c1539ee184d9d844b80153c5f7e Mon Sep 17 00:00:00 2001 From: James Pence Date: Tue, 11 Aug 2020 17:27:19 -0400 Subject: [PATCH 1/3] Changing from ExternalModules call to get project settings from the framework call --- includes/send_rx_functions.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/includes/send_rx_functions.php b/includes/send_rx_functions.php index 1453544..a6748ca 100644 --- a/includes/send_rx_functions.php +++ b/includes/send_rx_functions.php @@ -7,7 +7,8 @@ include_once dirname(APP_PATH_DOCROOT) . '/vendor/autoload.php'; use ExternalModules\ExternalModules; -use UserProfile\UserProfile; + use SendRx\ExternalModule\ExternalModule; + use UserProfile\UserProfile; /** * Gets Send RX config from project. @@ -35,29 +36,30 @@ function send_rx_get_project_config($project_id, $project_type) { if (!in_array($project_type, array('patient', 'site'))) { return false; } + $externalModule = New ExternalModule(); - $q = ExternalModules::getSettings('send_rx', $project_id); - if (!db_num_rows($q)) { + $projSettings = $externalModule->framework->getProjectSettings($project_id); + + if (empty($projSettings)) { return false; } $config = array(); - while ($result = db_fetch_assoc($q)) { - if ($result['type'] == 'json' || $result['type'] == 'json-array') { - $result['value'] = json_decode($result['value']); + foreach ( $projSettings as $result ) { + if ( $result['type'] == 'json' || $result['type'] == 'json-array' ) { + $result['value'] = json_decode( $result['value'] ); - if (strpos($result['key'], 'send-rx-pdf-template-variable-') === false) { - $result['value'] = reset($result['value']); + if ( strpos( $result['key'], 'send-rx-pdf-template-variable-' ) === false ) { + $result['value'] = reset( $result['value'] ); } - } - elseif ($result['type'] == 'file') { - $result['value'] = send_rx_get_edoc_file_contents($result['value']); + } elseif ( $result['type'] == 'file' ) { + $result['value'] = send_rx_get_edoc_file_contents( $result['value'] ); } - $config[str_replace('-', '_', str_replace('send-rx-', '', $result['key']))] = $result['value']; + $config[str_replace( '-', '_', str_replace( 'send-rx-', '', $result['key'] ) )] = $result['value']; } - if ($config['type'] != $project_type || empty($config['target_project_id'])) { + if ( $config['type'] != $project_type || empty( $config['target_project_id'] ) ) { return false; } From 416e9ab27d186a0b25da3adbf6eb9600288706ae Mon Sep 17 00:00:00 2001 From: James Pence Date: Mon, 24 Aug 2020 12:25:47 -0400 Subject: [PATCH 2/3] Fixing the retreval of project settings without using ExternalModules static calls. --- includes/send_rx_functions.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/send_rx_functions.php b/includes/send_rx_functions.php index a6748ca..d60cefb 100644 --- a/includes/send_rx_functions.php +++ b/includes/send_rx_functions.php @@ -6,8 +6,8 @@ include_once dirname(APP_PATH_DOCROOT) . '/vendor/autoload.php'; +use SendRx\ExternalModule\ExternalModule; use ExternalModules\ExternalModules; - use SendRx\ExternalModule\ExternalModule; use UserProfile\UserProfile; /** @@ -36,11 +36,17 @@ function send_rx_get_project_config($project_id, $project_type) { if (!in_array($project_type, array('patient', 'site'))) { return false; } - $externalModule = New ExternalModule(); + // since $module isn't defined, getting a module to pull data out of + $externalModule = new ExternalModule(); + $config = $externalModule->getConfig(); - $projSettings = $externalModule->framework->getProjectSettings($project_id); + if ( $config['project-settings'] ) { + $projSettings = $config['project-settings']; + } else { + $projSettings = []; + } + if ( empty( $projSettings ) ) { - if (empty($projSettings)) { return false; } From 935ecb696024989b80d0e244fdeec75958caaef0 Mon Sep 17 00:00:00 2001 From: James Pence Date: Tue, 25 Aug 2020 15:49:07 -0400 Subject: [PATCH 3/3] After trying to get the values through method calls, went to the databse to retrieve the project specific values. --- includes/send_rx_functions.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/includes/send_rx_functions.php b/includes/send_rx_functions.php index d60cefb..15baa8c 100644 --- a/includes/send_rx_functions.php +++ b/includes/send_rx_functions.php @@ -33,24 +33,29 @@ * Returns FALSE if the project is not configure properly. */ function send_rx_get_project_config($project_id, $project_type) { - if (!in_array($project_type, array('patient', 'site'))) { + + if ( !in_array( $project_type, array( 'patient', 'site' ) ) ) { return false; } - // since $module isn't defined, getting a module to pull data out of + // since $module isn't defined, getting a module to pull data out $externalModule = new ExternalModule(); - $config = $externalModule->getConfig(); + // going to the database to retrieve that project specific settings. + $sql = "SELECT * FROM `redcap_external_module_settings` where `project_id` = ?"; + $moduleConfigResult = $externalModule->query( $sql, [ $project_id ] ); - if ( $config['project-settings'] ) { - $projSettings = $config['project-settings']; - } else { - $projSettings = []; + $projSettings = []; + // pulling a row of the module settings. + while ( $moduleConfigRow = $moduleConfigResult->fetch_assoc() ) { + $projSettings[] = $moduleConfigRow; } + if ( empty( $projSettings ) ) { return false; } $config = array(); + // assemble the config and decoding json as applicable foreach ( $projSettings as $result ) { if ( $result['type'] == 'json' || $result['type'] == 'json-array' ) { $result['value'] = json_decode( $result['value'] ); @@ -61,7 +66,6 @@ function send_rx_get_project_config($project_id, $project_type) { } elseif ( $result['type'] == 'file' ) { $result['value'] = send_rx_get_edoc_file_contents( $result['value'] ); } - $config[str_replace( '-', '_', str_replace( 'send-rx-', '', $result['key'] ) )] = $result['value']; } @@ -69,10 +73,12 @@ function send_rx_get_project_config($project_id, $project_type) { return false; } + // assembling the pdf Template array with the keys and values as applicable. if (!empty($config['pdf_template_variable_key'])) { $config['pdf_template_variables'] = array_combine($config['pdf_template_variable_key'], $config['pdf_template_variable_value']); } + // removing the keys that aren't required. $to_remove = array( 'enabled', 'pdf_template_variable',