2 // This program is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU General Public License
4 // as published by the Free Software Foundation; either version 2
5 // of the License, or (at your option) any later version.
7 require_once($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
8 require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php");
9 require_once($GLOBALS['fileroot'] . "/library/classes/Provider.class.php");
10 require_once($GLOBALS['fileroot'] . "/library/classes/RXList.class.php");
11 require_once($GLOBALS['fileroot'] . "/library/registry.inc");
12 require_once($GLOBALS['fileroot'] . "/library/amc.php");
14 class C_Prescription
extends Controller
{
19 var $is_faxing = false;
20 var $is_print_to_fax = false;
22 function C_Prescription($template_mod = "general") {
25 $this->template_mod
= $template_mod;
26 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
27 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
28 $this->assign("STYLE", $GLOBALS['style']);
29 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
30 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
31 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
32 $this->assign("CSS_HEADER", $GLOBALS['css_header'] );
33 $this->assign("WEB_ROOT", $GLOBALS['webroot'] );
35 if ($GLOBALS['inhouse_pharmacy']) {
36 // Make an array of drug IDs and selectors for the template.
37 $drug_array_values = array(0);
38 $drug_array_output = array("-- or select from inventory --");
39 $drug_attributes = '';
41 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
43 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
44 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
45 "t.period, t.quantity, t.refills " .
46 "FROM drug_templates AS t, drugs AS d WHERE " .
47 "d.drug_id = t.drug_id ORDER BY t.selector");
49 while ($row = sqlFetchArray($res)) {
50 $tmp_output = $row['selector'];
51 if ($row['ndc_number']) {
52 $tmp_output .= ' [' . $row['ndc_number'] . ']';
54 $drug_array_values[] = $row['drug_id'];
55 $drug_array_output[] = $tmp_output;
56 if ($drug_attributes) $drug_attributes .= ',';
57 $drug_attributes .= "['" .
58 $row['name'] . "'," . // 0
59 $row['form'] . ",'" . // 1
60 $row['dosage'] . "'," . // 2
61 $row['size'] . "," . // 3
62 $row['unit'] . "," . // 4
63 $row['route'] . "," . // 5
64 $row['period'] . "," . // 6
65 $row['substitute'] . "," . // 7
66 $row['quantity'] . "," . // 8
67 $row['refills'] . "," . // 9
68 $row['quantity'] . "]"; // 10 quantity per_refill
70 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
71 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
72 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
76 function default_action() {
77 $this->assign("prescription",$this->prescriptions
[0]);
78 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
81 function edit_action($id = "",$patient_id="",$p_obj = null) {
83 if ($p_obj != null && get_class($p_obj) == "prescription") {
84 $this->prescriptions
[0] = $p_obj;
86 elseif (get_class($this->prescriptions
[0]) != "prescription" ) {
87 $this->prescriptions
[0] = new Prescription($id);
90 if (!empty($patient_id)) {
91 $this->prescriptions
[0]->set_patient_id($patient_id);
94 // If quantity to dispense is not already set from a POST, set its
96 if (! $this->get_template_vars('DISP_QUANTITY')) {
97 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
100 $this->default_action();
103 function list_action($id,$sort = "") {
105 $this->function_argument_error();
109 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
112 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
115 // flag to indicate the CAMOS form is regsitered and active
116 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
118 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
121 function block_action($id,$sort = "") {
123 $this->function_argument_error();
127 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
130 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
132 //print_r(Prescription::prescriptions_factory($id));
133 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
136 function fragment_action($id,$sort = "") {
138 $this->function_argument_error();
142 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
145 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
147 //print_r(Prescription::prescriptions_factory($id));
148 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_fragment.html");
151 function lookup_action() {
153 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
156 function edit_action_process() {
157 if ($_POST['process'] != "true")
161 // Stupid Smarty code treats empty values as not specified values.
162 // Since active is a checkbox, represent the unchecked state as -1.
163 if (empty($_POST['active'])) $_POST['active'] = '-1';
165 $this->prescriptions
[0] = new Prescription($_POST['id']);
166 parent
::populate_object($this->prescriptions
[0]);
167 //echo $this->prescriptions[0]->toString(true);
168 $this->prescriptions
[0]->persist();
169 $_POST['process'] = "";
171 // If the "Prescribe and Dispense" button was clicked, then
172 // redisplay as in edit_action() but also replicate the fee and
173 // include a piece of javascript to call dispense().
175 if ($_POST['disp_button']) {
176 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
177 $this->assign("DISP_FEE", $_POST['disp_fee']);
178 $this->assign("ENDING_JAVASCRIPT", "dispense();");
179 $this->_state
= false;
180 return $this->edit_action($this->prescriptions
[0]->id
);
183 // Set the AMC reporting flag (to record percentage of prescriptions that
184 // are set as e-prescriptions)
185 if (!(empty($_POST['escribe_flag']))) {
186 // add the e-prescribe flag
187 processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
190 // remove the e-prescribe flag
191 processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
194 if ($this->prescriptions
[0]->get_active() > 0) {
195 return $this->send_action($this->prescriptions
[0]->id
);
197 $this->list_action($this->prescriptions
[0]->get_patient_id());
201 function send_action($id) {
202 $_POST['process'] = "true";
204 $this->function_argument_error();
207 $rx = new Prescription($id);
208 // Populate pharmacy info if the patient has a default pharmacy.
209 // Probably the Prescription object should handle this instead, but
210 // doing it there will require more careful research and testing.
211 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
212 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
213 if ($prow['pharmacy_id']) {
214 $rx->pharmacy
->set_id($prow['pharmacy_id']);
215 $rx->pharmacy
->populate();
217 $this->assign("prescription", $rx);
219 $this->_state
= false;
220 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
221 $this->template_mod
. "_send.html");
224 function multiprintfax_header(& $pdf, $p) {
225 return $this->multiprint_header( $pdf, $p );
228 function multiprint_header(& $pdf, $p) {
229 $this->providerid
= $p->provider
->id
;
231 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'],'','50','','center','');
232 $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10));
233 $res = sqlQuery("SELECT concat('<b>',f.name,'</b>\n',f.street,'\n',f.city,', ',f.state,' ',f.postal_code,'\nTel:',f.phone,if(f.fax != '',concat('\nFax: ',f.fax),'')) addr FROM users JOIN facility AS f ON f.name = users.facility where users.id ='" .
234 mysql_real_escape_string($p->provider
->id
) . "'");
235 $pdf->ezText($res['addr'],12);
238 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>',12);
239 // A client had a bad experience with a patient misusing a DEA number, so
240 // now the doctors write those in on printed prescriptions and only when
241 // necessary. If you need to change this back, then please make it a
242 // configurable option. Faxed prescriptions were not changed. -- Rod
243 // Now it is configureable. Change value in
244 // <openemr root>/includes/config.php - Tekknogenius
245 if ($this->is_faxing ||
$GLOBALS['oer_config']['prescriptions']['show_DEA'])
246 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
, 12);
248 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
249 $pdf->ezColumnsStop();
250 if ($my_y < $pdf->y
){
254 $pdf->setLineStyle(1);
255 $pdf->ezColumnsStart(array('num'=>2));
256 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
257 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>',6);
258 $pdf->ezText($p->patient
->get_name_display(),10);
259 $res = sqlQuery("SELECT concat(street,'\n',city,', ',state,' ',postal_code,'\n',if(phone_home!='',phone_home,if(phone_cell!='',phone_cell,if(phone_biz!='',phone_biz,'')))) addr from patient_data where pid =". mysql_real_escape_string ($p->patient
->id
));
260 $pdf->ezText($res['addr']);
263 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
264 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>',6);
265 $pdf->ezText($p->patient
->date_of_birth
,10);
267 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
268 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>',6);
269 $pdf->ezText(str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
),10);
270 $pdf->ezColumnsStop();
271 if ($my_y < $pdf->y
){
275 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
276 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>',6);
280 function multiprintcss_header($p) {
281 echo("<div class='paddingdiv'>\n");
282 $this->providerid
= $p->provider
->id
;
283 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
285 echo ("<td></td>\n");
287 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
292 $res = sqlQuery("SELECT concat('<b>',f.name,'</b>\n',f.street,'\n',f.city,', ',f.state,' ',f.postal_code,'\nTel:',f.phone,if(f.fax != '',concat('\nFax: ',f.fax),'')) addr FROM users JOIN facility AS f ON f.name = users.facility where users.id ='" . mysql_real_escape_string($p->provider
->id
) . "'");
293 $patterns = array ('/\n/','/Tel:/','/Fax:/');
294 $replace = array ('<br>', xl('Tel').':', xl('Fax').':');
295 $res = preg_replace($patterns, $replace, $res);
296 echo ('<span class="large">' . $res['addr'] . '</span>');
299 echo ('<b><span class="large">' . $p->provider
->get_name_display() . '</span></b>'. '<br>');
300 if ($GLOBALS['oer_config']['prescriptions']['show_DEA']) echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
. '</span>');
301 else echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________');
305 echo ("<td rowspan='2' class='bordered'>\n");
306 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>'. '<br>');
307 echo ($p->patient
->get_name_display() . '<br>');
308 $res = sqlQuery("SELECT concat(street,'\n',city,', ',state,' ',postal_code,'\n',if(phone_home!='',phone_home,if(phone_cell!='',phone_cell,if(phone_biz!='',phone_biz,'')))) addr from patient_data where pid =". mysql_real_escape_string ($p->patient
->id
));
309 $patterns = array ('/\n/');
310 $replace = array ('<br>');
311 $res = preg_replace($patterns, $replace, $res);
314 echo ("<td class='bordered'>\n");
315 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br>');
316 echo ($p->patient
->date_of_birth
);
320 echo ("<td class='bordered'>\n");
321 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br>');
322 echo (str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
));
326 echo ("<td colspan='2' class='bordered'>\n");
327 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
333 function multiprintcss_preheader() {
334 // this sets styling and other header information of the multiprint css sheet
339 echo (" padding: 0;\n");
340 echo (" margin: 0;\n");
343 echo (" font-family: sans-serif;\n");
344 echo (" font-weight: normal;\n");
345 echo (" font-size: 10pt;\n");
346 echo (" background: white;\n");
347 echo (" color: black;\n");
349 echo ("span.large {\n");
350 echo (" font-size: 12pt;\n");
352 echo ("span.small {\n");
353 echo (" font-size: 6pt;\n");
356 echo (" vertical-align: top;\n");
357 echo (" width: 50%;\n");
358 echo (" font-size: 10pt;\n");
359 echo (" padding-bottom: 8pt;\n");
361 echo ("td.bordered {\n");
362 echo (" border-top:1pt solid black;\n");
364 echo ("div.paddingdiv {\n");
365 echo (" width: 524pt;\n");
366 echo (" height: 668pt;\n");
367 echo (" page-break-after: always;\n");
369 echo ("div.scriptdiv {\n");
370 echo (" padding-top: 12pt;\n");
371 echo (" padding-bottom: 22pt;\n");
372 echo (" padding-left: 35pt;\n");
373 echo (" border-bottom:1pt solid black;\n");
375 echo ("div.signdiv {\n");
376 echo (" margin-top: 40pt;\n");
377 echo (" font-size: 12pt;\n");
381 echo ("<title>" . xl('Prescription') . "</title>\n");
386 function multiprintfax_footer( & $pdf ) {
387 return $this->multiprint_footer( $pdf );
390 function multiprint_footer(& $pdf) {
391 if($this->pconfig
['use_signature'] && ( $this->is_faxing ||
$this->is_print_to_fax
) ) {
392 $sigfile = str_replace('{userid}', $_SESSION{"authUser"}, $this->pconfig
['signature']);
393 if (file_exists($sigfile)) {
394 $pdf->ezText( xl('Signature') . ": ",12);
395 // $pdf->ezImage($sigfile, "", "", "none", "left");
396 $pdf->ezImage($sigfile, "", "", "none", "center");
397 $pdf->ezText( xl('Date') . ": " . date('Y-m-d'), 12);
398 if ( $this->is_print_to_fax
) {
399 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
402 $addenumFile = $this->pconfig
['addendum_file'];
403 if ( file_exists( $addenumFile ) ) {
405 $f = fopen($addenumFile, "r");
406 while ( $line = fgets($f, 1000) ) {
407 $pdf->ezText(rtrim($line));
414 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'),12);
417 function multiprintcss_footer() {
418 echo ("<div class='signdiv'>\n");
419 echo (xl('Signature') . ":________________________________<br>");
420 echo (xl('Date') . ": " . date('Y-m-d'));
425 function multiprintcss_postfooter() {
426 echo("<script language='JavaScript'>\n");
427 echo("window.print();\n");
433 function get_prescription_body_text($p) {
434 $body = '<b>' . xl('Rx') . ': ' . $p->get_drug() . ' ' . $p->get_size() . ' ' . $p->get_unit_display();
435 if ($p->get_form()) $body .= ' [' . $p->form_array
[$p->get_form()] . "]";
436 $body .= "</b> <i>" .
437 $p->substitute_array
[$p->get_substitute()] . "</i>\n" .
438 '<b>' . xl('Disp #') . ':</b> <u>' . $p->get_quantity() . "</u>\n" .
439 '<b>' . xl('Sig') . ':</b> ' . $p->get_dosage() . ' ' . $p->form_array
[$p->get_form()] . ' ' .
440 $p->route_array
[$p->get_route()] . ' ' . $p->interval_array
[$p->get_interval()] . "\n";
441 if ($p->get_refills() > 0) {
442 $body .= "\n<b>" . xl('Refills') . ":</b> <u>" . $p->get_refills();
443 if ($p->get_per_refill()) {
444 $body .= " " . xl('of quantity') . " " . $p->get_per_refill();
449 $body .= "\n<b>" . xl('Refills') . ":</b> <u>0 (" . xl('Zero') . ")</u>\n";
451 $note = $p->get_note();
453 $body .= "\n$note\n";
458 function multiprintfax_body(& $pdf, $p){
459 return $this->multiprint_body( $pdf, $p );
462 function multiprint_body(& $pdf, $p){
463 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
464 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
465 $d = $this->get_prescription_body_text($p);
466 if ( $pdf->ezText($d,10,array(),1) ) {
467 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
468 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
469 $this->multiprint_footer($pdf);
471 $this->multiprint_header($pdf, $p);
472 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
473 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
477 if($this->pconfig
['shading']) {
478 $pdf->setColor(.9,.9,.9);
479 $pdf->filledRectangle($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin']-$pdf->ez
['leftMargin'],$my_y - $pdf->y
);
480 $pdf->setColor(0,0,0);
484 $pdf->ez
['leftMargin'] = $GLOBALS['oer_config']['prescriptions']['left'];
485 $pdf->ez
['rightMargin'] = $GLOBALS['oer_config']['prescriptions']['right'];
487 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
491 function multiprintcss_body($p){
492 $d = $this->get_prescription_body_text($p);
493 $patterns = array ('/\n/','/ /');
494 $replace = array ('<br>',' ');
495 $d = preg_replace($patterns, $replace, $d);
496 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
499 function multiprintfax_action($id = "") {
500 $this->is_print_to_fax
=true;
501 return $this->multiprint_action( $id );
504 function multiprint_action($id = "") {
505 $_POST['process'] = "true";
507 $this->function_argument_error();
509 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
510 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
511 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
512 ,$GLOBALS['oer_config']['prescriptions']['bottom']
513 ,$GLOBALS['oer_config']['prescriptions']['left']
514 ,$GLOBALS['oer_config']['prescriptions']['right']
516 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
518 // $print_header = true;
521 //print prescriptions body
522 $this->_state
= false; // Added by Rod - see Controller.class.php
523 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
524 foreach ($ids as $id) {
525 $p = new Prescription($id);
526 // if ($print_header == true) {
527 if ($on_this_page == 0) {
528 $this->multiprint_header($pdf, $p);
530 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
531 $this->multiprint_footer($pdf);
533 $this->multiprint_header($pdf, $p);
534 // $print_header = false;
537 $this->multiprint_body($pdf, $p);
540 $this->multiprint_footer($pdf);
546 function multiprintcss_action($id = "") {
547 $_POST['process'] = "true";
549 $this->function_argument_error();
552 $this->multiprintcss_preheader();
554 $this->_state
= false; // Added by Rod - see Controller.class.php
555 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
558 foreach ($ids as $id) {
559 $p = new Prescription($id);
560 if ($on_this_page == 0) {
561 $this->multiprintcss_header($p);
563 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
564 $this->multiprintcss_footer();
565 $this->multiprintcss_header($p);
568 $this->multiprintcss_body($p);
570 $this->multiprintcss_footer();
571 $this->multiprintcss_postfooter();
575 function send_action_process($id) {
576 $dummy = ""; // Added by Rod to avoid run-time warnings
577 if ($_POST['process'] != "true")
580 $this->function_argument_error();
582 $p = new Prescription($id);
583 switch ($_POST['submit']) {
585 case (xl("Print")." (".xl("PDF").")"):
586 // The following statement added by Rod.
587 // Looking at Controller.class.php, it appears that _state is set to false
588 // to indicate that no further HTML is to be generated.
589 $this->_state
= false; // Added by Rod - see Controller.class.php
590 return $this->_print_prescription($p, $dummy);
592 case (xl("Print")." (".xl("HTML").")"):
593 $this->_state
= false;
594 return $this->_print_prescription_css($p, $dummy);
596 case xl("Print To Fax"):
597 $this->_state
= false;
598 $this->is_print_to_fax
= true;
599 return $this->_print_prescription($p, $dummy);
602 return $this->_email_prescription($p,$_POST['email_to']);
605 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
606 //$this->assign("process_result","No fax server is currently setup.");
607 return $this->_fax_prescription($p,$_POST['fax_to']);
609 case xl("Auto Send"):
610 $pharmacy_id = $_POST['pharmacy_id'];
611 //echo "auto sending to : " . $_POST['pharmacy_id'];
612 $phar = new Pharmacy($_POST['pharmacy_id']);
614 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
615 return $this->_print_prescription($p, $dummy);
617 elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
618 $email = $phar->get_email();
619 if (!empty($email)) {
620 return $this->_email_prescription($p,$phar->get_email());
624 elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
625 $faxNum= $phar->get_fax();
626 if(!empty($faxNum)) {
627 Return $this->_fax_prescription ($p,$faxNum);
629 // return $this->assign("process_result","No fax server is currently setup.");
630 // else default is printing,
633 //the pharmacy has no default or default is print
634 return $this->_print_prescription($p, $dummy);
643 function _print_prescription($p, & $toFile) {
644 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
645 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
646 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
647 ,$GLOBALS['oer_config']['prescriptions']['bottom']
648 ,$GLOBALS['oer_config']['prescriptions']['left']
649 ,$GLOBALS['oer_config']['prescriptions']['right']
652 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
654 // Signature images are to be used only when faxing.
655 if(!empty($toFile)) $this->is_faxing
= true;
657 $this->multiprint_header($pdf, $p);
658 $this->multiprint_body($pdf, $p);
659 $this->multiprint_footer($pdf);
661 if(!empty($toFile)) {
662 $toFile = $pdf->ezOutput();
666 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
671 function _print_prescription_css($p, & $toFile) {
673 $this->multiprintcss_preheader();
674 $this->multiprintcss_header($p);
675 $this->multiprintcss_body($p);
676 $this->multiprintcss_footer();
677 $this->multiprintcss_postfooter();
681 function _print_prescription_old($p, & $toFile) {
682 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
683 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
684 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
685 ,$GLOBALS['oer_config']['prescriptions']['bottom']
686 ,$GLOBALS['oer_config']['prescriptions']['left']
687 ,$GLOBALS['oer_config']['prescriptions']['right']
689 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
690 if(!empty($this->pconfig
['logo'])) {
691 $pdf->ezImage($this->pconfig
['logo'],"","","none","left");
693 $pdf->ezText($p->get_prescription_display(),10);
694 if($this->pconfig
['use_signature']) {
695 $pdf->ezImage($this->pconfig
['signature'],"","","none","left");
698 $pdf->ezText("\n\n\n\nSignature:________________________________",10);
702 $toFile = $pdf->ezOutput();
707 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
712 function _email_prescription($p,$email) {
714 $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
717 require($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php");
718 $mail = new PHPMailer();
719 $mail->SetLanguage("en",$GLOBALS['fileroot'] . "/library/" );
720 //this is a temporary config item until the rest of the per practice billing settings make their way in
721 $mail->From
= $GLOBALS['practice_return_email_path'];
722 $mail->FromName
= $p->provider
->get_name_display();
724 $mail->Host
= "localhost";
725 $mail->Mailer
= "mail";
726 $text_body = $p->get_prescription_display();
727 $mail->Body
= $text_body;
728 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
729 $mail->AddAddress($email);
731 $this->assign("process_result","Email was successfully sent to: " . $email);
735 $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
740 function do_lookup() {
741 if ($_POST['process'] != "true") {
743 $this->assign("drug", $_GET['drug']);
747 // process the lookup
748 $this->assign("drug", $_POST['drug']);
750 if (!empty($_POST['drug'])) {
751 $list = @RxList
::get_list($_POST['drug']);
754 if (is_array($list)) {
755 $list = array_flip($list);
756 $this->assign("drug_options",$list);
757 $this->assign("drug_values",array_keys($list));
760 $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
763 //$this->assign("PROCESS","");
765 $_POST['process'] = "";
768 function _fax_prescription($p,$faxNum)
771 //strip - ,(, ), and ws
772 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum);
773 //validate the number
775 if(!empty($faxNum) && is_numeric($faxNum))
777 //get the sendfax command and execute it
778 $cmd = $this->pconfig
['sendfax'];
779 // prepend any prefix to the fax number
780 $pref=$this->pconfig
['prefix'];
781 $faxNum=$pref.$faxNum;
784 $err .= " Send fax not set in includes/config.php";
789 //generate file to fax
791 $this->_print_prescription($p, $faxFile);
794 $err .= " _print_prescription returned empty file";
797 $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() .
798 $p->get_patient_id() . "_fax_.pdf";
799 //print "filename is $fileName";
800 touch($fileName); // php bug
801 $handle = fopen($fileName,"w");
804 $err .= " Failed to open file $fileName to write fax to";
807 if(fwrite($handle, $faxFile) === false)
809 $err .= " Failed to write data to $fileName";
813 $args = " -n -d $faxNum $fileName";
814 //print "command is $cmd $args<br>";
821 $err = "bad fax number passed to function";
825 $this->assign("process_result",$err);