Index: cprs/trunk/CPRS-Chart/fFrame.pas
===================================================================
--- cprs/trunk/CPRS-Chart/fFrame.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/fFrame.pas	(revision 830)
@@ -14,8 +14,11 @@
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Tabs, ComCtrls,
   ExtCtrls, Menus, StdCtrls, Buttons, ORFn, fPage, uConst, ORCtrls, Trpcb,
-  OleCtrls, VERGENCECONTEXTORLib_TLB, ComObj, AppEvnts;
+  OleCtrls, VERGENCECONTEXTORLib_TLB, ComObj, AppEvnts, fBase508Form,
+  VA508AccessibilityManager
+{ TODO -oRV -cWVEHR Long Age : Changed to use long age }
+  , rWVEHR;
 
 type
-  TfrmFrame = class(TForm)
+  TfrmFrame = class(TfrmBase508Form)
     pnlToolbar: TPanel;
     stsArea: TStatusBar;
@@ -47,5 +50,4 @@
     mnuEditPref: TMenuItem;
     Prefs1: TMenuItem;
-    mnu24pt1: TMenuItem;
     mnu18pt1: TMenuItem;
     mnu14pt1: TMenuItem;
@@ -83,7 +85,4 @@
     lblPtCare: TStaticText;
     lblPtAttending: TStaticText;
-    pnlCIRN: TKeyClickPanel;
-    lblCIRN: TLabel;
-    lblCIRNData: TLabel;
     pnlReminders: TKeyClickPanel;
     imgReminder: TImage;
@@ -125,5 +124,4 @@
     laVAA2: TButton;
     laMHV: TButton;
-    lblCIRNAvail: TLabel;
     mnuViewInformation: TMenuItem;
     mnuViewVisits: TMenuItem;
@@ -133,4 +131,10 @@
     mnuViewFlags: TMenuItem;
     mnuViewRemoteData: TMenuItem;
+    compAccessTabPage: TVA508ComponentAccessibility;
+    pnlRemoteData: TKeyClickPanel;
+    pnlVistaWeb: TKeyClickPanel;
+    lblVistaWeb: TLabel;
+    pnlCIRN: TKeyClickPanel;
+    lblCIRN: TLabel;
     procedure tabPageChange(Sender: TObject);
     procedure FormCreate(Sender: TObject);
@@ -139,8 +143,4 @@
       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);
@@ -171,10 +171,4 @@
     procedure mnuGECStatusClick(Sender: TObject);
     procedure mnuFileNextClick(Sender: TObject);
-    procedure stsAreaMouseDown(Sender: TObject; Button: TMouseButton;
-      Shift: TShiftState; X, Y: Integer);
-    procedure stsAreaMouseUp(Sender: TObject; Button: TMouseButton;
-      Shift: TShiftState; X, Y: Integer);
-    procedure stsAreaDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
-      const Rect: TRect);
     procedure pnlPrimaryCareMouseDown(Sender: TObject;
       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
@@ -241,5 +235,13 @@
     procedure ViewInfo(Sender: TObject);
     procedure mnuViewInformationClick(Sender: TObject);
+    procedure compAccessTabPageCaptionQuery(Sender: TObject;
+      var Text: string);
+    procedure pnlVistaWebClick(Sender: TObject);
+    procedure pnlVistaWebMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure pnlVistaWebMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
   private
+    FProccessingNextClick : boolean;
     FJustEnteredApp : boolean;
     FCCOWInstalled: boolean;
@@ -261,4 +263,5 @@
     FNextButtonActive: Boolean;
     FNextButtonBitmap: TBitmap;
+    FNextButton: TBitBtn;
     FTerminate: Boolean;
     FTabChanged: TNotifyEvent;
@@ -271,7 +274,10 @@
     FFlagList: TStringList;
     FPrevPtID: string;
-    FVitalsDLLActive: boolean;
     FGraphFloatActive: boolean;
     FGraphContext: string;
+    FDoNotChangeEncWindow: boolean;
+    FOrderPrintForm: boolean;
+    FReviewclick: boolean;
+    FCtrlTabUsed: boolean;
     procedure RefreshFixedStatusWidth;
     procedure FocusApplicationTopForm;
@@ -318,12 +324,17 @@
     procedure CheckForDifferentUser(aContextItemCollection: IDispatch; var UserChanged: boolean);
 {$ENDIF}
-    procedure HideEverything;
+    procedure HideEverything(AMessage: string = 'No patient is currently selected.');
     procedure ShowEverything;
     //function FindBestCCOWDFN(var APatientName: string): string;
     function FindBestCCOWDFN: string;
     procedure HandleCCOWError(AMessage: string);
+    procedure SetUpNextButton;
+    procedure NextButtonClick(Sender: TObject);
+    procedure NextButtonMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
   public
-   EnduringPtSelSplitterPos: integer;
+   EnduringPtSelSplitterPos, frmFrameHeight, pnlPatientSelectedHeight: integer;
     procedure SetBADxList;
+    procedure SetActiveTab(PageID: Integer);
 
     function PageIDToTab(PageID: Integer): Integer;
@@ -332,4 +343,5 @@
     function  TabExists(ATabID: integer): boolean;
     procedure DisplayEncounterText;
+    function DLLActive: boolean;
     property ChangeSource:    Integer read FChangeSource;
     property CCOWContextChanging: Boolean read FCCOWContextChanging;
@@ -340,9 +352,10 @@
     property Closing:         Boolean read FClosing;
     property OnTabChanged:    TNotifyEvent read FTabChanged write FTabChanged;
-    property VitalsDLLActive: boolean read FVitalsDLLActive write FVitalsDLLActive;
     property GraphFloatActive: boolean read FGraphFloatActive write FGraphFloatActive;
     property GraphContext: string read FGraphContext write FGraphContext;
     procedure ToggleMenuItemChecked(Sender: TObject);
     procedure SetUpCIRN;
+    property DoNotChangeEncWindow: boolean read FDoNotChangeEncWindow write FDoNotChangeEncWindow;
+    property OrderPrintForm: boolean read FOrderPrintForm write FOrderPrintForm;
   end;
 
@@ -354,5 +367,5 @@
   ctxContextor : TContextorControl;
   NextTab, LastTab: Integer;
-  uToolsMaxed, uToolsWarned: boolean;
+  uToolsMaxed, uToolsWarned, uUseVistaWeb: boolean;
 
 const
@@ -370,11 +383,12 @@
   fxLists, fxServer, ORSystem, fRptBox, fSplash, rODAllergy, uInit, fLabTests, fLabInfo,
   uReminders, fReminderTree, ORClasses, fDeviceSelect, fDrawers, fReminderDialog, ShellAPI, rVitals,
-  fOptions, fGraphs, rTemplates, fSurgery, rSurgery, uEventHooks, uSignItems, fDefaultEvent,rECS,
-  fIconLegend, uOrders, fPtSelOptns, DateUtils, uSpell, uOrPtf, fPatientFlagMulti,
-  fAlertForward, UBAGlobals, fBAOptionsDiagnoses, UBACore, fOrdersSign, uVitals, fOrdersRenew, uFormMonitor
+  fOptions, fGraphs, fGraphData, rTemplates, fSurgery, rSurgery, uEventHooks, uSignItems,
+  fDefaultEvent, rECS, fIconLegend, uOrders, fPtSelOptns, DateUtils, uSpell, uOrPtf, fPatientFlagMulti,
+  fAlertForward, UBAGlobals, fBAOptionsDiagnoses, UBACore, fOrdersSign, uVitals, fOrdersRenew, fMHTest, uFormMonitor
   {$IFDEF CCOWBROKER}
   , CCOW_const
   {$ENDIF}
-  ;
+  , VA508AccessibilityRouter, fOtherSchedule, VAUtils, uVA508CPRSCompatibility, fIVRoutes,
+  fPrintLocation, fTemplateEditor;
 
 var                                 //  RV 05/11/04
@@ -453,9 +467,33 @@
 
 procedure TfrmFrame.TimeOutAction;
-begin
-  if frmFrame.VitalsDLLActive then
-    CloseVitalsDLL()
-  else
-    Close;
+var
+  ClosingCPRS: boolean;
+
+  procedure CloseCPRS;
+  begin
+    if ClosingCPRS then
+      halt;
+    try
+      ClosingCPRS := TRUE; 
+      Close;
+    except
+      halt;
+    end;
+  end;
+
+begin
+  ClosingCPRS := FALSE;
+  try
+    if assigned(frmOtherSchedule) then frmOtherSchedule.Close;
+    if assigned (frmIVRoutes) then frmIVRoutes.Close;
+    if frmFrame.DLLActive then
+    begin
+       CloseVitalsDLL();
+       CloseMHDLL();
+    end;
+    CloseCPRS;
+  except
+    CloseCPRS;
+  end;
 end;
 
@@ -478,5 +516,5 @@
       ErrMsg := ErrMsg + CRLF + 'Address was ' + IntToStr(Integer(AnAddr));
     end;
-    ShowMessage(ErrMsg);
+    ShowMsg(ErrMsg);
   end
   else if (E is EBrokerError) then
@@ -507,5 +545,5 @@
   FContextChanging := True;
   Result := True;
-  if COMObjectActive or SpellCheckInProgress or VitalsDLLActive then
+  if COMObjectActive or SpellCheckInProgress or DLLActive then
     begin
       Reason := 'COM_OBJECT_ACTIVE';
@@ -523,4 +561,5 @@
   if Result then Result := frmLabs.AllowContextChange(Reason);;
   if Result then Result := frmReports.AllowContextChange(Reason);
+  if Result then Result := frmGraphData.AllowContextChange(Reason);
   if (not User.IsReportsOnly) then
     if Result and Changes.RequireReview then //Result := ReviewChanges(TimedOut);
@@ -546,5 +585,5 @@
 { call all pages to make sure patient related information is cleared (when switching patients) }
 begin
-  if frmFrame.Timedout then Exit; // added to correct Access Violation when "Refresh Patient Information" selected
+  //if frmFrame.Timedout then Exit; // added to correct Access Violation when "Refresh Patient Information" selected
   lblPtName.Caption     := '';
   lblPtSSN.Caption      := '';
@@ -552,7 +591,10 @@
   pnlPatient.Caption    := '';
   lblPtCWAD.Caption     := '';
-  lblPtLocation.Caption := 'Visit Not Selected';
-  lblPtProvider.Caption := 'Current Provider Not Selected';
-  pnlVisit.Caption      := lblPtLocation.Caption + CRLF + lblPtProvider.Caption;
+  if DoNotChangeEncWindow = false then
+     begin
+      lblPtLocation.Caption := 'Visit Not Selected';
+      lblPtProvider.Caption := 'Current Provider Not Selected';
+      pnlVisit.Caption      := lblPtLocation.Caption + CRLF + lblPtProvider.Caption;
+     end;
   lblPtCare.Caption     := 'Primary Care Team Unassigned';
   lblPtAttending.Caption := '';
@@ -567,4 +609,5 @@
   if Assigned(frmSurgery) then frmSurgery.ClearPtData;
   frmLabs.ClearPtData;
+  frmGraphData.ClearPtData;
   frmReports.ClearPtData;
   tabPage.TabIndex := PageIDToTab(CT_NOPAGE);       // to make sure DisplayPage gets called
@@ -572,4 +615,5 @@
   ClearReminderData;
   SigItems.Clear;
+  Changes.Clear;
   lstCIRNLocations.Clear;
   uRemoteType := '';
@@ -584,6 +628,13 @@
     DisplayData('top');
     DisplayData('bottom');
-    lstCheck.Items.Clear;
+    GtslCheck.Clear;
     Caption := 'CPRS Graphing - Patient: ' + MixedCase(Patient.Name);
+  end;
+  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.'
+            + '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);
+    frmFrame.Close;
   end;
 end;
@@ -592,4 +643,5 @@
 { updates the display in the header bar of encounter related information (location & provider) }
 begin
+  if DoNotChangeEncWindow = true then exit;
   with Encounter do
   begin
@@ -605,4 +657,9 @@
 end;
 
+function TfrmFrame.DLLActive: boolean;
+begin
+  Result := (VitalsDLLHandle <> 0) or (MHDLLHandle <> 0);
+end;
+
 { Form Events (Create, Destroy) ----------------------------------------------------------- }
 
@@ -618,4 +675,5 @@
   ClientVer, ServerVer, ServerReq: string;
 begin
+  FProccessingNextClick := false;
   FJustEnteredApp := false;
   SizeHolder := TSizeHolder.Create;
@@ -801,4 +859,6 @@
   GraphFloatActive := false;
   GraphContext := '';
+  frmGraphData := TfrmGraphData.Create(self);        // form is only visible for testing
+  GraphDataOnUser;
   uRemoteType := '';
   FPrevPtID := '';
@@ -894,4 +954,5 @@
   Screen.OnActiveFormChange := FOldActiveFormChange;
   FNextButtonBitmap.Free;
+  if FNextButton <> nil then FNextButton.Free;
   uTabList.Free;
   FlaggedPTList.Free;
@@ -1014,4 +1075,10 @@
                  +' Division='+GetDivisionID;
 
+end;
+
+procedure TfrmFrame.compAccessTabPageCaptionQuery(Sender: TObject;
+  var Text: string);
+begin
+  Text := GetTabText;
 end;
 
@@ -1041,7 +1108,4 @@
 
 procedure TfrmFrame.FormClose(Sender: TObject; var Action: TCloseAction);
-//var
-//  i: Integer;
-//  UserTool: TMenuItem;
 begin
   FClosing := TRUE;
@@ -1082,4 +1146,6 @@
     frmLabs.Close;       //frmLabs.Release;
     frmReports.Close;    //frmReports.Release;
+    frmGraphData.Close;  //frmGraphData.Release;
+  
   end;
 //  with mnuTools do for i := Count - 1 downto 0 do
@@ -1202,4 +1268,6 @@
     if NewForm.Name = frmConsults.Name then frmConsults.Align := alClient
       else frmConsults.Align := alNone;
+    if NewForm.Name = frmReports.Name then frmReports.Align := alClient
+      else frmReports.Align := alNone;
     if NewForm.Name = frmDCSumm.Name then frmDCSumm.Align := alClient
       else frmDCSumm.Align := alNone;
@@ -1208,5 +1276,5 @@
         else frmSurgery.Align := alNone;
     NewForm.BringToFront;                    // to cause tab switch to happen immediately
-    NewForm.FocusFirstControl;
+//CQ12232 NewForm.FocusFirstControl;
     Application.ProcessMessages;
     PostMessage(Handle, UM_SHOWPAGE, 0, 0);  // this calls DisplayPage for the form
@@ -1224,9 +1292,14 @@
 procedure TfrmFrame.tabPageChange(Sender: TObject);
 { switches to form linked to NewTab }
-begin
-
+var
+  PageID : integer;
+begin
+  PageID := TabToPageID((sender as TTabControl).TabIndex);
+  if (PageID <> CT_NOPAGE) and (TabPage.CanFocus) and Assigned(FLastPage) and
+     (not TabPage.Focused) then
+    TabPage.SetFocus;  //CQ: 14854
   if (not User.IsReportsOnly) then
   begin
-    case TabToPageID((sender as TTabControl).TabIndex) of
+    case PageID of
       CT_NOPAGE:   SwitchToPage(nil);
       CT_COVER:    SwitchToPage(frmCover);
@@ -1244,5 +1317,6 @@
   else // Reports Only tab.
     SwitchToPage(frmReports);
-
+  if ScreenReaderSystemActive and FCtrlTabUsed then
+    SpeakPatient;
 end;
 
@@ -1307,5 +1381,9 @@
     lblPtName.Caption := Name;
     lblPtSSN.Caption := SSN;
-    lblPtAge.Caption := FormatFMDateTime('mmm dd,yyyy', DOB) + ' (' + IntToStr(Age) + ')';
+//
+    { 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) + ')';
+//
     pnlPatient.Caption := lblPtName.Caption + ' ' + lblPtSSN.Caption + ' ' + lblPtAge.Caption;
     if Length(CWAD) > 0
@@ -1331,5 +1409,5 @@
     begin
       pnlFlag.Enabled := True;
-      lblFlag.Font.Color := clMaroon;
+      lblFlag.Font.Color := Get508CompliantColor(clMaroon);
       lblFlag.Enabled := True;
       if (not FReFreshing) and (TriggerPRFPopUp(Patient.DFN)) then
@@ -1354,4 +1432,5 @@
   Reason: string;
   CCOWResponse: UserResponse;
+  AccessStatus: integer;
 
     procedure UpdatePatientInfoForAlert;
@@ -1371,4 +1450,6 @@
 
 begin
+  DoNotChangeEncWindow := False;
+  mnuFile.Tag := 0;
   SaveDFN := Patient.DFN;
   Notifications.Next;
@@ -1381,5 +1462,6 @@
     begin
       // newdfn does not have new patient.co information for CCOW call
-      if (AllowContextChangeAll(Reason)) then
+      if ((Sender = mnuFileOpen) or (AllowContextChangeAll(Reason)))
+          and AllowAccessToSensitivePatient(NewDFN, AccessStatus) then
       begin
         RemindersStarted := FALSE;
@@ -1421,7 +1503,37 @@
       end else
       begin
-        Patient.DFN := SaveDFN;
-        Notifications.Prior;
-        Exit;
+        if AccessStatus in [DGSR_ASK, DGSR_DENY] then
+        begin
+          Notifications.Clear;
+          // hide the 'next notification' button
+          FNextButtonActive := False;
+          FNextButton.Free;
+          FNextButton := nil;
+          mnuFileNext.Enabled := False;
+          mnuFileNotifRemove.Enabled := False;
+          Patient.DFN := '';
+          mnuFileOpenClick(mnuFileNext);
+          exit;
+        end
+        else
+        if SaveDFN <> '' then
+        begin
+          Patient.DFN := SaveDFN;
+          Notifications.Prior;
+          Exit;
+        end
+        else
+        begin
+          Notifications.Clear;
+(*          // hide the 'next notification' button
+          FNextButtonActive := False;
+          FNextButton.Free;
+          FNextButton := nil;
+          mnuFileNext.Enabled := False;
+          mnuFileNotifRemove.Enabled := False;*)
+          Patient.DFN := '';
+          mnuFileOpenClick(mnuFileNext);
+          exit;
+        end;
       end;
     end;
@@ -1485,4 +1597,7 @@
         end;
     NF_LAB_THRESHOLD_EXCEEDED        : NextIndex := PageIDToTab(CT_LABS);
+    NF_MAMMOGRAM_RESULTS             : NextIndex := PageIDToTab(CT_REPORTS);
+    NF_PAP_SMEAR_RESULTS             : NextIndex := PageIDToTab(CT_REPORTS);
+    NF_ANATOMIC_PATHOLOGY_RESULTS    : NextIndex := PageIDToTab(CT_REPORTS);
     NF_SURGERY_UNSIGNED_NOTE         : if TabExists(CT_SURGERY) then
                                          NextIndex := PageIDToTab(CT_SURGERY)
@@ -1498,5 +1613,4 @@
 end;
 
-
 procedure TfrmFrame.SetBADxList;
 var
@@ -1538,4 +1652,6 @@
 begin
   PtSelCancelled := FALSE;
+  if not FRefreshing then mnuFile.Tag := 0
+  else mnuFile.Tag := 1;
   DetermineNextTab;
 (*  if (FRefreshing or User.UseLastTab) and (not FFirstLoad) then
@@ -1554,5 +1670,6 @@
         PtEvtCompleted(TheCurrentView.EventDelay.PtEventIFN, TheCurrentView.EventDelay.EventName);
     end;*)
-  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 Exit;
      
   // update status text here
@@ -1613,4 +1730,5 @@
         if PtSelCancelled then exit;
         ShowEverything;
+        //HideEverything('Retrieving information - please wait....');  //v27 (pending) RV
         DisplayEncounterText;
         FPrevInPatient := Patient.Inpatient;
@@ -1618,12 +1736,8 @@
         begin
           // display 'next notification' button
+          SetUpNextButton;
           FNextButtonActive := True;
-          with stsArea.Panels[2] do
-          begin
-            //Text := 'Next ->';
-            Bevel := pbRaised;
-          end;
           mnuFileNext.Enabled := True;
-          mnuFileNextClick(Self);
+          mnuFileNextClick(mnuFileOpen);
         end
         else
@@ -1631,9 +1745,6 @@
           // hide the 'next notification' button
           FNextButtonActive := False;
-          with stsArea.Panels[2] do
-          begin
-            //Text := '';
-            Bevel := pbLowered;
-          end;
+          FNextButton.Free;
+          FNextButton := nil;
           mnuFileNext.Enabled := False;
           mnuFileNotifRemove.Enabled := False;
@@ -1699,4 +1810,6 @@
   if  BILLING_AWARE then frmFrame.SetBADxList; //end IsBillingAware
  {End BillingAware}
+ //ShowEverything;  //v27 (pending) RV
+ if not FRefreshing then DoNotChangeEncWindow := false;
  //frmCover.UpdateVAAButton; //VAA CQ7525   CQ#7933 - moved to SetupPatient, before event hook execution (RV)
 end;
@@ -1715,5 +1828,5 @@
   if NextTab = CT_NOPAGE then NextTab := User.InitialTab;
   if User.IsReportsOnly then // Reports Only tab.
-    NextTab := 0; // Only one tab should exist by this point in "REPORTS ONLY" mode.
+    NextTab := CT_REPORTS; // Only one tab should exist by this point in "REPORTS ONLY" mode.
   if not TabExists(NextTab) then NextTab := CT_COVER;
   if NextTab = CT_NOPAGE then NextTab := User.InitialTab;
@@ -1739,4 +1852,6 @@
   NameNeedLook: string;
 begin
+  FReviewClick := True;
+  mnuFile.Tag := 1;
   EventChanges := False;
   NameNeedLook := '';
@@ -1757,4 +1872,6 @@
   end
   else InfoBox('No new changes to review/sign.', 'Review Changes', MB_OK);
+  FOrderPrintForm := false;
+  FReviewClick := false;
 end;
 
@@ -1777,10 +1894,10 @@
      on EAccessViolation do
         begin
-        {$ifdef debug}ShowMessage('Access Violation in procedure TfrmFrame.mnuFileExitClick()');{$endif}
+        {$ifdef debug}Show508Message('Access Violation in procedure TfrmFrame.mnuFileExitClick()');{$endif}
         raise;
         end;
      on E: Exception do
         begin
-        {$ifdef debug}ShowMessage('Unhandled exception in procedure TfrmFrame.mnuFileExitClick()');{$endif}
+        {$ifdef debug}Show508Message('Unhandled exception in procedure TfrmFrame.mnuFileExitClick()');{$endif}
         raise;
         end;
@@ -1856,5 +1973,5 @@
            if Pos('ecs gui.exe',lowerCase(AFile))<1 then
            begin
-             ShowMessage('This is not a valid ECS application.');
+             ShowMsg('This is not a valid ECS application.');
              Result := True;
            end else
@@ -1896,5 +2013,5 @@
            if Pos('ecs gui.exe',lowerCase(AFile))<1 then
            begin
-             ShowMessage('This is not a valid ECS application.');
+             ShowMsg('This is not a valid ECS application.');
              Result := True;
            end else
@@ -1933,5 +2050,5 @@
     if FECSAuthUser then UpdateECSParameter(ECSAppend)
     else begin
-      ShowMessage('You don''t have permission to use ECS.');
+      ShowMsg('You don''t have permission to use ECS.');
       exit;
     end;
@@ -2003,36 +2120,4 @@
 end;
 
-procedure TfrmFrame.stsAreaMouseDown(Sender: TObject; Button: TMouseButton;
-  Shift: TShiftState; X, Y: Integer);
-begin
-  if (FNextButtonActive) and (X > FNextButtonL) and (X < FNextButtonR) then
-  begin
-    stsArea.Panels[2].Bevel := pbLowered;
-    popAlerts.AutoPopup := TRUE;
-  end;
-end;
-
-procedure TfrmFrame.stsAreaMouseUp(Sender: TObject; Button: TMouseButton;
-  Shift: TShiftState; X, Y: Integer);
-begin
-  if FNextButtonActive then
-  begin
-    stsArea.Panels[2].Bevel := pbRaised;
-    popAlerts.AutoPopup := FALSE;
-    if (X > FNextButtonL) and (X < FNextButtonR) then
-      if Button = mbLeft then mnuFileNextClick(Self);
-  end;
-end;
-
-procedure TfrmFrame.stsAreaDrawPanel(StatusBar: TStatusBar; Panel: TStatusPanel;
-  const Rect: TRect);
-begin
-  if FNextButtonActive then with StatusBar.Canvas do
-  begin
-    Draw(Rect.Left + 2, Rect.Top, FNextButtonBitmap);	{ draw bitmap }
-    TextOut(Rect.Left + 20, Rect.Top + 2, 'Next');	  { draw text to the right of the bitmap }
-  end;
-end;
-
 { Toolbar Methods (make panels act like buttons) ------------------------------------------- }
 
@@ -2059,28 +2144,4 @@
 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;
-  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;
-  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.pnlPrimaryCareMouseDown(Sender: TObject;
   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
@@ -2122,5 +2183,4 @@
 var
   s1, s2, s3, s4, Dummy: integer;
-
   panelBottom, panelMedIn : integer;
 
@@ -2140,4 +2200,7 @@
   SetUserColumns(TControl(frmMeds.hdrMedsIn));  // still need conversion
   SetUserColumns(TControl(frmMeds.hdrMedsOut));
+  SetUserBounds2(TemplateEditorSplitters, tmplEditorSplitterMiddle,
+                 tmplEditorSplitterProperties, tmplEditorSplitterMain, tmplEditorSplitterBoil);
+  SetUserBounds2(TemplateEditorSplitters2, tmplEditorSplitterNotes, Dummy, Dummy, Dummy);
   SetUserBounds2(ReminderTreeName, RemTreeDlgLeft, RemTreeDlgTop, RemTreeDlgWidth, RemTreeDlgHeight);
   SetUserBounds2(RemDlgName, RemDlgLeft, RemDlgTop, RemDlgWidth, RemDlgHeight);
@@ -2209,4 +2272,7 @@
       Add(StrUserColumns(frmMeds.hdrMedsIn));
       Add(StrUserColumns(frmMeds.hdrMedsOut));
+      Add(StrUserBounds2(TemplateEditorSplitters, tmplEditorSplitterMiddle,
+              tmplEditorSplitterProperties, tmplEditorSplitterMain, tmplEditorSplitterBoil));
+      Add(StrUserBounds2(TemplateEditorSplitters2, tmplEditorSplitterNotes, 0, 0, 0));
       Add(StrUserBounds2(ReminderTreeName, RemTreeDlgLeft, RemTreeDlgTop, RemTreeDlgWidth, RemTreeDlgHeight));
       Add(StrUserBounds2(RemDlgName, RemDlgLeft, RemDlgTop, RemDlgWidth, RemDlgHeight));
@@ -2274,6 +2340,13 @@
     FNextButtonR := FNextButtonL + Panels[2].Width;
   end;
+  if Notifications.Active then SetUpNextButton;
   lstCIRNLocations.Left  := FNextButtonL - ScrollBarWidth - 100;
   lstCIRNLocations.Width := ClientWidth - lstCIRNLocations.Left;
+  //cq: 15641
+  if frmFrame.FNextButtonActive then // keeps button alligned if cancel is pressed
+  begin
+    FNextButton.Left := FNextButtonL;
+    FNextButton.Top := stsArea.Top;
+  end;
   Self.Repaint;
 end;
@@ -2307,5 +2380,5 @@
       with lblPtCWAD     do Font.Size := NewFontSize;
       with lblCIRN       do Font.Size := NewFontSize;
-      with lblCIRNData   do Font.Size := NewFontSize;
+      with lblVistaWeb   do Font.Size := NewFontSize;
       with lstCIRNLocations do Font.Size := NewFontSize;
       with tabPage       do Font.Size := NewFontSize;
@@ -2313,4 +2386,6 @@
       with laVAA2        do Font.Size := NewFontSize; //VAA
 
+      frmFrameHeight := frmFrame.Height;
+      pnlPatientSelectedHeight := pnlPatientSelected.Height;
       tabPage.Height := MainFontHeight + TAB_VOFFSET;   // resize tab selector
       FitToolbar;                                       // resize toolbar
@@ -2341,11 +2416,4 @@
   end;
 
-  //remove CWAD color if using high-contrast colors
-  if ColorToRGB(clWindowText) <> ColorToRGB(clBlack) then
-  begin
-    lblPtCWAD.Font.Color := clWindowText;
-    lblFlag.Font.Color   := clWindowText;
-  end;
-
   case (NewFontSize) of
    8: mnu8pt.Checked := true;
@@ -2354,5 +2422,4 @@
   14: mnu14pt1.Checked := true;
   18: mnu18pt1.Checked := true;
-  24: mnu24pt1.Checked := true;
   end;
 
@@ -2378,11 +2445,17 @@
 { resizes and repositions the panels & labels used in the toolbar }
 const
-  PATIENT_WIDTH = 29;
+{ TODO -oRV -cWVEHR Long Age : Change to 40, to fit long age }
+  //PATIENT_WIDTH = 29;
+  PATIENT_WIDTH = 40;
+{}
   VISIT_WIDTH   = 36;
   POSTING_WIDTH = 11.5;
   FLAG_WIDTH    = 5;
-  CIRN_WIDTH    = 7;
+  CIRN_WIDTH    = 11;
   MHV_WIDTH     = 6;
-  LINES_HIGH    = 2;
+{ TODO -oRV -cWVEHR Long Age : Change to 3 lines high, to fit long age }
+  //LINES_HIGH    = 2;
+  LINES_HIGH    = 3;
+{}
   M_HORIZ       = 4;
   M_MIDDLE      = 2;
@@ -2393,9 +2466,18 @@
   //WidthNeeded: integer;
 begin
-  pnlToolbar.Height  := (LINES_HIGH * lblPtName.Height) + M_HORIZ + M_MIDDLE + M_HORIZ;
+//
+  { 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;
+//
   pnlPatient.Width   := HigherOf(PATIENT_WIDTH * MainFontWidth, lblPtName.Width + (M_WVERT * 2));
   lblPtSSN.Top       := M_HORIZ + lblPtName.Height + M_MIDDLE;
-  lblPtAge.Top       := lblPtSSN.Top;
-  lblPtAge.Left      := pnlPatient.Width - lblPtAge.Width - M_WVERT;
+//
+  { 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;
+//
   pnlVisit.Width     := HigherOf(LowerOf(VISIT_WIDTH * MainFontWidth,
                                          HigherOf(lblPtProvider.Width + (M_WVERT * 2),
@@ -2404,10 +2486,10 @@
   lblPtProvider.Top  := lblPtSSN.Top;
   lblPtAttending.Top := lblPtSSN.Top;
-  lblCIRNData.Top    := lblPtSSN.Top;
   pnlPostings.Width  := Round(POSTING_WIDTH * MainFontWidth);
   pnlFlag.Width      := Round(FLAG_WIDTH * MainFontWidth);
   pnlFlag.Width      := Round(FLAG_WIDTH * MainFontWidth);
-  pnlCIRN.Width      := Round(CIRN_WIDTH * MainFontWidth) + M_WVERT;
-  paVAA.Width        := Round(MHV_WIDTH * MainFontWidth) + M_WVERT;
+  pnlRemoteData.Width := Round(CIRN_WIDTH * MainFontWidth) + M_WVERT;
+  pnlVistaWeb.Height := pnlRemoteData.Height div 2;
+  paVAA.Width        := Round(MHV_WIDTH * MainFontWidth) + M_WVERT + 2;
   with lblPtPostings do
     SetBounds(M_WVERT, M_HORIZ, pnlPostings.Width-M_WVERT-M_WVERT, lblPtName.Height);
@@ -2452,8 +2534,8 @@
 begin
   if (frmRemDlg <> nil) then
-    ShowMessage('Please close the reminder dialog before changing font sizes.')
+    ShowMsg('Please close the reminder dialog before changing font sizes.')
   else
      if (dlgProbs <> nil) then
-    ShowMessage('Font size cannot be changed while adding or editing a problem.')
+    ShowMsg('Font size cannot be changed while adding or editing a problem.')
   else
      begin
@@ -2691,115 +2773,34 @@
   ASite: TRemoteSite;
 begin
+  uUseVistaWeb := false;
   with RemoteSites do
-  if UseVistaWeb then
-    begin
-      ChangePatient(Patient.DFN);
-      lblCIRN.Caption := 'Remote';      //VistaWeb On
-      lblCIRNData.Caption := 'Data*';
-      pnlCIRN.Caption := 'Remote Data';
-      lblCIRN.Width := 43;
-      lblCIRNData.Width := 43;
-      lblCIRNData.Alignment := taCenter;
-      lblCIRN.Alignment := taCenter;
-      lblCIRN.Enabled     := True;
-      lblCIRNData.Enabled := True;
-      lblCIRNAvail.Enabled := True;
-      pnlCIRN.TabStop     := True;
-      if RemoteDataExists and (RemoteSites.Count > 0) then
-        begin
-          lblCIRN.Enabled     := True;
-          lblCIRNData.Enabled := True;
-          lblCIRNAvail.Enabled := True;
-          pnlCIRN.TabStop     := True;
-          if ColorToRGB(clWindowText) = ColorToRGB(clBlack) then
-            begin
-              lblCIRN.Font.Color  := clBlue;
-              lblCIRNData.Font.Color  := clBlue;
-              lblCIRNAvail.Font.Color := clBlue;
-              lstCIRNLocations.Font.Color  := clBlue;
-              lblCIRN.Caption := 'Remote';
-              lblCIRNData.Caption := 'Data*';
-              lblCIRNAvail.Caption := 'Available';
-              pnlCIRN.Caption := 'Remote Data Available';
-            end
-          else
-            begin
-              lblCIRN.Font.Color  := clWindowText;
-              lblCIRNData.Font.Color  := clWindowText;
-              lblCIRNAvail.Font.Color := clWindowText;
-              lstCIRNLocations.Font.Color  := clWindowText;
-            end;
-        end
-      else
-        begin
-          lblCIRN.Font.Color  := clWindowText;
-          lblCIRNData.Font.Color  := clWindowText;
-          lblCIRNAvail.Font.Color := clWindowText;
-          lblCIRN.Enabled     := False;
-          lblCIRNData.Enabled := False;
-          lblCIRNAvail.Enabled := False;
-          pnlCIRN.TabStop     := False;
-          pnlCIRN.Hint := NoDataReason;
-        end;
-      pnlCIRN.Hint := 'Click to open VistaWeb';
-    end
-  else
-    begin
-      ChangePatient(Patient.DFN);
-      lblCIRN.Caption := ' Remote';
-      lblCIRNData.Caption := 'Data';
-      pnlCIRN.Caption := 'Remote Data';
-      lblCIRNAvail.Caption := '';
-      lblCIRN.Width := 43;
-      lblCIRNData.Width := 43;
-      lblCIRNData.Alignment := taCenter;
-      lblCIRN.Alignment := taCenter;
-      if RemoteDataExists and (RemoteSites.Count > 0) then
-        begin
-          lblCIRN.Enabled     := True;
-          lblCIRNData.Enabled := True;
-          lblCIRNAvail.Enabled := True;
-          pnlCIRN.TabStop     := True;
-          if ColorToRGB(clWindowText) = ColorToRGB(clBlack) then
-            begin
-              lblCIRN.Font.Color  := clBlue;
-              lblCIRNData.Font.Color  := clBlue;
-              lblCIRNAvail.Font.Color := clBlue;
-              lstCIRNLocations.Font.Color  := clBlue;
-              lblCIRN.Caption := 'Remote';
-              lblCIRNData.Caption := 'Data';
-              lblCIRNAvail.Caption := 'Available';
-              pnlCIRN.Caption := 'Remote Data Available';
-            end
-          else
-            begin
-              lblCIRN.Font.Color  := clWindowText;
-              lblCIRNData.Font.Color  := clWindowText;
-              lblCIRNAvail.Font.Color := clWindowText;
-              lstCIRNLocations.Font.Color  := clWindowText;
-              lblCIRNAvail.Color := clWindowText;
-            end;
-          pnlCIRN.Hint := 'Click to display other facilities having data for this patient.';
-          lstCIRNLocations.Items.Add('-1' + U + 'Use VistaWeb from now on');
-          if RemoteSites.Count > 0 then
-            lstCIRNLocations.Items.Add('0' + U + 'All Available Sites');
-          for i := 0 to RemoteSites.Count - 1 do
-            begin
-              ASite := TRemoteSite(SiteList[i]);
-              lstCIRNLocations.Items.Add(ASite.SiteID + U + ASite.SiteName + U +
-                FormatFMDateTime('mmm dd yyyy hh:nn', ASite.LastDate));
-            end;
-        end
-      else
-        begin
-          lblCIRN.Font.Color  := clWindowText;
-          lblCIRNData.Font.Color  := clWindowText;
-          lblCIRNAvail.Font.Color := clWindowText;
-          lblCIRN.Enabled     := False;
-          lblCIRNData.Enabled := False;
-          lblCIRNAvail.Enabled := False;
-          pnlCIRN.TabStop     := False;
-          pnlCIRN.Hint := NoDataReason;
-        end;
+  begin
+    ChangePatient(Patient.DFN);
+    lblCIRN.Caption := ' Remote Data';
+    lblCIRN.Alignment := taCenter;
+    if RemoteDataExists and (RemoteSites.Count > 0) then
+      begin
+        lblCIRN.Enabled     := True;
+        pnlCIRN.TabStop     := True;
+        lblCIRN.Font.Color  := Get508CompliantColor(clBlue);
+        lstCIRNLocations.Font.Color  := Get508CompliantColor(clBlue);
+        lblCIRN.Caption := 'Remote Data';
+        pnlCIRN.Hint := 'Click to display other facilities having data for this patient.';
+        if RemoteSites.Count > 0 then
+          lstCIRNLocations.Items.Add('0' + U + 'All Available Sites');
+        for i := 0 to RemoteSites.Count - 1 do
+          begin
+            ASite := TRemoteSite(SiteList[i]);
+            lstCIRNLocations.Items.Add(ASite.SiteID + U + ASite.SiteName + U +
+              FormatFMDateTime('mmm dd yyyy hh:nn', ASite.LastDate));
+          end;
+      end
+    else
+      begin
+        lblCIRN.Font.Color  := clWindowText;
+        lblCIRN.Enabled     := False;
+        pnlCIRN.TabStop     := False;
+        pnlCIRN.Hint := NoDataReason;
+      end;
     aAutoQuery := AutoRDV;        //Check to see if Remote Queries should be used for all available sites
     if (aAutoQuery = '1') and (lstCIRNLocations.Count > 0) then
@@ -2813,47 +2814,9 @@
 
 procedure TfrmFrame.pnlCIRNClick(Sender: TObject);
-//var
-//  aAddress: string;
-begin
-  {if UseVistaWeb then
-    begin
-      pnlCIRN.BevelOuter := bvRaised;
-      pnlCIRN.Hint := 'Click to open VistaWeb';
-      lblCIRN.Width := 43;
-      lblCIRNData.Width := 43;
-      lblCIRNData.Alignment := taCenter;
-      lblCIRN.Alignment := taCenter;
-      lstCIRNLocations.Visible := false;
-      lstCIRNLocations.SendToBack;
-      aAddress := GetVistaWebAddress(Patient.DFN);
-      ShellExecute(Handle, 'open', PChar(aAddress), PChar(''), '', SW_NORMAL);
-      Exit;
-    end;
-  if not RemoteSites.RemoteDataExists then Exit;
-  if (not lstCIRNLocations.Visible) then
-    begin
-      pnlCIRN.BevelOuter := bvLowered;
-      lstCIRNLocations.Visible := True;
-      lstCIRNLocations.BringToFront;
-      lstCIRNLocations.SetFocus;
-      pnlCIRN.Hint := 'Click to close list.';
-    end
-  else
-    begin
-      pnlCIRN.BevelOuter := bvRaised;
-      lstCIRNLocations.Visible := False;
-      lstCIRNLocations.SendToBack;
-      pnlCIRN.Hint := 'Click to display other facilities having data for this patient.';
-    end }
+begin
   ViewInfo(mnuViewRemoteData);
 end;
 
 procedure TfrmFrame.lstCIRNLocationsClick(Sender: TObject);
-const
-  DGSR_FAIL = -1;
-  DGSR_NONE =  0;
-  DGSR_SHOW =  1;
-  DGSR_ASK  =  2;
-  DGSR_DENY =  3;
 var
   iIndex,j,iAll,iCur: integer;
@@ -2864,61 +2827,4 @@
   AccessStatus := 0;
   iIndex := lstCIRNLocations.ItemIndex;
-  if iIndex = 0 then
-    if (piece(lstCIRNLocations.Items[0],'^',1) = '-1') and (lstCIRNLocations.Checked[iIndex] = true) then
-      begin
-        if MessageDlg('Are you sure you want to make VistaWeb your default for viewing Remote Data?',
-          mtConfirmation, [mbYes, mbNo], 0) = mrYes then
-          begin
-            ChangeVistaWebParam('1');
-            lblCIRN.Caption := 'Remote';          //VistaWeb On
-            lblCIRNData.Caption := 'Data*';
-            pnlCIRN.Caption := 'Remote Data';
-            lblCIRNAvail.Caption := '';
-            lblCIRN.Width := 43;
-            lblCIRNData.Width := 43;
-            lblCIRNData.Alignment := taCenter;
-            lblCIRN.Alignment := taCenter;
-            with RemoteSites do if RemoteDataExists and (RemoteSites.Count > 0) then
-              begin
-                lblCIRN.Enabled     := True;
-                lblCIRNData.Enabled := True;
-                pnlCIRN.TabStop     := True;
-                if ColorToRGB(clWindowText) = ColorToRGB(clBlack) then
-                  begin
-                    lblCIRN.Font.Color  := clBlue;
-                    lblCIRNData.Font.Color  := clBlue;
-                    lstCIRNLocations.Font.Color  := clBlue;
-                    lblCIRN.Caption := 'Remote';
-                    lblCIRNData.Caption := 'Data*';
-                    lblCIRNAvail.Caption := 'Available';
-                    pnlCIRN.Caption := 'Remote Data Available';
-                  end
-                else
-                  begin
-                    lblCIRN.Font.Color  := clWindowText;
-                    lblCIRNData.Font.Color  := clWindowText;
-                    lstCIRNLocations.Font.Color  := clWindowText;
-                    lblCIRNAvail.Font.Color := clWindowText;
-                  end;
-              end;
-            pnlCIRNClick(self);
-            Exit;
-          end
-        else
-          lstCIRNLocations.Checked[iIndex] := false;
-      end
-    else
-      begin
-        ChangeVistaWebParam('0');
-        lblCIRN.Caption := 'Remote';
-        lblCIRNData.Caption := 'Data';
-        pnlCIRN.Caption := 'Remote Data';
-        lblCIRN.Width := 43;
-        lblCIRNData.Width := 43;
-        lblCIRNData.Alignment := taCenter;
-        lblCIRN.Alignment := taCenter;
-        pnlCIRNClick(self);
-        Exit;
-      end;
   if not CheckHL7TCPLink then
     begin
@@ -2949,7 +2855,7 @@
         with RemoteSites.SiteList do
         for j := 0 to Count - 1 do
-          if lstCIRNLocations.Checked[j+2] = true then
+          if lstCIRNLocations.Checked[j+1] = true then
             begin
-              lstCIRNLocations.Checked[j+2] := false;
+              lstCIRNLocations.Checked[j+1] := false;
               TRemoteSite(RemoteSites.SiteList[j]).Selected := false;
               TRemoteSite(RemoteSites.SiteList[j]).ReportClear;
@@ -2967,11 +2873,11 @@
               Screen.Cursor := crDefault;
               aMsg := aMsg + ' at site: ' + TRemoteSite(Items[j]).SiteName;
-              s := lstCIRNLocations.Items[j+2];
-              lstCIRNLocations.Items[j+2] := pieces(s, '^', 1, 3);
+              s := lstCIRNLocations.Items[j+1];
+              lstCIRNLocations.Items[j+1] := pieces(s, '^', 1, 3);
               case AccessStatus of
               DGSR_FAIL: begin
                            if piece(aMsg,':',1) = 'RPC name not found at site' then //Allow for backward compatibility
                              begin
-                               lstCIRNLocations.Checked[j+2] := true;
+                               lstCIRNLocations.Checked[j+1] := true;
                                TRemoteSite(RemoteSites.SiteList[j]).ReportClear;
                                TRemoteSite(RemoteSites.SiteList[j]).LabClear;
@@ -2981,6 +2887,6 @@
                              begin
                                InfoBox(aMsg, TC_DGSR_ERR, MB_OK);
-                               lstCIRNLocations.Checked[j+2] := false;
-                               lstCIRNLocations.Items[j+2] := pieces(s, '^', 1, 3) + '^' + TC_DGSR_ERR;
+                               lstCIRNLocations.Checked[j+1] := false;
+                               lstCIRNLocations.Items[j+1] := pieces(s, '^', 1, 3) + '^' + TC_DGSR_ERR;
                                TRemoteSite(Items[j]).Selected := false;
                                Continue;
@@ -2988,5 +2894,5 @@
                          end;
               DGSR_NONE: begin
-                           lstCIRNLocations.Checked[j+2] := true;
+                           lstCIRNLocations.Checked[j+1] := true;
                            TRemoteSite(RemoteSites.SiteList[j]).ReportClear;
                            TRemoteSite(RemoteSites.SiteList[j]).LabClear;
@@ -2995,5 +2901,5 @@
               DGSR_SHOW: begin
                            InfoBox(AMsg, TC_DGSR_SHOW, MB_OK);
-                           lstCIRNLocations.Checked[j+2] := true;
+                           lstCIRNLocations.Checked[j+1] := true;
                            TRemoteSite(RemoteSites.SiteList[j]).ReportClear;
                            TRemoteSite(RemoteSites.SiteList[j]).LabClear;
@@ -3003,5 +2909,5 @@
                            MB_DEFBUTTON2) = IDYES then
                            begin
-                             lstCIRNLocations.Checked[j+2] := true;
+                             lstCIRNLocations.Checked[j+1] := true;
                              TRemoteSite(RemoteSites.SiteList[j]).ReportClear;
                              TRemoteSite(RemoteSites.SiteList[j]).LabClear;
@@ -3010,6 +2916,6 @@
                            else
                              begin
-                               lstCIRNLocations.Checked[j+2] := false;
-                               lstCIRNLocations.Items[j+2] := pieces(s, '^', 1, 3) + '^' + TC_DGSR_SHOW;
+                               lstCIRNLocations.Checked[j+1] := false;
+                               lstCIRNLocations.Items[j+1] := pieces(s, '^', 1, 3) + '^' + TC_DGSR_SHOW;
                                TRemoteSite(Items[j]).Selected := false;
                                Continue;
@@ -3017,6 +2923,6 @@
               else       begin
                            InfoBox(AMsg, TC_DGSR_DENY, MB_OK);
-                           lstCIRNLocations.Checked[j+2] := false;
-                           lstCIRNLocations.Items[j+2] := pieces(s, '^', 1, 3) + '^' + TC_DGSR_DENY;
+                           lstCIRNLocations.Checked[j+1] := false;
+                           lstCIRNLocations.Items[j+1] := pieces(s, '^', 1, 3) + '^' + TC_DGSR_DENY;
                            TRemoteSite(Items[j]).Selected := false;
                            Continue;
@@ -3100,8 +3006,14 @@
                     end;
               with frmLabs do
-                if lstReports.ItemIndex > -1 then
+                if piece(uRemoteType,'^',1) = '1' then
+                  if not(piece(uRemoteType,'^',2) = 'V') then
+                    begin
+                      TabControl1.Visible := true;
+                      pnlRightTop.Height := lblTitle.Height + TabControl1.Height;
+                    end;
+                {if lstReports.ItemIndex > -1 then
                   if piece(lstReports.Items[lstReports.ItemIndex],'^',3) = '1' then
                     if not(piece(lstReports.Items[lstReports.ItemIndex],'^',5) = 'V') then
-                      TabControl1.Visible := true;
+                      TabControl1.Visible := true;}
             end;
         end;
@@ -3116,8 +3028,8 @@
             TRemoteSite(Items[j]));
         end;
-  //frmLabs.TabControl1.OnChange(nil);
-  //frmReports.TabControl1.OnChange(nil);
+
   if frmReports.tvReports.SelectionCount > 0 then frmReports.tvReportsClick(self);
-  if frmLabs.lstReports.ItemIndex > -1 then frmLabs.ExtlstReportsClick(self, true);
+  if frmLabs.tvReports.SelectionCount > 0 then frmLabs.tvReportsClick(self);
+  //if frmLabs.lstReports.ItemIndex > -1 then frmLabs.ExtlstReportsClick(self, true);
   StatusText('');
 end;
@@ -3234,5 +3146,4 @@
 begin
   LoadSizesForUser;
-//  LoadUserVitalPreferences;
   GetUserTemplateDefaults(TRUE);
 end;
@@ -3241,5 +3152,4 @@
 begin
   SaveSizesForUser;         // position & size settings
-//  SaveUserVitalPreferences; // save Vitals metric setting
   SaveUserTemplateDefaults;
 end;
@@ -3248,4 +3158,5 @@
 begin
   FRefreshing := TRUE;
+
   try
     mnuFileOpenClick(Self);
@@ -3260,4 +3171,6 @@
     FOldActivate(Sender);
   SetActiveWindow(Application.Handle);
+  if ScreenReaderSystemActive and assigned(Patient) and (Patient.Name <> '') then
+      SpeakTabAndPatient;
 end;
 
@@ -3283,12 +3196,4 @@
 end;
 
-(*procedure TfrmFrame.CreateTab(var AnInstance: TObject; AClass: TClass; ATabID: integer; ALabel: string);
-begin
-  AnInstance := TPage.Create(Self);
-  TPage(AnInstance).Parent := pnlPage;
-  TPage(AnInstance).Show;
-  uTabList.Add(IntToStr(ATabID));
-  tabPage.Tabs.Add(ALabel);
-end;*)
 
 procedure TfrmFrame.CreateTab(ATabID: integer; ALabel: string);
@@ -3388,14 +3293,7 @@
 
 // Top panel components:
-//pnlVisit.visible := false;
 pnlVisit.hint := 'Provider/Location';
 pnlVisit.onMouseDown := nil;
 pnlVisit.onMouseUp := nil;
-//pnlPrimaryCare.visible := false;
-//pnlPostings.visible := false;
-//lblPtCWAD.visible := false;
-//lblPtPostings.visible := false;
-//pnlReminders.visible := false;
-//anmtRemSearch.visible := false;
 
 // Forms for other tabs:
@@ -3426,7 +3324,39 @@
   uCore.TempEncounterLoc := 0;  //hds7591  Clinic/Ward movement.
   uCore.TempEncounterLocName := ''; //hds7591  Clinic/Ward movement.
-
+  uCore.TempEncounterText := '';
+  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
-    Encounter.Location := Patient.Location
+    begin
+     // if DoNotChangeEncWindow = false then
+     //   begin
+          if FReviewClick = True then
+            begin
+              ucore.TempEncounterLoc := Encounter.Location;
+              uCore.TempEncounterLocName := Encounter.LocationName;
+              uCore.TempEncounterText := Encounter.LocationText;
+              uCore.TempEncounterDateTime := Encounter.DateTime;
+              uCore.TempEncounterVistCat := Encounter.VisitCategory;
+            end
+          else if (patient.Location <> encounter.Location) and (OrderPrintForm = false) then
+                begin
+                  frmPrintLocation.SwitchEncounterLoction(Encounter.Location, Encounter.locationName, Encounter.LocationText,
+                                                          Encounter.DateTime, Encounter.VisitCategory);
+                  DisplayEncounterText;
+                  exit;
+                end
+          else if (patient.Location <> encounter.Location) and (OrderPrintForm = True) then
+            begin
+              OrderPrintForm := false;
+              Exit;
+            end;
+               
+            //end;
+          Encounter.Location := Patient.Location;
+       // end;
+    end
   else if (FPrevInPatient and (not Patient.Inpatient)) then     //patient was discharged
   begin
@@ -3440,7 +3370,17 @@
     uCore.TempEncounterLoc := Encounter.Location;  //hds7591  Clinic/Ward movement.
     uCore.TempEncounterLocName := Encounter.LocationName; //hds7591  Clinic/Ward movement.
-    Encounter.Location := Patient.Location;
-    Encounter.DateTime := Patient.AdmitTime;
-    Encounter.VisitCategory := 'H';
+    uCore.TempEncounterText := Encounter.LocationText;
+    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)
+    else
+    //if DoNotChangeEncWindow = false then
+      begin
+        Encounter.Location := Patient.Location;
+        Encounter.DateTime := Patient.AdmitTime;
+        Encounter.VisitCategory := 'H';
+      end;
     FPrevInPatient := True;
   end;
@@ -3453,4 +3393,6 @@
   NewTabIndex: integer;
 begin
+  inherited;
+  FCtrlTabUsed := FALSE;
   //CQ2844: Toggle Remote Data button using Alt+R
    case Key of
@@ -3459,6 +3401,9 @@
      end;
 
-  if (Key = VK_TAB) then begin
-    if (ssCtrl in Shift) then begin
+  if (Key = VK_TAB) then
+  begin
+    if (ssCtrl in Shift) then
+    begin
+      FCtrlTabUsed := TRUE;
       if not (ActiveControl is TCustomMemo) or not TMemo(ActiveControl).WantTabs then begin
         NewTabIndex := tabPage.TabIndex;
@@ -3518,12 +3463,44 @@
 procedure TfrmFrame.pnlPatientClick(Sender: TObject);
 begin
+  pnlPatient.Enabled := false;
   ViewInfo(mnuViewDemo);
+  pnlPatient.Enabled := true;
 end;
 
 procedure TfrmFrame.pnlVisitClick(Sender: TObject);
 begin
- //if (not User.IsReportsOnly) then // Reports Only tab.
- //  mnuFileEncounterClick(Self);
+  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);
+
   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;
 
@@ -3551,5 +3528,5 @@
 begin
   {$ifdef DEBUG}
-    ShowMessage(AMessage);
+    Show508Message(AMessage);
   {$endif}
   InfoBox(TX_CCOW_ERROR, TC_CCOW_ERROR, MB_ICONERROR or MB_OK);
@@ -3649,5 +3626,5 @@
     begin
       // New context is committed.
-      //ShowMessage('Response was Commit');
+      //Show508Message('Response was Commit');
       mnuFileResumeContext.Enabled := False;
       mnuFileBreakContext.Enabled := True;
@@ -3692,6 +3669,6 @@
   except
     on exc : EOleException do
-      //ShowMessage('EOleException: ' + exc.Message + ' - ' + string(exc.ErrorCode) );
-      ShowMessage('EOleException: ' + exc.Message);
+      //Show508Message('EOleException: ' + exc.Message + ' - ' + string(exc.ErrorCode) );
+      ShowMsg('EOleException: ' + exc.Message);
   end;
 end;
@@ -3754,5 +3731,10 @@
     Sleep(12000)
   else if Length(Reason) > 0 then
-    ctxContextor.SetSurveyResponse(Reason);
+    ctxContextor.SetSurveyResponse(Reason)
+  else
+    begin
+      imgCCOW.Picture.BitMap.LoadFromResourceName(hInstance, 'BMP_CCOW_LINKED');
+      pnlCCOW.Hint := TX_CCOW_LINKED;
+    end;
   FCCOWContextChanging := False;
 end;
@@ -3788,4 +3770,5 @@
   end;
   if not PtChanged then exit;
+  // HideEverything('Retrieving information - please wait....'); // v27 (pending) RV
   FCCOWDrivedChange := True;
   i := 0;
@@ -3804,4 +3787,5 @@
   pnlCCOW.Hint := TX_CCOW_LINKED;
   imgCCOW.Picture.BitMap.LoadFromResourceName(hInstance, FCCOWIconName);
+  // ShowEverything;    // v27 (pending) RV
 end;
 
@@ -3870,4 +3854,5 @@
 begin
   if not FCCOWInstalled then exit;
+  DoNotChangeEncWindow := false;
   //PtDFN := FindBestCCOWDFN(PtName);
   PtDFN := FindBestCCOWDFN;
@@ -3940,10 +3925,13 @@
   if FCCOWError then exit;
   UpdateCCOWContext;
-  FCCOWIconName := 'BMP_CCOW_LINKED';
-  pnlCCOW.Hint := TX_CCOW_LINKED;
-  imgCCOW.Picture.BitMap.LoadFromResourceName(hInstance, FCCOWIconName);
-  mnuFileResumeContext.Enabled := False;
-  mnuFileBreakContext.Visible := True;
-  mnuFileBreakContext.Enabled := True;
+  if not FNoPatientSelected then
+  begin
+    FCCOWIconName := 'BMP_CCOW_LINKED';
+    pnlCCOW.Hint := TX_CCOW_LINKED;
+    imgCCOW.Picture.BitMap.LoadFromResourceName(hInstance, FCCOWIconName);
+    mnuFileResumeContext.Enabled := False;
+    mnuFileBreakContext.Visible := True;
+    mnuFileBreakContext.Enabled := True;
+  end;
 end;
 
@@ -4052,7 +4040,8 @@
 end;
 
-procedure TfrmFrame.HideEverything;
+procedure TfrmFrame.HideEverything(AMessage: string = 'No patient is currently selected.');
 begin
   FNoPatientSelected := TRUE;
+  pnlNoPatientSelected.Caption := AMessage;
   pnlNoPatientSelected.Visible := True;
   pnlNoPatientSelected.BringToFront;
@@ -4071,4 +4060,5 @@
   mnuView.Enabled := False;
   mnuTools.Enabled := False;
+  if FNextButtonActive then FNextButton.Visible := False;
 end;
 
@@ -4076,4 +4066,5 @@
 begin
   FNoPatientSelected := FALSE;
+  pnlNoPatientSelected.Caption := '';
   pnlNoPatientSelected.Visible := False;
   pnlNoPatientSelected.SendToBack;
@@ -4101,4 +4092,5 @@
   mnuView.Enabled := True;
   mnuTools.Enabled := True;
+  if FNextButtonActive then FNextButton.Visible := True;
 end;
 
@@ -4261,5 +4253,8 @@
       begin
         if btnClose.Tag = 1 then
-          Exit;
+        begin
+          Screen.Cursor := crDefault;
+          exit;
+        end;
         Initialize;
         Caption := 'CPRS Graphing - Patient: ' + MixedCase(Patient.Name);
@@ -4282,31 +4277,38 @@
     end;
   end
-  else if GraphFloat.btnClose.Tag = 1 then
-    Exit
-  else if GraphFloatActive and (GraphFloat.lstTypes.Hint = Patient.DFN) then
-    GraphFloat.BringToFront             // graph is active, same patient
-  else if GraphFloat.lstTypes.Hint = Patient.DFN then
-  begin                                 // graph is not active, same patient
-    // context sensitive
-    GraphFloat.Show;
-    GraphFloatActive := true;
-  end
   else
-  //with GraphFloat do                    // new patient
-  begin
-    GraphFloat.InitialRetain;
-    GraphFloatActive := false;
-    GraphFloat.Free;
-    GraphFloat := nil;
-    mnuToolsGraphingClick(self);          // delete and recurse
-    {//FormCreate(self);   //****************
-    Initialize;
-    DisplayData('top');
-    DisplayData('bottom');
-    lstCheck.Items.Clear;
-    Caption := 'CPRS Graphing - Patient: ' + MixedCase(Patient.Name);
-    // context sensitive
-    Show;
-    GraphFloatActive := true;}
+  begin
+    GraphFloat.Caption := 'CPRS Graphing - Patient: ' + MixedCase(Patient.Name);
+    if GraphFloat.btnClose.Tag = 1 then
+    begin
+      Screen.Cursor := crDefault;
+      exit;
+    end
+    else if GraphFloatActive and (frmGraphData.pnlData.Hint = Patient.DFN) then
+      GraphFloat.BringToFront             // graph is active, same patient
+    else if frmGraphData.pnlData.Hint = Patient.DFN then
+    begin                                 // graph is not active, same patient
+      // context sensitive
+      GraphFloat.Show;
+      GraphFloatActive := true;
+    end
+    else
+    //with GraphFloat do                    // new patient
+    begin
+      GraphFloat.InitialRetain;
+      GraphFloatActive := false;
+      GraphFloat.Free;
+      GraphFloat := nil;
+      mnuToolsGraphingClick(self);          // delete and recurse
+      {//FormCreate(self);   //****************
+      Initialize;
+      DisplayData('top');
+      DisplayData('bottom');
+      GtslCheck.Clear;
+      Caption := 'CPRS Graphing - Patient: ' + MixedCase(Patient.Name);
+      // context sensitive
+      Show;
+      GraphFloatActive := true;}
+    end;
   end;
   Screen.Cursor := crDefault;
@@ -4354,4 +4356,5 @@
   ReportString: TStringList;
   aAddress: string;
+
 begin
   case (Sender as TMenuItem).Tag of
@@ -4378,5 +4381,7 @@
         if fCover.VAAFlag[0] <> '0' then //'0' means subscriber not found
         begin
-          InsuranceSubscriberName := fCover.VAAFlag[12];
+         //  CQ:15534-GE  Remove leading spaces from Patient Name
+          InsuranceSubscriberName := ( (Piece(fCover.VAAFlag[12],':',1)) + ':  ' +
+                                     (TRIM(Piece(fCover.VAAFlag[12],':',2)) ));//fCover.VAAFlag[12];
           ReportString := VAAFlag;
           ReportString[0] := '';
@@ -4388,11 +4393,7 @@
       end;
     7:begin
-        if UseVistaWeb then
+        if uUseVistaWeb = true then
           begin
             pnlCIRN.BevelOuter := bvRaised;
-            pnlCIRN.Hint := 'Click to open VistaWeb';
-            lblCIRN.Width := 43;
-            lblCIRNData.Width := 43;
-            lblCIRNData.Alignment := taCenter;
             lblCIRN.Alignment := taCenter;
             lstCIRNLocations.Visible := false;
@@ -4441,5 +4442,51 @@
 end;
 
+procedure TfrmFrame.SetActiveTab(PageID: Integer);
+begin
+  tabPage.TabIndex := frmFrame.PageIDToTab(PageID);
+  tabPageChange(tabPage);
+end;
+
+procedure TfrmFrame.NextButtonClick(Sender: TObject);
+begin
+  if FProccessingNextClick then Exit;
+  FProccessingNextClick := true;
+  popAlerts.AutoPopup := TRUE;
+  mnuFileNext.Enabled := True;
+  mnuFileNextClick(Self);
+  FProccessingNextClick := false;
+end;
+
+procedure TfrmFrame.NextButtonMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+begin
+   popAlerts.AutoPopup := TRUE;
+end;
+
+procedure TfrmFrame.SetUpNextButton;
+ begin
+   if FNextButton <> nil then
+   begin
+      FNextButton.free;
+      FNextButton := nil;
+   end;
+   FNextButton := TBitBtn.Create(self);
+   FNextButton.Parent:= frmFrame;
+   FNextButton.Glyph := FNextButtonBitmap;
+   FNextButton.OnMouseDown := NextButtonMouseDown;
+   FNextButton.OnClick := NextButtonClick;
+   FNextButton.Caption := '&Next';
+   FNextButton.PopupMenu := popAlerts;
+   FNextButton.Top := stsArea.Top;
+   FNextButton.Left := FNextButtonL;
+   FNextButton.Height := stsArea.Height;
+   FNextButton.Width := stsArea.Panels[2].Width;
+   FNextButton.TabStop := True;
+   FNextButton.TabOrder := 1;
+   FNextButton.show;
+end;
+
 initialization
+  SpecifyFormIsNotADialog(TfrmFrame);
 
 finalization
