Skip to main content

Sending an Rx Map to a Field Computer

To determine the ID of the Field Computer that should receive the Rx Map, the API Client needs to issue a GET request to the /FieldComputers URI and allow the user to choose the Field Computer from their list of Field Computers. The response to a GET request to the /FieldComputers URI will be:

Step 1: Determining the ID of the Field Computer that should receive the Rx Map

Once the user picks a Field Computer, the API Client will need to save the Uri value of the chosen Field Computer to use in Step 3.

<slingshotindex xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.ravenslingshot.com/SlingshotIndex/2010">
<totalcount>2</totalcount>
<pagesize>20</pagesize>
<ispreviouspage>false</ispreviouspage>
<isnextpage>false</isnextpage>
<pageindex>0</pageindex>
<totalpages>1</totalpages>
<fieldcomputer>
<id>2058</id>
<name>VPRO4 T380</name>
<uri>https://api.ravenslingshot.com/FieldComputers/2058</uri>
</fieldcomputer>
<fieldcomputer>
<id>2558</id>
<name>E-Pro II B2</name>
<uri>https://api.ravenslingshot.com/FieldComputers/2558</uri>
</fieldcomputer>
</slingshotindex>

Step 2: Uploading the Rx Map to the Slingshot API Server

To upload the Rx Map to the Slingshot API Server, the API Client will issue a POST request to the /PrescriptionMaps URI. The POST request body will need to be in the multipart/form-data format. Please see the code sample for more information on the exact format.

The POST request body will consist of two parts: a text parameter named FileType and the binary contents parameter named FileName. The FileType parameter should have either the value "RX" or "AGX", which tells the Slingshot API Server which type of file is uploading. The FileName parameter will be a byte stream of the zipped file along with the name the file should be saved with. Again, more details are in the code sample.

If the POST request is successful, the Slingshot API Server will return a "201 Created" response to the API client along with an XML document that contains the URI of the newly POSTed file. The API Client will need to save this URI path for use in Step 3.

Sample PHP for File Upload

$method = "POST";

//initialize curl
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://api.ravenslingshot.com/PrescriptionMaps");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//create header for authentication
$header = getHeaders($method, "api.ravenslingshot.com", strtolower ("/PrescriptionMaps"));
array_push($header, 'Accept: application/xml');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

//handle file upload
if($method == "POST")
{
//it is a post
curl_setopt($curl, CURLOPT_POST, true);
$filePath = 'C:\PrescriptionMap.zip'; //file location
//array for file information
$postData = array(
"FileType" => "RX",//or AGX
"FileName" => "@".realpath($filePath)
);
//attach filetype and filename
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
}
//handle file ends here

//make the call
$curl_response = curl_exec($curl);

//pretty print
echo "
".htmlentities($curl_response)."
";
curl_close($curl);

Step 3: Directing the Slingshot API Server to send the Rx Map to the chosen Field Computer

To direct the Slingshot API Server to send the Rx Map to the chosen Field Computer the API Client will issue a PUT request to /PrescriptionMaps/{rxID}/FieldComputers/{fcID} where {rxID} is the ID returned by the POST request in Step 2 and {fcID} is the ID of the chosen field computer from Step 1.

If successful, the Slingshot API Server will respond with "200 OK". If the request fails, the Slingshot API Server will return the appropriate error code.

If a file with the same {rxID} is already queued for the field computer {fcID}, an appropriate message to wait will be returned and the file will NOT be queued.

If a file with the same file-name as {rxID} is already queued for the field computer {fcID}, an appropriate message indicating name conflict will be returned and the file will NOT be queued.

If all of the calls were successful, the Slingshot API Server will ensure that the POSTed file is made available for the Field Computer to download. The Field Computers currently have a timer which they use to check with the Slingshot system for files to be downloaded, so the file will not arrive at the Field Computer immediately, but will arrive after the timer fires and the Field Computer requests the file from Slingshot. The actual download time will vary depending on the speed of the Field Computer's connection to the Internet.

Sample PHP for File Upload

$method = "POST";

//initialize curl
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, "https://api.ravenslingshot.com/PrescriptionMaps");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//create header for authentication
$header = getHeaders($method, "api.ravenslingshot.com", strtolower ("/PrescriptionMaps"));
array_push($header, 'Accept: application/xml');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

//handle file upload
if($method == "POST")
{
//it is a post
curl_setopt($curl, CURLOPT_POST, true);
$filePath = 'C:\PrescriptionMap.zip'; //file location
//array for file information
$postData = array(
"FileType" => "RX",//or AGX
"FileName" => "@".realpath($filePath)
);
//attach filetype and filename
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
}
//handle file ends here

//make the call
$curl_response = curl_exec($curl);

//pretty print
echo "
".htmlentities($curl_response)."
";
curl_close($curl);