Restyled Miscellaneous Billing Options HCFA with help file (#1713)
[openemr.git] / controllers / C_Prescription.class.php
blob9727c2c5122162f92580ca57773f1d77f938a027
1 <?php
2 /**
3 * C_Prescription class
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Roberto Vasquez <robertogagliotta@gmail.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
10 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php");
16 require_once($GLOBALS['fileroot'] . "/library/registry.inc");
17 require_once($GLOBALS['fileroot'] . "/library/amc.php");
19 class C_Prescription extends Controller
22 var $template_mod;
23 var $pconfig;
24 var $providerid = 0;
25 var $is_faxing = false;
26 var $is_print_to_fax = false;
28 function __construct($template_mod = "general")
30 parent::__construct();
32 $this->template_mod = $template_mod;
33 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . attr($_SERVER['QUERY_STRING']));
34 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
35 $this->assign("STYLE", $GLOBALS['style']);
36 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
37 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
38 $this->pconfig = $GLOBALS['oer_config']['prescriptions'];
39 $this->RxList = new RxList();
41 if ($GLOBALS['inhouse_pharmacy']) {
42 // Make an array of drug IDs and selectors for the template.
43 $drug_array_values = array(0);
44 $drug_array_output = array("-- " . xl('or select from inventory') ." --");
45 $drug_attributes = '';
47 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
49 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
50 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
51 "t.period, t.quantity, t.refills, d.drug_code " .
52 "FROM drug_templates AS t, drugs AS d WHERE " .
53 "d.drug_id = t.drug_id ORDER BY t.selector");
55 while ($row = sqlFetchArray($res)) {
56 $tmp_output = $row['selector'];
57 if ($row['ndc_number']) {
58 $tmp_output .= ' [' . $row['ndc_number'] . ']';
61 $drug_array_values[] = $row['drug_id'];
62 $drug_array_output[] = $tmp_output;
63 if ($drug_attributes) {
64 $drug_attributes .= ',';
67 $drug_attributes .= "['" .
68 attr($row['name']) . "'," . // 0
69 attr($row['form']) . ",'" . // 1
70 attr($row['dosage']) . "','" . // 2
71 attr($row['size']) . "'," . // 3
72 attr($row['unit']) . "," . // 4
73 attr($row['route']) . "," . // 5
74 attr($row['period']) . "," . // 6
75 attr($row['substitute']) . "," . // 7
76 attr($row['quantity']) . "," . // 8
77 attr($row['refills']) . "," . // 9
78 attr($row['quantity']) . "," . // 10 quantity per_refill
79 attr($row['drug_code']) . "]"; // 11 rxnorm drug code
82 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
83 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
84 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
88 function default_action()
90 $this->assign("prescription", $this->prescriptions[0]);
91 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_edit.html");
94 function edit_action($id = "", $patient_id = "", $p_obj = null)
97 if ($p_obj != null && get_class($p_obj) == "prescription") {
98 $this->prescriptions[0] = $p_obj;
99 } elseif (!is_object($this->prescriptions[0]) || get_class($this->prescriptions[0]) != "prescription") {
100 $this->prescriptions[0] = new Prescription($id);
103 if (!empty($patient_id)) {
104 $this->prescriptions[0]->set_patient_id($patient_id);
107 // If quantity to dispense is not already set from a POST, set its
108 // default value.
109 if (! $this->get_template_vars('DISP_QUANTITY')) {
110 $this->assign('DISP_QUANTITY', $this->prescriptions[0]->quantity);
113 $this->default_action();
116 function list_action($id, $sort = "")
118 if (empty($id)) {
119 $this->function_argument_error();
120 exit;
123 if (!empty($sort)) {
124 $this->assign("prescriptions", Prescription::prescriptions_factory($id, $sort));
125 } else {
126 $this->assign("prescriptions", Prescription::prescriptions_factory($id));
129 // flag to indicate the CAMOS form is regsitered and active
130 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
132 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_list.html");
135 function block_action($id, $sort = "")
137 if (empty($id)) {
138 $this->function_argument_error();
139 exit;
142 if (!empty($sort)) {
143 $this->assign("prescriptions", Prescription::prescriptions_factory($id, $sort));
144 } else {
145 $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 if (empty($id)) {
155 $this->function_argument_error();
156 exit;
159 if (!empty($sort)) {
160 $this->assign("prescriptions", Prescription::prescriptions_factory($id, $sort));
161 } else {
162 $this->assign("prescriptions", Prescription::prescriptions_factory($id));
165 //print_r(Prescription::prescriptions_factory($id));
166 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_fragment.html");
169 function lookup_action()
171 $this->do_lookup();
172 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_lookup.html");
175 function edit_action_process()
177 if ($_POST['process'] != "true") {
178 return;
181 //print_r($_POST);
183 // Stupid Smarty code treats empty values as not specified values.
184 // Since active is a checkbox, represent the unchecked state as -1.
185 if (empty($_POST['active'])) {
186 $_POST['active'] = '-1';
189 $this->prescriptions[0] = new Prescription($_POST['id']);
190 parent::populate_object($this->prescriptions[0]);
191 //echo $this->prescriptions[0]->toString(true);
192 $this->prescriptions[0]->persist();
193 $_POST['process'] = "";
195 // If the "Prescribe and Dispense" button was clicked, then
196 // redisplay as in edit_action() but also replicate the fee and
197 // include a piece of javascript to call dispense().
199 if ($_POST['disp_button']) {
200 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
201 $this->assign("DISP_FEE", $_POST['disp_fee']);
202 $this->assign("ENDING_JAVASCRIPT", "dispense();");
203 $this->_state = false;
204 return $this->edit_action($this->prescriptions[0]->id);
207 // Set the AMC reporting flag (to record percentage of prescriptions that
208 // are set as e-prescriptions)
209 if (!(empty($_POST['escribe_flag']))) {
210 // add the e-prescribe flag
211 processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id);
212 } else {
213 // remove the e-prescribe flag
214 processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id);
217 // Set the AMC reporting flag (to record prescriptions that checked drug formulary)
218 if (!(empty($_POST['checked_formulary_flag']))) {
219 // add the e-prescribe flag
220 processAmcCall('e_prescribe_chk_formulary_amc', true, 'add', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id);
221 } else {
222 // remove the e-prescribe flag
223 processAmcCall('e_prescribe_chk_formulary_amc', true, 'remove', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id);
226 // Set the AMC reporting flag (to record prescriptions that are controlled substances)
227 if (!(empty($_POST['controlled_substance_flag']))) {
228 // add the e-prescribe flag
229 processAmcCall('e_prescribe_cont_subst_amc', true, 'add', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id);
230 } else {
231 // remove the e-prescribe flag
232 processAmcCall('e_prescribe_cont_subst_amc', true, 'remove', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id);
235 // TajEmo Work by CB 2012/05/29 02:58:29 PM to stop from going to send screen. Improves Work Flow
236 // if ($this->prescriptions[0]->get_active() > 0) {
237 // return $this->send_action($this->prescriptions[0]->id);
238 // }
239 $this->list_action($this->prescriptions[0]->get_patient_id());
240 exit;
243 function send_action($id)
245 $_POST['process'] = "true";
246 if (empty($id)) {
247 $this->function_argument_error();
250 $rx = new Prescription($id);
251 // Populate pharmacy info if the patient has a default pharmacy.
252 // Probably the Prescription object should handle this instead, but
253 // doing it there will require more careful research and testing.
254 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
255 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
256 if ($prow['pharmacy_id']) {
257 $rx->pharmacy->set_id($prow['pharmacy_id']);
258 $rx->pharmacy->populate();
261 $this->assign("prescription", $rx);
263 $this->_state = false;
264 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
265 $this->template_mod . "_send.html");
268 function multiprintfax_header(& $pdf, $p)
270 return $this->multiprint_header($pdf, $p);
273 function multiprint_header(& $pdf, $p)
275 $this->providerid = $p->provider->id;
276 //print header
277 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'], '', '50', '', 'center', '');
278 $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10));
279 $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 ='" .
280 add_escape_custom($p->provider->id) . "'");
281 $pdf->ezText($res['addr'], 12);
282 $my_y = $pdf->y;
283 $pdf->ezNewPage();
284 $pdf->ezText('<b>' . $p->provider->get_name_display() . '</b>', 12);
285 // A client had a bad experience with a patient misusing a DEA number, so
286 // now the doctors write those in on printed prescriptions and only when
287 // necessary. If you need to change this back, then please make it a
288 // configurable option. Faxed prescriptions were not changed. -- Rod
289 // Now it is configureable. Change value in
290 // Administration->Globals->Rx
291 if ($GLOBALS['rx_enable_DEA']) {
292 if ($this->is_faxing || $GLOBALS['rx_show_DEA']) {
293 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider->federal_drug_id, 12);
294 } else {
295 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
299 if ($GLOBALS['rx_enable_NPI']) {
300 if ($this->is_faxing || $GLOBALS['rx_show_NPI']) {
301 $pdf->ezText('<b>' . xl('NPI') . ':</b>' . $p->provider->npi, 12);
302 } else {
303 $pdf->ezText('<b>' . xl('NPI') . ':</b> _________________________', 12);
307 if ($GLOBALS['rx_enable_SLN']) {
308 if ($this->is_faxing || $GLOBALS['rx_show_SLN']) {
309 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b>' . $p->provider->state_license_number, 12);
310 } else {
311 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b> ___________________', 12);
315 $pdf->ezColumnsStop();
316 if ($my_y < $pdf->y) {
317 $pdf->ezSetY($my_y);
320 $pdf->ezText('', 10);
321 $pdf->setLineStyle(1);
322 $pdf->ezColumnsStart(array('num'=>2));
323 $pdf->line($pdf->ez['leftMargin'], $pdf->y, $pdf->ez['pageWidth']-$pdf->ez['rightMargin'], $pdf->y);
324 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>', 6);
325 $pdf->ezText($p->patient->get_name_display(), 10);
326 $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));
327 $pdf->ezText($res['addr']);
328 $my_y = $pdf->y;
329 $pdf->ezNewPage();
330 $pdf->line($pdf->ez['leftMargin'], $pdf->y, $pdf->ez['pageWidth']-$pdf->ez['rightMargin'], $pdf->y);
331 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>', 6);
332 $pdf->ezText($p->patient->date_of_birth, 10);
333 $pdf->ezText('');
334 $pdf->line($pdf->ez['leftMargin'], $pdf->y, $pdf->ez['pageWidth']-$pdf->ez['rightMargin'], $pdf->y);
335 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>', 6);
336 $pdf->ezText(str_pad($p->patient->get_pubpid(), 10, "0", STR_PAD_LEFT), 10);
337 $pdf->ezColumnsStop();
338 if ($my_y < $pdf->y) {
339 $pdf->ezSetY($my_y);
342 $pdf->ezText('');
343 $pdf->line($pdf->ez['leftMargin'], $pdf->y, $pdf->ez['pageWidth']-$pdf->ez['rightMargin'], $pdf->y);
344 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>', 6);
345 $pdf->ezText('', 10);
348 function multiprintcss_header($p)
350 echo("<div class='paddingdiv'>\n");
351 $this->providerid = $p->provider->id;
352 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
353 echo ("<tr>\n");
354 echo ("<td></td>\n");
355 echo ("<td>\n");
356 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
357 echo ("</td>\n");
358 echo ("</tr>\n");
359 echo ("<tr>\n");
360 echo ("<td>\n");
361 $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) . "'");
362 if (!empty($res)) {
363 $patterns = array ('/\n/','/Tel:/','/Fax:/');
364 $replace = array ('<br>', xl('Tel').':', xl('Fax').':');
365 $res = preg_replace($patterns, $replace, $res);
368 echo ('<span class="large">' . $res['addr'] . '</span>');
369 echo ("</td>\n");
370 echo ("<td>\n");
371 echo ('<b><span class="large">' . $p->provider->get_name_display() . '</span></b>'. '<br>');
373 if ($GLOBALS['rx_enable_DEA']) {
374 if ($GLOBALS['rx_show_DEA']) {
375 echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider->federal_drug_id . '</span><br>');
376 } else {
377 echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________<br>' );
381 if ($GLOBALS['rx_enable_NPI']) {
382 if ($GLOBALS['rx_show_NPI']) {
383 echo ('<span class="large"><b>' . xl('NPI') . ':</b>' . $p->provider->npi . '</span><br>');
384 } else {
385 echo ('<b><span class="large">' . xl('NPI') . ':</span></b> ________________________<br>');
389 if ($GLOBALS['rx_enable_SLN']) {
390 if ($GLOBALS['rx_show_SLN']) {
391 echo ('<span class="large"><b>' . xl('State Lic. #') . ':</b>' . $p->provider->state_license_number . '</span><br>');
392 } else {
393 echo ('<b><span class="large">' . xl('State Lic. #') . ':</span></b> ________________________<br>');
397 echo ("</td>\n");
398 echo ("</tr>\n");
399 echo ("<tr>\n");
400 echo ("<td rowspan='2' class='bordered'>\n");
401 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>'. '<br>');
402 echo ($p->patient->get_name_display() . '<br>');
403 $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));
404 if (!empty($res)) {
405 $patterns = array ('/\n/');
406 $replace = array ('<br>');
407 $res = preg_replace($patterns, $replace, $res);
410 echo ($res['addr']);
411 echo ("</td>\n");
412 echo ("<td class='bordered'>\n");
413 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br>');
414 echo ($p->patient->date_of_birth );
415 echo ("</td>\n");
416 echo ("</tr>\n");
417 echo ("<tr>\n");
418 echo ("<td class='bordered'>\n");
419 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br>');
420 echo (str_pad($p->patient->get_pubpid(), 10, "0", STR_PAD_LEFT));
421 echo ("</td>\n");
422 echo ("</tr>\n");
423 echo ("<tr>\n");
424 echo ("<td colspan='2' class='bordered'>\n");
425 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
426 echo ("</td>\n");
427 echo ("</tr>\n");
428 echo ("</table>\n");
431 function multiprintcss_preheader()
433 // this sets styling and other header information of the multiprint css sheet
434 echo ("<html>\n");
435 echo ("<head>\n");
436 echo ("<style>\n");
437 echo ("div {\n");
438 echo (" padding: 0;\n");
439 echo (" margin: 0;\n");
440 echo ("}\n");
441 echo ("body {\n");
442 echo (" font-family: sans-serif;\n");
443 echo (" font-weight: normal;\n");
444 echo (" font-size: 10pt;\n");
445 echo (" background: white;\n");
446 echo (" color: black;\n");
447 echo ("}\n");
448 echo ("span.large {\n");
449 echo (" font-size: 12pt;\n");
450 echo ("}\n");
451 echo ("span.small {\n");
452 echo (" font-size: 6pt;\n");
453 echo ("}\n");
454 echo ("td {\n");
455 echo (" vertical-align: top;\n");
456 echo (" width: 50%;\n");
457 echo (" font-size: 10pt;\n");
458 echo (" padding-bottom: 8pt;\n");
459 echo ("}\n");
460 echo ("td.bordered {\n");
461 echo (" border-top:1pt solid black;\n");
462 echo ("}\n");
463 echo ("div.paddingdiv {\n");
464 echo (" width: 524pt;\n");
465 echo (" height: 668pt;\n");
466 echo ("}\n");
467 echo ("div.scriptdiv {\n");
468 echo (" padding-top: 12pt;\n");
469 echo (" padding-bottom: 22pt;\n");
470 echo (" padding-left: 35pt;\n");
471 echo (" border-bottom:1pt solid black;\n");
472 echo ("}\n");
473 echo ("div.signdiv {\n");
474 echo (" margin-top: 40pt;\n");
475 echo (" font-size: 12pt;\n");
476 echo ("}\n");
477 echo ("</style>\n");
479 echo ("<title>" . xl('Prescription') . "</title>\n");
480 echo ("</head>\n");
481 echo ("<body>\n");
484 function multiprintfax_footer(& $pdf)
486 return $this->multiprint_footer($pdf);
489 function multiprint_footer(& $pdf)
491 if ($this->pconfig['use_signature'] && ( $this->is_faxing || $this->is_print_to_fax )) {
492 $sigfile = str_replace('{userid}', $_SESSION{"authUser"}, $this->pconfig['signature']);
493 if (file_exists($sigfile)) {
494 $pdf->ezText(xl('Signature') . ": ", 12);
495 // $pdf->ezImage($sigfile, "", "", "none", "left");
496 $pdf->ezImage($sigfile, "", "", "none", "center");
497 $pdf->ezText(xl('Date') . ": " . date('Y-m-d'), 12);
498 if ($this->is_print_to_fax) {
499 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
502 $addenumFile = $this->pconfig['addendum_file'];
503 if (file_exists($addenumFile)) {
504 $pdf->ezText('');
505 $f = fopen($addenumFile, "r");
506 while ($line = fgets($f, 1000)) {
507 $pdf->ezText(rtrim($line));
511 return;
515 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'), 12);
518 function multiprintcss_footer()
520 echo ("<div class='signdiv'>\n");
521 echo (xl('Signature') . ":________________________________<br>");
522 echo (xl('Date') . ": " . date('Y-m-d'));
523 echo ("</div>\n");
524 echo ("</div>\n");
527 function multiprintcss_postfooter()
529 echo("<script language='JavaScript'>\n");
530 echo("opener.top.printLogPrint(window);\n");
531 echo("</script>\n");
532 echo("</body>\n");
533 echo("</html>\n");
536 function get_prescription_body_text($p)
538 $body = '<b>' . xlt('Rx') . ': ' . text($p->get_drug()) . ' ' . text($p->get_size()) . ' ' . text($p->get_unit_display());
539 if ($p->get_form()) {
540 $body .= ' [' . text($p->form_array[$p->get_form()]) . "]";
543 $body .= "</b> <i>" .
544 text($p->substitute_array[$p->get_substitute()]) . "</i>\n" .
545 '<b>' . xlt('Disp #') . ':</b> <u>' . text($p->get_quantity()) . "</u>\n" .
546 '<b>' . xlt('Sig') . ':</b> ' . text($p->get_dosage()) . ' ' . text($p->form_array[$p->get_form()]) . ' ' .
547 text($p->route_array[$p->get_route()]) . ' ' . text($p->interval_array[$p->get_interval()]) . "\n";
548 if ($p->get_refills() > 0) {
549 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>" . text($p->get_refills());
550 if ($p->get_per_refill()) {
551 $body .= " " . xlt('of quantity') . " " . text($p->get_per_refill());
554 $body .= "</u>\n";
555 } else {
556 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>0 (" . xlt('Zero') . ")</u>\n";
559 $note = $p->get_note();
560 if ($note != '') {
561 $body .= "\n" . text($note) . "\n";
564 return $body;
567 function multiprintfax_body(& $pdf, $p)
569 return $this->multiprint_body($pdf, $p);
572 function multiprint_body(& $pdf, $p)
574 $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
575 $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
576 $d = $this->get_prescription_body_text($p);
577 if ($pdf->ezText($d, 10, array(), 1)) {
578 $pdf->ez['leftMargin'] -= $pdf->ez['leftMargin'];
579 $pdf->ez['rightMargin'] -= $pdf->ez['rightMargin'];
580 $this->multiprint_footer($pdf);
581 $pdf->ezNewPage();
582 $this->multiprint_header($pdf, $p);
583 $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
584 $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
587 $my_y = $pdf->y;
588 $pdf->ezText($d, 10);
589 if ($this->pconfig['shading']) {
590 $pdf->setColor(.9, .9, .9);
591 $pdf->filledRectangle($pdf->ez['leftMargin'], $pdf->y, $pdf->ez['pageWidth']-$pdf->ez['rightMargin']-$pdf->ez['leftMargin'], $my_y - $pdf->y);
592 $pdf->setColor(0, 0, 0);
595 $pdf->ezSetY($my_y);
596 $pdf->ezText($d, 10);
597 $pdf->ez['leftMargin'] = $GLOBALS['rx_left_margin'];
598 $pdf->ez['rightMargin'] = $GLOBALS['rx_right_margin'];
599 $pdf->ezText('');
600 $pdf->line($pdf->ez['leftMargin'], $pdf->y, $pdf->ez['pageWidth']-$pdf->ez['rightMargin'], $pdf->y);
601 $pdf->ezText('');
604 function multiprintcss_body($p)
606 $d = $this->get_prescription_body_text($p);
607 $patterns = array ('/\n/','/ /');
608 $replace = array ('<br>','&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
609 $d = preg_replace($patterns, $replace, $d);
610 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
613 function multiprintfax_action($id = "")
615 $this->is_print_to_fax=true;
616 return $this->multiprint_action($id);
619 function multiprint_action($id = "")
621 $_POST['process'] = "true";
622 if (empty($id)) {
623 $this->function_argument_error();
626 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
627 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
628 $pdf->selectFont('Helvetica');
630 // $print_header = true;
631 $on_this_page = 0;
633 //print prescriptions body
634 $this->_state = false; // Added by Rod - see Controller.class.php
635 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY);
636 foreach ($ids as $id) {
637 $p = new Prescription($id);
638 // if ($print_header == true) {
639 if ($on_this_page == 0) {
640 $this->multiprint_header($pdf, $p);
643 if (++$on_this_page > 3 || $p->provider->id != $this->providerid) {
644 $this->multiprint_footer($pdf);
645 $pdf->ezNewPage();
646 $this->multiprint_header($pdf, $p);
647 // $print_header = false;
648 $on_this_page = 1;
651 $this->multiprint_body($pdf, $p);
654 $this->multiprint_footer($pdf);
656 $pFirstName = $p->patient->fname; //modified by epsdky for prescription title change to include patient name and ID
657 $pFName = convert_safe_file_dir_name($pFirstName);
658 $modedFileName = "Rx_{$pFName}_{$p->patient->id}.pdf";
660 $pdf->ezStream(array('Content-Disposition' => $modedFileName));
661 return;
664 function multiprintcss_action($id = "")
666 $_POST['process'] = "true";
667 if (empty($id)) {
668 $this->function_argument_error();
671 $this->multiprintcss_preheader();
673 $this->_state = false; // Added by Rod - see Controller.class.php
674 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY);
676 $on_this_page = 0;
677 foreach ($ids as $id) {
678 $p = new Prescription($id);
679 if ($on_this_page == 0) {
680 $this->multiprintcss_header($p);
683 if (++$on_this_page > 3 || $p->provider->id != $this->providerid) {
684 $this->multiprintcss_footer();
685 $this->multiprintcss_header($p);
686 $on_this_page = 1;
689 $this->multiprintcss_body($p);
692 $this->multiprintcss_footer();
693 $this->multiprintcss_postfooter();
694 return;
697 function send_action_process($id)
699 $dummy = ""; // Added by Rod to avoid run-time warnings
700 if ($_POST['process'] != "true") {
701 return;
704 if (empty($id)) {
705 $this->function_argument_error();
708 $p = new Prescription($id);
709 switch ($_POST['submit']) {
710 case (xl("Print")." (".xl("PDF").")"):
711 // The following statement added by Rod.
712 // Looking at Controller.class.php, it appears that _state is set to false
713 // to indicate that no further HTML is to be generated.
714 $this->_state = false; // Added by Rod - see Controller.class.php
715 return $this->_print_prescription($p, $dummy);
716 break;
717 case (xl("Print")." (".xl("HTML").")"):
718 $this->_state = false;
719 return $this->_print_prescription_css($p, $dummy);
720 break;
721 case xl("Print To Fax"):
722 $this->_state = false;
723 $this->is_print_to_fax = true;
724 return $this->_print_prescription($p, $dummy);
725 break;
726 case xl("Email"):
727 return $this->_email_prescription($p, $_POST['email_to']);
728 break;
729 case xl("Fax"):
730 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
731 //$this->assign("process_result","No fax server is currently setup.");
732 return $this->_fax_prescription($p, $_POST['fax_to']);
733 break;
734 case xl("Auto Send"):
735 $pharmacy_id = $_POST['pharmacy_id'];
736 //echo "auto sending to : " . $_POST['pharmacy_id'];
737 $phar = new Pharmacy($_POST['pharmacy_id']);
738 //print_r($phar);
739 if ($phar->get_transmit_method() == TRANSMIT_PRINT) {
740 return $this->_print_prescription($p, $dummy);
741 } elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL) {
742 $email = $phar->get_email();
743 if (!empty($email)) {
744 return $this->_email_prescription($p, $phar->get_email());
747 //else print it
748 } elseif ($phar->get_transmit_method() == TRANSMIT_FAX) {
749 $faxNum= $phar->get_fax();
750 if (!empty($faxNum)) {
751 return $this->_fax_prescription($p, $faxNum);
754 // return $this->assign("process_result","No fax server is currently setup.");
755 // else default is printing,
756 } else {
757 //the pharmacy has no default or default is print
758 return $this->_print_prescription($p, $dummy);
760 break;
763 return;
766 function _print_prescription($p, & $toFile)
768 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
769 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
771 $pdf->selectFont('Helvetica');
773 // Signature images are to be used only when faxing.
774 if (!empty($toFile)) {
775 $this->is_faxing = true;
778 $this->multiprint_header($pdf, $p);
779 $this->multiprint_body($pdf, $p);
780 $this->multiprint_footer($pdf);
782 if (!empty($toFile)) {
783 $toFile = $pdf->ezOutput();
784 } else {
785 $pdf->ezStream();
786 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
789 return;
792 function _print_prescription_css($p, & $toFile)
795 $this->multiprintcss_preheader();
796 $this->multiprintcss_header($p);
797 $this->multiprintcss_body($p);
798 $this->multiprintcss_footer();
799 $this->multiprintcss_postfooter();
802 function _print_prescription_old($p, & $toFile)
804 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
805 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
806 $pdf->selectFont('Helvetica');
807 if (!empty($this->pconfig['logo'])) {
808 $pdf->ezImage($this->pconfig['logo'], "", "", "none", "left");
811 $pdf->ezText($p->get_prescription_display(), 10);
812 if ($this->pconfig['use_signature']) {
813 $pdf->ezImage($this->pconfig['signature'], "", "", "none", "left");
814 } else {
815 $pdf->ezText("\n\n\n\nSignature:________________________________", 10);
818 if (!empty($toFile)) {
819 $toFile = $pdf->ezOutput();
820 } else {
821 $pdf->ezStream();
822 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
825 return;
828 function _email_prescription($p, $email)
830 if (empty($email)) {
831 $this->assign("process_result", "Email could not be sent, the address supplied: '$email' was empty or invalid.");
832 return;
835 $mail = new PHPMailer();
836 //this is a temporary config item until the rest of the per practice billing settings make their way in
837 $mail->From = $GLOBALS['practice_return_email_path'];
838 $mail->FromName = $p->provider->get_name_display();
839 $mail->isMail();
840 $mail->Host = "localhost";
841 $mail->Mailer = "mail";
842 $text_body = $p->get_prescription_display();
843 $mail->Body = $text_body;
844 $mail->Subject = "Prescription for: " . $p->patient->get_name_display();
845 $mail->AddAddress($email);
846 if ($mail->Send()) {
847 $this->assign("process_result", "Email was successfully sent to: " . $email);
848 return;
849 } else {
850 $this->assign("process_result", "There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo);
851 return;
855 function do_lookup()
857 if ($_POST['process'] != "true") {
858 // don't do a lookup
859 $this->assign("drug", $_GET['drug']);
860 return;
863 // process the lookup
864 $this->assign("drug", $_POST['drug']);
865 $list = array();
866 if (!empty($_POST['drug'])) {
867 $list = $this->RxList->get_list($_POST['drug']);
870 if (is_array($list)) {
871 $list = array_flip($list);
872 $this->assign("drug_options", $list);
873 $this->assign("drug_values", array_keys($list));
874 } else {
875 $this->assign("NO_RESULTS", "No results found for: " .$_POST['drug'] . "<br />");
878 //print_r($_POST);
879 //$this->assign("PROCESS","");
881 $_POST['process'] = "";
884 function _fax_prescription($p, $faxNum)
886 $err = "Sent fax";
887 //strip - ,(, ), and ws
888 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/", "", $faxNum);
889 //validate the number
891 if (!empty($faxNum) && is_numeric($faxNum)) {
892 //get the sendfax command and execute it
893 $cmd = $this->pconfig['sendfax'];
894 // prepend any prefix to the fax number
895 $pref=$this->pconfig['prefix'];
896 $faxNum=$pref.$faxNum;
897 if (empty($cmd)) {
898 $err .= " Send fax not set in includes/config.php";
899 } else {
900 //generate file to fax
901 $faxFile = "Failed";
902 $this->_print_prescription($p, $faxFile);
903 if (empty($faxFile)) {
904 $err .= " _print_prescription returned empty file";
907 $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() .
908 $p->get_patient_id() . "_fax_.pdf";
909 //print "filename is $fileName";
910 touch($fileName); // php bug
911 $handle = fopen($fileName, "w");
912 if (!$handle) {
913 $err .= " Failed to open file $fileName to write fax to";
916 if (fwrite($handle, $faxFile) === false) {
917 $err .= " Failed to write data to $fileName";
920 fclose($handle);
921 $args = " -n -d $faxNum $fileName";
922 //print "command is $cmd $args<br>";
923 exec($cmd . $args);
925 } else {
926 $err = "bad fax number passed to function";
929 if ($err) {
930 $this->assign("process_result", $err);