7 * @link http://www.open-emr.org
8 * @author Roberto Vasquez <robertogagliotta@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @author Sherwin Gaddis <sherwingaddis@gmail.com>
11 * @copyright Copyright (c) 2015 Roberto Vasquez <robertogagliotta@gmail.com>
12 * @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
13 * @copyright Copyright (c) 2018 Sherwin Gaddis <sherwingaddis@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once($GLOBALS['fileroot'] . "/library/registry.inc");
18 require_once($GLOBALS['fileroot'] . "/library/amc.php");
20 use OpenEMR\Common\Csrf\CsrfUtils
;
21 use OpenEMR\Common\Http\oeHttp
;
22 use OpenEMR\Rx\RxList
;
23 use PHPMailer\PHPMailer\PHPMailer
;
25 class C_Prescription
extends Controller
30 var $is_faxing = false;
31 var $is_print_to_fax = false;
33 function __construct($template_mod = "general")
35 parent
::__construct();
36 $this->template_mod
= $template_mod;
37 $this->assign("FORM_ACTION", $GLOBALS['webroot'] . "/controller.php?" . attr($_SERVER['QUERY_STRING']));
38 $this->assign("TOP_ACTION", $GLOBALS['webroot'] . "/controller.php?" . "prescription" . "&");
39 $this->assign("STYLE", $GLOBALS['style']);
40 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
41 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
42 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
43 $this->RxList
= new RxList();
44 // test if rxnorm available for lookups.
45 $rxn = sqlQuery("SELECT table_name FROM information_schema.tables WHERE table_name = 'RXNCONSO' OR table_name = 'rxconso'");
46 $rxcui = sqlQuery("SELECT ct_id FROM `code_types` WHERE `ct_key` = ? AND `ct_active` = 1", array('RXCUI'));
47 $this->assign("RXNORMS_AVAILABLE", !empty($rxn));
48 $this->assign("RXCUI_AVAILABLE", !empty($rxcui));
49 // Assign the CSRF_TOKEN_FORM
50 $this->assign("CSRF_TOKEN_FORM", CsrfUtils
::collectCsrfToken());
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 js_escape($row['name']) . "," . // 0
80 js_escape($row['form']) . "," . // 1
81 js_escape($row['dosage']) . "," . // 2
82 js_escape($row['size']) . "," . // 3
83 js_escape($row['unit']) . "," . // 4
84 js_escape($row['route']) . "," . // 5
85 js_escape($row['period']) . "," . // 6
86 js_escape($row['substitute']) . "," . // 7
87 js_escape($row['quantity']) . "," . // 8
88 js_escape($row['refills']) . "," . // 9
89 js_escape($row['quantity']) . "," . // 10 quantity per_refill
90 js_escape($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 (empty($this->prescriptions
[0]) ||
!is_object($this->prescriptions
[0]) ||
(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 $this->assign("GBL_CURRENCY_SYMBOL", $GLOBALS['gbl_currency_symbol']);
120 // If quantity to dispense is not already set from a POST, set its
122 if (! $this->get_template_vars('DISP_QUANTITY')) {
123 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
126 $this->default_action();
129 function list_action($id, $sort = "")
132 $this->function_argument_error();
137 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
139 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
142 // Collect interactions if the global is turned on
143 if ($GLOBALS['rx_show_drug_drug']) {
145 // Ensure RxNorm installed
146 $rxn = sqlQuery("SELECT table_name FROM information_schema.tables WHERE table_name = 'RXNCONSO' OR table_name = 'rxconso'");
148 $interaction = xlt("Could not find RxNorm Table! Please install.");
149 } elseif ($rxn == true) {
150 // Grab medication list from prescriptions list and load into array
151 $pid = $GLOBALS['pid'];
152 $medList = sqlStatement("SELECT drug FROM prescriptions WHERE active = 1 AND patient_id = ?", array($pid));
154 while ($name = sqlFetchArray($medList)) {
155 $drug = explode(" ", $name['drug']);
156 $rXn = sqlQuery("SELECT `rxcui` FROM `" . mitigateSqlTableUpperCase('RXNCONSO') . "` WHERE `str` LIKE ?", array("%" . $drug[0] . "%"));
157 $nameList[] = $rXn['rxcui'];
159 if (count($nameList) < 2) {
160 $interaction = xlt("Need more than one drug.");
162 // If there are drugs to compare, collect the data
163 // (array_filter removes empty items)
164 $rxcui_list = implode("+", array_filter($nameList));
165 // Unable to urlencode the $rxcui, since this breaks the + items on call to rxnav.nlm.nih.gov; so need to include it in the path
166 $response = oeHttp
::get('https://rxnav.nlm.nih.gov/REST/interaction/list.json?rxcuis=' . $rxcui_list);
167 $data = $response->body();
168 $json = json_decode($data, true);
169 if (!empty($json['fullInteractionTypeGroup'][0]['fullInteractionType'])) {
170 foreach ($json['fullInteractionTypeGroup'][0]['fullInteractionType'] as $item) {
171 $interaction .= '<div class="alert alert-danger">';
172 $interaction .= xlt('Comment') . ":" . text($item['comment']) . "<br />";
173 $interaction .= xlt('Drug1 Name{{Drug1 Interaction}}') . ":" . text($item['minConcept'][0]['name']) . "<br />";
174 $interaction .= xlt('Drug2 Name{{Drug2 Interaction}}') . ":" . text($item['minConcept'][1]['name']) . "<br />";
175 $interaction .= xlt('Severity') . ":" . text($item['interactionPair'][0]['severity']) . "<br />";
176 $interaction .= xlt('Description') . ":" . text($item['interactionPair'][0]['description']);
177 $interaction .= '</div>';
180 $interaction = xlt('No interactions found');
184 $this->assign("INTERACTION", $interaction);
187 // flag to indicate the CAMOS form is regsitered and active
188 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
190 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
193 function block_action($id, $sort = "")
196 $this->function_argument_error();
201 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
203 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
206 //print_r(Prescription::prescriptions_factory($id));
207 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
210 function fragment_action($id, $sort = "")
213 $this->function_argument_error();
218 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
220 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
223 //print_r(Prescription::prescriptions_factory($id));
224 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_fragment.html");
227 function lookup_action()
230 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
233 function edit_action_process()
235 if ($_POST['process'] != "true") {
241 // Stupid Smarty code treats empty values as not specified values.
242 // Since active is a checkbox, represent the unchecked state as -1.
243 if (empty($_POST['active'])) {
244 $_POST['active'] = '-1';
246 if (!empty($_POST['start_date'])) {
247 $_POST['start_date'] = DateToYYYYMMDD($_POST['start_date']);
250 $this->prescriptions
[0] = new Prescription($_POST['id']);
251 parent
::populate_object($this->prescriptions
[0]);
252 //echo $this->prescriptions[0]->toString(true);
253 $this->prescriptions
[0]->persist();
254 $_POST['process'] = "";
256 $this->assign("GBL_CURRENCY_SYMBOL", $GLOBALS['gbl_currency_symbol']);
258 // If the "Prescribe and Dispense" button was clicked, then
259 // redisplay as in edit_action() but also replicate the fee and
260 // include a piece of javascript to call dispense().
262 if (!empty($_POST['disp_button'])) {
263 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
264 $this->assign("DISP_FEE", $_POST['disp_fee']);
265 $this->assign("ENDING_JAVASCRIPT", "dispense();");
266 $this->_state
= false;
267 return $this->edit_action($this->prescriptions
[0]->id
);
270 // Set the AMC reporting flag (to record percentage of prescriptions that
271 // are set as e-prescriptions)
272 if (!(empty($_POST['escribe_flag']))) {
273 // add the e-prescribe flag
274 processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
276 // remove the e-prescribe flag
277 processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
280 // Set the AMC reporting flag (to record prescriptions that checked drug formulary)
281 if (!(empty($_POST['checked_formulary_flag']))) {
282 // add the e-prescribe flag
283 processAmcCall('e_prescribe_chk_formulary_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
285 // remove the e-prescribe flag
286 processAmcCall('e_prescribe_chk_formulary_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
289 // Set the AMC reporting flag (to record prescriptions that are controlled substances)
290 if (!(empty($_POST['controlled_substance_flag']))) {
291 // add the e-prescribe flag
292 processAmcCall('e_prescribe_cont_subst_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
294 // remove the e-prescribe flag
295 processAmcCall('e_prescribe_cont_subst_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
298 // TajEmo Work by CB 2012/05/29 02:58:29 PM to stop from going to send screen. Improves Work Flow
299 // if ($this->prescriptions[0]->get_active() > 0) {
300 // return $this->send_action($this->prescriptions[0]->id);
302 $this->list_action($this->prescriptions
[0]->get_patient_id());
306 function send_action($id)
308 $_POST['process'] = "true";
310 $this->function_argument_error();
313 $rx = new Prescription($id);
314 // Populate pharmacy info if the patient has a default pharmacy.
315 // Probably the Prescription object should handle this instead, but
316 // doing it there will require more careful research and testing.
317 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
318 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
319 if ($prow['pharmacy_id']) {
320 $rx->pharmacy
->set_id($prow['pharmacy_id']);
321 $rx->pharmacy
->populate();
324 $this->assign("prescription", $rx);
326 $this->_state
= false;
327 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
328 $this->template_mod
. "_send.html");
331 function multiprintfax_header(&$pdf, $p)
333 return $this->multiprint_header($pdf, $p);
336 function multiprint_header(&$pdf, $p)
338 $this->providerid
= $p->provider
->id
;
340 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'], '', '50', '', 'center', '');
341 $pdf->ezColumnsStart(array('num' => 2, 'gap' => 10));
342 $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 ='" .
343 add_escape_custom($p->provider
->id
) . "'");
344 $pdf->ezText($res['addr'], 12);
347 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>', 12);
348 // A client had a bad experience with a patient misusing a DEA number, so
349 // now the doctors write those in on printed prescriptions and only when
350 // necessary. If you need to change this back, then please make it a
351 // configurable option. Faxed prescriptions were not changed. -- Rod
352 // Now it is configureable. Change value in
353 // Administration->Globals->Rx
354 if ($GLOBALS['rx_enable_DEA']) {
355 if ($this->is_faxing ||
$GLOBALS['rx_show_DEA']) {
356 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
, 12);
358 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
362 if ($GLOBALS['rx_enable_NPI']) {
363 if ($this->is_faxing ||
$GLOBALS['rx_show_NPI']) {
364 $pdf->ezText('<b>' . xl('NPI') . ':</b>' . $p->provider
->npi
, 12);
366 $pdf->ezText('<b>' . xl('NPI') . ':</b> _________________________', 12);
370 if ($GLOBALS['rx_enable_SLN']) {
371 if ($this->is_faxing ||
$GLOBALS['rx_show_SLN']) {
372 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
, 12);
374 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b> ___________________', 12);
378 $pdf->ezColumnsStop();
379 if ($my_y < $pdf->y
) {
383 $pdf->ezText('', 10);
384 $pdf->setLineStyle(1);
385 $pdf->ezColumnsStart(array('num' => 2));
386 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
387 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>', 6);
388 $pdf->ezText($p->patient
->get_name_display(), 10);
389 $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
));
390 $pdf->ezText($res['addr']);
393 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
394 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>', 6);
395 $pdf->ezText($p->patient
->date_of_birth
, 10);
397 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
398 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>', 6);
399 $pdf->ezText(str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
), 10);
400 $pdf->ezColumnsStop();
401 if ($my_y < $pdf->y
) {
406 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
407 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>', 6);
408 $pdf->ezText('', 10);
411 function multiprintcss_header($p)
413 echo("<div class='paddingdiv'>\n");
414 $this->providerid
= $p->provider
->id
;
415 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
417 echo ("<td></td>\n");
419 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
424 $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
) . "'");
426 $patterns = array ('/\n/','/Tel:/','/Fax:/');
427 $replace = array ('<br />', xl('Tel') . ':', xl('Fax') . ':');
428 $res = preg_replace($patterns, $replace, $res);
431 echo ('<span class="large">' . $res['addr'] . '</span>');
434 echo ('<b><span class="large">' . $p->provider
->get_name_display() . '</span></b>' . '<br />');
436 if ($GLOBALS['rx_enable_DEA']) {
437 if ($GLOBALS['rx_show_DEA']) {
438 echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
. '</span><br />');
440 echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________<br />' );
444 if ($GLOBALS['rx_enable_NPI']) {
445 if ($GLOBALS['rx_show_NPI']) {
446 echo ('<span class="large"><b>' . xl('NPI') . ':</b>' . $p->provider
->npi
. '</span><br />');
448 echo ('<b><span class="large">' . xl('NPI') . ':</span></b> ________________________<br />');
452 if ($GLOBALS['rx_enable_SLN']) {
453 if ($GLOBALS['rx_show_SLN']) {
454 echo ('<span class="large"><b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
. '</span><br />');
456 echo ('<b><span class="large">' . xl('State Lic. #') . ':</span></b> ________________________<br />');
463 echo ("<td rowspan='2' class='bordered'>\n");
464 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>' . '<br />');
465 echo ($p->patient
->get_name_display() . '<br />');
466 $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
));
468 $patterns = array ('/\n/');
469 $replace = array ('<br />');
470 $res = preg_replace($patterns, $replace, $res);
475 echo ("<td class='bordered'>\n");
476 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br />');
477 echo ($p->patient
->date_of_birth
);
481 echo ("<td class='bordered'>\n");
482 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br />');
483 echo (str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
));
487 echo ("<td colspan='2' class='bordered'>\n");
488 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
494 function multiprintcss_preheader()
496 // this sets styling and other header information of the multiprint css sheet
501 echo (" padding: 0;\n");
502 echo (" margin: 0;\n");
505 echo (" font-family: sans-serif;\n");
506 echo (" font-weight: normal;\n");
507 echo (" font-size: 10pt;\n");
508 echo (" background: white;\n");
509 echo (" color: black;\n");
511 echo ("span.large {\n");
512 echo (" font-size: 12pt;\n");
514 echo ("span.small {\n");
515 echo (" font-size: 6pt;\n");
518 echo (" vertical-align: top;\n");
519 echo (" width: 50%;\n");
520 echo (" font-size: 10pt;\n");
521 echo (" padding-bottom: 8pt;\n");
523 echo ("td.bordered {\n");
524 echo (" border-top:1pt solid black;\n");
526 echo ("div.paddingdiv {\n");
527 echo (" width: 524pt;\n");
528 echo (" height: 668pt;\n");
530 echo ("div.scriptdiv {\n");
531 echo (" padding-top: 12pt;\n");
532 echo (" padding-bottom: 22pt;\n");
533 echo (" padding-left: 35pt;\n");
534 echo (" border-bottom:1pt solid black;\n");
536 echo ("div.signdiv {\n");
537 echo (" margin-top: 40pt;\n");
538 echo (" font-size: 12pt;\n");
542 echo ("<title>" . xl('Prescription') . "</title>\n");
547 function multiprintfax_footer(&$pdf)
549 return $this->multiprint_footer($pdf);
552 function multiprint_footer(&$pdf)
554 if ($this->pconfig
['use_signature'] && ( $this->is_faxing ||
$this->is_print_to_fax
)) {
555 $sigfile = str_replace('{userid}', $_SESSION["authUser"], $this->pconfig
['signature']);
556 if (file_exists($sigfile)) {
557 $pdf->ezText(xl('Signature') . ": ", 12);
558 // $pdf->ezImage($sigfile, "", "", "none", "left");
559 $pdf->ezImage($sigfile, "", "", "none", "center");
560 $pdf->ezText(xl('Date') . ": " . date('Y-m-d'), 12);
561 if ($this->is_print_to_fax
) {
562 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
565 $addenumFile = $this->pconfig
['addendum_file'];
566 if (file_exists($addenumFile)) {
568 $f = fopen($addenumFile, "r");
569 while ($line = fgets($f, 1000)) {
570 $pdf->ezText(rtrim($line));
578 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'), 12);
581 function multiprintcss_footer()
583 echo ("<div class='signdiv'>\n");
584 echo (xl('Signature') . ":________________________________<br />");
585 echo (xl('Date') . ": " . date('Y-m-d'));
590 function multiprintcss_postfooter()
593 echo("opener.top.printLogPrint(window);\n");
599 function get_prescription_body_text($p)
601 $body = '<b>' . xlt('Rx') . ': ' . text($p->get_drug()) . ' ' . text($p->get_size()) . ' ' . text($p->get_unit_display());
602 if ($p->get_form()) {
603 $body .= ' [' . text($p->form_array
[$p->get_form()]) . "]";
606 $body .= "</b> <i>" .
607 text($p->substitute_array
[$p->get_substitute()]) . "</i>\n" .
608 '<b>' . xlt('Disp #') . ':</b> <u>' . text($p->get_quantity()) . "</u>\n" .
609 '<b>' . xlt('Sig') . ':</b> ' . text($p->get_dosage()) . ' ' . text($p->form_array
[$p->get_form()]) . ' ' .
610 text($p->route_array
[$p->get_route()]) . ' ' . text($p->interval_array
[$p->get_interval()]) . "\n";
611 if ($p->get_refills() > 0) {
612 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>" . text($p->get_refills());
613 if ($p->get_per_refill()) {
614 $body .= " " . xlt('of quantity') . " " . text($p->get_per_refill());
619 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>0 (" . xlt('Zero') . ")</u>\n";
622 $note = $p->get_note();
624 $body .= "\n" . text($note) . "\n";
630 function multiprintfax_body(&$pdf, $p)
632 return $this->multiprint_body($pdf, $p);
635 function multiprint_body(&$pdf, $p)
637 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
638 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
639 $d = $this->get_prescription_body_text($p);
640 if ($pdf->ezText($d, 10, array(), 1)) {
641 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
642 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
643 $this->multiprint_footer($pdf);
645 $this->multiprint_header($pdf, $p);
646 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
647 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
651 $pdf->ezText($d, 10);
652 if ($this->pconfig
['shading']) {
653 $pdf->setColor(.9, .9, .9);
654 $pdf->filledRectangle($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'] - $pdf->ez
['leftMargin'], $my_y - $pdf->y
);
655 $pdf->setColor(0, 0, 0);
659 $pdf->ezText($d, 10);
660 $pdf->ez
['leftMargin'] = $GLOBALS['rx_left_margin'];
661 $pdf->ez
['rightMargin'] = $GLOBALS['rx_right_margin'];
663 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
667 function multiprintcss_body($p)
669 $d = $this->get_prescription_body_text($p);
670 $patterns = array ('/\n/','/ /');
671 $replace = array ('<br />',' ');
672 $d = preg_replace($patterns, $replace, $d);
673 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
676 function multiprintfax_action($id = "")
678 $this->is_print_to_fax
= true;
679 return $this->multiprint_action($id);
682 function multiprint_action($id = "")
684 $_POST['process'] = "true";
686 $this->function_argument_error();
689 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
690 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
691 $pdf->selectFont('Helvetica');
693 // $print_header = true;
696 //print prescriptions body
697 $this->_state
= false; // Added by Rod - see Controller.class.php
698 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
699 foreach ($ids as $id) {
700 $p = new Prescription($id);
701 // if ($print_header == true) {
702 if ($on_this_page == 0) {
703 $this->multiprint_header($pdf, $p);
706 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
707 $this->multiprint_footer($pdf);
709 $this->multiprint_header($pdf, $p);
710 // $print_header = false;
714 $this->multiprint_body($pdf, $p);
717 $this->multiprint_footer($pdf);
719 $pFirstName = $p->patient
->fname
; //modified by epsdky for prescription filename change to include patient name and ID
720 $pFName = convert_safe_file_dir_name($pFirstName);
721 $modedFileName = "Rx_{$pFName}_{$p->patient->id}.pdf";
722 $pdf->ezStream(array('Content-Disposition' => $modedFileName));
726 function multiprintcss_action($id = "")
728 $_POST['process'] = "true";
730 $this->function_argument_error();
733 $this->multiprintcss_preheader();
735 $this->_state
= false; // Added by Rod - see Controller.class.php
736 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
739 foreach ($ids as $id) {
740 $p = new Prescription($id);
741 if ($on_this_page == 0) {
742 $this->multiprintcss_header($p);
745 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
746 $this->multiprintcss_footer();
747 $this->multiprintcss_header($p);
751 $this->multiprintcss_body($p);
754 $this->multiprintcss_footer();
755 $this->multiprintcss_postfooter();
759 function send_action_process($id)
761 $dummy = ""; // Added by Rod to avoid run-time warnings
762 if ($_POST['process'] != "true") {
767 $this->function_argument_error();
770 $p = new Prescription($id);
771 switch ($_POST['submit']) {
772 case (xl("Print") . " (" . xl("PDF") . ")"):
773 // The following statement added by Rod.
774 // Looking at Controller.class.php, it appears that _state is set to false
775 // to indicate that no further HTML is to be generated.
776 $this->_state
= false; // Added by Rod - see Controller.class.php
777 return $this->_print_prescription($p, $dummy);
779 case (xl("Print") . " (" . xl("HTML") . ")"):
780 $this->_state
= false;
781 return $this->_print_prescription_css($p, $dummy);
783 case xl("Print To Fax"):
784 $this->_state
= false;
785 $this->is_print_to_fax
= true;
786 return $this->_print_prescription($p, $dummy);
789 return $this->_email_prescription($p, $_POST['email_to']);
792 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
793 //$this->assign("process_result","No fax server is currently setup.");
794 return $this->_fax_prescription($p, $_POST['fax_to']);
796 case xl("Auto Send"):
797 $pharmacy_id = $_POST['pharmacy_id'];
798 //echo "auto sending to : " . $_POST['pharmacy_id'];
799 $phar = new Pharmacy($_POST['pharmacy_id']);
801 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
802 return $this->_print_prescription($p, $dummy);
803 } elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
804 $email = $phar->get_email();
805 if (!empty($email)) {
806 return $this->_email_prescription($p, $phar->get_email());
810 } elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
811 $faxNum = $phar->get_fax();
812 if (!empty($faxNum)) {
813 return $this->_fax_prescription($p, $faxNum);
816 // return $this->assign("process_result","No fax server is currently setup.");
817 // else default is printing,
819 //the pharmacy has no default or default is print
820 return $this->_print_prescription($p, $dummy);
828 function _print_prescription($p, &$toFile)
830 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
831 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
833 $pdf->selectFont('Helvetica');
835 // Signature images are to be used only when faxing.
836 if (!empty($toFile)) {
837 $this->is_faxing
= true;
840 $this->multiprint_header($pdf, $p);
841 $this->multiprint_body($pdf, $p);
842 $this->multiprint_footer($pdf);
844 if (!empty($toFile)) {
845 $toFile = $pdf->ezOutput();
848 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
854 function _print_prescription_css($p, &$toFile)
857 $this->multiprintcss_preheader();
858 $this->multiprintcss_header($p);
859 $this->multiprintcss_body($p);
860 $this->multiprintcss_footer();
861 $this->multiprintcss_postfooter();
864 function _print_prescription_old($p, &$toFile)
866 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
867 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
868 $pdf->selectFont('Helvetica');
869 if (!empty($this->pconfig
['logo'])) {
870 $pdf->ezImage($this->pconfig
['logo'], "", "", "none", "left");
873 $pdf->ezText($p->get_prescription_display(), 10);
874 if ($this->pconfig
['use_signature']) {
875 $pdf->ezImage($this->pconfig
['signature'], "", "", "none", "left");
877 $pdf->ezText("\n\n\n\nSignature:________________________________", 10);
880 if (!empty($toFile)) {
881 $toFile = $pdf->ezOutput();
884 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
890 function _email_prescription($p, $email)
893 $this->assign("process_result", "Email could not be sent, the address supplied: '$email' was empty or invalid.");
897 $mail = new PHPMailer();
898 //this is a temporary config item until the rest of the per practice billing settings make their way in
899 $mail->From
= $GLOBALS['practice_return_email_path'];
900 $mail->FromName
= $p->provider
->get_name_display();
902 $mail->Host
= "localhost";
903 $mail->Mailer
= "mail";
904 $text_body = $p->get_prescription_display();
905 $mail->Body
= $text_body;
906 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
907 $mail->AddAddress($email);
909 $this->assign("process_result", "Email was successfully sent to: " . $email);
912 $this->assign("process_result", "There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
919 if ($_POST['process'] != "true") {
921 $this->assign("drug", $_GET['drug']);
925 // process the lookup
926 $this->assign("drug", $_POST['drug']);
928 if (!empty($_POST['drug'])) {
929 $list = $this->RxList
->getList($_POST['drug']);
932 if (is_array($list)) {
933 $list = array_flip($list);
934 $this->assign("drug_options", $list);
935 $this->assign("drug_values", array_keys($list));
937 $this->assign("NO_RESULTS", xl("No results found for") . ": " . $_POST['drug']);
941 //$this->assign("PROCESS","");
943 $_POST['process'] = "";
946 function _fax_prescription($p, $faxNum)
949 //strip - ,(, ), and ws
950 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/", "", $faxNum);
951 //validate the number
953 if (!empty($faxNum) && is_numeric($faxNum)) {
954 //get the sendfax command and execute it
955 $cmd = $this->pconfig
['sendfax'];
956 // prepend any prefix to the fax number
957 $pref = $this->pconfig
['prefix'];
958 $faxNum = $pref . $faxNum;
960 $err .= " Send fax not set in includes/config.php";
962 //generate file to fax
964 $this->_print_prescription($p, $faxFile);
965 if (empty($faxFile)) {
966 $err .= " _print_prescription returned empty file";
969 $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() .
970 $p->get_patient_id() . "_fax_.pdf";
971 //print "filename is $fileName";
972 touch($fileName); // php bug
973 $handle = fopen($fileName, "w");
975 $err .= " Failed to open file $fileName to write fax to";
978 if (fwrite($handle, $faxFile) === false) {
979 $err .= " Failed to write data to $fileName";
983 $args = " -n -d $faxNum $fileName";
984 //print "command is $cmd $args<br />";
988 $err = "bad fax number passed to function";
992 $this->assign("process_result", $err);