3 * DocumentRestController
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)));
49 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
50 header('Pragma: public');
51 header('Content-Length: ' . filesize($file));
57 http_response_code(400);