コード例 #1
0
if ($subjects != '') {
	d($vals_array);
}

$timer['start_main'] = microtime(true);
/**
 * Main loop
 */
foreach ($vals_array as $subj_usubjid => $subj_val_array) {
	$seq = 1;
	$constants['USUBJID'] = $constants['STUDYID'] . '-' . $subj_usubjid;
	foreach ($subj_val_array AS $subj_array) {
		if ($subj_array['mhoccur'] != '') {
			$llt = $subj_array['mhmodify'] != '' ? $subj_array['mhmodify'] : get_llt($subj_array['mhterm']);
			$pt = get_pt($llt);
			$soc = get_bodsys($pt);
			$query[] = '(' .
				fix_null($constants['STUDYID']) . ',' .
				fix_null($constants['DOMAIN']) . ',' .
				fix_null($constants['USUBJID']) . ',' .
				fix_null($seq) . ',' .
				fix_null($subj_array['mhterm']) . ',' .
				fix_null($llt) . ',' .
				fix_null($pt) . ',' .
				fix_null($soc) . ',' .
				fix_null($subj_array['mhoccur']) . ',' .
				fix_null($subj_array['mhpresp']) . ',' .
				fix_null($subj_array['mhstdtc']) . ',' .
				fix_null($subj_array['mhstdtc']) .
				')';
			$seq++;
コード例 #2
0
/**
 * @param string $project_id
 * @param string $subject_id
 * @param string $event_id
 * @param string $cmdecod
 * @param string $atc_name
 * @param string $atc2_name
 * @param bool $recode
 * @param bool $debug
 */
function code_atc_soc($project_id, $subject_id, $event_id, $cmdecod, $atc_name, $atc2_name, $debug, $recode = false, $message)
{
	/**
	 * CM_SUPPCM_ATCNAME
	 * CM_SUPPCM_ATC2NAME
	 * queries to find ATC name for conmed
	 */
	if (isset($cmdecod) && $cmdecod != '') {
		/**
		 * get indcd -> soc for mapping soc to atc
		 */
		$soc = get_bodsys(get_single_field($subject_id, $project_id, $event_id, 'cm_suppcm_indcod', ''));
		$map_result = db_query("SELECT atc_code, atc_code_alt FROM _target_map_soc_atc WHERE soc = '$soc'");
		if ($map_result) {
			$atc_code = db_result($map_result, 0, 'atc_code');
			$atc_code_alt = db_result($map_result, 0, 'atc_code_alt');
			if ($debug) {
				/*error_log("DEBUG: " . $atc_code);
				error_log("DEBUG: " . $atc_code_alt);*/
			}
			db_free_result($map_result);
		}
		$atc_query = "SELECT DISTINCT atc.atc_name, atc1.atc_name AS atc2_name FROM
		(SELECT drug_name, drug_rec_num FROM _whodrug_mp_us) drug
		LEFT JOIN
		(SELECT drug_rec_num, atc_code FROM _whodrug_dda_target) mp_atc ON TRIM(LEADING '0' FROM drug.drug_rec_num) = mp_atc.drug_rec_num
		LEFT JOIN
		(SELECT atc_code, atc_name FROM _whodrug_atc) atc ON SUBSTRING(mp_atc.atc_code,1,1) = atc.atc_code
		LEFT JOIN
		(SELECT atc_code, atc_name FROM _whodrug_atc) atc1 ON SUBSTRING(mp_atc.atc_code,1,3) = atc1.atc_code";
		$atc_query .= " WHERE drug.drug_name = '" . prep($cmdecod) . "' AND ";
		if (isset($atc_code) && $atc_code !== false) {
			$atc_query .= "(atc.atc_code = '" . $atc_code . "'";
			if (isset($atc_code_alt) && $atc_code_alt != '') {
				$atc_query .= " OR atc.atc_code = '" . $atc_code_alt . "'";
			}
			$atc_query .= ") AND ";
		}
		$atc_query .= "atc.atc_name IS NOT NULL LIMIT 1";
		if ($debug) {
			//error_log("DEBUG: " . $atc_query);
		}
		$atcname_result = db_query($atc_query);
		if ($atcname_result) {
			while ($atcname = db_fetch_assoc($atcname_result)) {
				/**
				 * if we have atc and atc2, push to redcap
				 */
				if ($recode) {
					if (isset($atcname['atc_name']) && $atcname['atc_name'] != '') {
						update_field_compare($subject_id, $project_id, $event_id, $atcname['atc_name'], $atc_name, 'cm_suppcm_atcname', $debug, $message);
					}
					if (isset($atcname['atc2_name']) && $atcname['atc2_name'] != '') {
						update_field_compare($subject_id, $project_id, $event_id, $atcname['atc2_name'], $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
					}
				} else {
					if ($atc_name == '' && isset($atcname['atc_name']) && $atcname['atc_name'] != '') {
						update_field_compare($subject_id, $project_id, $event_id, $atcname['atc_name'], $atc_name, 'cm_suppcm_atcname', $debug, $message);
					}
					if ($atc2_name == '' && isset($atcname['atc2_name']) && $atcname['atc2_name'] != '') {
						update_field_compare($subject_id, $project_id, $event_id, $atcname['atc2_name'], $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
					}
				}
			}
			db_free_result($atcname_result);
		}
		/**
		 * if we didn't find one that maps to soc, be more generic
		 */
		$check_atc = get_single_field($subject_id, $project_id, $event_id, 'cm_suppcm_atcname', '');
		if (!isset($check_atc) || $check_atc == '') {
			$atc_query = "SELECT DISTINCT atc.atc_name, atc1.atc_name AS atc2_name FROM
			(SELECT drug_name, drug_rec_num FROM _whodrug_mp_us) drug
			LEFT JOIN
			(SELECT drug_rec_num, atc_code FROM _whodrug_dda_target) mp_atc ON TRIM(LEADING '0' FROM drug.drug_rec_num) = mp_atc.drug_rec_num
			LEFT JOIN
			(SELECT atc_code, atc_name FROM _whodrug_atc) atc ON SUBSTRING(mp_atc.atc_code,1,1) = atc.atc_code
			LEFT JOIN
			(SELECT atc_code, atc_name FROM _whodrug_atc) atc1 ON SUBSTRING(mp_atc.atc_code,1,3) = atc1.atc_code";
			$atcname_result = db_query($atc_query . " WHERE drug.drug_name = '" . prep($cmdecod) . "' AND atc.atc_name IS NOT NULL LIMIT 1");
			if ($atcname_result) {
				/**
				 * we don't want more than one result here
				 */
				while ($atcname = db_fetch_assoc($atcname_result)) {
					/**
					 * if we have atc and atc2, push to redcap
					 */
					if ($recode) {
						if (isset($atcname['atc_name']) && $atcname['atc_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname['atc_name'], $atc_name, 'cm_suppcm_atcname', $debug, $message);
						}
						if (isset($atcname['atc2_name']) && $atcname['atc2_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname['atc2_name'], $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
						}
					} else {
						if ($atc_name == '' && isset($atcname['atc_name']) && $atcname['atc_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname['atc_name'], $atc_name, 'cm_suppcm_atcname', $debug, $message);
						}
						if ($atc2_name == '' && isset($atcname['atc2_name']) && $atcname['atc2_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname['atc2_name'], $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
						}
					}
				}
				db_free_result($atcname_result);
			}
		}
		/**
		 * in case whodrug doesn't know about your conmed, code from alt table
		 */
		$check_atc = get_single_field($subject_id, $project_id, $event_id, 'cm_suppcm_atcname', '');
		if (!isset($check_atc) || $check_atc == '') {
			$atc_alt_query = "SELECT DISTINCT atc.atc_name, atc1.atc_name AS atc2_name FROM
			(SELECT * FROM _whodrug_dda_alt) mp_atc
			LEFT JOIN
			(SELECT atc_code, atc_name FROM _whodrug_atc) atc ON SUBSTRING(mp_atc.atc_code,1,1) = atc.atc_code
			LEFT JOIN
			(SELECT atc_code, atc_name FROM _whodrug_atc) atc1 ON SUBSTRING(mp_atc.atc_code,1,3) = atc1.atc_code";
			$atcname_alt_result = db_query($atc_alt_query . " WHERE mp_atc.drug_name = '" . prep($cmdecod) . "' LIMIT 1");
			if ($atcname_alt_result) {
				/**
				 * we don't want more than one result here
				 */
				while ($atcname_alt = db_fetch_assoc($atcname_alt_result)) {
					/**
					 * if we have atc and atc2, push to redcap
					 */
					if ($recode) {
						if (isset($atcname_alt['atc_name']) && $atcname_alt['atc_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname_alt['atc_name'], $atc_name, 'cm_suppcm_atcname', $debug, $message);
						}
						if (isset($atcname_alt['atc2_name']) && $atcname_alt['atc2_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname_alt['atc2_name'], $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
						}
					} else {
						if ($atc_name == '' && isset($atcname_alt['atc_name']) && $atcname_alt['atc_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname_alt['atc_name'], $atc_name, 'cm_suppcm_atcname', $debug, $message);
						}
						if ($atc2_name == '' && isset($atcname_alt['atc2_name']) && $atcname_alt['atc2_name'] != '') {
							update_field_compare($subject_id, $project_id, $event_id, $atcname_alt['atc2_name'], $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
						}
					}
				}
				db_free_result($atcname_alt_result);
			}
		}
	} else {
		update_field_compare($subject_id, $project_id, $event_id, '', $atc_name, 'cm_suppcm_atcname', $debug, $message);
		update_field_compare($subject_id, $project_id, $event_id, '', $atc2_name, 'cm_suppcm_atc2name', $debug, $message);
	}
}