also brought prior fix into the patient report
[openemr.git] / ccr / display.php
blobb2122b4fea2efdedc7cd762e4b9a5167bf530800
1 <?php
2 require_once(dirname(__FILE__) . "/../interface/globals.php");
3 require_once(dirname(__FILE__) . "/../library/classes/Document.class.php");
4 require_once(dirname(__FILE__) . "/../library/classes/CouchDB.class.php");
6 $type = $_GET['type'];
7 $document_id = $_GET['doc_id'];
8 $d = new Document($document_id);
9 $url = $d->get_url();
10 $storagemethod = $d->get_storagemethod();
11 $couch_docid = $d->get_couch_docid();
12 $couch_revid = $d->get_couch_revid();
14 if($couch_docid && $couch_revid){
15 $couch = new CouchDB();
16 $data = array($GLOBALS['couchdb_dbase'],$couch_docid);
17 $resp = $couch->retrieve_doc($data);
18 $xml = base64_decode($resp->data);
19 if($content=='' && $GLOBALS['couchdb_log']==1){
20 $log_content = date('Y-m-d H:i:s')." ==> Retrieving document\r\n";
21 $log_content = date('Y-m-d H:i:s')." ==> URL: ".$url."\r\n";
22 $log_content .= date('Y-m-d H:i:s')." ==> CouchDB Document Id: ".$couch_docid."\r\n";
23 $log_content .= date('Y-m-d H:i:s')." ==> CouchDB Revision Id: ".$couch_revid."\r\n";
24 $log_content .= date('Y-m-d H:i:s')." ==> Failed to fetch document content from CouchDB.\r\n";
25 //$log_content .= date('Y-m-d H:i:s')." ==> Will try to download file from HardDisk if exists.\r\n\r\n";
26 $this->document_upload_download_log($d->get_foreign_id(),$log_content);
27 die(xlt("File retrieval from CouchDB failed"));
29 }else{
30 $url = preg_replace("|^(.*)://|","",$url);
31 // Collect filename and path
32 $from_all = explode("/",$url);
33 $from_filename = array_pop($from_all);
34 $from_pathname_array = array();
35 for ($i=0;$i<$d->get_path_depth();$i++) {
36 $from_pathname_array[] = array_pop($from_all);
38 $from_pathname_array = array_reverse($from_pathname_array);
39 $from_pathname = implode("/",$from_pathname_array);
40 $temp_url = $GLOBALS['OE_SITE_DIR'] . '/documents/' . $from_pathname . '/' . $from_filename;
41 if (!file_exists($temp_url)) {
42 echo xl('The requested document is not present at the expected location on the filesystem or there are not sufficient permissions to access it.','','',' ') . $temp_url;
43 }else{
44 $url = $temp_url;
45 $f = fopen($url,"r");
46 $xml = fread($f,filesize($url));
47 fclose($f);
51 if($type == "CCR"){
52 $xmlDom = new DOMDocument();
53 $xmlDom->loadXML($xml);
54 $ss = new DOMDocument();
55 $ss->load(dirname(__FILE__).'/stylesheet/ccr.xsl');
56 $proc = new XSLTProcessor();
57 $proc->importStylesheet($ss);
58 $s_html = $proc->transformToXML($xmlDom);
59 echo $s_html;
60 }else{
61 $xmlDom = new DOMDocument();
62 $xmlDom->loadXML($xml);
63 $ss = new DOMDocument();
64 $ss->load(dirname(__FILE__).'/stylesheet/cda.xsl');
65 $xslt = new XSLTProcessor();
66 $xslt->importStyleSheet($ss);
67 $html = $xslt->transformToXML($xmlDom);
68 echo $html;