Skip to content

Removing ExternalModules static calls #98

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all 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
44 changes: 29 additions & 15 deletions includes/send_rx_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

include_once dirname(APP_PATH_DOCROOT) . '/vendor/autoload.php';

use SendRx\ExternalModule\ExternalModule;
use ExternalModules\ExternalModules;
use UserProfile\UserProfile;
use UserProfile\UserProfile;

/**
* Gets Send RX config from project.
Expand All @@ -32,39 +33,52 @@
* 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
$externalModule = new ExternalModule();
// 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 ] );

$projSettings = [];
// pulling a row of the module settings.
while ( $moduleConfigRow = $moduleConfigResult->fetch_assoc() ) {
$projSettings[] = $moduleConfigRow;
}

if ( empty( $projSettings ) ) {

$q = ExternalModules::getSettings('send_rx', $project_id);
if (!db_num_rows($q)) {
return false;
}

$config = array();
while ($result = db_fetch_assoc($q)) {
if ($result['type'] == 'json' || $result['type'] == 'json-array') {
$result['value'] = json_decode($result['value']);
// 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'] );

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;
}

// 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',
Expand Down