Пример #1
0
(SELECT * FROM `redcap_data_quality_status` WHERE project_id = '$project_id') `status`
LEFT JOIN
(SELECT * FROM redcap_data_quality_resolutions) res ON `status`.status_id = res.status_id
LEFT JOIN
(SELECT ui_id, user_firstname, user_lastname FROM redcap_user_information) users ON `status`.assigned_user_id = users.ui_id
LEFT JOIN
(SELECT ui_id, user_firstname, user_lastname FROM redcap_user_information) cur_users ON res.user_id = cur_users.ui_id
WHERE `status`.query_status != 'CLOSED'
ORDER BY `status`.status_id ASC, res.ts ASC";
$query_status_result = db_query($query_status_sql);
if ($query_status_result) {
	while ($query_status_row = db_fetch_assoc($query_status_result)) {
		/**
		 * initialize the working arrays
		 */
		$data_row = array();
		/**
		 * Freeze the query_id for future use and start the data row
		 */
		if (isset($query_status_row['query_id'])) {
			$query_id = $query_status_row['query_id'];
			$data_row['Query ID'] = $query_id;
		} else {
			$data_row['Query ID'] = '--';
		}
		$status_array[$query_id][] = $query_status_row['query_status'];
	}
}
if ($debug) {
	show_var($status_array);
}
Пример #2
0
					// Add new row to data_resolution_log
					$sql = "insert into redcap_data_quality_resolutions (status_id, ts, user_id, response_requested,
					response, comment, current_query_status, upload_doc_id)
					values ($status_id, '" . NOW . "', " . checkNull($userInitiator['ui_id']) . ",
					" . checkNull($response_requested) . ", " . checkNull($response) . ",
					" . checkNull($rule_info['name']) . ", " . checkNull($dr_status) . ", " . checkNull($_POST['upload_doc_id']) . ")";
					if (!$debug) {
						if (db_query($sql)) {
							// Success, so return content via JSON to redisplay with new changes made
							$res_id = db_insert_id();
							## Logging
							// Set data values as json_encoded
							$logDataValues = json_encode(array('res_id' => $res_id, 'record' => $result['record'], 'event_id' => $result['event_id'],
								'field' => $field, 'rule_id' => $rule_id));
							// Set event_id in query string for logging purposes only
							$_GET['event_id'] = $result['event_id'];
							// Log it
							log_event($sql, "redcap_data_quality_resolutions", "MANAGE", $result['record'], $logDataValues, $drw_log);
						} else {
							// ERROR!
							exit('0');
						}
					} else {
						show_var($sql, 'INSERT RESOLUTIONS', 'red');
					}
				}
			}
		}
	}
}
Пример #3
0
/**
 * @param $prefix string
 * @param $lab_fields array 'Must include _supplb_lbdtbl, _lbblfl, _lborres or _lbstresn without prefix'
 * @param $date_field array 'Date field for this form / fields'
 * @param $debug
 * UNDER CONSTRUCTION
 */
function derive_baseline_from_fields($prefix, $lab_fields, $date_field, $debug)
{
	$project = new Project();
	$initial_event = $project->firstEventId;
	$lab_fields = array_merge($date_field, $lab_fields);
	if ($debug) {
		/*show_var($lab_fields);*/
	}
	/**
	 * find baselines for each lab test
	 */
	$data = REDCap::getData('array', '', $lab_fields);
	foreach ($data AS $subjid => $subject) {
		$lab_subject = array();
		if ($debug) {
			show_var($subjid, 'FIELD SUBJID', 'blue');
		}
		/**
		 * get refstdtc for this subject
		 */
		$tx_start_fields = array("dm_rfstdtc");
		$tx_start_data = REDCap::getData('array', $subjid, $tx_start_fields);
		$rfstdtc = $tx_start_data[$subjid][$initial_event]['dm_rfstdtc'];
		if ($debug) {
			show_var($subject, 'BEFORE', 'red');
		}
		/**
		 * if treatment has started
		 */
		if (isset($rfstdtc) || $rfstdtc != '') {
			/**
			 * iterate the lab events for this prefix
			 */
			foreach ($subject AS $lab_event_id => $lab_event) {
				/**
				 * if we have a value for the orres, then add to candidate events array
				 */
				if ($lab_event[$prefix . "_lborres"] != '') {
					$lab_subject[$lab_event_id] = $subject[$lab_event_id];
				}
			}
			if ($debug) {
				show_var($lab_subject, "AFTER {$prefix}", 'green');
			}
			/**
			 * if we have candidate events
			 */
			if (count($lab_subject) > 0) {
				/**
				 * fetch the baseline date and set baseline / flag pair
				 */
				$baseline_date = '';
				$this_data = get_baseline_date($lab_subject, $fragment, $rfstdtc);
				/**
				 * if the nearest date is prior or equal to rfstdtc, it's a baseline date
				 */
				if ($debug) {
					show_var($lab_subject, 'FIELD SUBJECT DATA', 'blue');
					show_var($this_data, 'FIELD BASELINE DATA', 'red');
					show_var($rfstdtc, 'TX start', 'red');
				}
				if ($this_data[$fragment . '_lbdtc'] != '' && $this_data[$fragment . '_lbdtc'] <= $rfstdtc) {
					$baseline_date = $this_data[$fragment . '_lbdtc'];
					/**
					 * Baseline date belongs in Baseline event
					 */
					update_field_compare($subjid, $project_id, $initial_event, $baseline_date, get_single_field($subjid, $project_id, $initial_event, $prefix . "_supplb_lbdtbl", null), $prefix . "_supplb_lbdtbl", $debug);
					if ($debug) {
						show_var($baseline_date, 'FIELD BASELINE DATE', 'red');
					}
					/**
					 * Now reset all other flags that have changed
					 */
					$flag_reset_data = REDCap::getData('array', $subjid, $prefix . "_lbblfl");
					$this_baseline_flag = get_single_field($subjid, $project_id, $this_data['event_id'], $prefix . "_lbblfl", null);
					foreach ($flag_reset_data AS $reset) {
						if ($debug) {
							show_var($reset, 'FIELD RESET FLAGS', 'red');
						}
						foreach ($reset AS $reset_event_id => $reset_event) {
							foreach ($reset_event as $reset_field => $reset_val) {
								if ($reset_event_id != $this_data['event_id']) {
									update_field_compare($subjid, $project_id, $reset_event_id, '', $reset_val, $prefix . "_lbblfl", $debug);
								}
							}
						}
					}
					/**
					 * Baseline flag belongs in the event where the date occurs
					 */
					if ($baseline_date != '') {
						update_field_compare($subjid, $project_id, $this_data['event_id'], 'Y', $this_baseline_flag, $prefix . "_lbblfl", $debug);
					}
				}
			}
		}
	}
}
Пример #4
0
$debug = true;
/**
 * includes
 */
$base_path = dirname(dirname(dirname(__FILE__)));
require_once $base_path . "/redcap_connect.php";
require_once $base_path . '/plugins/includes/functions.php';
require_once APP_PATH_DOCROOT . '/Config/init_project.php';
require_once APP_PATH_DOCROOT . '/ProjectGeneral/header.php';
/**
 * if data was submitted here...
 */
if ($_GET && $_POST) {
    if ($debug) {
        show_var($_GET, 'GET');
        show_var($_POST, 'POST');
    }
    /**
     * initialize variables
     */
    $project = new Project();
    $next_event_id = getNextEventId($_GET['event_id'], $_GET['page']);
    $original_action = APP_PATH_WEBROOT . "DataEntry/index.php?pid={$_GET['pid']}&event_id={$_GET['event_id']}&page={$_GET['page']}";
    $redirect_url = APP_PATH_WEBROOT . "DataEntry/index.php?pid={$_GET['pid']}&event_id={$next_event_id}&page={$_GET['page']}";
    /**
     * conditionally modify post and redirect
     */
    //	if ($_POST['submit-action'] == 'submit-btn-savenextevent' && $next_event_id !== false) {
    //		$_POST['save-and-redirect'] = $redirect_url;
    //	}
    //	header('Location: ' . $original_action);
}
if (isset($found_posts)) {
    show_var('found_posts', $found_posts);
}
?>
			</tbody>
		</table>
	</div>
	
	<div class="box double">
		<h2>Query Vars set</h2>
		<table>
			<tbody>
		<?php 
foreach ($wp_query->query_vars as $var => $val) {
    show_var($var, $val, true);
}
?>
			</tbody>
		</table>
	</div>

	<div class="box double">
		<h2>SQL Query</h2>
		<p><?php 
echo $wp_query->request;
?>
</p>
	</div>
<?php 
get_footer();
Пример #6
0
	/**
	 * @param $record
	 * @param $instrument
	 * @param $debug
	 */
	public static function set_dag($record, $instrument, $debug)
	{
		global $project_id;
		/**
		 * SET Data Access Group based upon dm_usubjid prefix
		 */
		$fields = array('dm_usubjid');
		$data = REDCap::getData('array', $record, $fields);
		foreach ($data AS $subject) {
			foreach ($subject AS $event_id => $event) {
				if ($event['dm_usubjid'] != '') {
					/**
					 * find which DAG this subject belongs to
					 */
					$site_prefix = substr($event['dm_usubjid'], 0, 3) . '%';
					$dag_query = "SELECT group_id, group_name FROM redcap_data_access_groups WHERE project_id = '$project_id' AND group_name LIKE '$site_prefix'";
					$dag_result = db_query($dag_query);
					if ($dag_result) {
						$dag = db_fetch_assoc($dag_result);
						if (isset($dag['group_id'])) {
							/**
							 * For each event in project for this subject, determine if this subject_id has been added to its appropriate DAG. If it hasn't, make it so.
							 * First, we need a list of events for which this subject has data
							 */
							$subject_events_query = "SELECT DISTINCT event_id FROM redcap_data WHERE project_id = '$project_id' AND record = '$record' AND field_name = '" . $instrument . "_complete'";
							$subject_events_result = db_query($subject_events_query);
							if ($subject_events_result) {
								while ($subject_events_row = db_fetch_assoc($subject_events_result)) {
									if (isset($subject_events_row['event_id'])) {
										$_GET['event_id'] = $subject_events_row['event_id']; // for logging
										/**
										 * The subject has data in this event_id
										 * does the subject have corresponding DAG assignment?
										 */
										$has_event_data_query = "SELECT DISTINCT event_id FROM redcap_data WHERE project_id = '$project_id' AND record = '$record' AND event_id = '" . $subject_events_row['event_id'] . "' AND field_name = '__GROUPID__'";
										$has_event_data_result = db_query($has_event_data_query);
										if ($has_event_data_result) {
											$has_event_data = db_fetch_assoc($has_event_data_result);
											if (!isset($has_event_data['event_id'])) {
												/**
												 * Subject does not have a matching DAG assignment for this data
												 * construct proper matching __GROUPID__ record and insert
												 */
												$insert_dag_query = "INSERT INTO redcap_data SET record = '$record', event_id = '" . $subject_events_row['event_id'] . "', value = '" . $dag['group_id'] . "', project_id = '$project_id', field_name = '__GROUPID__'";
												if (!$debug) {
													if (db_query($insert_dag_query)) {
														target_log_event($insert_dag_query, 'redcap_data', 'insert', $record, $dag['group_name'], 'Assign record to Data Access Group (' . $dag['group_name'] . ')');
													} else {
														error_log("SQL INSERT FAILED: " . db_error() . "\n");
														echo db_error() . "\n";
													}
												} else {
													show_var($insert_dag_query);
													error_log('(TESTING) NOTICE: ' . $insert_dag_query);
												}
											}
											db_free_result($has_event_data_result);
										}
									}
								}
								db_free_result($subject_events_result);
							}
						}
						db_free_result($dag_result);
					}
				}
			}
		}
	}
Пример #7
0
		 * IMMUNOSUPPRESSANTS
		 */
		if (isset($event['cm_cmdecod']) && $event['cm_cmdecod'] != '') {
			$immun_flag = 'N';
			$immun_meds = array();
			$immun_meds_result = db_query("SELECT * FROM _target_meds_of_interest WHERE cm_cmcat != 'steroid' AND cm_cmtrt = '{$event['cm_cmdecod']}'");
			if ($immun_meds_result) {
				while ($immun_meds_row = db_fetch_assoc($immun_meds_result)) {
					$immun_meds[] = $immun_meds_row['cm_cmtrt'];
				}
				db_free_result($immun_meds_result);
			}
			if (count($immun_meds) != 0) {
				$immun_flag = 'Y';
				if ($debug) {
					show_var($immun_meds);
				}
			}
			update_field_compare($subject_id, $project_id, $event_id, $immun_flag, $event['cm_suppcm_cmimmuno'], 'cm_suppcm_cmimmuno', $debug);
		}
		/**
		 * CM_SUPPCM_INDCOD
		 */
		/**
		 * re-code all nutritional support to nutritional supplement
		 */
		if ($event['cm_oth_cmindc'] == 'Nutritional support') {
			$event['cm_oth_cmindc'] = 'Nutritional supplement';
		}
		code_llt($project_id, $subject_id, $event_id, fix_case($event['cm_cmindc']), fix_case($event['cm_oth_cmindc']), $event['cm_suppcm_indcod'], 'cm_suppcm_indcod', $debug, $recode_llt);
		/**
						if (db_query($delete_query)) {
							target_log_event($delete_query, 'redcap_data', 'delete', $empty_row['record'], "{$empty_row['field_name']} = '{$empty_row['value']}'", 'Delete hidden blank value', '', $project_id, $empty_row['event_id']);
						} else {
							error_log("SQL DELETE FAILED: " . db_error() . ': ' . $delete_query);
							echo db_error() . "<br />" . $delete_query;
						}
					} else {
						echo "<div class='red'>NON-MATCHING value is shown. THIS value ({$empty_row['value']}) is hidden. DELETE row.</div>";
						show_var($history, "{$empty_row['record']}, {$empty_row['event_id']}, {$empty_row['field_name']}", 'red');
						show_var($most_recent_event['value'], 'MOST RECENT', 'red');
						show_var($delete_query);
					}
				} else {
					/**
					 * do nothing
					 */
					if ($debug) {
						echo "<div class='green'>THIS value ({$empty_row['value']}) is shown. DO NOTHING.</div>";
						show_var($history, "{$empty_row['record']}, {$empty_row['event_id']}, {$empty_row['field_name']}", 'green');
						show_var($most_recent_event['value'], 'MOST RECENT', 'green');
					}
				}
			}
		}
		db_free_result($empty_result);
	}
	echo $rows_deleted . " ROWS DELETED.<br />";
	$timer['main_end'] = microtime(true);
	$init_time = benchmark_timing($timer);
	echo $init_time;
}
$fields = array('cm_cmoccur', 'cm_cmdecod', 'cm_cmindc', 'cm_oth_cmindc', 'cm_suppcm_indcmodf', 'cm_suppcm_indcod', 'cm_suppcm_indcsys', 'cm_suppcm_atcname', 'cm_suppcm_atc2name');
$data = REDCap::getData('array', $subjects, $fields);
foreach ($flush_data AS $subject_id => $flush_subject) {
	foreach ($flush_subject AS $event_id => $event) {
		foreach ($flush_fields as $flush_field) {
			if ($event[$flush_field] != '') {
				$flush_sql = "DELETE FROM redcap_data WHERE project_id = '$project_id' AND record = '$subject_id' AND event_id = '$event_id' AND field_name = '$flush_field'";
				if (!$debug) {
					if (db_query($flush_sql)) {
						target_log_event($flush_sql, 'redcap_data', 'delete', $subject_id, "$flush_field = ''", 'Delete record', $delete_message, $project_id, $event_id);
					} else {
						error_log(db_error() . ': ' . $flush_sql);
						echo db_error() . "<br />" . $flush_sql;
					}
				} else {
					show_var($flush_sql);
					error_log("DEBUG: " . $flush_sql);
				}

			}
		}
 	}
	foreach ($data[$subject_id] AS $subject) {
		foreach ($subject AS $event_id => $event) {
			if ($event['cm_cmoccur'] == 'Y') {
				code_pt($project_id, $subject_id, $event_id, $event['cm_suppcm_indcmodf'], $event['cm_suppcm_indcod'], 'cm_suppcm_indcod', $debug, $recode_pt, $message);
				if ($debug) {
					error_log("DEBUG: Coded INDC PT: subject=$subject_id, event=$event_id for INDICATION {$event['cm_suppcm_indcmodf']}");
				}
				code_bodsys($project_id, $subject_id, $event_id, $event['cm_suppcm_indcod'], $event['cm_suppcm_indcsys'], 'cm_suppcm_indcsys', $debug, $recode_soc, $message);
				if ($debug) {
Пример #10
0
						}
					}
				}
				/**
				 * inside the stream, we know about new samples and don't know about samples removed from inventory
				 */
				foreach ($stream_array AS $dm_usubjid => $stream_event) {
					$record = $dm_usubjid_array[$dm_usubjid];
					/**
					 * if we don't have a $record, it's not a current PT in the study
					 */
					if (isset($record)) {
						$site_name = $site_array[substr($dm_usubjid, 0, 3)];
						ksort($stream_event);
						if ($debug) {
							show_var($stream_event, "$record ($dm_usubjid)", 'blue');
						}
						$event_count = 1;
						$next_event = count($state_array[$record]) + 1;
						foreach ($stream_event AS $stream_date => $stream_samples) {
							ksort($stream_samples);
							$sample_code = NULL;
							$sample_type = NULL;
							$sample_onhand = NULL;
							/**
							 * if this $stream_date is not found in the $state, it's a new event
							 */
							if (!array_key_exists_recursive($stream_date, $state_array[$record])) {
								/**
								 * new event, start with the first field group
								 */
			}
		}
	}
	/**
	 * flush and log any '' values for $field_name
	 */
	$find_blank_values_query = "SELECT record, event_id FROM redcap_data WHERE project_id = '$project_id' AND field_name = '$field_name' AND value = ''";
	$find_blanks_result = db_query($find_blank_values_query);
	if ($find_blanks_result) {
		while ($found_blank_row = db_fetch_assoc($find_blanks_result)) {
			$delete_blank_values_query = "DELETE FROM redcap_data WHERE project_id = '$project_id' AND field_name = '$field_name' AND record = '{$found_blank_row['record']}' AND event_id = '{$found_blank_row['event_id']}' AND value = ''";
			if (!$debug) {
				if (db_query($delete_blank_values_query)) {
					//target_log_event($delete_blank_values_query, 'redcap_data', 'delete', $subject_id, "$field_name = ''", "Delete blank $field_name", '', $project_id);
					REDCap::logEvent("Delete blank $field_name", "$field_name = ''", $delete_blank_values_query, $found_blank_row['record'], $found_blank_row['event_id']);
				} else {
					error_log(db_error() . ': ' . $delete_blank_values_query);
					echo(db_error() . ": " . $delete_blank_values_query . "<br />");
				}
			} else {
				show_var($delete_blank_values_query);
			}
		}
		db_free_result($find_blanks_result);
	}
} else {
	print "<h3>You must select both a source (existing) and destination (new) field.</h3>";
}
$timer_stop = microtime(true);
$timer_time = number_format(($timer_stop - $timer_start), 2);
echo 'This page loaded in ', $timer_time / 60, ' minutes';
Пример #12
0
    $timer['main_start'] = microtime(true);
}
/*if ($_GET) {
	show_var($_GET, '$_GET');
}*/
if ($_SERVER) {
    $refer_outer = explode('&', substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], '?') + 1));
    $refer_inner = array();
    foreach ($refer_outer as $refer) {
        $refer = explode('=', $refer);
        $refer_inner[$refer[0]] = $refer[1];
    }
    if ($testing) {
        show_var($refer_inner, 'post-process');
    }
    if (isset($refer_inner['page']) && isset($refer_inner['event_id']) && isset($refer_inner['id'])) {
        $next_event_id = getNextEventId($refer_inner['event_id'], $refer_inner['page']);
        if ($next_event_id !== false) {
            header('Location: ' . APP_PATH_WEBROOT . "DataEntry/index.php?pid={$project_id}&id=" . urlencode($refer_inner['id']) . "&event_id={$next_event_id}&page={$refer_inner['page']}");
        } else {
            show_var($next_event_id);
        }
    } else {
        echo "<h1>You must first select a subject and a form to use this plugin.</h1>";
    }
}
if ($testing) {
    $timer['main_end'] = microtime(true);
    $init_time = benchmark_timing($timer);
    echo $init_time;
}
Пример #13
0
     $data = json_decode($var, true);
     foreach ($data as $name => $value) {
         if ($value != NULL) {
             $config->set($name, $value);
         }
     }
 } else {
     if ($action == "get") {
         if ($var == NULL) {
             $result = $config->getAll();
             if ($result != NULL) {
                 show_vars($result);
             }
         } else {
             $result = $config->get($var);
             show_var($var, $result);
         }
     } else {
         if ($action == "admin") {
             if ($var == NULL) {
                 $result = $users->getAllAdmins();
                 foreach ($result as $user) {
                     show_user($user);
                 }
             } else {
                 $user = $users->getByLogin($var);
                 if ($user != NULL) {
                     Audit::log('console', 'set user admin ' . $user->login . '(' . $user->id . ')');
                     $users->setAdmin($user->id, 1);
                 } else {
                     dbg('Login not found');
					} else {
						$avail_incomplete++;
						if ($value != '') {
							$filled_incomplete++;
						}
					}
				}
			}
		}
		/**
		 * output row to table
		 */
		$data_row['Form Name'] = '"' . $form_name_row['form_menu_description'] . '"';
		$data_row['Filled Fields on Locked Forms'] = '"' . $filled_locked . '"';
		$data_row['Avail Fields on Locked Forms'] = '"' . $avail_locked . '"';
		$data_row['Filled Fields on Completed Forms'] = '"' . $filled_complete . '"';
		$data_row['Avail Fields on Completed Forms'] = '"' . $avail_complete . '"';
		$data_row['Filled Fields on Incomplete Forms'] = '"' . $filled_incomplete . '"';
		$data_row['Avail Fields on Incomplete Forms'] = '"' . $avail_incomplete . '"';
		$data_row['Filled Fields on All Forms'] = '"' . $filled_all . '"';
		$data_row['Avail Fields on All Forms'] = '"' . $avail_all . '"';
		$row_csv = implode(',', $data_row) . "\n";
		$table_csv .= $row_csv;
	}
}
$headers = implode(',', array_keys($data_row)) . "\n";
if (!$debug) {
	create_download($lang, $app_title, $userid, $headers, $user_rights, $table_csv, '', $parent_chkd_flds, $project_id, "LOCKED_FORMS", $debug);
} else {
	show_var($table_csv, 'TABLE', 'red');
}
			$locked = db_fetch_assoc($locked_result);
			if (!isset($locked['ld_id'])) {
				$rows_deleted++;
				$delete_query = "DELETE FROM redcap_data WHERE record = '{$empty_row['record']}' AND project_id = '$project_id' AND event_id = '{$empty_row['event_id']}' AND field_name = '{$empty_row['field_name']}' AND value = '" . prep($empty_row['value']) . "' LIMIT 1";
				if (!$debug) {
					if (db_query($delete_query)) {
						target_log_event($delete_query, 'redcap_data', 'delete', $empty_row['record'], "{$empty_row['field_name']} = '{$empty_row['value']}'", 'Delete blank value', '', $project_id, $empty_row['event_id']);
					} else {
						error_log("SQL DELETE FAILED: " . db_error() . ': ' . $delete_query);
						echo db_error() . "<br />" . $delete_query;
					}
				} else {
					show_var($delete_query);
				}
			} else {
				$this_field_hidden = $my_branching_logic->allFieldsHidden($empty_row['record'], $empty_row['event_id'], array($empty_row['field_name']));
				$history = Form::getDataHistoryLog($empty_row['record'], $empty_row['event_id'], $empty_row['field_name']);
				if ($this_field_hidden) {
					$rows_deleted++;
					echo "<div class='red'>LOCKED with BLANK. Value is hidden. DELETE.</div>";
					show_var($history, "{$empty_row['record']}, {$empty_row['event_id']}, {$empty_row['field_name']}", 'red');
				} else {
					echo "<div class='green'>LOCKED with BLANK. Value is shown. Make no changes.</div>";
					show_var($history, "{$empty_row['record']}, {$empty_row['event_id']}, {$empty_row['field_name']}", 'green');
				}
			}
		}
	}
	db_free_result($empty_result);
}
echo $rows_deleted . " ROWS DELETED.<br />";
Пример #16
0
							 * if the entered units are to be converted:
							 */
							if (strtolower($this_lab['lborresu']) == strtolower($unit) || strtolower($lbstresu) == strtolower($unit)) {
								if ($debug) {
									show_var($formula, 'CONVERSION', 'red');
								}
								/**
								 * convert to standard units
								 */
								if ($formula == 'exp') {
									$lbstresn = (string)round(pow(10, $this_lab['lborres']));
								} else {
									$lbstresn = (string)round(eval("return (" . $this_lab['lborres'] . $formula . ");"), 3);
								}
								if ($debug) {
									show_var($lbstresn, 'CORRECTED VALUE', 'green');
								}
								$lbstresu = $units;
								$has_valid_units = true;
							}
						}
					}
				} else {
					$lbstresu = $units;
					$has_valid_units = true;
				}
				if ($has_valid_units) {
					update_field_compare($subjid, $project_id, $event_id, $lbstresn, $this_lab['lbstresn'], $prefix . '_lbstresn', $debug);
					update_field_compare($subjid, $project_id, $event_id, $lbstresu, $this_lab['lbstresu'], $prefix . '_lbstresu', $debug);
				}
			} elseif ($this_lab['lborresu'] == '' && $this_lab['lborres'] != '') {
								show_var($event['dm_rfstdtc'], 'START DATE');
								show_var($wk4_start_date, '4WK START');
								show_var($hcv_event['hcv_lbdtc'], 'HCVRNA DATE');
								show_var($wk4_end_date, '4WK END');
								show_var($hcv_event['hcv_lbstresn'], 'QUANT');
								show_var($hcv_event['hcv_supplb_hcvdtct'], 'DETECT');
							}
							$data_row['subjid'] = $subject_id;
							$data_row['regimen'] = $regimen;
							$data_row['tx start'] = $event['dm_rfstdtc'];
							$data_row['wk4 low'] = $wk4_start_date;
							$data_row['hcvrna date'] = $hcv_event['hcv_lbdtc'];
							$data_row['wk4 hi'] = $wk4_end_date;
							if ($hcv_event['hcv_lbstresn'] != '') {
								$data_row['hcvrna'] = $hcv_event['hcv_lbstresn'];
							} else {
								$data_row['hcvrna'] = $hcv_event['hcv_supplb_hcvdtct'];
							}
							$count++;
							$row_csv = implode(',', $data_row) . "\n";
							$table_csv .= $row_csv;
						}
					}
				}
			}
		}
	}
}
show_var($count);
$headers = implode(',', array_keys($data_row)) . "\n";
	create_download($lang, $app_title, $userid, $headers, $user_rights, $table_csv, '', $parent_chkd_flds, $project_id, "SIM_SOF_HCVRNA_WK4", $debug);
/**
 * restrict access to one or more pids
 */
$allowed_pids = array('38');
REDCap::allowProjects($allowed_pids);
/**
 * project metadata
 */
global $Proj;
/**
 * initialize variables
 */
$plugin_title = "Derive Treatment Started (trt_suppex_txstat)";
/**
 * plugin title
 */
echo "<h3>$plugin_title</h3>";
/**
 * MAIN LOOP
 */
$fields = array("dm_rfstdtc", "trt_suppex_txstat");
$data = REDCap::getData('array', $subjects, $fields, $Proj->firstEventId);
if ($debug && $subjects != '') {
	show_var($data);
}
foreach ($data AS $subject_id => $subject) {
	foreach ($subject AS $event_id => $event) {
		$started = $event['dm_rfstdtc'] == '' ? 'N' : 'Y';
		update_field_compare($subject_id, $project_id, $event_id, $started, $event['trt_suppex_txstat'], 'trt_suppex_txstat', $debug);
	}
}
Пример #19
0
									$has_event_data = db_fetch_assoc($has_event_data_result);
									if (!isset($has_event_data['event_id'])) {
										/**
										 * Subject does not have a matching DAG assignment for this data
										 * construct proper matching __GROUPID__ record and insert
										 */
										$insert_dag_query = "INSERT INTO redcap_data SET record = '{$event['dm_subjid']}', event_id = '" . $subject_events_row['event_id'] . "', value = '" . $dag['group_id'] . "', project_id = '$project_id', field_name = '__GROUPID__'";
										if (!$debug) {
											if (db_query($insert_dag_query)) {
												target_log_event($insert_dag_query, 'redcap_data', 'insert', $event['dm_subjid'], $dag['group_name'], 'Assign record to Data Access Group (' . $dag['group_name'] . ')');
												show_var($insert_dag_query, '', 'green');
											} else {
												error_log("SQL INSERT FAILED: " . db_error() . "\n");
												echo db_error() . "\n";
											}
										} else {
											show_var($insert_dag_query);
										}
									}
									db_free_result($has_event_data_result);
								}
							}
						}
						db_free_result($subject_events_result);
					}
				}
				db_free_result($dag_result);
			}
		}
	}
}
Пример #20
0
			if (defined("USERID")) {
				$userid = USERID;
			} else if (in_array(CRON_PAGE, non_auth_pages())) {
				$userid = "[CRON]";
			} else {
				$userid = '';
			}
			error_log("USER $userid attempted to create user file for domain {$constants['DOMAIN']}");
			if (is_array($fields_collection)) {
				foreach ($fields_collection AS $field_collection) {
					foreach ($field_collection AS $key => $val) {
						$chkd_fields_array[] = $key;
					}
				}
				$chkd_fields = "'" . implode("', '", array_unique($chkd_fields_array)) . "'";
			}
			create_cdisc_download($table_name, $lang, $app_title, $userid, $user_rights, $chkd_fields, '', $project_id, $constants['DOMAIN'], $debug);
		} else {
			error_log("SQL INSERT FAILED: " . db_error() . "\n");
			echo db_error() . "<br />";
		}
	} else {
		error_log("TRUNCATE FAILED: " . db_error() . "\n");
		echo db_error() . "<br />";
	}
} else {
	show_var($sql);
}
$timer['end'] = microtime(true);
$init_time = benchmark_timing($timer);
echo $init_time;
					if ($has_10week_results) {
						show_var($post_tx_plus10w_scores, 'POST TX +10week', 'red');
					} else {
						show_var('NO POST TX +10week HCVRNA', '', 'red');
					}
					if ($t3_start_date != '') {
						show_var('THIS PATIENT started HCVT3 TX on ' . $t3_start_date, '', 'red');
					}
				}
				show_var($hcvrna_before_zero_count, 'on tx BLOQ count', 'gray');
				show_var($last_hcvrna_bloq, 'last BLOQ?', 'gray');
				show_var($lost_to_followup, 'LTFU?', 'gray');
				show_var($tx_stopped_10_wks_ago, 'TX stop > 10wks ago', 'gray');
				show_var($outcome, 'Outcome', 'brown');
			} else {
				show_var('NO TX START', '', 'red');
			}
		}
		/**
		 * set overall hcvrna followup eligibility and reason if ineligible
		 */
		update_field_compare($subject_id, $project_id, $first_event_id, $eligible, $date_event['hcv_suppfa_fuelgbl'], 'hcv_suppfa_fuelgbl', $debug);
		update_field_compare($subject_id, $project_id, $first_event_id, $reason, $date_event['hcv_suppfa_nlgblrsn'], 'hcv_suppfa_nlgblrsn', $debug);
		/**
		 * set follow up timing - is it due?
		 */
		update_field_compare($subject_id, $project_id, $first_event_id, $data_due, $date_event['hcv_suppfa_fudue'], 'hcv_suppfa_fudue', $debug);
		/**
		 * set outcome
		 */
		update_field_compare($subject_id, $project_id, $first_event_id, $outcome, $date_event['hcv_suppfa_hcvout'], 'hcv_suppfa_hcvout', $debug);
				break;
			case 'FBRMTR':
				$equiv_lo = '';
				break;
			case 'OTHER':
				$equiv_lo = '';
				break;
			default:
				$equiv_lo = '';
		}
		foreach ($event AS $key => $value) {
			$data_row[$pretty_field_names[$key]] = '"' . $value . '"';
			if ($key == 'fib_lborres') {
				$data_row['Serum Fibrosis F4 Eqv'] = '"' . $equiv_lo . '"';
			}
			if ($key == 'fibscn_lborres' && $value != '') {
				$data_row['Fibroscan/Fibrosure F4 Eqv'] = '"' . 8.5 . '"';
			} elseif ($key == 'fibscn_lborres') {
				$data_row['Fibroscan/Fibrosure F4 Eqv'] = '""';
			}
		}
		$row_csv = implode(',', $data_row) . "\n";
		$table_csv .= $row_csv;
	}
}
$headers = implode(',', array_keys($data_row)) . "\n";
if (!$debug) {
	create_download($lang, $app_title, $userid, $headers, $user_rights, $table_csv, '', $parent_chkd_flds, $project_id, "CIRRHOSIS_VALUES", $debug);
} else {
	show_var($table_csv);
}
		$stack = array();
		foreach ($endt_prefix_array AS $endt_prefix) {
			foreach ($end_values AS $event) {
				if ($event[$endt_prefix . '_cmendtc'] != '' && ($event[$endt_prefix . '_suppcm_cmtrtout'] == 'COMPLETE') || $event[$endt_prefix . '_suppcm_cmtrtout'] == 'PREMATURELY_DISCONTINUED') {
					if ($debug) {
						show_var($event, 'PREFIX ' . $endt_prefix, 'red');
					}
					$stack[] = $event[$endt_prefix . '_cmendtc'];
				}
			}
		}
		sort($start_stack);
		sort($stack);
		if ($debug) {
			show_var($start_stack, 'START STACK sort', 'red');
			show_var($stack, 'STACK sort', 'red');
		}
		$last_date_in_start_stack = array_pop($start_stack);
		$last_date_in_stack = array_pop($stack);
		$stop_date = $last_date_in_stack <= $last_date_in_start_stack ? null : $last_date_in_stack;
		update_field_compare($subject_id, $project_id, $first_event_id, $stop_date, $subject[$first_event_id]['dm_rfendtc'], 'dm_rfendtc', $debug);

		/**
		 * HCV treatment duration
		 * dm_rfstdtc, dm_rfendtc, dis_dsstdy
		 */
		if (isset($stop_date)) {
			$tx_start_date_obj = new DateTime($tx_start_date);
			$tx_stop_date_obj = new DateTime($stop_date);
			$tx_duration = $tx_start_date_obj->diff($tx_stop_date_obj);
			$dis_dsstdy = $tx_duration->format('%R%a') + 1;