5 * Copyright (C) 2010 Garden State Health Systems <http://www.gshsys.com/>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Garden State Health Systems <http://www.gshsys.com/>
20 * @link http://www.open-emr.org
24 //SANITIZE ALL ESCAPES
25 $sanitize_all_escapes=true;
28 //STOP FAKE REGISTER GLOBALS
29 $fake_register_globals=false;
32 // check if using the patient portal
33 //(if so, then use the portal authorization)
34 if (isset($_GET['portal_auth'])) {
35 $landingpage = "../patients/index.php";
37 if ( isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite']) ) {
38 $pid = $_SESSION['pid'];
44 header('Location: '.$landingpage.'?w');
49 require_once(dirname(__FILE__
) . "/../interface/globals.php");
50 require_once(dirname(__FILE__
) . "/../library/sql-ccr.inc");
51 require_once(dirname(__FILE__
) . "/uuid.php");
52 require_once(dirname(__FILE__
) . "/../custom/code_types.inc.php");
54 function createCCR($action,$raw="no"){
56 $authorID = getUuid();
57 $patientID = getUuid();
58 $sourceID = getUuid();
61 $result = getActorData();
62 while($res = sqlFetchArray($result[2])){
63 $
{"labID{$res['id']}"} = getUuid();
66 $ccr = new DOMDocument('1.0','UTF-8');
67 $e_styleSheet = $ccr->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="stylesheet/ccr.xsl"');
68 $ccr->appendChild($e_styleSheet);
70 $e_ccr = $ccr->createElementNS('urn:astm-org:CCR', 'ContinuityOfCareRecord');
71 $ccr->appendChild($e_ccr);
73 /////////////// Header
75 require_once("createCCRHeader.php");
76 $e_Body = $ccr->createElement('Body');
77 $e_ccr->appendChild($e_Body);
79 /////////////// Problems
81 $e_Problems = $ccr->createElement('Problems');
82 require_once("createCCRProblem.php");
83 $e_Body->appendChild($e_Problems);
85 /////////////// Alerts
87 $e_Alerts = $ccr->createElement('Alerts');
88 require_once("createCCRAlerts.php");
89 $e_Body->appendChild($e_Alerts);
91 ////////////////// Medication
93 $e_Medications = $ccr->createElement('Medications');
94 require_once("createCCRMedication.php");
95 $e_Body->appendChild($e_Medications);
97 ///////////////// Immunization
99 $e_Immunizations = $ccr->createElement('Immunizations');
100 require_once("createCCRImmunization.php");
101 $e_Body->appendChild($e_Immunizations);
104 /////////////////// Results
106 $e_Results = $ccr->createElement('Results');
107 require_once("createCCRResult.php");
108 $e_Body->appendChild($e_Results);
111 /////////////////// Procedures
113 //$e_Procedures = $ccr->createElement('Procedures');
114 //require_once("createCCRProcedure.php");
115 //$e_Body->appendChild($e_Procedures);
117 //////////////////// Footer
119 // $e_VitalSigns = $ccr->createElement('VitalSigns');
120 // $e_Body->appendChild($e_VitalSigns);
122 /////////////// Actors
124 $e_Actors = $ccr->createElement('Actors');
125 require_once("createCCRActor.php");
126 $e_ccr->appendChild($e_Actors);
128 if ($action=="generate"){
132 if($action == "viewccd"){
137 function gnrtCCR($ccr,$raw="no"){
140 $ccr->preserveWhiteSpace
= false;
141 $ccr->formatOutput
= true;
144 // simply send the xml to a textarea (nice debugging tool)
145 echo "<textarea rows='35' cols='500' style='width:95%' readonly>";
146 echo $ccr->saveXml();
151 else if ($raw == "hybrid") {
152 // send a file that contains a hybrid file of the raw xml and the xsl stylesheet
153 createHybridXML($ccr);
156 else if ($raw == "pure") {
157 // send a zip file that contains a separate xml data file and xsl stylesheet
158 if (! (class_exists('ZipArchive')) ) {
159 displayError(xl("ERROR: Missing ZipArchive PHP Module"));
162 $tempDir = $GLOBALS['temporary_files_dir'];
163 $zipName = $tempDir . "/" . getReportFilename() . "-ccr.zip";
164 if (file_exists($zipName)) {
167 $zip = new ZipArchive();
169 displayError(xl("ERROR: Unable to Create Zip Archive."));
172 if ( $zip->open($zipName, ZIPARCHIVE
::CREATE
) ) {
173 $zip->addFile("stylesheet/ccr.xsl", "stylesheet/ccr.xsl");
174 $xmlName = $tempDir . "/" . getReportFilename() . "-ccr.xml";
175 if (file_exists($xmlName)) {
178 $ccr->save($xmlName);
179 $zip->addFile($xmlName, basename($xmlName) );
181 header("Pragma: public");
182 header("Expires: 0");
183 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
184 header("Content-Type: application/force-download");
185 header("Content-Length: " . filesize($zipName));
186 header("Content-Disposition: attachment; filename=" . basename($zipName) . ";");
187 header("Content-Description: File Transfer");
194 displayError(xl("ERROR: Unable to Create Zip Archive."));
200 header("Content-type: application/xml");
201 echo $ccr->saveXml();
206 function viewCCD($ccr,$raw="no"){
208 $ccr->preserveWhiteSpace
= false;
209 $ccr->formatOutput
= true;
211 $ccr->save(dirname(__FILE__
) .'/generatedXml/ccrForCCD.xml');
213 $xmlDom = new DOMDocument();
214 $xmlDom->loadXML($ccr->saveXML());
216 $ccr_ccd = new DOMDocument();
217 $ccr_ccd->load(dirname(__FILE__
) .'/ccd/ccr_ccd.xsl');
219 $xslt = new XSLTProcessor();
220 $xslt->importStylesheet($ccr_ccd);
222 $ccd = new DOMDocument();
223 $ccd->preserveWhiteSpace
= false;
224 $ccd->formatOutput
= true;
226 $ccd->loadXML($xslt->transformToXML($xmlDom));
228 $ccd->save(dirname(__FILE__
) .'/generatedXml/ccdDebug.xml');
231 // simply send the xml to a textarea (nice debugging tool)
232 echo "<textarea rows='35' cols='500' style='width:95%' readonly>";
233 echo $ccd->saveXml();
238 $ss = new DOMDocument();
239 $ss->load(dirname(__FILE__
) ."/stylesheet/cda.xsl");
241 $xslt->importStyleSheet($ss);
243 $html = $xslt->transformToXML($ccd);
251 function sourceType($ccr, $uuid){
253 $e_Source = $ccr->createElement('Source');
255 $e_Actor = $ccr->createElement('Actor');
256 $e_Source->appendChild($e_Actor);
258 $e_ActorID = $ccr->createElement('ActorID',$uuid);
259 $e_Actor->appendChild($e_ActorID);
265 function displayError($message) {
266 echo '<script type="text/javascript">alert("' . addslashes($message) . '");</script>';
270 function createHybridXML($ccr) {
273 $main_xml = $ccr->saveXml();
275 // save the stylesheet
276 $main_stylesheet = file_get_contents('stylesheet/ccr.xsl');
278 // replace stylesheet link in raw xml file
279 $substitute_string = '<?xml-stylesheet type="text/xsl" href="#style1"?>
280 <!DOCTYPE ContinuityOfCareRecord [
281 <!ATTLIST xsl:stylesheet id ID #REQUIRED>
284 $replace_string = '<?xml-stylesheet type="text/xsl" href="stylesheet/ccr.xsl"?>';
285 $main_xml = str_replace($replace_string,$substitute_string,$main_xml);
287 // remove redundant xml declaration from stylesheet
288 $replace_string = '<?xml version="1.0" encoding="UTF-8"?>';
289 $main_stylesheet = str_replace($replace_string,'',$main_stylesheet);
291 // embed the stylesheet in the raw xml file
292 $replace_string ='<ContinuityOfCareRecord xmlns="urn:astm-org:CCR">';
293 $main_stylesheet = $replace_string.$main_stylesheet;
294 $main_xml = str_replace($replace_string,$main_stylesheet,$main_xml);
296 // insert style1 id into the stylesheet parameter
297 $substitute_string = 'xsl:stylesheet id="style1" exclude-result-prefixes';
298 $replace_string = 'xsl:stylesheet exclude-result-prefixes';
299 $main_xml = str_replace($replace_string,$substitute_string,$main_xml);
301 // prepare the filename to use
302 // LASTNAME-FIRSTNAME-PID-DATESTAMP-ccr.xml
303 $main_filename = getReportFilename()."-ccr.xml";
305 // send the output as a file to the user
306 header("Content-type: text/xml");
307 header("Content-Disposition: attachment; filename=" . $main_filename . "");
311 if($_POST['ccrAction'])
313 createCCR($_POST['ccrAction'],$_POST['raw']);