erx fix 4
[openemr.git] / interface / eRx.php
blobb40b538a441fbfb44d26d1a7727a79d8fe930d0b
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 ZMG LLC <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Vinish K <vinish@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //SANITIZE ALL ESCAPES
28 $sanitize_all_escapes=true;
31 //STOP FAKE REGISTER GLOBALS
32 $fake_register_globals=false;
34 require('globals.php');
35 require('eRx_xml.php');
36 $userRole=sqlQuery("select * from users where username=?",array($_SESSION['authUser']));
37 $userRole['newcrop_user_role'] = preg_replace('/erx/','',$userRole['newcrop_user_role']);
38 $msg='';
39 $warning_msg='';
40 $dem_check='';
41 $doc = new DOMDocument();
42 $doc->formatOutput = true;
43 $GLOBALS['total_count']=60;
44 $r = $doc->createElement( "NCScript" );
45 $r->setAttribute('xmlns','http://secure.newcropaccounts.com/interfaceV7');
46 $r->setAttribute('xmlns:NCStandard','http://secure.newcropaccounts.com/interfaceV7:NCStandard');
47 $r->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
48 $doc->appendChild( $r );
50 credentials($doc,$r);
51 user_role($doc,$r);
52 $page=$_REQUEST['page'];
53 destination($doc,$r,$page,$pid);
54 account($doc,$r);
55 if($userRole['newcrop_user_role']!='manager')
57 location($doc,$r);
59 if($userRole['newcrop_user_role']=='doctor' || $page=='renewal')
61 LicensedPrescriber($doc,$r);
63 if($userRole['newcrop_user_role']=='manager' || $userRole['newcrop_user_role']=='admin' || $userRole['newcrop_user_role']=='nurse')
65 Staff($doc,$r);
67 if($userRole['newcrop_user_role']=='supervisingDoctor')
69 SupervisingDoctor($doc,$r);
71 if($userRole['newcrop_user_role']=='midlevelPrescriber')
73 MidlevelPrescriber($doc,$r);
75 $prescIds='';
76 if($pid)
78 $allergy=Patient($doc,$r,$pid);
79 $active = '';
80 if($GLOBALS['erx_upload_active']==1)
81 $active = 'and active=1';
82 $res_presc=sqlStatement("select id from prescriptions where patient_id=? and erx_source='0' and erx_uploaded='0' $active limit 0,".$GLOBALS['total_count'],array($pid));
83 $presc_limit=sqlNumRows($res_presc);
84 $med_limit=$GLOBALS['total_count']-$presc_limit;
85 while($row_presc=sqlFetchArray($res_presc))
87 $prescIds.=$row_presc['id'].":";
89 $prescIds=preg_replace('/:$/','',$prescIds);
90 if($_REQUEST['id'] || $prescIds)
92 if($_REQUEST['id'])
93 $prescArr=explode(':',$_REQUEST['id']);
94 elseif($prescIds)
95 $prescArr=explode(':',$prescIds);
96 foreach($prescArr as $prescid)
98 if($prescid)
99 OutsidePrescription($doc,$r,$pid,$prescid);
102 else
104 OutsidePrescription($doc,$r,$pid,0);
106 if($res_presc<$GLOBALS['total_count'])
107 $uploaded_med_arr =PatientMedication($doc,$r,$pid,$med_limit);
109 $xml = $doc->saveXML();
110 $xml = preg_replace('/"/',"'",$xml);
111 //echo $xml."<br><br>";
112 $xml = stripStrings($xml,array('&#xD;'=>'','\t'=>''));
113 //$xml = stripStrings($xml,array('&#xD;'=>'','\t'=>'','\r'=>'','\n'=>''));
114 if($dem_check){
115 echo "<b>".htmlspecialchars( xl("Warning:"), ENT_NOQUOTES)."</b><br><br>";
116 echo $dem_check."<br>";
117 echo htmlspecialchars( xl("The page will be redirected to Demographics. You can edit the country field and clickthrough to NewCrop again."), ENT_NOQUOTES);
118 ob_end_flush();
120 <script type="text/javascript">
121 window.setTimeout(function nav(){
122 window.location="patient_file/summary/demographics_full.php";
123 },5000);
124 </script>
125 <?php
126 die;
128 if($msg)
130 echo htmlspecialchars( xl('The following fields have to be filled to send request.'), ENT_NOQUOTES);
131 echo "<br>";
132 echo $msg;
133 die;
135 if($warning_msg)
137 echo "<font style='font-weight:bold;font-size:15px'>".htmlspecialchars( xl("Warning : "), ENT_NOQUOTES)."</font><br>".$warning_msg;
138 echo "<br><b>".htmlspecialchars( xl('This will not prevent you from going to the e-Prescriptions site.'), ENT_NOQUOTES)."</b>";
139 sleep(2);
141 //################################################
142 //XML GENERATED BY OPENEMR
143 //################################################
144 //$fh=fopen('click_xml.txt','a');
145 //fwrite($fh,$xml);
146 //echo $xml;
147 //die;
148 //################################################
149 if(!extension_loaded('curl'))
151 echo htmlspecialchars( xl('PHP CURL module should be enabled in your server.'), ENT_NOQUOTES);die;
153 $error = checkError($xml);
154 if($error==0)
156 if($page=='compose'){
157 sqlQuery("update patient_data set soap_import_status=1 where pid=?",array($pid));
159 elseif($page=='medentry'){
160 sqlQuery("update patient_data set soap_import_status=3 where pid=?",array($pid));
162 foreach($allergy as $allId)
164 sqlQuery("update lists set erx_uploaded='1' where type='allergy' and pid=? and id=?",array($pid,$allId));
166 $prescArr=explode(':',$prescIds);
167 foreach($prescArr as $prescid)
169 sqlQuery("update prescriptions set erx_uploaded='1' ,active='0' where patient_id=? and id=?",array($pid,$prescid));
171 foreach($uploaded_med_arr as $value)
173 sqlQuery("update lists set erx_uploaded='1' where id=?",array($value));
174 //sqlQuery("update lists set enddate=".date('Y-m-d')." where
175 //(enddate is null or enddate = '' ) and id=? ",array($value));
178 <script language='JavaScript'>
179 <?php require($GLOBALS['srcdir'] . "/restoreSession.php"); ?>
180 </script>
181 <form name='info' method='post' action="<?php echo getErxPath()?>" onsubmit='return top.restoreSession()'>
182 <input type='submit' style='display:none'>
183 <input type='hidden' id='RxInput' name='RxInput' value="<?php echo $xml;?>">
184 </form>
185 <script type="text/javascript" src="../library/js/jquery.1.3.2.js"></script>
186 <script type='text/javascript'>
187 document.forms[0].submit();
188 </script>
189 <?php
191 else
193 echo htmlspecialchars( xl('NewCrop call failed', ENT_NOQUOTES));