Index: cprs/trunk/CPRS-Chart/Consults/fConsults.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Consults/fConsults.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/Consults/fConsults.pas	(revision 829)
@@ -1,4 +1,8 @@
 unit fConsults;
-
+{Notes of Intent:
+  Tab Order:
+    The tab order has been custom coded to place the pnlRight in the Tab order
+    right after the tvConsults.  
+}
 
 interface
@@ -7,5 +11,6 @@
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ORDtTm,
   fHSplit, stdCtrls, ExtCtrls, Menus, ComCtrls, ORCtrls, ORFn, uConsults, rOrders, uPCE,
-  ORClasses, uConst, fDrawers, rTIU, uTIU, uDocTree, RichEdit, fPrintList;
+  ORClasses, uConst, fDrawers, rTIU, uTIU, uDocTree, RichEdit, fPrintList,
+  VA508AccessibilityManager, fBase508Form, VA508ImageListLabeler;
 
 type
@@ -172,4 +177,7 @@
     mnuViewRemoteData: TMenuItem;
     mnuViewPostings: TMenuItem;
+    imgLblNotes: TVA508ImageListLabeler;
+    imgLblImages: TVA508ImageListLabeler;
+    imgLblConsults: TVA508ImageListLabeler;
     procedure mnuChartTabClick(Sender: TObject);
     procedure lstConsultsClick(Sender: TObject);
@@ -268,16 +276,15 @@
     procedure popNoteMemoPreviewClick(Sender: TObject);
     procedure popNoteMemoInsTemplateClick(Sender: TObject);
-    procedure tvConsultsAddition(Sender: TObject; Node: TTreeNode);
-    procedure tvConsultsDeletion(Sender: TObject; Node: TTreeNode);
     procedure tvConsultsExit(Sender: TObject);
-    procedure pnlResultsExit(Sender: TObject);
-    procedure pnlActionExit(Sender: TObject);
     procedure FormHide(Sender: TObject);
     procedure FormShow(Sender: TObject);
-    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
-      Y: Integer);
     procedure ViewInfo(Sender: TObject);
     procedure mnuViewInformationClick(Sender: TObject);
+    procedure pnlLeftExit(Sender: TObject);
+    procedure pnlRightExit(Sender: TObject);
+    procedure cmdEditResubmitExit(Sender: TObject);
+    procedure cmdNewConsultExit(Sender: TObject);
   private
+    FocusToRightPanel : Boolean;
     FEditingIndex: Integer;      // TIU index of document being currently edited
     FChanged: Boolean;
@@ -300,12 +307,7 @@
     FNotifPending: boolean;
     FOldFramePnlPatientExit: TNotifyEvent;
-    FOldDrawerPnlTemplatesButtonExit: TNotifyEvent;
-    FOldDrawerPnlEncounterButtonExit: TNotifyEvent;
-    FOldDrawerEdtSearchExit: TNotifyEvent;
-    FMousing: TDateTime;
+    //FMousing: TDateTime;
+    procedure DoLeftPanelCustomShiftTab;
     procedure frmFramePnlPatientExit(Sender: TObject);
-    procedure frmDrawerPnlTemplatesButtonExit(Sender: TObject);
-    procedure frmDrawerPnlEncounterButtonExit(Sender: TObject);
-    procedure frmDrawerEdtSearchExit(Sender: TObject);
     procedure DoAutoSave(Suppress: integer = 1);
     function GetTitleText(AnIndex: Integer): string;
@@ -395,5 +397,5 @@
      fReminderDialog, uReminders, fConsMedRslt, fTemplateFieldEditor,
      dShared, rTemplates, fIconLegend, fNoteIDParents, fNoteCPFields,
-     uTemplates,  uAccessibleTreeView, uAccessibleTreeNode, fTemplateDialog, DateUtils;
+     uTemplates, fTemplateDialog, DateUtils, uVA508CPRSCompatibility, VA508AccessibilityRouter;
 
 const
@@ -906,5 +908,5 @@
       DocInfo := MakeXMLParamTIU(IntToStr(CreatedNote.IEN), FEditNote);
       ExecuteTemplateOrBoilerPlate(TmpBoilerPlate, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-      memResults.Lines.Assign(TmpBoilerPlate);
+      QuickCopyWith508Msg(TmpBoilerPlate, memResults);
       TmpBoilerPlate.Free;
     end;
@@ -1107,5 +1109,5 @@
       DocInfo := MakeXMLParamTIU(IntToStr(lstNotes.ItemIEN), FEditNote);
       ExecuteTemplateOrBoilerPlate(TmpBoilerPlate, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-      memResults.Lines.Assign(TmpBoilerPlate);
+      QuickCopyWith508Msg(TmpBoilerPlate, memResults);
       TmpBoilerPlate.Free;
     end;
@@ -1221,4 +1223,13 @@
 
 { Form events -----------------------------------------------------------------}
+
+procedure TfrmConsults.pnlRightExit(Sender: TObject);
+begin
+  inherited;
+  if TabIsPressed then
+    FindNextControl(tvConsults, True, True, False).SetFocus
+  else if ShiftTabIsPressed then
+    FindNextControl(pnlLeft, True, True, False).SetFocus;
+end;
 
 procedure TfrmConsults.pnlRightResize(Sender: TObject);
@@ -1383,4 +1394,11 @@
 end;
 
+procedure TfrmConsults.cmdNewConsultExit(Sender: TObject);
+begin
+  inherited;
+  if Not cmdEditResubmit.Visible then
+    DoLeftPanelCustomShiftTab;
+end;
+
 procedure TfrmConsults.cmdNewProcClick(Sender: TObject);
 begin
@@ -2338,5 +2356,5 @@
          mnuActPrintSF513.Enabled     :=  True;
          mnuActConsultResults.Enabled :=  (lstConsults.ItemIEN > 0) and
-                                          (((UserLevel = UL_UPDATE) or (UserLevel = UL_UPDATE_AND_ADMIN)) and
+                                          (((UserLevel = UL_UPDATE) or (UserLevel = UL_UPDATE_AND_ADMIN) or (UserLevel = UL_UNRESTRICTED)) and
                                           ((status<>ST_DISCONTINUED) and
                                            (status<>ST_CANCELLED)))
@@ -2365,5 +2383,6 @@
   mnuActComplete.Enabled           :=   mnuActConsultResults.Enabled and
                                         ((MenuAccessRec.UserLevel = UL_UPDATE) or
-                                        (MenuAccessRec.UserLevel = UL_UPDATE_AND_ADMIN))
+                                        (MenuAccessRec.UserLevel = UL_UPDATE_AND_ADMIN) or
+                                        (MenuAccessRec.UserLevel = UL_UNRESTRICTED))
                                         and
                                        ((ConsultRec.ORStatus=ST_PENDING) or
@@ -2374,5 +2393,6 @@
   mnuActMakeAddendum.Enabled       :=  mnuActConsultResults.Enabled and
                                         ((MenuAccessRec.UserLevel = UL_UPDATE) or
-                                        (MenuAccessRec.UserLevel = UL_UPDATE_AND_ADMIN))
+                                        (MenuAccessRec.UserLevel = UL_UPDATE_AND_ADMIN) or
+                                        (MenuAccessRec.UserLevel = UL_UNRESTRICTED))
                                         and
                                         (ConsultRec.ORStatus=ST_COMPLETE) and
@@ -2631,7 +2651,9 @@
        if Copy(Piece(lstNotes.ItemID, ';', 2), 1, 4)= 'MCAR' then
          begin
-           memConsult.Lines.Assign(GetDetailedMedicineResults(lstNotes.ItemID));
+           QuickCopy(GetDetailedMedicineResults(lstNotes.ItemID), memConsult);
            x := Piece(Piece(Piece(lstNotes.ItemID, ';', 2), '(', 2), ',', 1) + ';' + Piece(lstNotes.ItemID, ';', 1);
-           NotifyOtherApps(NAE_REPORT, 'MED^' + x);
+           x := 'MED^' + x;
+           SetPiece(x, U, 10, Piece(lstNotes.Items[lstNotes.ItemIndex], U, 11));
+           NotifyOtherApps(NAE_REPORT, x);
          end
        else
@@ -2640,5 +2662,7 @@
            mnuActChange.Enabled     := False;
            mnuActLoadBoiler.Enabled := False;
-           NotifyOtherApps(NAE_REPORT, 'TIU^' + lstNotes.ItemID);
+           x := 'TIU^' + lstNotes.ItemID;
+           SetPiece(x, U, 10, Piece(lstNotes.Items[lstNotes.ItemIndex], U, 11));
+           NotifyOtherApps(NAE_REPORT, x);
          end;
        memConsult.SelStart := 0;
@@ -2814,4 +2838,5 @@
 end;
 
+{for printing multiple notes}
 procedure TfrmConsults.RequestMultiplePrint(AForm: TfrmPrintList);
 var
@@ -2819,20 +2844,13 @@
   i: integer;
 begin
-  inherited;
   with AForm.lbIDParents do
-  begin
-    for i := 0 to Items.Count - 1 do
-     begin
-       if Selected[i] then
-        begin
-         NoteIEN := StrToInt64def(Piece(TStringList(Items.Objects[i])[0],U,1),0);
-         if NoteIEN > 0 then PrintSF513(NoteIEN, DisplayText[i]) else
-          begin
-           if NoteIEN = 0 then InfoBox(TX_NOCONSULT, TX_NOCSLT_CAP, MB_OK);
-           if NoteIEN < 0 then InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
-          end;
-        end; {if selected}
-     end; {for}
-  end; {with}
+  for i := 0 to Items.Count - 1 do
+  if Selected[i] then
+  begin
+    NoteIEN := StrToInt64def(Piece(Items[i], U, 1), 0);
+    if NoteIEN > 0 then PrintSF513(NoteIEN, DisplayText[i])
+    else if NoteIEN = 0 then InfoBox(TX_NOCONSULT, TX_NOCSLT_CAP, MB_OK)
+    else InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
+  end;
 end;
 
@@ -2852,4 +2870,6 @@
   memConsult.SelStart := 0;
   SetResultMenus;
+  if memConsult.CanFocus then
+    memConsult.SetFocus;
 end;
 
@@ -2883,15 +2903,24 @@
   LimitEditWidth(memResults, MAX_ENTRY_WIDTH - 1);
   memResults.Constraints.MinWidth := TextWidthByFont(memResults.Font.Handle, StringOfChar('X', MAX_ENTRY_WIDTH)) + (LEFT_MARGIN * 2) + ScrollBarWidth;
-  pnlLeft.Width := self.ClientWidth - pnlResults.Width - sptHorz.Width;
+  //CQ13181	508 Consults--Splitter bar doesn't retain size
+ //CQ13181  pnlLeft.Width := self.ClientWidth - pnlResults.Width - sptHorz.Width;
 end;
 
 procedure TfrmConsults.NotifyOrder(OrderAction: Integer; AnOrder: TOrder);
+var
+  SavedCsltID: string;
 begin
   if ViewContext = 0 then exit;     // form has not yet been displayed, so nothing to update
   if EditingIndex <> -1 then exit;  // do not rebuild list until after save
+  with tvConsults do if Selected <> nil then SavedCsltID := lstConsults.ItemID;
   case OrderAction of
   ORDER_NEW:  UpdateList ;
   ORDER_SIGN: UpdateList{ sent by fReview, fOrderSign when orders signed, AnOrder=nil}
   end;
+  if SavedCsltID <> '' then with tvConsults do
+  begin
+    Selected := FindPieceNode(SavedCsltID, U, Items.GetFirstNode);
+    tvConsultsChange(Self, Selected);
+  end;
 end;
 
@@ -2925,8 +2954,6 @@
 begin
   inherited;
+  FocusToRightPanel := False;
   PageID := CT_CONSULTS;
-  memConsult.Color := ReadOnlyColor;
-  memPCEShow.Color := ReadOnlyColor;
-  lblNewTitle.Color := ReadOnlyColor;
   EditingIndex := -1;
   FLastNoteID := '';
@@ -2940,7 +2967,4 @@
   frmDrawers.Splitter := splDrawers;
   frmDrawers.DefTempPiece := 2;
-  tvCsltNotes.Images := dmodShared.imgNotes;
-  tvCsltNotes.StateImages := dmodShared.imgImages;
-  tvConsults.Images := dmodShared.imgConsults;
   FImageFlag := TBitmap.Create;
   FDocList := TStringList.Create;
@@ -2952,5 +2976,4 @@
     end;
   FCsltList := TStringList.Create;
-  TAccessibleTreeView.WrapControl(tvConsults);
 end;
 
@@ -2968,4 +2991,6 @@
   tvConsultsChange(Self, tvConsults.Selected);
   //lstConsultsClick(Self);
+  if memConsult.CanFocus then
+    memConsult.SetFocus;
 end;
 
@@ -3255,4 +3280,10 @@
 end;
 
+procedure TfrmConsults.cmdEditResubmitExit(Sender: TObject);
+begin
+  inherited;
+  DoLeftPanelCustomShiftTab;
+end;
+
 procedure TfrmConsults.mnuViewSaveAsDefaultClick(Sender: TObject);
 begin
@@ -3291,4 +3322,17 @@
   inherited;
   EditTemplates(Self, True);
+end;
+
+procedure TfrmConsults.pnlLeftExit(Sender: TObject);
+begin
+  inherited;
+  if (Not FocusToRightPanel) then
+    if ShiftTabIsPressed then
+      frmFrame.tabPage.SetFocus
+    else if TabIsPressed then
+      frmFrame.pnlPatient.SetFocus;
+
+  if FocusToRightPanel then
+    FocusToRightPanel := False;
 end;
 
@@ -3387,5 +3431,4 @@
 procedure TfrmConsults.FormDestroy(Sender: TObject);
 begin
-  TAccessibleTreeView.UnwrapControl(tvConsults);
   FDocList.Free;
   FCsltList.Free;
@@ -3578,5 +3621,5 @@
     if (DocType = TYP_ADDENDUM) then
     begin
-      if AskCosignerForDocument(Addend, Author) and (Cosigner <= 0) then Result := True;
+      if AskCosignerForDocument(Addend, Author, DateTime) and (Cosigner <= 0) then Result := True;
     end else
     begin
@@ -3695,4 +3738,5 @@
   ErrMsg: string;
 begin
+  if fFrame.frmFrame.DLLActive = True then Exit;  
   if (EditingIndex > -1) and FChanged then
   begin
@@ -3711,4 +3755,12 @@
     InfoBox(TX_SAVE_ERROR1 + ErrMsg + TX_SAVE_ERROR2, TC_SAVE_ERROR, MB_OK or MB_ICONWARNING);
   //Assert(ErrMsg = '', 'AutoSave: ' + ErrMsg);
+end;
+
+procedure TfrmConsults.DoLeftPanelCustomShiftTab;
+begin
+  if ShiftTabIsPressed then begin
+    FocusToRightPanel := True;
+    FindNextControl(frmFrame.pnlPatient, False, True, False).SetFocus;
+  end;
 end;
 
@@ -3828,5 +3880,5 @@
   begin
     ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-    memResults.Lines.Assign(BoilerText);
+    QuickCopyWith508Msg(BoilerText, memResults);
     FChanged := False;
   end;
@@ -3849,5 +3901,5 @@
         1: begin
              ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-             memResults.Lines.AddStrings(BoilerText);  // append
+             QuickCopyWith508Msg(BoilerText, memResults);  // append
            end;
         2: AssignBoilerText;                         // replace
@@ -4283,5 +4335,5 @@
         CreateListItemsforConsultTree(FCsltList, tmpList, ViewContext, GroupBy, Ascending);
         UpdateConsultsTreeView(FCsltList, tvConsults);
-        lstConsults.Items.Assign(tmpList);
+        FastAssign(tmpList, lstConsults.Items);
       end;
     with tvConsults do
@@ -4309,5 +4361,5 @@
       uChanging := True;
       Items.BeginUpdate;
-      lstConsults.Items.AddStrings(DocList);
+      FastAddStrings(DocList, lstConsults.Items);
       BuildConsultsTree(Tree, DocList, '0', nil, FCurrentContext);
       Items.EndUpdate;
@@ -4539,5 +4591,5 @@
   Signers := TStringList.Create;
   try
-    Signers.Assign(GetCurrentSigners(NoteIEN));
+    FastAssign(GetCurrentSigners(NoteIEN), Signers);
     for i := 0 to Signers.Count - 1 do
       if Piece(Signers[i], U, 1) = IntToStr(User.DUZ) then
@@ -4594,18 +4646,4 @@
 end;
 
-procedure TfrmConsults.tvConsultsAddition(Sender: TObject;
-  Node: TTreeNode);
-begin
-  inherited;
-  TAccessibleTreeNode.WrapControl(Node as TORTreeNode);
-end;
-
-procedure TfrmConsults.tvConsultsDeletion(Sender: TObject;
-  Node: TTreeNode);
-begin
-  inherited;
-  TAccessibleTreeNode.UnwrapControl(Node as TORTreeNode);
-end;
-
 procedure TfrmConsults.lstConsultsToPrint;      
 var
@@ -4630,94 +4668,10 @@
 end;
 
-
-{Tab Order tricks.  Need to change
-  tvConsult
-
-  tvCsltNotes
-  cmdEditResubmit
-  cmdNewConsult
-  cmdNewProc
-  frmDrawers.pnlTemplateButton
-  frmDrawers.pnlEncounterButton
-  cmdPCE
-
-  cmdChange
-  txtSubject
-  memResults
-
-to
-  tvConsult
-
-  cmdChange
-  txtSubject
-  memResults
-
-  tvCsltNotes
-  cmdEditResubmit
-  cmdNewConsult
-  cmdNewProc
-  frmDrawers.pnlTemplateButton
-  frmDrawers.pnlEncounterButton
-  cmdPCE
-}
-
 procedure TfrmConsults.tvConsultsExit(Sender: TObject);
 begin
   inherited;
-  if IncSecond(FMousing,1) < Now then
-  begin
-    if (Screen.ActiveControl = tvCsltNotes) or
-        (Screen.ActiveControl = cmdEditResubmit) or
-        (Screen.ActiveControl = cmdNewConsult) or
-        (Screen.ActiveControl = cmdNewProc) or
-        (Screen.ActiveControl = frmDrawers.pnlTemplatesButton) or
-        (Screen.ActiveControl = frmDrawers.pnlEncounterButton) or
-        (Screen.ActiveControl = cmdPCE) then
-      FindNextControl( cmdPCE, True, True, False).SetFocus;
-  end;
-  FMousing := 0;
-end;
-
-procedure TfrmConsults.pnlResultsExit(Sender: TObject);
-begin
-  inherited;
-  if IncSecond(FMousing,1) < Now then
-  begin
-    if (Screen.ActiveControl = frmFrame.pnlPatient) then
-      FindNextControl( tvConsults, True, True, False).SetFocus
-    else
-    if (Screen.ActiveControl = tvCsltNotes) or
-        (Screen.ActiveControl = cmdEditResubmit) or
-        (Screen.ActiveControl = cmdNewConsult) or
-        (Screen.ActiveControl = cmdNewProc) or
-        (Screen.ActiveControl = frmDrawers.pnlTemplatesButton) or
-        (Screen.ActiveControl = frmDrawers.pnlEncounterButton) or
-        (Screen.ActiveControl = cmdPCE) then
-      FindNextControl( tvCsltNotes, False, True, False).SetFocus;
-  end;
-  FMousing := 0;
-end;
-
-procedure TfrmConsults.pnlActionExit(Sender: TObject);
-begin
-  inherited;
-  if IncSecond(FMousing,1) < Now then
-  begin
-    if (Screen.ActiveControl = memConsult) or
-        (Screen.ActiveControl = cmdChange) or
-        (Screen.ActiveControl = txtSubject) or
-        (Screen.ActiveControl = memResults) then
-      begin
-        //frmFrame.pnlPatient.SetFocus  //COMMENTED OUT FOR CQ6498
-        if memResults.CanFocus then
-          memResults.SetFocus //ADDED THIS LINE FOR CQ6498
-        else
-          memConsult.SetFocus;
-      end
-    else
-    if (Screen.ActiveControl = tvConsults) then
-      FindNextControl( frmFrame.pnlPatient, False, True, False).SetFocus;
-  end;
-  FMousing := 0;
+  FocusToRightPanel := True;
+  if TabIsPressed then
+    FindNextControl(pnlLeft, False, True, False).SetFocus;
 end;
 
@@ -4725,13 +4679,6 @@
 begin
   FOldFramePnlPatientExit(Sender);
-  if IncSecond(FMousing,1) < Now then
-  begin
-    if (Screen.ActiveControl = memConsult) or
-        (Screen.ActiveControl = cmdChange) or
-        (Screen.ActiveControl = txtSubject) or
-        (Screen.ActiveControl = memResults) then
-      FindNextControl( memConsult, False, True, False).SetFocus;
-  end;
-  FMousing := 0;
+  if ShiftTabIsPressed then
+    FindNextControl( pnlRight, False, True, False).SetFocus;
 end;
 
@@ -4740,7 +4687,4 @@
   inherited;
   frmFrame.pnlPatient.OnExit := FOldFramePnlPatientExit;
-  frmDrawers.pnlTemplatesButton.OnExit := FOldDrawerPnlTemplatesButtonExit;
-  frmDrawers.pnlEncounterButton.OnExit := FOldDrawerPnlEncounterButtonExit;
-  frmDrawers.edtSearch.OnExit := FOldDrawerEdtSearchExit;
 end;
 
@@ -4752,10 +4696,4 @@
   FOldFramePnlPatientExit := frmFrame.pnlPatient.OnExit;
   frmFrame.pnlPatient.OnExit := frmFramePnlPatientExit;
-  FOldDrawerPnlTemplatesButtonExit := frmDrawers.pnlTemplatesButton.OnExit;
-  frmDrawers.pnlTemplatesButton.OnExit := frmDrawerPnlTemplatesButtonExit;
-  FOldDrawerPnlEncounterButtonExit := frmDrawers.pnlEncounterButton.OnExit;
-  frmDrawers.pnlEncounterButton.OnExit := frmDrawerPnlEncounterButtonExit;
-  FOldDrawerEdtSearchExit := frmDrawers.edtSearch.OnExit;
-  frmDrawers.edtSearch.OnExit := frmDrawerEdtSearchExit;
   {Below is a fix for ClearQuest Defect HDS0000948, Kind of Kloogy I looked
   and looked for side effects and a better solution and this was the best!}
@@ -4773,29 +4711,4 @@
   end
   {End of ClearQuest Defect HDS0000948 Fixes}
-end;
-
-procedure TfrmConsults.frmDrawerEdtSearchExit(Sender: TObject);
-begin
-  FOldDrawerEdtSearchExit(Sender);
-  pnlActionExit(Sender);
-end;
-
-procedure TfrmConsults.frmDrawerPnlTemplatesButtonExit(Sender: TObject);
-begin
-  FOldDrawerPnlTemplatesButtonExit(Sender);
-  pnlActionExit(Sender);
-end;
-
-procedure TfrmConsults.frmDrawerPnlEncounterButtonExit(Sender: TObject);
-begin
-  FOldDrawerPnlEncounterButtonExit(Sender);
-  pnlActionExit(Sender);
-end;
-
-procedure TfrmConsults.FormMouseMove(Sender: TObject; Shift: TShiftState;
-  X, Y: Integer);
-begin
-  inherited;
-  FMousing := Now;
 end;
 
@@ -4821,4 +4734,5 @@
 
 initialization
+  SpecifyFormIsNotADialog(TfrmConsults);
   uPCEEdit := TPCEData.Create;
   uPCEShow := TPCEData.Create;
