<?php

require_once 'vendor/autoload.php';
require_once '../src/Optretina/Api/OAuth/OAuth2Provider.php';
require_once '../src/Optretina/Api/OAuth/ClientCredentialsGrant.php';
require_once '../src/Optretina/Api/Client.php';
define("CLIENT_ID", "CLIENT_ID_XXX");
define("CLIENT_SECRET", "CLIENT_SECRET_XXX");
define("CASE_ID", "XXXX");
$client = new Optretina\Api\Client(CLIENT_ID, CLIENT_SECRET);
$response = $client->getCase(CASE_ID);
/*
    Response:
    - success: true or false
    - content: if success = true -> Case object. Otherwise error message.
*/
if ($response->success) {
    echo "<pre>";
    var_dump($response->content);
    echo "</pre>";
} else {
    //Error
    echo $response->content;
}
<?php

require_once 'vendor/autoload.php';
require_once '../src/Optretina/Api/OAuth/OAuth2Provider.php';
require_once '../src/Optretina/Api/OAuth/ClientCredentialsGrant.php';
require_once '../src/Optretina/Api/Client.php';
define("CLIENT_ID", "CLIENT_ID_XXX");
define("CLIENT_SECRET", "CLIENT_SECRET_XXX");
$client = new Optretina\Api\Client(CLIENT_ID, CLIENT_SECRET);
$response = $client->getCases();
/*
    Response:
    - success: true or false
    - cases: if success = true -> Case object. Otherwise error message.
*/
if ($response->success) {
    echo "<pre>";
    var_dump($response->cases);
    echo "</pre>";
} else {
    //Error
    echo $response->content;
}
<?php

require_once 'vendor/autoload.php';
require_once '../src/Optretina/Api/OAuth/OAuth2Provider.php';
require_once '../src/Optretina/Api/OAuth/ClientCredentialsGrant.php';
require_once '../src/Optretina/Api/Client.php';
define("CLIENT_ID", "CLIENT_ID_XXX");
define("CLIENT_SECRET", "CLIENT_ID_XXX");
define("CASE_ID", 'XXXX');
$client = new Optretina\Api\Client(CLIENT_ID, CLIENT_SECRET);
$response = $client->getReport(CASE_ID);
/*
    Response:
    - success: true or false
    - content: if success = true -> File source decode in base64 . Otherwise error message.
*/
if ($response->success) {
    header('Content-Type: application/pdf');
    header('Cache-Control: public, must-revalidate, max-age=0');
    header('Pragma: public');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    echo base64_decode($response->content);
    die;
} else {
    echo $response->content;
}
<?php

require_once 'vendor/autoload.php';
require_once '../src/Optretina/Api/OAuth/OAuth2Provider.php';
require_once '../src/Optretina/Api/OAuth/ClientCredentialsGrant.php';
require_once '../src/Optretina/Api/Client.php';
define("CLIENT_ID", "CLIENT_ID_XXX");
define("CLIENT_SECRET", "CLIENT_SECRET_XXX");
define("MALE", 0);
define("FEMALE", 1);
$client = new Optretina\Api\Client(CLIENT_ID, CLIENT_SECRET);
$response = $client->createCase(['history_number' => 31415, 'first_name' => 'API Name', 'last_name' => 'Last Name', 'secondary_last_name' => 'Third Name', 'gender' => FEMALE, 'age' => 30, 'diabetes' => 1, 'visit_date' => (new \DateTime('now'))->format('Y-m-d'), 'visit_reason' => 'Patient with regular headaches when reading', 'ophthalmic_antecedents' => 'Relevant antecedents', 'other_relevant_info' => 'Other', 'retinologist_notes' => 'Internal notes for the retinologist', 'od_iop' => 16, 'od_va' => 0.5, 'od_axis' => 15, 'od_cylinder' => -1, 'od_sphere' => -1.25, 'od_add' => 3.5, 'od_prism' => 0.5, 'od_prism_base' => 0, 'os_iop' => 16, 'os_va' => 0.5, 'os_axis' => 15, 'os_cylinder' => -1, 'os_sphere' => -1.25, 'os_add' => 3.5, 'os_prism' => 0.5, 'os_prism_base' => 0, 'callback_url' => 'http://localhost.com/optretina-php-sdk/example/callback.php', 'images' => array('./images/2.jpg')]);
/*
    Response:
    - success: true or false
    - content: if success = true -> id value. Otherwise error message.
*/
if ($response->success) {
    $caso_id = $response->content;
    echo "New case id: " . $caso_id;
} else {
    //Error
    echo $response->content;
}