$raw_data_rows = explode('|||', strip_tags(str_replace('<br>', '|||', $result['data_display']))); foreach ($raw_data_rows AS $raw_data_row) { $this_row_array = explode(': ', $raw_data_row); $data_array[$this_row_array[0]] = $this_row_array[1]; } ksort($data_array); d($data_array); /** * we don't want to duplicate queries * if the result is excluded or has a query history, ignore it */ if (!$result['exclude']) { d($history); //$data_row['monitor'] = $result['record'] & 1 ? 'dianne_mattingly' : 'wendy_robertson'; $data_row['subjid'] = quote_wrap($result['record']); $data_row['usubjid'] = quote_wrap(get_single_field($result['record'], PROJECT_ID, $Proj->firstEventId, 'dm_usubjid', '')); $data_row['event'] = quote_wrap(REDCap::getEventNames(false, false, $result['event_id'])); //$data_row['field'] = quote_wrap($Proj->metadata[$field]['element_label']); //$data_row['data'] = quote_wrap(strip_tags(str_replace('<br>', ', ', $result['data_display']))); foreach ($data_array AS $key => $val) { $data_row[quote_wrap($Proj->metadata[$key]['element_label'] . " [$key]")] = quote_wrap($val); } $data_row['description'] = quote_wrap($rule_info['name']); $data_row["Queries on $field"] = quote_wrap(count($history)); $row_csv = implode(',', $data_row) . "\n"; $table_csv .= $row_csv; } } } $headers = implode(',', array_keys($data_row)) . "\n"; if (!$debug) {
$allowed_pids = array('38'); REDCap::allowProjects($allowed_pids); /** * do stuff */ if ($debug) { if (!is_form_locked($record, $instrument, $redcap_event_name)) { d(is_t_complete($record, $event_id), $redcap_event_name); } global $Proj, $project_id; $today = date("Y-m-d"); $fields = array(); $arms = get_arms(array_keys($Proj->eventsForms)); d($arms); $baseline_event_id = $Proj->firstEventId; $tx_duration = get_single_field($record, $project_id, $baseline_event_id, 'trt_exdur', null); $tx_duration = substr($tx_duration, strpos($tx_duration, 'P') + 1, strlen($tx_duration) - 2); $tx_first_event = array_search_recursive($tx_duration . ' Weeks', $arms) !== false ? array_search_recursive($tx_duration . ' Weeks', $arms) : null; $survey_event_ids = $Proj->getEventsByArmNum($arms[$tx_first_event]['arm_num']); d($survey_event_ids); foreach ($survey_event_ids as $survey_event_id) { $survey_event_name = $Proj->getUniqueEventNames($survey_event_id); $survey_prefix = substr($survey_event_name, 0, strpos($survey_event_name, '_')); $fields[] = $survey_prefix . '_completed'; $fields[] = $survey_prefix . '_date'; $fields[] = $survey_prefix . '_startdate'; $fields[] = $survey_prefix . '_deadline'; $fields[] = $survey_prefix . '_missed'; } d($fields); $data = REDCap::getData('array', $record, $fields, $baseline_event_id);
/** * @param $record * @param $debug * determine completeness of all survey-containing events */ function set_survey_completion($record, $debug) { if (isset($record)) { global $Proj, $project_id; $today = date("Y-m-d"); $fields = array(); $arms = get_arms(array_keys($Proj->eventsForms)); $baseline_event_id = $Proj->firstEventId; $trt = Treatment::getTrtInfo($record); /** * use the selected duration ($trt['arm']) to set timings */ $tx_first_event = array_search_recursive($trt['arm'], $arms) !== false ? array_search_recursive($trt['arm'], $arms) : null; $survey_event_ids = isset($tx_first_event) ? $Proj->getEventsByArmNum($arms[$tx_first_event]['arm_num']) : null; foreach ($survey_event_ids AS $survey_event_id) { $data_event_name = $Proj->getUniqueEventNames($survey_event_id); $prefix = substr($data_event_name, 0, strpos($data_event_name, '_')); /** * derive inter-event timing variables */ $start_date_value = get_single_field($record, $project_id, $baseline_event_id, $prefix . '_startdate', null); $deadline_value = get_single_field($record, $project_id, $baseline_event_id, $prefix . '_deadline', null); /** * for baseline surveys, reference date is randomization date. For all other survey events, * reference date is dm_rfxstdtc, recorded treatment start date NOT dm_rfstdtc, the * treatment start derived from the treatment med data */ $t_base_date = in_array($prefix, array('baseline', 'eot1year', 'eot3year')) ? $trt['rand_date'] : $trt['rfxstdtc']; if (isset($t_base_date) && $t_base_date != '') { $t_start_date = add_date($t_base_date, ($arms[$data_event_name]['day_offset'] - $arms[$data_event_name]['offset_min'])); update_field_compare($record, $project_id, $baseline_event_id, $t_start_date, $start_date_value, $prefix . '_startdate', $debug); $t_deadline_date = add_date($t_base_date, ($arms[$data_event_name]['day_offset'] + $arms[$data_event_name]['offset_max']) - 1); update_field_compare($record, $project_id, $baseline_event_id, $t_deadline_date, $deadline_value, $prefix . '_deadline', $debug); } } foreach ($survey_event_ids AS $survey_event_id) { $survey_event_name = $Proj->getUniqueEventNames($survey_event_id); $survey_prefix = substr($survey_event_name, 0, strpos($survey_event_name, '_')); $fields[] = $survey_prefix . '_completed'; $fields[] = $survey_prefix . '_date'; $fields[] = $survey_prefix . '_startdate'; $fields[] = $survey_prefix . '_deadline'; } $data = REDCap::getData('array', $record, $fields, $baseline_event_id); /** * switch to the scheduled arm to determine completion * this is done to avoid subjects switching arms and orphaning surveys completed * prior to duration change. This should (almost) never happen, but we still need to handle if it does */ $tx_first_event = array_search_recursive($trt['timing_arm'], $arms) !== false ? array_search_recursive($trt['timing_arm'], $arms) : null; $survey_event_ids = isset($tx_first_event) ? $Proj->getEventsByArmNum($arms[$tx_first_event]['arm_num']) : null; foreach ($survey_event_ids AS $survey_event_id) { $data_event_name = $Proj->getUniqueEventNames($survey_event_id); $prefix = substr($data_event_name, 0, strpos($data_event_name, '_')); $is_t_complete = is_t_complete($record, $survey_event_id); $t_complete = $is_t_complete ? '1' : '0'; $complete_value = get_single_field($record, $project_id, $baseline_event_id, $prefix . '_completed', null); $deadline_value = get_single_field($record, $project_id, $baseline_event_id, $prefix . '_deadline', null); $t_missed = $complete_value == '0' && $today > $deadline_value && isset($deadline_value) && $deadline_value != '' ? '1' : '0'; foreach ($data[$record] AS $data_event_id => $data_event) { foreach ($data_event AS $key => $value) { /** * derive completion variables */ switch ($key) { case $prefix . '_completed': update_field_compare($record, $project_id, $data_event_id, $t_complete, $value, $key, $debug); break; case $prefix . '_date': if ($value == '' && $is_t_complete) { update_field_compare($record, $project_id, $data_event_id, $today, $value, $key, $debug); } break; case $prefix . '_missed': update_field_compare($record, $project_id, $data_event_id, $t_missed, $value, $key, $debug); break; default: break; } } } } } }
$sof_rbv_regimen = false; $sof = array(); $rbv = array(); foreach ($due_data[$subject_id] AS $event_id => $event) { if ($event['sof_cmstdtc'] != '') { $sof[] = true; } if ($event['rib_cmstdtc'] != '') { $rbv[] = true; } } $sof_rbv_regimen = eval("return ((" . implode(' || ', $sof) . ") && (" . implode(' || ', $rbv) . "));"); /** * get genotype */ $genotype = get_single_field($subject_id, $project_id, $first_event_id, 'hcvgt_lborres', ''); /** * if regimen is SOF + RBV and Genotype 1 or 3 */ if ($sof_rbv_regimen && ($genotype == '1' || $genotype == '3')) { /** * AND if TX start is 168 days ago, data is due */ if (date("Y-m-d") >= (add_date($tx_start_date, 168, 0, 0))) { $hcv_data_due = true; } /** * if regimen is SOF + RBV and Genotype 2 */ } elseif ($sof_rbv_regimen && ($genotype == '2')) { /**
foreach ($actions AS $subject_id => $subject) { if ($debug) { d($subject_id); if ($subjects != '') { d($subject); d($data[$subject_id]); } } /** * pop the latest of these off the $subject array and set the ae_aeacn for the AE */ foreach (array_pop($subject) AS $ae_event_id => $ae_event) { foreach ($ae_event AS $tx_prefix => $ae_acn) { d($tx_prefix); d($ae_acn); $this_action = get_single_field($subject_id, $project_id, $ae_event_id, 'ae_aeacn', ''); d(array_search($ae_acn['txacn'], $action_priority)); d(array_search($this_action, $action_priority)); /** * make sure we have priorities for both $this_action and $ae_acn['txacn'] */ if (array_search($ae_acn['txacn'], $action_priority) !== false && array_search($this_action, $action_priority) !== false) { /** * determine priority of the current action. If its priority is higher than the one recorded, update. */ if (array_search($ae_acn['txacn'], $action_priority) > array_search($this_action, $action_priority)) { update_field_compare($subject_id, $project_id, $ae_event_id, $ae_acn['txacn'], $this_action, 'ae_aeacn', $debug); } } } }
/** * @param $record * @param $debug */ function set_deltas($record, $debug) { global $Proj, $project_id; $enable_kint = $debug && (isset($record) && $record != '') ? true : false; Kint::enabled($enable_kint); $baseline_event_id = $Proj->firstEventId; $thresholds = array(); $fields = array(); $baselines = array(); $all_deltas = array(); $prefix_result = db_query("SELECT DISTINCT prefix, threshold FROM _target_lab_deltas WHERE project_id = '$project_id'"); if ($prefix_result) { while ($prefixes = db_fetch_assoc($prefix_result)) { $thresholds[$prefixes['prefix']]['threshold'] = $prefixes['threshold']; } db_free_result($prefix_result); } foreach ($thresholds AS $key => $value) { $fields[] = $key . "_lbstresn"; $fields[] = $key . "_im_lbstresn"; $fields[] = $key . "_lbblfl"; $fields[] = $key . "_im_lbblfl"; } $data = REDCap::getData('array', $record, $fields); d($data); foreach ($data AS $subject_id => $subject) { foreach ($subject AS $event_id => $event) { foreach (array_keys($thresholds) AS $lab_prefix) { $all_deltas[$subject_id][$lab_prefix] = false; if ($event[$lab_prefix . '_lbblfl'] == 'Y' && $event[$lab_prefix . '_lbstresn'] != '') { $baselines[$subject_id][$lab_prefix] = $event[$lab_prefix . '_lbstresn']; } if ($event[$lab_prefix . '_im_lbblfl'] == 'Y' && $event[$lab_prefix . '_im_lbstresn'] != '') { $baselines[$subject_id][$lab_prefix] = $event[$lab_prefix . '_im_lbstresn']; } } } d($baselines); foreach ($subject AS $event_id => $event) { foreach (array_keys($thresholds) AS $lab_prefix) { $threshold = $thresholds[$lab_prefix]['threshold']; $baseline = $baselines[$subject_id][$lab_prefix]; if (isset($baseline) && $baseline != '' && isset($threshold) && $threshold != '' && !$all_deltas[$subject_id][$lab_prefix]) { if (isset($event[$lab_prefix . '_lbstresn']) && $event[$lab_prefix . '_lbstresn'] != '') { if ($event[$lab_prefix . '_lbstresn'] - $baseline > $threshold) { $all_deltas[$subject_id][$lab_prefix] = true; } } if (isset($event[$lab_prefix . '_im_lbstresn']) && $event[$lab_prefix . '_im_lbstresn'] != '') { if ($event[$lab_prefix . '_im_lbstresn'] - $baseline > $threshold) { $all_deltas[$subject_id][$lab_prefix] = true; } } } } } } d($thresholds); d($all_deltas); foreach ($all_deltas AS $subject_id => $lab_prefix) { foreach ($lab_prefix AS $prefix => $had_delta) { $delta = $had_delta ? 'Y' : 'N'; update_field_compare($subject_id, $project_id, $baseline_event_id, $delta, get_single_field($subject_id, $project_id, $baseline_event_id, $prefix . '_suppdm_gtdelta', ''), $prefix . '_suppdm_gtdelta', $debug); } } }
$this_baseline_flag = 'Y'; } else { /** * Now reset all other flags that have changed */ foreach ($data[$subject_id] AS $flag_event_id => $flag_event) { $reset[$flag_event_id] = $flag_event[$lab_prefix . '_im_lbblfl']; } foreach ($reset AS $reset_event_id => $reset_event) { foreach ($reset_event as $reset_field => $reset_val) { update_field_compare($subject_id, $project_id, $reset_event_id, '', $reset_val, $lab_prefix . "_im_lbblfl", $debug); } } } /** * Baseline flag belongs in the event where the date occurs */ update_field_compare($subject_id, $project_id, $this_data['event_id'], $this_baseline_flag, $data[$subject_id][$this_data['event_id']][$lab_prefix . "_im_lbblfl"], $lab_prefix . "_im_lbblfl", $debug); /** * Baseline date belongs in Baseline event - one date for both abstracted and imported */ d($baseline_date); update_field_compare($subject_id, $project_id, $initial_event, $baseline_date, get_single_field($subject_id, $project_id, $initial_event, $lab_prefix . "_supplb_lbdtbl", ''), $lab_prefix . "_supplb_lbdtbl", $debug); } } } } } $timer['main_end'] = microtime(true); $init_time = benchmark_timing($timer); echo $init_time;
*/ code_llt($project_id, $subject_id, $event_id, fix_case($event['ae_aeterm']), fix_case($event['ae_oth_aeterm']), $event['ae_aemodify'], 'ae_aemodify', $debug, $recode_llt, $recode_msg); if ($debug) { error_log("DEBUG: Coded AE_AEMODIFY {$event['ae_aemodify']}: subject=$subject_id, event=$event_id for AE {$event['ae_aeterm']} - {$event['ae_oth_aeterm']}"); } /** * AE_AEDECOD */ $aemodify = get_single_field($subject_id, $project_id, $event_id, 'ae_aemodify', ''); code_pt($project_id, $subject_id, $event_id, fix_case($aemodify), $event['ae_aedecod'], 'ae_aedecod', $debug, $recode_pt, $recode_msg); if ($debug) { error_log("DEBUG: Coded AE_AEDECOD {$event['ae_aedecod']}: subject=$subject_id, event=$event_id for AE {$aemodify}"); } /** * AE_AEBODSYS */ $aedecod = get_single_field($subject_id, $project_id, $event_id, 'ae_aedecod', ''); code_bodsys($project_id, $subject_id, $event_id, $aedecod, $event['ae_aebodsys'], 'ae_aebodsys', $debug, $recode_soc, $recode_msg); if ($debug) { error_log("DEBUG: Coded SOC: subject=$subject_id, event=$event_id for AE {$event['ae_aedecod']}"); } $timer_stop = microtime(true); $timer_time = number_format(($timer_stop - $timer_start), 2); if ($debug) { error_log("DEBUG: This DET action (Code AE) took $timer_time seconds"); } } } $timer_stop = microtime(true); $timer_time = number_format(($timer_stop - $timer_start), 2); echo 'This page loaded in ', $timer_time / 60, ' minutes';
* plugin */ echo "<h3>$plugin_title</h3>"; /** * MAIN */ if ($debug) { $timer['main_start'] = microtime(true); } $fields = array(); foreach ($mh_prefixes AS $prefix) { $fields[] = $prefix . "_oth_mhterm"; $fields[] = $prefix . "_mhmodify"; $fields[] = $prefix . "_mhdecod"; $fields[] = $prefix . "_mhbodsys"; } $data = REDCap::getData('array', $subjects, $fields); foreach ($data AS $subject_id => $subject) { foreach ($subject AS $event_id => $event) { foreach ($mh_prefixes AS $prefix) { code_llt($project_id, $subject_id, $event_id, fix_case($event[$prefix . '_oth_mhterm']), '', $event[$prefix . '_mhmodify'], $prefix . '_mhmodify', $debug, $recode_llt); code_pt($project_id, $subject_id, $event_id, get_single_field($subject_id, $project_id, $event_id, $prefix . "_mhmodify", ''), $event[$prefix . "_mhdecod"], $prefix . "_mhdecod", $debug, $recode_pt); code_bodsys($project_id, $subject_id, $event_id, get_single_field($subject_id, $project_id, $event_id, $prefix . "_mhdecod", ''), $event[$prefix . "_mhbodsys"], $prefix . "_mhbodsys", $debug, $recode_soc); } } } if ($debug) { $timer['main_end'] = microtime(true); $init_time = benchmark_timing($timer); echo $init_time; }
/** * @param $subject_id * @param $debug * determine completeness of all survey-containing events */ function events_completion($subject_id, $debug) { if (isset($subject_id)) { global $Proj, $project_id; $today = date("Y-m-d"); $fields = array(); $arms = get_arms(array_keys($Proj->eventsForms)); $baseline_event_id = $Proj->firstEventId; $enrollment_event_id = getNextEventId($baseline_event_id); $tx_duration = get_single_field($subject_id, $project_id, $enrollment_event_id, 'dm_suppdm_actarmdur', null); $tx_first_event = array_search_recursive($tx_duration . ' Weeks', $arms) !== false ? array_search_recursive($tx_duration . ' Weeks', $arms) : null; $survey_event_ids = isset($tx_first_event) ? array_merge(array($baseline_event_id), $Proj->getEventsByArmNum($arms[$tx_first_event]['arm_num'])) : array($baseline_event_id); foreach ($survey_event_ids AS $survey_event_id) { $survey_event_name = $Proj->getUniqueEventNames($survey_event_id); $survey_prefix = substr($survey_event_name, 0, strpos($survey_event_name, '_')); $fields[] = $survey_prefix . '_completed'; $fields[] = $survey_prefix . '_date'; $fields[] = $survey_prefix . '_startdate'; $fields[] = $survey_prefix . '_deadline'; } $data = REDCap::getData('array', $subject_id, $fields, $baseline_event_id); foreach ($survey_event_ids AS $survey_event_id) { $data_event_name = $Proj->getUniqueEventNames($survey_event_id); $prefix = substr($data_event_name, 0, strpos($data_event_name, '_')); $is_t_complete = is_t_complete($subject_id, $survey_event_id); $t_complete = $is_t_complete ? '1' : '0'; foreach ($data[$subject_id] AS $data_event_id => $data_event) { foreach ($data_event AS $key => $value) { /** * derive intra-event timing variables */ switch ($key) { case $prefix . '_completed': update_field_compare($subject_id, $project_id, $data_event_id, $t_complete, $value, $key, $debug); break; case $prefix . '_date': if ($value == '' && $is_t_complete) { update_field_compare($subject_id, $project_id, $data_event_id, $today, $value, $key, $debug); } break; default: break; } } } /** * derive inter-event timing variables */ $complete_value = get_single_field($subject_id, $project_id, $baseline_event_id, $prefix . '_completed', null); $start_date_value = get_single_field($subject_id, $project_id, $baseline_event_id, $prefix . '_startdate', null); $deadline_value = get_single_field($subject_id, $project_id, $baseline_event_id, $prefix . '_deadline', null); $missed_value = get_single_field($subject_id, $project_id, $baseline_event_id, $prefix . '_missed', null); $t_missed = $complete_value == '0' && $today > $deadline_value && isset($deadline_value) && $deadline_value != '' ? '1' : '0'; switch ($prefix) { case 't1': $t_base_date = get_single_field($subject_id, $project_id, $baseline_event_id, $prefix . '_date', null); $t_start_date = $t_base_date; $t_deadline_date = add_date($t_base_date, 89); break; default: $t_base_date = get_single_field($subject_id, $project_id, $enrollment_event_id, 'dm_rfstdtc', null); $t_start_date = add_date($t_base_date, ($arms[$data_event_name]['day_offset'] - $arms[$data_event_name]['offset_min'])); $t_deadline_date = add_date($t_base_date, ($arms[$data_event_name]['day_offset'] + $arms[$data_event_name]['offset_max']) - 1); break; } update_field_compare($subject_id, $project_id, $baseline_event_id, $t_complete, $complete_value, $prefix . '_completed', $debug); update_field_compare($subject_id, $project_id, $baseline_event_id, $t_missed, $missed_value, $prefix . '_missed', $debug); if (isset($t_base_date) && $t_base_date != '') { update_field_compare($subject_id, $project_id, $baseline_event_id, $t_start_date, $start_date_value, $prefix . '_startdate', $debug); update_field_compare($subject_id, $project_id, $baseline_event_id, $t_deadline_date, $deadline_value, $prefix . '_deadline', $debug); } } } }
$destination_form = $Proj->metadata[$field]['form_name']; /** * Execute this rule */ $dq->executeRule($rule_id); // $results_table = $dq->displayResultsTable($rule_info); // print $results_table[2]; // print $results_table[1]; /** * cycle through rule results */ $rule_results = $dq->getLogicCheckResults(); foreach ($rule_results AS $results) { foreach ($results AS $result) { $dag_prefix = substr(get_single_field($result['record'], $project_id, $Proj->firstEventId, 'dm_usubjid', ''), 0, 3); $dag_result = db_query("SELECT group_name FROM redcap_data_access_groups WHERE project_id = '$project_id' AND LEFT(group_name, 3) = '$dag_prefix'"); if ($dag_result) { $dag_name = db_result($dag_result, 0, 'group_name'); $dag_name = prep($dag_name); } /** * if the result is excluded ignore it */ if ($result['exclude'] != 1) { $today = date('Y-m-d'); $redcap_event_name = $Proj->getUniqueEventNames($result['event_id']); $check_table = array(); $check_table_result = db_query("SELECT * FROM _target_notifications WHERE project_id = '$project_id' AND record = '{$result['record']}' AND redcap_event_name = '$redcap_event_name' AND redcap_data_access_group = '$dag_name' AND form_name = '$destination_form' AND type = 'rule' AND type_id = '$rule_id' AND action_date = '$today'"); if ($check_table_result) { $check_table = db_fetch_assoc($check_table_result);
/** * restrict access to one or more pids */ $allowed_pids = array('26'); REDCap::allowProjects($allowed_pids); /** * set header so browser knows it's JSON */ header('Content-Type: application/json; charset=utf-8'); /** * conmeds */ $fields = array('cm_cmstdtc', 'cm_cmtrt', 'cm_cmindc', 'cm_oth_cmindc', 'cm_suppcm_exacindc', 'cm_suppcm_prphindc'); $conmeds_data = REDCap::getData('array', $subjid, $fields); foreach ($conmeds_data AS $subject_id => $subject) { $rfstdtc = get_single_field($subject_id, $project_id, $baseline_event_id, 'dm_rfstdtc', ''); foreach ($subject AS $event_id => $event) { $url = APP_PATH_WEBROOT_FULL . "redcap_v" . $redcap_version . "/DataEntry/index.php?pid=$project_id&page=conmeds&id=$subjid&event_id=$event_id"; $desc_array = array(); foreach ($event AS $field => $item) { if ($item != '' && !in_array($field, array('cm_cmstdtc', 'cm_oth_cmindc', 'cm_cmtrt'))) { if ($field == 'cm_cmindc' && $item == 'OTHER') { $item = $event['cm_oth_cmindc']; } $desc_array[] = get_field_label($field, $project_id) . ': <strong>' . $item . "</strong>"; } } $event_start = $event['cm_cmstdtc'] != '' ? $event['cm_cmstdtc'] : $rfstdtc; if ($event['cm_cmtrt'] != '') { $eventAtts[] = get_event_array($event_start, '', '', implode("<br />", $desc_array), $event['cm_cmtrt'], '', '', $url); }
if ($fields['utype'] == 'descriptive') { $event[$fields['lborresu']] = $fields['ulabel']; } /** * INR, HCVGT lbstresn */ if (count($lbstresn_array) > 0 && $subjects != '') { d($lbstresn_array); } $fields['lbstresc'] = is_numeric($event[$fields['lborres']]) ? $fields['lbstresn'] : $fields['lborres']; /** * HCV Genotype transform * @TODO: change LBSTRESN back to float and test cleaned values that wouldn't float... */ if ($fields['lbtestcd'] == 'HCVGT') { $subtype = get_single_field($subject_id, $project_id, $Proj->firstEventId, 'hcvgt_s_lborres', ''); if ($subtype != '' && $subtype != 'NOT_AVAILABLE') { $event[$fields['lborres']] = $event[$fields['lborres']] . $subtype; } $fields['lbstresc'] = $fields['lborres']; $event[$fields['lbstresn']] = is_numeric($event[$fields['lborres']]) ? $event[$fields['lborres']] : null; } if (in_array($fields['lbtestcd'], $lbstresn_array)) { $event[$fields['lbstresn']] = $event[$fields['lborres']]; } /** * iterate the fields and add to inner_vals array */ $fields['lbstnrlo'] = 'LBSTNRLO'; $fields['lbstnrhi'] = 'LBSTNRHI'; $fields['lbnrind'] = 'LBNRIND';
/** * @param $record * @param $redcap_event_name * @param $instrument * @param $type * @param $debug */ public static function set_notification($record, $redcap_event_name, $instrument, $debug) { global $Proj, $project_id; $group_id = self::getGroupID($record); $group_name_result = db_query("SELECT group_name FROM redcap_data_access_groups WHERE project_id = '{$project_id}' AND group_id = '{$group_id}'"); if ($group_name_result) { $today = date('Y-m-d'); $group_name_row = db_fetch_assoc($group_name_result); $group_name = $group_name_row['group_name']; $site_id = substr($group_name_row['group_name'], 0, 3); $first_event_id = $Proj->firstEventId; switch ($instrument) { case 'site_source_upload_form': if ($debug) { error_log("DEBUG: {$instrument} notification for {$group_name}"); } else { if (!db_query("INSERT INTO target_email_actions SET project_id = '{$project_id}', record = '{$record}', redcap_event_name = '{$redcap_event_name}', redcap_data_access_group = '" . prep($group_name) . "', form_name = '{$instrument}', action_date = '{$today}'")) { error_log(db_error()); } } break; case 'source_upload_form': if ($debug) { error_log("DEBUG: {$instrument} notification for {$group_name}"); } else { if ($site_id >= '300') { if (!db_query("INSERT INTO target_email_actions SET project_id = '{$project_id}', record = '{$record}', redcap_event_name = '{$redcap_event_name}', redcap_data_access_group = '" . prep($group_name) . "', form_name = '{$instrument}', action_date = '{$today}'")) { error_log(db_error()); } } } break; case 'treatment_start': $started_tx = get_single_field($record, $project_id, $first_event_id, 'trt_suppex_txstat', null); if ($started_tx == 'Y') { if ($debug) { error_log("DEBUG: Subject# {$record} for {$group_name} has started treatment"); } else { if (!db_query("INSERT INTO target_email_actions SET project_id = '{$project_id}', record = '{$record}', redcap_event_name = '{$redcap_event_name}', redcap_data_access_group = '" . prep($group_name) . "', form_name = '{$instrument}', action_date = '{$today}'")) { error_log(db_error()); } } } else { error_log("DEBUG: Subject# {$record} for {$group_name} has not started treatment"); } break; default: break; } } }
/** * @param $record * @param $debug */ public static function setTrtDuration($record, $debug) { /** * derive treatment duration and therefore arm from randomized treatment and duration selected in this form */ global $Proj, $project_id; $first_event_id = $Proj->firstEventId; $trt = self::getTrtInfo($record); if ($debug) { error_log(print_r($trt, true)); } $prescribed_duration = get_single_field($record, $project_id, $first_event_id, 'dm_suppex_trtdur', null); if (!isset($prescribed_duration) || $prescribed_duration == '') { update_field_compare($record, $project_id, $first_event_id, $trt['dur'], $prescribed_duration, 'dm_suppex_trtdur', $debug); } }
/** * restrict access to one or more pids */ $allowed_pids = array('38'); REDCap::allowProjects($allowed_pids); /** * set header so browser knows it's JSON */ header('Content-Type: application/json; charset=utf-8'); /** * conmeds */ $fields = array('cm_cmstdtc', 'cm_cmtrt', 'cm_cmindc', 'cm_oth_cmindc', 'cm_suppcm_exacindc', 'cm_suppcm_prphindc'); $conmeds_data = REDCap::getData('array', $subjid, $fields); foreach ($conmeds_data AS $subject_id => $subject) { $rfstdtc = get_single_field($subject_id, $project_id, $first_event_id, 'dm_rfstdtc', ''); foreach ($subject AS $event_id => $event) { $url = APP_PATH_WEBROOT_FULL . "redcap_v" . $redcap_version . "/DataEntry/index.php?pid=$project_id&page=conmeds&id=$subjid&event_id=$event_id"; $desc_array = array(); foreach ($event AS $field => $item) { if ($item != '' && !in_array($field, array('cm_cmstdtc', 'cm_oth_cmindc', 'cm_cmtrt'))) { if ($field == 'cm_cmindc' && $item == 'OTHER') { $item = $event['cm_oth_cmindc']; } $desc_array[] = get_field_label($field, $project_id) . ': <strong>' . $item . "</strong>"; } } $event_start = $event['cm_cmstdtc'] != '' ? $event['cm_cmstdtc'] : $rfstdtc; if ($event['cm_cmtrt'] != '') { $eventAtts[] = get_event_array($event_start, '', '', implode("<br />", $desc_array), $event['cm_cmtrt'], '', '', $url); }
* project metadata */ $project = new Project(); $first_event_id = $project->firstEventId; $plugin_title = "Derive INDCMODF, INDCOD and INDCSYS for all CMINDC"; /** * plugin */ echo "<h3>$plugin_title</h3>"; /** * MAIN */ if ($debug) { $timer['main_start'] = microtime(true); } $fields = array('cm_cmindc', 'cm_oth_cmindc', 'cm_suppcm_indcmodf', 'cm_suppcm_indcod', 'cm_suppcm_indcsys'); $data = REDCap::getData('array', $subjects, $fields); foreach ($data AS $subject_id => $subject) { foreach ($subject AS $event_id => $event) { if ($event['cm_cmindc'] != '') { code_llt($project_id, $subject_id, $event_id, fix_case($event['cm_cmindc']), fix_case($event['cm_oth_cmindc']), $event['cm_suppcm_indcmodf'], 'cm_suppcm_indcmodf', $debug, $recode_llt); code_pt($project_id, $subject_id, $event_id, get_single_field($subject_id, $project_id, $event_id, "cm_suppcm_indcmodf", ''), $event["cm_suppcm_indcod"], "cm_suppcm_indcod", $debug, $recode_pt); code_bodsys($project_id, $subject_id, $event_id, get_single_field($subject_id, $project_id, $event_id, "cm_suppcm_indcod", ''), $event["cm_suppcm_indcsys"], "cm_suppcm_indcsys", $debug, $recode_soc); } } } if ($debug) { $timer['main_end'] = microtime(true); $init_time = benchmark_timing($timer); echo $init_time; }
$chem_fields = array('chem_lbdtc', 'creat_lbstresn'); $fields = array('dm_brthyr', 'weight_suppvs_wtkg', 'dm_sex'); $data = REDCap::getData('array', $record, $fields, $project->firstEventId); foreach ($data as $vitals) { foreach ($vitals as $vital) { if ($vital['dm_brthyr'] != '' && $vital['weight_suppvs_wtkg'] != '' && $vital['dm_sex'] != '') { $chem_data = REDCap::getData('array', $record, $chem_fields, $redcap_event_name); foreach ($chem_data as $chem_values) { foreach ($chem_values as $chem_event => $values) { unset($creatinine_clearance); if ($values['chem_lbdtc'] != '' && $values['creat_lbstresn'] != '') { $sex = isset($vital['dm_sex']) ? $vital['dm_sex'] : 'F'; $chem_age = (substr($values['chem_lbdtc'], 0, 4)) - $vital['dm_brthyr']; $sex_factor = $sex == 'F' ? .85 : 1; $creatinine_clearance = round(((140 - $chem_age) * $vital['weight_suppvs_wtkg'] * $sex_factor) / (72 * $values['creat_lbstresn'])); update_field_compare($record, $project_id, $chem_event, $creatinine_clearance, get_single_field($record, $project_id, $chem_event, 'crcl_lborres', ''), 'crcl_lborres', $debug); } } } } } } $timer_stop = microtime(true); $timer_time = number_format(($timer_stop - $timer_start), 2); if ($debug) { error_log("DEBUG: This DET action (Standardize $instrument) took $timer_time seconds"); } break; /** * all other forms do nothing */