forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 13
/
DocumentRestController.php
57 lines (48 loc) · 1.73 KB
/
DocumentRestController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* DocumentRestController
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <[email protected]>
* @copyright Copyright (c) 2018 Matthew Vita <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\Services\DocumentService;
use OpenEMR\RestControllers\RestControllerHelper;
class DocumentRestController
{
private $documentService;
public function __construct()
{
$this->documentService = new DocumentService();
}
public function getAllAtPath($pid, $path)
{
$serviceResult = $this->documentService->getAllAtPath($pid, $path);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function postWithPath($pid, $path, $fileData)
{
$serviceResult = $this->documentService->insertAtPath($pid, $path, $fileData);
return RestControllerHelper::responseHandler($serviceResult, null, 200);
}
public function downloadFile($pid, $did)
{
$results = $this->documentService->getFile($pid, $did);
if (!empty($results)) {
header('Content-Description: File Transfer');
header("Content-Type: " . $results['mimetype']);
header('Content-Disposition: attachment; filename=' . $results['filename']);
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($results['file']));
echo $results['file'];
exit;
} else {
http_response_code(400);
}
}
}