New Http Rest Client (#2023)
[openemr.git] / rest_controllers / DocumentRestController.php
blob01dac8017da58aacf3e264c2e1f9f3858543c37f
1 <?php
2 /**
3 * DocumentRestController
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Matthew Vita <matthewvita48@gmail.com>
8 * @copyright Copyright (c) 2018 Matthew Vita <matthewvita48@gmail.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\RestControllers;
15 use OpenEMR\Services\DocumentService;
16 use OpenEMR\RestControllers\RestControllerHelper;
18 class DocumentRestController
20 private $documentService;
22 public function __construct()
24 $this->documentService = new DocumentService();
27 public function getAllAtPath($pid, $path)
29 $serviceResult = $this->documentService->getAllAtPath($pid, $path);
30 return RestControllerHelper::responseHandler($serviceResult, null, 200);
33 public function postWithPath($pid, $path, $fileData)
35 $serviceResult = $this->documentService->insertAtPath($pid, $path, $fileData);
36 return RestControllerHelper::responseHandler($serviceResult, null, 200);
39 public function downloadFile($pid, $did)
41 $results = $this->documentService->getFile($pid, $did);
42 $file = $results['url'];
43 if (file_exists($file)) {
44 header('Content-Description: File Transfer');
45 header('Content-Type: application/octet-stream');
46 header("Content-Type: application/force-download");
47 header('Content-Disposition: attachment; filename=' . urlencode(basename($file)));
48 header('Expires: 0');
49 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
50 header('Pragma: public');
51 header('Content-Length: ' . filesize($file));
52 ob_clean();
53 flush();
54 readfile($file);
55 exit;
56 } else {
57 http_response_code(400);