3 * This script print Prescriptions.
5 * Copyright (C) 2015 Roberto Vasquez <robertogagliotta@gmail.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 2
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 Roberto Vasquez <robertogagliotta@gmail.com>
20 * @link http://www.open-emr.org
24 require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php");
25 require_once($GLOBALS['fileroot'] . "/library/registry.inc");
26 require_once($GLOBALS['fileroot'] . "/library/amc.php");
28 class C_Prescription
extends Controller
34 var $is_faxing = false;
35 var $is_print_to_fax = false;
37 function __construct($template_mod = "general")
39 parent
::__construct();
41 $this->template_mod
= $template_mod;
42 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
43 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
44 $this->assign("STYLE", $GLOBALS['style']);
45 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
46 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
47 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
48 $this->assign("CSS_HEADER", $GLOBALS['css_header']);
49 $this->assign("WEB_ROOT", $GLOBALS['webroot']);
50 $this->RxList
= new RxList();
52 if ($GLOBALS['inhouse_pharmacy']) {
53 // Make an array of drug IDs and selectors for the template.
54 $drug_array_values = array(0);
55 $drug_array_output = array("-- " . xl('or select from inventory') ." --");
56 $drug_attributes = '';
58 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
60 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
61 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
62 "t.period, t.quantity, t.refills, d.drug_code " .
63 "FROM drug_templates AS t, drugs AS d WHERE " .
64 "d.drug_id = t.drug_id ORDER BY t.selector");
66 while ($row = sqlFetchArray($res)) {
67 $tmp_output = $row['selector'];
68 if ($row['ndc_number']) {
69 $tmp_output .= ' [' . $row['ndc_number'] . ']';
72 $drug_array_values[] = $row['drug_id'];
73 $drug_array_output[] = $tmp_output;
74 if ($drug_attributes) {
75 $drug_attributes .= ',';
78 $drug_attributes .= "['" .
79 $row['name'] . "'," . // 0
80 $row['form'] . ",'" . // 1
81 $row['dosage'] . "','" . // 2
82 $row['size'] . "'," . // 3
83 $row['unit'] . "," . // 4
84 $row['route'] . "," . // 5
85 $row['period'] . "," . // 6
86 $row['substitute'] . "," . // 7
87 $row['quantity'] . "," . // 8
88 $row['refills'] . "," . // 9
89 $row['quantity'] . "," . // 10 quantity per_refill
90 $row['drug_code'] . "]"; // 11 rxnorm drug code
93 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
94 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
95 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
99 function default_action()
101 $this->assign("prescription", $this->prescriptions
[0]);
102 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
105 function edit_action($id = "", $patient_id = "", $p_obj = null)
108 if ($p_obj != null && get_class($p_obj) == "prescription") {
109 $this->prescriptions
[0] = $p_obj;
110 } elseif (get_class($this->prescriptions
[0]) != "prescription") {
111 $this->prescriptions
[0] = new Prescription($id);
114 if (!empty($patient_id)) {
115 $this->prescriptions
[0]->set_patient_id($patient_id);
118 // If quantity to dispense is not already set from a POST, set its
120 if (! $this->get_template_vars('DISP_QUANTITY')) {
121 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
124 $this->default_action();
127 function list_action($id, $sort = "")
130 $this->function_argument_error();
135 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
137 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
140 // flag to indicate the CAMOS form is regsitered and active
141 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
143 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
146 function block_action($id, $sort = "")
149 $this->function_argument_error();
154 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
156 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
159 //print_r(Prescription::prescriptions_factory($id));
160 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
163 function fragment_action($id, $sort = "")
166 $this->function_argument_error();
171 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
173 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
176 //print_r(Prescription::prescriptions_factory($id));
177 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_fragment.html");
180 function lookup_action()
183 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
186 function edit_action_process()
188 if ($_POST['process'] != "true") {
194 // Stupid Smarty code treats empty values as not specified values.
195 // Since active is a checkbox, represent the unchecked state as -1.
196 if (empty($_POST['active'])) {
197 $_POST['active'] = '-1';
200 $this->prescriptions
[0] = new Prescription($_POST['id']);
201 parent
::populate_object($this->prescriptions
[0]);
202 //echo $this->prescriptions[0]->toString(true);
203 $this->prescriptions
[0]->persist();
204 $_POST['process'] = "";
206 // If the "Prescribe and Dispense" button was clicked, then
207 // redisplay as in edit_action() but also replicate the fee and
208 // include a piece of javascript to call dispense().
210 if ($_POST['disp_button']) {
211 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
212 $this->assign("DISP_FEE", $_POST['disp_fee']);
213 $this->assign("ENDING_JAVASCRIPT", "dispense();");
214 $this->_state
= false;
215 return $this->edit_action($this->prescriptions
[0]->id
);
218 // Set the AMC reporting flag (to record percentage of prescriptions that
219 // are set as e-prescriptions)
220 if (!(empty($_POST['escribe_flag']))) {
221 // add the e-prescribe flag
222 processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
224 // remove the e-prescribe flag
225 processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
228 // Set the AMC reporting flag (to record prescriptions that checked drug formulary)
229 if (!(empty($_POST['checked_formulary_flag']))) {
230 // add the e-prescribe flag
231 processAmcCall('e_prescribe_chk_formulary_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
233 // remove the e-prescribe flag
234 processAmcCall('e_prescribe_chk_formulary_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
237 // Set the AMC reporting flag (to record prescriptions that are controlled substances)
238 if (!(empty($_POST['controlled_substance_flag']))) {
239 // add the e-prescribe flag
240 processAmcCall('e_prescribe_cont_subst_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
242 // remove the e-prescribe flag
243 processAmcCall('e_prescribe_cont_subst_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
246 // TajEmo Work by CB 2012/05/29 02:58:29 PM to stop from going to send screen. Improves Work Flow
247 // if ($this->prescriptions[0]->get_active() > 0) {
248 // return $this->send_action($this->prescriptions[0]->id);
250 $this->list_action($this->prescriptions
[0]->get_patient_id());
254 function send_action($id)
256 $_POST['process'] = "true";
258 $this->function_argument_error();
261 $rx = new Prescription($id);
262 // Populate pharmacy info if the patient has a default pharmacy.
263 // Probably the Prescription object should handle this instead, but
264 // doing it there will require more careful research and testing.
265 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
266 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
267 if ($prow['pharmacy_id']) {
268 $rx->pharmacy
->set_id($prow['pharmacy_id']);
269 $rx->pharmacy
->populate();
272 $this->assign("prescription", $rx);
274 $this->_state
= false;
275 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
276 $this->template_mod
. "_send.html");
279 function multiprintfax_header(& $pdf, $p)
281 return $this->multiprint_header($pdf, $p);
284 function multiprint_header(& $pdf, $p)
286 $this->providerid
= $p->provider
->id
;
288 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'], '', '50', '', 'center', '');
289 $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10));
290 $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 ='" .
291 add_escape_custom($p->provider
->id
) . "'");
292 $pdf->ezText($res['addr'], 12);
295 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>', 12);
296 // A client had a bad experience with a patient misusing a DEA number, so
297 // now the doctors write those in on printed prescriptions and only when
298 // necessary. If you need to change this back, then please make it a
299 // configurable option. Faxed prescriptions were not changed. -- Rod
300 // Now it is configureable. Change value in
301 // Administration->Globals->Rx
302 if ($GLOBALS['rx_enable_DEA']) {
303 if ($this->is_faxing ||
$GLOBALS['rx_show_DEA']) {
304 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
, 12);
306 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
310 if ($GLOBALS['rx_enable_NPI']) {
311 if ($this->is_faxing ||
$GLOBALS['rx_show_NPI']) {
312 $pdf->ezText('<b>' . xl('NPI') . ':</b>' . $p->provider
->npi
, 12);
314 $pdf->ezText('<b>' . xl('NPI') . ':</b> _________________________', 12);
318 if ($GLOBALS['rx_enable_SLN']) {
319 if ($this->is_faxing ||
$GLOBALS['rx_show_SLN']) {
320 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
, 12);
322 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b> ___________________', 12);
326 $pdf->ezColumnsStop();
327 if ($my_y < $pdf->y
) {
331 $pdf->ezText('', 10);
332 $pdf->setLineStyle(1);
333 $pdf->ezColumnsStart(array('num'=>2));
334 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'], $pdf->y
);
335 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>', 6);
336 $pdf->ezText($p->patient
->get_name_display(), 10);
337 $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 =". add_escape_custom($p->patient
->id
));
338 $pdf->ezText($res['addr']);
341 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'], $pdf->y
);
342 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>', 6);
343 $pdf->ezText($p->patient
->date_of_birth
, 10);
345 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'], $pdf->y
);
346 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>', 6);
347 $pdf->ezText(str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
), 10);
348 $pdf->ezColumnsStop();
349 if ($my_y < $pdf->y
) {
354 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'], $pdf->y
);
355 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>', 6);
356 $pdf->ezText('', 10);
359 function multiprintcss_header($p)
361 echo("<div class='paddingdiv'>\n");
362 $this->providerid
= $p->provider
->id
;
363 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
365 echo ("<td></td>\n");
367 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
372 $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 ='" . add_escape_custom($p->provider
->id
) . "'");
374 $patterns = array ('/\n/','/Tel:/','/Fax:/');
375 $replace = array ('<br>', xl('Tel').':', xl('Fax').':');
376 $res = preg_replace($patterns, $replace, $res);
379 echo ('<span class="large">' . $res['addr'] . '</span>');
382 echo ('<b><span class="large">' . $p->provider
->get_name_display() . '</span></b>'. '<br>');
384 if ($GLOBALS['rx_enable_DEA']) {
385 if ($GLOBALS['rx_show_DEA']) {
386 echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
. '</span><br>');
388 echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________<br>' );
392 if ($GLOBALS['rx_enable_NPI']) {
393 if ($GLOBALS['rx_show_NPI']) {
394 echo ('<span class="large"><b>' . xl('NPI') . ':</b>' . $p->provider
->npi
. '</span><br>');
396 echo ('<b><span class="large">' . xl('NPI') . ':</span></b> ________________________<br>');
400 if ($GLOBALS['rx_enable_SLN']) {
401 if ($GLOBALS['rx_show_SLN']) {
402 echo ('<span class="large"><b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
. '</span><br>');
404 echo ('<b><span class="large">' . xl('State Lic. #') . ':</span></b> ________________________<br>');
411 echo ("<td rowspan='2' class='bordered'>\n");
412 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>'. '<br>');
413 echo ($p->patient
->get_name_display() . '<br>');
414 $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 =". add_escape_custom($p->patient
->id
));
416 $patterns = array ('/\n/');
417 $replace = array ('<br>');
418 $res = preg_replace($patterns, $replace, $res);
423 echo ("<td class='bordered'>\n");
424 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br>');
425 echo ($p->patient
->date_of_birth
);
429 echo ("<td class='bordered'>\n");
430 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br>');
431 echo (str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
));
435 echo ("<td colspan='2' class='bordered'>\n");
436 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
442 function multiprintcss_preheader()
444 // this sets styling and other header information of the multiprint css sheet
449 echo (" padding: 0;\n");
450 echo (" margin: 0;\n");
453 echo (" font-family: sans-serif;\n");
454 echo (" font-weight: normal;\n");
455 echo (" font-size: 10pt;\n");
456 echo (" background: white;\n");
457 echo (" color: black;\n");
459 echo ("span.large {\n");
460 echo (" font-size: 12pt;\n");
462 echo ("span.small {\n");
463 echo (" font-size: 6pt;\n");
466 echo (" vertical-align: top;\n");
467 echo (" width: 50%;\n");
468 echo (" font-size: 10pt;\n");
469 echo (" padding-bottom: 8pt;\n");
471 echo ("td.bordered {\n");
472 echo (" border-top:1pt solid black;\n");
474 echo ("div.paddingdiv {\n");
475 echo (" width: 524pt;\n");
476 echo (" height: 668pt;\n");
478 echo ("div.scriptdiv {\n");
479 echo (" padding-top: 12pt;\n");
480 echo (" padding-bottom: 22pt;\n");
481 echo (" padding-left: 35pt;\n");
482 echo (" border-bottom:1pt solid black;\n");
484 echo ("div.signdiv {\n");
485 echo (" margin-top: 40pt;\n");
486 echo (" font-size: 12pt;\n");
490 echo ("<title>" . xl('Prescription') . "</title>\n");
495 function multiprintfax_footer(& $pdf)
497 return $this->multiprint_footer($pdf);
500 function multiprint_footer(& $pdf)
502 if ($this->pconfig
['use_signature'] && ( $this->is_faxing ||
$this->is_print_to_fax
)) {
503 $sigfile = str_replace('{userid}', $_SESSION{"authUser"}, $this->pconfig
['signature']);
504 if (file_exists($sigfile)) {
505 $pdf->ezText(xl('Signature') . ": ", 12);
506 // $pdf->ezImage($sigfile, "", "", "none", "left");
507 $pdf->ezImage($sigfile, "", "", "none", "center");
508 $pdf->ezText(xl('Date') . ": " . date('Y-m-d'), 12);
509 if ($this->is_print_to_fax
) {
510 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
513 $addenumFile = $this->pconfig
['addendum_file'];
514 if (file_exists($addenumFile)) {
516 $f = fopen($addenumFile, "r");
517 while ($line = fgets($f, 1000)) {
518 $pdf->ezText(rtrim($line));
526 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'), 12);
529 function multiprintcss_footer()
531 echo ("<div class='signdiv'>\n");
532 echo (xl('Signature') . ":________________________________<br>");
533 echo (xl('Date') . ": " . date('Y-m-d'));
538 function multiprintcss_postfooter()
540 echo("<script language='JavaScript'>\n");
541 echo("opener.top.printLogPrint(window);\n");
547 function get_prescription_body_text($p)
549 $body = '<b>' . xlt('Rx') . ': ' . text($p->get_drug()) . ' ' . text($p->get_size()) . ' ' . text($p->get_unit_display());
550 if ($p->get_form()) {
551 $body .= ' [' . text($p->form_array
[$p->get_form()]) . "]";
554 $body .= "</b> <i>" .
555 text($p->substitute_array
[$p->get_substitute()]) . "</i>\n" .
556 '<b>' . xlt('Disp #') . ':</b> <u>' . text($p->get_quantity()) . "</u>\n" .
557 '<b>' . xlt('Sig') . ':</b> ' . text($p->get_dosage()) . ' ' . text($p->form_array
[$p->get_form()]) . ' ' .
558 text($p->route_array
[$p->get_route()]) . ' ' . text($p->interval_array
[$p->get_interval()]) . "\n";
559 if ($p->get_refills() > 0) {
560 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>" . text($p->get_refills());
561 if ($p->get_per_refill()) {
562 $body .= " " . xlt('of quantity') . " " . text($p->get_per_refill());
567 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>0 (" . xlt('Zero') . ")</u>\n";
570 $note = $p->get_note();
572 $body .= "\n" . text($note) . "\n";
578 function multiprintfax_body(& $pdf, $p)
580 return $this->multiprint_body($pdf, $p);
583 function multiprint_body(& $pdf, $p)
585 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
586 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
587 $d = $this->get_prescription_body_text($p);
588 if ($pdf->ezText($d, 10, array(), 1)) {
589 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
590 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
591 $this->multiprint_footer($pdf);
593 $this->multiprint_header($pdf, $p);
594 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
595 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
599 $pdf->ezText($d, 10);
600 if ($this->pconfig
['shading']) {
601 $pdf->setColor(.9, .9, .9);
602 $pdf->filledRectangle($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth']-$pdf->ez
['rightMargin']-$pdf->ez
['leftMargin'], $my_y - $pdf->y
);
603 $pdf->setColor(0, 0, 0);
607 $pdf->ezText($d, 10);
608 $pdf->ez
['leftMargin'] = $GLOBALS['rx_left_margin'];
609 $pdf->ez
['rightMargin'] = $GLOBALS['rx_right_margin'];
611 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'], $pdf->y
);
615 function multiprintcss_body($p)
617 $d = $this->get_prescription_body_text($p);
618 $patterns = array ('/\n/','/ /');
619 $replace = array ('<br>',' ');
620 $d = preg_replace($patterns, $replace, $d);
621 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
624 function multiprintfax_action($id = "")
626 $this->is_print_to_fax
=true;
627 return $this->multiprint_action($id);
630 function multiprint_action($id = "")
632 $_POST['process'] = "true";
634 $this->function_argument_error();
637 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
638 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
639 $pdf->selectFont('Helvetica');
641 // $print_header = true;
644 //print prescriptions body
645 $this->_state
= false; // Added by Rod - see Controller.class.php
646 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
647 foreach ($ids as $id) {
648 $p = new Prescription($id);
649 // if ($print_header == true) {
650 if ($on_this_page == 0) {
651 $this->multiprint_header($pdf, $p);
654 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
655 $this->multiprint_footer($pdf);
657 $this->multiprint_header($pdf, $p);
658 // $print_header = false;
662 $this->multiprint_body($pdf, $p);
665 $this->multiprint_footer($pdf);
667 $pFirstName = $p->patient
->fname
; //modified by epsdky for prescription title change to include patient name and ID
668 $pFName = convert_safe_file_dir_name($pFirstName);
669 $modedFileName = "Rx_{$pFName}_{$p->patient->id}.pdf";
671 $pdf->ezStream(array('Content-Disposition' => $modedFileName));
675 function multiprintcss_action($id = "")
677 $_POST['process'] = "true";
679 $this->function_argument_error();
682 $this->multiprintcss_preheader();
684 $this->_state
= false; // Added by Rod - see Controller.class.php
685 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
688 foreach ($ids as $id) {
689 $p = new Prescription($id);
690 if ($on_this_page == 0) {
691 $this->multiprintcss_header($p);
694 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
695 $this->multiprintcss_footer();
696 $this->multiprintcss_header($p);
700 $this->multiprintcss_body($p);
703 $this->multiprintcss_footer();
704 $this->multiprintcss_postfooter();
708 function send_action_process($id)
710 $dummy = ""; // Added by Rod to avoid run-time warnings
711 if ($_POST['process'] != "true") {
716 $this->function_argument_error();
719 $p = new Prescription($id);
720 switch ($_POST['submit']) {
721 case (xl("Print")." (".xl("PDF").")"):
722 // The following statement added by Rod.
723 // Looking at Controller.class.php, it appears that _state is set to false
724 // to indicate that no further HTML is to be generated.
725 $this->_state
= false; // Added by Rod - see Controller.class.php
726 return $this->_print_prescription($p, $dummy);
728 case (xl("Print")." (".xl("HTML").")"):
729 $this->_state
= false;
730 return $this->_print_prescription_css($p, $dummy);
732 case xl("Print To Fax"):
733 $this->_state
= false;
734 $this->is_print_to_fax
= true;
735 return $this->_print_prescription($p, $dummy);
738 return $this->_email_prescription($p, $_POST['email_to']);
741 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
742 //$this->assign("process_result","No fax server is currently setup.");
743 return $this->_fax_prescription($p, $_POST['fax_to']);
745 case xl("Auto Send"):
746 $pharmacy_id = $_POST['pharmacy_id'];
747 //echo "auto sending to : " . $_POST['pharmacy_id'];
748 $phar = new Pharmacy($_POST['pharmacy_id']);
750 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
751 return $this->_print_prescription($p, $dummy);
752 } elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
753 $email = $phar->get_email();
754 if (!empty($email)) {
755 return $this->_email_prescription($p, $phar->get_email());
759 } elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
760 $faxNum= $phar->get_fax();
761 if (!empty($faxNum)) {
762 return $this->_fax_prescription($p, $faxNum);
765 // return $this->assign("process_result","No fax server is currently setup.");
766 // else default is printing,
768 //the pharmacy has no default or default is print
769 return $this->_print_prescription($p, $dummy);
777 function _print_prescription($p, & $toFile)
779 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
780 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
782 $pdf->selectFont('Helvetica');
784 // Signature images are to be used only when faxing.
785 if (!empty($toFile)) {
786 $this->is_faxing
= true;
789 $this->multiprint_header($pdf, $p);
790 $this->multiprint_body($pdf, $p);
791 $this->multiprint_footer($pdf);
793 if (!empty($toFile)) {
794 $toFile = $pdf->ezOutput();
797 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
803 function _print_prescription_css($p, & $toFile)
806 $this->multiprintcss_preheader();
807 $this->multiprintcss_header($p);
808 $this->multiprintcss_body($p);
809 $this->multiprintcss_footer();
810 $this->multiprintcss_postfooter();
813 function _print_prescription_old($p, & $toFile)
815 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
816 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
817 $pdf->selectFont('Helvetica');
818 if (!empty($this->pconfig
['logo'])) {
819 $pdf->ezImage($this->pconfig
['logo'], "", "", "none", "left");
822 $pdf->ezText($p->get_prescription_display(), 10);
823 if ($this->pconfig
['use_signature']) {
824 $pdf->ezImage($this->pconfig
['signature'], "", "", "none", "left");
826 $pdf->ezText("\n\n\n\nSignature:________________________________", 10);
829 if (!empty($toFile)) {
830 $toFile = $pdf->ezOutput();
833 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
839 function _email_prescription($p, $email)
842 $this->assign("process_result", "Email could not be sent, the address supplied: '$email' was empty or invalid.");
846 $mail = new PHPMailer();
847 //this is a temporary config item until the rest of the per practice billing settings make their way in
848 $mail->From
= $GLOBALS['practice_return_email_path'];
849 $mail->FromName
= $p->provider
->get_name_display();
851 $mail->Host
= "localhost";
852 $mail->Mailer
= "mail";
853 $text_body = $p->get_prescription_display();
854 $mail->Body
= $text_body;
855 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
856 $mail->AddAddress($email);
858 $this->assign("process_result", "Email was successfully sent to: " . $email);
861 $this->assign("process_result", "There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
868 if ($_POST['process'] != "true") {
870 $this->assign("drug", $_GET['drug']);
874 // process the lookup
875 $this->assign("drug", $_POST['drug']);
877 if (!empty($_POST['drug'])) {
878 $list = $this->RxList
->get_list($_POST['drug']);
881 if (is_array($list)) {
882 $list = array_flip($list);
883 $this->assign("drug_options", $list);
884 $this->assign("drug_values", array_keys($list));
886 $this->assign("NO_RESULTS", "No results found for: " .$_POST['drug'] . "<br />");
890 //$this->assign("PROCESS","");
892 $_POST['process'] = "";
895 function _fax_prescription($p, $faxNum)
898 //strip - ,(, ), and ws
899 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/", "", $faxNum);
900 //validate the number
902 if (!empty($faxNum) && is_numeric($faxNum)) {
903 //get the sendfax command and execute it
904 $cmd = $this->pconfig
['sendfax'];
905 // prepend any prefix to the fax number
906 $pref=$this->pconfig
['prefix'];
907 $faxNum=$pref.$faxNum;
909 $err .= " Send fax not set in includes/config.php";
911 //generate file to fax
913 $this->_print_prescription($p, $faxFile);
914 if (empty($faxFile)) {
915 $err .= " _print_prescription returned empty file";
918 $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() .
919 $p->get_patient_id() . "_fax_.pdf";
920 //print "filename is $fileName";
921 touch($fileName); // php bug
922 $handle = fopen($fileName, "w");
924 $err .= " Failed to open file $fileName to write fax to";
927 if (fwrite($handle, $faxFile) === false) {
928 $err .= " Failed to write data to $fileName";
932 $args = " -n -d $faxNum $fileName";
933 //print "command is $cmd $args<br>";
937 $err = "bad fax number passed to function";
941 $this->assign("process_result", $err);