public function api_get_string($data, $error) { $data['token'] = $this->token; // Create REDCap API request object $request = new RestCallRequest($this->api_url, $data); // Initiate the API request, and fetch the results from the request object. $request->execute(); $body_str = $request->getResponseBody(); $header_array = $request->getResponseInfo(); // Decode the JSON content returned by REDCap (into an array rather // than into an object by specifying the second argument as "true"), $body_array = json_decode($body_str, true); // If an error is returned, there will be an 'error' key in // the $body_array if (is_array($body_array) && array_key_exists('error', $body_array)) { $error .= "Error: '" . $body_array['error'] . "'\n"; $this->notifier->notify($error); return false; } else { return $body_str; } }
$temp .= print_r($metadata_lookup, 1); $temp .= "</pre>"; echo $temp; echo "<hr/>\n"; //print the data to the screen //echo $metadata_xml; /////////////////////////////////////////////////////// //Records //This is the actual patient data /////////////////////////////////////////////////////// //The rawOrLabel flag does the look up for me to get the real data out. $options = array('content' => 'record', 'type' => 'flat', 'format' => 'xml', 'rawOrLabel' => 'label', 'token' => $token); //create a new API request object $request = new RestCallRequest("localhost/api/", 'POST', $options); //initiate the API request $request->execute(); $data_xml = $request->getResponseBody(); //By getting rid of the blank XML elements here we dont have to deal with //empty fields that haven't been filled in due to branching logic //excluding them. $data = simplexml_load_string($data_xml, 'SimpleXMLElement', LIBXML_NOBLANKS); ////////////////////////////////////////////////////////////////// //Ideally we would have sanitized all the data by now and made //sure all the required fields are present. $number_of_patients = count($data->item); echo $number_of_patients . " patients to process<br/>\n"; //Cycle through each set of forms. //A key point here is that I pick out the fields that I expect to be there for //non-observations, use them, then unset them. Everything that is then left //gets thrown in as an observation. for ($patient_number = 0; $patient_number < $number_of_patients; $patient_number++) {
# an array containing all the elements that must be submitted to the API $data = array('content' => 'record', 'type' => 'flat', 'format' => 'csv', 'records' => $records, 'events' => $events, 'fields' => $fields, 'token' => $local_token); # create a new API request object for the local machine $request_local = new RestCallRequest($init_params['local_ip'], 'POST', $data); # initiate the API request for the data on the local machine $request_local->execute(); #$local_response = $request_local->getResponseInfo(); $exportdata = $request_local->getResponseBody(); #data from the local machine //print_r($exportdata); # an array containing all the elements that must be submitted to the server API $data = array('content' => 'record', 'type' => 'flat', 'format' => 'csv', 'token' => $server_token, 'data' => $exportdata); # create a new API request object for the server $request_server = new RestCallRequest($init_params['server_ip'], 'POST', $data); # initiate the API request to the server $request_server->execute(); $server_response = $request_server->getResponseInfo(); //print_r($server_response); $log_message = implode("\n", array_map(function ($v, $k) { return $k . '=' . $v; }, $server_response, array_keys($server_response))); # Prepare log folder $path = $init_params['log_location']; $response_code = $server_response['http_code']; if ($response_code != '200') { //there was an error echo json_encode(array("<h2>ERROR!</h2><br/>", return_httpstat($response_code))); } else { //Success message here #Success message here $the_date = getdate();