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");
8 class C_Prescriptiondutch
extends Controller
{
13 var $use_signature_images = false;
15 function C_Prescriptiondutch($template_mod = "general") {
18 $this->template_mod
= $template_mod;
19 $this->assign("FORM_ACTION", $GLOBALS['webroot']."/controller.php?" . $_SERVER['QUERY_STRING']);
20 $this->assign("TOP_ACTION", $GLOBALS['webroot']."/controller.php?" . "prescriptiondutch" . "&");
21 $this->assign("STYLE", $GLOBALS['style']);
22 $this->assign("WEIGHT_LOSS_CLINIC", $GLOBALS['weight_loss_clinic']);
23 $this->assign("SIMPLIFIED_PRESCRIPTIONS", $GLOBALS['simplified_prescriptions']);
24 $this->pconfig
= $GLOBALS['oer_config']['prescriptions'];
26 if ($GLOBALS['inhouse_pharmacy']) {
27 // Make an array of drug IDs and selectors for the template.
28 $drug_array_values = array(0);
29 $drug_array_output = array("-- or select from inventory --");
30 $drug_attributes = '';
32 // $res = sqlStatement("SELECT * FROM drugs ORDER BY selector");
34 $res = sqlStatement("SELECT d.name, d.ndc_number, d.form, d.size, " .
35 "d.unit, d.route, d.substitute, t.drug_id, t.selector, t.dosage, " .
36 "t.period, t.quantity, t.refills " .
37 "FROM drug_templates AS t, drugs AS d WHERE " .
38 "d.drug_id = t.drug_id ORDER BY t.selector");
40 while ($row = sqlFetchArray($res)) {
41 $tmp_output = $row['selector'];
42 if ($row['ndc_number']) {
43 $tmp_output .= ' [' . $row['ndc_number'] . ']';
45 $drug_array_values[] = $row['drug_id'];
46 $drug_array_output[] = $tmp_output;
47 if ($drug_attributes) $drug_attributes .= ',';
48 $drug_attributes .= "['" .
49 $row['name'] . "'," . // 0
50 $row['form'] . ",'" . // 1
51 $row['dosage'] . "'," . // 2
52 $row['size'] . "," . // 3
53 $row['unit'] . "," . // 4
54 $row['route'] . "," . // 5
55 $row['period'] . "," . // 6
56 $row['substitute'] . "," . // 7
57 $row['quantity'] . "," . // 8
58 $row['refills'] . "," . // 9
59 $row['quantity'] . "]"; // 10 quantity per_refill
61 $this->assign("DRUG_ARRAY_VALUES", $drug_array_values);
62 $this->assign("DRUG_ARRAY_OUTPUT", $drug_array_output);
63 $this->assign("DRUG_ATTRIBUTES", $drug_attributes);
67 function default_action() {
68 $this->assign("prescription",$this->prescriptions
[0]);
69 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_edit.html");
72 function edit_action($id = "",$patient_id="",$p_obj = null) {
74 if ($p_obj != null && get_class($p_obj) == "prescriptiondutch") {
75 $this->prescriptions
[0] = $p_obj;
77 elseif (get_class($this->prescriptions
[0]) != "prescriptiondutch" ) {
78 $this->prescriptions
[0] = new Prescription($id);
81 if (!empty($patient_id)) {
82 $this->prescriptions
[0]->set_patient_id($patient_id);
85 // If quantity to dispense is not already set from a POST, set its
87 if (! $this->get_template_vars('DISP_QUANTITY')) {
88 $this->assign('DISP_QUANTITY', $this->prescriptions
[0]->quantity
);
91 $this->default_action();
94 function list_action($id,$sort = "") {
96 $this->function_argument_error();
100 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
103 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
105 //print_r(Prescription::prescriptions_factory($id));
106 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_list_dutch.html");
109 function block_action($id,$sort = "") {
111 $this->function_argument_error();
115 $this->assign("prescriptions", Prescription
::prescriptions_factory($id,$sort));
118 $this->assign("prescriptions", Prescription
::prescriptions_factory($id));
120 //print_r(Prescription::prescriptions_factory($id));
121 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_block.html");
124 function lookup_action() {
126 $this->display($GLOBALS['template_dir'] . "prescription/" . $this->template_mod
. "_lookup.html");
129 function edit_action_process() {
130 if ($_POST['process'] != "true")
134 $this->prescriptions
[0] = new Prescription($_POST['id']);
135 parent
::populate_object($this->prescriptions
[0]);
136 //echo $this->prescriptions[0]->toString(true);
137 $this->prescriptions
[0]->persist();
138 $_POST['process'] = "";
140 // If the "Prescribe and Dispense" button was clicked, then
141 // redisplay as in edit_action() but also replicate the fee and
142 // include a piece of javascript to call dispense().
144 if ($_POST['disp_button']) {
145 $this->assign("DISP_QUANTITY", $_POST['disp_quantity']);
146 $this->assign("DISP_FEE", $_POST['disp_fee']);
147 $this->assign("ENDING_JAVASCRIPT", "dispense();");
148 $this->_state
= false;
149 return $this->edit_action($this->prescriptions
[0]->id
);
152 return $this->send_action($this->prescriptions
[0]->id
);
155 function send_action($id) {
156 $_POST['process'] = "true";
158 $this->function_argument_error();
161 $rx = new Prescription($id);
162 // Populate pharmacy info if the patient has a default pharmacy.
163 // Probably the Prescription object should handle this instead, but
164 // doing it there will require more careful research and testing.
165 $prow = sqlQuery("SELECT pt.pharmacy_id FROM prescriptions AS rx, " .
166 "patient_data AS pt WHERE rx.id = '$id' AND pt.pid = rx.patient_id");
167 if ($prow['pharmacy_id']) {
168 $rx->pharmacy
->set_id($prow['pharmacy_id']);
169 $rx->pharmacy
->populate();
171 $this->assign("prescription", $rx);
173 $this->_state
= false;
174 return $this->fetch($GLOBALS['template_dir'] . "prescription/" .
175 $this->template_mod
. "_send.html");
178 function multiprint_header(& $pdf, $p) {
179 $this->providerid
= $p->provider
->id
;
180 $pdf->ezImage($GLOBALS['fileroot'] . '/interface/pic/logo_bosmanggz.jpg','5','280','','center','');
183 $pdf->ezText('Bosman GGz',9, array('left' => 480, 'justification' => 'right'));
184 $pdf->ezText('Kanaalweg 17h',9, array('left' => 480, 'justification' => 'right'));
185 $pdf->ezText('3526 KL Utrecht',9, array('left' => 480, 'justification' => 'right'));
186 $pdf->ezText('Tel (030) 751 9820',9, array('left' => 460, 'justification' => 'right'));
187 $pdf->ezText('Tel (030) 751 9831',9, array('left' => 460, 'justification' => 'right'));
188 $pdf->ezText('Email: info@bosmanggz.nl',9, array('left' => 440, 'justification' => 'right'));
189 $pdf->ezText('Web: www.bosmanggz.nl',9, array('left' => 450, 'justification' => 'right'));
191 $pdf->ezText('Recept',12, array('left' => 30));
192 $pdf->ezText(str_pad('Datum:', 26) . date('d-m-Y'), 12, array('left' => 30, 'spacing' => 2));
193 $pdf->ezText(str_pad('Naam:', 25) . $p->patient
->get_name_display(), 12, array('left' => 30, 'spacing' => 2));
195 // prepare data for dutch usage
196 $da = explode('/', $p->patient
->date_of_birth
);
197 $dap = $da[1] . '-' . $da[0] . '-' .$da[2];
198 $pdf->ezText(str_pad('Geboortedatum:', 20) . $dap, 12, array('left' => 30, 'spacing' => 2));
201 $pdf->setLineStyle(0.2);
202 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
206 function multiprint_footer(& $pdf, $p) {
207 if($this->pconfig
['use_signature'] && $this->use_signature_images
) {
208 /*$sigfile = str_replace('{userid}', $this->providerid, $this->pconfig['signature']);
209 if (file_exists($sigfile)) {
210 $pdf->ezText("<i>Handtekening</i>: ",12);
211 // $pdf->ezImage($sigfile, "", "", "none", "left");
212 $pdf->ezImage($sigfile, "", "", "none", "center");
213 $pdf->ezText("Date: " . date('Y-m-d'), 12);
217 $pdf->setLineStyle(0.2);
218 $pdf->line($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin'],$pdf->y
);
220 $pdf->ezText('<b>' . $p->provider
->get_name_display() . '</b>, '. $p->provider
->get_specialty(), 10, array('left' => 30));
221 $pdf->addJpegFromFile('prescriptionbg.jpg', 10, 10);
224 function get_prescription_body_text($p) {
225 $body = "\n\n" . 'R/ ' . $p->get_drug() . ' ' . $p->get_size() . ' ' . $p->get_unit_display();
226 //if ($p->get_form()) $body .= ' [' . $p->form_array[$p->get_form()] . "]";
228 'No.' . $p->get_quantity() . "\n" .
229 'S. ' . $p->route_array
[$p->get_route()] . ' ' . $p->interval_array
[$p->get_interval()] .
230 ' ' . $p->get_dosage(). "\n";
231 if ($p->get_refills() > 0) {
232 $body .= "\n" . $p->get_refills() . ' x herhalen';
233 /*if ($p->get_per_refill()) {
234 $body .= " of quantity " . $p->get_per_refill();
239 $body .= "\n<b>Niet herhalen</b>\n";
241 $note = $p->get_note();
243 $body .= "\n$note\n";
248 function multiprint_body(& $pdf, $p){
249 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
250 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
251 $d = $this->get_prescription_body_text($p);
252 if ( $pdf->ezText($d,10,array(),1) ) {
253 $pdf->ez
['leftMargin'] -= $pdf->ez
['leftMargin'];
254 $pdf->ez
['rightMargin'] -= $pdf->ez
['rightMargin'];
255 $this->multiprint_footer($pdf, $p);
257 $this->multiprint_header($pdf, $p);
258 $pdf->ez
['leftMargin'] +
= $pdf->ez
['leftMargin'];
259 $pdf->ez
['rightMargin'] +
= $pdf->ez
['rightMargin'];
263 if($this->pconfig
['shading']) {
264 $pdf->setColor(.9,.9,.9);
265 $pdf->filledRectangle($pdf->ez
['leftMargin'],$pdf->y
,$pdf->ez
['pageWidth']-$pdf->ez
['rightMargin']-$pdf->ez
['leftMargin'],$my_y - $pdf->y
);
266 $pdf->setColor(0,0,0);
270 $pdf->ez
['leftMargin'] = $GLOBALS['oer_config']['prescriptions']['left'];
271 $pdf->ez
['rightMargin'] = $GLOBALS['oer_config']['prescriptions']['right'];
275 function multiprint_action($id = "") {
276 $_POST['process'] = "true";
278 $this->function_argument_error();
280 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
281 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
282 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
283 ,$GLOBALS['oer_config']['prescriptions']['bottom']
284 ,$GLOBALS['oer_config']['prescriptions']['left']
285 ,$GLOBALS['oer_config']['prescriptions']['right']
287 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
289 // $print_header = true;
292 //print prescriptions body
293 $this->_state
= false; // Added by Rod - see Controller.class.php
294 $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY
);
295 foreach ($ids as $id) {
296 $p = new Prescription($id);
297 // if ($print_header == true) {
298 if ($on_this_page == 0) {
299 $this->multiprint_header($pdf, $p);
301 if (++
$on_this_page > 3 ||
$p->provider
->id
!= $this->providerid
) {
302 $this->multiprint_footer($pdf, $p);
304 $this->multiprint_header($pdf, $p);
305 // $print_header = false;
308 $this->multiprint_body($pdf, $p);
311 $this->multiprint_footer($pdf, $p);
317 function send_action_process($id) {
318 $dummy = ""; // Added by Rod to avoid run-time warnings
319 if ($_POST['process'] != "true")
322 $this->function_argument_error();
324 $p = new Prescription($id);
325 switch ($_POST['submit']) {
326 // here the names are the same on the form!!
328 // The following statement added by Rod.
329 // Looking at Controller.class.php, it appears that _state is set to false
330 // to indicate that no further HTML is to be generated.
331 $this->_state
= false; // Added by Rod - see Controller.class.php
332 return $this->_print_prescription($p, $dummy);
335 return $this->_email_prescription($p,$_POST['email_to']);
338 //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
339 //$this->assign("process_result","No fax server is currently setup.");
340 return $this->_fax_prescription($p,$_POST['fax_to']);
343 $pharmacy_id = $_POST['pharmacy_id'];
344 //echo "auto sending to : " . $_POST['pharmacy_id'];
345 $phar = new Pharmacy($_POST['pharmacy_id']);
347 if ($phar->get_transmit_method() == TRANSMIT_PRINT
) {
348 return $this->_print_prescription($p, $dummy);
350 elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL
) {
351 $email = $phar->get_email();
352 if (!empty($email)) {
353 return $this->_email_prescription($p,$phar->get_email());
357 elseif ($phar->get_transmit_method() == TRANSMIT_FAX
) {
358 $faxNum= $phar->get_fax();
359 if(!empty($faxNum)) {
360 Return $this->_fax_prescription ($p,$faxNum);
362 // return $this->assign("process_result","No fax server is currently setup.");
363 // else default is printing,
366 //the pharmacy has no default or default is print
367 return $this->_print_prescription($p, $dummy);
376 function _print_prescription($p, & $toFile) {
377 require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
378 $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
379 $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
380 ,$GLOBALS['oer_config']['prescriptions']['bottom']
381 ,$GLOBALS['oer_config']['prescriptions']['left']
382 ,$GLOBALS['oer_config']['prescriptions']['right']
385 $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
387 // Signature images are to be used only when faxing.
388 if(!empty($toFile)) $this->use_signature_images
= true;
390 $this->multiprint_header($pdf, $p);
391 $this->multiprint_body($pdf, $p);
392 $this->multiprint_footer($pdf, $p);
394 if(!empty($toFile)) {
395 $toFile = $pdf->ezOutput();
399 // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
404 function _email_prescription($p,$email) {
406 $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
409 require($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php");
410 $mail = new PHPMailer();
411 $mail->SetLanguage("en",$GLOBALS['fileroot'] . "/library/" );
412 //this is a temporary config item until the rest of the per practice billing settings make their way in
413 $mail->From
= $GLOBALS['practice_return_email_path'];
414 $mail->FromName
= $p->provider
->get_name_display();
416 $mail->Host
= "localhost";
417 $mail->Mailer
= "mail";
418 $text_body = $p->get_prescription_display();
419 $mail->Body
= $text_body;
420 $mail->Subject
= "Prescription for: " . $p->patient
->get_name_display();
421 $mail->AddAddress($email);
423 $this->assign("process_result","Email was successfully sent to: " . $email);
427 $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo
);
432 function do_lookup() {
433 if ($_POST['process'] != "true")
436 if (!empty($_POST['drug'])) {
437 $list = @RxList
::get_list($_POST['drug']);
439 if (is_array($list)) {
440 $list = array_flip($list);
441 $this->assign("drug_options",$list);
442 $this->assign("drug_values",array_keys($list));
445 $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
448 //$this->assign("PROCESS","");
450 $_POST['process'] = "";
453 function _fax_prescription($p,$faxNum)
456 //strip - ,(, ), and ws
457 $faxNum = preg_replace("/(-*)(\(*)(\)*)(\s*)/","",$faxNum);
458 //validate the number
460 if(!empty($faxNum) && is_numeric($faxNum))
462 //get the sendfax command and execute it
463 $cmd = $this->pconfig
['sendfax'];
464 // prepend any prefix to the fax number
465 $pref=$this->pconfig
['prefix'];
466 $faxNum=$pref.$faxNum;
469 $err .= " Send fax not set in includes/config.php";
474 //generate file to fax
476 $this->_print_prescription($p, $faxFile);
479 $err .= " _print_prescription returned empty file";
482 $fileName = dirname(__FILE__
)."/../documents/".$p->get_id()
483 .$p->get_patient_id()."_fax_.pdf";
484 //print "filename is $fileName";
485 touch($fileName); // php bug
486 $handle = fopen($fileName,"w");
489 $err .= " Failed to open file $fileName to write fax to";
492 if(fwrite($handle, $faxFile) === false)
494 $err .= " Failed to write data to $fileName";
498 $args = " -n -d $faxNum $fileName";
499 //print "command is $cmd $args<br>";
506 $err = "bad fax number passed to function";
510 $this->assign("process_result",$err);