예제 #1
0
	/**
	 * @param $record
	 * @param $debug
	 */
	public static function set_tx_data($record, $debug)
	{
		global $Proj, $project_id, $tx_prefixes, $dm_array, $tx_array, $endt_fields, $regimen_fields;
		$enable_kint = $debug && (isset($record) && $record != '') ? true : false;
		Kint::enabled($enable_kint);
		$baseline_event_id = $Proj->firstEventId;
		$fields = array_merge($dm_array, $tx_array, $endt_fields, array('trt_suppex_txstat'));
		$data = REDCap::getData('array', $record, $fields);
		$regimen_data = REDCap::getData('array', $record, $regimen_fields);
		foreach ($data AS $subject_id => $subject) {
			$start_stack = array();
			$tx_start_date = null;
			$stop_date = null;
			$age_at_start = null;
			$end_values = array();
			foreach ($subject AS $event_id => $event) {
				/**
				 * build dm_rfstdtc array
				 */
				foreach ($tx_array AS $tx_start) {
					if ($event[$tx_start] != '') {
						$start_stack[] = $event[$tx_start];
					}
				}
				/**
				 * build entdtc array
				 */
				foreach ($endt_fields AS $endt_field) {
					if ($event[$endt_field] != '') {
						$end_values[$event_id][$endt_field] = $event[$endt_field];
					}
				}
			}
			/**
			 * SUBJECT LEVEL
			 */
			rsort($start_stack);
			$tx_start_date = get_end_of_array($start_stack);
			/**
			 * dm_rfstdtc
			 */
			update_field_compare($subject_id, $project_id, $baseline_event_id, $tx_start_date, $subject[$baseline_event_id]['dm_rfstdtc'], 'dm_rfstdtc', $debug);
			/**
			 * age is dependent on the dm_rfxstdtc, not the derived treatment start date used elsewhere
			 */
			$dm_rfxstdtc = $subject[$baseline_event_id]['dm_rfxstdtc'];
			if (isset($dm_rfxstdtc)) {
				/**
				 * Age at start of treatment
				 * age_suppvs_age
				 */
				if ($subject[$baseline_event_id]['dm_brthyr'] != '') {
					$birth_year = $subject[$baseline_event_id]['dm_brthyr'];
				} elseif ($subject[$baseline_event_id]['dm_brthdtc'] != '') {
					$birth_year = substr($subject[$baseline_event_id]['dm_brthdtc'], 0, 4);
				} else {
					$birth_year = '';
				}
				if (isset($birth_year) && $birth_year != '') {
					$tx_start_year = substr($dm_rfxstdtc, 0, 4);
					$age_at_start = ($tx_start_year - $birth_year) > 0 ? $tx_start_year - $birth_year : null;
				}
				update_field_compare($subject_id, $project_id, $baseline_event_id, $age_at_start, $subject[$baseline_event_id]['age_suppvs_age'], 'age_suppvs_age', $debug);
			}
			/**
			 * dependent on derived TX start
			 */
			if (isset($tx_start_date)) {
				/**
				 * Date of last dose of HCV treatment or Treatment stop date
				 * dis_suppfa_txendt
				 */
				$stack = array();
				if (array_search_recursive('ONGOING', $end_values) === false) {
					foreach ($tx_prefixes AS $endt_prefix) {
						foreach ($end_values AS $event) {
							if ($event[$endt_prefix . '_exendtc'] != '' && ($event[$endt_prefix . '_suppex_extrtout'] == 'COMPLETE') || $event[$endt_prefix . '_suppex_extrtout'] == 'PREMATURELY_DISCONTINUED') {
								$stack[] = $event[$endt_prefix . '_exendtc'];
								d('PREFIX ' . $endt_prefix, $event);
							}
						}
					}
				}
				sort($start_stack);
				sort($stack);
				$last_date_in_start_stack = get_end_of_array($start_stack);
				$last_date_in_stack = get_end_of_array($stack);
				$stop_date = $last_date_in_stack < $last_date_in_start_stack ? null : $last_date_in_stack;
				d($end_values);
				d($start_stack);
				d($stack);
				d($last_date_in_start_stack);
				d($last_date_in_stack);
				d($stop_date);
				update_field_compare($subject_id, $project_id, $baseline_event_id, $stop_date, $subject[$baseline_event_id]['dis_suppfa_txendt'], 'dis_suppfa_txendt', $debug);
				/**
				 * HCV Treatment duration
				 */
				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;
					update_field_compare($subject_id, $project_id, $baseline_event_id, $dis_dsstdy, $subject[$baseline_event_id]['dis_dsstdy'], 'dis_dsstdy', $debug);
				}
			}
			/**
			 * update treatment regimen
			 */
			$txstat = isset($tx_start_date) ? 'Y' : 'N';
			$regimen = get_regimen($regimen_data[$subject_id], $subject[$baseline_event_id]['eot_dsterm'], $txstat);
			update_field_compare($subject_id, $project_id, $baseline_event_id, $regimen['actarm'], $subject[$baseline_event_id]['dm_actarm'], 'dm_actarm', $debug);
			update_field_compare($subject_id, $project_id, $baseline_event_id, $regimen['actarmcd'], $subject[$baseline_event_id]['dm_actarmcd'], 'dm_actarmcd', $debug);
		}
	}
예제 #2
0
 /**
  * @param $record
  * @param $debug
  */
 public static function set_hcvrna_outcome($record, $debug)
 {
     global $Proj, $project_id, $ie_criteria_labels;
     $enable_kint = $debug && (isset($record) && $record != '') ? true : false;
     Kint::enabled($enable_kint);
     $baseline_event_id = $Proj->firstEventId;
     $fieldsets = array('abstracted' => array(array('date_field' => 'hcv_lbdtc'), array('value_field' => 'hcv_lbstresn'), array('detect_field' => 'hcv_supplb_hcvdtct')), 'imported' => array(array('date_field' => 'hcv_im_lbdtc'), array('value_field' => 'hcv_im_lbstresn'), array('detect_field' => 'hcv_im_supplb_hcvdtct'), array('trust' => 'hcv_im_nxtrust')));
     $data = array();
     $field_translate = array();
     $reverse_translate = array();
     foreach ($fieldsets as $formtype => $fieldset) {
         $filter_logic = $formtype == 'abstracted' ? "[hcv_lbdtc] != ''" : "[hcv_im_lbdtc] != '' AND [hcv_im_nxtrust] != 'N'";
         $fields = array();
         foreach ($fieldset as $field) {
             foreach ($field as $key => $value) {
                 $fields[] = $value;
                 $field_translate[$formtype][$key] = $value;
                 $reverse_translate[$formtype][$value] = $key;
             }
         }
         $data[$formtype] = REDCap::getData('array', $record, $fields, null, null, false, false, false, $filter_logic);
     }
     /**
      * Main
      */
     $ie_fields = array('ie_ietestcd');
     $ie_data = REDCap::getData('array', $record, $ie_fields);
     $date_fields = array('dm_usubjid', 'dm_rfstdtc', 'dis_suppfa_txendt', 'eot_dsterm', 'dis_dsstdy', 'hcv_suppfa_fuelgbl', 'hcv_suppfa_nlgblrsn', 'hcv_suppfa_hcvout', 'hcv_suppfa_wk10rna', 'hcv_suppfa_lastbloq', 'dis_suppds_funcmprsn', 'hcv_suppfa_fudue', 'dm_suppdm_hcvt2id', 'dm_actarmcd', 'dm_suppdm_rtrtsdtc');
     $date_data = REDCap::getData('array', $record, $date_fields, $baseline_event_id);
     foreach ($date_data as $subject_id => $subject) {
         $all_events = array();
         $post_tx_dates = array();
         $post_tx_bloq_dates = array();
         $re_treat_candidate = false;
         $re_treat_dates = array();
         foreach ($subject as $date_event_id => $date_event) {
             /**
              * HCV RNA Outcome
              */
             $hcvrna_improved = false;
             $on_tx_scores = array();
             $hcvrna_previous_score = '';
             $post_tx_scores = array();
             $post_tx_plus10w_scores = array();
             $post_tx_plus10d_scores = array();
             $last_hcvrna_bloq = false;
             $stop_date_plus_10w = null;
             $stop_date_plus_10d = null;
             $tx_stopped_10_wks_ago = false;
             $started_tx = false;
             $stopped_tx = false;
             $hcv_fu_eligible = true;
             $hcv_fu_ineligible_reason = array();
             $lost_to_followup = false;
             $hcv_data_due = false;
             $tx_start_date = isset($date_event['dm_rfstdtc']) && $date_event['dm_rfstdtc'] != '' ? $date_event['dm_rfstdtc'] : null;
             $stop_date = isset($date_event['dis_suppfa_txendt']) && $date_event['dis_suppfa_txendt'] != '' ? $date_event['dis_suppfa_txendt'] : null;
             $dis_dsstdy = isset($date_event['dis_dsstdy']) && $date_event['dis_dsstdy'] != '' ? $date_event['dis_dsstdy'] : null;
             $eot_dsterm = isset($date_event['eot_dsterm']) && $date_event['eot_dsterm'] != '' ? $date_event['eot_dsterm'] : null;
             /**
              * look for this dm_usubjid in dm_suppdm_hcvt2id. This is a foreign key between TARGET 2 and TARGET 3 patients.
              * Get the start date of the TARGET 3 patient if dm_suppdm_hcvt2id is not empty.
              */
             $t3_fk_result = db_query("SELECT record FROM redcap_data WHERE project_id = '{$project_id}' AND field_name = 'dm_suppdm_hcvt2id' AND value = '{$date_event['dm_usubjid']}'");
             if ($t3_fk_result) {
                 $t3_fk = db_fetch_assoc($t3_fk_result);
                 $t3_start_date_value = get_single_field($t3_fk['record'], $project_id, $baseline_event_id, 'dm_rfstdtc', '');
             }
             $t3_start_date = isset($t3_start_date_value) ? $t3_start_date_value : '';
             /**
              * where are we in treatment?
              */
             if (isset($tx_start_date)) {
                 // started treatment
                 $started_tx = true;
                 /**
                  * treatment must have started to stop
                  */
                 if (isset($stop_date)) {
                     // completed treatment
                     $stopped_tx = true;
                     $stop_date_plus_10d = add_date($stop_date, 10, 0, 0);
                     $stop_date_plus_10w = add_date($stop_date, 64, 0, 0);
                     if (date("Y-m-d") >= $stop_date_plus_10w && isset($stop_date_plus_10w)) {
                         $tx_stopped_10_wks_ago = true;
                     }
                 } else {
                     // not completed treatment
                     $stopped_tx = false;
                     $hcv_fu_eligible = false;
                     $hcv_fu_ineligible_reason[] = 'TX Not Completed';
                 }
             } else {
                 // not started treatment
                 $started_tx = false;
                 $hcv_fu_eligible = false;
                 $hcv_fu_ineligible_reason[] = 'TX Not Started';
             }
             /**
              * get fields for both abstracted (standardized) and imported HCV RNA forms
              */
             foreach ($fieldsets as $formtype => $fieldset) {
                 foreach ($data[$formtype][$subject_id] as $event_id => $event) {
                     /**
                      * standardize array keys
                      */
                     foreach ($event as $event_key => $event_value) {
                         unset($event[$event_key]);
                         $event[array_search($event_key, $field_translate[$formtype])] = $event_value;
                     }
                     /**
                      * merge into all_events array
                      */
                     if ($event['date_field'] != '') {
                         $all_events[$event['date_field']][] = $event;
                     }
                 }
             }
             ksort($all_events);
             /**
              * get outcomes
              */
             foreach ($all_events as $event_date => $event_set) {
                 foreach ($event_set as $event) {
                     /**
                      * if we have a date, and the HCV RNA isn't an 'untrusted blip'...
                      * (blips are sudden, small increases in viral load following EOT)
                      */
                     if (($event['value_field'] != '' || $event['detect_field'] != '') && ($event['date_field'] != '' && $t3_start_date == '' || $event['date_field'] != '' && $t3_start_date != '' && $event['date_field'] <= $t3_start_date)) {
                         $is_bloq = in_array($event['detect_field'], array('BLOQ', 'NOT_SPECIFIED', 'DETECTED')) || $event['value_field'] == '0' ? true : false;
                         $score = $is_bloq ? '0' : '1';
                         /**
                          * if treatment has started, and $event['date_field'] is after start date (is baseline or later)
                          */
                         if ($started_tx && $tx_start_date <= $event['date_field']) {
                             /**
                              * and is...
                              */
                             if (!$stopped_tx || $stopped_tx && $event['date_field'] <= $stop_date) {
                                 // on treatment
                                 $on_tx_scores[] = $score;
                                 if ($score >= $hcvrna_previous_score) {
                                     $hcvrna_improved = false;
                                 } elseif ($score < $hcvrna_previous_score) {
                                     $hcvrna_improved = true;
                                 }
                                 $hcvrna_previous_score = $score;
                                 if ($eot_dsterm == 'LACK_OF_EFFICACY' && get_end_of_array($on_tx_scores) == '1') {
                                     $re_treat_candidate = true;
                                 }
                             } else {
                                 // post-treatment
                                 /**
                                  * RE-TREAT handling
                                  * If this HCVRNA is quantifiable, add the date to an array
                                  * if this HCVRNA is bloq and we have quantified post-TX HCVRNA, it's a re-treat and we don't want it in $post_tx_scores
                                  */
                                 if ($is_bloq && !in_array('1', $post_tx_scores) && !$re_treat_candidate) {
                                     $post_tx_bloq_dates[] = $event['date_field'];
                                     $post_tx_scores[] = $score;
                                     /**
                                      * capture scores that are after EOT plus 10 weeks
                                      */
                                     if (isset($stop_date_plus_10w) && $event['date_field'] >= $stop_date_plus_10w) {
                                         $post_tx_plus10w_scores[] = $score;
                                     }
                                     /**
                                      * capture scores that are between EOT and EOT plus 10 days
                                      */
                                     if (isset($stop_date_plus_10d) && $event['date_field'] <= $stop_date_plus_10d) {
                                         $post_tx_plus10d_scores[] = $score;
                                     }
                                 }
                                 if (!$is_bloq && !in_array('1', $post_tx_scores) && !$re_treat_candidate) {
                                     $post_tx_dates[] = $event['date_field'];
                                     $post_tx_scores[] = $score;
                                     /**
                                      * capture scores that are after EOT plus 10 weeks
                                      */
                                     if (isset($stop_date_plus_10w) && $event['date_field'] >= $stop_date_plus_10w) {
                                         $post_tx_plus10w_scores[] = $score;
                                     }
                                     /**
                                      * capture scores that are between EOT and EOT plus 10 days
                                      */
                                     if (isset($stop_date_plus_10d) && $event['date_field'] <= $stop_date_plus_10d) {
                                         $post_tx_plus10d_scores[] = $score;
                                     }
                                 }
                                 if ($is_bloq && in_array('1', $post_tx_scores)) {
                                     $re_treat_candidate = true;
                                 }
                             }
                         }
                     }
                 }
             }
             /**
              * we have all our score candidates
              */
             $all_scores = array_merge($on_tx_scores, $post_tx_scores);
             $last_hcvrna_bloq = count($all_scores) > 0 && get_end_of_array($all_scores) == '0' ? true : false;
             /**
              * get candidates for re-treat cutoff date
              */
             $re_treat_dates = array_diff(array_unique($post_tx_dates), array_unique($post_tx_bloq_dates));
             /**
              * HCVRNA Followup Eligibility
              * subjects are ineligible for followup if:
              */
             foreach ($ie_data[$subject_id] as $ie_event) {
                 if ($ie_event['ie_ietestcd'] != '') {
                     // failed i/e criteria
                     $hcv_fu_eligible = false;
                     $hcv_fu_ineligible_reason[] = $ie_criteria_labels[$ie_event['ie_ietestcd']];
                 }
             }
             /**
              * disposition-related ineligibility
              */
             if (in_array($date_event['eot_dsterm'], array('LOST_TO_FOLLOWUP', 'LACK_OF_EFFICACY'))) {
                 // disposition is lost to followup
                 $lost_to_followup = true;
                 $hcv_fu_eligible = false;
                 $hcv_fu_ineligible_reason[] = fix_case($date_event['eot_dsterm']);
             }
             /**
              * Quantified HCVRNA after EOT
              */
             if (count($post_tx_scores) > 1 && !$hcvrna_improved) {
                 if (in_array('1', $post_tx_scores)) {
                     // had quantified HCV RNA after EOT
                     $hcv_fu_eligible = false;
                     $hcv_fu_ineligible_reason[] = 'Quantified post-TX HCVRNA';
                 }
             } else {
                 if (in_array('1', $post_tx_scores)) {
                     // had quantified HCV RNA after EOT
                     $hcv_fu_eligible = false;
                     $hcv_fu_ineligible_reason[] = 'Quantified post-TX HCVRNA';
                 }
             }
             /**
              * lost to post-treatment follow up if not already LTFU
              */
             $post_tx_followup_eligible = $date_event['dis_suppds_funcmprsn'] == 'LOST_TO_FOLLOWUP' ? false : true;
             if (!$lost_to_followup) {
                 if (!$post_tx_followup_eligible) {
                     $lost_to_followup = true;
                     $hcv_fu_eligible = false;
                     $hcv_fu_ineligible_reason[] = 'Lost to post-TX followup';
                 }
             }
             /**
              * derive outcome now as it's needed below
              */
             $GLOBALS['started_tx'] = $started_tx;
             $GLOBALS['stopped_tx'] = $stopped_tx;
             $GLOBALS['post_tx_plus10w_scores'] = $post_tx_plus10w_scores;
             $GLOBALS['last_hcvrna_bloq'] = $last_hcvrna_bloq;
             $GLOBALS['lost_to_followup'] = $lost_to_followup;
             $GLOBALS['tx_stopped_10_wks_ago'] = $tx_stopped_10_wks_ago;
             $GLOBALS['hcv_fu_eligible'] = $hcv_fu_eligible;
             $GLOBALS['on_tx_scores'] = $on_tx_scores;
             $GLOBALS['post_tx_plus10d_scores'] = $post_tx_plus10d_scores;
             $GLOBALS['post_tx_scores'] = $post_tx_scores;
             $GLOBALS['eot_dsterm'] = $eot_dsterm;
             $outcome = self::get_outcome();
             /**
              * IS FOLLOWUP DATA FOR THIS SUBJECT DUE?
              * if followup eligible and treatment duration greater than 4 weeks...
              */
             if ($hcv_fu_eligible && $post_tx_followup_eligible && isset($dis_dsstdy) && $dis_dsstdy >= 29) {
                 /**
                  * AND today is TX stop date + 14 weeks ago, and no final outcome, data is due
                  */
                 if (date("Y-m-d") >= add_date($stop_date, 98, 0, 0) && !in_array($outcome, array('SVR', 'VIRAL BREAKTHROUGH', 'RELAPSE', 'NON-RESPONDER', 'LOST TO FOLLOWUP'))) {
                     $hcv_data_due = true;
                 }
             }
             /**
              * if not followup eligible (and no TX stop - implied by ineligible)...
              */
             if ((!$hcv_fu_eligible || !$post_tx_followup_eligible) && $started_tx && !$stopped_tx) {
                 /**
                  * is regimen SOF + RBV?
                  */
                 $regimen = get_single_field($subject_id, $project_id, $baseline_event_id, 'dm_actarmcd', null);
                 //					$due_fields = array('sof_cmstdtc', 'rib_cmstdtc');
                 //					$due_data = REDCap::getData('array', $subject_id, $due_fields);
                 //					$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 = $regimen == 'SOF/RBV' ? true : false;
                 /**
                  * get genotype
                  */
                 $genotype = get_single_field($subject_id, $project_id, $baseline_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') {
                     /**
                      * if TX start is 84 days ago, data is due
                      */
                     if (date("Y-m-d") >= add_date($tx_start_date, 84, 0, 0)) {
                         $hcv_data_due = true;
                     }
                     /**
                      * if any other regimen or genotype
                      */
                 } else {
                     /**
                      * if TX start is 84 days ago, data is due
                      */
                     if (date("Y-m-d") >= add_date($tx_start_date, 84, 0, 0)) {
                         $hcv_data_due = true;
                     }
                 }
             }
             /**
              * get values
              */
             $last_bloq = $last_hcvrna_bloq ? 'Y' : 'N';
             $eligible = !$hcv_fu_eligible ? 'N' : 'Y';
             $reason = implode('; ', array_unique($hcv_fu_ineligible_reason));
             $data_due = $hcv_data_due ? 'Y' : 'N';
             $wk10_rna = count($post_tx_plus10w_scores) > 0 ? 'Y' : 'N';
             rsort($re_treat_dates);
             $re_treat_date = $re_treat_candidate ? get_end_of_array($re_treat_dates) : null;
             /**
              * debug
              */
             d($all_scores);
             if ($started_tx) {
                 d($tx_start_date);
                 d($on_tx_scores);
                 if ($stopped_tx) {
                     d($stop_date);
                     d($post_tx_scores);
                     d($post_tx_plus10d_scores);
                     d($post_tx_plus10w_scores);
                     d($last_hcvrna_bloq);
                     d($lost_to_followup);
                     d($post_tx_followup_eligible);
                     d($hcv_fu_eligible);
                     d($post_tx_bloq_dates);
                     d($post_tx_dates);
                     d($t3_start_date);
                     d($re_treat_candidate);
                     d($re_treat_date);
                     d($tx_stopped_10_wks_ago);
                     d($hcv_data_due);
                     d($outcome);
                 } else {
                     d('NO TX STOP');
                 }
             } else {
                 d('NO TX START');
             }
             /**
              * set overall hcvrna followup eligibility and reason if ineligible
              */
             update_field_compare($subject_id, $project_id, $baseline_event_id, $eligible, $date_event['hcv_suppfa_fuelgbl'], 'hcv_suppfa_fuelgbl', $debug);
             update_field_compare($subject_id, $project_id, $baseline_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, $baseline_event_id, $data_due, $date_event['hcv_suppfa_fudue'], 'hcv_suppfa_fudue', $debug);
             /**
              * set outcome
              */
             update_field_compare($subject_id, $project_id, $baseline_event_id, $outcome, $date_event['hcv_suppfa_hcvout'], 'hcv_suppfa_hcvout', $debug);
             /**
              * set 10 HCV RNA?
              */
             update_field_compare($subject_id, $project_id, $baseline_event_id, $wk10_rna, $date_event['hcv_suppfa_wk10rna'], 'hcv_suppfa_wk10rna', $debug);
             /**
              * set HCV RNA BLOQ?
              */
             update_field_compare($subject_id, $project_id, $baseline_event_id, $last_bloq, $date_event['hcv_suppfa_lastbloq'], 'hcv_suppfa_lastbloq', $debug);
             /**
              * set re-treat window start date
              */
             update_field_compare($subject_id, $project_id, $baseline_event_id, $re_treat_date, $date_event['dm_suppdm_rtrtsdtc'], 'dm_suppdm_rtrtsdtc', $debug);
         }
     }
 }
				 */
				if (date("Y-m-d") >= (add_date($tx_start_date, 84, 0, 0))) {
					$hcv_data_due = true;
				}
			}
		}
		/**
		 * get values
		 */
		$last_bloq = $last_hcvrna_bloq ? 'Y' : 'N';
		$eligible = !$hcv_fu_eligible ? 'N' : 'Y';
		$reason = implode('; ', array_unique($hcv_fu_ineligible_reason));
		$data_due = $hcv_data_due ? 'Y' : 'N';
		$wk10_rna = count($post_tx_plus10w_scores) > 0 ? 'Y' : 'N';
		rsort($re_treat_dates);
		$re_treat_date = $re_treat_possible ? get_end_of_array($re_treat_dates) : null;
		/**
		 * debug
		 */
		if ($debug) {
			d($all_scores);
			if ($started_tx) {
				d($tx_start_date);
				d($on_tx_scores);
				if ($stopped_tx) {
					d($stop_date);
					d($post_tx_scores);
					d($post_tx_plus10d_scores);
					d($post_tx_plus10w_scores);
					d($last_hcvrna_bloq);
					d($lost_to_followup);
예제 #4
0
/**
 * @param $record
 * @param $debug
 */
function set_svr_dates($record, $debug)
{
	global $Proj, $project_id, $dm_array, $hcv_fields;
	$enable_kint = $debug && (isset($record) && $record != '') ? true : false;
	Kint::enabled($enable_kint);
	$baseline_event_id = $Proj->firstEventId;
	$fields = array_merge($dm_array, $hcv_fields);
	$data = REDCap::getData('array', $record, $fields);
	if ($debug) {
		error_log(print_r($data, TRUE));
	}
	foreach ($data AS $subject_id => $subject) {
		$stop_date = $subject[$baseline_event_id]['dis_suppfa_txendt'] != '' ? $subject[$baseline_event_id]['dis_suppfa_txendt'] : null;
		$hcv_values = array();
		if (isset($stop_date)) {
			foreach ($subject AS $event_id => $event) {
				/**
				 * build HCVDT array
				 */
				foreach ($hcv_fields AS $hcv_field) {
					$hcv_values[$event_id][$hcv_field] = $event[$hcv_field];
				}
			}
			d($hcv_values);
			/**
			 * SVR 12 and 24 dates
			 * hcv_supplb_hcvdtct, hcv_lbdtc, ifn_cmendtc, hcv_suppfa_svr12dt
			 */
			$svr_classes = array(63 => 'hcv_suppfa_svr12dt', 147 => 'hcv_suppfa_svr24dt');
			$svr_range = 83;
			foreach ($svr_classes as $svr_class => $svr_field) {
				$hcv_dates_array = array();
				$lower_date = new DateTime($stop_date);
				$lower_date->add(new DateInterval("P" . $svr_class . "D"));
				$lower_svr_date = $lower_date->format('Y-m-d');
				$upper_date = new DateTime($stop_date);
				$upper_date->add(new DateInterval("P" . ($svr_class + $svr_range) . "D"));
				$upper_svr_date = $upper_date->format('Y-m-d');
				d($svr_field, $upper_svr_date);
				foreach ($hcv_values as $event) {
					if ($event['hcv_lbdtc'] != '') {
						$date_obj = new DateTime($event['hcv_lbdtc']);
						$svr_date = $date_obj->format('Y-m-d');
						if ($lower_svr_date <= $svr_date && $svr_date <= $upper_svr_date) {
							$hcv_dates_array[] = $svr_date;
						}
					}
					if ($event['hcv_im_lbdtc'] != '' && empty($hcv_dates_array)) {
						$date_obj = new DateTime($event['hcv_im_lbdtc']);
						$svr_date = $date_obj->format('Y-m-d');
						if ($lower_svr_date <= $svr_date && $svr_date <= $upper_svr_date) {
							$hcv_dates_array[] = $svr_date;
						}
					}
				}
				rsort($hcv_dates_array);
				$hcv_date = get_end_of_array($hcv_dates_array);
				update_field_compare($subject_id, $project_id, $baseline_event_id, $hcv_date, $subject[$baseline_event_id][$svr_field], $svr_field, $debug);
			}
		}
	}
}