jhunyan wrote on Friday, November 13, 2015:
Hi,
I need some help and advise about modifying prescription. I am able to modify the codes in C.Prescription.class.php so it will be able to suit the way how Australia requires for the prescription to be printed out. However, I have trouble understanding the php code for provider federal drug ID and state license number to appear on the bottom of the page rather than on top. Please looks at line 494 and 507
The codes are as follows:
<?php // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. require_once($GLOBALS['fileroot'] . "/library/classes/Controller.class.php"); require_once($GLOBALS['fileroot'] . "/library/classes/Prescription.class.php"); require_once($GLOBALS['fileroot'] . "/library/classes/Provider.class.php"); require_once($GLOBALS['fileroot'] . "/library/classes/RXList.class.php"); require_once($GLOBALS['fileroot'] . "/library/registry.inc"); require_once($GLOBALS['fileroot'] . "/library/amc.php"); class C_Prescription extends Controller { var $template_mod; var $pconfig; var $providerid = 0; var $is_faxing = false; var $is_print_to_fax = false; function C_Prescription($template_mod = "general") { parent::Controller(); $this->template_mod = $template_mod; $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']); $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescription" . "&"); $this->assign("STYLE", $GLOBALS['style']); $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']); $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']); $this->pconfig = $GLOBALS['oer_config']['prescriptions']; $this->assign("CSS_HEADER", $GLOBALS['css_header'] ); $this->assign("WEB_ROOT", $GLOBALS['webroot'] ); if ($GLOBALS['inhouse_pharmacy']) { // Make an array of drug IDs and selectors for the template. $drug_array_values = array(0); $drug_array_output = array("-- " . xl('or select from inventory') ." --"); $drug_attributes = ''; // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector"); $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " . "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " . "t.period, t.quantity, t.refills " . "FROM drug_templates AS t, drugs AS d WHERE " . "d.drug_id = t.drug_id ORDER BY t.selector"); while ($row = sqlFetchArray($res)) { $tmp_output = $row['selector']; if ($row['ndc_number']) { $tmp_output .= ' [' . $row['ndc_number'] . ']'; } $drug_array_values[] = $row['drug_id']; $drug_array_output[] = $tmp_output; if ($drug_attributes) $drug_attributes .= ','; $drug_attributes .= "['" . $row['name'] . "'," . // 0 $row['form'] . ",'" . // 1 $row['dosage'] . "'," . // 2 $row['size'] . "," . // 3 $row['unit'] . "," . // 4 $row['route'] . "," . // 5 $row['period'] . "," . // 6 $row['substitute'] . "," . // 7 $row['quantity'] . "," . // 8 $row['refills'] . "," . // 9 $row['quantity'] . "]"; // 10 quantity per_refill } $this->assign("DRUG_ARRAY_VALUES", $drug_array_values); $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output); $this->assign("DRUG_ATTRIBUTES", $drug_attributes); } } function default_action() { $this->assign("prescription",$this->prescriptions[0]); $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_edit.html"); } function edit_action($id = "",$patient_id="",$p_obj = null) { if ($p_obj != null && get_class($p_obj) == "prescription") { $this->prescriptions[0] = $p_obj; } elseif (get_class($this->prescriptions[0]) != "prescription" ) { $this->prescriptions[0] = new Prescription($id); } if (!empty($patient_id)) { $this->prescriptions[0]->set_patient_id($patient_id); } // If quantity to dispense is not already set from a POST, set its // default value. if (! $this->get_template_vars('DISP_QUANTITY')) { $this->assign('DISP_QUANTITY', $this->prescriptions[0]->quantity); } $this->default_action(); } function list_action($id,$sort = "") { if (empty($id)) { $this->function_argument_error(); exit; } if (!empty($sort)) { $this->assign("prescriptions", Prescription::prescriptions_factory($id,$sort)); } else { $this->assign("prescriptions", Prescription::prescriptions_factory($id)); } // flag to indicate the CAMOS form is regsitered and active $this->assign("CAMOS_FORM", isRegistered("CAMOS")); $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_list.html"); } function block_action($id,$sort = "") { if (empty($id)) { $this->function_argument_error(); exit; } if (!empty($sort)) { $this->assign("prescriptions", Prescription::prescriptions_factory($id,$sort)); } else { $this->assign("prescriptions", Prescription::prescriptions_factory($id)); } //print_r(Prescription::prescriptions_factory($id)); $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_block.html"); } function fragment_action($id,$sort = "") { if (empty($id)) { $this->function_argument_error(); exit; } if (!empty($sort)) { $this->assign("prescriptions", Prescription::prescriptions_factory($id,$sort)); } else { $this->assign("prescriptions", Prescription::prescriptions_factory($id)); } //print_r(Prescription::prescriptions_factory($id)); $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_fragment.html"); } function lookup_action() { $this->do_lookup(); $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_lookup.html"); } function edit_action_process() { if ($_POST['process'] != "true") return; //print_r($_POST); // Stupid Smarty code treats empty values as not specified values. // Since active is a checkbox, represent the unchecked state as -1. if (empty($_POST['active'])) $_POST['active'] = '-1'; $this->prescriptions[0] = new Prescription($_POST['id']); parent::populate_object($this->prescriptions[0]); //echo $this->prescriptions[0]->toString(true); $this->prescriptions[0]->persist(); $_POST['process'] = ""; // If the "Prescribe and Dispense" button was clicked, then // redisplay as in edit_action() but also replicate the fee and // include a piece of javascript to call dispense(). // if ($_POST['disp_button']) { $this->assign("DISP_QUANTITY", $_POST['disp_quantity']); $this->assign("DISP_FEE", $_POST['disp_fee']); $this->assign("ENDING_JAVASCRIPT", "dispense();"); $this->_state = false; return $this->edit_action($this->prescriptions[0]->id); } // Set the AMC reporting flag (to record percentage of prescriptions that // are set as e-prescriptions) if (!(empty($_POST['escribe_flag']))) { // add the e-prescribe flag processAmcCall('e_prescribe_amc', true, 'add', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id); } else { // remove the e-prescribe flag processAmcCall('e_prescribe_amc', true, 'remove', $this->prescriptions[0]->get_patient_id(), 'prescriptions', $this->prescriptions[0]->id); } // TajEmo Work by CB 2012/05/29 02:58:29 PM to stop from going to send screen. Improves Work Flow // if ($this->prescriptions[0]->get_active() > 0) { // return $this->send_action($this->prescriptions[0]->id); // } $this->list_action($this->prescriptions[0]->get_patient_id()); exit; } function send_action($id) { $_POST['process'] = "true"; if(empty($id)) { $this->function_argument_error(); } $rx = new Prescription($id); // Populate pharmacy info if the patient has a default pharmacy. // Probably the Prescription object should handle this instead, but // doing it there will require more careful research and testing. $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " . "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id"); if ($prow['pharmacy_id']) { $rx->pharmacy->set_id($prow['pharmacy_id']); $rx->pharmacy->populate(); } $this->assign("prescription", $rx); $this->_state = false; return $this->fetch($GLOBALS['template_dir'] . "prescription/" . $this->template_mod . "_send.html"); } function multiprintfax_header(& $pdf, $p) { return $this->multiprint_header( $pdf, $p ); } function multiprint_header(& $pdf, $p) { $this->providerid = $p->provider->id; //print header $pdf->ezImage($GLOBALS['oer_config']['prescriptions']['logo'],'','50','','center',''); $pdf->ezColumnsStart(array('num'=>2, 'gap'=>10)); $res = sqlQuery("SELECT concat('',f.name,'\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) . "'"); $pdf->ezText($res['addr'],12); $my_y = $pdf->y; $pdf->ezNewPage(); $pdf->ezText('' . $p->provider->get_name_display() . '',12); // A client had a bad experience with a patient misusing a DEA number, so // now the doctors write those in on printed prescriptions and only when // necessary. If you need to change this back, then please make it a // configurable option. Faxed prescriptions were not changed. -- Rod // Now it is configureable. Change value in // Administration->Globals->Rx if ($GLOBALS['rx_enable_DEA']) { if ($this->is_faxing || $GLOBALS['rx_show_DEA']) { $pdf->ezText('' . xl('DEA') . ':' . $p->provider->federal_drug_id, 12); } else { $pdf->ezText('' . xl('DEA') . ': ________________________', 12); } } if ($GLOBALS['rx_enable_NPI']) { if ($this->is_faxing || $GLOBALS['rx_show_NPI']) { $pdf->ezText('' . xl('NPI') . ':' . $p->provider->npi, 12); } else { $pdf->ezText('' . xl('NPI') . ': _________________________', 12); } } if ($GLOBALS['rx_enable_SLN']) { if ($this->is_faxing || $GLOBALS['rx_show_SLN']) { $pdf->ezText('' . xl('State Lic. #') . ':' . $p->provider->state_license_number, 12); } else { $pdf->ezText('' . xl('State Lic. #') . ': ___________________', 12); } } $pdf->ezColumnsStop(); if ($my_y < $pdf->y){ $pdf->ezSetY($my_y); } $pdf->ezText('',10); $pdf->setLineStyle(1); $pdf->ezColumnsStart(array('num'=>2)); $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y); $pdf->ezText('' . xl('Patient Name & Address') . '',6); $pdf->ezText($p->patient->get_name_display(),10); $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)); $pdf->ezText($res['addr']); $my_y = $pdf->y; $pdf->ezNewPage(); $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y); $pdf->ezText('' . xl('Date of Birth') . '',6); $pdf->ezText($p->patient->date_of_birth,10); $pdf->ezText(''); $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y); $pdf->ezText('' . xl('Medical Record #') . '',6); $pdf->ezText(str_pad($p->patient->get_pubpid(), 10, "0", STR_PAD_LEFT),10); $pdf->ezColumnsStop(); if ($my_y < $pdf->y){ $pdf->ezSetY($my_y); } $pdf->ezText(''); $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y); $pdf->ezText('' . xl('Prescriptions') . '',6); $pdf->ezText('',10); } function multiprintcss_header($p) { echo("\n");
$res = sqlQuery("SELECT concat('',f.name,'\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) . "'");
$patterns = array ('/\n/','/Tel:/','/Fax:/');
$replace = array (' ', xl('Tel').':', xl('Fax').':'); $res = preg_replace($patterns, $replace, $res); echo ('' . $res['addr'] . ''); echo (" | \n");
echo ("\n");
$res = sqlQuery("SELECT concat('',f.name,'\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) . "'");
$patterns = array ('/\n/','/Tel:/','/Fax:/');
$replace = array (' ', xl('Tel').':', xl('Fax').':'); $res = preg_replace($patterns, $replace, $res); echo ('' . $res['addr'] . ''); echo (" | \n");
echo ("\n");
echo ("
\n");
echo ('' . xl('Patient Name & Address') . ''. ' '); echo ($p->patient->get_name_display() . ' '); $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)); $patterns = array ('/\n/'); $replace = array (' '); $res = preg_replace($patterns, $replace, $res); echo ($res['addr']); echo ('' . xl('Date of Birth') . '' . ' '); echo ($p->patient->date_of_birth . ' ' ); echo (" | \n");
echo ("\n");
echo ('' . xl('Patient Name & Address') . ''. ' '); echo ($p->patient->get_name_display() . ' '); $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)); $patterns = array ('/\n/'); $replace = array (' '); $res = preg_replace($patterns, $replace, $res); echo ($res['addr']); echo ('' . xl('Date of Birth') . '' . ' '); echo ($p->patient->date_of_birth ); echo (" | \n");
echo ("
\n"); echo ('' . xl('Prescriptions') . ''); echo (" | \n"); echo ("\n"); echo ('' . xl('Prescriptions') . ''); echo (" | \n"); echo ("
"); echo (''. xl('Date') . ": " . date('Y-m-d'). '
'); //Need codes for provider federal ID and state license number echo ("
"); echo (''. xl('Date') . ": " . date('Y-m-d'). '
'); //Need codes for provider federal ID and state license number echo ("
',' '); $d = preg_replace($patterns, $replace, $d); echo ("\n"); echo ("
"); } //print_r($_POST); //$this->assign("PROCESS",""); $_POST['process'] = ""; } function _fax_prescription($p,$faxNum) { $err = "Sent fax"; //strip - ,(, ), and ws $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum); //validate the number if(!empty($faxNum) && is_numeric($faxNum)) { //get the sendfax command and execute it $cmd = $this->pconfig['sendfax']; // prepend any prefix to the fax number $pref=$this->pconfig['prefix']; $faxNum=$pref.$faxNum; if(empty($cmd)) { $err .= " Send fax not set in includes/config.php"; break; } else { //generate file to fax $faxFile = "Failed"; $this->_print_prescription($p, $faxFile); if(empty($faxFile)) { $err .= " _print_prescription returned empty file"; break; } $fileName = $GLOBALS['OE_SITE_DIR'] . "/documents/" . $p->get_id() . $p->get_patient_id() . "_fax_.pdf"; //print "filename is $fileName"; touch($fileName); // php bug $handle = fopen($fileName,"w"); if(!$handle) { $err .= " Failed to open file $fileName to write fax to"; break; } if(fwrite($handle, $faxFile) === false) { $err .= " Failed to write data to $fileName"; break; } fclose($handle); $args = " -n -d $faxNum $fileName"; //print "command is $cmd $args
"; exec($cmd . $args); } } else { $err = "bad fax number passed to function"; } if($err) { $this->assign("process_result",$err); } } } ?>
The codes I intend to insert as below.
if ($GLOBALS[‘rx_enable_DEA’]) {
if ($this->is_faxing || $GLOBALS[‘rx_show_DEA’]) {
$pdf->ezText(’’ . xl(‘DEA’) . ‘:’ . $p->provider->federal_drug_id, 12);
}
else {
$pdf->ezText(’’ . xl(‘DEA’) . ‘: ________________________’, 12);
}
}
if ($GLOBALS['rx_enable_NPI']) {
if ($this->is_faxing || $GLOBALS['rx_show_NPI']) {
$pdf->ezText('<b>' . xl('NPI') . ':</b>' . $p->provider->npi, 12);
}
else {
$pdf->ezText('<b>' . xl('NPI') . ':</b> _________________________', 12);
}
}
if ($GLOBALS['rx_enable_SLN']) {
if ($this->is_faxing || $GLOBALS['rx_show_SLN']) {
$pdf->ezText('<b>' . xl('State Lic. #') . ':</b>' . $p->provider->state_license_number, 12);
}
else {
$pdf->ezText('<b>' . xl('State Lic. #') . ':</b> ___________________', 12);
}
}