1. Go to this page and download the library: Download drchrono/php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
drchrono / php-sdk example snippets
use DrChrono\DrChronoClient;
// Create client with access token
$client = DrChronoClient::withAccessToken('your_access_token');
// Get current user
$user = $client->getCurrentUser();
echo "Authenticated as: {$user['first_name']} {$user['last_name']}";
// List patients
$patients = $client->patients->list();
foreach ($patients as $patient) {
echo "{$patient['first_name']} {$patient['last_name']}\n";
}
use DrChrono\DrChronoClient;
// Initialize client with OAuth credentials
$client = DrChronoClient::withOAuth(
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
redirectUri: 'https://yourapp.com/callback'
);
// Step 1: Redirect user to authorization URL
$authUrl = $client->auth()->getAuthorizationUrl(
scopes: ['patients:read', 'appointments:read', 'appointments:write']
);
header("Location: {$authUrl}");
// Step 2: Exchange code for tokens (in your callback handler)
$tokens = $client->auth()->exchangeAuthorizationCode($_GET['code']);
// Step 3: Use access token
$client->getConfig()->setAccessToken($tokens['access_token']);
$patients = $client->patients->list();
use DrChrono\DrChronoClient;
use Illuminate\Support\Facades\Http;
Http::fake();
$client = app(DrChronoClient::class);
$patients = $client->patients->list();
// Get patient with full insurance details
$patient = $client->patients->getWithInsurance($patientId);
echo "Insurance: {$patient['primary_insurance']['insurance_payer_name']}\n";
echo "Policy #: {$patient['primary_insurance']['insurance_id_number']}\n";
// Get appointment with clinical data (vitals, notes, etc.)
$appointment = $client->appointments->getWithClinicalData($appointmentId);
echo "BP: {$appointment['vitals']['blood_pressure_1']}/{$appointment['vitals']['blood_pressure_2']}\n";
// Get clinical note with full section content
$note = $client->clinicalNotes->getWithSections($noteId);
foreach ($note['clinical_note_sections'] as $section) {
echo "{$section['section_name']}: {$section['section_content']}\n";
}
// List patients with insurance details
// Note: Page size limited to 50 (vs 250 default)
$patients = $client->patients->listWithInsurance(['doctor' => 123456]);
// Manual verbose mode (low-level)
$appointments = $client->appointments->list(['verbose' => 'true']);
// Get first page
$patients = $client->patients->list(['page_size' => 50]);
echo "Page count: {$patients->count()}\n";
echo "Has more: " . ($patients->hasNext() ? 'Yes' : 'No') . "\n";
// Iterate through items
foreach ($patients as $patient) {
// Process patient
}
// Auto-iterate all pages (memory efficient)
foreach ($client->patients->iterateAll() as $patient) {
// Processes all patients across all pages
}
// Get all at once (caution: may be memory intensive)
$allPatients = $client->patients->all();
use DrChrono\Model\Patient;
use DrChrono\Model\Appointment;
// Create from array
$patient = Patient::fromArray($patientData);
echo $patient->getFullName();
echo $patient->getEmail();
echo $patient->getDateOfBirth();
// Convert to array
$data = $patient->toArray();
// Use models with resources
$appointmentData = (new Appointment())
->setDoctor(123)
->setPatient(456)
->setOffice(1)
->setDuration(30)
->setScheduledTime('2025-01-15T10:00:00')
->toArray();
$created = $client->appointments->create($appointmentData);