Index: cprs/trunk/CPRS-Chart/fFrame.pas
===================================================================
--- cprs/trunk/CPRS-Chart/fFrame.pas	(revision 830)
+++ cprs/trunk/CPRS-Chart/fFrame.pas	(revision 1679)
@@ -5,6 +5,6 @@
 {$OPTIMIZATION OFF}                              // REMOVE AFTER UNIT IS DEBUGGED
 {$WARN SYMBOL_PLATFORM OFF}
-{$DEFINE CCOWBROKER}
-
+{$DEFINE CCOWBROKER}                              
+                               
 {.$define debug}
 
@@ -15,7 +15,5 @@
   ExtCtrls, Menus, StdCtrls, Buttons, ORFn, fPage, uConst, ORCtrls, Trpcb,
   OleCtrls, VERGENCECONTEXTORLib_TLB, ComObj, AppEvnts, fBase508Form,
-  VA508AccessibilityManager
-{ TODO -oRV -cWVEHR Long Age : Changed to use long age }
-  , rWVEHR;
+  VA508AccessibilityManager, RichEdit;
 
 type
@@ -109,6 +107,4 @@
     pnlPatientSelected: TPanel;
     pnlNoPatientSelected: TPanel;
-    pnlFlag: TKeyClickPanel;
-    lblFlag: TLabel;
     pnlPostings: TKeyClickPanel;
     lblPtPostings: TStaticText;
@@ -132,4 +128,8 @@
     mnuViewRemoteData: TMenuItem;
     compAccessTabPage: TVA508ComponentAccessibility;
+    pnlCVnFlag: TPanel;
+    btnCombatVet: TButton;
+    pnlFlag: TKeyClickPanel;
+    lblFlag: TLabel;
     pnlRemoteData: TKeyClickPanel;
     pnlVistaWeb: TKeyClickPanel;
@@ -137,4 +137,5 @@
     pnlCIRN: TKeyClickPanel;
     lblCIRN: TLabel;
+    mnuEditRedo: TMenuItem;
     procedure tabPageChange(Sender: TObject);
     procedure FormCreate(Sender: TObject);
@@ -143,4 +144,8 @@
       Shift: TShiftState; X, Y: Integer);
     procedure pnlPatientMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure pnlVisitMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure pnlVisitMouseUp(Sender: TObject; Button: TMouseButton;
       Shift: TShiftState; X, Y: Integer);
     procedure mnuFileExitClick(Sender: TObject);
@@ -225,5 +230,4 @@
     procedure ScreenActiveFormChange(Sender: TObject);
     procedure AppEventsShortCut(var Msg: TWMKey; var Handled: Boolean);
-    procedure mnuToolsClick(Sender: TObject);
     procedure mnuToolsGraphingClick(Sender: TObject);
     procedure pnlCIRNMouseDown(Sender: TObject; Button: TMouseButton;
@@ -237,8 +241,12 @@
     procedure compAccessTabPageCaptionQuery(Sender: TObject;
       var Text: string);
+    procedure btnCombatVetClick(Sender: TObject);
     procedure pnlVistaWebClick(Sender: TObject);
+    procedure pnlVistaWebMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
     procedure pnlVistaWebMouseDown(Sender: TObject; Button: TMouseButton;
       Shift: TShiftState; X, Y: Integer);
-    procedure pnlVistaWebMouseUp(Sender: TObject; Button: TMouseButton;
+    procedure mnuEditRedoClick(Sender: TObject);
+    procedure tabPageMouseDown(Sender: TObject; Button: TMouseButton;
       Shift: TShiftState; X, Y: Integer);
   private
@@ -334,5 +342,6 @@
       Shift: TShiftState; X, Y: Integer);
   public
-   EnduringPtSelSplitterPos, frmFrameHeight, pnlPatientSelectedHeight: integer;
+    EnduringPtSelSplitterPos, frmFrameHeight, pnlPatientSelectedHeight: integer;
+    EnduringPtSelColumns: string;
     procedure SetBADxList;
     procedure SetActiveTab(PageID: Integer);
@@ -363,9 +372,12 @@
   frmFrame: TfrmFrame;
   uTabList: TStringList;
-  uRemoteType : string;
+  uRemoteType, uReportID, uLabRepID : string;
   FlaggedPTList: TStringList;
   ctxContextor : TContextorControl;
-  NextTab, LastTab: Integer;
-  uToolsMaxed, uToolsWarned, uUseVistaWeb: boolean;
+  NextTab, LastTab, ChangingTab: Integer;
+  uUseVistaWeb: boolean;
+  PTSwitchRefresh: boolean = FALSE;  //flag for patient refresh or switch of patients
+  ProbTabClicked: boolean = FALSE;
+  TabCtrlClicked: Boolean = FALSE;
 
 const
@@ -390,5 +402,5 @@
   {$ENDIF}
   , VA508AccessibilityRouter, fOtherSchedule, VAUtils, uVA508CPRSCompatibility, fIVRoutes,
-  fPrintLocation, fTemplateEditor;
+  fPrintLocation, fTemplateEditor, fTemplateDialog, fCombatVet;
 
 var                                 //  RV 05/11/04
@@ -421,5 +433,5 @@
   FCP_FINISH  = 99;                             // form create finished successfully
 
-  TX_IN_USE     = 'VistA CPRS in use by: ';
+  TX_IN_USE     = 'VistA CPRS in use by: ';     // use same as with CPRSInstances in fTimeout
   TX_OPTION     = 'OR CPRS GUI CHART';
   TX_ECSOPT     = 'EC GUI CONTEXT';
@@ -532,4 +544,12 @@
   else Application.ShowException(E);
   Application.RestoreTopMosts;
+end;
+
+procedure TfrmFrame.btnCombatVetClick(Sender: TObject);
+begin
+  inherited;
+  frmCombatVet := TfrmCombatVet.Create(frmFrame);
+  frmCombatVet.ShowModal;
+  frmCombatVet.Free;
 end;
 
@@ -617,5 +637,4 @@
   Changes.Clear;
   lstCIRNLocations.Clear;
-  uRemoteType := '';
   ClearFlag;
   if Assigned(FlagList) then FlagList.Clear;
@@ -633,5 +652,5 @@
   if frmFrame.TimedOut then
   begin
-    infoBox('CPRS has encountered a serious problem and is unable to display the selected patient''s data. This is a known issue documented in PSPO 1089.'
+    infoBox('CPRS has encountered a serious problem and is unable to display the selected patient''s data. '
             + 'To prevent patient safety issues, CPRS is shutting down. Shutting down and then restarting CPRS will correct the problem, and you may continue working in CPRS.'
              + CRLF + CRLF + 'Please report all occurrences of this problem by contacting your CPRS Help Desk.', 'CPRS Error', MB_OK);
@@ -664,4 +683,5 @@
 { Form Events (Create, Destroy) ----------------------------------------------------------- }
 
+
 procedure TfrmFrame.RefreshFixedStatusWidth;
 begin
@@ -675,5 +695,4 @@
   ClientVer, ServerVer, ServerReq: string;
 begin
-  FProccessingNextClick := false;
   FJustEnteredApp := false;
   SizeHolder := TSizeHolder.Create;
@@ -862,7 +881,10 @@
   GraphDataOnUser;
   uRemoteType := '';
+  uReportID := '';
+  uLabRepID := '';
   FPrevPtID := '';
   SetUserTools;
   EnduringPtSelSplitterPos := 0;
+  EnduringPtSelColumns := '';
   if User.IsReportsOnly then // Reports Only tab.
     ReportsOnlyDisplay; // Calls procedure to hide all components/menus not needed.
@@ -986,8 +1008,9 @@
 procedure TfrmFrame.SetUserTools;
 var
-  ToolItems: TToolItemList;
-  i: Integer;
+  item, parent: TToolMenuItem;
+  ok: boolean;
+  index, i, idx, count: Integer;
   UserTool: TMenuItem;
-  MaxedOut: boolean;
+  Menus: TStringList;
   //  OptionsClick: TNotifyEvent;
 begin
@@ -1011,40 +1034,63 @@
     //exit;
   end;
-  GetToolMenu(ToolItems, MaxedOut); // For all other users, proceed normally with creation of Tools menu:
-  for i := Low(ToolItems) to High(ToolItems) do
-  begin
-    if (AnsiCompareText(ToolItems[i].Caption, 'Event Capture Interface') = 0 ) and
+  GetToolMenu; // For all other users, proceed normally with creation of Tools menu:
+  for i := uToolMenuItems.Count-1 downto 0 do
+  begin
+    item := TToolMenuItem(uToolMenuItems[i]);
+    if (AnsiCompareText(item.Caption, 'Event Capture Interface') = 0 ) and
        (not uECSReport.ECSPermit) then
     begin
-      ToolItems[i].Caption := '';
-      ToolItems[i].Action  := '';
+      uToolMenuItems.Delete(i);
       Break;
     end;
   end;
-  if MaxedOut then
-  begin
-    uToolsMaxed := True;
-    uToolsWarned := False;
-  end;
-  for i := 0 to MAX_TOOLITEMS do with ToolItems[i] do if Length(Caption) > 0 then
-  begin
-    UserTool := TMenuItem.Create(Self);
-    UserTool.Caption := Caption;
-    UserTool.Hint := Action;
-    UserTool.OnClick := ToolClick;
-    mnuTools.Insert(i, UserTool);
-  end;
-end;
-
-procedure TfrmFrame.mnuToolsClick(Sender: TObject);
-const
-  TX_TOO_MANY_TOOLS = 'Some defined items may not be shown';
-  TC_TOO_MANY_TOOLS = 'Tool Menu Limit Exceeded';
-begin
-  if uToolsMaxed and (not uToolsWarned) then
-  begin
-    InfoBox(TX_TOO_MANY_TOOLS, TC_TOO_MANY_TOOLS, MB_ICONWARNING or MB_OK);
-    uToolsWarned := True;
-  end;
+  Menus := TStringList.Create;
+  try
+    count := 0;
+    idx := 0;
+    index := 0;
+    while count < uToolMenuItems.Count do
+    begin
+      for I := 0 to uToolMenuItems.Count - 1 do
+      begin
+        item := TToolMenuItem(uToolMenuItems[i]);
+        if assigned(item.MenuItem) then continue;        
+        if item.SubMenuID = '' then
+          ok := True
+        else
+        begin
+          idx := Menus.IndexOf(item.SubMenuID);
+          ok := (idx >= 0);
+        end;
+        if ok then
+        begin
+          inc(count);
+          UserTool := TMenuItem.Create(Self);
+          UserTool.Caption := Item.Caption;
+          if Item.Action <> '' then
+          begin
+            UserTool.Hint := Item.Action;
+            UserTool.OnClick := ToolClick;
+          end;
+          Item.MenuItem := UserTool;
+          if item.SubMenuID = '' then
+          begin
+            mnuTools.Insert(Index,UserTool);
+            inc(Index);
+          end
+          else
+          begin
+            parent := TToolMenuItem(Menus.Objects[idx]);
+            parent.MenuItem.Add(UserTool);
+          end;
+          if item.MenuID <> '' then
+            Menus.AddObject(item.MenuID, item);
+        end;
+      end;
+    end;
+  finally
+    Menus.Free;
+  end;
+  FreeAndNil(uToolMenuItems);
 end;
 
@@ -1168,5 +1214,5 @@
   IsProgrammer: Boolean;
 begin
-  IsProgrammer := User.HasKey('XUPROGMODE');
+  IsProgrammer := User.HasKey('XUPROGMODE') or (ShowRPCList = True);
   mnuHelpBroker.Visible  := IsProgrammer;
   mnuHelpLists.Visible   := IsProgrammer;
@@ -1236,5 +1282,5 @@
   if FLastPage = NewForm then
     begin
-      if Notifications.Active then PostMessage(Handle, UM_SHOWPAGE, 0, 0);
+      if Notifications.Active and Assigned(NewForm) then PostMessage(Handle, UM_SHOWPAGE, 0, 0);
       Exit;
     end;
@@ -1319,4 +1365,5 @@
   if ScreenReaderSystemActive and FCtrlTabUsed then
     SpeakPatient;
+  ChangingTab := PageID;
 end;
 
@@ -1377,13 +1424,11 @@
   begin
     ClearPatient;  // must be called to avoid leaving previous patient's information visible!
+    btnCombatVet.Caption := 'CV '+ CombatVet.ExpirationDate;
+    btnCombatVet.Visible := Patient.CombatVet.IsEligible;
     Visible := True;
     Application.ProcessMessages;
-    lblPtName.Caption := Name;
+    lblPtName.Caption := Name + Status; //CQ #17491: Allow for the display of the patient status indicator in header bar.
     lblPtSSN.Caption := SSN;
-//
-    { TODO -oRV -cWVEHR Long Age : Change for long patient age. }
-    lblPtAge.Caption := FormatFMDateTime('mmm dd,yyyy', DOB) + '   (' + GetPatientBriefAge(Patient.DFN) + ')';
-    //lblPtAge.Caption := FormatFMDateTime('mmm dd,yyyy', DOB) + ' (' + IntToStr(Age) + ')';
-//
+    lblPtAge.Caption := FormatFMDateTime('mmm dd,yyyy', DOB) + ' (' + IntToStr(Age) + ')';
     pnlPatient.Caption := lblPtName.Caption + ' ' + lblPtSSN.Caption + ' ' + lblPtAge.Caption;
     if Length(CWAD) > 0
@@ -1396,4 +1441,6 @@
     if Length(Attending) > 0 then lblPtAttending.Caption := 'Attending:  ' + MixedCase(Attending);
     pnlPrimaryCare.Caption := lblPtCare.Caption + ' ' + lblPtAttending.Caption;
+    if Length(Associate) > 0  then lblPtAttending.Caption := lblPtAttending.Caption + ' - Associate: ' + MixedCase(Associate);
+    pnlPrimaryCare.Caption := lblPtCare.Caption + ' ' + lblPtAttending.Caption ;
     SetUpCIRN;
     DisplayEncounterText;
@@ -1451,4 +1498,5 @@
 begin
   DoNotChangeEncWindow := False;
+  OrderPrintForm := False;
   mnuFile.Tag := 0;
   SaveDFN := Patient.DFN;
@@ -1651,4 +1699,7 @@
   CCOWResponse: UserResponse;
 begin
+  pnlPatient.Enabled := false;
+  if (Sender = mnuFileOpen) or (FRefreshing) then PTSwitchRefresh := True
+  else PTSwitchRefresh := False;  //part of a change to CQ #11529
   PtSelCancelled := FALSE;
   if not FRefreshing then mnuFile.Tag := 0
@@ -1670,7 +1721,10 @@
         PtEvtCompleted(TheCurrentView.EventDelay.PtEventIFN, TheCurrentView.EventDelay.EventName);
     end;*)
-  //if Sender <> mnuFileNext then     //CQ 16273 & 16419 - Missing Review/Sign changes dialog when clicking 'Next' button
-    if not AllowContextChangeAll(Reason) then Exit;
-     
+  //if Sender <> mnuFileNext then        //CQ 16273 & 16419 - Missing Review/Sign Changes dialog when clicking 'Next' button.
+    if not AllowContextChangeAll(Reason) then
+      begin
+        pnlPatient.Enabled := True;
+        Exit;
+      end;
   // update status text here
   stsArea.Panels.Items[1].Text := '';
@@ -1685,4 +1739,5 @@
         begin
           Notifications.Prior;
+          pnlPatient.Enabled := True;
           Exit;
         end;
@@ -1728,5 +1783,9 @@
         if (Patient.DFN = '') or (Sender = mnuFileOpen) or (Sender = mnuFileNext) or (Sender = mnuViewDemo) then
           SelectPatient(SHOW_NOTIFICATIONS, Font.Size, PtSelCancelled);
-        if PtSelCancelled then exit;
+        if PtSelCancelled then
+          begin
+            pnlPatient.Enabled := True;
+            exit;
+          end;
         ShowEverything;
         //HideEverything('Retrieving information - please wait....');  //v27 (pending) RV
@@ -1811,5 +1870,12 @@
  {End BillingAware}
  //ShowEverything;  //v27 (pending) RV
- if not FRefreshing then DoNotChangeEncWindow := false;
+ if not FRefreshing then
+   begin
+      DoNotChangeEncWindow := false;
+      OrderPrintForm := false;
+      uCore.TempEncounterLoc := 0;
+      uCore.TempEncounterLocName := '';
+   end;
+ pnlPatient.Enabled := True;
  //frmCover.UpdateVAAButton; //VAA CQ7525   CQ#7933 - moved to SetupPatient, before event hook execution (RV)
 end;
@@ -1856,5 +1922,5 @@
   EventChanges := False;
   NameNeedLook := '';
-  UpdatePtInfoOnRefresh;
+  //UpdatePtInfoOnRefresh;
   if Changes.Count > 0 then
   begin
@@ -1872,4 +1938,7 @@
   end
   else InfoBox('No new changes to review/sign.', 'Review Changes', MB_OK);
+  //CQ #17491: Moved UpdatePtInfoOnRefresh here to allow for the updating of the patient status indicator
+  //in the header bar (after the Review Changes dialog closes) if the patient becomes admitted/discharged.
+  UpdatePtInfoOnRefresh;
   FOrderPrintForm := false;
   FReviewClick := false;
@@ -2144,7 +2213,57 @@
 end;
 
+procedure TfrmFrame.pnlVisitMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+{ emulate a button press in the encounter panel }
+begin
+  if User.IsReportsOnly then
+    exit;
+  if pnlVisit.BevelOuter = bvLowered then exit;
+  pnlVisit.BevelOuter := bvLowered;
+  //with lblStLocation do SetBounds(Left+2, Top+2, Width, Height);
+  with lblPtLocation do SetBounds(Left+2, Top+2, Width, Height);
+  with lblPtProvider do SetBounds(Left+2, Top+2, Width, Height);
+end;
+
+procedure TfrmFrame.pnlVisitMouseUp(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+{ emulate a button raising in the encounter panel and call Update Provider/Location }
+begin
+  if User.IsReportsOnly then
+    exit;
+  if pnlVisit.BevelOuter = bvRaised then exit;
+  pnlVisit.BevelOuter := bvRaised;
+  //with lblStLocation do SetBounds(Left-2, Top-2, Width, Height);
+  with lblPtLocation do SetBounds(Left-2, Top-2, Width, Height);
+  with lblPtProvider do SetBounds(Left-2, Top-2, Width, Height);
+end;
+
+procedure TfrmFrame.pnlVistaWebClick(Sender: TObject);
+begin
+  inherited;
+  uUseVistaWeb := true;
+  pnlVistaWeb.BevelOuter := bvLowered;
+  pnlCIRNClick(self);
+  uUseVistaWeb := false;
+end;
+
+procedure TfrmFrame.pnlVistaWebMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+begin
+  inherited;
+  pnlVistaWeb.BevelOuter := bvLowered;
+end;
+
+procedure TfrmFrame.pnlVistaWebMouseUp(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+begin
+  inherited;
+  pnlVistaWeb.BevelOuter := bvRaised;
+end;
+
 procedure TfrmFrame.pnlPrimaryCareMouseDown(Sender: TObject;
   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 begin
+  if pnlPrimaryCare.BevelOuter = bvLowered then exit;
   pnlPrimaryCare.BevelOuter := bvLowered;
   with lblPtCare      do SetBounds(Left+2, Top+2, Width, Height);
@@ -2155,4 +2274,5 @@
   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 begin
+  if pnlPrimaryCare.BevelOuter = bvRaised then exit;
   pnlPrimaryCare.BevelOuter := bvRaised;
   with lblPtCare      do SetBounds(Left-2, Top-2, Width, Height);
@@ -2164,4 +2284,5 @@
 { emulate a button press in the postings panel }
 begin
+  if pnlPostings.BevelOuter = bvLowered then exit;
   pnlPostings.BevelOuter := bvLowered;
   with lblPtPostings do SetBounds(Left+2, Top+2, Width, Height);
@@ -2173,4 +2294,5 @@
 { emulate a button raising in the posting panel and call Postings }
 begin
+  if pnlPostings.BevelOuter = bvRaised then exit;
   pnlPostings.BevelOuter := bvRaised;
   with lblPtPostings do SetBounds(Left-2, Top-2, Width, Height);
@@ -2200,4 +2322,6 @@
   SetUserColumns(TControl(frmMeds.hdrMedsIn));  // still need conversion
   SetUserColumns(TControl(frmMeds.hdrMedsOut));
+  SetUserString('frmPtSel.lstvAlerts',EnduringPtSelColumns);
+  SetUserString(SpellCheckerSettingName, SpellCheckerSettings);
   SetUserBounds2(TemplateEditorSplitters, tmplEditorSplitterMiddle,
                  tmplEditorSplitterProperties, tmplEditorSplitterMain, tmplEditorSplitterBoil);
@@ -2212,5 +2336,5 @@
   frmDCSumm.Drawers.LastOpenSize := s3;
 
-  with frmMeds do                                           
+  with frmMeds do
      begin
      SetUserBounds2(frmMeds.Name+'Split', panelBottom, panelMedIn, Dummy, Dummy);
@@ -2272,4 +2396,5 @@
       Add(StrUserColumns(frmMeds.hdrMedsIn));
       Add(StrUserColumns(frmMeds.hdrMedsOut));
+      Add(StrUserString(SpellCheckerSettingName, SpellCheckerSettings));
       Add(StrUserBounds2(TemplateEditorSplitters, tmplEditorSplitterMiddle,
               tmplEditorSplitterProperties, tmplEditorSplitterMain, tmplEditorSplitterBoil));
@@ -2308,4 +2433,6 @@
       if EnduringPtSelSplitterPos <> 0 then
         Add(StrUserBounds2('frmPtSel.sptVert', EnduringPtSelSplitterPos, 0, 0, 0));
+      if EnduringPtSelColumns <> '' then
+        Add('C^frmPtSel.lstvAlerts^' + EnduringPtSelColumns);
     end;
     //Add sizes for forms that used SaveUserBounds() to save thier positions
@@ -2381,5 +2508,9 @@
       with lblCIRN       do Font.Size := NewFontSize;
       with lblVistaWeb   do Font.Size := NewFontSize;
-      with lstCIRNLocations do Font.Size := NewFontSize;
+      with lstCIRNLocations do
+        begin
+          Font.Size := NewFontSize;
+          ItemHeight := NewFontSize + 6;
+        end;
       with tabPage       do Font.Size := NewFontSize;
       with laMHV         do Font.Size := NewFontSize; //VAA
@@ -2445,17 +2576,12 @@
 { resizes and repositions the panels & labels used in the toolbar }
 const
-{ TODO -oRV -cWVEHR Long Age : Change to 40, to fit long age }
-  //PATIENT_WIDTH = 29;
-  PATIENT_WIDTH = 40;
-{}
+  PATIENT_WIDTH = 29;
   VISIT_WIDTH   = 36;
   POSTING_WIDTH = 11.5;
   FLAG_WIDTH    = 5;
+  CV_WIDTH      = 15; //14; WAT
   CIRN_WIDTH    = 11;
   MHV_WIDTH     = 6;
-{ TODO -oRV -cWVEHR Long Age : Change to 3 lines high, to fit long age }
-  //LINES_HIGH    = 2;
-  LINES_HIGH    = 3;
-{}
+  LINES_HIGH    = 2;
   M_HORIZ       = 4;
   M_MIDDLE      = 2;
@@ -2466,18 +2592,9 @@
   //WidthNeeded: integer;
 begin
-//
-  { TODO -oRV -cWVEHR Long Age : Changed to fit long age }
-  pnlToolbar.Height  := (LINES_HIGH * lblPtName.Height) + M_HORIZ + M_MIDDLE + M_HORIZ + M_HORIZ;
-  //pnlToolbar.Height  := (LINES_HIGH * lblPtName.Height) + M_HORIZ + M_MIDDLE + M_HORIZ;
-//
+  pnlToolbar.Height  := (LINES_HIGH * lblPtName.Height) + M_HORIZ + M_MIDDLE + M_HORIZ;
   pnlPatient.Width   := HigherOf(PATIENT_WIDTH * MainFontWidth, lblPtName.Width + (M_WVERT * 2));
   lblPtSSN.Top       := M_HORIZ + lblPtName.Height + M_MIDDLE;
-//
-  { TODO -oRV -cWVEHR Long Age : Changed to fit long age }
-  lblPtAge.Top       := lblPtSSN.Top + lblPtSSN.Height + M_MIDDLE;
-  lblPtAge.Left      := lblPtSSN.Left;
-  //lblPtAge.Top       := lblPtSSN.Top;
-  //lblPtAge.Left      := pnlPatient.Width - lblPtAge.Width - M_WVERT;
-//
+  lblPtAge.Top       := lblPtSSN.Top;
+  lblPtAge.Left      := pnlPatient.Width - lblPtAge.Width - M_WVERT;
   pnlVisit.Width     := HigherOf(LowerOf(VISIT_WIDTH * MainFontWidth,
                                          HigherOf(lblPtProvider.Width + (M_WVERT * 2),
@@ -2487,6 +2604,15 @@
   lblPtAttending.Top := lblPtSSN.Top;
   pnlPostings.Width  := Round(POSTING_WIDTH * MainFontWidth);
-  pnlFlag.Width      := Round(FLAG_WIDTH * MainFontWidth);
-  pnlFlag.Width      := Round(FLAG_WIDTH * MainFontWidth);
+  if btnCombatVet.Visible then
+   begin
+    pnlCVnFlag.Width   := Round(CV_WIDTH * MainFontWidth);
+    pnlFlag.Width      := Round(CV_WIDTH * MainFontWidth);
+    btnCombatVet.Height := Round(pnlCVnFlag.Height div 2);
+   end
+  else
+   begin
+    pnlCVnFlag.Width   := Round(FLAG_WIDTH * MainFontWidth);
+    pnlFlag.Width      := Round(FLAG_WIDTH * MainFontWidth);
+   end;
   pnlRemoteData.Width := Round(CIRN_WIDTH * MainFontWidth) + M_WVERT;
   pnlVistaWeb.Height := pnlRemoteData.Height div 2;
@@ -2561,5 +2687,8 @@
     else if FEditCtrl is TRichEdit then IsReadOnly := TRichEdit(FEditCtrl).ReadOnly
     else IsReadOnly := True;
-    mnuEditUndo.Enabled := FEditCtrl.Perform(EM_CANUNDO, 0, 0) <> 0;
+
+    mnuEditRedo.Enabled := FEditCtrl.Perform(EM_CANREDO, 0, 0) <> 0;
+    mnuEditUndo.Enabled := (FEditCtrl.Perform(EM_CANUNDO, 0, 0) <> 0) and (FEditCtrl.Perform(EM_CANREDO, 0, 0) = 0);
+
     mnuEditCut.Enabled := FEditCtrl.SelLength > 0;
     mnuEditCopy.Enabled := mnuEditCut.Enabled;
@@ -2578,4 +2707,10 @@
   FEditCtrl.Perform(EM_UNDO, 0, 0);
 end;
+
+procedure TfrmFrame.mnuEditRedoClick(Sender: TObject);
+begin
+  FEditCtrl.Perform(EM_REDO, 0, 0);
+end;
+
 
 procedure TfrmFrame.mnuEditCutClick(Sender: TObject);
@@ -2779,4 +2914,5 @@
     lblCIRN.Caption := ' Remote Data';
     lblCIRN.Alignment := taCenter;
+    pnlVistaWeb.BevelOuter := bvRaised;
     if RemoteDataExists and (RemoteSites.Count > 0) then
       begin
@@ -2787,4 +2923,6 @@
         lblCIRN.Caption := 'Remote Data';
         pnlCIRN.Hint := 'Click to display other facilities having data for this patient.';
+        lblVistaWeb.Font.Color := Get508CompliantColor(clBlue);
+        pnlVistaWeb.Hint := 'Click to go to VistaWeb to see data from other facilities for this patient.';
         if RemoteSites.Count > 0 then
           lstCIRNLocations.Items.Add('0' + U + 'All Available Sites');
@@ -2799,4 +2937,5 @@
       begin
         lblCIRN.Font.Color  := clWindowText;
+        lblVistaWeb.Font.Color := clWindowText;
         lblCIRN.Enabled     := False;
         pnlCIRN.TabStop     := False;
@@ -3028,7 +3167,12 @@
             TRemoteSite(Items[j]));
         end;
-
-  if frmReports.tvReports.SelectionCount > 0 then frmReports.tvReportsClick(self);
-  if frmLabs.tvReports.SelectionCount > 0 then frmLabs.tvReportsClick(self);
+  //uReportID, uLabRepID = Report ID's set when report is selected (from file 101.24)
+  if not(Piece(uReportID,':',1) = 'OR_VWAL')
+    and not(Piece(uReportID,':',1) = 'OR_VWRX')
+    and not(Piece(uReportID,':',1) = 'OR_VWVS')
+    and (frmReports.tvReports.SelectionCount > 0) then frmReports.tvReportsClick(self);
+  if not(uLabRepID = '6:GRAPH') and not(uLabRepID = '5:WORKSHEET')
+    and not(uLabRepID = '4:SELECTED TESTS BY DATE')
+    and (frmLabs.tvReports.SelectionCount > 0) then frmLabs.tvReportsClick(self);
   //if frmLabs.lstReports.ItemIndex > -1 then frmLabs.ExtlstReportsClick(self, true);
   StatusText('');
@@ -3062,5 +3206,5 @@
   CurrPrt: string;
 begin
-  CurrPrt := SelectDevice(Self, Encounter.Location, True,'');
+  CurrPrt := SelectDevice(Self, Encounter.Location, True, 'Print Device Selection');
   User.CurrentPrinter := Piece(CurrPrt, U, 1);
 end;
@@ -3068,8 +3212,9 @@
 procedure TfrmFrame.lstCIRNLocationsChange(Sender: TObject);
 begin
-  if lstCIRNLocations.ItemIndex > 0 then
+  {if lstCIRNLocations.ItemIndex > 0 then
     if (lstCIRNLocations.Selected[lstCIRNLocations.ItemIndex] = true) and (uUpdateStat = false) then
       if not (piece(lstCIRNLocations.Items[1],'^',1) = '0') then
         lstCIRNLocations.OnClick(nil);
+  // Causing Access Violations}
 end;
 
@@ -3158,9 +3303,9 @@
 begin
   FRefreshing := TRUE;
-
   try
     mnuFileOpenClick(Self);
   finally
     FRefreshing := FALSE;
+    OrderPrintForm := FALSE;
   end;
 end;
@@ -3171,5 +3316,5 @@
     FOldActivate(Sender);
   SetActiveWindow(Application.Handle);
-  if ScreenReaderSystemActive and assigned(Patient) and (Patient.Name <> '') then
+  if ScreenReaderSystemActive and assigned(Patient) and (Patient.Name <> '') and (Patient.Status <> '') then
       SpeakTabAndPatient;
 end;
@@ -3327,11 +3472,7 @@
   uCore.TempEncounterDateTime := 0;
   uCore.TempEncounterVistCat := #0;
-  //ucore.TempOutEncounterLoc := 0;
-  //uCore.TempOutEncounterLocName := '';
   if (not FRefreshing) and (FReviewClick = false) then DoNotChangeEncWindow := false;
   if (FPrevInPatient and Patient.Inpatient) then                //transfering inside hospital
     begin
-     // if DoNotChangeEncWindow = false then
-     //   begin
           if FReviewClick = True then
             begin
@@ -3354,8 +3495,5 @@
               Exit;
             end;
-               
-            //end;
-          Encounter.Location := Patient.Location;
-       // end;
+          if orderprintform = false then Encounter.Location := Patient.Location;
     end
   else if (FPrevInPatient and (not Patient.Inpatient)) then     //patient was discharged
@@ -3364,4 +3502,6 @@
     Encounter.Location := 0;
     FPrevInPatient := False;
+    lblPtName.Caption := '';
+    lblPtName.Caption := Patient.Name + Patient.Status; //CQ #17491: Refresh patient status indicator in header bar on discharge.
   end
   else if ((not FPrevInPatient) and Patient.Inpatient) then     //patient was admitted
@@ -3373,9 +3513,19 @@
     uCore.TempEncounterDateTime := Encounter.DateTime;
     uCore.TempEncounterVistCat := Encounter.VisitCategory;
-    if (FReviewClick = False) and (encounter.Location <> patient.Location) then
-        frmPrintLocation.SwitchEncounterLoction(Encounter.Location, Encounter.locationName, Encounter.LocationText,
-                                                Encounter.DateTime, Encounter.VisitCategory)
+    lblPtName.Caption := '';
+    lblPtName.Caption := Patient.Name + Patient.Status; //CQ #17491: Refresh patient status indicator in header bar on admission.
+    if (FReviewClick = False) and (encounter.Location <> patient.Location) and (OrderPrintForm = false) then
+        begin
+          frmPrintLocation.SwitchEncounterLoction(Encounter.Location, Encounter.locationName, Encounter.LocationText,
+                                                Encounter.DateTime, Encounter.VisitCategory);
+          //agp values are reset depending on the user process
+          uCore.TempEncounterLoc := 0;  //hds7591  Clinic/Ward movement.
+          uCore.TempEncounterLocName := ''; //hds7591  Clinic/Ward movement.
+          uCore.TempEncounterText := '';
+          uCore.TempEncounterDateTime := 0;
+          uCore.TempEncounterVistCat := #0;
+        end
     else
-    //if DoNotChangeEncWindow = false then
+    if OrderPrintForm = false then
       begin
         Encounter.Location := Patient.Location;
@@ -3463,44 +3613,21 @@
 procedure TfrmFrame.pnlPatientClick(Sender: TObject);
 begin
+  Screen.Cursor := crHourglass; //wat cq 18425 added hourglass and disabled mnuFileOpen
+  mnuFileOpen.Enabled := False;
+  try
   pnlPatient.Enabled := false;
   ViewInfo(mnuViewDemo);
   pnlPatient.Enabled := true;
+  finally
+    Screen.Cursor := crDefault;
+    mnuFileOpen.Enabled := True;
+  end;
 end;
 
 procedure TfrmFrame.pnlVisitClick(Sender: TObject);
 begin
-  pnlVisit.Enabled := false;
-  pnlVisit.BevelOuter := bvLowered;
-  with lblPtLocation do SetBounds(Left+2, Top+2, Width, Height);
-  with lblPtProvider do SetBounds(Left+2, Top+2, Width, Height);
-
+ //if (not User.IsReportsOnly) then // Reports Only tab.
+ //  mnuFileEncounterClick(Self);
   ViewInfo(mnuViewVisits);
-
-  pnlVisit.BevelOuter := bvRaised;
-  with lblPtLocation do SetBounds(Left-2, Top-2, Width, Height);
-  with lblPtProvider do SetBounds(Left-2, Top-2, Width, Height);
-  pnlVisit.Enabled := true;
-end;
-
-procedure TfrmFrame.pnlVistaWebClick(Sender: TObject);
-begin
-  inherited;
-  uUseVistaWeb := true;
-  pnlCIRNClick(self);
-  uUseVistaWeb := false;
-end;
-
-procedure TfrmFrame.pnlVistaWebMouseDown(Sender: TObject; Button: TMouseButton;
-  Shift: TShiftState; X, Y: Integer);
-begin
-  inherited;
-  pnlVistaWeb.BevelOuter := bvLowered;
-end;
-
-procedure TfrmFrame.pnlVistaWebMouseUp(Sender: TObject; Button: TMouseButton;
-  Shift: TShiftState; X, Y: Integer);
-begin
-  inherited;
-  pnlVistaWeb.BevelOuter := bvRaised;
 end;
 
@@ -4179,5 +4306,5 @@
   pnlFlag.BevelInner := bvRaised;
   pnlFlag.BevelOuter := bvNone;
-  pnlFlag.BevelWidth := 4;
+  pnlFlag.BevelWidth := 3;
 end;
 
@@ -4187,4 +4314,11 @@
   pnlFlag.BevelInner := bvNone;
   pnlFlag.BevelOuter := bvRaised;
+end;
+
+procedure TfrmFrame.tabPageMouseDown(Sender: TObject; Button: TMouseButton;
+  Shift: TShiftState; X, Y: Integer);
+begin
+  inherited;
+  TabCtrlClicked := True;
 end;
 
@@ -4356,5 +4490,4 @@
   ReportString: TStringList;
   aAddress: string;
-
 begin
   case (Sender as TMenuItem).Tag of
@@ -4395,5 +4528,4 @@
         if uUseVistaWeb = true then
           begin
-            pnlCIRN.BevelOuter := bvRaised;
             lblCIRN.Alignment := taCenter;
             lstCIRNLocations.Visible := false;
@@ -4401,4 +4533,5 @@
             aAddress := GetVistaWebAddress(Patient.DFN);
             ShellExecute(pnlCirn.Handle, 'open', PChar(aAddress), PChar(''), '', SW_NORMAL);
+            pnlCIRN.BevelOuter := bvRaised;
             Exit;
           end;
