3 require_once ($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
4 require_once($GLOBALS['fileroot'] ."/library/classes/Prescription.class.php");
5 require_once($GLOBALS['fileroot'] ."/library/classes/Provider.class.php");
6 require_once($GLOBALS['fileroot'] ."/library/classes/RXList.class.php");
8 class C_Prescription
extends Controller
{
13 function C_Prescription($template_mod = "general") {
15 $this->template_mod
= $template_mod;
16 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
17 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
18 $this->assign("STYLE", $GLOBALS['style']);
19 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
22 function default_action() {
23 $this->assign("prescription",$this->prescriptions
[0]);
24 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
27 function edit_action($id = "",$patient_id="",$p_obj = null) {
29 if ($p_obj != null && get_class($p_obj) == "prescription") {
30 $this->prescriptions
[0] = $p_obj;
32 elseif (get_class($this->prescriptions
[0]) != "prescription" ) {
33 $this->prescriptions
[0] = new Prescription($id);
36 if (!empty($patient_id)) {
37 $this->prescriptions
[0]->set_patient_id($patient_id);
39 $this->default_action();
42 function list_action($id,$sort = "") {
44 $this->function_argument_error();
48 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
51 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
53 //print_r(Prescription::prescriptions_factory($id));
54 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
57 function block_action($id,$sort = "") {
59 $this->function_argument_error();
63 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
66 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
68 //print_r(Prescription::prescriptions_factory($id));
69 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
72 function lookup_action() {
74 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
77 function edit_action_process() {
78 if ($_POST['process'] != "true")
82 $this->prescriptions
[0] = new Prescription($_POST['id']);
83 parent
::populate_object($this->prescriptions
[0]);
84 //echo $this->prescriptions[0]->toString(true);
85 $this->prescriptions
[0]->persist();
86 $_POST['process'] = "";
87 return $this->send_action($this->prescriptions
[0]->id
);
90 function send_action($id) {
91 $_POST['process'] = "true";
93 $this->function_argument_error();
96 $this->assign("prescription",new Prescription($id));
97 $this->_state
= false;
98 return $this->fetch($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_send.html");
101 function send_action_process($id) {
102 $dummy = ""; // Added by Rod to avoid run-time warnings
103 if ($_POST['process'] != "true")
106 $this->function_argument_error();
108 $p = new Prescription($id);
109 switch ($_POST['submit']) {
112 // The following statement added by Rod.
113 // Looking at Controller.class.php, it appears that _state is set to false
114 // to indicate that no further HTML is to be generated.
115 $this->_state
= false; // Added by Rod - see Controller.class.php
116 return $this->_print_prescription($p, $dummy);
119 return $this->_email_prescription($p,$_POST['email_to']);
122 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
123 //$this->assign("process_result","No fax server is currently setup.");
124 return $this->_fax_prescription($p,$_POST['fax_to']);
127 $pharmacy_id = $_POST['pharmacy_id'];
128 //echo "auto sending to : " . $_POST['pharmacy_id'];
129 $phar = new Pharmacy($_POST['pharmacy_id']);
131 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
132 return $this->_print_prescription($p, $dummy);
134 elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
135 $email = $phar->get_email();
136 if (!empty($email)) {
137 return $this->_email_prescription($p,$phar->get_email());
141 elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
142 $faxNum= $phar->get_fax();
143 if(!empty($faxNum)) {
144 Return $this->_fax_prescription ($p,$faxNum);
146 // return $this->assign("process_result","No fax server is currently setup.");
147 // else default is printing,
150 //the pharmacy has no default or default is print
151 return $this->_print_prescription($p, $dummy);
160 function _print_prescription($p, & $toFile) {
161 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
162 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
163 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
164 ,$GLOBALS['oer_config']['prescriptions']['bottom']
165 ,$GLOBALS['oer_config']['prescriptions']['left']
166 ,$GLOBALS['oer_config']['prescriptions']['right']
169 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
171 if(!empty($this->pconfig
['logo'])) {
172 $pdf->ezImage($this->pconfig
['logo'],"","","none","left");
174 $pdf->ezText($p->get_prescription_display(),10);
175 if($this->pconfig
['use_signature'] == true ) {
176 $pdf->ezImage($this->pconfig
['signature'],"","","none","left");
179 $pdf->ezText("\n\n\n\nSignature:________________________________",10);
184 $toFile = $pdf->ezOutput();
189 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
194 function _email_prescription($p,$email) {
196 $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
199 require($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php");
200 $mail = new PHPMailer();
201 $mail->SetLanguage("en",$GLOBALS['fileroot'] . "/library/" );
202 //this is a temporary config item until the rest of the per practice billing settings make their way in
203 $mail->From
= $GLOBALS['practice_return_email_path'];
204 $mail->FromName
= $p->provider
->get_name_display();
206 $mail->Host
= "localhost";
207 $mail->Mailer
= "mail";
208 $text_body = $p->get_prescription_display();
209 $mail->Body
= $text_body;
210 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
211 $mail->AddAddress($email);
213 $this->assign("process_result","Email was successfully sent to: " . $email);
217 $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
222 function do_lookup() {
223 if ($_POST['process'] != "true")
226 if (!empty($_POST['drug'])) {
227 $list = @RxList
::get_list($_POST['drug']);
229 if (is_array($list)) {
230 $list = array_flip($list);
231 $this->assign("drug_options",$list);
232 $this->assign("drug_values",array_keys($list));
235 $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
238 //$this->assign("PROCESS","");
240 $_POST['process'] = "";
243 function _fax_prescription($p,$faxNum)
246 //strip - ,(, ), and ws
247 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum);
248 //validate the number
250 if(!empty($faxNum) && is_numeric($faxNum))
252 //get the sendfax command and execute it
253 $cmd = $this->pconfig
['sendfax'];
254 // prepend any prefix to the fax number
255 $pref=$this->pconfig
['prefix'];
256 $faxNum=$pref.$faxNum;
259 $err .= " Send fax not set in includes/config.php";
264 //generate file to fax
266 $this->_print_prescription($p, $faxFile);
269 $err .= " _print_prescription returned empty file";
272 $fileName = dirname(__FILE__
)."/../documents/".$p->get_id()
273 .$p->get_patient_id()."_fax_.pdf";
274 //print "filename is $fileName";
275 touch($fileName); // php bug
276 $handle = fopen($fileName,"w");
279 $err .= " Failed to open file $fileName to write fax to";
282 if(fwrite($handle, $faxFile) === false)
284 $err .= " Failed to write data to $fileName";
288 $args = " -n -d $faxNum $fileName";
289 //print "command is $cmd $args<br>";
296 $err = "bad fax number passed to function";
300 $this->assign("process_result",$err);