Menu

Medications/prescription

Help
Pieter W
2009-03-18
2023-11-05
  • Pieter W

    Pieter W - 2009-03-18

    In CAMOS i found a good way of medication prescription. It can also be extended with medication categories and names even with generic replacement (cheaper?) in the resulting recipe.

    In the patient encounter there is an option to write prescription with look-up function.

    Is "anybody" working on using medications and writing prescriptions? Or should I start including my own favorite prescriptions? Eighter for each seperate patient or in CAMOS or both as soon as needed. It took me about two years in another EMR to include most of my recipes, but I did it when encountered.

    So I have some kind of exptensive list of local available medications with generic counterparts and inclusion in CAMOS shoul not be to difficult but I want to include it in the most relevant spot of OpenEMR.

    Pimm

     
    • mjl69

      mjl69 - 2009-03-19

      I have used CAMOS for all prescriptions for about three years now.

      Regarding browsers: I use the latest version of Firefox 2.  There is a problem with version 3 that causes the prescriptions to render improperly.  The body of the prescription comes out jumbled.  The solution is to stick to Firefox 2 for now.  I may add code in the future to generate PDF prescriptions as an alternative with the same four-per-page format.  They are currently generated with HTML and CSS which puts rendering at the mercy of the browser.

       
    • Pieter W

      Pieter W - 2009-03-19

      Mark,  you use CAMOS for prescriptions that is a good start.

      Did you have to make many changes in the CAMOS medicine database as it is offered in the new version OpenEMR3.0.0? Or is there a way to include your/or my private or any other list into the Database and get it up to standard every now and then.

      In the past I used EXCEL to rearrange the database en upload "my" new version.

      Although this seems to be a rather dirty and time consuming job, the question remains: Is there a different way to find medication to update the used database after some time?

      Should I take some time and investigate the BUTTON "LOOKUP MEDICATION" as still offered? It did not work as supposed in the past, but now I see some results as to loking into a table but since my table are also VIRGIN style. I suppose nothing is to be found.

      Tnx again for time and thinking and giving me some guidance......

      Pimmm

       
    • mjl69

      mjl69 - 2009-03-19

      Currently, you have to add entries to CAMOS by hand, one at a time.  The new version comes with some prescriptions already entered, but they may not be the ones you want or you may not like the format.

      I am now working on an import/export function.  Part of the process is deciding on the format of the data.   I have the export function working now and I am putting the data in an XML type format.  I am not planning to use any XML functions at this point.  I am just using tags like <category></category> etc...  It is possible that you could put your existing data in this format and import it.  If you could post a sample of the format your prescription data is currently in, I might be able to help with that.

      I will post the additional code to do import/export when I have it working.  It is just an additional php file to drop into the CAMOS directory.

       
    • Pieter W

      Pieter W - 2009-03-21

      Mark, what to do?

      can I send you my prescription list in CSV file or will the following little sample do for now?

      ==============================================================
      ,"E:M:A-D zalf","R/ A - D zalf da 1 tube..S. 3 dd insmeren","Non-inventory Part",0,0.00,"Non","","","","",
      ,"E:M:Acetyl Cyst. drank 20mg/ml","R/ Acetylcysteine drank 20mg/ml 150 ml..S. 3 dd 2.5 ml","Non-inventory Part",0,0.00,"Non","","","","",
      ,"E:M:Acetylcyst.br.tabl. 200mg","R/ Acetylcysteine bruistabl. 200mg. Dtd no 20..S. 3 dd 1 in glas water","Non-inventory Part",0,0.00,"Non",0,"","",0.00,
      ,"E:M:Aciclovir 5% creme","R/ Aciclovir 5% creme     10 gram..S. 3 dd dun inwrijven / insmeren","Non-inventory Part",0,0.00,"Non",0,"","",0.00,
      ,"E:M:Aciclovir tabl. 200mg.","R/ Aciclovir tabl. 200mg.","Non-inventory Part",0,0.00,"Non",0,"","",0.00,
      ,"E:M:Actos15 tab","R/ Actos tabl. 15  mg dtd no 30..S. 1 dd 1","Non-inventory Part",0,0.00,"Non","","","","",
      ,"E:M:Actos30 tab","R/ Actos tabl. 30 mg dtd no 30..S. 1 dd 1","Non-inventory Part",0,0.00,"Non","","","","",
      ======================================
      In the comma separated field you might be able to decipher the following:
      FIELD 1: subdivision of account receivable in QuickBooks
      FIELD 2: prescription followed after " .. " with Sig (how often taken and sometimes some remarks for usability)

      the 2 points are used in QB to go to the next line in the .

      Field 3: needed by QB to send the information to the right accounts.
      Field 4 might be for some related information
      Field 5 price indication
      Field 6, 7 ,8 ,9  I dont 'remember, but could be reserved for generic name and other relevant entities

      Hope to hear some good news, so I can continue to implement the right stuff for my trial /error implementations and replacements, due to continuous efforts to improve my own working OpenEMR test versions.

      Pimm

       
    • bowyn

      bowyn - 2009-03-22

      The "Look up" button in prescription mode is 'useless.' 
      That button only provides me with the correct spelling of the name medication in search, nothing else!  There is no suggestions on available strengths, how to take it, etc..  CAMOS form is great but the medications prescribed did not appear in the medication list.  It is more helpful if it does.

      Is there anyway that we can make our own medication list? and the "look up" function will link to that list, and upon selecting the appropriate medication, it will appear in the 'add prescription' with proper dose and frequency already filled in, instead of adding everything manually every time!!!  It is not very useful at all!

      Most of the clinicians I spoke to, they only have about 20-30 favorite medications that they used on the regular basis.  If we can add a medication table that allow the clinicians to add or edit at their wimp.  Then it will become much more useful.  In other words, bring CAMOS capability to "add prescription" menu.  That will be a winner for all.
      That's only my opinion!

      Bo,

       
    • Riaz Chaudhry

      Riaz Chaudhry - 2009-03-22

      Hi

      I have the inhouse pharmacy enabled  and use that. It is easily modified to include dosage, frequency, amount and refills.

      Hope that helps

      Regards

      Rayaz

       
    • Pieter W

      Pieter W - 2009-03-22

      Riaz,

      that sound like an easy solution! Why wasn't it discovered before? Or did I miss some mails?

      Please explain:

      How do you solve stocks?

      Prices are not known by physicians here, but could be implemented. Does it HAVE to be implemented?

      But if you give out a prescription from your stoch, did you make a prescription on the run or from the dispensary?

      Please give some more information and steps to be taken before I mess up my latest installations.

      Tnx Pimm for sharing this.

       
    • Riaz Chaudhry

      Riaz Chaudhry - 2009-03-22

      Pieter,

      Enable inhouse pharmacy support in /openemr/interface/globals.php at line 234.

      To be able to populate the pharmacy you must be logged in as administrator or have administrative rights.

      You will see a inventory button or drugs button depending on the concurrent layout or original layout.
      Click that to get to the inventory.
      Click on Add Drug to add drugs.
      A new window will open where you can input the drug name, form of the drug, pill size, units, route.
      In the templates section you can set up the drug name that will appear in the drop down list in the prescription generator, I set the drug name with whatever schedule I would be using e.g: "drugname1" for 1 tab or "drugname2" for 2 tablet prescription. Fill in the schedule "1" tablet or "2" tablet or what you want, then specify the interval, the quantity to be dispensed and refills.
      Save and you will be taken to the next window, which I don't use but you may, where you specify Lot number, Manufacturer, Expiration etc.

      Hope I was clear enough.

      Regards

      Rayaz

       
    • bowyn

      bowyn - 2009-03-23

      Thanks!

      That seems to work but I wish the 'pill size' field be located in the 'name' section where the 'interval', 'quantity', 'refill' fields are located, because that way, I don't have to reentered the drug name with different strength twice or three times.  For example, a drug name 'atenolol' has different strengths from 25 mg, 50 mg, and 100 mg.  I would have entered atenolol three times!  Maybe, it is better for drug inventory but not for clinicians.  I still believe that adaptation of CAMOS to prescription module is more intuitive.  Anyway, it is better than I previously thought.

      Bo,

       
    • Riaz Chaudhry

      Riaz Chaudhry - 2009-03-24

      Bowyn.
      But you have to enter the durg details only once! When you use the inhouse pharmacy all you have to do is to select the drug from the inhouse pharmacy dropdown, and all fields in the prescrition generator are filled! Second click to save and the third to print. I think it simply fills my needs.

      Regards

       
    • bowyn

      bowyn - 2009-03-24

      Thanks Riaz,

      I think I can live with it for now.  Next question is how to print 5 to 7 medications on 1 page? Currently it only prints 3 medications on 1 page only.  Any idea?

      Bo,

       
    • Riaz Chaudhry

      Riaz Chaudhry - 2009-03-27

      Bowyn,

      So sorry for the late reply, haven't been keeping track of this thread.

      You will need to modify C_Prescription.class.php located in /openemr/controllers. On line 333:
            if (++$on_this_page > 3 || $p->provider->id != $this->providerid) {
      change ">3 " to the number of prescriptions you want. I currently manage to get 8 prescriptions but with heavy modifications. If you would like I could post my modified file.

      Please make a backup of your original file before modifying it. For the changes to take effect you just need to print another multiple prescription.

      Hope that helps.

      Regards

      Rayaz

       
    • bowyn

      bowyn - 2009-03-27

      Riaz,

      Thanks for your reply. I will try it later, but it would be great if you can post your modified file.  Eight medications on 1 page is exactly what I need.

      Best Regards,

      Bo

       
    • Riaz Chaudhry

      Riaz Chaudhry - 2009-03-28

      Here it is:

      <?php

      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");

      class C_Prescription extends Controller {

          var $template_mod;
          var $pconfig;
          var $providerid = 0;
          var $is_faxing = 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'];

              if ($GLOBALS['inhouse_pharmacy']) {
                  // Make an array of drug IDs and selectors for the template.
                  $drug_array_values = array(0);
                  $drug_array_output = array("-- 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));
              }
              //print_r(Prescription::prescriptions_factory($id));
              $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 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);
              }

          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();
              }--Rayaz

              $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 multiprint_header(& $pdf, $p) {
              $this->providerid = $p->provider->id;
              //print header
              //$pdf->ezImage($GLOBALS['fileroot'] . '/interface/pic/Rx.png','','500','','left','');
              //My prescription has four columns in the header, one for the default facility name, one for my logo, one for my name and qualifictions         and the fourth for my facility name in urdu, which is an image file since urdu is not supported by ezpdf yet --Rayaz       
              $pdf->ezColumnsStart(array('num'=>4, 'gap'=>10));
              $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) . "'");
              $pdf->ezText($res['addr'],12);
              $my_y = $pdf->y;
              $pdf->ezNewPage();
              $pdf->ezImage($GLOBALS['fileroot'] . '/interface/pic/logo.jpg','','75','','center','');
              $my_y = $pdf->y;
              $pdf->ezNewPage();
              $pdf->ezText('<b>' . $p->provider->get_name_display() . '</b>',12);
              // your qualificatons --Rayaz
              $pdf->ezText('<b>qualifications</b>',10);
              // your speciality --Rayaz
              $pdf->ezText('<b>Speciality</b>',10);
              $pdf->ezText('',20);
              //your mobile number if you want --Rayaz
              $pdf->ezText('Mobile ########, #########',10);
              $my_y = $pdf->y;
              $pdf->ezNewPage();
              //my clinic name image in urdu which I have commented out, you could replace it with any thing you want --Rayaz       
              //$pdf->ezImage($GLOBALS['fileroot'] . '/interface/pic/tsc.png','','','','center','');
              //Since I don't need my registration number on my prescriptions I have commented out the DEA number --Rayaz
          // 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
          //     <openemr root>/includes/config.php - Tekknogenius
          //if ($this->is_faxing || $GLOBALS['oer_config']['prescriptions']['show_DEA'])
            //$pdf->ezText('<b>DEA:</b>' . $p->provider->federal_drug_id, 12);
          //else
            //$pdf->ezText('<b>DEA:</b> ________________________', 12);
              $pdf->ezColumnsStop();
              if ($my_y < $pdf->y){
                  $pdf->ezSetY($my_y);
              }
              $pdf->ezText('',20);
              $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('<b>Patient Name & Address</b>',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('<b>Date of Birth</b>',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('<b>Medical Record #</b>',6);
              $pdf->ezText(str_pad($p->patient->get_id(), 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('<b>Prescriptions</b>',6);
              $pdf->ezText('',10);
          }

          function multiprint_footer(& $pdf) {
              if($this->pconfig['use_signature'] && $this->is_faxing) {
                  $sigfile = str_replace('{userid}', $this->providerid, $this->pconfig['signature']);
                  if (file_exists($sigfile)) {
                      $pdf->ezText("Signature: ",12);
                      // $pdf->ezImage($sigfile, "", "", "none", "left");
                      $pdf->ezImage($sigfile, "", "", "none", "center");
                      $pdf->ezText("Date: " . date('Y-m-d'), 12);
                      return;
                  }
              }
              $pdf->ezText("\n\n\nSignature:________________________________\nDate: " . date('Y-m-d'),12);
                  $pdf->ezText('',10);
              // Another image file of urdu instructions for my patients, with english instructions commented out --Rayaz
              //$pdf->ezImage($GLOBALS['fileroot'] . '/interface/pic/ft.png','','300','','center','');
              //$pdf->ezText('<b>Please call to confirm your appointment before coming to the clinic</b>',10);
              //$pdf->ezText('<b>Clinic will remain closed on Friday and Sunday</b>',10);
          }
              //here I have modified the prescription body to get 8 prescriptions in an A4 size page by squeezing the prescription to two lines instead             of the original four. You will also have to change the paper size to A4 from LETTER in /openemr/inludes/config.php --Rayaz
          function get_prescription_body_text($p) {
              $body = '<b>Rx: ' . $p->get_drug() . ' ' . $p->get_size() . ' ' . $p->get_unit_display();
              if ($p->get_form()) $body .= ' [' . $p->form_array[$p->get_form()] . "]";
              $body .= "</b>     <i>" .
                  $p->substitute_array[$p->get_substitute()] . "</i>" .'   '.
                  '<b>Disp #:</b> <u>' . $p->get_quantity() . "</u>\n\n" .
                  '<b>Sig:</b> ' . $p->get_dosage() . ' ' . $p->form_array[$p->get_form()] . ' ' .
                  $p->route_array[$p->get_route()] . ' ' . $p->interval_array[$p->get_interval()] . "    ";
              if ($p->get_refills() > 0) {
                  $body .= "\n<b>Refills:</b> <u>" .  $p->get_refills();
                  if ($p->get_per_refill()) {
                      $body .= " of quantity " . $p->get_per_refill();
                  }
                  $body .= "</u>";
              }
              else {
                  $body .= "<b>Refills:</b> <u>0 (Zero)</u>";
              }
              $note = $p->get_note();
              if ($note != '') {
                  $body .= "\n$note\n";
              }
              return $body;
          }

          function multiprint_body(& $pdf, $p){
              $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
              $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
              $d = $this->get_prescription_body_text($p);
              if ( $pdf->ezText($d,10,array(),1) ) {
                  $pdf->ez['leftMargin'] -= $pdf->ez['leftMargin'];
                  $pdf->ez['rightMargin'] -= $pdf->ez['rightMargin'];
                  $this->multiprint_footer($pdf);
                  $pdf->ezNewPage();
                  $this->multiprint_header($pdf, $p);
                  $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
                  $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
              }
              $my_y = $pdf->y;
              $pdf->ezText($d,10);
              if($this->pconfig['shading']) {
                  $pdf->setColor(.9,.9,.9);
                  $pdf->filledRectangle($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin']-$pdf->ez['leftMargin'],$my_y - $pdf->y);
                  $pdf->setColor(0,0,0);
              }
              $pdf->ezSetY($my_y);
              $pdf->ezText($d,10);
              $pdf->ez['leftMargin'] = $GLOBALS['oer_config']['prescriptions']['left'];
              $pdf->ez['rightMargin'] = $GLOBALS['oer_config']['prescriptions']['right'];
              $pdf->ezText('');
              $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
              $pdf->ezText('');
          }

          function multiprint_action($id = "") {
              $_POST['process'] = "true";
              if(empty($id)) {
                  $this->function_argument_error();
              }
              require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
              $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
              $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
                  ,$GLOBALS['oer_config']['prescriptions']['bottom']
                  ,$GLOBALS['oer_config']['prescriptions']['left']
                  ,$GLOBALS['oer_config']['prescriptions']['right']
              );
              $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");

              // $print_header = true;
              $on_this_page = 0;

              //print prescriptions body
              $this->_state = false; // Added by Rod - see Controller.class.php
              $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY);
              foreach ($ids as $id) {
                  $p = new Prescription($id);
                  // if ($print_header == true) {
                  if ($on_this_page == 0) {
                      $this->multiprint_header($pdf, $p);
                  }
                  //here is the number of prescriptions per page --Rayaz
                      if (++$on_this_page > 8 || $p->provider->id != $this->providerid) {
                      $this->multiprint_footer($pdf);
                      $pdf->ezNewPage();
                      $this->multiprint_header($pdf, $p);
                      // $print_header = false;
                      $on_this_page = 1;
                  }
                  $this->multiprint_body($pdf, $p);
              }

              $this->multiprint_footer($pdf);

              $pdf->ezStream();
              return;
          }

          function send_action_process($id) {
              $dummy = ""; // Added by Rod to avoid run-time warnings
              if ($_POST['process'] != "true")
                  return;
              if(empty($id)) {
                  $this->function_argument_error();
              }
              $p = new Prescription($id);
              switch ($_POST['submit']) {

              case "Print":
                      // The following statement added by Rod.
                      // Looking at Controller.class.php, it appears that _state is set to false
                      // to indicate that no further HTML is to be generated.
                      $this->_state = false; // Added by Rod - see Controller.class.php
                      return $this->_print_prescription($p, $dummy);
                      break;
              case "Email":
                      return $this->_email_prescription($p,$_POST['email_to']);
                      break;
              case "Fax":
                      //this is intended to be the hook for the hylafax code we already have that hasn't worked its way into the tree yet.
                      //$this->assign("process_result","No fax server is currently setup.");
                      return $this->_fax_prescription($p,$_POST['fax_to']);
                      break;
              case "Auto Send":
                      $pharmacy_id = $_POST['pharmacy_id'];
                      //echo "auto sending to : " . $_POST['pharmacy_id'];
                      $phar = new Pharmacy($_POST['pharmacy_id']);
                      //print_r($phar);
                      if ($phar->get_transmit_method() == TRANSMIT_PRINT) {
                          return $this->_print_prescription($p, $dummy);
                      }
                      elseif ($phar->get_transmit_method() == TRANSMIT_EMAIL) {
                          $email = $phar->get_email();
                          if (!empty($email)) {
                              return $this->_email_prescription($p,$phar->get_email());
                          }
                          //else print it
                      }
                      elseif ($phar->get_transmit_method() == TRANSMIT_FAX) {
                          $faxNum= $phar->get_fax();
                          if(!empty($faxNum)) {
                              Return $this->_fax_prescription ($p,$faxNum);
                          }
                          // return $this->assign("process_result","No fax server is currently setup.");
                          // else default is printing,
                      }
                      else {
                           //the pharmacy has no default or default is print
                          return $this->_print_prescription($p, $dummy);
                      }
                      break;
              }

              return;

          }

          function _print_prescription($p, & $toFile) {
              require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
              $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
              $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
                  ,$GLOBALS['oer_config']['prescriptions']['bottom']
                  ,$GLOBALS['oer_config']['prescriptions']['left']
                  ,$GLOBALS['oer_config']['prescriptions']['right']
              );

              $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");

              // Signature images are to be used only when faxing.
              if(!empty($toFile)) $this->is_faxing = true;

              $this->multiprint_header($pdf, $p);
              $this->multiprint_body($pdf, $p);
              $this->multiprint_footer($pdf);

              if(!empty($toFile)) {
                  $toFile = $pdf->ezOutput();
              }
              else {
                  $pdf->ezStream();
                  // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
              }
              return;
          }

          function _print_prescription_old($p, & $toFile) {
              require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
              $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
              $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
                            ,$GLOBALS['oer_config']['prescriptions']['bottom']
                                ,$GLOBALS['oer_config']['prescriptions']['left']
                            ,$GLOBALS['oer_config']['prescriptions']['right']
                            );
              $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");
              if(!empty($this->pconfig['logo'])) {
                  $pdf->ezImage($this->pconfig['logo'],"","","none","left");
              }
              $pdf->ezText($p->get_prescription_display(),10);
              if($this->pconfig['use_signature']) {
                  $pdf->ezImage($this->pconfig['signature'],"","","none","left");
              }
              else{
                $pdf->ezText("\n\n\n\nSignature:________________________________",10);
              }
              if(!empty($toFile))
              {
                  $toFile = $pdf->ezOutput();
              }
              else
              {
                  $pdf->ezStream();
                  // $pdf->ezStream(array('compress' => 0)); // for testing with uncompressed output
              }
              return;
          }

          function _email_prescription($p,$email) {
              if (empty($email)) {
                  $this->assign("process_result","Email could not be sent, the address supplied: '$email' was empty or invalid.");
                  return;
              }
              require($GLOBALS['fileroot'] . "/library/classes/class.phpmailer.php");
              $mail = new PHPMailer();
              $mail->SetLanguage("en",$GLOBALS['fileroot'] . "/library/" );
              //this is a temporary config item until the rest of the per practice billing settings make their way in
              $mail->From = $GLOBALS['practice_return_email_path'];
              $mail->FromName = $p->provider->get_name_display();
              $mail->isMail();
              $mail->Host     = "localhost";
              $mail->Mailer   = "mail";
              $text_body  = $p->get_prescription_display();
              $mail->Body = $text_body;
              $mail->Subject = "Prescription for: " . $p->patient->get_name_display();
              $mail->AddAddress($email);
              if($mail->Send()) {
                  $this->assign("process_result","Email was successfully sent to: " . $email);
                  return;
              }
              else {
                  $this->assign("process_result","There has been a mail error sending to " . $_POST['email_to'] . " " . $mail->ErrorInfo);
                  return;
              }
          }

          function do_lookup() {
              if ($_POST['process'] != "true") {
                          // don't do a lookup
                  $this->assign("drug", $_GET['drug']);
                          return;
                      }

                      // process the lookup
              $this->assign("drug", $_POST['drug']);
              $list = array();
              if (!empty($_POST['drug'])) {
                  $list = @RxList::get_list($_POST['drug']);
              }

              if (is_array($list)) {
                  $list = array_flip($list);
                  $this->assign("drug_options",$list);
                  $this->assign("drug_values",array_keys($list));
              }
              else {
                  $this->assign("NO_RESULTS","No results found for: " .$_POST['drug'] . "<br />");
              }
              //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 = dirname(__FILE__)."/../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<br>";
                      exec($cmd . $args);
                  }

              }
              else
              {
                  $err = "bad fax number passed to function";
              }
              if($err)
              {
                  $this->assign("process_result",$err);
              }
          }
      }

      ?>

      Hope it helps

      Regards

      Rayaz

       
    • bowyn

      bowyn - 2009-03-29

      Thanks very much,

      I see what you have changed.  Based on you comments, I change my header to 3 columns: one for patient's name and address, middle column is for pt's DOB with medical record number and bottom for my name, last column is for my clinic name and address.  I also added number for each prescription like 1, 2, 3 to 8 to avoid confusion by assign
      $n = $on_this_page and modifiied  the functions and indentations to line up as follow:

      //add $n here
      function get_prescription_body_text($p, $n) {
      //add $n here               
              $body =  '<b>'. $n . ' ' . $p->get_drug() . ' ' . $p->get_size() . ' ' . $p->get_unit_display();
              if ($p->get_form()) $body .= ' [' . $p->form_array[$p->get_form()] . "]";

              $note = $p->get_note();
              $body .= "</b>     <i>" .
                  $p->substitute_array[$p->get_substitute()] . "</i>\n" .
                  '<b>   Disp #:</b> <u>' . $p->get_quantity() . "</u>\n" .
                  '<b>   Sig:</b> ' . $p->get_dosage() . ' ' . $p->form_array[$p->get_form()] . ' ' .
                  $p->route_array[$p->get_route()] . ' ' . $p->interval_array[$p->get_interval()] .
                  ' ' . $note;

              if ($p->get_refills() > 0) {
                  $body .= "\n<b>   Refills:</b> <u>" .  $p->get_refills();
                  if ($p->get_per_refill()) {
                      $body .= " of quantity " . $p->get_per_refill();
                  }
                  $body .= "</u>\n";
              }
              else {
                  $body .= "\n<b>   Refills:</b> <u>0 (Zero)</u>\n";
              }
      //        $note = $p->get_note();
      //        if ($note != '') {
      //            $body .= "\n$note\n";
      //        }
              return $body;
          }

          function multiprint_body(& $pdf, $p, $n){  // add $n here
              $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
              $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
              $d = $this->get_prescription_body_text($p, $n);
              if ( $pdf->ezText($d,10,array(),1) ) {
                  $pdf->ez['leftMargin'] -= $pdf->ez['leftMargin'];
                  $pdf->ez['rightMargin'] -= $pdf->ez['rightMargin'];
                  $this->multiprint_footer($pdf);
                  $pdf->ezNewPage();
                  $this->multiprint_header($pdf, $p);
                  $pdf->ez['leftMargin'] += $pdf->ez['leftMargin'];
                  $pdf->ez['rightMargin'] += $pdf->ez['rightMargin'];
              }
              $my_y = $pdf->y;
              $pdf->ezText($d,10);
              if($this->pconfig['shading']) {
                  $pdf->setColor(.9,.9,.9);
                  $pdf->filledRectangle($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin']-$pdf->ez['leftMargin'],$my_y - $pdf->y);
                  $pdf->setColor(0,0,0);
              }
              $pdf->ezSetY($my_y);
              $pdf->ezText($d,10);
              $pdf->ez['leftMargin'] = $GLOBALS['oer_config']['prescriptions']['left'];
              $pdf->ez['rightMargin'] = $GLOBALS['oer_config']['prescriptions']['right'];
      //        $pdf->ezText('');
              $pdf->line($pdf->ez['leftMargin'],$pdf->y,$pdf->ez['pageWidth']-$pdf->ez['rightMargin'],$pdf->y);
      //        $pdf->ezText('');
          }

          function multiprint_action($id = "") {
              $_POST['process'] = "true";
              if(empty($id)) {
                  $this->function_argument_error();
              }
              require_once ($GLOBALS['fileroot'] . "/library/classes/class.ezpdf.php");
              $pdf =& new Cezpdf($GLOBALS['oer_config']['prescriptions']['paper_size']);
              $pdf->ezSetMargins($GLOBALS['oer_config']['prescriptions']['top']
                  ,$GLOBALS['oer_config']['prescriptions']['bottom']
                  ,$GLOBALS['oer_config']['prescriptions']['left']
                  ,$GLOBALS['oer_config']['prescriptions']['right']
              );
              $pdf->selectFont($GLOBALS['fileroot'] . "/library/fonts/Helvetica.afm");

              // $print_header = true;
              $on_this_page = 0;
              //print prescriptions body
              $this->_state = false; // Added by Rod - see Controller.class.php
              $ids = preg_split('/::/', substr($id,1,strlen($id) - 2), -1, PREG_SPLIT_NO_EMPTY);
              foreach ($ids as $id) {
                  $p = new Prescription($id);
                  // if ($print_header == true) {
                  if ($on_this_page == 0) {
                      $this->multiprint_header($pdf, $p);
                  }
                  if (++$on_this_page > 8 || $p->provider->id != $this->providerid) {
                      $this->multiprint_footer($pdf);
                      $pdf->ezNewPage();
                      $this->multiprint_header($pdf, $p);
                      // $print_header = false;
                      $on_this_page = 1;
                  }
      //add $n here
                  $n = $on_this_page;
                  $this->multiprint_body($pdf, $p, $n);
              }

              $this->multiprint_footer($pdf);

      I noticed that the prescription and drug module for openEMR DO NOT support for the Drug to take as p.r.n (as needed).  To my surprise for this being overlooked for a long time. The reason is when we prescribe certain medication such as pain meds, we do not want patient to take round the clock if they do not have pain.  Therefore, I make the get 'note section' move to after 'SIG: ', so that I can make additional comments like 'PRN' or intructions for tapering dosage when giving corticosteroid, etc.

      Someone, please correct misspelled word "inhilation"  with corrected one "inhalation" in /openemr/library/class/Prescription.class.php line 147

      FORM_INHILATIONS => xl("inhilations"),
      to
      FORM_INHILATIONS => xl("inhalations"),

      Thank again Rayaz

      Bo,

       
    • Riaz Chaudhry

      Riaz Chaudhry - 2009-03-29

      Hi

      Quick work there, am trying out your mods.
      Check out line 135  in /openemr/library/classes/Prescription.class.php,  that's got the as needed or PRN bit.

      Regards
      Rayaz

       
    • bowyn

      bowyn - 2009-03-30

      Hi Rayaz,

      There is a prn bit, but it should not be on the same line with bid, tid.  Currently it cannot handle, for example, Tylenol 500mg 1 tablet PO q8h PRN.  This is what I meant.

      Best Regards,

      Bo

       
  • Wilfred Galea

    Wilfred Galea - 2023-11-05

    Any updates here please? I am testing openEMR and find that I can only include two medications in one prescription - can you add more items to fit in one A5 page? Can the header of the prescription be customised at all?

     
  • Wilfred Galea

    Wilfred Galea - 2023-11-05

    Any updates here please? I am testing openEMR and find that I can only include two medications in one prescription - can you add more items to fit in one A5 page? Can the header of the prescription be customised at all?

     

Log in to post a comment.