$REDCAP_TOKEN,'content' => 'record','format' => 'json', 'type' => 'flat','records' => $RECORD,'events'=>array($EVENT)); # - - - - - - - - - - - - - - - - - - # # Curl Commands $exp = curl_init(); curl_setopt($exp, CURLOPT_URL, $API_URL); curl_setopt($exp, CURLOPT_POSTFIELDS, http_build_query($DATA, '', '&')); curl_setopt($exp, CURLOPT_RETURNTRANSFER, true); curl_setopt($exp, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($exp, CURLOPT_VERBOSE, 0); curl_setopt($exp, CURLOPT_FOLLOWLOCATION, true); curl_setopt($exp, CURLOPT_AUTOREFERER, true); curl_setopt($exp, CURLOPT_MAXREDIRS, 10); curl_setopt($exp, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($exp, CURLOPT_FRESH_CONNECT, 1); $output = curl_exec($exp); $list=json_decode($output, true); curl_close($exp); # - - - - - - - - - - - - - - - - - - - - - - - - - # # Only Process Follow-up Text Survey Responses if it's # Complete; i.e. "Submitted": $fu_screen_complete=$list[0]['text_followup_screens_complete']; $log_details1="\nFU Screen Status: ".$fu_screen_complete."\n"; fwrite($logging,$log_details1); if($fu_screen_complete=='2') { $record_id=$list[0]['record_id']; $fu_q1=$list[0]['fu_q1']; $fu_q2=$list[0]['fu_q2']; $fu_q3=$list[0]['fu_q3']; $fu_q4=$list[0]['fu_q4']; $fu_q5=$list[0]['fu_q5']; $fu_q6=$list[0]['fu_q6']; # - - - - - - - - - - - - - - - - - - - - - - - - - # # B. Evaluate the Text Responses and Assign Coded Value: # - - - - - - - - - - - - - - - - - - - - - - - - - # # FU Q1: $fu_q1=strtolower(trim($fu_q1)); if(!in_array($fu_q1,$yes_array) && !in_array($fu_q1,$no_array)){$fu_q1_ans='';} else { if(in_array($fu_q1, $yes_array)){ $fu_q1_ans='1';} if(in_array($fu_q1, $no_array)){ $fu_q1_ans='0'; } } # FU Q2: $fu_q2=strtolower(trim($fu_q2)); if(!in_array($fu_q2,$yes_array) && !in_array($fu_q2,$no_array)){$fu_q2_ans='';} else { if(in_array($fu_q2, $yes_array)){ $fu_q2_ans='1';} if(in_array($fu_q2, $no_array)){ $fu_q2_ans='0'; } } # FU Q3: $fu_q3=strtolower(trim($fu_q3)); if(!in_array($fu_q3,$yes_array) && !in_array($fu_q3,$no_array)){$fu_q3_ans='';} else { if(in_array($fu_q3, $yes_array)){ $fu_q3_ans='1';} if(in_array($fu_q3, $no_array)){ $fu_q3_ans='0';} } # FU Q4: $fu_q4=strtolower(trim($fu_q4)); if(!in_array($fu_q4,$yes_array) && !in_array($fu_q4,$no_array)){$fu_q4_ans='';} else { if(in_array($fu_q4, $yes_array)){ $fu_q4_ans='1';} if(in_array($fu_q4, $no_array)){ $fu_q4_ans='0';} } # FU Q5: $fu_q5=strtolower(trim($fu_q5)); if(!in_array($fu_q5,$yes_array) && !in_array($fu_q5,$no_array)){$fu_q5_ans='';} else { if(in_array($fu_q5, $yes_array)){ $fu_q5_ans='1'; } if(in_array($fu_q5, $no_array)){ $fu_q5_ans='0'; } } # FU Q6: $fu_q6=strtolower(trim($fu_q6)); if(!in_array($fu_q6,$yes_array) && !in_array($fu_q6,$no_array)){$fu_q6_ans='';} else { if(in_array($fu_q6, $yes_array)){ $fu_q6_ans='1';} if(in_array($fu_q6, $no_array)){ $fu_q6_ans='0';} } # - - - - - - - - - - - - - - - - - - - - - - - - - # # C. Determine Risk Category and Send Text w/ Twilio API: $client = new Client($sid, $token); # - - - - - - - - - - - - - - - - - - - - - # # Low Risk Text Messages if($fu_q1_ans=='0' && $fu_q2_ans=='0' && $fu_q3_ans=='0' && $fu_q4_ans=='0' && $fu_q5_ans=='0' && $fu_q6_ans=='0'){ $risk_category='0'; $clinic_risk_cat___0='1'; $clinic_risk_cat___1='0'; $clinic_risk_cat___2='0'; $clinic_risk_cat___3='0'; $clinic_risk_cat___4='0'; # Build & send Twilio text message: $client->messages->create($cell_num, array("body"=>$TXT_GLOBAL['low_txt_1'],"from"=>$twilio_num)); sleep(1); $client->messages->create($cell_num, array("body"=>$TXT_GLOBAL['low_txt_2'],"from"=>$twilio_num)); sleep(1); $client->messages->create($cell_num, array("body"=>$TXT_GLOBAL['low_contact_txt'],"from"=>$twilio_num)); $client->messages->create($cell_num, array("body"=>$TXT_GLOBAL['safety_txt'],"from"=>$twilio_num)); } # Not Low Risk: else { # - - - - - - - - - - - - - - - - - - - - - # # Positive Depression Text Messages if($fu_q3_ans=='1'){ $risk_category='1'; $clinic_risk_cat___0='0'; } # Not positive depression, low risk: else { # - - - - - - - - - - - - - - - - - - - - - # # Substance and Domestic Abuse Risk: if ($fu_q4_ans='1' || $fu_q5_ans=='1' || $fu_q6_ans=='1'){ if ($fu_q4_ans=='1') { $risk_category='4'; # Domestic Abuse $clinic_risk_cat___0='0'; } else { $risk_category='3'; # Substance Abuse $clinic_risk_cat___0='0'; } } # Not SDA, positive depression, low risk else { # - - - - - - - - - - - - - - - - - - - - - # # Prevention Risk: if (($fu_q1_ans=='1' || $fu_q2_ans=='1') && $fu_q3_ans=='0'){ $risk_category='2'; $clinic_risk_cat___0='0'; } } # Not SDA, positive depression, low risk } # else not low risk && not positive depression # Clinical Risk Categories: if($fu_q3_ans=='1'){ $clinic_risk_cat___1='1'; # Pos. Depression Check $clinic_risk_cat___2='0'; # Prevention Uncheck if($fu_q4_ans=='1'){ $clinic_risk_cat___4='1'; } # Domestic Check else { $clinic_risk_cat___4='0'; } # Domestic Uncheck if($fu_q5_ans=='1' || $fu_q6_ans=='1'){ $clinic_risk_cat___3='1'; # Substance Check } else { $clinic_risk_cat___3='0'; } # Substance Uncheck } else { $clinic_risk_cat___1='0'; # Pos. Depression Uncheck if($fu_q1_ans=='1' || $fu_q2_ans=='1'){ $clinic_risk_cat___2='1'; # Prevention Check if($fu_q4_ans=='1'){ $fu_risk_cat___4='1'; } # Domestic Chekc else { $clinic_risk_cat___4='0'; } # Domestic Uncheck if($fu_q5_ans=='1' || $fu_q6_ans=='1'){ $clinic_risk_cat___3='1'; # Substance Check } else { $clinic_risk_cat___3='0'; } # Substance Uncheck } else { if($fu_q4_ans=='1'){ $clinic_risk_cat___4='1'; } # Domestic Check else { $clinic_risk_cat___4='0'; } # Domestic Check if($fu_q5_ans=='1' || $fu_q6_ans=='1'){ $clinic_risk_cat___3='1'; # Substance Check } else { $clinic_risk_cat___3='0'; } #Substance Uncheck } } } # else not low risk # - - - - - - - - - - - - - - - - - - - - - - - - - # # D. Import Risk Category and Coded Values for # Text Messages: # - - - - - - - - - - - - - - - - - - - - - - - - - # $import_info=array('record_id'=>$record_id,'redcap_event_name'=>$EVENT,'txt_risk_cat'=>$risk_category,'fu_q1_ans'=>$fu_q1_ans,'fu_q2_ans'=>$fu_q2_ans,'fu_q3_ans'=>$fu_q3_ans,'fu_q4_ans'=>$fu_q4_ans,'fu_q5_ans'=>$fu_q5_ans,'fu_q6_ans'=>$fu_q6_ans,'clinic_risk_cat___0'=>$clinic_risk_cat___0,'clinic_risk_cat___1'=>$clinic_risk_cat___1,'clinic_risk_cat___2'=>$clinic_risk_cat___2,'clinic_risk_cat___3'=>$clinic_risk_cat___3,'clinic_risk_cat___4'=>$clinic_risk_cat___4); $import=json_encode(array($import_info)); $DATA_IMPORT=array('token'=>$REDCAP_TOKEN,'content'=>'record', 'format'=>'json','type'=>'flat','data'=>$import); $imp = curl_init(); curl_setopt($imp, CURLOPT_URL, $API_URL); curl_setopt($imp, CURLOPT_POSTFIELDS, http_build_query($DATA_IMPORT, '', '&')); curl_setopt($imp, CURLOPT_RETURNTRANSFER, true); curl_setopt($imp, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($imp, CURLOPT_VERBOSE, 0); curl_setopt($imp, CURLOPT_FOLLOWLOCATION, true); curl_setopt($imp, CURLOPT_AUTOREFERER, true); curl_setopt($imp, CURLOPT_MAXREDIRS, 10); curl_setopt($imp, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($imp, CURLOPT_FRESH_CONNECT, 1); curl_exec($imp); curl_close($imp); fwrite($logging,print_r($import_info,TRUE)); } #if sbirt_complete else { exit(); } fclose($logging); ?>