IIMTAPI.class.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. <?php
  2. require_once 'API.class.php';
  3. require_once 'Config/Settings.class.php';
  4. require_once 'Tools/UUID.class.php';
  5. require_once 'Models/APIKey.class.php';
  6. require_once 'Models/User.class.php';
  7. require_once 'Models/DataInterface.class.php';
  8. require_once 'Models/AccountInterface.class.php';
  9. require_once 'Models/HomeInterface.class.php';
  10. require_once 'Models/ProfileInterface.class.php';
  11. require_once 'Models/PatientInterface.class.php';
  12. require_once 'Models/AcquireInterface.class.php';
  13. require_once 'Models/ReportInterface.class.php';
  14. require_once 'Models/MeasureInterface.class.php';
  15. require_once 'Models/AdminInterface.class.php';
  16. require_once 'Models/CtAdminInterface.class.php';
  17. require_once 'External/PHP-JWT/src/JWT.php';
  18. require_once 'External/PHP-JWT/src/ExpiredException.php';
  19. require_once 'External/PHP-JWT/src/BeforeValidException.php';
  20. require_once 'External/PHP-JWT/src/SignatureInvalidException.php';
  21. class IIMTAPI extends API {
  22. //
  23. protected $User;
  24. protected $APIKey;
  25. protected $DataInterface;
  26. protected $AdminInterface;
  27. protected $AccountInterface;
  28. protected $ProfileInterface;
  29. protected $HomeInterface;
  30. protected $AcquireInterface;
  31. protected $ReportInterface;
  32. //protected $Broker;
  33. /**
  34. *
  35. */
  36. public function __construct($request, $origin) {
  37. parent::__construct($request);
  38. $this->APIKey = new Models\APIKey();
  39. $this->User = new Models\User();
  40. if (!array_key_exists('apiKey', $this->request)) {
  41. throw new Exception('No API Key provided');
  42. }
  43. else if (!$this->APIKey->verifyKey($this->request['apiKey'], $origin)) {
  44. throw new Exception('Invalid API Key');
  45. }
  46. try {
  47. $this->DataInterface = new Models\DataInterface();
  48. $this->AdminInterface = new Models\AdminInterface($this->DataInterface);
  49. $this->CtAdminInterface = new Models\CtAdminInterface($this->DataInterface);
  50. $this->AccountInterface = new Models\AccountInterface($this->DataInterface);
  51. $this->HomeInterface = new Models\HomeInterface($this->DataInterface);
  52. $this->ProfileInterface = new Models\ProfileInterface($this->DataInterface);
  53. $this->PatientInterface = new Models\PatientInterface($this->DataInterface);
  54. $this->AcquireInterface = new Models\AcquireInterface($this->DataInterface);
  55. $this->ReportInterface = new Models\ReportInterface($this->DataInterface);
  56. $this->MeasureInterface = new Models\MeasureInterface($this->DataInterface);
  57. }
  58. catch (Exception $e) {
  59. throw $e;
  60. }
  61. }
  62. /**
  63. * Get:
  64. * /api/v1/test/?apiKey=
  65. */
  66. protected function test($args, $verb) {
  67. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  68. throw new Exception('Permission denied.');
  69. switch($this->method) {
  70. case 'GET':
  71. return $this->DataInterface->test();
  72. default:
  73. throw new Exception('Not implemented.');
  74. }
  75. }
  76. /**
  77. *
  78. */
  79. protected function ray($args, $verb) {
  80. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) ) {
  81. throw new Exception('Permission denied.');
  82. }
  83. if($this->method != 'POST') {
  84. throw new Exception('Not implemented.');
  85. }
  86. // ray
  87. $headers = getallheaders();
  88. $id_ray = 0;
  89. if(array_key_exists('RayID', $headers)) {
  90. $id_ray = $headers['RayID'];
  91. }
  92. // ip
  93. $ip = $_SERVER['REMOTE_ADDR'];
  94. $ip_type = 'direct';
  95. if(array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
  96. $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  97. $ip_type = 'x_forwarded_for';
  98. }
  99. if($ip == '::1') {
  100. $ip = '';
  101. $ip_type = 'localhost';
  102. }
  103. $ip_data = array(
  104. 'ip' => $ip,
  105. 'type' => $ip_type
  106. );
  107. // location
  108. try {
  109. if($ip_type=='localhost') {
  110. $location_data = json_decode(file_get_contents("http://www.geoplugin.net/json.gp"));
  111. }
  112. else {
  113. $location_data = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=$ip"));
  114. }
  115. $location_data = array(
  116. 'city' => $location_data->geoplugin_city,
  117. 'continentCode' => $location_data->geoplugin_continentCode,
  118. 'continentName' => $location_data->geoplugin_continentName,
  119. 'countryCode' => $location_data->geoplugin_countryCode,
  120. 'countryName' => $location_data->geoplugin_countryName,
  121. 'currencyCode' => $location_data->geoplugin_currencyCode,
  122. 'latitude' => $location_data->geoplugin_latitude,
  123. 'longitude' => $location_data->geoplugin_longitude,
  124. 'timezone' => $location_data->geoplugin_timezone,
  125. 'request' => $location_data->geoplugin_request
  126. );
  127. }
  128. catch(Exception $e) {
  129. $location_data = [];
  130. }
  131. // store
  132. if($id_ray != 0) {
  133. $result = $this->DataInterface->rayUpdate(
  134. $id_ray,
  135. $this->request['userAgent'],
  136. $this->request['apiKey'],
  137. $ip_data,
  138. $location_data
  139. );
  140. }
  141. else {
  142. $result = $this->DataInterface->rayCreate(
  143. $this->request['userAgent'],
  144. $this->request['apiKey'],
  145. $ip_data,
  146. $location_data
  147. );
  148. }
  149. $result['country'] = $location_data['countryCode'];
  150. return $result;
  151. }
  152. /**
  153. *
  154. */
  155. protected function log($args, $verb) {
  156. // ray
  157. $headers = getallheaders();
  158. $id_ray = 0;
  159. if(array_key_exists('RayID', $headers)) {
  160. $id_ray = $headers['RayID'];
  161. try {
  162. $chkToken = $this->User->checkToken();
  163. }
  164. catch(Exception $e) {
  165. $chkToken = 'denied';
  166. }
  167. $user_data = array(
  168. 'ID' => $this->User->ID,
  169. 'firstname' => $this->User->firstname,
  170. 'lastname' => $this->User->lastname,
  171. 'email' => $this->User->email,
  172. 'token' => $chkToken
  173. );
  174. $activity_data = array(
  175. 'method' => $this->method,
  176. 'endpoint' => $this->endpoint,
  177. 'args' => $args,
  178. 'verb' => $verb,
  179. 'request' => $this->request
  180. );
  181. $this->DataInterface->auditLog($id_ray, $user_data, $activity_data);
  182. }
  183. }
  184. /**
  185. * Post:
  186. * /api/v1/mailer/send/ with data {from:from,to:to,subject:subject,message:message,apiKey:apiKey}
  187. */
  188. protected function mailer($args, $verb) {
  189. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  190. throw new Exception('Permission denied.');
  191. switch($this->method) {
  192. case 'POST':
  193. if ($verb == 'send') {
  194. return $this->DataInterface->sendMail(
  195. $this->request['from'],
  196. $this->request['to'],
  197. $this->request['subject'],
  198. $this->request['message'],
  199. null
  200. );
  201. }
  202. else {
  203. throw new Exception('Not implemented.');
  204. }
  205. default:
  206. throw new Exception('Not implemented.');
  207. }
  208. }
  209. /**
  210. * Put:
  211. * /api/v1/upload/?apiKey=
  212. */
  213. protected function upload($args, $verb) {
  214. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  215. throw new Exception('Permission denied.');
  216. $resArray = array();
  217. try {
  218. $chkToken = $this->User->checkToken();
  219. if($chkToken !== false) {
  220. $resArray = array_merge($resArray, array("newToken" => $chkToken));
  221. }
  222. }
  223. catch(Exception $e) {
  224. return array('result' => 'ERROR', 'reason' => 'denied');
  225. }
  226. switch($this->method) {
  227. case 'PUT':
  228. // Fetch content and determine boundary
  229. $raw_data = $this->file;
  230. $boundary = substr($raw_data, 0, strpos($raw_data, "\r\n"));
  231. // Fetch each part
  232. $parts = array_slice(explode($boundary, $raw_data), 1);
  233. $data = array();
  234. $files = array();
  235. foreach ($parts as $part) {
  236. // If this is the last part, break
  237. if ($part == "--\r\n") break;
  238. // Separate content from headers
  239. $part = ltrim($part, "\r\n");
  240. list($raw_headers, $body) = explode("\r\n\r\n", $part, 2);
  241. // Parse the headers list
  242. $raw_headers = explode("\r\n", $raw_headers);
  243. $headers = array();
  244. foreach ($raw_headers as $header) {
  245. list($name, $value) = explode(':', $header);
  246. $headers[strtolower($name)] = ltrim($value, ' ');
  247. }
  248. // Parse the Content-Disposition to get the field name, etc.
  249. if (isset($headers['content-disposition'])) {
  250. $filename = null;
  251. preg_match(
  252. '/^(.+); *name="([^"]+)"(; *filename="([^"]+)")?/',
  253. $headers['content-disposition'],
  254. $matches
  255. );
  256. list(, $type, $name) = $matches;
  257. isset($matches[4]) and $filename = $matches[4];
  258. $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
  259. $baseDir = $_SERVER['DOCUMENT_ROOT']."/storage/user";
  260. $filename = \Tools\UUID::v4().'.'.$ext;
  261. // handle your fields here
  262. switch ($name) {
  263. // this is a file upload
  264. case 'file':
  265. $ID = $this->User->ID;
  266. // Convert PDF
  267. if($ext == 'pdf') {
  268. $pdfFile = "$baseDir/$filename";
  269. file_put_contents($pdfFile, $body);
  270. $im = new \Imagick();
  271. $im->setResolution( 300, 300 );
  272. $im->readImage($pdfFile);
  273. $im->setImageFormat('jpeg');
  274. $im->setImageCompressionQuality(100);
  275. $num_pages = $im->getNumberImages();
  276. for($i = 0;$i < $num_pages; $i++) {
  277. // New filename
  278. $filename = \Tools\UUID::v4().'.jpg';
  279. $prefix = substr($filename, 0, 2);
  280. $baseDir = $_SERVER['DOCUMENT_ROOT']."/storage/user/$ID/image/$prefix";
  281. \Tools\FS::mkpath($baseDir);
  282. // Write file
  283. $im->setIteratorIndex($i);
  284. $files[] = $filename;
  285. $im->writeImage("$baseDir/$filename");
  286. }
  287. $im->clear();
  288. $im->destroy();
  289. // Delete PDF
  290. unlink($pdfFile);
  291. }
  292. // Store image directly
  293. else if(in_array($ext, array('jpeg', 'jpg', 'png'))) {
  294. // New filename
  295. $filename = \Tools\UUID::v4().'.'.$ext;
  296. $prefix = substr($filename, 0, 2);
  297. $baseDir = $_SERVER['DOCUMENT_ROOT']."/storage/user/$ID/image/$prefix";
  298. \Tools\FS::mkpath($baseDir);
  299. // Write file
  300. file_put_contents("$baseDir/$filename", $body);
  301. $files[] = $filename;
  302. }
  303. else {
  304. return array(
  305. 'result' => 'ERROR',
  306. 'reason' => 'invalid_input',
  307. 'message' => $ext
  308. );
  309. }
  310. break;
  311. // default for all other files is to populate $data
  312. default:
  313. $data[$name] = substr($body, 0, strlen($body) - 2);
  314. break;
  315. }
  316. }
  317. }
  318. return array_merge($resArray, array('result' => 'OK', 'files' => $files));
  319. default:
  320. throw new Exception('Not implemented.');
  321. }
  322. }
  323. /**
  324. *
  325. */
  326. protected function admin_($args, $verb) {
  327. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  328. throw new Exception('Permission denied.');
  329. switch($this->method) {
  330. case 'GET':
  331. switch($verb) {
  332. case 'signout':
  333. return $this->AdminInterface->adminLogout($this->User);
  334. case 'signin':
  335. return $this->AdminInterface->adminLogin($this->User, $args[0], $args[1]);
  336. default:
  337. throw new Exception('Not implemented.');
  338. }
  339. default:
  340. throw new Exception('Not implemented.');
  341. }
  342. }
  343. /**
  344. *
  345. */
  346. protected function admin($args, $verb) {
  347. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  348. throw new Exception('Permission denied.');
  349. $resArray = array();
  350. try {
  351. $chkToken = $this->User->checkToken();
  352. if($chkToken !== false) {
  353. $resArray = array_merge($resArray, array("newToken" => $chkToken));
  354. }
  355. }
  356. catch(Exception $e) {
  357. return array('result' => 'ERROR', 'reason' => 'denied');
  358. }
  359. switch($this->method) {
  360. case 'GET':
  361. switch($verb) {
  362. case 'profile':
  363. return array_merge($resArray, $this->AdminInterface->adminProfileGet($this->User));
  364. case 'common':
  365. return array_merge($resArray, $this->AdminInterface->adminCommonGet($this->User));
  366. case 'credit':
  367. return array_merge($resArray, $this->AdminInterface->adminCreditGet($this->User, $args[0]));
  368. case 'customer':
  369. return array_merge($resArray, $this->AdminInterface->adminCustomerGet($this->User, $args[0]));
  370. case 'ctparams':
  371. return array_merge($resArray, $this->AdminInterface->adminCtParamsGet($this->User));
  372. case 'ctusers':
  373. return array_merge($resArray, $this->AdminInterface->adminCtUsersGet($this->User));
  374. case 'ctstats':
  375. return array_merge($resArray, $this->AdminInterface->adminCtStatsGet($this->User));
  376. case 'phystats':
  377. return array_merge($resArray, $this->AdminInterface->adminPhyStatsGet($this->User));
  378. case 'pacs':
  379. return array_merge($resArray, $this->AdminInterface->adminPacsGet($this->User, $args[0]));
  380. case 'export':
  381. return array_merge($resArray, $this->AdminInterface->adminExportGet($this->User));
  382. default:
  383. throw new Exception('Not implemented.');
  384. }
  385. case 'POST':
  386. switch($verb) {
  387. case 'common':
  388. return array_merge($resArray, $this->AdminInterface->adminCommonPost($this->User, $this->request));
  389. case 'credit':
  390. return array_merge($resArray, $this->AdminInterface->adminCreditPost($this->User, $this->request));
  391. case 'customer':
  392. return array_merge($resArray, $this->AdminInterface->adminCustomerPost($this->User, $this->request));
  393. case 'pacs':
  394. return array_merge($resArray, $this->AdminInterface->adminPacsPost($this->User, $this->request));
  395. case 'echo':
  396. return array_merge($resArray, $this->AdminInterface->adminEchoPost($this->User, $this->request));
  397. case 'export':
  398. return array_merge($resArray, $this->AdminInterface->adminExportPost($this->User, $this->request));
  399. default:
  400. throw new Exception('Not implemented.');
  401. }
  402. default:
  403. throw new Exception('Not implemented.');
  404. }
  405. }
  406. /**
  407. *
  408. */
  409. protected function ct_admin_($args, $verb) {
  410. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  411. throw new Exception('Permission denied.');
  412. switch($this->method) {
  413. case 'GET':
  414. switch($verb) {
  415. case 'signout':
  416. return $this->CtAdminInterface->ctAdminLogout($this->User);
  417. case 'signin':
  418. return $this->CtAdminInterface->ctAdminLogin($this->User, $args[0], $args[1]);
  419. default:
  420. throw new Exception('Not implemented.');
  421. }
  422. default:
  423. throw new Exception('Not implemented.');
  424. }
  425. }
  426. /**
  427. *
  428. */
  429. protected function ct_admin_account($args, $verb) {
  430. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  431. throw new Exception('Permission denied.');
  432. $resArray = array();
  433. switch($this->method) {
  434. case 'GET':
  435. switch($verb) {
  436. default:
  437. throw new Exception('Not implemented.');
  438. }
  439. case 'POST':
  440. switch($verb) {
  441. case 'password':
  442. return array_merge($resArray, $this->CtAdminInterface->ctAdminPasswordPost($this->request));
  443. default:
  444. throw new Exception('Not implemented.');
  445. }
  446. default:
  447. throw new Exception('Not implemented.');
  448. }
  449. }
  450. /**
  451. *
  452. */
  453. protected function ct_admin($args, $verb) {
  454. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  455. throw new Exception('Permission denied.');
  456. $resArray = array();
  457. try {
  458. $chkToken = $this->User->checkToken();
  459. if($chkToken !== false) {
  460. $resArray = array_merge($resArray, array("newToken" => $chkToken));
  461. }
  462. }
  463. catch(Exception $e) {
  464. return array('result' => 'ERROR', 'reason' => 'denied');
  465. }
  466. switch($this->method) {
  467. case 'GET':
  468. switch($verb) {
  469. case 'profile':
  470. return array_merge($resArray, $this->CtAdminInterface->ctAdminProfileGet($this->User));
  471. case 'cros':
  472. return array_merge($resArray, $this->CtAdminInterface->ctAdminCROsGet($this->User));
  473. case 'users':
  474. return array_merge($resArray, $this->CtAdminInterface->ctAdminUsersGet($this->User, $args[0]));
  475. case 'centers':
  476. return array_merge($resArray, $this->CtAdminInterface->ctAdminCentersGet($this->User));
  477. case 'settings':
  478. return array_merge($resArray, $this->CtAdminInterface->ctAdminSettingsGet($this->User));
  479. case 'patients':
  480. return array_merge($resArray, $this->CtAdminInterface->ctAdminPatientsGet($this->User, $args[0]));
  481. case 'investigators':
  482. return array_merge($resArray, $this->CtAdminInterface->ctAdminInvestigatorsGet($this->User, $args[0]));
  483. case 'readers':
  484. return array_merge($resArray, $this->CtAdminInterface->ctAdminReadersGet($this->User, $args[0]));
  485. case 'overview':
  486. return array_merge($resArray, $this->CtAdminInterface->ctAdminOverviewGet($this->User, $args[0]));
  487. case 'visits':
  488. return array_merge($resArray, $this->CtAdminInterface->ctAdminVisitsGet($this->User, $args[0]));
  489. case 'pacs':
  490. return array_merge($resArray, $this->CtAdminInterface->ctAdminPacsGet($this->User));
  491. default:
  492. throw new Exception('Not implemented.');
  493. }
  494. case 'POST':
  495. switch($verb) {
  496. case 'settings':
  497. return array_merge($resArray, $this->CtAdminInterface->ctAdminSettingsPost($this->User, $this->request));
  498. case 'centers':
  499. return array_merge($resArray, $this->CtAdminInterface->ctAdminCentersPost($this->User, $this->request));
  500. case 'users':
  501. return array_merge($resArray, $this->CtAdminInterface->ctAdminUsersPost($this->User, $this->request));
  502. case 'cros':
  503. return array_merge($resArray, $this->CtAdminInterface->ctAdminCROsPost($this->User, $this->request));
  504. case 'pacs':
  505. return array_merge($resArray, $this->CtAdminInterface->ctAdminPacsPost($this->User, $this->request));
  506. case 'echo':
  507. return array_merge($resArray, $this->CtAdminInterface->ctAdminEchoPost($this->User, $this->request));
  508. case 'auditlog':
  509. return array_merge($resArray, $this->CtAdminInterface->ctAdminAuditLogPost($this->User, $this->request));
  510. case 'ecrf':
  511. return array_merge($resArray, $this->CtAdminInterface->ctAdminAuditECRFPost($this->User, $this->request));
  512. case 'reader':
  513. return array_merge($resArray, $this->CtAdminInterface->ctAdminReaderPost($this->User, $this->request));
  514. default:
  515. throw new Exception('Not implemented.');
  516. }
  517. default:
  518. throw new Exception('Not implemented.');
  519. }
  520. }
  521. /**
  522. * /api/v1/profile/...
  523. */
  524. protected function profile($args, $verb) {
  525. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  526. throw new Exception('Permission denied.');
  527. $resArray = [];
  528. try {
  529. $chkToken = $this->User->checkToken();
  530. if($chkToken !== false) {
  531. $resArray = array_merge($resArray, ["newToken" => $chkToken]);
  532. }
  533. else {
  534. return ['result' => 'ERROR', 'reason' => 'denied'];
  535. }
  536. }
  537. catch(Exception $e) {
  538. return ['result' => 'ERROR', 'reason' => 'denied'];
  539. }
  540. switch($this->method) {
  541. case 'GET':
  542. switch($verb) {
  543. case '':
  544. return array_merge($resArray, $this->ProfileInterface->profileGet($this->User, $this->request['lang']));
  545. default:
  546. throw new Exception('Not implemented.');
  547. }
  548. case 'POST':
  549. switch($verb) {
  550. case '':
  551. return array_merge($resArray, $this->ProfileInterface->profilePost($this->User, $this->request));
  552. default:
  553. throw new Exception('Not implemented.');
  554. }
  555. default:
  556. throw new Exception('Not implemented.');
  557. }
  558. }
  559. /**
  560. * /api/v1/home/...
  561. */
  562. protected function home($args, $verb) {
  563. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  564. throw new Exception('Permission denied.');
  565. $resArray = [];
  566. try {
  567. $chkToken = $this->User->checkToken();
  568. if($chkToken !== false) {
  569. $resArray = array_merge($resArray, ["newToken" => $chkToken]);
  570. }
  571. else {
  572. return ['result' => 'ERROR', 'reason' => 'denied'];
  573. }
  574. }
  575. catch(Exception $e) {
  576. return ['result' => 'ERROR', 'reason' => 'denied'];
  577. }
  578. switch($this->method) {
  579. case 'GET':
  580. switch($verb) {
  581. case 'export':
  582. return array_merge($resArray, $this->AdminInterface->exportByID($this->User->ID));
  583. case '':
  584. return array_merge($resArray, $this->HomeInterface->homeGet($this->User));
  585. default:
  586. throw new Exception('Not implemented.');
  587. }
  588. case 'POST':
  589. switch($verb) {
  590. default:
  591. throw new Exception('Not implemented.');
  592. }
  593. default:
  594. throw new Exception('Not implemented.');
  595. }
  596. }
  597. /**
  598. * /api/v1/patient/...
  599. */
  600. protected function patient($args, $verb) {
  601. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  602. throw new Exception('Permission denied.');
  603. $resArray = [];
  604. try {
  605. $chkToken = $this->User->checkToken();
  606. if($chkToken !== false) {
  607. $resArray = array_merge($resArray, ["newToken" => $chkToken]);
  608. }
  609. else {
  610. return ['result' => 'ERROR', 'reason' => 'denied'];
  611. }
  612. }
  613. catch(Exception $e) {
  614. return ['result' => 'ERROR', 'reason' => 'denied'];
  615. }
  616. switch($this->method) {
  617. case 'GET':
  618. switch($verb) {
  619. case 'files-existing':
  620. return array_merge($resArray, $this->PatientInterface->patientFilesExistingGet($this->User));
  621. case 'files-new':
  622. return array_merge($resArray, $this->PatientInterface->patientFilesNewGet($this->User, $this->request['lang']));
  623. case 'files-pacs':
  624. return array_merge($resArray, $this->PatientInterface->patientFilesPacsGet($this->User));
  625. case 'risks':
  626. return array_merge($resArray, $this->PatientInterface->patientRisksGet($this->User, $this->args[0]));
  627. case 'history':
  628. return array_merge($resArray, $this->PatientInterface->patientHistoryGet($this->User, $this->args[0], $this->args[1]));
  629. case 'family':
  630. return array_merge($resArray, $this->PatientInterface->patientFamilyGet($this->User, $this->args[0]));
  631. case 'examination':
  632. return array_merge($resArray, $this->PatientInterface->patientExaminationGet($this->User, $this->args[0]));
  633. case 'treatments':
  634. return array_merge($resArray, $this->PatientInterface->patientTreatmentsGet($this->User, $this->args[0]));
  635. default:
  636. throw new Exception('Not implemented.');
  637. }
  638. case 'POST':
  639. switch($verb) {
  640. case 'files-existing':
  641. return array_merge($resArray, $this->PatientInterface->patientFilesExistingPost($this->User, $this->request));
  642. case 'create':
  643. return array_merge($resArray, $this->PatientInterface->patientCreatePost($this->User, $this->request));
  644. case 'create-visit':
  645. return array_merge($resArray, $this->PatientInterface->patientCreateVisitPost($this->User, $this->request));
  646. case 'context':
  647. return array_merge($resArray, $this->PatientInterface->patientContextPost($this->User, $this->request));
  648. case 'pacs-query':
  649. return array_merge($resArray, $this->PatientInterface->patientPacsQueryPost($this->User, $this->request));
  650. case 'pacs-retrieve':
  651. return array_merge($resArray, $this->PatientInterface->patientPacsRetrievePost($this->User, $this->request));
  652. default:
  653. throw new Exception('Not implemented.');
  654. }
  655. default:
  656. throw new Exception('Not implemented.');
  657. }
  658. }
  659. /**
  660. * /api/v1/report/...
  661. */
  662. protected function report($args, $verb) {
  663. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  664. throw new Exception('Permission denied.');
  665. $resArray = [];
  666. try {
  667. $chkToken = $this->User->checkToken();
  668. if($chkToken !== false) {
  669. $resArray = array_merge($resArray, ["newToken" => $chkToken]);
  670. }
  671. else {
  672. return ['result' => 'ERROR', 'reason' => 'denied'];
  673. }
  674. }
  675. catch(Exception $e) {
  676. return ['result' => 'ERROR', 'reason' => 'denied'];
  677. }
  678. switch($this->method) {
  679. case 'GET':
  680. switch($verb) {
  681. case '':
  682. return array_merge($resArray, $this->ReportInterface->reportGet($this->User, $this->args[0], $this->args[1]));
  683. default:
  684. throw new Exception('Not implemented.');
  685. }
  686. case 'POST':
  687. switch($verb) {
  688. case 'mail-add':
  689. return array_merge($resArray, $this->ReportInterface->reportMailAddPost($this->User, $this->request));
  690. case 'mail-delete':
  691. return array_merge($resArray, $this->ReportInterface->reportMailDeletePost($this->User, $this->request));
  692. case 'pdf-download':
  693. return array_merge($resArray, $this->ReportInterface->reportPdfDownloadPost($this->User, $this->request));
  694. case 'pdf-pacs':
  695. return array_merge($resArray, $this->ReportInterface->reportPdfPACSPost($this->User, $this->request));
  696. case 'pdf-mail':
  697. return array_merge($resArray, $this->ReportInterface->reportPdfMailPost($this->User, $this->request));
  698. default:
  699. throw new Exception('Not implemented.');
  700. }
  701. default:
  702. throw new Exception('Not implemented.');
  703. }
  704. }
  705. /**
  706. * /api/v1/acquire/...
  707. */
  708. protected function acquire($args, $verb) {
  709. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  710. throw new Exception('Permission denied.');
  711. $resArray = [];
  712. try {
  713. $chkToken = $this->User->checkToken();
  714. if($chkToken !== false) {
  715. $resArray = array_merge($resArray, ["newToken" => $chkToken]);
  716. }
  717. else {
  718. return ['result' => 'ERROR', 'reason' => 'denied'];
  719. }
  720. }
  721. catch(Exception $e) {
  722. return ['result' => 'ERROR', 'reason' => 'denied'];
  723. }
  724. switch($this->method) {
  725. case 'GET':
  726. switch($verb) {
  727. case 'media':
  728. return array_merge($resArray, $this->AcquireInterface->acquireMediaGet($this->User, $this->args[0], $this->args[1]));
  729. case 'download':
  730. return array_merge($resArray, $this->AcquireInterface->acquireDownloadGet($this->User, $this->args[0], $this->args[1]));
  731. default:
  732. throw new Exception('Not implemented.');
  733. }
  734. case 'POST':
  735. switch($verb) {
  736. case 'area':
  737. return array_merge($resArray, $this->AcquireInterface->acquireAreaPost($this->User, $this->request));
  738. case 'upload':
  739. return array_merge($resArray, $this->AcquireInterface->acquireUploadPost($this->User, $this->request));
  740. case 'lesion':
  741. return array_merge($resArray, $this->AcquireInterface->acquireLesionPost($this->User, $this->request));
  742. case 'lesionDelete':
  743. return array_merge($resArray, $this->AcquireInterface->acquireLesionDeletePost($this->User, $this->request));
  744. case 'media':
  745. return array_merge($resArray, $this->AcquireInterface->acquireMediaPost($this->User, $this->request));
  746. case 'delete':
  747. return array_merge($resArray, $this->AcquireInterface->acquireDeletePost($this->User, $this->request));
  748. default:
  749. throw new Exception('Not implemented.');
  750. }
  751. default:
  752. throw new Exception('Not implemented.');
  753. }
  754. }
  755. /**
  756. * /api/v1/measure/...
  757. */
  758. protected function measure($args, $verb) {
  759. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  760. throw new Exception('Permission denied.');
  761. $resArray = [];
  762. try {
  763. $chkToken = $this->User->checkToken();
  764. if($chkToken !== false) {
  765. $resArray = array_merge($resArray, ["newToken" => $chkToken]);
  766. }
  767. else {
  768. return ['result' => 'ERROR', 'reason' => 'denied'];
  769. }
  770. }
  771. catch(Exception $e) {
  772. return ['result' => 'ERROR', 'reason' => 'denied'];
  773. }
  774. switch($this->method) {
  775. case 'GET':
  776. switch($verb) {
  777. case '':
  778. return array_merge($resArray, $this->MeasureInterface->measureGet($this->User, $this->args[0], $this->args[1]));
  779. default:
  780. throw new Exception('Not implemented.');
  781. }
  782. case 'POST':
  783. switch($verb) {
  784. case 'calibration':
  785. return array_merge($resArray, $this->MeasureInterface->measureCalibrationPost($this->User, $this->request));
  786. case 'distance':
  787. return array_merge($resArray, $this->MeasureInterface->measureDistancePost($this->User, $this->request));
  788. case 'area':
  789. return array_merge($resArray, $this->MeasureInterface->measureAreaPost($this->User, $this->request));
  790. case 'imt':
  791. return array_merge($resArray, $this->MeasureInterface->measureImtPost($this->User, $this->request));
  792. case 'plaque':
  793. return array_merge($resArray, $this->MeasureInterface->measurePlaquePost($this->User, $this->request));
  794. case 'complete':
  795. return array_merge($resArray, $this->MeasureInterface->measureCompletePost($this->User, $this->request));
  796. default:
  797. throw new Exception('Not implemented.');
  798. }
  799. default:
  800. throw new Exception('Not implemented.');
  801. }
  802. }
  803. /**
  804. * /api/v1/account/...
  805. */
  806. protected function account($args, $verb) {
  807. if( !$this->APIKey->isGranted(__FUNCTION__, $this->method) )
  808. throw new Exception('Permission denied.');
  809. switch($this->method) {
  810. case 'GET':
  811. switch($verb) {
  812. case 'signup':
  813. return $this->AccountInterface->accountSignupGet($this->request['lang']);
  814. case 'activate':
  815. return $this->AccountInterface->accountActivateGet($this->request['activation_token']);
  816. case 'signout':
  817. return $this->AccountInterface->accountLogoutGet($this->User);
  818. default:
  819. throw new Exception('Not implemented.');
  820. }
  821. case 'POST':
  822. switch($verb) {
  823. case 'signup':
  824. return $this->AccountInterface->accountSignupPost($this->request);
  825. case 'signin':
  826. return $this->AccountInterface->accountSigninPost($this->User, $this->request);
  827. case 'reset':
  828. return $this->AccountInterface->accountResetPost($this->request);
  829. case 'reset2':
  830. return $this->AccountInterface->accountReset2Post($this->request);
  831. default:
  832. throw new Exception('Not implemented.');
  833. }
  834. default:
  835. throw new Exception('Not implemented.');
  836. }
  837. }
  838. }
  839. ?>