Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.
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