3 require_once($GLOBALS['fileroot'] . "/library/classes/Controller.class.php");
4 require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php");
5 require_once($GLOBALS['fileroot'] . "/library/classes/Provider.class.php");
6 require_once($GLOBALS['fileroot'] . "/library/classes/RXList.class.php");
7 require_once($GLOBALS['fileroot'] . "/library/registry.inc");
9 class C_Prescription
extends Controller
{
14 var $is_faxing = false;
15 var $is_print_to_fax = false;
17 function C_Prescription($template_mod = "general") {
20 $this->template_mod
= $template_mod;
21 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
22 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&");
23 $this->assign("STYLE", $GLOBALS['style']);
24 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
25 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
26 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
27 $this->assign("CSS_HEADER", $GLOBALS['css_header'] );
28 $this->assign("WEB_ROOT", $GLOBALS['webroot'] );
30 if ($GLOBALS['inhouse_pharmacy']) {
31 // Make an array of drug IDs and selectors for the template.
32 $drug_array_values = array(0);
33 $drug_array_output = array("-- or select from inventory --");
34 $drug_attributes = '';
36 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
38 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
39 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
40 "t.period, t.quantity, t.refills " .
41 "FROM drug_templates AS t, drugs AS d WHERE " .
42 "d.drug_id = t.drug_id ORDER BY t.selector");
44 while ($row = sqlFetchArray($res)) {
45 $tmp_output = $row['selector'];
46 if ($row['ndc_number']) {
47 $tmp_output .= ' [' . $row['ndc_number'] . ']';
49 $drug_array_values[] = $row['drug_id'];
50 $drug_array_output[] = $tmp_output;
51 if ($drug_attributes) $drug_attributes .= ',';
52 $drug_attributes .= "['" .
53 $row['name'] . "'," . // 0
54 $row['form'] . ",'" . // 1
55 $row['dosage'] . "'," . // 2
56 $row['size'] . "," . // 3
57 $row['unit'] . "," . // 4
58 $row['route'] . "," . // 5
59 $row['period'] . "," . // 6
60 $row['substitute'] . "," . // 7
61 $row['quantity'] . "," . // 8
62 $row['refills'] . "," . // 9
63 $row['quantity'] . "]"; // 10 quantity per_refill
65 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
66 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
67 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
71 function default_action() {
72 $this->assign("prescription",$this->prescriptions
[0]);
73 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
76 function edit_action($id = "",$patient_id="",$p_obj = null) {
78 if ($p_obj != null && get_class($p_obj) == "prescription") {
79 $this->prescriptions
[0] = $p_obj;
81 elseif (get_class($this->prescriptions
[0]) != "prescription" ) {
82 $this->prescriptions
[0] = new Prescription($id);
85 if (!empty($patient_id)) {
86 $this->prescriptions
[0]->set_patient_id($patient_id);
89 // If quantity to dispense is not already set from a POST, set its
91 if (! $this->get_template_vars('DISP_QUANTITY')) {
92 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
95 $this->default_action();
98 function list_action($id,$sort = "") {
100 $this->function_argument_error();
104 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
107 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
110 // flag to indicate the CAMOS form is regsitered and active
111 $this->assign("CAMOS_FORM", isRegistered("CAMOS"));
113 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list.html");
116 function block_action($id,$sort = "") {
118 $this->function_argument_error();
122 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
125 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
127 //print_r(Prescription::prescriptions_factory($id));
128 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
131 function fragment_action($id,$sort = "") {
133 $this->function_argument_error();
137 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
140 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
142 //print_r(Prescription::prescriptions_factory($id));
143 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_fragment.html");
146 function lookup_action() {
148 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
151 function edit_action_process() {
152 if ($_POST['process'] != "true")
156 // Stupid Smarty code treats empty values as not specified values.
157 // Since active is a checkbox, represent the unchecked state as -1.
158 if (empty($_POST['active'])) $_POST['active'] = '-1';
160 $this->prescriptions
[0] = new Prescription($_POST['id']);
161 parent
::populate_object($this->prescriptions
[0]);
162 //echo $this->prescriptions[0]->toString(true);
163 $this->prescriptions
[0]->persist();
164 $_POST['process'] = "";
166 // If the "Prescribe and Dispense" button was clicked, then
167 // redisplay as in edit_action() but also replicate the fee and
168 // include a piece of javascript to call dispense().
170 if ($_POST['disp_button']) {
171 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
172 $this->assign("DISP_FEE", $_POST['disp_fee']);
173 $this->assign("ENDING_JAVASCRIPT", "dispense();");
174 $this->_state
= false;
175 return $this->edit_action($this->prescriptions
[0]->id
);
178 if ($this->prescriptions
[0]->get_active() > 0) {
179 return $this->send_action($this->prescriptions
[0]->id
);
181 $this->list_action($this->prescriptions
[0]->get_patient_id());
185 function send_action($id) {
186 $_POST['process'] = "true";
188 $this->function_argument_error();
191 $rx = new Prescription($id);
192 // Populate pharmacy info if the patient has a default pharmacy.
193 // Probably the Prescription object should handle this instead, but
194 // doing it there will require more careful research and testing.
195 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
196 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
197 if ($prow['pharmacy_id']) {
198 $rx->pharmacy
->set_id($prow['pharmacy_id']);
199 $rx->pharmacy
->populate();
201 $this->assign("prescription", $rx);
203 $this->_state
= false;
204 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
205 $this->template_mod
. "_send.html");
208 function multiprintfax_header(& $pdf, $p) {
209 return $this->multiprint_header( $pdf, $p );
212 function multiprint_header(& $pdf, $p) {
213 $this->providerid
= $p->provider
->id
;
215 $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'],'','50','','center','');
216 $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10));
217 $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 ='" .
218 mysql_real_escape_string($p->provider
->id
) . "'");
219 $pdf->ezText($res['addr'],12);
222 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>',12);
223 // A client had a bad experience with a patient misusing a DEA number, so
224 // now the doctors write those in on printed prescriptions and only when
225 // necessary. If you need to change this back, then please make it a
226 // configurable option. Faxed prescriptions were not changed. -- Rod
227 // Now it is configureable. Change value in
228 // <openemr root>/includes/config.php - Tekknogenius
229 if ($this->is_faxing ||
$GLOBALS['oer_config']['prescriptions']['show_DEA'])
230 $pdf->ezText('<b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
, 12);
232 $pdf->ezText('<b>' . xl('DEA') . ':</b> ________________________', 12);
233 $pdf->ezColumnsStop();
234 if ($my_y < $pdf->y
){
238 $pdf->setLineStyle(1);
239 $pdf->ezColumnsStart(array('num'=>2));
240 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
241 $pdf->ezText('<b>' . xl('Patient Name & Address') . '</b>',6);
242 $pdf->ezText($p->patient
->get_name_display(),10);
243 $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 =". mysql_real_escape_string ($p->patient
->id
));
244 $pdf->ezText($res['addr']);
247 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
248 $pdf->ezText('<b>' . xl('Date of Birth') . '</b>',6);
249 $pdf->ezText($p->patient
->date_of_birth
,10);
251 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
252 $pdf->ezText('<b>' . xl('Medical Record #') . '</b>',6);
253 $pdf->ezText(str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
),10);
254 $pdf->ezColumnsStop();
255 if ($my_y < $pdf->y
){
259 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
260 $pdf->ezText('<b>' . xl('Prescriptions') . '</b>',6);
264 function multiprintcss_header($p) {
265 echo("<div class='paddingdiv'>\n");
266 $this->providerid
= $p->provider
->id
;
267 echo ("<table cellspacing='0' cellpadding='0' width='100%'>\n");
269 echo ("<td></td>\n");
271 echo ("<img WIDTH='68pt' src='./interface/pic/" . $GLOBALS['oer_config']['prescriptions']['logo_pic'] . "' />");
276 $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 ='" . mysql_real_escape_string($p->provider
->id
) . "'");
277 $patterns = array ('/\n/','/Tel:/','/Fax:/');
278 $replace = array ('<br>', xl('Tel').':', xl('Fax').':');
279 $res = preg_replace($patterns, $replace, $res);
280 echo ('<span class="large">' . $res['addr'] . '</span>');
283 echo ('<b><span class="large">' . $p->provider
->get_name_display() . '</span></b>'. '<br>');
284 if ($GLOBALS['oer_config']['prescriptions']['show_DEA']) echo ('<span class="large"><b>' . xl('DEA') . ':</b>' . $p->provider
->federal_drug_id
. '</span>');
285 else echo ('<b><span class="large">' . xl('DEA') . ':</span></b> ________________________');
289 echo ("<td rowspan='2' class='bordered'>\n");
290 echo ('<b><span class="small">' . xl('Patient Name & Address') . '</span></b>'. '<br>');
291 echo ($p->patient
->get_name_display() . '<br>');
292 $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 =". mysql_real_escape_string ($p->patient
->id
));
293 $patterns = array ('/\n/');
294 $replace = array ('<br>');
295 $res = preg_replace($patterns, $replace, $res);
298 echo ("<td class='bordered'>\n");
299 echo ('<b><span class="small">' . xl('Date of Birth') . '</span></b>' . '<br>');
300 echo ($p->patient
->date_of_birth
);
304 echo ("<td class='bordered'>\n");
305 echo ('<b><span class="small">' . xl('Medical Record #') . '</span></b>' . '<br>');
306 echo (str_pad($p->patient
->get_pubpid(), 10, "0", STR_PAD_LEFT
));
310 echo ("<td colspan='2' class='bordered'>\n");
311 echo ('<b><span class="small">' . xl('Prescriptions') . '</span></b>');
317 function multiprintcss_preheader() {
318 // this sets styling and other header information of the multiprint css sheet
323 echo (" padding: 0;\n");
324 echo (" margin: 0;\n");
327 echo (" font-family: sans-serif;\n");
328 echo (" font-weight: normal;\n");
329 echo (" font-size: 10pt;\n");
330 echo (" background: white;\n");
331 echo (" color: black;\n");
333 echo ("span.large {\n");
334 echo (" font-size: 12pt;\n");
336 echo ("span.small {\n");
337 echo (" font-size: 6pt;\n");
340 echo (" vertical-align: top;\n");
341 echo (" width: 50%;\n");
342 echo (" font-size: 10pt;\n");
343 echo (" padding-bottom: 8pt;\n");
345 echo ("td.bordered {\n");
346 echo (" border-top:1pt solid black;\n");
348 echo ("div.paddingdiv {\n");
349 echo (" width: 524pt;\n");
350 echo (" height: 668pt;\n");
351 echo (" page-break-after: always;\n");
353 echo ("div.scriptdiv {\n");
354 echo (" padding-top: 12pt;\n");
355 echo (" padding-bottom: 22pt;\n");
356 echo (" padding-left: 35pt;\n");
357 echo (" border-bottom:1pt solid black;\n");
359 echo ("div.signdiv {\n");
360 echo (" margin-top: 40pt;\n");
361 echo (" font-size: 12pt;\n");
365 echo ("<title>" . xl('Prescription') . "</title>\n");
370 function multiprintfax_footer( & $pdf ) {
371 return $this->multiprint_footer( $pdf );
374 function multiprint_footer(& $pdf) {
375 if($this->pconfig
['use_signature'] && ( $this->is_faxing ||
$this->is_print_to_fax
) ) {
376 $sigfile = str_replace('{userid}', $_SESSION{"authUser"}, $this->pconfig
['signature']);
377 if (file_exists($sigfile)) {
378 $pdf->ezText( xl('Signature') . ": ",12);
379 // $pdf->ezImage($sigfile, "", "", "none", "left");
380 $pdf->ezImage($sigfile, "", "", "none", "center");
381 $pdf->ezText( xl('Date') . ": " . date('Y-m-d'), 12);
382 if ( $this->is_print_to_fax
) {
383 $pdf->ezText(xl('Please do not accept this prescription unless it was received via facsimile.'));
386 $addenumFile = $this->pconfig
['addendum_file'];
387 if ( file_exists( $addenumFile ) ) {
389 $f = fopen($addenumFile, "r");
390 while ( $line = fgets($f, 1000) ) {
391 $pdf->ezText(rtrim($line));
398 $pdf->ezText("\n\n\n\n" . xl('Signature') . ":________________________________\n" . xl('Date') . ": " . date('Y-m-d'),12);
401 function multiprintcss_footer() {
402 echo ("<div class='signdiv'>\n");
403 echo (xl('Signature') . ":________________________________<br>");
404 echo (xl('Date') . ": " . date('Y-m-d'));
409 function multiprintcss_postfooter() {
410 echo("<script language='JavaScript'>\n");
411 echo("window.print();\n");
417 function get_prescription_body_text($p) {
418 $body = '<b>' . xl('Rx') . ': ' . $p->get_drug() . ' ' . $p->get_size() . ' ' . $p->get_unit_display();
419 if ($p->get_form()) $body .= ' [' . $p->form_array
[$p->get_form()] . "]";
420 $body .= "</b> <i>" .
421 $p->substitute_array
[$p->get_substitute()] . "</i>\n" .
422 '<b>' . xl('Disp #') . ':</b> <u>' . $p->get_quantity() . "</u>\n" .
423 '<b>' . xl('Sig') . ':</b> ' . $p->get_dosage() . ' ' . $p->form_array
[$p->get_form()] . ' ' .
424 $p->route_array
[$p->get_route()] . ' ' . $p->interval_array
[$p->get_interval()] . "\n";
425 if ($p->get_refills() > 0) {
426 $body .= "\n<b>" . xl('Refills') . ":</b> <u>" . $p->get_refills();
427 if ($p->get_per_refill()) {
428 $body .= " " . xl('of quantity') . " " . $p->get_per_refill();
433 $body .= "\n<b>" . xl('Refills') . ":</b> <u>0 (" . xl('Zero') . ")</u>\n";
435 $note = $p->get_note();
437 $body .= "\n$note\n";
442 function multiprintfax_body(& $pdf, $p){
443 return $this->multiprint_body( $pdf, $p );
446 function multiprint_body(& $pdf, $p){
447 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
448 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
449 $d = $this->get_prescription_body_text($p);
450 if ( $pdf->ezText($d,10,array(),1) ) {
451 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
452 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
453 $this->multiprint_footer($pdf);
455 $this->multiprint_header($pdf, $p);
456 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
457 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
461 if($this->pconfig
['shading']) {
462 $pdf->setColor(.9,.9,.9);
463 $pdf->filledRectangle($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin']-$pdf->ez
['leftMargin'],$my_y - $pdf->y
);
464 $pdf->setColor(0,0,0);
468 $pdf->ez
['leftMargin'] = $GLOBALS['oer_config']['prescriptions']['left'];
469 $pdf->ez
['rightMargin'] = $GLOBALS['oer_config']['prescriptions']['right'];
471 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
475 function multiprintcss_body($p){
476 $d = $this->get_prescription_body_text($p);
477 $patterns = array ('/\n/','/ /');
478 $replace = array ('<br>',' ');
479 $d = preg_replace($patterns, $replace, $d);
480 echo ("<div class='scriptdiv'>\n" . $d . "</div>\n");
483 function multiprintfax_action($id = "") {
484 $this->is_print_to_fax
=true;
485 return $this->multiprint_action( $id );
488 function multiprint_action($id = "") {
489 $_POST['process'] = "true";
491 $this->function_argument_error();
493 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
494 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
495 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
496 ,$GLOBALS['oer_config']['prescriptions']['bottom']
497 ,$GLOBALS['oer_config']['prescriptions']['left']
498 ,$GLOBALS['oer_config']['prescriptions']['right']
500 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
502 // $print_header = true;
505 //print prescriptions body
506 $this->_state
= false; // Added by Rod - see Controller.class.php
507 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
508 foreach ($ids as $id) {
509 $p = new Prescription($id);
510 // if ($print_header == true) {
511 if ($on_this_page == 0) {
512 $this->multiprint_header($pdf, $p);
514 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
515 $this->multiprint_footer($pdf);
517 $this->multiprint_header($pdf, $p);
518 // $print_header = false;
521 $this->multiprint_body($pdf, $p);
524 $this->multiprint_footer($pdf);
530 function multiprintcss_action($id = "") {
531 $_POST['process'] = "true";
533 $this->function_argument_error();
536 $this->multiprintcss_preheader();
538 $this->_state
= false; // Added by Rod - see Controller.class.php
539 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
542 foreach ($ids as $id) {
543 $p = new Prescription($id);
544 if ($on_this_page == 0) {
545 $this->multiprintcss_header($p);
547 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
548 $this->multiprintcss_footer();
549 $this->multiprintcss_header($p);
552 $this->multiprintcss_body($p);
554 $this->multiprintcss_footer();
555 $this->multiprintcss_postfooter();
559 function send_action_process($id) {
560 $dummy = ""; // Added by Rod to avoid run-time warnings
561 if ($_POST['process'] != "true")
564 $this->function_argument_error();
566 $p = new Prescription($id);
567 switch ($_POST['submit']) {
569 case (xl("Print")." (".xl("PDF").")"):
570 // The following statement added by Rod.
571 // Looking at Controller.class.php, it appears that _state is set to false
572 // to indicate that no further HTML is to be generated.
573 $this->_state
= false; // Added by Rod - see Controller.class.php
574 return $this->_print_prescription($p, $dummy);
576 case (xl("Print")." (".xl("HTML").")"):
577 $this->_state
= false;
578 return $this->_print_prescription_css($p, $dummy);
580 case xl("Print To Fax"):
581 $this->_state
= false;
582 $this->is_print_to_fax
= true;
583 return $this->_print_prescription($p, $dummy);
586 return $this->_email_prescription($p,$_POST['email_to']);
589 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
590 //$this->assign("process_result","No fax server is currently setup.");
591 return $this->_fax_prescription($p,$_POST['fax_to']);
593 case xl("Auto Send"):
594 $pharmacy_id = $_POST['pharmacy_id'];
595 //echo "auto sending to : " . $_POST['pharmacy_id'];
596 $phar = new Pharmacy($_POST['pharmacy_id']);
598 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
599 return $this->_print_prescription($p, $dummy);
601 elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
602 $email = $phar->get_email();
603 if (!empty($email)) {
604 return $this->_email_prescription($p,$phar->get_email());
608 elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
609 $faxNum= $phar->get_fax();
610 if(!empty($faxNum)) {
611 Return $this->_fax_prescription ($p,$faxNum);
613 // return $this->assign("process_result","No fax server is currently setup.");
614 // else default is printing,
617 //the pharmacy has no default or default is print
618 return $this->_print_prescription($p, $dummy);
627 function _print_prescription($p, & $toFile) {
628 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
629 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
630 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
631 ,$GLOBALS['oer_config']['prescriptions']['bottom']
632 ,$GLOBALS['oer_config']['prescriptions']['left']
633 ,$GLOBALS['oer_config']['prescriptions']['right']
636 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
638 // Signature images are to be used only when faxing.
639 if(!empty($toFile)) $this->is_faxing
= true;
641 $this->multiprint_header($pdf, $p);
642 $this->multiprint_body($pdf, $p);
643 $this->multiprint_footer($pdf);
645 if(!empty($toFile)) {
646 $toFile = $pdf->ezOutput();
650 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
655 function _print_prescription_css($p, & $toFile) {
657 $this->multiprintcss_preheader();
658 $this->multiprintcss_header($p);
659 $this->multiprintcss_body($p);
660 $this->multiprintcss_footer();
661 $this->multiprintcss_postfooter();
665 function _print_prescription_old($p, & $toFile) {
666 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
667 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
668 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
669 ,$GLOBALS['oer_config']['prescriptions']['bottom']
670 ,$GLOBALS['oer_config']['prescriptions']['left']
671 ,$GLOBALS['oer_config']['prescriptions']['right']
673 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
674 if(!empty($this->pconfig
['logo'])) {
675 $pdf->ezImage($this->pconfig
['logo'],"","","none","left");
677 $pdf->ezText($p->get_prescription_display(),10);
678 if($this->pconfig
['use_signature']) {
679 $pdf->ezImage($this->pconfig
['signature'],"","","none","left");
682 $pdf->ezText("\n\n\n\nSignature:________________________________",10);
686 $toFile = $pdf->ezOutput();
691 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
696 function _email_prescription($p,$email) {
698 $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
701 require($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php");
702 $mail = new PHPMailer();
703 $mail->SetLanguage("en",$GLOBALS['fileroot'] . "/library/" );
704 //this is a temporary config item until the rest of the per practice billing settings make their way in
705 $mail->From
= $GLOBALS['practice_return_email_path'];
706 $mail->FromName
= $p->provider
->get_name_display();
708 $mail->Host
= "localhost";
709 $mail->Mailer
= "mail";
710 $text_body = $p->get_prescription_display();
711 $mail->Body
= $text_body;
712 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
713 $mail->AddAddress($email);
715 $this->assign("process_result","Email was successfully sent to: " . $email);
719 $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
724 function do_lookup() {
725 if ($_POST['process'] != "true") {
727 $this->assign("drug", $_GET['drug']);
731 // process the lookup
732 $this->assign("drug", $_POST['drug']);
734 if (!empty($_POST['drug'])) {
735 $list = @RxList
::get_list($_POST['drug']);
738 if (is_array($list)) {
739 $list = array_flip($list);
740 $this->assign("drug_options",$list);
741 $this->assign("drug_values",array_keys($list));
744 $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
747 //$this->assign("PROCESS","");
749 $_POST['process'] = "";
752 function _fax_prescription($p,$faxNum)
755 //strip - ,(, ), and ws
756 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum);
757 //validate the number
759 if(!empty($faxNum) && is_numeric($faxNum))
761 //get the sendfax command and execute it
762 $cmd = $this->pconfig
['sendfax'];
763 // prepend any prefix to the fax number
764 $pref=$this->pconfig
['prefix'];
765 $faxNum=$pref.$faxNum;
768 $err .= " Send fax not set in includes/config.php";
773 //generate file to fax
775 $this->_print_prescription($p, $faxFile);
778 $err .= " _print_prescription returned empty file";
781 $fileName = dirname(__FILE__
)."/../documents/".$p->get_id()
782 .$p->get_patient_id()."_fax_.pdf";
783 //print "filename is $fileName";
784 touch($fileName); // php bug
785 $handle = fopen($fileName,"w");
788 $err .= " Failed to open file $fileName to write fax to";
791 if(fwrite($handle, $faxFile) === false)
793 $err .= " Failed to write data to $fileName";
797 $args = " -n -d $faxNum $fileName";
798 //print "command is $cmd $args<br>";
805 $err = "bad fax number passed to function";
809 $this->assign("process_result",$err);