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.php");
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;
35 function __construct($template_mod = "general")
37 parent
::__construct();
38 $this->template_mod
= $template_mod;
39 $this->assign("FORM_ACTION", $GLOBALS['webroot'] . "/controller.php?" . attr($_SERVER['QUERY_STRING']));
40 $this->assign("TOP_ACTION", $GLOBALS['webroot'] . "/controller.php?" . "prescription" . "&");
41 $this->assign("STYLE", $GLOBALS['style']);
42 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
43 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
44 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
45 $this->RxList
= new RxList();
46 // test if rxnorm available for lookups.
47 $rxn = sqlQuery("SELECT table_name FROM information_schema.tables WHERE table_name = 'RXNCONSO' OR table_name = 'rxconso'");
48 $rxcui = sqlQuery("SELECT ct_id FROM `code_types` WHERE `ct_key` = ? AND `ct_active` = 1", array('RXCUI'));
49 $this->assign("RXNORMS_AVAILABLE", !empty($rxn));
50 $this->assign("RXCUI_AVAILABLE", !empty($rxcui));
51 // Assign the CSRF_TOKEN_FORM
52 $this->assign("CSRF_TOKEN_FORM", CsrfUtils
::collectCsrfToken());
54 if ($GLOBALS['inhouse_pharmacy']) {
55 // Make an array of drug IDs and selectors for the template.
56 $drug_array_values = array(0);
57 $drug_array_output = array("-- " . xl('or select from inventory') . " --");
58 $drug_attributes = '';
60 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
62 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
63 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
64 "t.period, t.quantity, t.refills, d.drug_code " .
65 "FROM drug_templates AS t, drugs AS d WHERE " .
66 "d.drug_id = t.drug_id ORDER BY t.selector");
68 while ($row = sqlFetchArray($res)) {
69 $tmp_output = $row['selector'];
70 if ($row['ndc_number']) {
71 $tmp_output .= ' [' . $row['ndc_number'] . ']';
74 $drug_array_values[] = $row['drug_id'];
75 $drug_array_output[] = $tmp_output;
76 if ($drug_attributes) {
77 $drug_attributes .= ',';
80 $drug_attributes .= "[" .
81 js_escape($row['name']) . "," . // 0
82 js_escape($row['form']) . "," . // 1
83 js_escape($row['dosage']) . "," . // 2
84 js_escape($row['size']) . "," . // 3
85 js_escape($row['unit']) . "," . // 4
86 js_escape($row['route']) . "," . // 5
87 js_escape($row['period']) . "," . // 6
88 js_escape($row['substitute']) . "," . // 7
89 js_escape($row['quantity']) . "," . // 8
90 js_escape($row['refills']) . "," . // 9
91 js_escape($row['quantity']) . "," . // 10 quantity per_refill
92 js_escape($row['drug_code']) . "]"; // 11 rxnorm drug code
95 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
96 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
97 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
101 function default_action()
103 $this->assign("prescription", $this->prescriptions
[0]);
104 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
107 function edit_action($id = "", $patient_id = "", $p_obj = null)
110 if ($p_obj != null && get_class($p_obj) == "prescription") {
111 $this->prescriptions
[0] = $p_obj;
112 } elseif (empty($this->prescriptions
[0]) ||
!is_object($this->prescriptions
[0]) ||
(get_class($this->prescriptions
[0]) != "prescription")) {
113 $this->prescriptions
[0] = new Prescription($id);
116 if (!empty($patient_id)) {
117 $this->prescriptions
[0]->set_patient_id($patient_id);
120 $this->assign("GBL_CURRENCY_SYMBOL", $GLOBALS['gbl_currency_symbol']);
122 // If quantity to dispense is not already set from a POST, set its
124 if (! $this->getTemplateVars('DISP_QUANTITY')) {
125 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
128 $this->default_action();
131 function list_action($id, $sort = "")
134 $this->function_argument_error();
139 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
141 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
144 // Collect interactions if the global is turned on
145 if ($GLOBALS['rx_show_drug_drug']) {
147 // Ensure RxNorm installed
148 $rxn = sqlQuery("SELECT table_name FROM information_schema.tables WHERE table_name = 'RXNCONSO' OR table_name = 'rxconso'");
150 $interaction = xlt("Could not find RxNorm Table! Please install.");
151 } elseif ($rxn == true) {
152 // Grab medication list from prescriptions list and load into array
153 $pid = $GLOBALS['pid'];
154 $medList = sqlStatement("SELECT drug FROM prescriptions WHERE active = 1 AND patient_id = ?", array($pid));
156 while ($name = sqlFetchArray($medList)) {
157 $drug = explode(" ", $name['drug']);
158 $rXn = sqlQuery("SELECT `rxcui` FROM `" . mitigateSqlTableUpperCase('RXNCONSO') . "` WHERE `str` LIKE ?", array("%" . $drug[0] . "%"));
159 $nameList[] = $rXn['rxcui'];
161 if (count($nameList) < 2) {
162 $interaction = xlt("Need more than one drug.");
164 // If there are drugs to compare, collect the data
165 // (array_filter removes empty items)
166 $rxcui_list = implode("+", array_filter($nameList));
167 // 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
168 $response = oeHttp
::get('https://rxnav.nlm.nih.gov/REST/interaction/list.json?rxcuis=' . $rxcui_list);
169 $data = $response->body();
170 $json = json_decode($data, true);
171 if (!empty($json['fullInteractionTypeGroup'][0]['fullInteractionType'])) {
172 foreach ($json['fullInteractionTypeGroup'][0]['fullInteractionType'] as $item) {
173 $interaction .= '<div class="alert alert-danger">';
174 $interaction .= xlt('Comment') . ":" . text($item['comment']) . "<br />";
175 $interaction .= xlt('Drug1 Name{{Drug1 Interaction}}') . ":" . text($item['minConcept'][0]['name']) . "<br />";
176 $interaction .= xlt('Drug2 Name{{Drug2 Interaction}}') . ":" . text($item['minConcept'][1]['name']) . "<br />";
177 $interaction .= xlt('Severity') . ":" . text($item['interactionPair'][0]['severity']) . "<br />";
178 $interaction .= xlt('Description') . ":" . text($item['interactionPair'][0]['description']);
179 $interaction .= '</div>';
182 $interaction = xlt('No interactions found');
186 $this->assign("INTERACTION", $interaction);
189 // flag to indicate the CAMOS form is regsitered and active
190 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
192 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
195 function block_action($id, $sort = "")
198 $this->function_argument_error();
203 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
205 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
208 //print_r(Prescription::prescriptions_factory($id));
209 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
212 function fragment_action($id, $sort = "")
215 $this->function_argument_error();
220 $this->assign("prescriptions", Prescription
::prescriptions_factory($id, $sort));
222 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
225 //print_r(Prescription::prescriptions_factory($id));
226 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_fragment.html");
229 function lookup_action()
232 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
235 function edit_action_process()
237 if ($_POST['process'] != "true") {
243 // Stupid Smarty code treats empty values as not specified values.
244 // Since active is a checkbox, represent the unchecked state as -1.
245 if (empty($_POST['active'])) {
246 $_POST['active'] = '-1';
248 if (!empty($_POST['start_date'])) {
249 $_POST['start_date'] = DateToYYYYMMDD($_POST['start_date']);
252 $this->prescriptions
[0] = new Prescription($_POST['id']);
253 parent
::populate_object($this->prescriptions
[0]);
254 //echo $this->prescriptions[0]->toString(true);
255 $this->prescriptions
[0]->persist();
256 $_POST['process'] = "";
258 $this->assign("GBL_CURRENCY_SYMBOL", $GLOBALS['gbl_currency_symbol']);
260 // If the "Prescribe and Dispense" button was clicked, then
261 // redisplay as in edit_action() but also replicate the fee and
262 // include a piece of javascript to call dispense().
264 if (!empty($_POST['disp_button'])) {
265 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
266 $this->assign("DISP_FEE", $_POST['disp_fee']);
267 $this->assign("ENDING_JAVASCRIPT", "dispense();");
268 $this->_state
= false;
269 return $this->edit_action($this->prescriptions
[0]->id
);
272 // Set the AMC reporting flag (to record percentage of prescriptions that
273 // are set as e-prescriptions)
274 if (!(empty($_POST['escribe_flag']))) {
275 // add the e-prescribe flag
276 processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
278 // remove the e-prescribe flag
279 processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
282 // Set the AMC reporting flag (to record prescriptions that checked drug formulary)
283 if (!(empty($_POST['checked_formulary_flag']))) {
284 // add the e-prescribe flag
285 processAmcCall('e_prescribe_chk_formulary_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
287 // remove the e-prescribe flag
288 processAmcCall('e_prescribe_chk_formulary_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
291 // Set the AMC reporting flag (to record prescriptions that are controlled substances)
292 if (!(empty($_POST['controlled_substance_flag']))) {
293 // add the e-prescribe flag
294 processAmcCall('e_prescribe_cont_subst_amc', true, 'add', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
296 // remove the e-prescribe flag
297 processAmcCall('e_prescribe_cont_subst_amc', true, 'remove', $this->prescriptions
[0]->get_patient_id(), 'prescriptions', $this->prescriptions
[0]->id
);
300 // TajEmo Work by CB 2012/05/29 02:58:29 PM to stop from going to send screen. Improves Work Flow
301 // if ($this->prescriptions[0]->get_active() > 0) {
302 // return $this->send_action($this->prescriptions[0]->id);
304 $this->list_action($this->prescriptions
[0]->get_patient_id());
308 function send_action($id)
310 $_POST['process'] = "true";
312 $this->function_argument_error();
315 $rx = new Prescription($id);
316 // Populate pharmacy info if the patient has a default pharmacy.
317 // Probably the Prescription object should handle this instead, but
318 // doing it there will require more careful research and testing.
319 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
320 "patient_data AS pt WHERE rx.id = ? AND pt.pid = rx.patient_id", [$id]);
321 if ($prow['pharmacy_id']) {
322 $rx->pharmacy
->set_id($prow['pharmacy_id']);
323 $rx->pharmacy
->populate();
326 $this->assign("prescription", $rx);
328 $this->_state
= false;
329 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
330 $this->template_mod
. "_send.html");
333 function multiprintfax_header(&$pdf, $p)
335 return $this->multiprint_header($pdf, $p);
338 function multiprint_header(&$pdf, $p)
340 $this->providerid
= $p->provider
->id
;
342 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'], null, '50', '', 'center', '');
343 $pdf->ezColumnsStart(array('num' => 2, 'gap' => 10));
344 $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 ='" .
345 add_escape_custom($p->provider
->id
) . "'");
346 $pdf->ezText($res['addr'] ??
'', 12);
349 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>', 12);
350 // A client had a bad experience with a patient misusing a DEA number, so
351 // now the doctors write those in on printed prescriptions and only when
352 // necessary. If you need to change this back, then please make it a
353 // configurable option. Faxed prescriptions were not changed. -- Rod
354 // Now it is configureable. Change value in
355 // Administration->Globals->Rx
356 if ($GLOBALS['rx_enable_DEA']) {
357 if ($this->is_faxing ||
$GLOBALS['rx_show_DEA']) {
358 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
, 12);
360 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
364 if ($GLOBALS['rx_enable_NPI']) {
365 if ($this->is_faxing ||
$GLOBALS['rx_show_NPI']) {
366 $pdf->ezText('<b>' . xl('NPI') . ':</b>' . $p->provider
->npi
, 12);
368 $pdf->ezText('<b>' . xl('NPI') . ':</b> _________________________', 12);
372 if ($GLOBALS['rx_enable_SLN']) {
373 if ($this->is_faxing ||
$GLOBALS['rx_show_SLN']) {
374 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
, 12);
376 $pdf->ezText('<b>' . xl('State Lic. #') . ':</b> ___________________', 12);
380 $pdf->ezColumnsStop();
381 if ($my_y < $pdf->y
) {
385 $pdf->ezText('', 10);
386 $pdf->setLineStyle(1);
387 $pdf->ezColumnsStart(array('num' => 2));
388 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
389 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>', 6);
390 $pdf->ezText($p->patient
->get_name_display(), 10);
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
));
392 $pdf->ezText($res['addr']);
395 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
396 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>', 6);
397 $pdf->ezText($p->patient
->date_of_birth
, 10);
399 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
400 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>', 6);
401 $pdf->ezText(str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
), 10);
402 $pdf->ezColumnsStop();
403 if ($my_y < $pdf->y
) {
408 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
409 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>', 6);
410 $pdf->ezText('', 10);
413 function multiprintcss_header($p)
415 echo("<div class='paddingdiv'>\n");
416 $this->providerid
= $p->provider
->id
;
417 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
419 echo ("<td></td>\n");
421 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
426 $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
) . "'");
428 $patterns = array ('/\n/','/Tel:/','/Fax:/');
429 $replace = array ('<br />', xl('Tel') . ':', xl('Fax') . ':');
430 $res = preg_replace($patterns, $replace, $res);
433 echo ('<span class="large">' . ($res['addr'] ??
'') . '</span>');
436 echo ('<b><span class="large">' . $p->provider
->get_name_display() . '</span></b>' . '<br />');
438 if ($GLOBALS['rx_enable_DEA']) {
439 if ($GLOBALS['rx_show_DEA']) {
440 echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
. '</span><br />');
442 echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________<br />' );
446 if ($GLOBALS['rx_enable_NPI']) {
447 if ($GLOBALS['rx_show_NPI']) {
448 echo ('<span class="large"><b>' . xl('NPI') . ':</b>' . $p->provider
->npi
. '</span><br />');
450 echo ('<b><span class="large">' . xl('NPI') . ':</span></b> ________________________<br />');
454 if ($GLOBALS['rx_enable_SLN']) {
455 if ($GLOBALS['rx_show_SLN']) {
456 echo ('<span class="large"><b>' . xl('State Lic. #') . ':</b>' . $p->provider
->state_license_number
. '</span><br />');
458 echo ('<b><span class="large">' . xl('State Lic. #') . ':</span></b> ________________________<br />');
465 echo ("<td rowspan='2' class='bordered'>\n");
466 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>' . '<br />');
467 echo ($p->patient
->get_name_display() . '<br />');
468 $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
));
470 $patterns = array ('/\n/');
471 $replace = array ('<br />');
472 $res = preg_replace($patterns, $replace, $res);
477 echo ("<td class='bordered'>\n");
478 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br />');
479 echo ($p->patient
->date_of_birth
);
483 echo ("<td class='bordered'>\n");
484 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br />');
485 echo (str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
));
489 echo ("<td colspan='2' class='bordered'>\n");
490 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
496 function multiprintcss_preheader()
498 // this sets styling and other header information of the multiprint css sheet
503 echo (" padding: 0;\n");
504 echo (" margin: 0;\n");
507 echo (" font-family: sans-serif;\n");
508 echo (" font-weight: normal;\n");
509 echo (" font-size: 10pt;\n");
510 echo (" background: white;\n");
511 echo (" color: black;\n");
513 echo ("span.large {\n");
514 echo (" font-size: 12pt;\n");
516 echo ("span.small {\n");
517 echo (" font-size: 6pt;\n");
520 echo (" vertical-align: top;\n");
521 echo (" width: 50%;\n");
522 echo (" font-size: 10pt;\n");
523 echo (" padding-bottom: 8pt;\n");
525 echo ("td.bordered {\n");
526 echo (" border-top:1pt solid black;\n");
528 echo ("div.paddingdiv {\n");
529 echo (" width: 524pt;\n");
530 echo (" height: 668pt;\n");
532 echo ("div.scriptdiv {\n");
533 echo (" padding-top: 12pt;\n");
534 echo (" padding-bottom: 22pt;\n");
535 echo (" padding-left: 35pt;\n");
536 echo (" border-bottom:1pt solid black;\n");
538 echo ("div.signdiv {\n");
539 echo (" margin-top: 40pt;\n");
540 echo (" font-size: 12pt;\n");
544 echo ("<title>" . xl('Prescription') . "</title>\n");
549 function multiprintfax_footer(&$pdf)
551 return $this->multiprint_footer($pdf);
554 function multiprint_footer(&$pdf)
556 if ($this->pconfig
['use_signature'] && ( $this->is_faxing ||
$this->is_print_to_fax
)) {
557 $sigfile = str_replace('{userid}', $_SESSION["authUser"], $this->pconfig
['signature']);
558 if (file_exists($sigfile)) {
559 $pdf->ezText(xl('Signature') . ": ", 12);
560 // $pdf->ezImage($sigfile, "", "", "none", "left");
561 $pdf->ezImage($sigfile, "", "", "none", "center");
562 $pdf->ezText(xl('Date') . ": " . date('Y-m-d'), 12);
563 if ($this->is_print_to_fax
) {
564 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
567 $addenumFile = $this->pconfig
['addendum_file'];
568 if (file_exists($addenumFile)) {
570 $f = fopen($addenumFile, "r");
571 while ($line = fgets($f, 1000)) {
572 $pdf->ezText(rtrim($line));
580 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'), 12);
583 function multiprintcss_footer()
585 echo ("<div class='signdiv'>\n");
586 echo (xl('Signature') . ":________________________________<br />");
587 echo (xl('Date') . ": " . date('Y-m-d'));
592 function multiprintcss_postfooter()
595 echo("opener.top.printLogPrint(window);\n");
601 function get_prescription_body_text($p)
603 $body = '<b>' . xlt('Rx') . ': ' . text($p->get_drug()) . ' ' . text($p->get_size()) . ' ' . text($p->get_unit_display());
604 if ($p->get_form()) {
605 $body .= ' [' . text($p->form_array
[$p->get_form()]) . "]";
608 $body .= "</b> <i>" .
609 text($p->substitute_array
[$p->get_substitute()]) . "</i>\n" .
610 '<b>' . xlt('Disp #') . ':</b> <u>' . text($p->get_quantity()) . "</u>\n" .
611 '<b>' . xlt('Sig') . ':</b> ' . text($p->get_dosage() ??
'') . ' ' . text($p->form_array
[$p->get_form()] ??
'') . ' ' .
612 text($p->route_array
[$p->get_route()] ??
'') . ' ' . text($p->interval_array
[$p->get_interval()] ??
'') . "\n";
613 if ($p->get_refills() > 0) {
614 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>" . text($p->get_refills());
615 if ($p->get_per_refill()) {
616 $body .= " " . xlt('of quantity') . " " . text($p->get_per_refill());
621 $body .= "\n<b>" . xlt('Refills') . ":</b> <u>0 (" . xlt('Zero') . ")</u>\n";
624 $note = $p->get_note();
626 $body .= "\n" . text($note) . "\n";
632 function multiprintfax_body(&$pdf, $p)
634 return $this->multiprint_body($pdf, $p);
637 function multiprint_body(&$pdf, $p)
639 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
640 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
641 $d = $this->get_prescription_body_text($p);
642 if ($pdf->ezText($d, 10, array(), 1)) {
643 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
644 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
645 $this->multiprint_footer($pdf);
647 $this->multiprint_header($pdf, $p);
648 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
649 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
653 $pdf->ezText($d, 10);
654 if ($this->pconfig
['shading']) {
655 $pdf->setColor(.9, .9, .9);
656 $pdf->filledRectangle($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'] - $pdf->ez
['leftMargin'], $my_y - $pdf->y
);
657 $pdf->setColor(0, 0, 0);
661 $pdf->ezText($d, 10);
662 $pdf->ez
['leftMargin'] = $GLOBALS['rx_left_margin'];
663 $pdf->ez
['rightMargin'] = $GLOBALS['rx_right_margin'];
665 $pdf->line($pdf->ez
['leftMargin'], $pdf->y
, $pdf->ez
['pageWidth'] - $pdf->ez
['rightMargin'], $pdf->y
);
669 function multiprintcss_body($p)
671 $d = $this->get_prescription_body_text($p);
672 $patterns = array ('/\n/','/ /');
673 $replace = array ('<br />',' ');
674 $d = preg_replace($patterns, $replace, $d);
675 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
678 function multiprintfax_action($id = "")
680 $this->is_print_to_fax
= true;
681 return $this->multiprint_action($id);
684 function multiprint_action($id = "")
686 $_POST['process'] = "true";
688 $this->function_argument_error();
691 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
692 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
693 $pdf->selectFont('Helvetica');
695 // $print_header = true;
698 //print prescriptions body
699 $this->_state
= false; // Added by Rod - see Controller.class.php
700 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
701 foreach ($ids as $id) {
702 $p = new Prescription($id);
703 // if ($print_header == true) {
704 if ($on_this_page == 0) {
705 $this->multiprint_header($pdf, $p);
708 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
709 $this->multiprint_footer($pdf);
711 $this->multiprint_header($pdf, $p);
712 // $print_header = false;
716 $this->multiprint_body($pdf, $p);
719 $this->multiprint_footer($pdf);
721 $pFirstName = $p->patient
->fname
; //modified by epsdky for prescription filename change to include patient name and ID
722 $pFName = convert_safe_file_dir_name($pFirstName);
723 $modedFileName = "Rx_{$pFName}_{$p->patient->id}.pdf";
724 $pdf->ezStream(array('Content-Disposition' => $modedFileName));
728 function multiprintcss_action($id = "")
730 $_POST['process'] = "true";
732 $this->function_argument_error();
735 $this->multiprintcss_preheader();
737 $this->_state
= false; // Added by Rod - see Controller.class.php
738 $ids = preg_split('/::/', substr($id, 1, strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
741 foreach ($ids as $id) {
742 $p = new Prescription($id);
743 if ($on_this_page == 0) {
744 $this->multiprintcss_header($p);
747 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
748 $this->multiprintcss_footer();
749 $this->multiprintcss_header($p);
753 $this->multiprintcss_body($p);
756 $this->multiprintcss_footer();
757 $this->multiprintcss_postfooter();
761 function send_action_process($id)
763 $dummy = ""; // Added by Rod to avoid run-time warnings
764 if ($_POST['process'] != "true") {
769 $this->function_argument_error();
772 $p = new Prescription($id);
773 switch ($_POST['submit']) {
774 case (xl("Print") . " (" . xl("PDF") . ")"):
775 // The following statement added by Rod.
776 // Looking at Controller.class.php, it appears that _state is set to false
777 // to indicate that no further HTML is to be generated.
778 $this->_state
= false; // Added by Rod - see Controller.class.php
779 return $this->print_prescription($p, $dummy);
781 case (xl("Print") . " (" . xl("HTML") . ")"):
782 $this->_state
= false;
783 return $this->print_prescription_css($p, $dummy);
785 case xl("Print To Fax"):
786 $this->_state
= false;
787 $this->is_print_to_fax
= true;
788 return $this->print_prescription($p, $dummy);
791 return $this->email_prescription($p, $_POST['email_to']);
794 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
795 //$this->assign("process_result","No fax server is currently setup.");
796 return $this->fax_prescription($p, $_POST['fax_to']);
798 case xl("Auto Send"):
799 $pharmacy_id = $_POST['pharmacy_id'];
800 //echo "auto sending to : " . $_POST['pharmacy_id'];
801 $phar = new Pharmacy($_POST['pharmacy_id']);
803 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
804 return $this->print_prescription($p, $dummy);
805 } elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
806 $email = $phar->get_email();
807 if (!empty($email)) {
808 return $this->email_prescription($p, $phar->get_email());
812 } elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
813 $faxNum = $phar->get_fax();
814 if (!empty($faxNum)) {
815 return $this->fax_prescription($p, $faxNum);
818 // return $this->assign("process_result","No fax server is currently setup.");
819 // else default is printing,
821 //the pharmacy has no default or default is print
822 return $this->print_prescription($p, $dummy);
830 function print_prescription($p, &$toFile)
832 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
833 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
835 $pdf->selectFont('Helvetica');
837 // Signature images are to be used only when faxing.
838 if (!empty($toFile)) {
839 $this->is_faxing
= true;
842 $this->multiprint_header($pdf, $p);
843 $this->multiprint_body($pdf, $p);
844 $this->multiprint_footer($pdf);
846 if (!empty($toFile)) {
847 $toFile = $pdf->ezOutput();
850 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
856 function print_prescription_css($p, &$toFile)
859 $this->multiprintcss_preheader();
860 $this->multiprintcss_header($p);
861 $this->multiprintcss_body($p);
862 $this->multiprintcss_footer();
863 $this->multiprintcss_postfooter();
866 function print_prescription_old($p, &$toFile)
868 $pdf = new Cezpdf($GLOBALS['rx_paper_size']);
869 $pdf->ezSetMargins($GLOBALS['rx_top_margin'], $GLOBALS['rx_bottom_margin'], $GLOBALS['rx_left_margin'], $GLOBALS['rx_right_margin']);
870 $pdf->selectFont('Helvetica');
871 if (!empty($this->pconfig
['logo'])) {
872 $pdf->ezImage($this->pconfig
['logo'], "", "", "none", "left");
875 $pdf->ezText($p->get_prescription_display(), 10);
876 if ($this->pconfig
['use_signature']) {
877 $pdf->ezImage($this->pconfig
['signature'], "", "", "none", "left");
879 $pdf->ezText("\n\n\n\nSignature:________________________________", 10);
882 if (!empty($toFile)) {
883 $toFile = $pdf->ezOutput();
886 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
892 function email_prescription($p, $email)
895 $this->assign("process_result", "Email could not be sent, the address supplied: '$email' was empty or invalid.");
899 $mail = new PHPMailer();
900 //this is a temporary config item until the rest of the per practice billing settings make their way in
901 $mail->From
= $GLOBALS['practice_return_email_path'];
902 $mail->FromName
= $p->provider
->get_name_display();
904 $mail->Host
= "localhost";
905 $mail->Mailer
= "mail";
906 $text_body = $p->get_prescription_display();
907 $mail->Body
= $text_body;
908 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
909 $mail->AddAddress($email);
911 $this->assign("process_result", "Email was successfully sent to: " . $email);
914 $this->assign("process_result", "There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
921 if ($_POST['process'] != "true") {
923 $this->assign("drug", $_GET['drug']);
927 // process the lookup
928 $this->assign("drug", $_POST['drug']);
930 if (!empty($_POST['drug'])) {
931 $list = $this->RxList
->getList($_POST['drug']);
934 if (is_array($list)) {
935 $list = array_flip($list);
936 $this->assign("drug_options", $list);
937 $this->assign("drug_values", array_keys($list));
939 $this->assign("NO_RESULTS", xl("No results found for") . ": " . $_POST['drug']);
943 //$this->assign("PROCESS","");
945 $_POST['process'] = "";
948 function fax_prescription($p, $faxNum)
951 //strip - ,(, ), and ws
952 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/", "", $faxNum);
953 //validate the number
955 if (!empty($faxNum) && is_numeric($faxNum)) {
956 //get the sendfax command and execute it
957 $cmd = $this->pconfig
['sendfax'];
958 // prepend any prefix to the fax number
959 $pref = $this->pconfig
['prefix'];
960 $faxNum = $pref . $faxNum;
962 $err .= " Send fax not set in includes/config.php";
964 //generate file to fax
966 $this->print_prescription($p, $faxFile);
967 if (empty($faxFile)) {
968 $err .= " print_prescription returned empty file";
971 $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() .
972 $p->get_patient_id() . "_fax_.pdf";
973 //print "filename is $fileName";
974 touch($fileName); // php bug
975 $handle = fopen($fileName, "w");
977 $err .= " Failed to open file $fileName to write fax to";
980 if (fwrite($handle, $faxFile) === false) {
981 $err .= " Failed to write data to $fileName";
985 $args = " -n -d $faxNum $fileName";
986 //print "command is $cmd $args<br />";
990 $err = "bad fax number passed to function";
994 $this->assign("process_result", $err);