1

Drchrono API provides sample code in Python for uploading medical documents.

Here is the sample in Python:

import datetime, json, requests

headers = {
    'Authorization': 'Bearer ACCESS_TOKEN',
}
data = {
    'doctor': 1234,
    'patient': 5678,
    'description': 'Short document description here',
    'date': '2014-02-24',
    'metatags': json.dumps(['tag1', 'tag2']),
}
with open('/path/to/your.pdf', 'rb') as f:
    files = {'document': f}
    requests.post(
        'https://drchrono.com/api/documents',
        data=data, files=files, headers=headers,
    )

According to Drchrono API, There are several pitfalls with content-types:

Creating or updating nested objects, as well as creating multiple objects, are only supported using the application/json content-type.

Files are only supported using the form/multipart content-type.

Here is my issue: I am trying to re-write the above code to php to enable me upload files to the API by following the sample code here:

sample code

but it throws error:

{"document":["The submitted data was not a file. Check the encoding type on the form."]}.

Here is the code.

form.php

<form method="post" action="document_upload.php" enctype="multipart/form-data">
    <input type="text" name="doctor" value="2846">
    <input type="text" name="patient" value="91189">
    <input type="text" name="description" value="Patient Medical History Form">
    <input type="text" name="date" value="2015-11-02">
    <input type="file" name="document">
    <input type="submit" name="submit" value="Upload">

</form>

upload.php

$fsize = $_FILES['document']['size']; 
$ftmp = $_FILES['document']['tmp_name'];
$fname= $_FILES["document"]["name"];
$tok='my-token-goes here';
$doctor =$_POST['doctor'];
$patient =$_POST['patient'];

$data_params= array(
'document' => $ftmp,
    'doctor' => $doctor,
    'patient' => $patient,
    'date' => "2015-11-02",
    'description' => "Patient Medical History File"
); 



$url ='https://app.drchrono.com/api/documents';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $tok", 'Content-Type: application/json'));  
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $tok"));  

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_params);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch); 

echo $output;
Laurel
  • 5,965
  • 14
  • 31
  • 57
Nancy Moore
  • 2,322
  • 2
  • 21
  • 38

1 Answers1

0

It was resolved. The issue is that am using an expired token

Nancy Moore
  • 2,322
  • 2
  • 21
  • 38