javascript - boolean testing

I get the following error message when package is being compiled.
PLS-00306: wrong number or types of arguments in call to '||'
I am trying to check if edit_adt_data = true.

Any suggestions why I am getting error mesage?

function save_form() {
      var frm = document.forms[0];
    if ("'||newcertid||'" > 0 && "'||edit_adt_data||'" == TRUE ) {
        frm.submit();  }
    else if (frm.F_STARTDATE.value.substring(0,11).toUpperCase() != "'
                        || renew_date
                        || '") {
        if (confirm("'
                        || renew_date_msg
                        || '")) {
         if (check_form(frm)) {
           alert("one");
            frm.submit();
         }
        }
      } else if (check_form(frm)) {
            alert("two");
            frm.submit();
         }

     }
CREATE OR REPLACE PACKAGE BODY HOSPICEDBA.patient_browser_elig_pkg
AS
   PROCEDURE patient_browser_checklist (f_pid IN varchar2:= NULL,
                                        f_intakeid IN varchar2:= NULL,
                                        f_browser_area IN varchar2:= NULL,
                                        f_viewmode IN varchar2:= 'expand',
                                        f_status IN varchar2:= 'A'
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newviewmode   VARCHAR2 (30) := NVL (f_viewmode, 'expand');
      --NEWSTAT           VARCHAR2(30) := NVL(F_STATUS,'%');
      INSTR         VARCHAR2 (1000);
      datarow       patient_checklist%ROWTYPE;
      userrow       user_details%ROWTYPE;

      CURSOR datacur
      IS
         SELECT a.checklist_item, a.sort_order, b.*
         FROM org_checklist a, patient_checklist b
         WHERE     a.itemid = b.itemid
               AND a.checklist_group = 'I'
               AND b.pid = f_pid
               AND b.intakeid = f_intakeid
         --AND STATUS=NEWSTAT
         ORDER BY a.sort_order;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Patient Checklist');
      ui.css;
      --COMMON.JSCRIPT_LIBRARIES;
      HTP.script ('
function edit_checklist(pid,inid,chkid) {
  var wtitle;
  var mwindow;
  mwindow = "patient_browser_elig_pkg.patient_browser_checklst_edit?f_pid="+pid+"$f_intakeid="+inid+"$f_checkid="+chkid;
  if (chkid > "0") {
      wtitle  = "Edit Patient Checklist Item";
      vReturnValue = window.showModalDialog("common.modal_window?wtitle="+wtitle+"&wurl="+mwindow,window,"center:yes;status:no;help:no;dialogHeight:400px;dialogWidth:700px");
  } else {
      alert("Please save this record before attempting to edit this checklist item.");
  }
}
',
                  'JavaScript'
      );
      HTP.headclose;
      HTP.bodyopen (cattributes => 'topmargin="0" leftmargin="0" rightmargin="0" bgcolor="#EAEEEF" '
      );
      HTP.formopen (' PATIENT_BROWSER_ELIG_PKG.PATIENT_BROWSER_CHECKLIST');
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_VIEWMODE', newviewmode);
      --HTP.FORMHIDDEN('F_DME_STATUS',NEWSTAT);

      HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=4 border=0 '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<td valign="top">');

      HTP.tableopen (cattributes => ' width=100% cellspacing=0 cellpadding=2 border=0'
      );
      HTP.tablerowopen;
      HTP.tabledata (HTF.underline (HTF.bold ('Patient Checklist')),
                     cattributes => 'height="25" valign="top" class="datapageHeader"'
      );
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata(HTF.anchor2 ('patient_browser_elig_pkg.patient_browser_checklist?f_pid='
                                 || newpid
                                 || '&f_intakeid='
                                 || newintakeid
                                 || '&f_viewmode=collapse',
                                 'Collapse',
                                 cattributes => 'class="blueLinkLine"'
                    ));
      --htf.anchor2('patient_browser_pkg.patient_browser_dme?f_pid='||NEWPID||'&f_intakeid='||NEWINTAKEID||'&f_dme_status=D','Discontinued', cattributes=>'class="blueLinkLine"'));
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.br;

      IF f_viewmode = 'collapse'
      THEN
         FOR rec IN datacur
         LOOP
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
            );
            HTP.tablerowopen;
            HTP.tabledata ('<font color="white">'
                           || HTF.bold(   rec.sort_order
                                       || '.&nbsp;'
                                       || INITCAP (rec.checklist_item))
                           || '</font>',
                           cattributes => 'bgcolor="#6487DC"'
            );
            HTP.tablerowclose;
            HTP.tableclose;
            HTP.br;
         END LOOP;
      ELSE
         FOR rec IN datacur
         LOOP
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
            );
            HTP.tablerowopen;
            HTP.tabledata ('<font color="white">'
                           || HTF.bold(   rec.sort_order
                                       || '.&nbsp;'
                                       || INITCAP (rec.checklist_item))
                           || '</font>',
                           cattributes => 'bgcolor="#6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.PRINT ('<TD bgcolor="white">');
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=0 onClick="edit_checklist('
                                         || rec.pid
                                         || ','
                                         || rec.intakeid
                                         || ','
                                         || rec.checkid
                                         || ');this.document.location.reload();"'
            );

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('status: '),
                           cattributes => 'class="datapageLabel" width="30%" height="30" style="border-bottom: 1px solid #6487DC"'
            );

            IF rec.item_status = 'I'
            THEN
               HTP.tabledata ('Incomplete',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" '
               );
            ELSE
               HTP.tabledata ('Complete',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" '
               );
            END IF;

            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('date: '),
                           cattributes => 'class="datapageLabel"  height="30" style="border-bottom: 1px solid #6487DC" '
            );
            HTP.tabledata (NVL (TO_CHAR (rec.item_date_stamp, 'MM/DD/YYYY'),
                                '&nbsp;'
                           ),
                           cattributes => ' style="border-bottom: 1px solid #6487DC" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('user: '),
                           cattributes => 'class="datapageLabel"  height="30"  '
            );
            HTP.tabledata (common.user_lookup (rec.item_userid_stamp),
                           cattributes => ' '
            );
            HTP.tablerowclose;
            HTP.tableclose;

            HTP.PRINT ('</TD>');
            HTP.tablerowclose;
            HTP.tableclose;
            HTP.br;
         END LOOP;
      END IF;

      HTP.PRINT ('</td>');
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.PRINT (INSTR);
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_browser_checklist;


   PROCEDURE patient_browser_checklst_edit (recstatus IN varchar2:= NULL,
                                            f_pid IN varchar2:= NULL,
                                            f_intakeid IN varchar2:= NULL,
                                            f_checkid IN varchar2:= NULL,
                                            f_itemid IN varchar2:= NULL,
                                            f_item_status IN varchar2:= NULL,
                                            f_item_date_stamp IN VARCHAR2:= NULL,
                                            f_item_time_stamp IN VARCHAR2:= NULL,
                                            f_item_userid_stamp IN VARCHAR2:= NULL,
                                            f_item_notes IN varchar2:= NULL
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newcheckid    VARCHAR2 (30) := f_checkid;
      name          VARCHAR2 (100);
      INSTR         VARCHAR2 (1000);
      datarow       patient_checklist%ROWTYPE;
      userrow       user_details%ROWTYPE;

      CURSOR datacur
      IS
         SELECT *
         FROM patient_checklist
         WHERE     pid = newpid
               AND intakeid = newintakeid
               AND checkid = newcheckid;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      IF recstatus IS NOT NULL
      THEN
         BEGIN
            IF recstatus = 'update'
            THEN
               --FIRST CLOSE THE OTHER TEAM RECORD, STAMP ENDATE AND STATUS--
               UPDATE patient_checklist
               SET item_status         = f_item_status,
                   item_date_stamp     =
                      common.get_time (f_item_date_stamp, f_item_time_stamp),
                   item_userid_stamp   = f_item_userid_stamp,
                   moduser             = userrow.contactid,
                   moddate             = SYSDATE,
                   item_notes          = f_item_notes
               WHERE     pid = newpid
                     AND intakeid = newintakeid
                     AND checkid = newcheckid;

               -- COMMIT;
               INSTR   := HTF.script ('top.window.close();', 'JavaScript');
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               hi_common.error_handler;
         END;
      END IF;

      FOR rec IN datacur
      LOOP
         datarow   := rec;
      END LOOP;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Edit Checklist Item');
      ui.css;
      common.jscript_libraries;
      HTP.script ('
function save_form() {
  var efrm = document.forms[0];
  validate();
  if (returnVal) {
     efrm.submit();
  }
}
function init() {
  define("F_ITEM_STATUS", "dropdown", "Item Status");
  define("F_ITEM_DATE_STAMP", "string", "Completion Date");
  define("F_ITEM_USERID_STAMP", "dropdown", "Who Completed");
}
function stamp_datetime(datefld,timefld) {
  var frm = this.document.forms[0];
  var thisdate = "'
                  || TO_CHAR (SYSDATE, 'DD-Mon-YYYY')
                  || '";
  //var thistime = "'
                  || TO_CHAR (SYSDATE, 'HH:MIAM')
                  || '";
  var Hours;
  var Mins;
  var Time;
  Stamp = new Date();
  Hours = Stamp.getHours();
  if (Hours >= 12) {
    Time = "PM";
  } else {
    Time = "AM";
  }
  if (Hours > 12) {
    Hours -= 12;
  }
  if (Hours == 0) {
    Hours = 12;
  }
  Mins = Stamp.getMinutes();
  if (Mins < 10) {
    Mins = "0" + Mins;
  }
  var thistime = Hours + ":" + Mins + Time;

  var dfield = eval("this.document.forms[0]."+datefld);
  var tfield = eval("this.document.forms[0]."+timefld);
  dfield.value = thisdate;
  tfield.value = thistime;
}
function startup() {
  var frm = this.document.forms[0];
  frm.F_ITEM_STATUS.focus();
}
',
                  'JavaScript'
      );
      HTP.headclose;
      HTP.bodyopen (cattributes => 'onLoad="init();" TOPMARGIN="5" LEFTMARGIN="5" bgcolor="#FFFFFF" '
      );
      HTP.formopen ('PATIENT_BROWSER_ELIG_PKG.PATIENT_BROWSER_CHECKLST_EDIT');
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_CHECKID', newcheckid);
      HTP.formhidden ('RECSTATUS', 'update');

      ui.section_open_blue (   'Edit Patient Checklist Item '
                            || HTF.bold ('&raquo;')
                            || '&nbsp;'
                            || common.patient_lookup (newpid, TRUE),
                            ui.make_blubutton ('Save and Close',
                                               '120',
                                               'save_form();'
                            )
                            || '&nbsp;'
      );

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=5 border=0 width=100% height=100% '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<TD valign=top>');

      hi_common.fieldset_open (HTF.bold ('Checklist Item Details'));

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '
      );
      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Checklist Item:'),
                     cattributes => 'width="35%" class="datapageLabel" '
      );
      HTP.tabledata(common.get_checklist_item (datarow.itemid, userrow.orgid));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Status:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(common.coderefoptions ('F_ITEM_STATUS',
                                           'PATIENT_CHECKLIST_STATUS',
                                           NVL (datarow.item_status, NULL),
                                           userrow.orgid
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Completion Date and Time:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(hi_common.date_picker ('F_ITEM_DATE_STAMP',
                                           NVL (datarow.item_date_stamp,
                                                SYSDATE
                                           )
                    )
                    || '&nbsp'
                    || common.time_picker ('F_ITEM_TIME_STAMP',
                                           NVL (datarow.item_date_stamp,
                                                SYSDATE
                                           )
                       )
                    || '&nbsp;'
                    || ui.make_button ('&nbsp;',
                                       '15',
                                       'stamp_datetime(&#34;F_ITEM_DATE_STAMP&#34;,&#34;F_ITEM_TIME_STAMP&#34;)'
                       ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Who Completed:'),
                     cattributes => ' class="datapageLabel"'
      );
      HTP.tabledata(common.useroptions ('F_ITEM_USERID_STAMP',
                                        NVL (datarow.item_userid_stamp,
                                             userrow.contactid
                                        ),
                                        userrow.orgid
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Checklist Notes:'),
                     cattributes => 'colspan=2 class="datapageLabel"'
      );
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.formtextareaopen2 ('F_ITEM_NOTES',
                                            10,
                                            10,
                                            'LEFT',
                                            'SOFT',
                                            cattributes => 'style="height:150px; width:100%;"'
                     )
                     || NVL (datarow.item_notes, NULL)
                     || HTF.formtextareaclose,
                     cattributes => 'colspan=2'
      );
      HTP.tablerowclose;
      HTP.tableclose;

      hi_common.fieldset_close;

      HTP.PRINT ('</TD>');
      HTP.tablerowclose;
      HTP.tableclose;

      ui.section_close_blue('&nbsp;'
                            || common.audit_msg (datarow.moduser,
                                                 datarow.moddate
                               ));

      HTP.PRINT (INSTR);
      HTP.formclose;
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_browser_checklst_edit;


   PROCEDURE cert_list (f_pid IN varchar2:= NULL,
                        f_intakeid IN varchar2:= NULL,
                        f_viewmode IN varchar2:= 'expand'
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newviewmode   VARCHAR2 (30) := NVL (f_viewmode, 'expand');
      certcnt       NUMBER := 0;
      INSTR         VARCHAR2 (1000);
      userrow       user_details%ROWTYPE;


      --2/18/04 andy: had to revert back to old code due to new reqs - verified/not verified is only used for first cert
      CURSOR datacur
      IS
         SELECT *
         FROM patient_cert_periods
         WHERE pid = f_pid AND intakeid = f_intakeid
         ORDER BY certid DESC;



      datarow       datacur%ROWTYPE;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      -- --check for an existing patient certification period record
      -- SELECT COUNT(CERTID) INTO CERTCNT FROM PATIENT_CERT_PERIODS
      --     WHERE PID=NEWPID AND INTAKEID=NEWINTAKEID;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Patient Certifications');
      ui.css;
      --COMMON.JSCRIPT_LIBRARIES;
      HTP.script ('
function edit_cert(pid,inid,certid) {
  var wtitle;
  var mwindow;
  mwindow = "patient_browser_elig_pkg.cert_edit?f_pid="+pid+"$f_intakeid="+inid+"$f_certid="+certid;
  if (pid > "0") {
      wtitle  = "Patient Certification";
      vReturnValue = window.showModalDialog("common.modal_window?wtitle="+wtitle+"&wurl="+mwindow,window,"center:yes;status:no;help:no;dialogHeight:550px;dialogWidth:750px");
  } else {
      alert("Please select a valid patient before attempting to change this patient''s certification.");
  }
}
function delete_cert(pid,inid,certid) {
    if (confirm("Are you sure you want to delete this certification record? This cannot be undone.")) {
      this.saveframe.document.location="patient_browser_elig_pkg.cert_save?recstatus=DELETE&f_pid="+pid+"&f_intakeid="+inid+"&f_certid="+certid;
  }
}
',
                  'JavaScript'
      );
      HTP.headclose;

      HTP.bodyopen (cattributes => 'topmargin="0" leftmargin="0" rightmargin="0" bgcolor="#EAEEEF" '
      );
      HTP.formopen (' PATIENT_BROWSER_ELIG_PKG.CERT_LIST');
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_VIEWMODE', newviewmode);

      HTP.PRINT('<iframe name="saveframe" style="display:none" src="ui.blank"></iframe>');

      HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=4 border=0 '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<td valign="top">');

      HTP.tableopen (cattributes => ' width=100% cellspacing=0 cellpadding=2 border=0'
      );
      HTP.tablerowopen;
      HTP.tabledata (HTF.underline (HTF.bold ('Patient Certifications')),
                     cattributes => 'height="25" valign="top" class="datapageHeader"'
      );
      HTP.tablerowclose;
      HTP.tablerowopen;
      HTP.tabledata(HTF.anchor2 (   'javascript:edit_cert('
                                 || newpid
                                 || ','
                                 || newintakeid
                                 || ',0);this.document.location.reload();',
                                 'Certify Patient',
                                 cattributes => 'class="bluelinkUL"'
                    ));
      HTP.tablerowclose;

      HTP.tableclose;

      HTP.br;

      IF f_viewmode = 'collapse'
      THEN
         FOR rec IN datacur
         LOOP
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
            );
            HTP.tablerowopen;
            HTP.tabledata ('<font color="white">'
                           || HTF.bold(common.coderef (rec.cert_period,
                                                       'CERTIFICATION_PERIOD'
                                       ))
                           || '</font>',
                           cattributes => 'bgcolor="#6487DC"'
            );
            HTP.tablerowclose;
            HTP.tableclose;
            HTP.br;
         END LOOP;
      ELSE
         FOR rec IN datacur
         LOOP
            certcnt     := certcnt + 1;

            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
            );
            HTP.tablerowopen;
            HTP.tabledata ('<font color="white">'
                           || HTF.bold(common.coderef (rec.cert_period,
                                                       'CERTIFICATION_PERIOD'
                                       ))
                           || '</font>',
                           cattributes => 'bgcolor="#6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;

            IF certcnt = 1
            THEN
               HTP.tabledata ('<font color="white">'
                              || HTF.anchor2 (   'javascript:edit_cert('
                                              || rec.pid
                                              || ','
                                              || rec.intakeid
                                              || ','
                                              || rec.certid
                                              || ');this.document.location.reload();',
                                              'edit',
                                              cattributes => 'class="whitelink"'
                                 )
                              || '&nbsp;|&nbsp;'
                              || HTF.anchor2 (   'javascript:delete_cert('
                                              || rec.pid
                                              || ','
                                              || rec.intakeid
                                              || ','
                                              || rec.certid
                                              || ');',
                                              'delete',
                                              cattributes => 'class="whitelink"'
                                 )
                              || '</font>',
                              cattributes => 'bgcolor="#6487DC" '
               );
            ELSE
               HTP.tabledata ('<font color="white">'
                              || HTF.anchor2 (   'javascript:edit_cert('
                                              || rec.pid
                                              || ','
                                              || rec.intakeid
                                              || ','
                                              || rec.certid
                                              || ');this.document.location.reload();',
                                              'edit',
                                              cattributes => 'class="whitelink"'
                                 )
                              || '&nbsp;|&nbsp;'
                              || --htf.anchor2('javascript:delete_cert('||rec.pid||','||rec.intakeid||','||rec.certid||');', 'delete', cattributes=>'class="whitelink"')||
                                 '</font>',
                              cattributes => 'bgcolor="#6487DC" '
               );
            END IF;

            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.PRINT ('<TD bgcolor="white">');
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=0 '
            );

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('start: '),
                           cattributes => 'class="datapageLabel" width="30%" height="30" style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tabledata (NVL (TO_CHAR (rec.startdate, 'DD-Mon-YYYY'),
                                '&nbsp;'
                           ),
                           cattributes => ' style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('renew: '),
                           cattributes => 'class="datapageLabel"  height="30" style="border-bottom: 1px solid #6487DC" '
            );
            HTP.tabledata (NVL (TO_CHAR (rec.enddate, 'DD-Mon-YYYY'),
                                '&nbsp;'
                           ),
                           cattributes => ' style="border-bottom: 1px solid #6487DC" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('status: '),
                           cattributes => 'class="datapageLabel" height="30" style="border-bottom: 1px solid #6487DC" '
            );

            IF rec.status = 'A'
            THEN
               HTP.tabledata ('Active',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" '
               );
            ELSIF rec.status = 'I'
            THEN
               HTP.tabledata ('Inactive',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" '
               );
            END IF;

            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('verified: '),
                           cattributes => 'class="datapageLabel" height="30" style="border-bottom: 1px solid #6487DC" '
            );

            IF rec.verify_status = 'P' OR rec.verify_status IS NULL
            THEN
               HTP.tabledata ('Not Verified',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" '
               );
            ELSIF rec.verify_status = 'C'
            THEN
               HTP.tabledata ('Verified',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" '
               );
            END IF;

            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('notes '),
                           cattributes => 'class="datapageLabel" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (NVL (rec.notes, '&nbsp;'),
                           cattributes => 'colspan=2 '
            );
            HTP.tablerowclose;

            HTP.tableclose;

            HTP.PRINT ('</TD>');
            HTP.tablerowclose;
            HTP.tableclose;
            HTP.br;
         END LOOP;
      END IF;

      HTP.PRINT ('</td>');
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.PRINT (INSTR);
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END cert_list;


   PROCEDURE cert_save (recstatus IN varchar2:= NULL,
                        f_pid IN varchar2:= NULL,
                        f_intakeid IN varchar2:= NULL,
                        f_certid IN varchar2:= NULL
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newcertid     VARCHAR2 (30) := f_certid;
      INSTR         VARCHAR2 (1000);
      userrow       user_details%ROWTYPE;
      delete_cert   BOOLEAN := FALSE;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      --Check whether user has the delete patient cert profile setting
      delete_cert   :=
         common.check_userprofile_setting (userrow.contactid,
                                           107,
                                           userrow.orgid
         );

      IF recstatus IS NOT NULL
      THEN
         BEGIN
            IF recstatus = 'DELETE' AND delete_cert = TRUE
            THEN
               --delete the cert
               DELETE FROM patient_cert_periods
               WHERE     pid = newpid
                     AND intakeid = newintakeid
                     AND certid = newcertid;

               --commit;

               --update the last/max cert for the patient and set status=A
               --if the last/max cert date has not expired (eg, enddate is < sysdate)

               UPDATE patient_cert_periods
               SET status    = 'A',
                   moduser   = userrow.contactid,
                   moddate   = SYSDATE
               WHERE pid = newpid AND intakeid = newintakeid
                     AND certid =
                           (SELECT MAX (certid)
                            FROM patient_cert_periods
                            WHERE pid = newpid AND intakeid = newintakeid);

               --                and   status ='I' )
               --                and   trunc(enddate) < trunc(sysdate));
               --commit;


               INSTR   := HTF.script ('delete_notif();', 'JavaScript');
            ELSE
               -- Display Alert message  kiran
               HTP.script ('
        alert("To delete this certificate please call the Latis Application Administrator");
     ',
                           'JavaScript'
               );
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               hi_common.error_handler;
         END;
      END IF;


      HTP.htmlopen;
      HTP.headopen;
      HTP.script ('
function delete_notif() {
  //alert("This record was successfully deleted.");
  parent.document.location.reload();
}
',
                  'JavaScript'
      );
      HTP.PRINT (INSTR);
      HTP.headclose;
      HTP.bodyopen;
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END cert_save;


PROCEDURE cert_edit (recstatus IN varchar2:= NULL,
                        f_pid IN varchar2:= NULL,
                        f_intakeid IN varchar2:= NULL,
                        f_certid IN varchar2:= NULL,
                        f_cert_period IN varchar2:= NULL,
                        f_cur_cert_period IN varchar2:= NULL,
                        f_status IN varchar2:= NULL,
                        f_startdate IN varchar2:= NULL,
                        f_starttime IN varchar2:= NULL,
                        f_enddate IN varchar2:= NULL,
                        f_endtime IN varchar2:= NULL,
                        f_diagnosis IN varchar2:= NULL,
                        f_diagnosis_disp IN varchar2:= NULL,
                        f_md1_contactid IN varchar2:= NULL,
                        f_md1_contactid_sig IN varchar2:= NULL,-----Issue 1330 zh
                        f_md1_contactid_disp IN varchar2:= NULL,
                        f_md1_verbal IN varchar2:= NULL,
                        f_md1_verbal_date IN varchar2:= NULL,
                        f_md1_sig IN varchar2:= NULL,
                        f_md1_sig_date IN varchar2:= NULL,
                        f_md2_contactid IN varchar2:= NULL,
                        f_md2_contactid_sig IN varchar2:= NULL,-----Issue 1330 zh
                        f_md2_contactid_disp IN varchar2:= NULL,
                        f_md2_verbal IN varchar2:= NULL,
                        f_md2_verbal_date IN varchar2:= NULL,
                        f_md2_sig IN varchar2:= NULL,
                        f_md2_sig_date IN varchar2:= NULL,
                        f_notes IN varchar2:= NULL,
                        -- 2/2/03 mcs: added verify_status_flag and processing
                        f_verify_status IN varchar2:= 'P',
                        f_paysource_contactid IN varchar2:= NULL,
                        f_override IN varchar2:= NULL,
                        f_emp_attending IN varchar2:= 'N'
   )
   IS
      newpid              NUMBER := f_pid;
      newintakeid         NUMBER := f_intakeid;
      newcertid           NUMBER := f_certid;
      newnoteid           NUMBER;
      newenddate          DATE;
      name                VARCHAR2 (100);
      INSTR               VARCHAR2 (1000);
      cert_exists         NUMBER := 0;
      initial_cert_date   DATE;
      cur_cert_period     VARCHAR2 (30);
      cur_startdate       DATE;
      cur_enddate         DATE;

      new_cert_period     VARCHAR2 (30);
      new_startdate       DATE;
      new_enddate         DATE;
      diag                patient_order_items.order_item%TYPE;
      pt_ps_contactid     VARCHAR2 (30);
      pt_ps_psid          VARCHAR2 (30);
      verify_cert         BOOLEAN := FALSE;
      edit_adt_data       BOOLEAN := FALSE;
      userrow             user_details%ROWTYPE;
      this_start_date     VARCHAR2 (20);
      renew_date          VARCHAR2 (20);
      renew_date_msg      VARCHAR2 (500);
      acertid             NUMBER := 0;
      v_doc_name          VARCHAR2 (500);
      v_doc_type          VARCHAR2 (30);
      v_doc_type_sig      VARCHAR2 (30);----
      v_doc_contactid     NUMBER;
      v_doc_cnt           NUMBER;
      v_emp_attending     VARCHAR2 (2);
      v_emp_attending_sig VARCHAR2 (2);----
      v_certs             NUMBER;
      v_doc_name_sig      VARCHAR2 (500);---
      v_prior             DATE;------Issue 1330 zh----
      v_after             DATE;--------Issue 1330 zh
      v_priorstart          DATE;-----Issue 1330 zh
      v_afterstart          DATE;-----Issue 1330 zh
      v_doc_contactid_sig NUMBER:= null;
      v_doc_contactid_2     NUMBER:= null;
      v_doc_contactid_sig_2 NUMBER:= null;
      v_doc_contactid_ver  NUMBER := null;
    
      CURSOR datacur
      IS
         SELECT *
         FROM patient_cert_periods
         WHERE pid = newpid AND intakeid = newintakeid AND certid = newcertid;

      datarow             datacur%ROWTYPE;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      SELECT COUNT ( * )
      INTO v_certs
      FROM patient_cert_periods
      WHERE pid = newpid AND intakeid = newintakeid;

      SELECT COUNT ( * )
      INTO cert_exists
      FROM patient_cert_periods
      WHERE     pid = newpid
            AND intakeid = newintakeid
            AND certid <= DECODE (f_certid, 0, v_certs, f_certid); --added for issue 744
      ------Verify date -----Issue 1330 zh
      SELECT admit_date-15,admit_date+2
       INTO v_prior,v_after
         FROM patient_intake
         WHERE pid = newpid AND intakeid = newintakeid;  
     
      --if patient has no cert then lookup admit date to use as initial cert date
      IF cert_exists = 0
      THEN
         SELECT admit_date
         INTO initial_cert_date
         FROM patient_intake
         WHERE pid = newpid AND intakeid = newintakeid;
      END IF;

      IF cert_exists = 0 OR (f_certid = 1 AND cert_exists > 0)
      THEN
         SELECT TO_CHAR (admit_date, 'DD-MON-YYYY')
         INTO renew_date
         FROM patient_intake
         WHERE pid = newpid AND intakeid = newintakeid;

         renew_date_msg   :=
            'The Effective Date of this initial cert does not match the Admission Date. \n Are you sure you wish to continue?';
      ELSE
         IF f_certid = 1 OR (f_certid = 0 AND cert_exists = 1)
         THEN                     -- the first cert or renewing the first cert
            acertid   := 1;
         ELSIF f_certid = 0 AND cert_exists > 1
         THEN -- renewing beyond the first cert - v_certs will be the pprevious cert
            acertid   := cert_exists;
         ELSE                         -- editing, so look at the provious cert
            acertid   := cert_exists - 1;
         END IF;

         SELECT TO_CHAR (enddate, 'DD-MON-YYYY')
         INTO renew_date
         FROM patient_cert_periods
         WHERE pid = newpid AND intakeid = newintakeid AND certid = acertid;

         renew_date_msg   :=
            ' The Effective Date of this cert does not\n match the Renewal Date of the previous cert. \n Are you sure you wish to continue?';
      END IF;

      --select current cert period
      BEGIN
         IF cert_exists > 0
         THEN
            SELECT cert_period, startdate, enddate
            INTO cur_cert_period, cur_startdate, cur_enddate
            FROM patient_cert_periods
            WHERE pid = newpid AND intakeid = newintakeid AND status = 'A';
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;

      --determine the next cert period and date for the patient from the existing cert period
      --if this is going to be the first cert then the period is 1
      IF cert_exists = 0
      THEN
         new_cert_period   := 1;
         new_startdate     := initial_cert_date;
         new_enddate       := initial_cert_date + 90;
      ELSIF cur_cert_period = 1
      THEN   --if the patient is in 1st 90 day period then the new period is 2
         new_cert_period   := 2;
         new_startdate     := cur_enddate;
         this_start_date   := TO_CHAR (cur_enddate, 'DD-MON-YYYY');
         new_enddate       := cur_enddate + 90;
      ELSIF cur_cert_period = 2
      THEN   --if the patient is in 2nd 90 day period then the new period is 3
         new_cert_period   := 3;
         new_startdate     := cur_enddate;
         this_start_date   := TO_CHAR (cur_enddate, 'DD-MON-YYYY');
         new_enddate       := cur_enddate + 60;
      ELSIF cur_cert_period = 3
      THEN   --if the patient is in 1st 60 day period then the new period is 3
         new_cert_period   := 3;
         new_startdate     := cur_enddate;
         this_start_date   := TO_CHAR (cur_enddate, 'DD-MON-YYYY');
         new_enddate       := cur_enddate + 60;
      END IF;
     
      --select current dx
      BEGIN
         SELECT order_item
         INTO diag
         FROM patient_order_items
         WHERE     pid = newpid
               AND intakeid = newintakeid
               AND order_type = 'DIAG'
               AND item_rank = 'P';
      EXCEPTION
         WHEN OTHERS
         THEN
            NULL;
      END;


      --check whether user has the edit adt data profile setting
      edit_adt_data   :=
         common.check_userprofile_setting (userrow.contactid,
                                           105,
                                           userrow.orgid
         );

      --check whether user has the verify patient cert profile setting
      verify_cert   :=
         common.check_userprofile_setting (userrow.contactid,
                                           104,
                                           userrow.orgid
         );


      IF recstatus IS NOT NULL
      THEN
         BEGIN
            IF recstatus = 'insert'
            THEN
               --first close the active cert record (set status=I)
               UPDATE patient_cert_periods
               SET status    = 'I',
                   moduser   = userrow.contactid,
                   moddate   = SYSDATE
               WHERE pid = newpid AND intakeid = newintakeid AND status = 'A';

               --insert record into cert period table
               SELECT NVL (MAX (certid), 0) + 1
               INTO newcertid
               FROM patient_cert_periods
               WHERE pid = newpid AND intakeid = newintakeid;

               INSERT INTO patient_cert_periods
              (
                  orgid,
                  pid,
                  intakeid,
                  certid,
                  cert_period,
                  status,
                  startdate,
                  enddate,
                  diagnosis,
                  md1_contactid,
                  md1_contactid_sig,--------Issue 1330 zh
                  md1_verbal,
                  md1_verbal_date,
                  md1_sig,
                  md1_sig_date,
                  md2_contactid,
                  md2_contactid_sig,---------Issue 1330 zh
                  md2_verbal,
                  md2_verbal_date,
                  md2_sig,
                  md2_sig_date,
                  notes,
                  createuser,
                  createdate,
                  verify_status,
                  paysource_contactid,
                  psid
                
              )
               VALUES (
                         userrow.orgid,
                         newpid,
                         newintakeid,
                         newcertid,
                         new_cert_period,
                         'A',
                         new_startdate,
                         new_enddate,
                         f_diagnosis,
                         f_md1_contactid,
                         f_md1_contactid_sig,---------Issue 1330 zh
                         f_md1_verbal,
                         f_md1_verbal_date,
                         decode(f_md1_contactid_sig,null,null,'T'),-----Issue 1330 zh
                         f_md1_sig_date,
                         f_md2_contactid,
                         f_md2_contactid_sig,---------Issue 1330 zh
                         f_md2_verbal,
                         f_md2_verbal_date,
                         decode(f_md2_contactid_sig,null,null,'T'),-----Issue 1330 zh
                         f_md2_sig_date,
                         f_notes,
                         userrow.contactid,
                         SYSDATE,
                         f_verify_status,
                         NULL,
                         NULL
                      
                      );

               INSTR   := HTF.script ('window.top.close();', 'JavaScript');
            ELSE
               --if the user is updating (not overriding) the cert data then do update
               --note: dont permit updates on the period or dates
               IF edit_adt_data = FALSE
               THEN
                  UPDATE patient_cert_periods
                  SET diagnosis         = f_diagnosis,
                       md1_contactid     = f_md1_contactid,
                      md1_contactid_sig = f_md1_contactid_sig,--------Issue 1330 zh
                      md1_verbal        = decode(f_md1_contactid,null,null,'T'),-----Issue 1330 zh
                      md1_verbal_date   = f_md1_verbal_date,
                      md1_sig           = decode(f_md1_contactid_sig,null,null,'T'),-----Issue 1330 zh
                      md1_sig_date     = f_md1_sig_date,
                      md2_contactid     = f_md2_contactid,
                      md2_contactid_sig = f_md2_contactid_sig,--------Issue 1330 zh
                      md2_verbal        = decode(f_md2_contactid,null,null,'T'),
                      md2_verbal_date   = f_md2_verbal_date,
                      md2_sig           = decode(f_md2_contactid_sig,null,null,'T'),-----Issue 1330 zh
                      md2_sig_date     = f_md2_sig_date,
                      notes             = f_notes,
                      moduser           = userrow.contactid,
                      moddate           = SYSDATE,
                      verify_status     = f_verify_status
                     
                  WHERE     pid = newpid
                        AND intakeid = newintakeid
                        AND certid = newcertid;
               --if user is overriding then permit updates on all fields
               ELSIF edit_adt_data = TRUE
               THEN
                  IF f_cert_period IN (1, 2)
                  THEN
                     newenddate   :=
                        common.get_time (f_startdate, f_starttime) + 90;
                  ELSIF f_cert_period = 3
                  THEN
                     newenddate   :=
                        common.get_time (f_startdate, f_starttime) + 60;
                  END IF;

                  --calc
                  UPDATE patient_cert_periods
                  SET cert_period       = f_cert_period,
                      startdate         =
                      common.get_time (f_startdate, f_starttime),
                      enddate           = newenddate,
                      diagnosis         = f_diagnosis,
                       md1_contactid     = f_md1_contactid,
                       md1_contactid_sig = f_md1_contactid_sig,--------Issue 1330 zh
                       md1_verbal        = decode(f_md1_contactid,null,null,'T'),-----Issue 1330 zh
                      md1_verbal_date   = f_md1_verbal_date,
                      md1_sig           = decode(f_md1_contactid_sig,null,null,'T'),-----Issue 1330 zh
                      md1_sig_date      = f_md1_sig_date,
                      md2_contactid     = f_md2_contactid,
                      md2_contactid_sig = f_md2_contactid_sig,--------Issue 1330 zh
                      md2_verbal        = decode(f_md2_contactid,null,null,'T'),-----Issue 1330 zh
                      md2_verbal_date   = f_md2_verbal_date,
                      md2_sig           = decode(f_md2_contactid_sig,null,null,'T'),-----Issue 1330 zh
                      md2_sig_date      = f_md2_sig_date,
                      notes             = f_notes,
                      moduser           = userrow.contactid,
                      moddate           = SYSDATE,
                      verify_status     = f_verify_status
                     
                  WHERE     pid = newpid
                        AND intakeid = newintakeid
                        AND certid = newcertid;
               END IF;

               INSTR   := HTF.script ('window.top.close();', 'JavaScript');
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               hi_common.error_handler;
         END;
      END IF;

      FOR rec IN datacur
      LOOP
         datarow   := rec;
      END LOOP;
      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Certification Details');
      ui.css;
      common.jscript_libraries;


      --if a new record, check if they are setting the verify_status = "C"
      --handle both sets of fields - MD1 and MD2
      IF cert_exists = 0 OR datarow.certid = 1
      THEN

         --if not verified then verify md options
         IF datarow.verify_status IS NULL OR datarow.verify_status = 'P'
         THEN
            HTP.script ('
//alert("CERT PENDING")
function save_form() {
      var frm = document.forms[0];
    if ("'||newcertid||'" > 0 && "'||edit_adt_data||'" == TRUE ) {
        frm.submit();  }
    else if (frm.F_STARTDATE.value.substring(0,11).toUpperCase() != "'
                        || renew_date
                        || '") {
        if (confirm("'
                        || renew_date_msg
                        || '")) {
         if (check_form(frm)) {
           alert("one");
            frm.submit();
         }
        }
      } else if (check_form(frm)) {
            alert("two");
            frm.submit();
         }

     }
    function setEmpAttending(pid, intakeid) {
      frm = document.forms[0];
      idx = frm.F_MD1_CONTACTID.selectedIndex;
      var contactid = frm.F_MD1_CONTACTID.options(idx).value;
      document.all.fiddles.src = "patient_browser_elig_pkg.set_emp_attending?p_contactid="+contactid+"&p_pid="+pid+"&p_intakeid="+intakeid;
    }
    function setEmpAttendingSig(pid, intakeid) {
      frm = document.forms[0];
      idx = frm.F_MD1_CONTACTID_SIG.selectedIndex;
      var contactid = frm.F_MD1_CONTACTID_SIG.options(idx).value;

      document.all.fiddles.src = "patient_browser_elig_pkg.set_emp_attendingSig?p_contactid="+contactid+"&p_pid="+pid+"&p_intakeid="+intakeid;
    }

     function check_form(frm) {
  //alert("f_emp_attending "+frm.f_emp_attending.value);
       var Msg = "";
       frm = this.document.forms[0];
       AttendingDoc = frm.f_emp_attending.value;
       var str = frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text;
       var str2 = frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text;
       var cstr =  (str.indexOf("Non Employee"));
       var cstr2 =  (str2.indexOf("Non Employee"));
       var reptxt = /-/g;
       var a = new Date(frm.F_MD1_VERBAL_DATE.value.replace(reptxt," "));
       var b = new Date(frm.F_MD1_SIG_DATE.value.replace(reptxt," "));
       var c = new Date(frm.F_MD2_VERBAL_DATE.value.replace(reptxt," "));
       var d = new Date(frm.F_MD2_SIG_DATE.value.replace(reptxt," "));
       var pdate = new Date("'||to_char(v_prior,'dd mon hh24:mi:ss yyyy')||'");
       var adate = new Date("'||to_char(v_after,'dd mon hh24:mi:ss yyyy')||'"); 
       var a_flag = "" 
       var h_flag = ""     
           
    
    //if ( frm.F_MD1_VERBAL_DATE.value != "" && (!(a > pdate  && a < adate)) 
     //  ) {a_flag = "Y";}
   // if ( frm.F_MD2_VERBAL_DATE.value != "" && (!(c > pdate  && c < adate))
     //   ) {h_flag = "Y";}
        
     if (frm.F_MD1_VERBAL.checked == true && frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text == "") {
          alert("Please specify the name of the Attending Physician who submitted verbal.");
          frm.F_MD1_CONTACTID.focus();
              return false;  }  
        
     if (frm.F_MD1_VERBAL.checked == true && frm.F_MD1_VERBAL_DATE.value == ""
         ) {
          alert("Please specify the date the verbal was obtained by the Attending Physician.");
           frm.F_MD1_VERBAL_DATE.focus();
               return false;
            }
      if(frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text != "" && frm.F_MD2_VERBAL_DATE.value == "" 
         ) {
           alert("Please specify the date the verbal was obtained by the Hospice Physician.");
           frm.F_MD2_VERBAL_DATE.focus();
               return false;
            }
     if (frm.F_MD2_VERBAL.checked == true && 
                 frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text == ""
               ) {
          alert("Please specify the name of the Hospice Physician who submitted verbal.");
          frm.F_MD2_CONTACTID.focus();
              return false;    
              }      
      
  if (frm.F_MD1_SIG_DATE.value == "" && frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text != ""
           ) {
           alert("Please specify the date the signature was obtained by the Attending Physician.");
           frm.F_MD1_SIG_DATE.focus();
               return false;
            }
   if (frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text == "" &&
           frm.F_MD1_SIG_DATE.value != "" 
          ) {
           alert("Please specify the name of the Attending Physician signing certification.");
           frm.F_MD1_CONTACTID_SIG.focus();
              return false;    
              }   
          
    if (frm.F_MD2_SIG_DATE.value == "" && frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text != ""
           ) {
           alert("Please specify the date the signature was obtained by the Hospice Physician.");
           frm.F_MD2_SIG_DATE.focus();
               return false;
            }
     if (frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "" &&
         frm.F_MD2_SIG_DATE.value != "" 
        ) {
          alert("Please specify the name of the Hospice Physician signing certification.");
          frm.F_MD2_CONTACTID_SIG.focus();
              return false;    
              }    
     if ((( frm.F_MD1_CONTACTID_SIG.value != "" &&  frm.F_MD2_CONTACTID_SIG.value != "" ) &&
             (frm.F_MD1_CONTACTID_SIG.value ==  frm.F_MD2_CONTACTID_SIG.value ))||
             
             (( frm.F_MD1_CONTACTID_SIG.value != "" &&  frm.F_MD2_CONTACTID.value != "" ) &&
             (frm.F_MD1_CONTACTID_SIG.value ==  frm.F_MD2_CONTACTID.value ))||
             
              (( frm.F_MD2_CONTACTID_SIG.value != "" &&  frm.F_MD1_CONTACTID.value != "" ) &&
             (frm.F_MD2_CONTACTID_SIG.value ==  frm.F_MD1_CONTACTID.value ))||
             
             (( frm.F_MD1_CONTACTID.value != "" &&  frm.F_MD2_CONTACTID.value != "" ) &&
             (frm.F_MD1_CONTACTID.value ==  frm.F_MD2_CONTACTID.value ))||
             
             (( frm.F_MD1_CONTACTID.value != "" &&  frm.F_MD2_CONTACTID_SIG.value != "" ) &&
             (frm.F_MD1_CONTACTID.value ==  frm.F_MD2_CONTACTID_SIG.value ))||
             
              (( frm.F_MD2_CONTACTID.value != "" &&  frm.F_MD1_CONTACTID_SIG.value != "" ) &&
             (frm.F_MD2_CONTACTID.value ==  frm.F_MD1_CONTACTID_SIG.value )))
             {
               alert("Please note that the two physicians must be different");
             return false;      
              }
              
     if ( frm.F_MD1_VERBAL_DATE.value != "" && (!(a > pdate  && a < adate)) 
       ) {
        a_flag = "Y";
        if (!confirm("The Attending Physician''s verbal date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
       
         frm.F_MD1_VERBAL_DATE.focus();
         return false;
        }
        }
        
      //alert(a_flag);
    if (a_flag == "Y" && frm.F_MD1_SIG_DATE.value != "" && (!(b > pdate  && b < adate))){
        if (! confirm("The Attending Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
        frm.F_MD1_SIG_DATE.focus();   
         return false;
       }  }
       
    if (frm.F_MD1_VERBAL_DATE.value == "" && frm.F_MD1_SIG_DATE.value != "" && (!(b > pdate  && b < adate))){
        if (! confirm("The Attending Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
        frm.F_MD1_SIG_DATE.focus();   
         return false;
       }  }   
         
   if ( frm.F_MD2_VERBAL_DATE.value != "" && (!(c > pdate  && c < adate))
        ) {
        h_flag = "Y";
         if (!confirm("The Hospice Physician''s verbal date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
            frm.F_MD2_VERBAL_DATE.focus();
            return false;
         }}
        //alert(h_flag);
   if (h_flag == "Y" && frm.F_MD2_SIG_DATE.value != "" && (!(d > pdate  && d < adate) 
       )){
       if (!confirm("The Hospice Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
         frm.F_MD2_SIG_DATE.focus();  
          return false;
         } }
         
      if (frm.F_MD2_VERBAL_DATE.value == "" && frm.F_MD2_SIG_DATE.value != "" && (!(d > pdate  && d < adate))){
      if (!confirm("The Hospice Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
        frm.F_MD2_SIG_DATE.focus();  
          return false;
       } }
           
     if (frm.F_VERIFY_STATUS.value == "C") {
         if (confirm("Are you sure you want to verify this cert?\n"+Msg)) {
          
     if (frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text == "" &&
           frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "" )
            {
           alert("To Complete an initial certification two physician \nsignatures and dates signed are required.");
           return false;
           };
                   
          
            if (frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text == ""
                && frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text == "") 
                {
                alert("Please specify Attending Physician.");
                frm.F_MD1_CONTACTID_SIG.focus();
                return false;   
                 
             }else if (frm.F_DIAGNOSIS_DISP.value =="") {
            alert("Please specify the primary diagnosis.");
            frm.F_DIAGNOSIS_DISP.focus();
            return false;
        
            } else if (frm.F_MD1_VERBAL.checked == true && frm.F_MD1_VERBAL_DATE.value == "") {
           alert("Please specify the date the verbal was obtained by the Attending Physician.");
           frm.F_MD1_VERBAL_DATE.focus();
               return false;
            } else if (frm.F_MD1_VERBAL.checked == true && 
                       frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text == "") {
              alert("Please specify that the signature was obtained for Hospice Physician.");
               return false;   
         
           }else if (cstr != -1 && frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text == ""
           && frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text != "")
           {
               alert("Please specify that the signature was obtained for Attending Physician.");
                
             frm.F_MD1_CONTACTID.focus();
             return false;
             }else if (cstr != -1 && frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text == ""
           && frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text != "")
           {
                alert("Please specify that the signature was obtained for Hospice Physician.");
               
             frm.F_MD2_CONTACTID_SIG.focus();
             return false;
             }else if (cstr == -1 && cstr2 == -1 && frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text == "")
           { alert("Please specify the name of the Attending Physician signing certification.");
             frm.F_MD1_CONTACTID_SIG.focus();
             return false;
          }else if (cstr != -1 && cstr2 != -1 
          && frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "")
         {
              alert("Please specify the name of the Hospice Physician signing certification.");
               
            frm.F_MD2_CONTACTID_SIG.focus();
             return false;
             
          }else if (cstr2 != -1 
          && frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "")
         {
              alert("Please specify the name of the Hospice Physician signing certification.");
               
            frm.F_MD2_CONTACTID_SIG.focus();
             return false;    
             }else if (cstr != -1 && cstr2 != -1 && frm.F_MD1_CONTACTID.options[frm.F_MD1_CONTACTID.selectedIndex].text != "" &&
             frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text != "")
         {
             return true;
            
               }else if (cstr != -1 && cstr2 != -1 && frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == ""
               && frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text == "")
         {
             alert("Please specify the name of the Hospice Physician who submitted verbal");
                
            frm.F_MD2_CONTACTID.focus();
             return false;
            
           } else if ((( frm.F_MD1_CONTACTID_SIG.value != "" &&  frm.F_MD2_CONTACTID_SIG.value != "" ) &&
             (frm.F_MD1_CONTACTID_SIG.value ==  frm.F_MD2_CONTACTID_SIG.value ))||
             
             (( frm.F_MD1_CONTACTID_SIG.value != "" &&  frm.F_MD2_CONTACTID.value != "" ) &&
             (frm.F_MD1_CONTACTID_SIG.value ==  frm.F_MD2_CONTACTID.value ))||
             
              (( frm.F_MD2_CONTACTID_SIG.value != "" &&  frm.F_MD1_CONTACTID.value != "" ) &&
             (frm.F_MD2_CONTACTID_SIG.value ==  frm.F_MD1_CONTACTID.value ))||
             
             (( frm.F_MD1_CONTACTID.value != "" &&  frm.F_MD2_CONTACTID.value != "" ) &&
             (frm.F_MD1_CONTACTID.value ==  frm.F_MD2_CONTACTID.value ))||
             
             (( frm.F_MD1_CONTACTID.value != "" &&  frm.F_MD2_CONTACTID_SIG.value != "" ) &&
             (frm.F_MD1_CONTACTID.value ==  frm.F_MD2_CONTACTID_SIG.value ))||
             
              (( frm.F_MD2_CONTACTID.value != "" &&  frm.F_MD1_CONTACTID_SIG.value != "" ) &&
             (frm.F_MD2_CONTACTID.value ==  frm.F_MD1_CONTACTID_SIG.value )))
             {
               alert("Please note that the two physicians must be different");
             return false;
           
        
          
            } 
           else {
                return true;
            }
 if ( (frm.F_MD1_CONTACTID_SIG.options[frm.F_MD1_CONTACTID_SIG.selectedIndex].text != "" &&
           frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text != "" )
          || (cstr2 == -1) 
           ) {
           return true;
           };
         
        }

      } else {
        return true;
      }
    }


    ',
     'JavaScript'
            );
         --if verified then dont verify md options
         ELSIF datarow.verify_status = 'C'
         THEN
            HTP.script ('
//alert("CERT COMPLETED")
    function save_form() {
      var frm = document.forms[0];
      //alert(frm.F_STARTDATE.value.substring(0,11).toUpperCase()+"\n"+"'
                        || renew_date
                        || '"); return false;
    if (frm.F_STARTDATE.value.substring(0,11).toUpperCase() != "'
                        || renew_date
                        || '") {
        if (confirm("'
                        || renew_date_msg
                        || '")) {
         if (check_form(frm)) {
            frm.submit();
         }
        }
      } else {
        if (check_form(frm)) {
         frm.submit();
         }
      }
     }
  

    function check_form(frm) {
   //alert("TEST2");
     //  if (frm.F_MD1_VERBAL.checked == true && frm.F_MD1_VERBAL_DATE.value == "") {
      //    alert("A date needs to be supplied for the Verbal Obtained Date field.");
      //  return false;
     //  } else {
        return true;
     //  }
    }

    ',
                        'JavaScript'
            );
         END IF;
      ----------------------------
      --if a subsequent record, only need to handle one set of md fields
      --check if they are setting the verify_status = "C"
      ELSE
         --if not verified then verify md options
         IF datarow.verify_status IS NULL OR datarow.verify_status = 'P'
         THEN
            HTP.script ('
//alert("3")
    function save_form() {
      var frm = document.forms[0];
    if (frm.F_STARTDATE.value.substring(0,11).toUpperCase() != "'
                        || renew_date
                        || '") {
        if (confirm("'
                        || renew_date_msg
                        || '")) {
         if (check_form(frm)) {
            frm.submit();
         }
       }
      } else {
        if (check_form(frm)) {
         frm.submit();
         }
        }
     }
     
 function check_form(frm) {
        //alert("Subsequent Cert");
        var Msg = "";
        frm = this.document.forms[0];
        var reptxt = /-/g;
        var h_flag = "" 
            
        var c = new Date(frm.F_MD2_VERBAL_DATE.value.replace(reptxt," "));
        c.setDate(c.getDate());
        var c = c.getTime() ;
              
        var d = new Date(frm.F_MD2_SIG_DATE.value.replace(reptxt," "));
        d.setDate(d.getDate());
        var d = d.getTime(); 
        var pdate = new Date(frm.F_STARTDATE.value.replace(reptxt," "));
              
        pdate.setDate(pdate.getDate()+ 2);
        var pdate = pdate.getTime(); 
                 
        var adate = new Date(frm.F_STARTDATE.value.replace(reptxt," "));
         adate.setDate(adate.getDate() - 15);
        var adate = adate.getTime(); 
        
       
      if(frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text != "" && frm.F_MD2_VERBAL_DATE.value == "" ) {
           alert("Please specify the date the verbal was obtained by the Hospice Physician.");
               frm.F_MD2_VERBAL_DATE.focus();
               return false;
            }
       if (frm.F_MD2_VERBAL.checked == true && 
                 frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text == ""
                 ) {
          alert("Please specify the name of the Hospice Physician who submitted verbal.");
          frm.F_MD2_CONTACTID.focus();
              return false;    
              }      
       
       if (frm.F_MD2_SIG_DATE.value == "" && frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text != ""
           ) {
           alert("Please specify the date the signature was obtained by the Hospice Physician.");
               frm.F_MD2_SIG_DATE.focus();
               return false;
            }
       if (frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "" &&
         frm.F_MD2_SIG_DATE.value != "" ) {
          alert("Please specify the name of the Hospice Physician signing certification.");
              frm.F_MD2_CONTACTID_SIG.focus();
              return false;    
              }  
       
        
      if ( frm.F_MD2_VERBAL_DATE.value != "" && (!(c >= adate  && c <= pdate))) {
         h_flag = "Y";
         if (!confirm("The Hospice Physician''s verbal date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
            frm.F_MD2_VERBAL_DATE.focus();
            return false;
         }}
       //alert(h_flag);
       
     if (h_flag == "Y" && frm.F_MD2_SIG_DATE.value != "" && (!(d >= adate  && d <= pdate) )){
     if (!confirm("The Hospice Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
         frm.F_MD2_SIG_DATE.focus();  
          return false;
         } }
        
       if (frm.F_MD2_VERBAL_DATE.value == "" && frm.F_MD2_SIG_DATE.value != "" && (!(d >= adate  && d <= pdate))){
      if (!confirm("The Hospice Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
        frm.F_MD2_SIG_DATE.focus();  
          return false;
       } }
       //
      //} else 
      //if( frm.F_MD2_SIG_DATE.value != "" && (!(d >= adate  && d <= pdate))) {
       ///  if (!confirm("The Hospice Physician''s signature date does not comply to Medicare Guidelines.\nSelect OKAY to continue?")){
       //  frm.F_MD2_SIG_DATE.focus();  
       //   return false;
       //  } }
               
          
        if (frm.F_VERIFY_STATUS.value == "C") {
        if (confirm("Are you sure you want to verify this cert? ")) {
        //Please note that the physician signature is required.**
                

        if (frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text == "" && frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "") {
        alert("Please note that the physician signature is required.");
            frm.F_MD2_CONTACTID_SIG.focus();
        return false;
         } else if (frm.F_MD2_VERBAL.checked == true && frm.F_MD2_VERBAL_DATE.value == "") {
            alert("A date needs to be supplied for the Verbal Obtained Date field.");
        return false;
         } else if (frm.F_MD2_CONTACTID_SIG.options[frm.F_MD2_CONTACTID_SIG.selectedIndex].text == "" && frm.F_MD2_SIG_DATE.value == "") { 
            alert("Please note that the physician signature is required.");
            frm.F_MD2_CONTACTID_SIG.focus();
        return false;
         }else if (frm.F_DIAGNOSIS_DISP.value ==""
            ) {
            alert("Please specify the primary diagnosis.");
            frm.F_DIAGNOSIS_DISP.focus();
              return false;
                
        } else if (frm.F_MD2_VERBAL.checked == true && 
        frm.F_MD2_CONTACTID.options[frm.F_MD2_CONTACTID.selectedIndex].text == "") {
          alert("Please specify the name of the Hospice Physician who submitted verbal.");
              return false;
                
        } else {
            return true;
        }

        }
        } else {
        return true;
        }
        }


    ',
                   'JavaScript'
            );
         --if verified then dont verify md options
         ELSIF datarow.verify_status = 'C'
         THEN
            HTP.script ('
       // alert("4")
    function save_form() {
      var frm = document.forms[0];
    if (frm.F_STARTDATE.value.substring(0,11).toUpperCase() != "'
                        || renew_date
                        || '") {
        if (confirm("'
                        || renew_date_msg
                        || '")) {
         if (check_form(frm)) {
            frm.submit();
         }
       }
      } else {
        if (check_form(frm)) {
         frm.submit();
         }
        }
     }
  
    function check_form(frm) {
   //alert("test");
    if (frm.F_MD2_VERBAL.checked == true && frm.F_MD2_VERBAL_DATE.value == "") {
       alert("A date needs to be supplied for the Verbal Obtained Date field.");
        return false;
     }  else {
          return true;
       }
    }

    ',
                        'JavaScript'
            );
         END IF;
      END IF;



      HTP.script ('
  // alert("5")
function stamp_date(datefld) {
  var frm = this.document.forms[0];
  var thisdate = "'
                  || TO_CHAR(SYSDATE, 'dd-Mon-yyyy')
                  || '";
  var dfield = eval("this.document.forms[0]."+datefld);
  dfield.value = thisdate;
  
}

function center_open(mypage,myname,h,w,scroll){
   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
   settings = ''height=''+h+'',width=''+w+'',top=''+TopPosition+'',left=''+LeftPosition+'',scrollbars=''+scroll+'',resizable'';
   win = window.open(mypage,myname,settings)
}
function open_icdsearch(dispfld,idfld,frm) {
   center_open("utilities_pkg.icd_search_header?display="+dispfld+"&id="+idfld+"&fname="+frm,"icdsearchwin","500","600","false");
}
function startup() {
  var frm = this.document.forms[0];
  frm.F_CERT_PERIOD.focus();
}
//ISSUE 1330 ZH
function display_datefield(fld,td,td2,td3,td4) {
 var frm = eval("document.forms[0]."+fld);
 var frm2=this.document.forms[0];
 var v_td  = eval(td+".style");
 var v_td2 = eval(td2+".style");
 var v_td3 = eval(td3+".style");
 var v_td4 = eval(td4+".style");
 
 if (frm.checked) {
    v_td.display = "";
    v_td2.display = "";
    v_td3.display = "";
    v_td4.display = "";
  }
 else if (frm2.F_MD1_CONTACTID.value != "" || frm2.F_MD1_VERBAL_DATE.value != "" ){
 if (confirm("Unchecking this box will clear data entered for Verbal Certification. Are you sure you want to continue?")){
    v_td.display = "none";
    v_td2.display = "none";
    v_td3.display = "none";
    v_td4.display = "none";
    frm2.F_MD1_CONTACTID.options[frm2.F_MD1_CONTACTID.selectedIndex].text = "";
    frm2.F_MD1_CONTACTID.value = "";
  frm2.F_MD1_VERBAL_DATE.value = "";
   }
    else{
   frm2.F_MD1_VERBAL.checked = true;
    }
   }
   else {
    v_td.display = "none";
    v_td2.display = "none";
    v_td3.display = "none";
    v_td4.display = "none";
    // frm2.F_MD1_VERBAL.checked = true
  }
  }
  //ISSUE 1330 ZH
function display_datefield1(fld,td5,td6,td7,td8) {
 var frm = eval("document.forms[0]."+fld);
 var frm2=this.document.forms[0];
 var v_td5  = eval(td5+".style");
 var v_td6 = eval(td6+".style");
 var v_td7 = eval(td7+".style");
 var v_td8 = eval(td8+".style");
 //alert(v_td);
 if (frm.checked) {
    v_td5.display = "";
    v_td6.display = "";
    v_td7.display = "";
    v_td8.display = "";
  }
 else if (frm2.F_MD2_CONTACTID.value != "" || frm2.F_MD2_VERBAL_DATE.value != "" ){
 if (confirm("Unchecking this box will clear data entered for Verbal Certification. Are you sure you want to continue?")){
  v_td5.display = "none";
   v_td6.display = "none";
   v_td7.display = "none";
    v_td8.display = "none";
    frm2.F_MD2_CONTACTID.options[frm2.F_MD2_CONTACTID.selectedIndex].text = "";
    frm2.F_MD2_CONTACTID.value = "";
   frm2.F_MD2_VERBAL_DATE.value = "";
    }
    else{
   frm2.F_MD2_VERBAL.checked = true;
    }
   }
   else {
     v_td5.display = "none";
    v_td6.display = "none";
    v_td7.display = "none";
    v_td8.display = "none";
  }
  }
  //ISSUE 1330 ZH
function display_hphy(fld,td13) {
 var frm2=this.document.forms[0];
 var v_td13 = eval(td13+".style");
 var str = frm2.F_MD1_CONTACTID.options[frm2.F_MD1_CONTACTID.selectedIndex].text;
 var str2 = frm2.F_MD1_CONTACTID_SIG.options[frm2.F_MD1_CONTACTID_SIG.selectedIndex].text;
 var cstr =  (str.indexOf("Non Employee"));
 var cstr2 =  (str2.indexOf("Non Employee"));
 var hphy = null;

if ((cstr != -1 || str == "")
&& (cstr2 != -1 || str2 == "")){
v_td13.display = "";
return true;
}else {
v_td13.display = "none";
alert("Only one signature is required when patient''s attending physician is a Hospice employee.");
frm2.F_MD2_CONTACTID.options[frm2.F_MD2_CONTACTID.selectedIndex].text = "";
frm2.F_MD2_CONTACTID.value = "";
frm2.F_MD2_VERBAL_DATE.value = "";
frm2.F_MD2_VERBAL.checked = false;
frm2.F_MD2_CONTACTID_SIG.options[frm2.F_MD2_CONTACTID_SIG.selectedIndex].text = "";
frm2.F_MD2_CONTACTID_SIG.value = "";
frm2.F_MD2_SIG_DATE.value = "";


return false;
  
}
    }  
//ISSUE 1330 ZH
function display_datefield3(fld,td9,td10,td11,td12) {
  var frm = eval("document.forms[0]."+fld);
  var frm2=this.document.forms[0];
  var v_td9 = eval(td9+".style");
  var v_td10 = eval(td10+".style");
  var v_td11 = eval(td11+".style");
  var v_td12 = eval(td12+".style");
  if (frm.checked) {
    v_td9.display = "";
    v_td10.display = "";
    v_td11.display = "";
    v_td12.display = "";
    }
 else if (frm2.F_MD2_CONTACTID.value != "" || frm2.F_MD2_VERBAL_DATE.value != "" ){
 if (confirm("Unchecking this box will clear data entered for Verbal Certification. Are you sure you want to continue?")){
    v_td9.display = "none";
    v_td10.display = "none";
    v_td11.display = "none";
   v_td12.display = "none";
   frm2.F_MD2_CONTACTID.options[frm2.F_MD2_CONTACTID.selectedIndex].text = "";
   frm2.F_MD2_CONTACTID.value = "";
    frm2.F_MD2_VERBAL_DATE.value = "";
    }
  else{
    frm2.F_MD2_VERBAL.checked = true;
    }
   }
   else {
     v_td9.display = "none";
    v_td10.display = "none";
    v_td11.display = "none";
    v_td12.display = "none";
  }
  }

function override(pid,inid,certid) {
   var frm = this.document.forms[0];
   if (confirm("Are you sure you want to override the setting for certification record?")) {
      //this.document.location="patient_browser_elig_pkg.cert_edit?f_override=true&f_pid="+pid+"&f_intakeid="+inid+"&f_certid="+certid;
      frm.submit();
   }
}
',
                  'JavaScript'


      );

      HTP.headclose;
      HTP.bodyopen (cattributes => ' TOPMARGIN="5" LEFTMARGIN="5" bgcolor="#FFFFFF" '
      );
      HTP.formopen ('PATIENT_BROWSER_ELIG_PKG.CERT_EDIT',
                    cattributes => 'name="mainfrm"'
      );
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_CERTID', newcertid);
      HTP.formhidden ('F_OVERRIDE', f_override);
      
      HTP.PRINT('<iframe name="fiddles" style="display:none" src="ui.blank"></iframe>');

      --htp.print(f_paysource_contactid);

      IF newcertid = 0
      THEN
         HTP.formhidden ('recstatus', 'insert');
      ELSE
         HTP.formhidden ('recstatus', 'update');
      END IF;

      -- close screen if the patient is not admitted

      FOR r1
      IN (SELECT COUNT ( * ) AS adm
          FROM patient_intake
          WHERE     pid = f_pid
                AND intakeid = f_intakeid
                AND patient_status IN ('ADM', 'DIS'))
      LOOP
         IF r1.adm = 0
         THEN
            HTP.script('alert("Please admit this patient before entering a certification.");window.top.close();');
         END IF;
      END LOOP;


      -- close screen if we don't have any physicians set up
      FOR r2
      IN (SELECT COUNT ( * ) AS prov
          FROM patient_providers
          WHERE     pid = f_pid
                AND intakeid = f_intakeid
                AND provider_role IN (5, 6, 8, 22, 23)
                AND status = 'A')
      LOOP
         IF r2.prov = 0
         THEN
            HTP.script('alert("Please enter Patient Physician Providers on the Intake form before entering a certification.");window.top.close();');
         END IF;
      END LOOP;
      -------------------------------------zh
      -- close screen if we don't have an attending physician set up
      FOR r3
      IN (SELECT COUNT ( * ) AS prov
          FROM patient_providers
          WHERE     pid = f_pid
                AND intakeid = f_intakeid
                AND provider_role IN (6)
                AND status = 'A')
      LOOP
         IF r3.prov = 0
         THEN
            HTP.script('alert("Please enter the Attending Physician on the Intake form before entering a certification.");window.top.close();');
         END IF;
      END LOOP;

      --if this is not an unsaved cert and if the user has the edit settings then permit overrides
      IF newcertid > 0 AND verify_cert = TRUE
      THEN
         ui.section_open_blue (   'Patient Certification '
                               || HTF.bold ('&raquo;')
                               || '&nbsp;'
                               || common.patient_lookup (newpid, TRUE),
                               ui.make_blubutton ('Override',
                                                  '100',
                                                     'save_form('
                                                  || newpid
                                                  || ','
                                                  || newintakeid
                                                  || ','
                                                  || newcertid
                                                  || ');'
                               )
                               || '&nbsp;'
         );
      --if this is not an unsaved cert and the user cant edit the data and its not verified then permit saves
      ELSIF newcertid > 0 AND edit_adt_data = FALSE AND datarow.verify_status = 'P'
      THEN
         ui.section_open_blue (   'Patient Certification '
                               || HTF.bold ('&raquo;')
                               || '&nbsp;'
                               || common.patient_lookup (newpid, TRUE),
                               ui.make_blubutton ('Save and Close',
                                                  '150',
                                                  'save_form();'
                               )
                               || '&nbsp;'
         );
      --if this is not an unsaved cert and the user cant edit the data and its not verified then permit saves
      ELSIF newcertid > 0 AND edit_adt_data = FALSE AND datarow.verify_status = 'C'
      THEN
         ui.section_open_blue (   'Patient Certification '
                               || HTF.bold ('&raquo;')
                               || '&nbsp;'
                               || common.patient_lookup (newpid, TRUE),
                               ui.make_blubutton ('Close',
                                                  '100',
                                                  'top.window.close();'
                               )
                               || '&nbsp;'
         );
      --elsif newcertid = 0 then
      ELSE
         ui.section_open_blue (   'Patient Certification '
                               || HTF.bold ('&raquo;')
                               || '&nbsp;'
                               || common.patient_lookup (newpid, TRUE),
                               ui.make_blubutton ('Save and Close',
                                                  '150',
                                                  'save_form();'
                               )
                               || '&nbsp;'
         );
      END IF;
      SELECT decode(get_emp_attending(datarow.md1_contactid, newpid, newintakeid),'Y',
      get_emp_attending(datarow.md1_contactid, newpid, newintakeid),get_emp_attending(datarow.md1_contactid_sig, newpid, newintakeid))
     INTO v_emp_attending
      FROM DUAL;
      

      HTP.formhidden ('f_emp_attending', v_emp_attending);
     ---htp.p(', v_emp_attending '||v_emp_attending);
      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=5 border=0 width=100% height=100% '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<TD valign=top>');

      hi_common.fieldset_open (HTF.bold ('Certification Details'));

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '
      );


      --if the user is creating a new cert then display the period info
      IF newcertid = 0
      THEN
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('New Period:'),
                        cattributes => 'class="datapageLabel" width="30%" '
         );
         HTP.tabledata (HTF.formtext ('F_CERT_PERIOD',
                                      50,
                                      50,
                                      common.coderef (new_cert_period,
                                                      'CERTIFICATION_PERIOD',
                                                      userrow.orgid
                                      ),
                                      cattributes => 'class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('New Effective Date:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_STARTDATE',
                                      50,
                                      50,
                                      TO_CHAR (new_startdate,
                                               'DD-MON-YYYY HH12:MI AM'
                                      ),
                                      cattributes => 'class="blueInput" onFocus="this.blur(); alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('New Renew Date:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_ENDDATE',
                                      50,
                                      50,
                                      TO_CHAR (new_enddate,
                                               'DD-MON-YYYY HH12:MI AM'
                                      ),
                                      cattributes => 'class="blueInput" onFocus="this.blur(); alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
      ELSIF newcertid > 0 AND edit_adt_data = FALSE
      THEN
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Current Period:'),
                        cattributes => 'class="datapageLabel" width="30%" '
         );
         HTP.tabledata (HTF.formtext ('F_CERT_PERIOD',
                                      50,
                                      50,
                                      common.coderef (datarow.cert_period,
                                                      'CERTIFICATION_PERIOD',
                                                      userrow.orgid
                                      ),
                                      cattributes => 'class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Effective Date:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_STARTDATE',
                                      50,
                                      50,
                                      TO_CHAR (datarow.startdate,
                                               'DD-MON-YYYY HH12:MI AM'
                                      ),
                                      cattributes => 'class="blueInput" onFocus="this.blur(); alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
         
        
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Renew Date:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_ENDDATE',
                                      50,
                                      50,
                                      TO_CHAR (datarow.enddate,
                                               'DD-MON-YYYY HH12:MI AM'
                                      ),
                                      cattributes => 'READONLY class="blueInput" onFocus="this.blur(); alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
      --otherwise if the user the user has the security setting and elects to override/edit the cert
      ELSIF newcertid > 0 AND edit_adt_data = TRUE
      THEN
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Current Period:'),
                        cattributes => 'class="datapageLabel" width="30%" '
         );
         HTP.tabledata (common.coderefoptions ('F_CERT_PERIOD',
                                               'CERTIFICATION_PERIOD',
                                               datarow.cert_period,
                                               userrow.orgid,
                                               NULL,
                                               'class="blueInput"'
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Effective Date:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (hi_common.date_picker ('F_STARTDATE',
                                               datarow.startdate
                        )
                        || '&nbsp'
                        || common.time_picker ('F_STARTTIME',
                                               datarow.startdate
                           ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
         
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Renew Date:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (hi_common.date_picker ('F_ENDDATE', datarow.enddate)
                        || '&nbsp'
                        || common.time_picker ('F_ENDTIME', datarow.enddate),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
      END IF;


      --if verified, display a read-only text box for the diag
      IF datarow.verify_status = 'C'
      THEN
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Diagnosis: '),
                        cattributes => 'class="datapageLabel"'
         );
         HTP.tabledata (HTF.formtext ('F_DIAGNOSIS_DISP',
                                      50,
                                      50,
                                      common.icd_lookup (datarow.diagnosis),
                                      cattributes => 'READONLY class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('ICD Code:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_DIAGNOSIS',
                                      25,
                                      50,
                                      datarow.diagnosis,
                                      cattributes => 'readonly class="blueInput" onFocus="this.blur(); alert(&#34;This code value is read-only.&#34;);"'
                        )
                        || HTF.formhidden ('F_DIAGNOSIS', datarow.diagnosis),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
      ELSE
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Diagnosis:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_DIAGNOSIS_DISP',
                                      50,
                                      50,
                                      common.icd_lookup(NVL (datarow.diagnosis,
                                                             diag
                                                        )),
                                      cattributes => 'onClick="javascript:open_icdsearch(&#34;F_DIAGNOSIS_DISP&#34;,&#34;F_DIAGNOSIS&#34;,&#34;mainfrm&#34;);"'
                        )
                        || '&nbsp;'
                        || ui.make_button ('&nbsp;',
                                           '15',
                                           'open_icdsearch(&#34;F_DIAGNOSIS_DISP&#34;,&#34;F_DIAGNOSIS&#34;,&#34;mainfrm&#34;)'
                           ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('ICD Code:'),
                        cattributes => 'class="datapageLabel" '
         );
         HTP.tabledata (HTF.formtext ('F_DIAGNOSIS',
                                      25,
                                      50,
                                      NVL (datarow.diagnosis, diag),
                                      cattributes => 'onFocus="this.blur(); alert(&#34;This code value is read-only.&#34;);"'
                        ),
                        cattributes => 'colspan=2'
         );
         HTP.tablerowclose;
      END IF;
 ----Issue 1330 by zh
 
 htp.tableclose;

IF cert_exists = 0 OR datarow.certid = 1
      THEN
       HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '  );
 HTP.p('<td colspan=2><font color="red">If inital certification''s signature is a Hospice employee physician <u>and</u> '
              || 'the patient''s attending physician, only one signature is required.</font></td>');
htp.tableclose;
 hi_common.fieldset_open (HTF.bold ('Attending Physician '));
     HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '  );
     else
     hi_common.fieldset_open (HTF.bold ('Hospice Physician '));
     HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '  );
     end if;
     ---------------------------
     --if the first cert then show MD1 and MD2 fields, otherwise only show MD1 fields
  IF cert_exists = 0 OR datarow.certid = 1
      THEN
               --physician 1 information
         --if cert is verified (eg, phsycian 1 is already entered) then display a read-only text box
     
         
         -----zh
       --v_hphy := null;
     ------------------------------------------------------------
   if datarow.MD1_VERBAL  = 'T' then
    IF datarow.verify_status = 'C'
       THEN   
      htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
       htp.tabledata(hi_common.check_box('F_MD1_VERBAL',datarow.MD1_VERBAL,'T'), cattributes=>'DISABLED width="10%"');
      htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md1verbal" class="datapageLabel"width="29%" '
            );
         else
         htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
     --htp.tabledata(hi_common.check_box('F_MD1_VERBAL',NVL(datarow.MD1_VERBAL,NULL),'T', 'display_datefield(&#34;F_MD1_VERBAL&#34;,&#34;md1verbal&#34;
       htp.tabledata(hi_common.check_box('F_MD1_VERBAL',NVL(datarow.MD1_VERBAL,NULL),'T', 'display_datefield(&#34;F_MD1_VERBAL&#34;,&#34;md1verbal&#34;
       
       ,&#34;md1verbal2&#34;,&#34;md1verbal3&#34;,&#34;md1verbal4&#34;)'), cattributes=>' width="10%"');
     -- -- ,&#34;md1verbal2&#34;,&#34;md1verbal3&#34;,&#34;md1verbal4&#34;)'), cattributes=>'onClick="javascript:cleardata_att()" width="10%"');
       htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md1verbal" class="datapageLabel"width="29%" '
            );
            end if;   
            
           ------------- 
         IF datarow.verify_status = 'C'
            
       THEN
      
            IF datarow.md1_contactid IS NOT NULL
            THEN
               BEGIN
                  SELECT DISTINCT c.contactid,
                         INITCAP (last_name || ', ' || first_name) || ' '
                         || DECODE (c.contact_type,
                                    '0',
                                    c.emp_discipline,
                                    '2',
                                    c.suffix
                            ),
                         DECODE (c.contact_type,
                            '0', 'Employee',
                            'Non Employee')
                  INTO v_doc_contactid_ver,v_doc_name, v_doc_type
                  FROM contacts c, patient_providers pp, domain d
                  WHERE     c.contactid = datarow.md1_contactid
                        AND pp.contactid(+) = c.contactid
                        AND pp.pid(+) = newpid
                        AND pp.intakeid(+) = newintakeid
                        ------
                       /* AND ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))*/
                        -------------------------
                        AND pp.provider_role = d.rv_low_value(+)
                        AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE';
                   
                   v_doc_cnt    := 0;

                  FOR vtx
                  IN (SELECT null role--null role--d.rv_meaning role
                  
                      FROM domain d, patient_providers pp
                      WHERE     pp.pid = newpid
                            AND pp.intakeid = newintakeid
                            AND pp.contactid = datarow.md1_contactid
                            ------
                       /* AND ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))*/
                        -------------------------
                            AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
                            AND d.rv_low_value = pp.provider_role)
                  LOOP
                     IF v_doc_cnt = 0
                     THEN
                        v_doc_name   := v_doc_name ;--|| ' (' ;--|| vtx.role;
                     ELSE
                        v_doc_name   := v_doc_name ;-- || vtx.role;
                     END IF;

                     v_doc_cnt   := v_doc_cnt + 1;
                     

                  END LOOP;

                  --v_doc_name   := v_doc_name || ' - ' || v_doc_type || ')';
                 v_doc_name   := v_doc_name || ' - ' || v_doc_type;
                  
               EXCEPTION
                  WHEN NO_DATA_FOUND
                  THEN
                     NULL;
               END;
            END IF;

            HTP.tabledata (HTF.formtext ('',
                                         LENGTH (v_doc_name),
                                         LENGTH (v_doc_name),
                                         v_doc_name,
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;'
                                                       || v_doc_name
                                                       || '&#34;);" '
                           )
                           || HTF.formhidden ('F_MD1_CONTACTID',
                                              datarow.md1_contactid
                          ),
                              
                           cattributes => 'id="md1verbal2" colspan=3 width="70%"'
            );
            
        
         ELSE
         -------------------------
        --HTP.p('<select name="F_MD1_CONTACTID"
            HTP.p ('<td  id="md1verbal2"  colspan=3>');
         --HTP.p('<select name="F_MD1_CONTACTID" ONCHANGE="display_hphy(this.document);" 
         HTP.p('<select name="F_MD1_CONTACTID" ONCHANGE="display_hphy(&#34;F_MD1_CONTACTID&#34;,&#34;h_display2&#34;);"
                                                                                       
            
            onChange="setEmpAttending('
                  || newpid
                  || ','
                  || newintakeid
                  || ');">');
                  --|| ');">this.document.location.reload(); ');
                -- || ');" ONCHANGE="display_hphy(this.document);">');
            HTP.p ('<option value=""></option>');
           

           FOR vtx
            IN (SELECT pp.contactid,
                       INITCAP (last_name || ', ' || first_name) || ' '
                       || DECODE (c.contact_type,
                                  '0',
                                  c.emp_discipline,
                                  '2',
                                  c.suffix
                          )
                     --  || ' ('
                     --  || d.rv_meaning
                       || ' - '
                       || DECODE (c.contact_type,
                             '0', 'Employee',
                             'Non Employee')
                      -- || ')'
                          name,
                       0 AS sorts,
                       last_name
                       --,DECODE (C.emp_discipline,'MD','Y','DO','Y','N')HOSPICE_DR
                FROM contacts c, patient_providers pp, domain d
                WHERE      --pp.provider_role IN ('6', '23', '5', '8', '22')
                ------
                        ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))
                        -------------------------
                      AND c.contactid = pp.contactid
                      AND pp.pid = newpid
                      AND pp.intakeid = newintakeid
                      AND (contact_type = 2 OR emp_discipline IN ('MD', 'DO'))
                      AND pp.provider_role = d.rv_low_value
                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
              
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md1_contactid
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
               END IF;
            
            END LOOP;
            
 
            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
          --  v_hphy := F_MD1_CONTACTID;--.options[F_MD1_CONTACTID.selectedIndex].text;
         --v_hphy :=  (F_MD1_CONTACTID.indexOf("Non Employee"));
            
        END IF;
            -----------------------
        IF datarow.verify_status = 'C'
         THEN 
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md1verbal3" class="datapageLabel" width="29%" '
                           );
        
          HTP.tabledata (HTF.formtext ('',
                                         F_MD1_VERBAL_DATE,
                                         F_MD1_VERBAL_DATE,
                                         to_char(datarow.md1_verbal_date,'dd-Mon-yyyy'),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD1_VERBAL_DATE',
                                              datarow.md1_verbal_date
                          ),
                                       cattributes => 'id="md1verbal4" colspan=3 width="70%"'
            );
        
            else
             HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md1verbal3" class="datapageLabel" width="29%" '
                           );
        
           HTP.tabledata (common.flex_date_picker('F_MD1_VERBAL_DATE',
                          datarow.md1_verbal_date,
                          NULL,
                          NULL,
                          'NO'
                          )
                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD1_VERBAL_DATE&#34;)'
                              ),
                         -- cattributes => 'id="md1verbal4" onChange="javascript:check_d()"  align="left" width="70%"'
                          cattributes => 'id="md1verbal4" align="left" width="70%"'
                        
            );
            end if;
            
     else
     IF datarow.verify_status = 'C'
       THEN   
      htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
       htp.tabledata(hi_common.check_box('F_MD1_VERBAL',datarow.MD1_VERBAL,'T'), cattributes=>'DISABLED width="10%"');
      htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md1verbal" style="display:none" class="datapageLabel"width="29%" '
            );
   
         else
         htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
      --htp.tabledata(hi_common.check_box('F_MD1_VERBAL',NVL(datarow.MD1_VERBAL,NULL),'T', 'display_datefield(&#34;F_MD1_VERBAL&#34;,&#34;md1verbal&#34;
       htp.tabledata(hi_common.check_box('F_MD1_VERBAL',NVL(datarow.MD1_VERBAL,NULL),'T', 'display_datefield(&#34;F_MD1_VERBAL&#34;,&#34;md1verbal&#34;
      
       ,&#34;md1verbal2&#34;,&#34;md1verbal3&#34;,&#34;md1verbal4&#34;)'), cattributes=>' width="10%"');
     -- -- ,&#34;md1verbal2&#34;,&#34;md1verbal3&#34;,&#34;md1verbal4&#34;)'), cattributes=>'onClick="javascript:cleardata_att()" width="10%"');
       htp.tablerowclose;
       HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md1verbal" style="display:none" class="datapageLabel"width="29%" '
          --  HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md1verbal" class="datapageLabel"width="29%" '
            
            );
            end if;
--       htp.tablerowopen;
--       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
--      htp.tabledata(hi_common.check_box('F_MD1_VERBAL',NVL(datarow.MD1_VERBAL,NULL),'T', 'display_datefield(&#34;F_MD1_VERBAL&#34;,&#34;md1verbal&#34;
--      ,&#34;md1verbal2&#34;,&#34;md1verbal3&#34;,&#34;md1verbal4&#34;)'), cattributes=>' width="10%"');
--      htp.tablerowclose;
--      
--      HTP.tablerowopen;
--            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '),
--              cattributes => 'id="md1verbal" style="display:none" class="datapageLabel" width="29%"'
--            );
           ------------- 
         ------------- 
          IF datarow.verify_status = 'C'
         THEN
        
            IF datarow.md1_contactid IS NOT NULL
            THEN
               BEGIN
                  SELECT DISTINCT c.contactid,
                         INITCAP (last_name || ', ' || first_name) || ' '
                         || DECODE (c.contact_type,
                                    '0',
                                    c.emp_discipline,
                                    '2',
                                    c.suffix
                            ),
                         DECODE (c.contact_type,
                            '0', 'Employee',
                            'Non Employee')
                  INTO v_doc_contactid_ver, v_doc_name, v_doc_type
                  FROM contacts c, patient_providers pp, domain d
                  WHERE     c.contactid = datarow.md1_contactid
                        AND pp.contactid(+) = c.contactid
                        AND pp.pid(+) = newpid
                        AND pp.intakeid(+) = newintakeid
                        ------
                      /*  AND ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))*/
                        -------------------------
                        AND pp.provider_role = d.rv_low_value(+)
                        AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE';

                  v_doc_cnt    := 0;

                  FOR vtx
                  IN (SELECT null role--d.rv_meaning role
                      FROM domain d, patient_providers pp
                      WHERE     pp.pid = newpid
                            AND pp.intakeid = newintakeid
                            AND pp.contactid = datarow.md1_contactid
                            AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
                            AND d.rv_low_value = pp.provider_role)
                  LOOP
                     IF v_doc_cnt = 0
                     THEN
                        v_doc_name   := v_doc_name ;-- ' ||(';-- || vtx.role;
                     ELSE
                        v_doc_name   := v_doc_name;-- ||', ';-- || vtx.role;
                     END IF;

                     v_doc_cnt   := v_doc_cnt + 1;
                  END LOOP;

                --  v_doc_name   := v_doc_name || ' - ' || v_doc_type || ')';
                  v_doc_name   := v_doc_name || ' - ' || v_doc_type ;
               EXCEPTION
                  WHEN NO_DATA_FOUND
                  THEN
                     NULL;
               END;
            END IF;

            HTP.tabledata (HTF.formtext ('',
                                         LENGTH (v_doc_name),
                                         LENGTH (v_doc_name),
                                         v_doc_name,
                                         cattributes => 'class="blueInput" onFocus="this.blur; alert(&#34;'
                                                       || v_doc_name
                                                       || '&#34;);" '
                           )
                           || HTF.formhidden ('F_MD1_CONTACTID',
                                              datarow.md1_contactid
                              ),
                        cattributes => 'id="md1verbal2"style="display:none" colspan=3'
                         --  cattributes => 'id="md1verbal2" colspan=3'
            );
         ELSE
           
            --HTP.p('<select name="F_MD1_CONTACTID"
       HTP.p ('<td  id="md1verbal2" style="display:none" colspan=3>');
          --  HTP.p ('<td  id="md1verbal2"  colspan=3>');
         --HTP.p('<select name="F_MD1_CONTACTID" ONCHANGE="display_hphy(this.document);" 
         HTP.p('<select name="F_MD1_CONTACTID" ONCHANGE="display_hphy(&#34;F_MD1_CONTACTID&#34;,&#34;h_display2&#34;);"
                                                                                       
            
            onChange="setEmpAttending('
                  || newpid
                  || ','
                  || newintakeid
                  || ');">');
                  --|| ');">this.document.location.reload(); ');
                -- || ');" ONCHANGE="display_hphy(this.document);">');
            HTP.p ('<option value=""></option>');
           

           FOR vtx
            IN (SELECT pp.contactid,
                       INITCAP (last_name || ', ' || first_name) || ' '
                       || DECODE (c.contact_type,
                                  '0',
                                  c.emp_discipline,
                                  '2',
                                  c.suffix
                          )
                       --|| ' ('
                      -- || d.rv_meaning
                       || ' - '
                       || DECODE (c.contact_type,
                             '0', 'Employee',
                             'Non Employee')
                      -- || ')'
                          name,
                       0 AS sorts,
                       last_name
                FROM contacts c, patient_providers pp, domain d
                WHERE      --pp.provider_role IN ('6', '23', '5', '8', '22')
                ------
                        ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))
                        -------------------------
                      AND c.contactid = pp.contactid
                      AND pp.pid = newpid
                      AND pp.intakeid = newintakeid
                      AND (contact_type = 2 OR emp_discipline IN ('MD', 'DO'))
                      AND pp.provider_role = d.rv_low_value
                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
              
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md1_contactid
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
               END IF;
            
            END LOOP;
            
            


            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
       END IF;
      
             HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                       --    cattributes => 'id="md1verbal3" style="display:none" class="datapageLabel" width="29%"'
                           cattributes => 'id="md1verbal3"  class="datapageLabel" width="29%"style="display:none"'
                           );
            
            HTP.tabledata (common.FLEX_DATE_PICKER('F_MD1_VERBAL_DATE',
                                             datarow.md1_verbal_date,
                                             NULL,
                                             NULL,
                                             NULL,
                                             'NO'
                          )
                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD1_VERBAL_DATE&#34;)'
                              ),
                      --  cattributes => 'id="md1verbal4"  align="left" width="70%" style="display:none"'
                         cattributes => 'id="md1verbal4" align="left"  style="display:none"'
            );
           
            HTP.tablerowclose;
            
     end if;
     ----------------------------------------------------------------------------------------------------------------
  htp.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;<u>Signed Certification</u>'), cattributes=>'class="datapageLabel"');
         HTP.tablerowclose;
          --HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Attending Physician Signing Certification: '),
           HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Signature Obtained From: '),
              cattributes => 'class="datapageLabel" width="29%"'
            );

          ------------- 
           IF datarow.verify_status = 'C'
          
         THEN
        -- v_doc_contactid_sig := null;
         --   md1_pp_sig := null;
            IF datarow.md1_contactid_sig IS NOT NULL
            THEN
               BEGIN
                  SELECT DISTINCT c.contactid,
                         INITCAP (last_name || ', ' || first_name) || ' '
                         || DECODE (c.contact_type,
                                    '0',
                                    c.emp_discipline,
                                    '2',
                                    c.suffix
                            ),
                         DECODE (c.contact_type,
                            '0', 'Employee',
                            'Non Employee')
                  INTO v_doc_contactid_sig,v_doc_name_sig, v_doc_type_sig
                  FROM contacts c, patient_providers pp, domain d
                  WHERE     c.contactid = datarow.md1_contactid_sig
                        AND pp.contactid(+) = c.contactid
                        AND pp.pid(+) = newpid
                        AND pp.intakeid(+) = newintakeid
                        ------
                       /* and ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))*/
                         ----------------------------------------
                        AND pp.provider_role = d.rv_low_value(+)
                        AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE';

                 
                  v_doc_cnt    := 0;

                  FOR vtx
                  IN (SELECT null role--d.rv_meaning role
                      FROM domain d, patient_providers pp
                      WHERE     pp.pid = newpid
                            AND pp.intakeid = newintakeid
                            ----------------------------------------
                         AND   ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))
                         -------------------------------------------------------
                            AND pp.contactid = datarow.md1_contactid_sig
                            AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
                            AND d.rv_low_value = pp.provider_role)
                  LOOP
                     IF v_doc_cnt = 0
                     THEN
                        v_doc_name_sig   := v_doc_name_sig;-- || ' (';-- || vtx.role;
                        
                     ELSE
                        v_doc_name_sig   := v_doc_name_sig ;-- || vtx.role;
                     END IF;

                     v_doc_cnt   := v_doc_cnt + 1;
                  END LOOP;

                  --v_doc_name_sig   := v_doc_name_sig || ' - ' || v_doc_type_sig || ')';
                 v_doc_name_sig   := v_doc_name_sig || ' - ' || v_doc_type_sig;
               EXCEPTION
                  WHEN NO_DATA_FOUND
                  THEN
                     NULL;
               END;
            END IF;
           -- HTP.p('<td colspan=2><font color="red">'||md1_pp_sig||'</font></td>');
            HTP.tabledata (HTF.formtext ('',
                                         LENGTH (v_doc_name_sig),
                                         LENGTH (v_doc_name_sig),
                                         v_doc_name_sig,
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;'
                                                       || v_doc_name_sig
                                                       || '&#34;);" '
                           )
                           || HTF.formhidden ('F_MD1_CONTACTID_SIG',
                                             datarow.md1_contactid_sig),
                           cattributes => 'colspan=3 width="70%" '
                            
            );
         ELSE
          
           -- HTP.p ('<td style="display:none" colspan=3 width="70%">');
         HTP.p ('<td colspan=3 width="70%">');
            HTP.p('<select name="F_MD1_CONTACTID_SIG" ONCHANGE="display_hphy(&#34;F_MD1_CONTACTID_SIG&#34;,&#34;h_display2&#34;);"
            onChange="setEmpAttendingSig('
                  || newpid
                  || ','
                  || newintakeid
                  || ');">');
            HTP.p ('<option value=""></option>');

           FOR vtx  IN (
           SELECT pp.contactid,
                       INITCAP (last_name || ', ' || first_name) || ' '
                       || DECODE (c.contact_type,
                                  '0',
                                  c.emp_discipline,
                                  '2',
                                  c.suffix
                          )
                      -- || ' ('
                       --|| d.rv_meaning
                       || ' - '
                       || DECODE (c.contact_type,
                             '0', 'Employee',
                             'Non Employee')
                      -- || ')'
                          name,
                       0 AS sorts,
                       last_name,pp.provider_role
                       --,DECODE (C.emp_discipline,'MD','Y','DO','Y','N')HOSPICE_DR
                FROM contacts c, patient_providers pp, domain d
                WHERE --pp.provider_role IN ('6', '23', '5', '8', '22')
                ------------------------------------------------
                ((sysdate >= TO_DATE('03/01/2010', 'mm/dd/yyyy')
                        and PP.PROVIDER_ROLE = 6)
                         OR (sysdate < TO_DATE('03/01/2010', 'mm/dd/yyyy')))
                         -------------------------------------------
                      AND c.contactid = pp.contactid
                      AND pp.pid = newpid
                      AND pp.intakeid = newintakeid
                      AND (contact_type = 2 OR emp_discipline IN ('MD', 'DO'))
                      AND pp.provider_role = d.rv_low_value
                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
                      ORDER BY sorts, last_name)
            LOOP
              IF vtx.contactid = datarow.md1_contactid_sig
               
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
               END IF;
               
            END LOOP;
    HTP.formselectclose;
            HTP.p ('</td>');
         
            HTP.tablerowclose;
         END IF;
         --------------------------------------------

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=5 border=0 width=100% height=100% '
      );
   HTP.tablerowopen;
     
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Signature Obtained:'),
                           cattributes => 'class="datapageLabel"width="29%"'
                           );
    IF datarow.verify_status = 'C'
         THEN       
   HTP.tabledata (HTF.formtext ('',
                                         F_MD1_SIG_DATE,
                                         F_MD1_SIG_DATE,
                                         to_char(datarow.MD1_SIG_DATE,'dd-Mon-yyyy'),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD1_SIG_DATE',
                                              datarow.MD1_SIG_DATE
                          ),
                                       cattributes => 'colspan=3 width="70%"'
            );
            
            else
   
    HTP.tabledata (common.FLEX_DATE_PICKER('F_MD1_SIG_DATE',
                                                  datarow.MD1_SIG_DATE,
                                              NULL,
                                              NULL,
                                              NULL,
                                             'NO'
                          )
                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD1_SIG_DATE&#34;)'
                              ),
                        
                           cattributes => ' align="left"width="70%"'-- onChange="check_date(this);"'
            );
            
            HTP.tablerowclose; 
            end if; 
                --------------------------------------------------------------------------------------------    
     
         --    HTP.p ('<td colspan=2>'||v_emp_attending||'</td>');
-----------------------------------------------------------------------------------------------------------
            
        --     HTP.p ('<td colspan=2>'||v_hphy||'</td>');
        
HTP.tableclose;
HI_COMMON.FIELDSET_CLOSE;


--START OF TRANSFER NOTIF--
IF v_emp_attending = 'N'  then
HI_COMMON.FIELDSET_OPEN(htf.bold('Hospice Physician'));
HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" id="h_display2"' );
ELSE
HI_COMMON.FIELDSET_OPEN(htf.bold('Hospice Physician'));
HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" id="h_display2"style="display:none"' );
 begin
 update patient_cert_periods
 set md2_contactid = ''
 ,md2_contactid_sig = '',
 md2_verbal_date = ''
 ,md2_sig_date= ''
 ,md2_verbal = '',
 md2_sig = ''
 where pid = newpid
 and intakeid = newintakeid
 and certid = 1;
 exception when others then null;
      end;
      commit;
END IF;

         --physician 2 information
         --if cert is verified (eg, phsycian 2 is already entered) then display a read-only text box
              -----zh
    

          ------------- 
       if datarow.MD2_VERBAL  = 'T' then
       
    IF datarow.verify_status = 'C'
    --HTP.p('||hphy||'); 
    
       THEN   
       --HTP.p ('<td colspan=2>'||hphy||'</td>');
      htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
       htp.tabledata(hi_common.check_box('F_MD2_VERBAL',datarow.MD2_VERBAL,'T'), cattributes=>'DISABLED width="10%"');
      htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel"width="29%" '
            );
         else
         htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
      htp.tabledata(hi_common.check_box('F_MD2_VERBAL',NVL(datarow.MD2_VERBAL,NULL),'T', 'display_datefield1(&#34;F_MD2_VERBAL&#34;,&#34;md2verbal&#34;
       ,&#34;md2verbal2&#34;,&#34;md2verbal3&#34;,&#34;md2verbal4&#34;)'), cattributes=>' width="10%"');
     -- -- ,&#34;md1verbal2&#34;,&#34;md1verbal3&#34;,&#34;md1verbal4&#34;)'), cattributes=>'onClick="javascript:cleardata_att()" width="10%"');
       htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel"width="29%" '
            );
            end if;   
            
     
        IF datarow.verify_status = 'C'
        THEN
            /* HTP.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.tabledata (HTF.formtext ('',
                                         60,
                                         60,
                                         common.user_lookup (datarow.md2_contactid,
                                                             TRUE
                                         ),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_CONTACTID',
                                              datarow.md2_contactid),
                           --cattributes => 'id="md2verbal2"align="left" colspan=2 width="58%"'
                           cattributes => 'id="md2verbal2" colspan=3 width="70%" '
            );
          HTP.tablerowclose;
         ELSE
      
          HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );
            --HTP.p ('<td colspan=2>');
            --HTP.p ('<td  id="md2verbal2" colspan=2 width="58%">');
            HTP.p ('<td  id="md2verbal2"  colspan=3 width="70%" >');
            HTP.p ('<select name="F_MD2_CONTACTID">');
            HTP.p ('<option value=""></option>');

            FOR vtx IN (
               SELECT c.contactid,
                          INITCAP (last_name || ', ' || first_name)
                       || ' '
                       || emp_discipline name,
                       --|| emp_discipline||' (Hospice Physician)' name,
                       1 AS sorts,
                       last_name,pp.provider_role
                FROM contacts c,patient_providers pp, domain d
                WHERE     contact_type(+) = '0'
                      AND c.emp_discipline IN ('MD', 'DO')
                      AND c.status(+) = 'A'
                      and c.contactid = pp.contactid(+)
                      AND pp.pid(+) = newpid
                      AND pp.intakeid(+) = newintakeid
                      AND pp.provider_role = d.rv_low_value(+)
                      AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE'
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md2_contactid
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
                        ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');     
               END IF;
              -- v_doc_contactid_2 := vtx.contactid;
              -- md2_pp_ver := vtx.provider_role;

            END LOOP;
            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
       
             
         END IF;
         
     
            
       IF datarow.verify_status = 'C'
         THEN 
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md2verbal3" class="datapageLabel" width="29%" '
                           );
        
          HTP.tabledata (HTF.formtext ('',
                                         F_MD2_VERBAL_DATE,
                                         F_MD2_VERBAL_DATE,
                                         to_char(datarow.md2_verbal_date,'dd-Mon-yyyy'),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_VERBAL_DATE',
                                              datarow.md2_verbal_date
                          ),
                                       cattributes => 'id="md2verbal4" colspan=3 width="70%"'
            );
          
            else
            
             HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md2verbal3" class="datapageLabel" width="29%" '
                           );
      
      HTP.tabledata (common.flex_date_picker('F_MD2_VERBAL_DATE',
                          datarow.md2_verbal_date,
                          NULL,
                          NULL,
                          NULL,
                          'NO'
                          )
                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD2_VERBAL_DATE&#34;)'
                              ),
                         cattributes => 'id="md2verbal4" align="left" width="70%" class="datapageLabel"'
                           
            );
          
            end if;
            
     else
     
          IF datarow.verify_status = 'C' 
        
       THEN   
      htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
       htp.tabledata(hi_common.check_box('F_MD2_VERBAL',datarow.MD2_VERBAL,'T'), cattributes=>'DISABLED width="10%"');
      htp.tablerowclose;
     --  HTP.tablerowopen;
     --     HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel"width="29%" '
       --    );
         else
         htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
      htp.tabledata(hi_common.check_box('F_MD2_VERBAL',NVL(datarow.MD2_VERBAL,NULL),'T', 'display_datefield1(&#34;F_MD2_VERBAL&#34;,&#34;md2verbal&#34;
       ,&#34;md2verbal2&#34;,&#34;md2verbal3&#34;,&#34;md2verbal4&#34;)'), cattributes=>' width="10%"');
      htp.tablerowclose;
     -- HTP.tablerowopen;
       --   HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel"width="29%" '
       --    );
            end if;
            HTP.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel"width="29%" '
           );
          ------------- 
            IF datarow.verify_status = 'C' --and hphy = 1
         THEN
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.tabledata (HTF.formtext ('',
                                         60,
                                         60,
                                         common.user_lookup (datarow.md2_contactid,
                                                             TRUE
                                         ),
                                         cattributes => 'class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_CONTACTID',
                                              datarow.md2_contactid),
                           cattributes => 'id="md2verbal2" style="display:none" colspan=3 width="70%" '
                           --cattributes => 'id="md2verbal2"align="left" style="display:none" colspan=2 width="58%"'
            );
           -- HTP.tablerowclose;
         ELSE
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            --HTP.p ('<td colspan=2>');
           -- HTP.p ('<td  id="md2verbal2" colspan=2  style="display:none" width="58%">');
            HTP.p ('<td  id="md2verbal2" colspan=3  style="display:none" width="70%" >');
            HTP.p ('<select name="F_MD2_CONTACTID">');
            HTP.p ('<option value=""></option>');

            FOR vtx
            IN (SELECT c.contactid,
                          INITCAP (last_name || ', ' || first_name)
                       || ' '
                       || emp_discipline name,
                       --|| emp_discipline||' (Hospice Physician)' name,
                       1 AS sorts,
                       last_name,provider_role
                FROM contacts c,patient_providers pp, domain d
                WHERE     contact_type(+) = '0'
                      AND c.emp_discipline IN ('MD', 'DO')
                      AND c.status(+) = 'A'
                      and c.contactid = pp.contactid(+)
                      AND pp.pid(+) = newpid
                      AND pp.intakeid(+) = newintakeid
                      AND pp.provider_role = d.rv_low_value(+)
                      AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE'
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md2_contactid
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
              ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
              END IF;
             --  v_doc_contactid_2 := vtx.contactid;
              -- md2_pp_ver := vtx.provider_role;

            END LOOP;

            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
         END IF;

             
             HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md2verbal3"  class="datapageLabel" style="display:none" width="29%"'
                           );
            HTP.tabledata (common.flex_date_picker('F_MD2_VERBAL_DATE',
                                                  datarow.md2_verbal_date,
                                             NULL,
                                             NULL,
                                             NULL,
                                             'NO'
                          )

                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD2_VERBAL_DATE&#34;)'
                              ),
                           --cattributes => 'id="md2verbal4" align="left"style="display:none" width="58%" '
                           cattributes => 'id="md2verbal4" style="display:none" align="left" width="70%"'
            );
            HTP.tablerowclose;
     end if;
     --end if;
     
    
--------------------------------------
         htp.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;<u>Signed Certification</u>'), cattributes=>'class="datapageLabel"');
         HTP.tablerowclose;
         -- HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician Signing Certification: '),
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Signature Obtained From: '),
              cattributes => 'class="datapageLabel" width="29%" '
            );

-------------------------

 ------------- 
            IF datarow.verify_status = 'C' --and hphy = 1
         THEN
            /* HTP.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.tabledata (HTF.formtext ('',
                                         60,
                                         60,
                                         common.user_lookup (datarow.md2_contactid_sig,
                                                             TRUE
                                         ),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_CONTACTID_SIG',
                                              datarow.md2_contactid_sig),
                           --cattributes => 'id="md2verbal2"align="left" colspan=2 width="58%"'
                           cattributes => ' colspan=3 width="70%"'
            );
           -- HTP.formhidden ('F_MD2_PROVIDER_ROLE_SIG',md2_prov_rl_sig );
            --**HTP.tablerowclose;
         ELSE
         
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.p ('<td  colspan=3 width="70%" >');
            HTP.p ('<select name="F_MD2_CONTACTID_SIG">');
            HTP.p ('<option value=""></option>');

            FOR vtx
            IN (SELECT c.contactid,
                          INITCAP (last_name || ', ' || first_name)
                       || ' '
                       || emp_discipline name,
                       --|| emp_discipline||' (Hospice Physician)'name,
                       1 AS sorts,
                       last_name,provider_role
                FROM contacts c,patient_providers pp, domain d
                WHERE     contact_type(+) = '0'
                      AND c.emp_discipline IN ('MD', 'DO')
                      AND c.status(+) = 'A'
                      and c.contactid = pp.contactid(+)
                      AND pp.pid(+) = newpid
                      AND pp.intakeid(+) = newintakeid
                      AND pp.provider_role = d.rv_low_value(+)
                      AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE'
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md2_contactid_sig
               
               THEN
                 HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
                       
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
                       
               END IF;
              -- v_doc_contactid_sig_2 := vtx.contactid;
              -- md2_pp_sig := vtx.provider_role;
   
            END LOOP;

            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
        
             
         END IF;

             
--------------------------
         
             IF datarow.verify_status = 'C'
         THEN 
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Signature Obtained:'),
                           cattributes => 'class="datapageLabel" width="29%" '
                           );
        
          HTP.tabledata (HTF.formtext ('',
                                         F_MD2_SIG_DATE,
                                         F_MD2_SIG_DATE,
                                         to_char(datarow.MD2_SIG_DATE,'dd-Mon-yyyy'),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_SIG_DATE',
                                              datarow.MD2_SIG_DATE
                          ),
                                       cattributes => 'colspan=3 width="70%"'
            );
          
            else
            
             HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Signature Obtained:'),
                           cattributes => ' class="datapageLabel" width="29%" '
                           );
      HTP.tabledata (common.flex_date_picker('F_MD2_SIG_DATE',
                                                  datarow.MD2_SIG_DATE,
                                             NULL,
                                             NULL,
                                             NULL,
                                             'NO'
                          )

                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD2_SIG_DATE&#34;)'
                              ),
                         --  cattributes => ' align="left" width="55%"'
                           cattributes => ' align="left" colspan=3 width="70%" '
            );
          
            end if;
            
            
                         
            HTP.tablerowclose;
         
            
   

     -------------------------------------------------------------------------------------------------------------   
--else if this is not the 1st cert then only display MD 1 information
      ELSE
         
         --physician 1 information
         if datarow.MD2_VERBAL  = 'T' then
         
            --if DATAROW.MD1_CONTACTID is not null then
            HTP.tablerowopen;
            --here
            --issue # 1289- change label by zh 01-05-10
           /* htp.tableData(htf.bold('Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            IF datarow.verify_status = 'C'
       THEN   
      
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
       htp.tabledata(hi_common.check_box('F_MD2_VERBAL',datarow.MD2_VERBAL,'T'), cattributes=>'DISABLED width="10%"');
      htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel"width="29%" '
            );
         else
         htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
         htp.tabledata(hi_common.check_box('F_MD2_VERBAL',NVL(datarow.MD2_VERBAL,NULL),'T', 'display_datefield3(&#34;F_MD2_VERBAL&#34;,&#34;md2verbal&#34;
       ,&#34;md2verbal2&#34;,&#34;md2verbal3&#34;,&#34;md2verbal4&#34;)'), cattributes=>' width="10%"');
      htp.tablerowclose;
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel" '
            );
            ------------- 
        end if; 
        
        IF datarow.verify_status = 'C'
         THEN
            /* HTP.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.tabledata (HTF.formtext ('',
                                         60,
                                         60,
                                         common.user_lookup (datarow.md2_contactid,
                                                             TRUE
                                         ),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_CONTACTID',
                                              datarow.md2_contactid
                          -- || HTF.formhidden ('F_MD2_PROVIDER_ROLE_VER',
                           ---                   datarow.md2_provider_role_ver    
                              ),
                           --cattributes => 'id="md2verbal2"align="left" colspan=2 width="58%"'
                           cattributes => 'id="md2verbal2" colspan=3  '
            );
            --**HTP.tablerowclose;
         ELSE
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            --HTP.p ('<td colspan=2>');
            --HTP.p ('<td  id="md2verbal2" colspan=2 width="58%">');
            HTP.p ('<td  id="md2verbal2" colspan=3  >');
            HTP.p ('<select name="F_MD2_CONTACTID">');
            HTP.p ('<option value=""></option>');

            FOR vtx
            IN (/*SELECT pp.contactid,
                       INITCAP (last_name || ', ' || first_name) || ' '
                       || DECODE (c.contact_type,
                                  '0',
                                  c.emp_discipline,
                                  '2',
                                  c.suffix
                          )
                       || ' ('
                       || d.rv_meaning
                       || ')'
                          name,
                       0 AS sorts,
                       last_name,pp.provider_role
                FROM contacts c, patient_providers pp, domain d
                WHERE     pp.provider_role IN ('6', '23', '5', '8', '22')
                      AND c.contactid = pp.contactid
                      AND pp.pid = newpid
                      AND pp.intakeid = newintakeid
                      AND (contact_type = 2 OR emp_discipline IN ('MD', 'DO'))
                      AND pp.provider_role = d.rv_low_value
                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
                UNION*/
                SELECT contactid,
                          INITCAP (last_name || ', ' || first_name)
                       || ' '
                       || emp_discipline name,
                       --|| emp_discipline||' (Hospice Physician)',
                       1 AS sorts,
                       last_name,null provider_role
                FROM contacts c
                WHERE     contact_type = '0'
                      AND emp_discipline IN ('MD', 'DO')
                      AND status = 'A'
                     /* AND contactid NOT IN
                               (SELECT pp.contactid
                                FROM contacts c,
                                     patient_providers pp,
                                     domain d
                                WHERE contact_type = '0'
                                      AND pp.provider_role IN
                                               ('6', '23', '5', '8', '22')
                                      AND c.contactid = pp.contactid
                                      AND pp.pid = newpid
                                      AND pp.intakeid = newintakeid
                                      AND emp_discipline IN ('MD', 'DO')
                                      AND pp.provider_role = d.rv_low_value
                                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE')*/
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md2_contactid
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
               END IF;
            --   v_doc_contactid_2 := vtx.contactid;
             --  md2_pp_ver := vtx.provider_role;
            END LOOP;

            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
         END IF;

           
       IF datarow.verify_status = 'C'
         THEN 
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md2verbal3" class="datapageLabel" width="29%" '
                           );
        
          HTP.tabledata (HTF.formtext ('',
                                         F_MD2_VERBAL_DATE,
                                         F_MD2_VERBAL_DATE,
                                         to_char(datarow.md2_verbal_date,'dd-Mon-yyyy'),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_VERBAL_DATE',
                                              datarow.md2_verbal_date
                          ),
                                       cattributes => 'id="md2verbal4" colspan=3 width="70%"'
            );
          
            else
            
        HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md2verbal3" class="datapageLabel"'
                           
                           );
            HTP.tabledata (common.flex_date_picker('F_MD2_VERBAL_DATE',
                                                  datarow.md2_verbal_date,
                                          NULL,
                                             NULL,
                                             NULL,
                                             'NO'
                          )

                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD2_VERBAL_DATE&#34;)'
                              ),
                         --  cattributes => 'id="md1verbal4" align="left" width="58%"'
                           cattributes => 'id="md2verbal4" align="left"'
                           
            );
            HTP.tablerowclose;
          
            end if;
            
            
        
        ELSE
         IF datarow.verify_status = 'C'
       THEN   
      htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
       htp.tabledata(hi_common.check_box('F_MD2_VERBAL',datarow.MD1_VERBAL,'T'), cattributes=>'DISABLED width="10%"');
      htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '), cattributes => 'id="md2verbal" class="datapageLabel" style="display:none"'
            );
         else
        htp.tablerowopen;
       htp.tabledata(HTF.bold ('&nbsp;&nbsp;<u>Verbal Certification</u>'), cattributes=>'class="datapageLabel"');
     htp.tabledata(hi_common.check_box('F_MD2_VERBAL',NVL(datarow.MD2_VERBAL,NULL),'T', 'display_datefield3(&#34;F_MD2_VERBAL&#34;,&#34;md2verbal&#34;
     ,&#34;md2verbal2&#34;,&#34;md2verbal3&#34;,&#34;md2verbal4&#34;)'), cattributes=>'width="10%" ');
      htp.tablerowclose;
       HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Verbal Obtained From: '),
              cattributes => 'id="md2verbal" class="datapageLabel" style="display:none"'
           
            );
            end if; 
            
            
          
          ------------- 
           IF datarow.verify_status = 'C'
         THEN
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.tabledata (HTF.formtext ('',
                                         60,
                                         60,
                                         common.user_lookup (datarow.md2_contactid,
                                                             TRUE
                                         ),
                                         cattributes => 'class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_CONTACTID',
                                              datarow.md2_contactid--)
                          -- || HTF.formhidden ('F_MD2_PROVIDER_ROLE_VER',
                           --                   datarow.md2_provider_role_ver    
                              ),
                           cattributes => 'id="md2verbal2" style="display:none" colspan=3  '
                           --cattributes => 'id="md2verbal2"align="left" style="display:none" colspan=2 width="58%"'
            );
           -- HTP.tablerowclose;
         ELSE
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            --HTP.p ('<td colspan=2>');
           -- HTP.p ('<td  id="md2verbal2" colspan=2  style="display:none" width="58%">');
            HTP.p ('<td  id="md2verbal2" colspan=3  style="display:none" >');
            HTP.p ('<select name="F_MD2_CONTACTID">');
            HTP.p ('<option value=""></option>');

            FOR vtx
            IN (SELECT c.contactid,
                          INITCAP (last_name || ', ' || first_name)
                       || ' '
                       || emp_discipline name,
                       --|| emp_discipline||' (Hospice Physician)' name,
                       1 AS sorts,
                       last_name
                FROM contacts c,patient_providers pp, domain d
                WHERE     contact_type(+) = '0'
                      AND c.emp_discipline IN ('MD', 'DO')
                      AND c.status(+) = 'A'
                      and c.contactid = pp.contactid(+)
                      AND pp.pid(+) = newpid
                      AND pp.intakeid(+) = newintakeid
                      AND pp.provider_role = d.rv_low_value(+)
                      AND d.rv_domain(+) = 'PATIENT_PROVIDER_ROLE'
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md2_contactid
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
               END IF;
             --  v_doc_contactid_2 := vtx.contactid;
             --  md2_pp_ver := vtx.provider_role;
            END LOOP;

            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
         END IF;

             
             
         ---here   
        HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Verbal Obtained:'),
                           cattributes => 'id="md2verbal3" class="datapageLabel" style="display:none"'
                           );
            HTP.tabledata (common.flex_date_picker('F_MD2_VERBAL_DATE',
                                                  datarow.md2_verbal_date,
                                          NULL,
                                             NULL,
                                             NULL,
                                             'NO'
                          )
                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD2_VERBAL_DATE&#34;)'
                              ),
                        --  cattributes => 'id="md1verbal4"  align="left" width="58%"'
                          cattributes => 'id="md2verbal4" align="left" style="display:none"'
                          
            );
            HTP.tablerowclose;
            --------------------------------------

       END IF;  

  htp.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;<u>Signed Certification</u>'), cattributes=>'class="datapageLabel"');
         HTP.tablerowclose;
         -- HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician Signing Certification: '),
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Signature Obtained From: '),
              cattributes => 'class="datapageLabel" '
            );

-------------------------

 ------------- 
            IF datarow.verify_status = 'C'
         THEN
            /* HTP.tablerowopen;
          HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            HTP.tabledata (HTF.formtext ('',
                                         60,
                                         60,
                                         common.user_lookup (datarow.md2_contactid_sig,
                                                             TRUE
                                         ),
                                         cattributes => 'class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_CONTACTID_SIG',
                                              datarow.md2_contactid_sig--)
                           --|| HTF.formhidden ('F_MD2_PROVIDER_ROLE_SIG',
                           --                   datarow.md2_provider_role_sig    
                              ),
                           --cattributes => 'id="md2verbal2"align="left" colspan=2 width="58%"'
                           cattributes => ' colspan=3 width="72%"'
            );
            --**HTP.tablerowclose;
         ELSE
           /* HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Hospice Physician: '),
                           cattributes => 'class="datapageLabel"'
            );*/
            --HTP.p ('<td colspan=2>');
            --HTP.p ('<td  id="md2verbal2" colspan=2 width="58%">');
            HTP.p ('<td  colspan=3 width="72%" >');
            HTP.p ('<select name="F_MD2_CONTACTID_SIG">');
            HTP.p ('<option value=""></option>');

            FOR vtx
            IN (
            /*SELECT pp.contactid,
                       INITCAP (last_name || ', ' || first_name) || ' '
                       || DECODE (c.contact_type,
                                  '0',
                                  c.emp_discipline,
                                  '2',
                                  c.suffix
                          )
                       || ' ('
                       || d.rv_meaning
                       || ')'
                          name,
                       0 AS sorts,
                       last_name,pp.provider_role
                FROM contacts c, patient_providers pp, domain d
                WHERE     pp.provider_role IN ('6', '23', '5', '8', '22')
                      AND c.contactid = pp.contactid
                      AND pp.pid = newpid
                      AND pp.intakeid = newintakeid
                      AND (contact_type = 2 OR emp_discipline IN ('MD', 'DO'))
                      AND pp.provider_role = d.rv_low_value
                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE'
                UNION*/
                SELECT contactid,
                          INITCAP (last_name || ', ' || first_name)
                       || ' '
                       || emp_discipline name,
                       --|| emp_discipline||' (Hospice Physician)',
                       1 AS sorts,
                       last_name, null provider_role
                FROM contacts c
                WHERE     contact_type = '0'
                      AND emp_discipline IN ('MD', 'DO')
                      AND status = 'A'
                     /* AND contactid NOT IN
                               (SELECT pp.contactid
                                FROM contacts c,
                                     patient_providers pp,
                                     domain d
                                WHERE contact_type = '0'
                                      AND pp.provider_role IN
                                               ('6', '23', '5', '8', '22')
                                      AND c.contactid = pp.contactid
                                      AND pp.pid = newpid
                                      AND pp.intakeid = newintakeid
                                      AND emp_discipline IN ('MD', 'DO')
                                      AND pp.provider_role = d.rv_low_value
                                      AND d.rv_domain = 'PATIENT_PROVIDER_ROLE')*/
                ORDER BY sorts, last_name)
            LOOP
               IF vtx.contactid = datarow.md2_contactid_sig
               THEN
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '" selected>'
                        || vtx.name
                        || '</option>');
               ELSE
                  HTP.p(   '<OPTION VALUE="'
                        || vtx.contactid
                        || '">'
                        || vtx.name
                        || '</option>');
               END IF;
              --  v_doc_contactid_2 := vtx.contactid;
              -- md2_pp_sig := vtx.provider_role;
            END LOOP;

            HTP.formselectclose;
            HTP.p ('</td>');
            HTP.tablerowclose;
         END IF;

             
--------------------------
         
             IF datarow.verify_status = 'C'
         THEN 
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Signature Obtained:'),
                           cattributes => 'class="datapageLabel" width="29%" '
                           );
        
          HTP.tabledata (HTF.formtext ('',
                                         F_MD2_SIG_DATE,
                                         F_MD2_SIG_DATE,
                                         to_char(datarow.MD2_SIG_DATE,'dd-Mon-yyyy'),
                                         cattributes => 'readonly class="blueInput" onFocus="this.blur; alert(&#34;This field is read-only&#34;);" '
                           )
                           || HTF.formhidden ('F_MD2_SIG_DATE',
                                              datarow.MD2_SIG_DATE
                          ),
                                       cattributes => 'colspan=3 width="70%"'
            );
          
            else
            
             
           HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('&nbsp;&nbsp;&nbsp;&nbsp;Date Signature Obtained:'),
                           cattributes => 'class="datapageLabel"'
                           );
            HTP.tabledata (common.flex_date_picker('F_MD2_SIG_DATE',
                                                  datarow.MD2_SIG_DATE,
                                          NULL,
                                             NULL,
                                             NULL,
                                             'NO'
                          )
                           || '&nbsp'
                           || ui.make_button ('&nbsp;',
                                              '15',
                                              'stamp_date(&#34;F_MD2_SIG_DATE&#34;)'
                              ),
                         --  cattributes => ' align="left" width="55%"'
                           cattributes => ' align="left" colspan=3 width="72%" '
            );
           
            HTP.tablerowclose;
            -----------------------------
 end if;
             
      END IF;

      --end of check for whether 1st cert
      ---zh
     

     --htp.tablerowclose;
    htp.tableclose;
   ------
      hi_common.fieldset_close;
     HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '  );

      IF datarow.verify_status = 'C' AND verify_cert = FALSE
      THEN
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Verified Status:'),
                        cattributes => ' class="datapageLabel" '
         );
         HTP.tabledata ('Verified');
         HTP.tablerowclose;
         HTP.formhidden ('F_VERIFY_STATUS', datarow.verify_status);
      ELSIF verify_cert = TRUE
      THEN
         HTP.tablerowopen;
         HTP.tabledata (HTF.bold ('Verified Status:'),
                        cattributes => 'width="30%" class="datapageLabel" '
         );
         HTP.tabledata(common.coderefoptions ('F_VERIFY_STATUS',
                                              'CERT_VERIF_STATUS',
                                              NVL (datarow.verify_status, 'P'
                                              ),
                                              userrow.orgid
                       ));
         HTP.tablerowclose;
      ELSE
         HTP.tablerowopen;
         HTP.tabledata(HTF.formhidden ('F_VERIFY_STATUS',
                                       datarow.verify_status
                       ));
         HTP.tablerowclose;
      END IF;

      HTP.tablerowopen;
      HTP.tabledata (HTF.underline (HTF.bold ('Certification Notes')),
                     cattributes => 'height="25" valign="bottom" colspan=2 class="datapageLabel" '
      );
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.formtextareaopen2 ('F_NOTES',
                                            10,
                                            10,
                                            'LEFT',
                                            'SOFT',
                                            cattributes => 'style="height:75px; width:100%;"'
                     )
                     || NVL (datarow.notes, NULL)
                     || HTF.formtextareaclose,
                     cattributes => 'colspan=3'
      );
      HTP.tablerowclose;

      HTP.tableclose;

   hi_common.fieldset_close;
   
      

      HTP.PRINT ('</TD>');
      HTP.tablerowclose;
      HTP.tableclose;
    
      ui.section_close_blue('&nbsp;'
                            || common.audit_msg (datarow.moduser,
                                                 datarow.moddate
                               ));

      HTP.PRINT (INSTR);
      HTP.formclose;
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END cert_edit;


 PROCEDURE patient_lmrp_list (f_pid IN varchar2:= NULL,
                                f_intakeid IN varchar2:= NULL,
                                f_browser_area IN varchar2:= NULL,
                                f_viewmode IN varchar2:= 'expand',
                                f_status IN varchar2:= 'A'
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newviewmode   VARCHAR2 (30) := NVL (f_viewmode, 'expand');
      --NEWSTAT           VARCHAR2(30) := NVL(F_STATUS,'%');
      INSTR         VARCHAR2 (1000);
      datarow       patient_lmrp%ROWTYPE;
      userrow       user_details%ROWTYPE;

      CURSOR datacur
      IS
         SELECT *
         FROM patient_lmrp
         WHERE pid = newpid AND intakeid = newintakeid
         ORDER BY status;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Patient Benefit Periods');
      ui.css;
      --COMMON.JSCRIPT_LIBRARIES;
      HTP.script ('
function lmrp_edit(pid,inid,lmrpid) {
  var wtitle;
  var mwindow;
  mwindow = "patient_browser_elig_pkg.lmrp_edit?f_pid="+pid+"$f_intakeid="+inid+"$f_lmrpid="+lmrpid;
  if (pid > "0") {
      wtitle  = "LMRP Details";
      vReturnValue = window.showModalDialog("common.modal_window?wtitle="+wtitle+"&wurl="+mwindow,window,"center:yes;status:no;help:no;dialogHeight:425px;dialogWidth:700px");
  } else {
      alert("Please save this record before attempting to transfer this patient.");
  }
}
',
                  'JavaScript'
      );
      HTP.headclose;
      HTP.bodyopen (cattributes => 'topmargin="0" leftmargin="0" rightmargin="0" bgcolor="#EAEEEF" '
      );
      HTP.formopen (' PATIENT_BROWSER_ELIG_PKG.PATIENT_LMRP_LIST');
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_VIEWMODE', newviewmode);
      --HTP.FORMHIDDEN('F_DME_STATUS',NEWSTAT);

      HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=4 border=0 '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<td valign="top">');

      HTP.tableopen (cattributes => ' width=100% cellspacing=0 cellpadding=2 border=0'
      );
      HTP.tablerowopen;
      HTP.tabledata (HTF.underline (HTF.bold ('Patient LMRPs')),
                     cattributes => 'height="25" valign="top" class="datapageHeader"'
      );
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata(HTF.anchor2 (   'javascript:lmrp_edit('
                                 || newpid
                                 || ','
                                 || newintakeid
                                 || ',0);this.document.location.reload();',
                                 'Change LMRP',
                                 cattributes => 'class="blueLinkLine"'
                    )
                    || ' | '
                    || HTF.anchor2 ('patient_browser_elig_pkg.patient_browser_team?f_pid='
                                    || newpid
                                    || '&f_intakeid='
                                    || newintakeid
                                    || '&f_viewmode=collapse',
                                    'Collapse',
                                    cattributes => 'class="blueLinkLine"'
                       ));
      --htf.anchor2('patient_browser_pkg.patient_browser_dme?f_pid='||NEWPID||'&f_intakeid='||NEWINTAKEID||'&f_dme_status=D','Discontinued', cattributes=>'class="blueLinkLine"'));
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.br;

      IF f_viewmode = 'collapse'
      THEN
         FOR rec IN datacur
         LOOP
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
            );
            HTP.tablerowopen;
            HTP.tabledata ('<font color="white">'
                           || HTF.bold(common.coderef (rec.disease_group,
                                                       'LMRP_DISEASE_GROUP'
                                       ))
                           || '</font>',
                           cattributes => 'bgcolor="#6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata ('&nbsp;', cattributes => 'bgcolor="#6487DC" ');
            HTP.tablerowclose;
            HTP.tableclose;
            HTP.br;
         END LOOP;
      ELSE
         FOR rec IN datacur
         LOOP
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
            );
            HTP.tablerowopen;
            HTP.tabledata ('<font color="white">'
                           || HTF.bold(common.coderef (rec.disease_group,
                                                       'LMRP_DISEASE_GROUP'
                                       ))
                           || '</font>',
                           cattributes => 'bgcolor="#6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata ('&nbsp;', cattributes => 'bgcolor="#6487DC" ');
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.PRINT ('<TD bgcolor="white">');
            HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=0 '
            );

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('diagnosis: '),
                           cattributes => 'class="datapageLabel" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (common.icd_lookup (rec.diagnosis),
                           cattributes => ' colspan=2 style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('icd code: '),
                           cattributes => 'class="datapageLabel" height="30" style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tabledata (rec.diagnosis,
                           cattributes => ' style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('start: '),
                           cattributes => 'class="datapageLabel" width="30%" height="30" style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tabledata (NVL (TO_CHAR (rec.start_date, 'MM/DD/YYYY'),
                                '&nbsp;'
                           ),
                           cattributes => ' style="border-bottom: 1px solid #6487DC"'
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('end: '),
                           cattributes => 'class="datapageLabel"  height="30" style="border-bottom: 1px solid #6487DC" '
            );
            HTP.tabledata (NVL (TO_CHAR (rec.end_date, 'MM/DD/YYYY'),
                                '&nbsp;'
                           ),
                           cattributes => ' style="border-bottom: 1px solid #6487DC" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('status: '),
                           cattributes => 'class="datapageLabel" height="30" '
            );

            IF rec.status = 'A'
            THEN
               HTP.tabledata ('Active');
            ELSE
               HTP.tabledata ('Inactive');
            END IF;

            HTP.tablerowclose;

            HTP.tableclose;

            HTP.PRINT ('</TD>');
            HTP.tablerowclose;
            HTP.tableclose;
            HTP.br;
         END LOOP;
      END IF;

      HTP.PRINT ('</td>');
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.PRINT (INSTR);
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_lmrp_list;


   PROCEDURE patient_lmrp_edit (recstatus IN varchar2:= NULL,
                                f_pid IN varchar2:= NULL,
                                f_intakeid IN varchar2:= NULL,
                                f_lmrpid IN varchar2:= NULL,
                                f_disease_group IN varchar2:= NULL,
                                f_diagnosis IN varchar2:= NULL,
                                f_diagnosis_disp IN varchar2:= NULL,
                                f_start_date IN varchar2:= NULL,
                                f_end_date IN varchar2:= NULL,
                                f_status IN varchar2:= NULL,
                                f_current_lmrp IN varchar2:= NULL,
                                f_md_contactid IN varchar2:= NULL,
                                f_md_contactid_disp IN varchar2:= NULL,
                                f_md_contactid_sig IN varchar2:= NULL,
                                f_md_userid IN varchar2:= NULL,
                                f_md_userid_sig IN varchar2:= NULL
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newlmrpid     VARCHAR2 (30) := f_lmrpid;
      datarow       patient_lmrp%ROWTYPE;
      userrow       user_details%ROWTYPE;
      name          VARCHAR2 (100);
      INSTR         VARCHAR2 (1000);

      CURSOR datacur
      IS
         SELECT *
         FROM patient_lmrp
         WHERE pid = newpid AND intakeid = newintakeid AND lmrpid = newlmrpid;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      IF recstatus IS NOT NULL
      THEN
         BEGIN
            --FIRST DO CHECK AND ENSURE THAT AT LEAST ONE RECORD AND ONLY ONE RECORD IS SET AS THE PRIMARY LMRP--
            --IF UPPER(F_CURRENT_LMRP) = 'T' THEN
            --SELECT COUNT(*) INTO DPRIMARY FROM PATIENT_ADV_DIRECTIVES WHERE PID=NEWPID AND INTAKEID=NEWINTAKEID AND PRIMARY_DIRECTIVE='T';
            --IF DPRIMARY > 1 THEN
            UPDATE patient_lmrp
            SET current_lmrp = 'F', status = 'I'
            WHERE pid = newpid AND intakeid = newintakeid;

            --END IF;
            --END IF;
            -- COMMIT;

            IF recstatus = 'update'
            THEN
               UPDATE patient_lmrp
               SET disease_group      = f_disease_group,
                   diagnosis          = f_diagnosis,
                   start_date         = f_start_date,
                   end_date           = f_end_date,
                   status             = f_status,
                   current_lmrp       = f_current_lmrp,
                   md_contactid       = f_md_contactid,
                   md_contactid_sig   = f_md_contactid_sig,
                   md_userid          = f_md_userid,
                   md_userid_sig      = f_md_userid_sig,
                   moduser            = userrow.contactid,
                   moddate            = SYSDATE
               WHERE     pid = newpid
                     AND intakeid = newintakeid
                     AND lmrpid = newlmrpid;

               --    COMMIT;
               INSTR   := HTF.script ('top.window.close();', 'JavaScript');
            ELSIF recstatus = 'insert'
            THEN
               SELECT NVL (MAX (lmrpid), 0) + 1
               INTO newlmrpid
               FROM patient_lmrp
               WHERE pid = newpid AND intakeid = newintakeid;

               INSERT INTO patient_lmrp
              (
                  orgid,
                  pid,
                  intakeid,
                  lmrpid,
                  disease_group,
                  diagnosis,
                  start_date,
                  end_date,
                  status,
                  current_lmrp,
                  md_contactid,
                  md_contactid_sig,
                  md_userid,
                  md_userid_sig,
                  createuser,
                  createdate
              )
               VALUES (
                         userrow.orgid,
                         newpid,
                         newintakeid,
                         newlmrpid,
                         f_disease_group,
                         f_diagnosis,
                         f_start_date,
                         f_end_date,
                         f_status,
                         f_current_lmrp,
                         f_md_contactid,
                         f_md_contactid_sig,
                         f_md_userid,
                         f_md_userid_sig,
                         userrow.contactid,
                         SYSDATE
                      );

               --    COMMIT;
               INSTR   := HTF.script ('top.window.close();', 'JavaScript');
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               hi_common.error_handler;
         END;
      END IF;

      FOR rec IN datacur
      LOOP
         datarow   := rec;
      END LOOP;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('LMRP Details');
      ui.css;
      common.jscript_libraries;
      HTP.script ('
function save_form() {
  var efrm = document.forms[0];
  validate();
  if (returnVal) {
     efrm.submit();
  }
}
function init() {
  define("F_DISEASE_GROUP", "string", "Disease Group");
  define("F_DIAGNOSIS", "string", "Related Diagnosis");
  define("F_START_DATE", "string", "Start Date");
}
function stamp_date(datefld) {
  var frm = this.document.forms[0];
  var thisdate = "'
                  || TO_CHAR (SYSDATE, 'DD-Mon-YYYY')
                  || '";
  var dfield = eval("this.document.forms[0]."+datefld);
  dfield.value = thisdate;
}
function open_icdsearch(dispfld,idfld,frm) {
   center_open("utilities_pkg.icd_picklist_header?display="+dispfld+"&id="+idfld+"&fname="+frm,"icdsearchwin","450","400","false");
}
function open_contactsearch(dispfld,idfld,frm) {
   center_open("utilities_pkg.contact_search_header?display="+dispfld+"&id="+idfld+"&fname="+frm,"mdsearchwin","450","400","false");
}
function refresh_notes() {
  var frm = this.document.forms[0];
  var pid = frm.F_PID.value;
  var inid = frm.F_INTAKEID.value;
  var certid = frm.F_CERTID.value;
  notesframe.document.location="utilities_pkg.patient_notes_list?f_pid="+pid+"&f_intakeid="+inid+"&f_note_context=CT&f_note_fk="+certid;
}
function note_edit(pid,inid,nid,context,id) {
  var wtitle;
  var mwindow;
  mwindow = "utilities_pkg.patient_notes_newnote?f_pid="+pid+"$f_intakeid="+inid+"$f_noteid="+nid+"$f_note_context="+context+"$f_note_fk="+id;
  if (id > "0") {
      wtitle  = "Patient Certification Note";
      vReturnValue = window.showModalDialog("common.modal_window?wtitle="+wtitle+"&wurl="+mwindow,window,"center:yes;status:no;help:no;dialogHeight:500px;dialogWidth:700px");
  } else {
      alert("Please save this record before creating a new note.");
  }
}
',
                  'JavaScript'
      );
      HTP.headclose;
      HTP.bodyopen (cattributes => 'onLoad="init();" TOPMARGIN="5" LEFTMARGIN="5" bgcolor="#FFFFFF" '
      );
      HTP.formopen ('PATIENT_BROWSER_ELIG_PKG.PAITENT_LMRP_EDIT',
                    cattributes => 'name="mainfrm"'
      );
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_LMRPID', newlmrpid);

      IF newlmrpid = 0
      THEN
         HTP.formhidden ('recstatus', 'insert');
      ELSE
         HTP.formhidden ('recstatus', 'update');
      END IF;

      ui.section_open_blue (   'Patient LMRP Details '
                            || HTF.bold ('&raquo;')
                            || '&nbsp;'
                            || common.patient_lookup (newpid, TRUE),
                            ui.make_blubutton ('Save and Close',
                                               '150',
                                               'save_form();'
                            )
                            || '&nbsp;'
      );

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=5 border=0 width=100% height=100% '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<TD valign=top>');

      hi_common.fieldset_open (HTF.bold ('LMRP Details'));

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% '
      );

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('LMRP Disease Group:'),
                     cattributes => 'width="25%" class="datapageLabel"'
      );
      HTP.tabledata(common.coderefoptions ('F_DISEASE_GROUP',
                                           'LMRP_DISEASE_GROUP',
                                           NVL (datarow.disease_group, NULL),
                                           userrow.orgid
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Diagnosis:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(HTF.formtext ('F_DIAGNOSIS_DISP',
                                  25,
                                  50,
                                  common.icd_lookup (datarow.diagnosis),
                                  cattributes => 'onClick="javascript:open_icdsearch(&#34;F_DIAGNOSIS_DISP&#34;,&#34;F_DIAGNOSIS&#34;,&#34;mainfrm&#34;);"'
                    )
                    || '&nbsp;'
                    || ui.make_button ('&nbsp;',
                                       '15',
                                       'open_icdsearch(&#34;F_DIAGNOSIS_DISP&#34;,&#34;F_DIAGNOSIS&#34;,&#34;mainfrm&#34;)'
                       ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('ICD Code:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(HTF.formtext ('F_DIAGNOSIS',
                                  25,
                                  50,
                                  datarow.diagnosis,
                                  cattributes => 'onFocus="this.blur(); alert(&#34;This code value is read-only.&#34;);"'
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Start Date:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(hi_common.date_picker ('F_START_DATE', datarow.start_date
                    )
                    || '&nbsp'
                    || ui.make_button ('&nbsp;',
                                       '15',
                                       'stamp_date(&#34;F_START_DATE&#34;)'
                       ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('End Date:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(hi_common.date_picker ('F_END_DATE', datarow.end_date)
                    || '&nbsp'
                    || ui.make_button ('&nbsp;',
                                       '15',
                                       'stamp_date(&#34;F_END_DATE&#34;)'
                       ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('LMRP Status:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(common.coderefoptions ('F_STATUS',
                                           'LMRP_STATUS',
                                           NVL (datarow.status, 'A'),
                                           userrow.orgid
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Primary LMRP:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(hi_common.check_box ('F_CURRENT_LMRP',
                                         NVL (datarow.current_lmrp, NULL),
                                         'T'
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Outside Physician:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(HTF.formtext ('F_MD_CONTACTID_DISP',
                                  25,
                                  50,
                                  common.get_contact_form_lu(datarow.md_contactid),
                                  cattributes => 'onClick="javascript:open_contactsearch(&#34;F_MD_CONTACTID_DISP&#34;,&#34;F_MD_CONTACTID&#34;,&#34;mainfrm&#34;);"'
                    )
                    || HTF.formhidden ('F_MD_CONTACTID', datarow.md_contactid
                       )
                    || '&nbsp;'
                    || ui.make_button ('&nbsp;',
                                       '15',
                                       'open_contactsearch(&#34;F_MD_CONTACTID_DISP&#34;,&#34;F_MD_CONTACTID&#34;,&#34;mainfrm&#34;)'
                       ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Signature Obtained:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(hi_common.check_box ('F_MD_CONTACTID_SIG',
                                         NVL (datarow.md_contactid_sig, NULL),
                                         'T'
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Hospice Physician:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(common.useroptions ('F_MD_USERID',
                                        NVL (datarow.md_userid, NULL),
                                        userrow.orgid
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Signature Obtained:'),
                     cattributes => 'class="datapageLabel"'
      );
      HTP.tabledata(hi_common.check_box ('F_MD_USERID_SIG',
                                         NVL (datarow.md_userid_sig, NULL),
                                         'T'
                    ));
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.br;

      hi_common.fieldset_close;

      HTP.PRINT ('</TD>');
      HTP.tablerowclose;
      HTP.tableclose;

      ui.section_close_blue('&nbsp;'
                            || common.audit_msg (datarow.moduser,
                                                 datarow.moddate
                               ));

      HTP.PRINT (INSTR);
      HTP.formclose;
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_lmrp_edit;


   PROCEDURE patient_provider_list (f_pid IN varchar2:= NULL,
                                    f_intakeid IN varchar2:= NULL,
                                    f_viewmode IN varchar2:= 'expand',
                                    recstatus IN varchar2:= NULL
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newviewmode   VARCHAR2 (30) := NVL (f_viewmode, 'expand');
      INSTR         VARCHAR2 (1000);
      datarow       patient_providers%ROWTYPE;
      userrow       user_details%ROWTYPE;
      v_specialty   VARCHAR2 (200);                   -- issue 914 v_specialty

      CURSOR datacur
      IS
         SELECT a.pid,
                a.intakeid,
                a.provid,
                a.contactid,
                a.provider_role,
                a.status,
                b.first_name,
                b.last_name,
                b.company_name,
                b.contact_type,
                b.display_mode,
                b.suffix,
                b.emp_phone_work,
                b.emp_phone_mobile,
                b.emp_phone_pager,
                c.phone1_type,
                c.phone1,
                c.phone2_type,
                c.phone2,
                c.phone3_type,
                c.phone3,
                c.phone4_type,
                c.phone4
         FROM patient_providers a, contacts b, contacts_address c
         WHERE     a.contactid = b.contactid
               AND a.contactid = c.contactid(+)
               AND 'T' = c.addr_primary(+)
               AND a.pid = newpid
               AND a.intakeid = newintakeid
         --and   a.provider_role in (6,7,8)
         ORDER BY a.status;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Patient Provider List');
      ui.css;
      --COMMON.JSCRIPT_LIBRARIES;
      HTP.script ('
function center_open(mypage,myname,h,w,scroll){
   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
   settings =''height=''+h+'',width=''+w+'',top=''+TopPosition+'',left=''+LeftPosition+'',scrollbars=''+scroll+'',resizable''
   win = window.open(mypage,myname,settings)
}
function open_providerbuilder(pid,inid) {
  if (pid > "0" || inid > "0") {
      center_open("utilities_pkg.select_providers_header?f_pid="+pid+"&f_intakeid="+inid+"&openerContext=PIB","buildprovwin","475","500","false");
  } else {
     alert("Please save this patient record prior to opening this window.");
  }
}
function edit_provider(pid,inid,provid) {
  var wtitle;
  var mwindow;
  mwindow = "patient_browser_elig_pkg.patient_provider_edit?f_pid="+pid+"$f_intakeid="+inid+"$f_provid="+provid;
  if (pid > "0") {
      wtitle  = "Edit Patient Provider";
      vReturnValue = window.showModalDialog("common.modal_window?wtitle="+wtitle+"&wurl="+mwindow,window,"center:yes;status:no;help:no;dialogHeight:425px;dialogWidth:700px");
  } else {
      alert("Please save this record before attempting to edit this record.");
  }
}
function delete_provider(pid,inid,provid) {
    if (confirm("Are you sure you want to delete this patient provider? This cannot be undone.")) {
      this.saveframe.document.location="patient_browser_elig_pkg.patient_provider_save?recstatus=DELETE&f_pid="+pid+"&f_intakeid="+inid+"&f_provid="+provid;
  }
}
function contact_details(cid,ronly) {
  center_open("CONTACTS_PKG.CONTACT_MAIN?CID="+cid+"&READONLY="+ronly,"contactwin","600","800","false");
}
',
                  'JavaScript'
      );
      HTP.headclose;
      HTP.bodyopen (cattributes => 'topmargin="0" leftmargin="0" rightmargin="0" bgcolor="#EAEEEF" '
      );
      HTP.formopen (' PATIENT_BROWSER_ELIG_PKG.PATIENT_PROVIDER_LIST');
      --HTP.FORMHIDDEN('F_PID',NEWPID);
      --HTP.FORMHIDDEN('F_INTAKEID',NEWINTAKEID);
      HTP.formhidden ('F_VIEWMODE', newviewmode);
      HTP.formhidden ('RECSTATUS', 'INSERT');

      HTP.PRINT('<iframe name="saveframe" style="display:none" src="ui.blank"></iframe>');

      HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=4 border=0 '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<td valign="top">');

      HTP.tableopen (cattributes => ' width=100% cellspacing=0 cellpadding=2 border=0'
      );
      HTP.tablerowopen;
      HTP.tabledata (HTF.underline (HTF.bold ('Patient Providers')),
                     cattributes => 'height="25" valign="top" class="datapageHeader"'
      );
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata(HTF.anchor2 (   'javascript:edit_provider('
                                 || newpid
                                 || ','
                                 || newintakeid
                                 || ',0);this.document.location.reload();',
                                 'New Provider',
                                 cattributes => 'class="blueLinkLine"'
                    ));
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.br;

      -- IF F_VIEWMODE='collapse' THEN
      --   FOR REC IN DATACUR LOOP
      --   htp.tableopen(cattributes=>' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"');
      --      htp.tableRowOpen;
      --     htp.tabledata('<font color="white">'||htf.bold(REC.ORDER_ITEM)||'</font>', cattributes=>'bgcolor="#6487DC"');
      --     htp.tableRowClose;
      --   htp.tableclose;
      --   htp.br;
      --   END LOOP;
      -- ELSE
      FOR rec IN datacur
      LOOP
         HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=1 bordercolor="#6487DC"'
         );
         HTP.tablerowopen;
         HTP.tabledata ('<font color="white">'
                        || HTF.bold(   common.get_contact (rec.contactid)
                                    || ', '
                                    || rec.suffix)
                        || '</font>',
                        cattributes => 'bgcolor="#6487DC"'
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         -- Modified By RMK - 11/08/2006 - Support Issue Track 342
         -- Add new parameter to call contract_details when selecting 'all detail',
         -- sets the view to be Read Only
         HTP.tabledata ('<font color="white">'
                        || HTF.anchor2 (   'javascript:edit_provider('
                                        || rec.pid
                                        || ','
                                        || rec.intakeid
                                        || ','
                                        || rec.provid
                                        || ');this.document.location.reload();',
                                        'edit',
                                        cattributes => 'class="whitelink"'
                           )
                        || '&nbsp;|&nbsp;'
                        || HTF.anchor2 (   'javascript:delete_provider('
                                        || rec.pid
                                        || ','
                                        || rec.intakeid
                                        || ','
                                        || rec.provid
                                        || ');',
                                        'delete',
                                        cattributes => 'class="whitelink"'
                           )
                        || '&nbsp;|&nbsp;'
                        || HTF.anchor2 (   'javascript:contact_details('
                                        || rec.contactid
                                        || ',&#34;T&#34;);',
                                        'all details',
                                        cattributes => 'class="whitelink"'
                           )
                        || '</font>',
                        cattributes => 'bgcolor="#6487DC" '
         );
         HTP.tablerowclose;

         HTP.tablerowopen;
         HTP.PRINT ('<TD bgcolor="white">');
         HTP.tableopen (cattributes => ' width="100%" cellspacing=0 cellpadding=2 border=0 '
         );

         --IF THE PROVIDER IS AN EMP THEN DISPLAY EMP PHONES FROM THE CONTACTS TABLE, OTHERWISE SHOW THE PHONES FROM THE ADDRESS TABLE
         BEGIN                         -- issue 914 get specialty if populated
            SELECT '<br>' || rv_meaning
            INTO v_specialty
            FROM contacts c, domain d
            WHERE     c.specialty = d.rv_low_value
                  AND d.rv_domain = 'SPECIALTY'
                  AND c.contactid = rec.contactid;
         EXCEPTION
            WHEN OTHERS
            THEN
               v_specialty   := NULL;
         END;

         IF rec.contact_type = 0
         THEN
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('provider: '),
                           cattributes => 'width="40%" class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
            );
            -- issue 914 v_specialty
            HTP.tabledata (common.get_contact (rec.contactid) || v_specialty,
                           cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
            );
            HTP.tablerowclose;
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('role: '),
                           cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
            );

            IF rec.provider_role IS NULL
            THEN
               HTP.tabledata ('<font color="red">Not Assigned</font>',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
            ELSE
               HTP.tabledata (common.coderef (rec.provider_role,
                                              'PATIENT_PROVIDER_ROLE',
                                              userrow.orgid
                              ),
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
            END IF;

            IF rec.status = 'I'
            THEN
               HTP.tablerowopen;
               HTP.tabledata (HTF.bold ('status: '),
                              cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tabledata ('<font color="Red">Inactive</font>',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tablerowclose;
            END IF;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('work: '),
                           cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
            );
            HTP.tabledata (NVL (rec.emp_phone_work, 'Not found'),
                           cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('mobile: '),
                           cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
            );
            HTP.tabledata (NVL (rec.emp_phone_mobile, 'Not found'),
                           cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('pager: '),
                           cattributes => 'class="datapageLabel" height="30" '
            );
            HTP.tabledata (NVL (rec.emp_phone_pager, 'Not found'),
                           cattributes => ' height="30" '
            );
            HTP.tablerowclose;
         --IF THE PROVIDER IS NOT AN EMP THEN DISPLAY THE PHONES FROM THE ADDRESS TABLE FOR THE PRIMARY ADDRESS
         ELSE
            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('provider: '),
                           cattributes => 'width="40%" class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
            );
            -- issue 914 v_specialty
            HTP.tabledata (common.get_contact (rec.contactid) || v_specialty,
                           cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
            );
            HTP.tablerowclose;

            HTP.tablerowopen;
            HTP.tabledata (HTF.bold ('role: '),
                           cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
            );

            IF rec.provider_role IS NULL
            THEN
               HTP.tabledata ('<font color="red">Not Assigned</font>',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
            ELSE
               HTP.tabledata (common.coderef (rec.provider_role,
                                              'PATIENT_PROVIDER_ROLE',
                                              userrow.orgid
                              ),
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
            END IF;

            HTP.tablerowclose;

            --IF THERE ARE NO PHONES THEN DONT PUT THE BORDER ON THE BOTTOM OF THE ROW
            --if rec.phone1 is null and rec.phone2 is null and rec.phone3 is null and rec.phone4 is null then
            IF rec.status = 'I'
            THEN
               HTP.tablerowopen;
               HTP.tabledata (HTF.bold ('status: '),
                              cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tabledata ('<font color="Red">Inactive</font>',
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tablerowclose;
            END IF;

            --end if;

            IF rec.phone1 IS NOT NULL AND rec.phone1_type IS NOT NULL
            THEN
               HTP.tablerowopen;
               HTP.tabledata (HTF.bold(common.coderef (rec.phone1_type,
                                                       'PHONE_TYPE',
                                                       userrow.orgid
                                       )
                                       || ': '),
                              cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tabledata (rec.phone1,
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tablerowclose;
            END IF;

            IF rec.phone2 IS NOT NULL AND rec.phone2_type IS NOT NULL
            THEN
               HTP.tablerowopen;
               HTP.tabledata (HTF.bold(common.coderef (rec.phone2_type,
                                                       'PHONE_TYPE',
                                                       userrow.orgid
                                       )
                                       || ': '),
                              cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tabledata (rec.phone2,
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tablerowclose;
            END IF;

            IF rec.phone3 IS NOT NULL AND rec.phone3_type IS NOT NULL
            THEN
               HTP.tablerowopen;
               HTP.tabledata (HTF.bold(common.coderef (rec.phone3_type,
                                                       'PHONE_TYPE',
                                                       userrow.orgid
                                       )
                                       || ': '),
                              cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tabledata (rec.phone3,
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tablerowclose;
            END IF;

            IF rec.phone4 IS NOT NULL AND rec.phone4_type IS NOT NULL
            THEN
               HTP.tablerowopen;
               HTP.tabledata (HTF.bold(common.coderef (rec.phone4_type,
                                                       'PHONE_TYPE',
                                                       userrow.orgid
                                       )
                                       || ': '),
                              cattributes => 'class="datapageLabel" style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tabledata (rec.phone4,
                              cattributes => ' style="border-bottom: 1px solid #6487DC" height="30" '
               );
               HTP.tablerowclose;
            END IF;
         END IF;

         HTP.tablerowclose;

         HTP.tableclose;

         HTP.PRINT ('</TD>');
         HTP.tablerowclose;
         HTP.tableclose;
         HTP.br;
      END LOOP;

      --END IF;

      HTP.PRINT ('</td>');
      HTP.tablerowclose;
      HTP.tableclose;

      HTP.br;

      HTP.PRINT (INSTR);
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_provider_list;


   PROCEDURE patient_provider_save (recstatus IN varchar2:= NULL,
                                    f_pid IN varchar2:= NULL,
                                    f_intakeid IN varchar2:= NULL,
                                    f_provid IN varchar2:= NULL
   )
   IS
      newpid        VARCHAR2 (30) := f_pid;
      newintakeid   VARCHAR2 (30) := f_intakeid;
      newprovid     VARCHAR2 (30) := f_provid;
      INSTR         VARCHAR2 (1000);
      userrow       user_details%ROWTYPE;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      IF recstatus IS NOT NULL
      THEN
         BEGIN
            IF recstatus = 'DELETE'
            THEN
               DELETE FROM patient_providers
               WHERE     pid = newpid
                     AND intakeid = newintakeid
                     AND provid = newprovid;

               --  COMMIT;
               INSTR   := HTF.script ('delete_notif();', 'JavaScript');
            END IF;
         EXCEPTION
            WHEN OTHERS
            THEN
               hi_common.error_handler;
         END;
      END IF;

      HTP.htmlopen;
      HTP.headopen;
      HTP.script ('
function delete_notif() {
  //alert("This record was successfully deleted.");
  parent.document.location.reload();
}
',
                  'JavaScript'
      );
      HTP.PRINT (INSTR);
      HTP.headclose;
      HTP.bodyopen;
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_provider_save;


   PROCEDURE patient_provider_edit (recstatus IN varchar2:= NULL,
                                    f_pid IN varchar2:= NULL,
                                    f_intakeid IN varchar2:= NULL,
                                    f_provid IN varchar2:= NULL,
                                    f_contactid_disp IN varchar2:= NULL,
                                    f_contactid IN varchar2:= NULL,
                                    f_provider_role IN varchar2:= NULL,
                                    f_status IN varchar2:= NULL
   )
   IS
      newpid          VARCHAR2 (30) := f_pid;
      newintakeid     VARCHAR2 (30) := f_intakeid;
      newprovid       VARCHAR2 (30) := f_provid;
      INSTR           VARCHAR2 (1000);
      datarow         patient_providers%ROWTYPE;
      userrow         user_details%ROWTYPE;

      CURSOR datacur
      IS
         SELECT *
         FROM patient_providers
         WHERE pid = newpid AND intakeid = newintakeid AND provid = newprovid;

      prev_provider   VARCHAR2 (150);
      v_role          VARCHAR2 (100);
      justanumber     NUMBER;
   BEGIN
      SELECT *
      INTO userrow
      FROM user_details;

      IF recstatus IS NOT NULL
      THEN
         IF f_provider_role IN ('7', '8', '26', '19', '12')
         THEN
            BEGIN
               DELETE FROM patient_providers
               WHERE     pid = f_pid
                     AND intakeid = f_intakeid
                     AND provid <> f_provid
                     AND provider_role = f_provider_role;
            EXCEPTION
               WHEN OTHERS
               THEN
                  NULL;
            END;
         ELSIF f_provider_role = '6'
         THEN
            UPDATE patient_providers
            SET status    = 'I'
            WHERE     provider_role = '6'
                  AND pid = f_pid
                  AND intakeid = f_intakeid
                  AND provid <> f_provid;
         -- Issue 1055 begin
         ELSIF f_provider_role = '18'
         THEN
            UPDATE patient_providers
            SET status    = 'I'
            WHERE     provider_role = '18'
                  AND pid = f_pid
                  AND intakeid = f_intakeid
                  AND provid <> f_provid;
         ELSIF f_provider_role = '28'
         THEN
            UPDATE patient_providers
            SET status    = 'I'
            WHERE     provider_role = '28'
                  AND pid = f_pid
                  AND intakeid = f_intakeid
                  AND provid <> f_provid;
         -- Issue 1055 end
         END IF;

         BEGIN
            SELECT pid
            INTO justanumber
            FROM patient_providers
            WHERE pid = f_pid AND intakeid = f_intakeid AND provid = f_provid;

            UPDATE patient_providers
            SET contactid       = f_contactid,
                provider_role   = f_provider_role,
                status          = f_status,
                moduser         = userrow.contactid,
                moddate         = SYSDATE
            WHERE     pid = newpid
                  AND intakeid = newintakeid
                  AND provid = newprovid;
         EXCEPTION
            WHEN NO_DATA_FOUND
            THEN
               SELECT NVL (MAX (provid), 0) + 1
               INTO newprovid
               FROM patient_providers
               WHERE pid = newpid AND intakeid = newintakeid;

               INSERT INTO patient_providers
              (
                  orgid,
                  pid,
                  intakeid,
                  provid,
                  contactid,
                  provider_role,
                  start_date,
                  status,
                  createuser,
                  createdate
              )
               VALUES (
                         userrow.orgid,
                         newpid,
                         newintakeid,
                         newprovid,
                         f_contactid,
                         f_provider_role,
                         SYSDATE,
                         f_status,
                         userrow.contactid,
                         SYSDATE
                      );
         END;

         INSTR   := HTF.script ('top.window.close();', 'JavaScript');
      END IF;

      FOR rec IN datacur
      LOOP
         datarow   := rec;
      END LOOP;

      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('Provider Edit');
      ui.css;
      common.jscript_libraries;
      HTP.script ('

function save_form() {
  var frm = document.forms[0];
  if (ckForm()) {
     frm.submit();
  }
}

function ckForm() {
  frm = document.forms[0];
  idx = frm.F_PROVIDER_ROLE.selectedIndex;
  role = frm.F_PROVIDER_ROLE.options(idx).text;
  if ( role == "" ) {
    alert("Provider Role is required.");
    frm.F_PROVIDER_ROLE.focus();
    return false;
    }
  return true;


}


function init() {
  define("F_CONTACTID", "string", "Patient Provider");
}
function open_contactsearch(dispfld,idfld,frm) {
    center_open("utilities_pkg.select_providers_header?openerContext=PIB","buildprovwin","475","500","false");
  //center_open("utilities_pkg.contact_search_header?display_field="+dispfld+"&id_field="+idfld+"&frmname="+frm,"mdsearchwin","475","500","false");
}
function center_open(mypage,myname,h,w,scroll){
   LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
   TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
   settings =''height=''+h+'',width=''+w+'',top=''+TopPosition+'',left=''+LeftPosition+'',scrollbars=''+scroll+'',resizable''
   win = window.open(mypage,myname,settings)
}
',
                  'JavaScript'
      );
      HTP.headclose;
      HTP.bodyopen (cattributes => 'onLoad="init();" TOPMARGIN="5" LEFTMARGIN="5" bgcolor="#FFFFFF" '
      );
      HTP.formopen ('PATIENT_BROWSER_ELIG_PKG.PATIENT_PROVIDER_EDIT',
                    cattributes => 'name="mainfrm"'
      );
      HTP.formhidden ('F_PID', newpid);
      HTP.formhidden ('F_INTAKEID', newintakeid);
      HTP.formhidden ('F_PROVID', newprovid);

      --htp.p('boo '||v_referral_doc);
      IF newprovid = 0
      THEN
         HTP.formhidden ('recstatus', 'insert');
      ELSE
         HTP.formhidden ('recstatus', 'update');
      END IF;

      ui.section_open_blue (   'Provider Edit '
                            || HTF.bold ('&raquo;')
                            || '&nbsp;'
                            || common.patient_lookup (newpid, TRUE),
                            ui.make_blubutton ('Save and Close',
                                               '120',
                                               'save_form();'
                            )
                            || '&nbsp;'
      );

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=5 border=0 width=100% height=100% '
      );
      HTP.tablerowopen;
      HTP.PRINT ('<TD valign=top>');

      hi_common.fieldset_open (HTF.bold ('Patient Provider Details'));

      HTP.tableopen (cattributes => ' cellspacing=0 cellpadding=2 border=0 width=100% bgcolor="#EAEEEF" '
      );
      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Provider:'),
                     cattributes => 'width="30%" class="datapageLabel" '
      );
      HTP.tabledata(HTF.formtext ('F_CONTACTID_DISP',
                                  35,
                                  50,
                                  common.get_all_contacts (datarow.contactid),
                                  cattributes => 'onClick="javascript:open_contactsearch(&#34;F_CONTACTID_DISP&#34;,&#34;F_CONTACTID&#34;,&#34;mainfrm&#34;);"'
                    )
                    || HTF.formhidden ('F_CONTACTID', datarow.contactid)
                    || '&nbsp;'
                    || ui.make_button ('&nbsp;',
                                       '15',
                                       'open_contactsearch(&#34;F_CONTACTID_DISP&#34;,&#34;F_CONTACTID&#34;,&#34;mainfrm&#34;);'
                       ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Provider Role:'),
                     cattributes => 'class="datapageLabel" '
      );
      HTP.tabledata(common.coderefoptions ('F_PROVIDER_ROLE',
                                           'PATIENT_PROVIDER_ROLE',
                                           NVL (datarow.provider_role, NULL),
                                           userrow.orgid
                    ));
      HTP.tablerowclose;

      HTP.tablerowopen;
      HTP.tabledata (HTF.bold ('Provider Status:'),
                     cattributes => 'class="datapageLabel" '
      );
      HTP.tabledata(common.coderefoptions ('F_STATUS',
                                           'PATIENT_PROVIDER_STATUS',
                                           NVL (datarow.status, 'A'),
                                           userrow.orgid
                    ));
      HTP.tablerowclose;
      HTP.tableclose;

      hi_common.fieldset_close;

      HTP.PRINT ('</TD>');
      HTP.tablerowclose;
      HTP.tableclose;

      ui.section_close_blue('&nbsp;'
                            || common.audit_msg (datarow.moduser,
                                                 datarow.moddate
                               ));

      HTP.PRINT (INSTR);
      HTP.formclose;
      HTP.bodyclose;
      HTP.htmlclose;
   EXCEPTION
      WHEN OTHERS
      THEN
         hi_common.error_handler;
   END patient_provider_edit;

   PROCEDURE set_emp_attending (p_contactid IN varchar2:= NULL,
                                p_pid IN varchar2:= NULL,
                                p_intakeid IN varchar2:= NULL
   )
   IS
      v_emp_attending   VARCHAR2 (2);
      INSTR             VARCHAR2 (2000);
   BEGIN
      HTP.htmlopen;
      HTP.headopen;
      HTP.title ('');

      HTP.script ('
      function returnY() {
           parent.document.forms[0].f_emp_attending.value = "Y";
           //alert("now is "+parent.document.forms[0].f_emp_attending.value);
      }
       function returnN() {
           parent.document.forms[0].f_emp_attending.value = "N";
           //alert("now is "+parent.document.forms[0].f_emp_attending.value);
      }



   ',
                  'JavaScript'
      );

      HTP.headclose;

      SELECT get_emp_attending (p_contactid, p_pid, p_intakeid)
      INTO v_emp_attending
      FROM DUAL;

      IF v_emp_attending = 'Y'
      THEN
         INSTR   := HTF.script ('returnY();', 'JavaScript');
      ELSE
         INSTR   := HTF.script ('returnN();', 'JavaScript');
      END IF;

      HTP.PRINT (INSTR);
      --HTP.FORMCLOSE;
      --HTP.BODYCLOSE;
      HTP.htmlclose;
   END set_emp_attending;

   FUNCTION get_emp_attending (p_contactid IN varchar2:= NULL,
                               p_pid IN varchar2:= NULL,
                               p_intakeid IN varchar2:= NULL
   )
      RETURN VARCHAR2
   IS
      v_emp_attending   VARCHAR2 (2) := 'N';
   BEGIN
      BEGIN
         SELECT 'Y'
         INTO v_emp_attending
         FROM contacts c, patient_providers pp
         WHERE     pp.provider_role = '6'           --attending physician role
               AND c.contactid = p_contactid
               AND c.contactid = pp.contactid
               AND pp.pid = p_pid
               AND pp.intakeid = p_intakeid
               AND contact_type = '0'                      -- employee contact
               AND emp_discipline IN ('MD', 'DO');       -- physician employee

         RETURN 'Y';
      EXCEPTION
         WHEN OTHERS
         THEN
            RETURN 'N';
      END;
   /*
     begin
       select case when pp.provider_role = '6' and c.contact_type = '0' then
                        'Y'
                   else 'N'
               end into v_emp_attending
        from contacts c, patient_providers pp, domain d
       where pp.provider_role = '6' --pp.provider_role in ('6', '23', '5','8','22')
         and c.contactid = p_contactid
         and c.contactid = pp.contactid
         and pp.pid = p_pid
         and pp.intakeid = p_intakeid
         and (contact_type = 2 or emp_discipline in ('MD', 'DO'))
         and pp.provider_role = d.rv_low_value
         and d.rv_domain = 'PATIENT_PROVIDER_ROLE';
     exception when others then null;
     end;
     --v_emp_attending := 'X';
     return v_emp_attending;
   */
   END get_emp_attending;
END patient_browser_elig_pkg;
/

Open in new window

Zee75Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HonorGodSoftware EngineerCommented:
You have some syntax errors.

if ("'||newcertid||'" > 0 && "'||edit_adt_data||'" == TRUE ) {

In this

"'||newcertid||'"        Is a text string
and
 0                           Is a number
and
"'||edit_adt_data||'"  Is another text string
and
TRUE                       Is a variable


What is the comparison of the string to a number supposed to do?

This expression (simplified) should be something like this:

if ( ( value1 > value2 ) && ( value3 == value4 ) ) {
  // Then clause
} else {
  // else clause
}

Does this help?
0
Zee75Author Commented:
HonorGod:
"'||newcertid||'"        Is a number declared in the beginning of procedure.
("'||newcertid||'" > 0 - this expression actually function properly.

I get error message with the following expression
"'||edit_adt_data||'" == TRUE
"'||edit_adt_data||'"  is declared as a boolean in the procedure.

Is there a certain way I need to call a boolean variable in a javascript function?
0
HonorGodSoftware EngineerCommented:
JavaScript uses a value of 0 to represent "false", and any non-zero as "true"
Normally one would use 0 for false, and 1 for true

How is "'||newcertid||'"  interpreted as a number?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Zee75Author Commented:
"'||newcertid||'" IS ALWAYS GREATER THAN 0 IF PATIENT HAS A CERT RECORD.
0
Zee75Author Commented:
I can not even put variable in an alert to view value. I get that same error message...
alert("'edit_adt_data||'");
Any suggestions?
0
HonorGodSoftware EngineerCommented:
> "'||newcertid||'" IS ALWAYS GREATER THAN 0 IF PATIENT HAS A CERT RECORD.

  I still don't know how "'||newcertid||'" is interpreted as anything other than a string.

> alert("'edit_adt_data||'");

  What do you see?  A dialog box with the text?

'edit_adt_data||'

If so, that would indicate that the string is not being recognized as anything other than a string.
0
Zee75Author Commented:
alert("'||edit_adt_data||'");

  What do you see?  -  Package do not compile. Do not get a dialog box. Get error message
PLS-00306: wrong number or types of arguments in call to '||'

How would I test a boolean in a javascript function? edit_adt_data(boolean)
0
HonorGodSoftware EngineerCommented:
> Package do not compile.

  Interesting.

  I wonder if the presence of the nested quotes is what is causing this problem.
Instead of this:

"'||edit_adt_data||'"

try this instead:

'\'||edit_adt_data||\''

Look for all instances of a double quote within your strings.  I think that is what is causing the compilation to fail.

0
Zee75Author Commented:
Did you mean  -  ''\||edit_adt_data||\''  ?

If so, I get an error message....."Unterminated String contstant"

Is there a way to pass boolean type from PL/SQL to javascript?
0
HonorGodSoftware EngineerCommented:
> Is there a way to pass boolean type from PL/SQL to javascript?

  Use a value of 0 for false, and 1 for true.

> Did you mean  -  ''\||edit_adt_data||\''  ?

  I was trying to have a single quote, followed by an escaped single quote (i.e., backslash quote) followed by the value.

  Now, I'm thinking that when you have double quote followed by a single quote, the single quote may be the terminating quote, so what you might need instead is:

\"'||edit_adt_data||'\''

Which is:

backslash double quote
single quote
two vertical bars
variable name
two vertical bars
single quote
backslash double quote
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Zee75Author Commented:
Just passED a zero and did not try to pass a boolean.
0
HonorGodSoftware EngineerCommented:
Thanks for the grade & points.

Sorry you only thought it worth a B.

Good luck & have a great day.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.