fix and chore: pinned maennchen/zipstream-php version to work with arm7 and updated...
[openemr.git] / ccr / display.php
blob2261340208f645d85c5dd00382dcca8a7649a9c2
1 <?php
3 /**
4 * display.php Is responsible for display a CCR/CCD/CCDA document previewed from the documents folder.
6 * @package openemr
7 * @link http://www.open-emr.org
8 * @author Ajil P.M <ajilpm@zhservices.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Stephen Nielson <snielson@discoverandchange.com>
11 * @deprecated 7.0.0 People should use the /interface/modules/zend_modules/public/encountermanager/previewDocument?docId=<id> REST action instead of this file
12 * @copyright Copyright (c) 2011 Z&H Consultancy Services Private Limited <ajilpm@zhservices.com>
13 * @copyright Copyright (c) 2013 Brady Miller <brady.g.miller@gmail.com>
14 * @copyright Copyright (c) 2022 Discover and Change <snielson@discoverandchange.com>
15 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
18 require_once(dirname(__FILE__) . "/../interface/globals.php");
20 use OpenEMR\Events\PatientDocuments\PatientDocumentViewCCDAEvent;
21 use OpenEMR\Common\Twig\TwigContainer;
22 use OpenEMR\Common\Logging\SystemLogger;
24 $type = $_GET['type'];
25 $document_id = $_GET['doc_id'];
26 $d = new Document($document_id);
29 try {
30 $twig = new TwigContainer(null, $GLOBALS['kernel']);
31 // can_access will check session if no params are passed.
32 if (!$d->can_access()) {
33 echo $twig->getTwig()->render("templates/error/400.html.twig", ['statusCode' => 401, 'errorMessage' => 'Access Denied']);
34 exit;
35 } else if ($d->is_deleted()) {
36 echo $twig->getTwig()->render("templates/error/404.html.twig");
37 exit;
40 $xml = $d->get_data();
41 if (empty($xml)) {
42 echo $twig->getTwig()->render("templates/error/404.html.twig");
43 exit;
46 $viewCCDAEvent = new PatientDocumentViewCCDAEvent();
47 $viewCCDAEvent->setCcdaType($type); // not sure if we want to send the old CCR... but I guess module authors can use it if they want
48 if (!empty($d->get_foreign_reference_id())) {
49 $viewCCDAEvent->setCcdaId($d->get_foreign_reference_id());
52 $viewCCDAEvent->setDocumentId($d->get_id());
53 $viewCCDAEvent->setContent($d->get_data());
54 $viewCCDAEvent->setFormat("html");
56 $updatedViewCCDAEvent = $GLOBALS['kernel']->getEventDispatcher()->dispatch($viewCCDAEvent, PatientDocumentViewCCDAEvent::EVENT_NAME);
58 $content = $updatedViewCCDAEvent->getContent();
59 if (empty($content)) {
60 // TODO: @adunsulag log the security error as someone is trying to do a remote file inclusion
61 echo $twig->getTwig()->render("templates/error/general_http_error.html.twig", ['statusCode' => 500, 'errorMessage' => 'System error occurred in processing content']);
62 exit;
64 echo $updatedViewCCDAEvent->getContent($content);
65 } catch (\Exception $exception) {
66 (new SystemLogger())->errorLogCaller(
67 "Failed to generate ccda for view",
68 ['type' => $type, 'document_id' => $document_id, 'message' => $exception, 'trace' => $exception->getTraceAsString()]