2 // ------------------------------------------------------------------------ //
3 // Garden State Health Systems //
4 // Copyright (c) 2010 gshsys.com //
5 // <http://www.gshsys.com/> //
6 // ------------------------------------------------------------------------ //
7 // This program is free software; you can redistribute it and/or modify //
8 // it under the terms of the GNU General Public License as published by //
9 // the Free Software Foundation; either version 2 of the License, or //
10 // (at your option) any later version. //
12 // You may not change or alter any portion of this comment or credits //
13 // of supporting developers from this source code or any supporting //
14 // source code which is considered copyrighted (c) material of the //
15 // original comment or credit authors. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details. //
22 // You should have received a copy of the GNU General Public License //
23 // along with this program; if not, write to the Free Software //
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
25 // ------------------------------------------------------------------------ //
27 //SANITIZE ALL ESCAPES
28 $sanitize_all_escapes=true;
31 //STOP FAKE REGISTER GLOBALS
32 $fake_register_globals=false;
35 // check if using the patient portal
36 //(if so, then use the portal authorization)
37 if (isset($_GET['portal_auth'])) {
38 $landingpage = "../patients/index.php";
40 if ( isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite']) ) {
41 $pid = $_SESSION['pid'];
47 header('Location: '.$landingpage.'?w');
52 require_once(dirname(__FILE__
) . "/../interface/globals.php");
53 require_once(dirname(__FILE__
) . "/../library/sql-ccr.inc");
54 require_once(dirname(__FILE__
) . "/uuid.php");
55 require_once(dirname(__FILE__
) . "/../custom/code_types.inc.php");
57 function createCCR($action,$raw="no"){
59 $authorID = getUuid();
60 $patientID = getUuid();
61 $sourceID = getUuid();
64 $result = getActorData();
65 while($res = sqlFetchArray($result[2])){
66 $
{"labID{$res['id']}"} = getUuid();
69 $ccr = new DOMDocument('1.0','UTF-8');
70 $e_styleSheet = $ccr->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="stylesheet/ccr.xsl"');
71 $ccr->appendChild($e_styleSheet);
73 $e_ccr = $ccr->createElementNS('urn:astm-org:CCR', 'ContinuityOfCareRecord');
74 $ccr->appendChild($e_ccr);
76 /////////////// Header
78 require_once("createCCRHeader.php");
79 $e_Body = $ccr->createElement('Body');
80 $e_ccr->appendChild($e_Body);
82 /////////////// Problems
84 $e_Problems = $ccr->createElement('Problems');
85 require_once("createCCRProblem.php");
86 $e_Body->appendChild($e_Problems);
88 /////////////// Alerts
90 $e_Alerts = $ccr->createElement('Alerts');
91 require_once("createCCRAlerts.php");
92 $e_Body->appendChild($e_Alerts);
94 ////////////////// Medication
96 $e_Medications = $ccr->createElement('Medications');
97 require_once("createCCRMedication.php");
98 $e_Body->appendChild($e_Medications);
100 ///////////////// Immunization
102 $e_Immunizations = $ccr->createElement('Immunizations');
103 require_once("createCCRImmunization.php");
104 $e_Body->appendChild($e_Immunizations);
107 /////////////////// Results
109 $e_Results = $ccr->createElement('Results');
110 require_once("createCCRResult.php");
111 $e_Body->appendChild($e_Results);
114 /////////////////// Procedures
116 //$e_Procedures = $ccr->createElement('Procedures');
117 //require_once("createCCRProcedure.php");
118 //$e_Body->appendChild($e_Procedures);
120 //////////////////// Footer
122 // $e_VitalSigns = $ccr->createElement('VitalSigns');
123 // $e_Body->appendChild($e_VitalSigns);
125 /////////////// Actors
127 $e_Actors = $ccr->createElement('Actors');
128 require_once("createCCRActor.php");
129 $e_ccr->appendChild($e_Actors);
131 if ($action=="generate"){
135 if($action == "viewccd"){
140 function gnrtCCR($ccr,$raw="no"){
143 $ccr->preserveWhiteSpace
= false;
144 $ccr->formatOutput
= true;
147 // simply send the xml to a textarea (nice debugging tool)
148 echo "<textarea rows='35' cols='500' style='width:95%' readonly>";
149 echo $ccr->saveXml();
154 else if ($raw == "hybrid") {
155 // send a file that contains a hybrid file of the raw xml and the xsl stylesheet
156 createHybridXML($ccr);
159 else if ($raw == "pure") {
160 // send a zip file that contains a separate xml data file and xsl stylesheet
161 if (! (class_exists('ZipArchive')) ) {
162 displayError(xl("ERROR: Missing ZipArchive PHP Module"));
165 $tempDir = $GLOBALS['temporary_files_dir'];
166 $zipName = $tempDir . "/" . getReportFilename() . "-ccr.zip";
167 if (file_exists($zipName)) {
170 $zip = new ZipArchive();
172 displayError(xl("ERROR: Unable to Create Zip Archive."));
175 if ( $zip->open($zipName, ZIPARCHIVE
::CREATE
) ) {
176 $zip->addFile("stylesheet/ccr.xsl", "stylesheet/ccr.xsl");
177 $xmlName = $tempDir . "/" . getReportFilename() . "-ccr.xml";
178 if (file_exists($xmlName)) {
181 $ccr->save($xmlName);
182 $zip->addFile($xmlName, basename($xmlName) );
184 header("Pragma: public");
185 header("Expires: 0");
186 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
187 header("Content-Type: application/force-download");
188 header("Content-Length: " . filesize($zipName));
189 header("Content-Disposition: attachment; filename=" . basename($zipName) . ";");
190 header("Content-Description: File Transfer");
197 displayError(xl("ERROR: Unable to Create Zip Archive."));
203 header("Content-type: application/xml");
204 echo $ccr->saveXml();
209 function viewCCD($ccr,$raw="no"){
211 $ccr->preserveWhiteSpace
= false;
212 $ccr->formatOutput
= true;
214 $ccr->save(dirname(__FILE__
) .'/generatedXml/ccrForCCD.xml');
216 $xmlDom = new DOMDocument();
217 $xmlDom->loadXML($ccr->saveXML());
219 $ccr_ccd = new DOMDocument();
220 $ccr_ccd->load(dirname(__FILE__
) .'/ccd/ccr_ccd.xsl');
222 $xslt = new XSLTProcessor();
223 $xslt->importStylesheet($ccr_ccd);
225 $ccd = new DOMDocument();
226 $ccd->preserveWhiteSpace
= false;
227 $ccd->formatOutput
= true;
229 $ccd->loadXML($xslt->transformToXML($xmlDom));
231 $ccd->save(dirname(__FILE__
) .'/generatedXml/ccdDebug.xml');
234 // simply send the xml to a textarea (nice debugging tool)
235 echo "<textarea rows='35' cols='500' style='width:95%' readonly>";
236 echo $ccd->saveXml();
241 $ss = new DOMDocument();
242 $ss->load(dirname(__FILE__
) ."/stylesheet/cda.xsl");
244 $xslt->importStyleSheet($ss);
246 $html = $xslt->transformToXML($ccd);
254 function sourceType($ccr, $uuid){
256 $e_Source = $ccr->createElement('Source');
258 $e_Actor = $ccr->createElement('Actor');
259 $e_Source->appendChild($e_Actor);
261 $e_ActorID = $ccr->createElement('ActorID',$uuid);
262 $e_Actor->appendChild($e_ActorID);
268 function displayError($message) {
269 echo '<script type="text/javascript">alert("' . addslashes($message) . '");</script>';
273 function createHybridXML($ccr) {
276 $main_xml = $ccr->saveXml();
278 // save the stylesheet
279 $main_stylesheet = file_get_contents('stylesheet/ccr.xsl');
281 // replace stylesheet link in raw xml file
282 $substitute_string = '<?xml-stylesheet type="text/xsl" href="#style1"?>
283 <!DOCTYPE ContinuityOfCareRecord [
284 <!ATTLIST xsl:stylesheet id ID #REQUIRED>
287 $replace_string = '<?xml-stylesheet type="text/xsl" href="stylesheet/ccr.xsl"?>';
288 $main_xml = str_replace($replace_string,$substitute_string,$main_xml);
290 // remove redundant xml declaration from stylesheet
291 $replace_string = '<?xml version="1.0" encoding="UTF-8"?>';
292 $main_stylesheet = str_replace($replace_string,'',$main_stylesheet);
294 // embed the stylesheet in the raw xml file
295 $replace_string ='<ContinuityOfCareRecord xmlns="urn:astm-org:CCR">';
296 $main_stylesheet = $replace_string.$main_stylesheet;
297 $main_xml = str_replace($replace_string,$main_stylesheet,$main_xml);
299 // insert style1 id into the stylesheet parameter
300 $substitute_string = 'xsl:stylesheet id="style1" exclude-result-prefixes';
301 $replace_string = 'xsl:stylesheet exclude-result-prefixes';
302 $main_xml = str_replace($replace_string,$substitute_string,$main_xml);
304 // prepare the filename to use
305 // LASTNAME-FIRSTNAME-PID-DATESTAMP-ccr.xml
306 $main_filename = getReportFilename()."-ccr.xml";
308 // send the output as a file to the user
309 header("Content-type: text/xml");
310 header("Content-Disposition: attachment; filename=" . $main_filename . "");
314 if($_POST['ccrAction'])
316 createCCR($_POST['ccrAction'],$_POST['raw']);