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
{
33 var $is_faxing = false;
34 var $is_print_to_fax = false;
36 function __construct($template_mod = "general") {
37 parent
::__construct();
39 $this->template_mod
= $template_mod;
40 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
41 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
42 $this->assign("STYLE", $GLOBALS['style']);
43 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
44 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
45 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
46 $this->assign("CSS_HEADER", $GLOBALS['css_header'] );
47 $this->assign("WEB_ROOT", $GLOBALS['webroot'] );
48 $this->RxList
= new RxList();
50 if ($GLOBALS['inhouse_pharmacy']) {
51 // Make an array of drug IDs and selectors for the template.
52 $drug_array_values = array(0);
53 $drug_array_output = array("-- " . xl('or select from inventory') ." --");
54 $drug_attributes = '';
56 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
58 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
59 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
60 "t.period, t.quantity, t.refills, d.drug_code " .
61 "FROM drug_templates AS t, drugs AS d WHERE " .
62 "d.drug_id = t.drug_id ORDER BY t.selector");
64 while ($row = sqlFetchArray($res)) {
65 $tmp_output = $row['selector'];
66 if ($row['ndc_number']) {
67 $tmp_output .= ' [' . $row['ndc_number'] . ']';
69 $drug_array_values[] = $row['drug_id'];
70 $drug_array_output[] = $tmp_output;
71 if ($drug_attributes) $drug_attributes .= ',';
72 $drug_attributes .= "['" .
73 $row['name'] . "'," . // 0
74 $row['form'] . ",'" . // 1
75 $row['dosage'] . "','" . // 2
76 $row['size'] . "'," . // 3
77 $row['unit'] . "," . // 4
78 $row['route'] . "," . // 5
79 $row['period'] . "," . // 6
80 $row['substitute'] . "," . // 7
81 $row['quantity'] . "," . // 8
82 $row['refills'] . "," . // 9
83 $row['quantity'] . "," . // 10 quantity per_refill
84 $row['drug_code'] . "]"; // 11 rxnorm drug code
86 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
87 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
88 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
92 function default_action() {
93 $this->assign("prescription",$this->prescriptions
[0]);
94 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
97 function edit_action($id = "",$patient_id="",$p_obj = null) {
99 if ($p_obj != null && get_class($p_obj) == "prescription") {
100 $this->prescriptions
[0] = $p_obj;
102 elseif (get_class($this->prescriptions
[0]) != "prescription" ) {
103 $this->prescriptions
[0] = new Prescription($id);
106 if (!empty($patient_id)) {
107 $this->prescriptions
[0]->set_patient_id($patient_id);
110 // If quantity to dispense is not already set from a POST, set its
112 if (! $this->get_template_vars('DISP_QUANTITY')) {
113 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
116 $this->default_action();
119 function list_action($id,$sort = "") {
121 $this->function_argument_error();
125 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
128 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
131 // flag to indicate the CAMOS form is regsitered and active
132 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
134 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
137 function block_action($id,$sort = "") {
139 $this->function_argument_error();
143 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
146 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
148 //print_r(Prescription::prescriptions_factory($id));
149 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
152 function fragment_action($id,$sort = "") {
154 $this->function_argument_error();
158 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
161 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
163 //print_r(Prescription::prescriptions_factory($id));
164 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_fragment.html");
167 function lookup_action() {
169 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
172 function edit_action_process() {
173 if ($_POST['process'] != "true")
177 // Stupid Smarty code treats empty values as not specified values.
178 // Since active is a checkbox, represent the unchecked state as -1.
179 if (empty($_POST['active'])) $_POST['active'] = '-1';
181 $this->prescriptions
[0] = new Prescription($_POST['id']);
182 parent
::populate_object($this->prescriptions
[0]);
183 //echo $this->prescriptions[0]->toString(true);
184 $this->prescriptions
[0]->persist();
185 $_POST['process'] = "";
187 // If the "Prescribe and Dispense" button was clicked, then
188 // redisplay as in edit_action() but also replicate the fee and
189 // include a piece of javascript to call dispense().
191 if ($_POST['disp_button']) {
192 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
193 $this->assign("DISP_FEE", $_POST['disp_fee']);
194 $this->assign("ENDING_JAVASCRIPT", "dispense();");
195 $this->_state
= false;
196 return $this->edit_action($this->prescriptions
[0]->id
);
199 // Set the AMC reporting flag (to record percentage of prescriptions that
200 // are set as e-prescriptions)
201 if (!(empty($_POST['escribe_flag']))) {
202 // add the e-prescribe flag
203 processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
206 // remove the e-prescribe flag
207 processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
210 // Set the AMC reporting flag (to record prescriptions that checked drug formulary)
211 if (!(empty($_POST['checked_formulary_flag']))) {
212 // add the e-prescribe flag
213 processAmcCall('e_prescribe_chk_formulary_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
216 // remove the e-prescribe flag
217 processAmcCall('e_prescribe_chk_formulary_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
220 // Set the AMC reporting flag (to record prescriptions that are controlled substances)
221 if (!(empty($_POST['controlled_substance_flag']))) {
222 // add the e-prescribe flag
223 processAmcCall('e_prescribe_cont_subst_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
226 // remove the e-prescribe flag
227 processAmcCall('e_prescribe_cont_subst_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
230 // TajEmo Work by CB 2012/05/29 02:58:29 PM to stop from going to send screen. Improves Work Flow
231 // if ($this->prescriptions[0]->get_active() > 0) {
232 // return $this->send_action($this->prescriptions[0]->id);
234 $this->list_action($this->prescriptions
[0]->get_patient_id());
238 function send_action($id) {
239 $_POST['process'] = "true";
241 $this->function_argument_error();
244 $rx = new Prescription($id);
245 // Populate pharmacy info if the patient has a default pharmacy.
246 // Probably the Prescription object should handle this instead, but
247 // doing it there will require more careful research and testing.
248 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
249 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
250 if ($prow['pharmacy_id']) {
251 $rx->pharmacy
->set_id($prow['pharmacy_id']);
252 $rx->pharmacy
->populate();
254 $this->assign("prescription", $rx);
256 $this->_state
= false;
257 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
258 $this->template_mod
. "_send.html");
261 function multiprintfax_header(& $pdf, $p) {
262 return $this->multiprint_header( $pdf, $p );
265 function multiprint_header(& $pdf, $p) {
266 $this->providerid
= $p->provider
->id
;
268 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'],'','50','','center','');
269 $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10));
270 $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 ='" .
271 add_escape_custom($p->provider
->id
) . "'");
272 $pdf->ezText($res['addr'],12);
275 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>',12);
276 // A client had a bad experience with a patient misusing a DEA number, so
277 // now the doctors write those in on printed prescriptions and only when
278 // necessary. If you need to change this back, then please make it a
279 // configurable option. Faxed prescriptions were not changed. -- Rod
280 // Now it is configureable. Change value in
281 // Administration->Globals->Rx
282 if ($GLOBALS['rx_enable_DEA']) {
283 if ($this->is_faxing ||
$GLOBALS['rx_show_DEA']) {
284 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
, 12);
287 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
291 if ($GLOBALS['rx_enable_NPI']) {
292 if ($this->is_faxing ||
$GLOBALS['rx_show_NPI']) {
293 $pdf->ezText('<b>' . xl('NPI') . ':</b>' . $p->provider
->npi
, 12);
296 $pdf->ezText('<b>' . xl('NPI') . ':</b> _________________________', 12);
299 if ($GLOBALS['rx_enable_SLN']) {
300 if ($this->is_faxing ||
$GLOBALS['rx_show_SLN']) {
301 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
, 12);
304 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b> ___________________', 12);
307 $pdf->ezColumnsStop();
308 if ($my_y < $pdf->y
){
312 $pdf->setLineStyle(1);
313 $pdf->ezColumnsStart(array('num'=>2));
314 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
315 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>',6);
316 $pdf->ezText($p->patient
->get_name_display(),10);
317 $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
));
318 $pdf->ezText($res['addr']);
321 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
322 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>',6);
323 $pdf->ezText($p->patient
->date_of_birth
,10);
325 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
326 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>',6);
327 $pdf->ezText(str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
),10);
328 $pdf->ezColumnsStop();
329 if ($my_y < $pdf->y
){
333 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
334 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>',6);
338 function multiprintcss_header($p) {
339 echo("<div class='paddingdiv'>\n");
340 $this->providerid
= $p->provider
->id
;
341 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
343 echo ("<td></td>\n");
345 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
350 $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
) . "'");
352 $patterns = array ('/\n/','/Tel:/','/Fax:/');
353 $replace = array ('<br>', xl('Tel').':', xl('Fax').':');
354 $res = preg_replace($patterns, $replace, $res);
356 echo ('<span class="large">' . $res['addr'] . '</span>');
359 echo ('<b><span class="large">' . $p->provider
->get_name_display() . '</span></b>'. '<br>');
361 if ($GLOBALS['rx_enable_DEA']) {
362 if ($GLOBALS['rx_show_DEA']) {
363 echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
. '</span><br>');
366 echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________<br>' );
369 if ($GLOBALS['rx_enable_NPI']) {
370 if ($GLOBALS['rx_show_NPI']) {
371 echo ('<span class="large"><b>' . xl('NPI') . ':</b>' . $p->provider
->npi
. '</span><br>');
374 echo ('<b><span class="large">' . xl('NPI') . ':</span></b> ________________________<br>');
377 if ($GLOBALS['rx_enable_SLN']) {
378 if ($GLOBALS['rx_show_SLN']) {
379 echo ('<span class="large"><b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
. '</span><br>');
382 echo ('<b><span class="large">' . xl('State Lic. #') . ':</span></b> ________________________<br>');
388 echo ("<td rowspan='2' class='bordered'>\n");
389 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>'. '<br>');
390 echo ($p->patient
->get_name_display() . '<br>');
391 $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
));
393 $patterns = array ('/\n/');
394 $replace = array ('<br>');
395 $res = preg_replace($patterns, $replace, $res);
399 echo ("<td class='bordered'>\n");
400 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br>');
401 echo ($p->patient
->date_of_birth
);
405 echo ("<td class='bordered'>\n");
406 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br>');
407 echo (str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
));
411 echo ("<td colspan='2' class='bordered'>\n");
412 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
418 function multiprintcss_preheader() {
419 // this sets styling and other header information of the multiprint css sheet
424 echo (" padding: 0;\n");
425 echo (" margin: 0;\n");
428 echo (" font-family: sans-serif;\n");
429 echo (" font-weight: normal;\n");
430 echo (" font-size: 10pt;\n");
431 echo (" background: white;\n");
432 echo (" color: black;\n");
434 echo ("span.large {\n");
435 echo (" font-size: 12pt;\n");
437 echo ("span.small {\n");
438 echo (" font-size: 6pt;\n");
441 echo (" vertical-align: top;\n");
442 echo (" width: 50%;\n");
443 echo (" font-size: 10pt;\n");
444 echo (" padding-bottom: 8pt;\n");
446 echo ("td.bordered {\n");
447 echo (" border-top:1pt solid black;\n");
449 echo ("div.paddingdiv {\n");
450 echo (" width: 524pt;\n");
451 echo (" height: 668pt;\n");
453 echo ("div.scriptdiv {\n");
454 echo (" padding-top: 12pt;\n");
455 echo (" padding-bottom: 22pt;\n");
456 echo (" padding-left: 35pt;\n");
457 echo (" border-bottom:1pt solid black;\n");
459 echo ("div.signdiv {\n");
460 echo (" margin-top: 40pt;\n");
461 echo (" font-size: 12pt;\n");
465 echo ("<title>" . xl('Prescription') . "</title>\n");
470 function multiprintfax_footer( & $pdf ) {
471 return $this->multiprint_footer( $pdf );
474 function multiprint_footer(& $pdf) {
475 if($this->pconfig
['use_signature'] && ( $this->is_faxing ||
$this->is_print_to_fax
) ) {
476 $sigfile = str_replace('{userid}', $_SESSION{"authUser"}, $this->pconfig
['signature']);
477 if (file_exists($sigfile)) {
478 $pdf->ezText( xl('Signature') . ": ",12);
479 // $pdf->ezImage($sigfile, "", "", "none", "left");
480 $pdf->ezImage($sigfile, "", "", "none", "center");
481 $pdf->ezText( xl('Date') . ": " . date('Y-m-d'), 12);
482 if ( $this->is_print_to_fax
) {
483 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
486 $addenumFile = $this->pconfig
['addendum_file'];
487 if ( file_exists( $addenumFile ) ) {
489 $f = fopen($addenumFile, "r");
490 while ( $line = fgets($f, 1000) ) {
491 $pdf->ezText(rtrim($line));
498 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'),12);
501 function multiprintcss_footer() {
502 echo ("<div class='signdiv'>\n");
503 echo (xl('Signature') . ":________________________________<br>");
504 echo (xl('Date') . ": " . date('Y-m-d'));
509 function multiprintcss_postfooter() {
510 echo("<script language='JavaScript'>\n");
511 echo("opener.top.printLogPrint(window);\n");
517 function get_prescription_body_text($p) {
518 $body = '<b>' . xlt('Rx') . ': ' . text($p->get_drug()) . ' ' . text($p->get_size()) . ' ' . text($p->get_unit_display());
519 if ($p->get_form()) $body .= ' [' . text($p->form_array
[$p->get_form()]) . "]";
520 $body .= "</b> <i>" .
521 text($p->substitute_array
[$p->get_substitute()]) . "</i>\n" .
522 '<b>' . xlt('Disp #') . ':</b> <u>' . text($p->get_quantity()) . "</u>\n" .
523 '<b>' . xlt('Sig') . ':</b> ' . text($p->get_dosage()) . ' ' . text($p->form_array
[$p->get_form()]) . ' ' .
524 text($p->route_array
[$p->get_route()]) . ' ' . text($p->interval_array
[$p->get_interval()]) . "\n";
525 if ($p->get_refills() > 0) {
526 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>" . text($p->get_refills());
527 if ($p->get_per_refill()) {
528 $body .= " " . xlt('of quantity') . " " . text($p->get_per_refill());
533 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>0 (" . xlt('Zero') . ")</u>\n";
535 $note = $p->get_note();
537 $body .= "\n" . text($note) . "\n";
542 function multiprintfax_body(& $pdf, $p){
543 return $this->multiprint_body( $pdf, $p );
546 function multiprint_body(& $pdf, $p){
547 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
548 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
549 $d = $this->get_prescription_body_text($p);
550 if ( $pdf->ezText($d,10,array(),1) ) {
551 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
552 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
553 $this->multiprint_footer($pdf);
555 $this->multiprint_header($pdf, $p);
556 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
557 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
561 if($this->pconfig
['shading']) {
562 $pdf->setColor(.9,.9,.9);
563 $pdf->filledRectangle($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin']-$pdf->ez
['leftMargin'],$my_y - $pdf->y
);
564 $pdf->setColor(0,0,0);
568 $pdf->ez
['leftMargin'] = $GLOBALS['rx_left_margin'];
569 $pdf->ez
['rightMargin'] = $GLOBALS['rx_right_margin'];
571 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
575 function multiprintcss_body($p){
576 $d = $this->get_prescription_body_text($p);
577 $patterns = array ('/\n/','/ /');
578 $replace = array ('<br>',' ');
579 $d = preg_replace($patterns, $replace, $d);
580 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
583 function multiprintfax_action($id = "") {
584 $this->is_print_to_fax
=true;
585 return $this->multiprint_action( $id );
588 function multiprint_action($id = "") {
589 $_POST['process'] = "true";
591 $this->function_argument_error();
593 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
594 $pdf->ezSetMargins($GLOBALS['rx_top_margin']
595 ,$GLOBALS['rx_bottom_margin']
596 ,$GLOBALS['rx_left_margin']
597 ,$GLOBALS['rx_right_margin']
599 $pdf->selectFont('Helvetica');
601 // $print_header = true;
604 //print prescriptions body
605 $this->_state
= false; // Added by Rod - see Controller.class.php
606 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
607 foreach ($ids as $id) {
608 $p = new Prescription($id);
609 // if ($print_header == true) {
610 if ($on_this_page == 0) {
611 $this->multiprint_header($pdf, $p);
613 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
614 $this->multiprint_footer($pdf);
616 $this->multiprint_header($pdf, $p);
617 // $print_header = false;
620 $this->multiprint_body($pdf, $p);
623 $this->multiprint_footer($pdf);
625 $pFirstName = $p->patient
->fname
; //modified by epsdky for prescription title change to include patient name and ID
626 $pFName = convert_safe_file_dir_name($pFirstName);
627 $modedFileName = "Rx_{$pFName}_{$p->patient->id}.pdf";
629 $pdf->ezStream(array('Content-Disposition' => $modedFileName));
633 function multiprintcss_action($id = "") {
634 $_POST['process'] = "true";
636 $this->function_argument_error();
639 $this->multiprintcss_preheader();
641 $this->_state
= false; // Added by Rod - see Controller.class.php
642 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
645 foreach ($ids as $id) {
646 $p = new Prescription($id);
647 if ($on_this_page == 0) {
648 $this->multiprintcss_header($p);
650 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
651 $this->multiprintcss_footer();
652 $this->multiprintcss_header($p);
655 $this->multiprintcss_body($p);
657 $this->multiprintcss_footer();
658 $this->multiprintcss_postfooter();
662 function send_action_process($id) {
663 $dummy = ""; // Added by Rod to avoid run-time warnings
664 if ($_POST['process'] != "true")
667 $this->function_argument_error();
669 $p = new Prescription($id);
670 switch ($_POST['submit']) {
672 case (xl("Print")." (".xl("PDF").")"):
673 // The following statement added by Rod.
674 // Looking at Controller.class.php, it appears that _state is set to false
675 // to indicate that no further HTML is to be generated.
676 $this->_state
= false; // Added by Rod - see Controller.class.php
677 return $this->_print_prescription($p, $dummy);
679 case (xl("Print")." (".xl("HTML").")"):
680 $this->_state
= false;
681 return $this->_print_prescription_css($p, $dummy);
683 case xl("Print To Fax"):
684 $this->_state
= false;
685 $this->is_print_to_fax
= true;
686 return $this->_print_prescription($p, $dummy);
689 return $this->_email_prescription($p,$_POST['email_to']);
692 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
693 //$this->assign("process_result","No fax server is currently setup.");
694 return $this->_fax_prescription($p,$_POST['fax_to']);
696 case xl("Auto Send"):
697 $pharmacy_id = $_POST['pharmacy_id'];
698 //echo "auto sending to : " . $_POST['pharmacy_id'];
699 $phar = new Pharmacy($_POST['pharmacy_id']);
701 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
702 return $this->_print_prescription($p, $dummy);
704 elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
705 $email = $phar->get_email();
706 if (!empty($email)) {
707 return $this->_email_prescription($p,$phar->get_email());
711 elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
712 $faxNum= $phar->get_fax();
713 if(!empty($faxNum)) {
714 Return $this->_fax_prescription ($p,$faxNum);
716 // return $this->assign("process_result","No fax server is currently setup.");
717 // else default is printing,
720 //the pharmacy has no default or default is print
721 return $this->_print_prescription($p, $dummy);
730 function _print_prescription($p, & $toFile) {
731 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
732 $pdf->ezSetMargins($GLOBALS['rx_top_margin']
733 ,$GLOBALS['rx_bottom_margin']
734 ,$GLOBALS['rx_left_margin']
735 ,$GLOBALS['rx_right_margin']
738 $pdf->selectFont('Helvetica');
740 // Signature images are to be used only when faxing.
741 if(!empty($toFile)) $this->is_faxing
= true;
743 $this->multiprint_header($pdf, $p);
744 $this->multiprint_body($pdf, $p);
745 $this->multiprint_footer($pdf);
747 if(!empty($toFile)) {
748 $toFile = $pdf->ezOutput();
752 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
757 function _print_prescription_css($p, & $toFile) {
759 $this->multiprintcss_preheader();
760 $this->multiprintcss_header($p);
761 $this->multiprintcss_body($p);
762 $this->multiprintcss_footer();
763 $this->multiprintcss_postfooter();
767 function _print_prescription_old($p, & $toFile) {
768 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
769 $pdf->ezSetMargins($GLOBALS['rx_top_margin']
770 ,$GLOBALS['rx_bottom_margin']
771 ,$GLOBALS['rx_left_margin']
772 ,$GLOBALS['rx_right_margin']
774 $pdf->selectFont('Helvetica');
775 if(!empty($this->pconfig
['logo'])) {
776 $pdf->ezImage($this->pconfig
['logo'],"","","none","left");
778 $pdf->ezText($p->get_prescription_display(),10);
779 if($this->pconfig
['use_signature']) {
780 $pdf->ezImage($this->pconfig
['signature'],"","","none","left");
783 $pdf->ezText("\n\n\n\nSignature:________________________________",10);
787 $toFile = $pdf->ezOutput();
792 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
797 function _email_prescription($p,$email) {
799 $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
802 $mail = new PHPMailer();
803 //this is a temporary config item until the rest of the per practice billing settings make their way in
804 $mail->From
= $GLOBALS['practice_return_email_path'];
805 $mail->FromName
= $p->provider
->get_name_display();
807 $mail->Host
= "localhost";
808 $mail->Mailer
= "mail";
809 $text_body = $p->get_prescription_display();
810 $mail->Body
= $text_body;
811 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
812 $mail->AddAddress($email);
814 $this->assign("process_result","Email was successfully sent to: " . $email);
818 $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
823 function do_lookup() {
824 if ($_POST['process'] != "true") {
826 $this->assign("drug", $_GET['drug']);
830 // process the lookup
831 $this->assign("drug", $_POST['drug']);
833 if (!empty($_POST['drug'])) {
834 $list = $this->RxList
->get_list($_POST['drug']);
837 if (is_array($list)) {
838 $list = array_flip($list);
839 $this->assign("drug_options",$list);
840 $this->assign("drug_values",array_keys($list));
843 $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
846 //$this->assign("PROCESS","");
848 $_POST['process'] = "";
851 function _fax_prescription($p,$faxNum)
854 //strip - ,(, ), and ws
855 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum);
856 //validate the number
858 if(!empty($faxNum) && is_numeric($faxNum))
860 //get the sendfax command and execute it
861 $cmd = $this->pconfig
['sendfax'];
862 // prepend any prefix to the fax number
863 $pref=$this->pconfig
['prefix'];
864 $faxNum=$pref.$faxNum;
867 $err .= " Send fax not set in includes/config.php";
871 //generate file to fax
873 $this->_print_prescription($p, $faxFile);
876 $err .= " _print_prescription returned empty file";
878 $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() .
879 $p->get_patient_id() . "_fax_.pdf";
880 //print "filename is $fileName";
881 touch($fileName); // php bug
882 $handle = fopen($fileName,"w");
885 $err .= " Failed to open file $fileName to write fax to";
887 if(fwrite($handle, $faxFile) === false)
889 $err .= " Failed to write data to $fileName";
892 $args = " -n -d $faxNum $fileName";
893 //print "command is $cmd $args<br>";
900 $err = "bad fax number passed to function";
904 $this->assign("process_result",$err);