| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902 |
- <?php
- require_once 'API.class.php';
- require_once 'Config/Settings.class.php';
- require_once 'Tools/UUID.class.php';
- require_once 'Models/APIKey.class.php';
- require_once 'Models/User.class.php';
- require_once 'Models/DataInterface.class.php';
- require_once 'Models/AccountInterface.class.php';
- require_once 'Models/HomeInterface.class.php';
- require_once 'Models/ProfileInterface.class.php';
- require_once 'Models/PatientInterface.class.php';
- require_once 'Models/AcquireInterface.class.php';
- require_once 'Models/ReportInterface.class.php';
- require_once 'Models/MeasureInterface.class.php';
- require_once 'Models/AdminInterface.class.php';
- require_once 'Models/CtAdminInterface.class.php';
- require_once 'External/PHP-JWT/src/JWT.php';
- require_once 'External/PHP-JWT/src/ExpiredException.php';
- require_once 'External/PHP-JWT/src/BeforeValidException.php';
- require_once 'External/PHP-JWT/src/SignatureInvalidException.php';
- class IIMTAPI extends API {
- //
- protected $User;
- protected $APIKey;
- protected $DataInterface;
- protected $AdminInterface;
- protected $AccountInterface;
- protected $ProfileInterface;
- protected $HomeInterface;
- protected $AcquireInterface;
- protected $ReportInterface;
- //protected $Broker;
- /**
- *
- */
- public function __construct($request, $origin) {
- parent::__construct($request);
- $this->APIKey = new Models\APIKey();
- $this->User = new Models\User();
- if (!array_key_exists('apiKey', $this->request)) {
- throw new Exception('No API Key provided');
- }
- else if (!$this->APIKey->verifyKey($this->request['apiKey'], $origin)) {
- throw new Exception('Invalid API Key');
- }
- try {
- $this->DataInterface = new Models\DataInterface();
- $this->AdminInterface = new Models\AdminInterface($this->DataInterface);
- $this->CtAdminInterface = new Models\CtAdminInterface($this->DataInterface);
- $this->AccountInterface = new Models\AccountInterface($this->DataInterface);
- $this->HomeInterface = new Models\HomeInterface($this->DataInterface);
- $this->ProfileInterface = new Models\ProfileInterface($this->DataInterface);
- $this->PatientInterface = new Models\PatientInterface($this->DataInterface);
- $this->AcquireInterface = new Models\AcquireInterface($this->DataInterface);
- $this->ReportInterface = new Models\ReportInterface($this->DataInterface);
- $this->MeasureInterface = new Models\MeasureInterface($this->DataInterface);
- }
- catch (Exception $e) {
- throw $e;
- }
- }
- /**
- * Get:
- * /api/v1/test/?apiKey=
- */
- protected function test($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- switch($this->method) {
- case 'GET':
- return $this->DataInterface->test();
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- *
- */
- protected function ray($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) ) {
- throw new Exception('Permission denied.');
- }
- if($this->method != 'POST') {
- throw new Exception('Not implemented.');
- }
- // ray
- $headers = getallheaders();
- $id_ray = 0;
- if(array_key_exists('RayID', $headers)) {
- $id_ray = $headers['RayID'];
- }
- // ip
- $ip = $_SERVER['REMOTE_ADDR'];
- $ip_type = 'direct';
- if(array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- $ip_type = 'x_forwarded_for';
- }
- if($ip == '::1') {
- $ip = '';
- $ip_type = 'localhost';
- }
- $ip_data = array(
- 'ip' => $ip,
- 'type' => $ip_type
- );
- // location
- try {
- if($ip_type=='localhost') {
- $location_data = json_decode(file_get_contents("http://www.geoplugin.net/json.gp"));
- }
- else {
- $location_data = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=$ip"));
- }
- $location_data = array(
- 'city' => $location_data->geoplugin_city,
- 'continentCode' => $location_data->geoplugin_continentCode,
- 'continentName' => $location_data->geoplugin_continentName,
- 'countryCode' => $location_data->geoplugin_countryCode,
- 'countryName' => $location_data->geoplugin_countryName,
- 'currencyCode' => $location_data->geoplugin_currencyCode,
- 'latitude' => $location_data->geoplugin_latitude,
- 'longitude' => $location_data->geoplugin_longitude,
- 'timezone' => $location_data->geoplugin_timezone,
- 'request' => $location_data->geoplugin_request
- );
- }
- catch(Exception $e) {
- $location_data = [];
- }
- // store
- if($id_ray != 0) {
- $result = $this->DataInterface->rayUpdate(
- $id_ray,
- $this->request['userAgent'],
- $this->request['apiKey'],
- $ip_data,
- $location_data
- );
- }
- else {
- $result = $this->DataInterface->rayCreate(
- $this->request['userAgent'],
- $this->request['apiKey'],
- $ip_data,
- $location_data
- );
- }
- $result['country'] = $location_data['countryCode'];
- return $result;
- }
- /**
- *
- */
- protected function log($args, $verb) {
- // ray
- $headers = getallheaders();
- $id_ray = 0;
- if(array_key_exists('RayID', $headers)) {
- $id_ray = $headers['RayID'];
- try {
- $chkToken = $this->User->checkToken();
- }
- catch(Exception $e) {
- $chkToken = 'denied';
- }
- $user_data = array(
- 'ID' => $this->User->ID,
- 'firstname' => $this->User->firstname,
- 'lastname' => $this->User->lastname,
- 'email' => $this->User->email,
- 'token' => $chkToken
- );
- $activity_data = array(
- 'method' => $this->method,
- 'endpoint' => $this->endpoint,
- 'args' => $args,
- 'verb' => $verb,
- 'request' => $this->request
- );
- $this->DataInterface->auditLog($id_ray, $user_data, $activity_data);
- }
- }
- /**
- * Post:
- * /api/v1/mailer/send/ with data {from:from,to:to,subject:subject,message:message,apiKey:apiKey}
- */
- protected function mailer($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- switch($this->method) {
- case 'POST':
- if ($verb == 'send') {
- return $this->DataInterface->sendMail(
- $this->request['from'],
- $this->request['to'],
- $this->request['subject'],
- $this->request['message'],
- null
- );
- }
- else {
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * Put:
- * /api/v1/upload/?apiKey=
- */
- protected function upload($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = array();
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, array("newToken" => $chkToken));
- }
- }
- catch(Exception $e) {
- return array('result' => 'ERROR', 'reason' => 'denied');
- }
- switch($this->method) {
- case 'PUT':
- // Fetch content and determine boundary
- $raw_data = $this->file;
- $boundary = substr($raw_data, 0, strpos($raw_data, "\r\n"));
- // Fetch each part
- $parts = array_slice(explode($boundary, $raw_data), 1);
- $data = array();
- $files = array();
- foreach ($parts as $part) {
- // If this is the last part, break
- if ($part == "--\r\n") break;
- // Separate content from headers
- $part = ltrim($part, "\r\n");
- list($raw_headers, $body) = explode("\r\n\r\n", $part, 2);
- // Parse the headers list
- $raw_headers = explode("\r\n", $raw_headers);
- $headers = array();
- foreach ($raw_headers as $header) {
- list($name, $value) = explode(':', $header);
- $headers[strtolower($name)] = ltrim($value, ' ');
- }
- // Parse the Content-Disposition to get the field name, etc.
- if (isset($headers['content-disposition'])) {
- $filename = null;
- preg_match(
- '/^(.+); *name="([^"]+)"(; *filename="([^"]+)")?/',
- $headers['content-disposition'],
- $matches
- );
- list(, $type, $name) = $matches;
- isset($matches[4]) and $filename = $matches[4];
- $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
- $baseDir = $_SERVER['DOCUMENT_ROOT']."/storage/user";
- $filename = \Tools\UUID::v4().'.'.$ext;
- // handle your fields here
- switch ($name) {
- // this is a file upload
- case 'file':
- $ID = $this->User->ID;
- // Convert PDF
- if($ext == 'pdf') {
- $pdfFile = "$baseDir/$filename";
- file_put_contents($pdfFile, $body);
- $im = new \Imagick();
- $im->setResolution( 300, 300 );
- $im->readImage($pdfFile);
- $im->setImageFormat('jpeg');
- $im->setImageCompressionQuality(100);
- $num_pages = $im->getNumberImages();
- for($i = 0;$i < $num_pages; $i++) {
- // New filename
- $filename = \Tools\UUID::v4().'.jpg';
- $prefix = substr($filename, 0, 2);
- $baseDir = $_SERVER['DOCUMENT_ROOT']."/storage/user/$ID/image/$prefix";
- \Tools\FS::mkpath($baseDir);
- // Write file
- $im->setIteratorIndex($i);
- $files[] = $filename;
- $im->writeImage("$baseDir/$filename");
- }
- $im->clear();
- $im->destroy();
- // Delete PDF
- unlink($pdfFile);
- }
- // Store image directly
- else if(in_array($ext, array('jpeg', 'jpg', 'png'))) {
- // New filename
- $filename = \Tools\UUID::v4().'.'.$ext;
- $prefix = substr($filename, 0, 2);
- $baseDir = $_SERVER['DOCUMENT_ROOT']."/storage/user/$ID/image/$prefix";
- \Tools\FS::mkpath($baseDir);
- // Write file
- file_put_contents("$baseDir/$filename", $body);
- $files[] = $filename;
- }
- else {
- return array(
- 'result' => 'ERROR',
- 'reason' => 'invalid_input',
- 'message' => $ext
- );
- }
- break;
- // default for all other files is to populate $data
- default:
- $data[$name] = substr($body, 0, strlen($body) - 2);
- break;
- }
- }
- }
- return array_merge($resArray, array('result' => 'OK', 'files' => $files));
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- *
- */
- protected function admin_($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
-
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'signout':
- return $this->AdminInterface->adminLogout($this->User);
- case 'signin':
- return $this->AdminInterface->adminLogin($this->User, $args[0], $args[1]);
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- *
- */
- protected function admin($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = array();
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, array("newToken" => $chkToken));
- }
- }
- catch(Exception $e) {
- return array('result' => 'ERROR', 'reason' => 'denied');
- }
-
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'profile':
- return array_merge($resArray, $this->AdminInterface->adminProfileGet($this->User));
- case 'common':
- return array_merge($resArray, $this->AdminInterface->adminCommonGet($this->User));
- case 'credit':
- return array_merge($resArray, $this->AdminInterface->adminCreditGet($this->User, $args[0]));
- case 'customer':
- return array_merge($resArray, $this->AdminInterface->adminCustomerGet($this->User, $args[0]));
- case 'ctparams':
- return array_merge($resArray, $this->AdminInterface->adminCtParamsGet($this->User));
- case 'ctusers':
- return array_merge($resArray, $this->AdminInterface->adminCtUsersGet($this->User));
- case 'ctstats':
- return array_merge($resArray, $this->AdminInterface->adminCtStatsGet($this->User));
- case 'phystats':
- return array_merge($resArray, $this->AdminInterface->adminPhyStatsGet($this->User));
- case 'pacs':
- return array_merge($resArray, $this->AdminInterface->adminPacsGet($this->User, $args[0]));
- case 'export':
- return array_merge($resArray, $this->AdminInterface->adminExportGet($this->User));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'common':
- return array_merge($resArray, $this->AdminInterface->adminCommonPost($this->User, $this->request));
- case 'credit':
- return array_merge($resArray, $this->AdminInterface->adminCreditPost($this->User, $this->request));
- case 'customer':
- return array_merge($resArray, $this->AdminInterface->adminCustomerPost($this->User, $this->request));
- case 'pacs':
- return array_merge($resArray, $this->AdminInterface->adminPacsPost($this->User, $this->request));
- case 'echo':
- return array_merge($resArray, $this->AdminInterface->adminEchoPost($this->User, $this->request));
- case 'export':
- return array_merge($resArray, $this->AdminInterface->adminExportPost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
-
- /**
- *
- */
- protected function ct_admin_($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
-
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'signout':
- return $this->CtAdminInterface->ctAdminLogout($this->User);
- case 'signin':
- return $this->CtAdminInterface->ctAdminLogin($this->User, $args[0], $args[1]);
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- *
- */
- protected function ct_admin_account($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = array();
-
- switch($this->method) {
- case 'GET':
- switch($verb) {
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'password':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminPasswordPost($this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- *
- */
- protected function ct_admin($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = array();
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, array("newToken" => $chkToken));
- }
- }
- catch(Exception $e) {
- return array('result' => 'ERROR', 'reason' => 'denied');
- }
-
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'profile':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminProfileGet($this->User));
- case 'cros':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminCROsGet($this->User));
- case 'users':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminUsersGet($this->User, $args[0]));
- case 'centers':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminCentersGet($this->User));
- case 'settings':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminSettingsGet($this->User));
- case 'patients':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminPatientsGet($this->User, $args[0]));
- case 'investigators':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminInvestigatorsGet($this->User, $args[0]));
- case 'readers':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminReadersGet($this->User, $args[0]));
- case 'overview':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminOverviewGet($this->User, $args[0]));
- case 'visits':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminVisitsGet($this->User, $args[0]));
- case 'pacs':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminPacsGet($this->User));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'settings':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminSettingsPost($this->User, $this->request));
- case 'centers':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminCentersPost($this->User, $this->request));
- case 'users':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminUsersPost($this->User, $this->request));
- case 'cros':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminCROsPost($this->User, $this->request));
- case 'pacs':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminPacsPost($this->User, $this->request));
- case 'echo':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminEchoPost($this->User, $this->request));
- case 'auditlog':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminAuditLogPost($this->User, $this->request));
- case 'ecrf':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminAuditECRFPost($this->User, $this->request));
- case 'reader':
- return array_merge($resArray, $this->CtAdminInterface->ctAdminReaderPost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/profile/...
- */
- protected function profile($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = [];
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, ["newToken" => $chkToken]);
- }
- else {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- }
- catch(Exception $e) {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case '':
- return array_merge($resArray, $this->ProfileInterface->profileGet($this->User, $this->request['lang']));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case '':
- return array_merge($resArray, $this->ProfileInterface->profilePost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/home/...
- */
- protected function home($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = [];
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, ["newToken" => $chkToken]);
- }
- else {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- }
- catch(Exception $e) {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'export':
- return array_merge($resArray, $this->AdminInterface->exportByID($this->User->ID));
- case '':
- return array_merge($resArray, $this->HomeInterface->homeGet($this->User));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/patient/...
- */
- protected function patient($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = [];
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, ["newToken" => $chkToken]);
- }
- else {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- }
- catch(Exception $e) {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'files-existing':
- return array_merge($resArray, $this->PatientInterface->patientFilesExistingGet($this->User));
- case 'files-new':
- return array_merge($resArray, $this->PatientInterface->patientFilesNewGet($this->User, $this->request['lang']));
- case 'files-pacs':
- return array_merge($resArray, $this->PatientInterface->patientFilesPacsGet($this->User));
- case 'risks':
- return array_merge($resArray, $this->PatientInterface->patientRisksGet($this->User, $this->args[0]));
- case 'history':
- return array_merge($resArray, $this->PatientInterface->patientHistoryGet($this->User, $this->args[0], $this->args[1]));
- case 'family':
- return array_merge($resArray, $this->PatientInterface->patientFamilyGet($this->User, $this->args[0]));
- case 'examination':
- return array_merge($resArray, $this->PatientInterface->patientExaminationGet($this->User, $this->args[0]));
- case 'treatments':
- return array_merge($resArray, $this->PatientInterface->patientTreatmentsGet($this->User, $this->args[0]));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'create':
- return array_merge($resArray, $this->PatientInterface->patientCreatePost($this->User, $this->request));
- case 'create-visit':
- return array_merge($resArray, $this->PatientInterface->patientCreateVisitPost($this->User, $this->request));
- case 'context':
- return array_merge($resArray, $this->PatientInterface->patientContextPost($this->User, $this->request));
- case 'pacs-query':
- return array_merge($resArray, $this->PatientInterface->patientPacsQueryPost($this->User, $this->request));
- case 'pacs-retrieve':
- return array_merge($resArray, $this->PatientInterface->patientPacsRetrievePost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/report/...
- */
- protected function report($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = [];
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, ["newToken" => $chkToken]);
- }
- else {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- }
- catch(Exception $e) {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case '':
- return array_merge($resArray, $this->ReportInterface->reportGet($this->User, $this->args[0], $this->args[1]));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'mail-add':
- return array_merge($resArray, $this->ReportInterface->reportMailAddPost($this->User, $this->request));
- case 'mail-delete':
- return array_merge($resArray, $this->ReportInterface->reportMailDeletePost($this->User, $this->request));
- case 'pdf-download':
- return array_merge($resArray, $this->ReportInterface->reportPdfDownloadPost($this->User, $this->request));
- case 'pdf-pacs':
- return array_merge($resArray, $this->ReportInterface->reportPdfPACSPost($this->User, $this->request));
- case 'pdf-mail':
- return array_merge($resArray, $this->ReportInterface->reportPdfMailPost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/acquire/...
- */
- protected function acquire($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = [];
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, ["newToken" => $chkToken]);
- }
- else {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- }
- catch(Exception $e) {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'media':
- return array_merge($resArray, $this->AcquireInterface->acquireMediaGet($this->User, $this->args[0], $this->args[1]));
- case 'download':
- return array_merge($resArray, $this->AcquireInterface->acquireDownloadGet($this->User, $this->args[0], $this->args[1]));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'area':
- return array_merge($resArray, $this->AcquireInterface->acquireAreaPost($this->User, $this->request));
- case 'upload':
- return array_merge($resArray, $this->AcquireInterface->acquireUploadPost($this->User, $this->request));
- case 'lesion':
- return array_merge($resArray, $this->AcquireInterface->acquireLesionPost($this->User, $this->request));
- case 'lesionDelete':
- return array_merge($resArray, $this->AcquireInterface->acquireLesionDeletePost($this->User, $this->request));
- case 'media':
- return array_merge($resArray, $this->AcquireInterface->acquireMediaPost($this->User, $this->request));
- case 'delete':
- return array_merge($resArray, $this->AcquireInterface->acquireDeletePost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/measure/...
- */
- protected function measure($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- $resArray = [];
- try {
- $chkToken = $this->User->checkToken();
- if($chkToken !== false) {
- $resArray = array_merge($resArray, ["newToken" => $chkToken]);
- }
- else {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- }
- catch(Exception $e) {
- return ['result' => 'ERROR', 'reason' => 'denied'];
- }
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case '':
- return array_merge($resArray, $this->MeasureInterface->measureGet($this->User, $this->args[0], $this->args[1]));
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'calibration':
- return array_merge($resArray, $this->MeasureInterface->measureCalibrationPost($this->User, $this->request));
- case 'distance':
- return array_merge($resArray, $this->MeasureInterface->measureDistancePost($this->User, $this->request));
- case 'area':
- return array_merge($resArray, $this->MeasureInterface->measureAreaPost($this->User, $this->request));
- case 'imt':
- return array_merge($resArray, $this->MeasureInterface->measureImtPost($this->User, $this->request));
- case 'plaque':
- return array_merge($resArray, $this->MeasureInterface->measurePlaquePost($this->User, $this->request));
- case 'complete':
- return array_merge($resArray, $this->MeasureInterface->measureCompletePost($this->User, $this->request));
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
- /**
- * /api/v1/account/...
- */
- protected function account($args, $verb) {
- if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
- throw new Exception('Permission denied.');
- switch($this->method) {
- case 'GET':
- switch($verb) {
- case 'signup':
- return $this->AccountInterface->accountSignupGet($this->request['lang']);
- case 'activate':
- return $this->AccountInterface->accountActivateGet($this->request['activation_token']);
- case 'signout':
- return $this->AccountInterface->accountLogoutGet($this->User);
- default:
- throw new Exception('Not implemented.');
- }
- case 'POST':
- switch($verb) {
- case 'signup':
- return $this->AccountInterface->accountSignupPost($this->request);
- case 'signin':
- return $this->AccountInterface->accountSigninPost($this->User, $this->request);
- case 'reset':
- return $this->AccountInterface->accountResetPost($this->request);
- case 'reset2':
- return $this->AccountInterface->accountReset2Post($this->request);
- default:
- throw new Exception('Not implemented.');
- }
- default:
- throw new Exception('Not implemented.');
- }
- }
-
- }
- ?>
|