Index: cprs/trunk/CPRS-Chart/fReports.pas
===================================================================
--- cprs/trunk/CPRS-Chart/fReports.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/fReports.pas	(revision 830)
@@ -6,5 +6,6 @@
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   fHSplit, StdCtrls, ExtCtrls, ORCtrls, ComCtrls, Menus, uConst, ORDtTmRng,
-  OleCtrls, SHDocVw, Buttons, ClipBrd, rECS, Variants, StrUtils;
+  OleCtrls, SHDocVw, Buttons, ClipBrd, rECS, Variants, StrUtils, fBase508Form,
+  VA508AccessibilityManager, VA508ImageListLabeler;
 
 type
@@ -28,5 +29,4 @@
     pnlRightBottom: TPanel;
     pnlRightMiddle: TPanel;
-    lblTitle: TOROffsetLabel;
     TabControl1: TTabControl;
     lvReports: TCaptionListView;
@@ -54,4 +54,8 @@
     lstDateRange: TORListBox;
     pnlTopViews: TPanel;
+    pnlTopRtLabel: TPanel;
+    lblTitle: TOROffsetLabel;
+    chkMaxFreq: TCheckBox;
+    imgLblImages: TVA508ImageListLabeler;
     procedure lstQualifierClick(Sender: TObject);
     procedure GotoTop1Click(Sender: TObject);
@@ -66,5 +70,5 @@
     procedure TabControl1Change(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
-    procedure GoRemote(Dest: TStringList; AItem: string; AQualifier, ARpc: string; AHSTag: string; AHDR: string);
+    procedure GoRemote(Dest: TStringList; AItem: string; AQualifier, ARpc: string; AHSTag: string; AHDR: string; aFHIE: string);
     procedure lstHeadersClick(Sender: TObject);
     procedure Splitter1CanResize(Sender: TObject; var NewSize: Integer;
@@ -107,5 +111,5 @@
     procedure tvProceduresExpanding(Sender: TObject; Node: TTreeNode;                   
       var AllowExpansion: Boolean);
-    procedure tvProceduresClick(Sender: TObject);                                       
+    procedure tvProceduresClick(Sender: TObject);
     procedure tvProceduresChange(Sender: TObject; Node: TTreeNode);
     procedure tvProceduresKeyDown(Sender: TObject; var Key: Word;                       
@@ -116,4 +120,5 @@
     procedure lstDateRangeClick(Sender: TObject);
     procedure sptHorzMoved(Sender: TObject);
+    procedure chkMaxFreqClick(Sender: TObject);
 
   private
@@ -123,5 +128,4 @@
     procedure Graph(reportien: integer);
     procedure GraphPanel(active: boolean);
-
   public
     procedure ClearPtData; override;
@@ -167,5 +171,8 @@
 
 uses ORFn, rCore, rReports, fFrame, uCore, uReports, fReportsPrint,
-     fReportsAdhocComponent1, activex, mshtml, dShared, fGraphs, rGraphs;  //*****
+     fReportsAdhocComponent1, activex, mshtml, dShared, fGraphs, fGraphData, rGraphs,
+     VA508AccessibilityRouter, VAUtils
+     { TODO -oRV -cWVEHR Long Age : Changed to use long age }
+     , rWVEHR;
 
 const
@@ -209,4 +216,5 @@
   lblProcTypeMsg.Visible := FALSE;
   lvReports.SmallImages := uEmptyImageList;
+  imgLblImages.ComponentImageListChanged;
   lvReports.Items.Clear;
   uLocalReportData.Clear;
@@ -215,4 +223,5 @@
   TabControl1.Visible := false;
   TabControl1.TabStop := false;
+  lstDateRange.Tag := 0; // used to reset date default on graph
   if (GraphForm <> nil) and GraphFormActive then
   with GraphForm do
@@ -222,5 +231,5 @@
     DisplayData('top');
     DisplayData('bottom');
-    lstCheck.Items.Clear;
+    GtslCheck.Clear;
     GraphFormActive := false;
   end;
@@ -251,7 +260,7 @@
         DisplayData('top');
         DisplayData('bottom');
-        lstCheck.Items.Clear;
+        GtslCheck.Clear;
         GraphPanel(true);
-        lstTypes.Hint := Patient.DFN;
+        frmGraphData.pnlData.Hint := Patient.DFN;
         BringToFront;
       end;
@@ -269,37 +278,15 @@
   else if GraphForm.btnClose.Tag = 1 then
     Exit
-  else if GraphFormActive and (GraphForm.lstTypes.Hint = Patient.DFN) then
-  begin   // displaying same patient
-    if Tag <> reportien then
+  else
+  begin
     with GraphForm do
-    begin  // new report
+    if pnlMain.Tag <> reportien then
+    begin  // different report
       pnlMain.Tag := reportien;
       Initialize;
-      //DisplayData('top');
-      //DisplayData('bottom');
-      lstCheck.Items.Clear;
+      GtslCheck.Clear;
       GraphPanel(true);
       BringToFront;
     end;
-    //no action
-  end
-  else if GraphForm.lstTypes.Hint = Patient.DFN then
-  begin   // same patient, bring back graph
-    GraphPanel(true);
-    BringToFront;
-    GraphFormActive := true;
-  end
-  else
-  with GraphForm do
-  begin  // new patient
-    pnlMain.Tag := reportien;
-    Initialize;
-    DisplayData('top');
-    DisplayData('bottom');
-    lstCheck.Items.Clear;
-    lstTypes.Hint := Patient.DFN;
-    GraphPanel(true);
-    BringToFront;
-    GraphFormActive := true;
   end;
 end;
@@ -307,5 +294,7 @@
 procedure TfrmReports.GraphPanel(active: boolean);
 var
-  aQualifier, aStartTime, aStopTime: string;
+  adddaterange: boolean;
+  i: integer;
+  aQualifier, aStartTime, aStopTime, aNewLine: string;
 begin
   if active then
@@ -326,10 +315,19 @@
       aStartTime  :=  Piece(aQualifier,';',1);
       aStopTime   :=  Piece(aQualifier,';',2);
-      GraphForm.cboDateRange.Items.Add(
-        '^' + aStartTime + ' to ' + aStopTime +'^^^' + aStartTime + ';' +  aStopTime +
-        '^' + floattostr(strtofmdatetime(aStartTime)) + '^' + floattostr(strtofmdatetime(aStopTime)));
+      adddaterange := true;
+      aNewLine := '^' + aStartTime + ' to ' + aStopTime +'^^^' + aStartTime + ';' +  aStopTime +
+        '^' + floattostr(strtofmdatetime(aStartTime)) + '^' + floattostr(strtofmdatetime(aStopTime));
+      for i := 0 to GraphForm.cboDateRange.Items.Count - 1 do
+        if GraphForm.cboDateRange.Items[i] = aNewLine then
+        begin
+          adddaterange := false;
+          break;
+        end;
+      if adddaterange then GraphForm.cboDateRange.Items.Add(aNewLine);
       lstDateRange.Items := GraphForm.cboDateRange.Items;
+      GraphForm.DateDefaults;
+      lstDateRange.ItemIndex := GraphForm.cboDateRange.ItemIndex;
       //lstDateRange.ItemIndex := lstDateRange.Items.Count - 1;
-      lstDateRange.ItemIndex := lstDateRange.Items.Count - 2;      //set to all results till fixed
+      //lstDateRange.ItemIndex := lstDateRange.Items.Count - 2;      //set to all results till fixed
       lstDateRangeClick(self);
     end;
@@ -438,5 +436,8 @@
                   + '<TD nowrap><B>Patient: ' + Patient.Name + '</B></TD>'
                   + '<TD nowrap><B>' + Patient.SSN + '</B></TD>'
-                  + '<TD nowrap><B>Age: ' + IntToStr(Patient.Age) + '</B></TD>'
+{ TODO -oRV -cWVEHR Long Age : Changed to use long age }
+                  //+ '<TD nowrap><B>Age: ' + IntToStr(Patient.Age) + '</B></TD>'
+                  + '<TD nowrap><B>Age: ' + GetPatientBriefAge(Patient.DFN) + '</B></TD>'
+{}
                   + '</TR></TABLE></DIV><HR>';
                   //the preferred method would be to use headers and footers
@@ -454,8 +455,10 @@
   if InitPatient and not (CallingContext = CC_NOTIFICATION) then
     begin
+      uColChange := '';
       lstQualifier.Clear;
       tvProcedures.Items.Clear;
       lblProcTypeMsg.Visible := FALSE;
       lvReports.SmallImages := uEmptyImageList;
+      imgLblImages.ComponentImageListChanged;
       lvReports.Items.Clear;
       lvReports.Columns.Clear;
@@ -477,4 +480,5 @@
           begin
             tvReports.Selected := tvReports.Items.GetFirstNode;
+            tvReportsClick(self);
           end;
     end;
@@ -482,8 +486,10 @@
     CC_INIT_PATIENT:  if not InitPatient then
                         begin
+                        uColChange := '';
                         lstQualifier.Clear;
                         tvProcedures.Items.Clear;
                         lblProcTypeMsg.Visible := FALSE;      
                         lvReports.SmallImages := uEmptyImageList;
+                        imgLblImages.ComponentImageListChanged;
                         lvReports.Items.Clear;
                         Splitter1.Visible := false;
@@ -493,8 +499,9 @@
                             begin
                               tvReports.Selected := tvReports.Items.GetFirstNode;
+                              tvReportsClick(self);
                             end;
                         end;
     CC_NOTIFICATION:  ProcessNotifications;
-  end;  
+  end;
 end;
 
@@ -523,7 +530,7 @@
 var
   i,j: integer;
-  currentNode, parentNode, grandParentNode: TTreeNode;
+  currentNode, parentNode, grandParentNode, gtGrandParentNode: TTreeNode;
   x: string;
-  addchild, addgrandchild: boolean;
+  addchild, addgrandchild, addgtgrandchild: boolean;
 begin
   tvReports.Items.Clear;
@@ -532,6 +539,7 @@
   WebBrowser1.Navigate('about:blank');
   tvProcedures.Items.Clear;
-  lblProcTypeMsg.Visible := FALSE;      
+  lblProcTypeMsg.Visible := FALSE;
   lvReports.SmallImages := uEmptyImageList;
+  imgLblImages.ComponentImageListChanged;
   lvReports.Items.Clear;
   uTreeStrings.Clear;
@@ -541,6 +549,8 @@
   addchild := false;
   addgrandchild := false;
+  addgtgrandchild := false;
   parentNode := nil;
   grandParentNode := nil;
+  gtGrandParentNode := nil;
   currentNode := nil;
   for i := 0 to uTreeStrings.Count - 1 do
@@ -549,33 +559,46 @@
       if UpperCase(Piece(x,'^',1))='[PARENT END]' then
         begin
-          if addgrandchild = true then
+          if addgtgrandchild = true then
             begin
-              currentNode := grandParentNode;
-              addgrandchild := false;
+              currentNode := gtgrandParentNode;
+              addgtgrandchild := false;
             end
           else
-            begin
-              currentNode := parentNode;
-              addchild := false;
-            end;
+            if addgrandchild = true then
+              begin
+                currentNode := grandParentNode;
+                addgrandchild := false;
+              end
+            else
+              begin
+                currentNode := parentNode;
+                addchild := false;
+              end;
           continue;
         end;
       if UpperCase(Piece(x,'^',1))='[PARENT START]' then
         begin
-          if addgrandchild = true then
-            currentNode := tvReports.Items.AddChildObject(grandParentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,15)))
+          if addgtgrandchild = true then
+            currentNode := tvReports.Items.AddChildObject(gtGrandParentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,21)))
           else
-            if addchild = true then
+            if addgrandchild = true then
               begin
-                currentNode := tvReports.Items.AddChildObject(parentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,15)));
-                addgrandchild := true;
-                grandParentNode := currentNode;
+                currentNode := tvReports.Items.AddChildObject(grandParentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,21)));
+                addgtgrandchild := true;
+                gtgrandParentNode := currentNode;
               end
             else
-              begin
-                currentNode := tvReports.Items.AddObject(currentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,15)));
-                parentNode := currentNode;
-                addchild := true;
-              end;
+              if addchild = true then
+                begin
+                  currentNode := tvReports.Items.AddChildObject(parentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,21)));
+                  addgrandchild := true;
+                  grandParentNode := currentNode;
+                end
+              else
+                begin
+                  currentNode := tvReports.Items.AddObject(currentNode,Piece(x,'^',3),MakeReportTreeObject(Pieces(x,'^',2,21)));
+                  parentNode := currentNode;
+                  addchild := true;
+                end;
         end
       else
@@ -587,8 +610,11 @@
         else
           begin
-            if addgrandchild = true then
-                currentNode := tvReports.Items.AddChildObject(grandParentNode,Piece(x,'^',2),MakeReportTreeObject(x))
+            if addgtgrandchild = true then
+                currentNode := tvReports.Items.AddChildObject(gtGrandParentNode,Piece(x,'^',2),MakeReportTreeObject(x))
             else
-                currentNode := tvReports.Items.AddChildObject(parentNode,Piece(x,'^',2),MakeReportTreeObject(x));
+              if addgrandchild = true then
+                  currentNode := tvReports.Items.AddChildObject(grandParentNode,Piece(x,'^',2),MakeReportTreeObject(x))
+              else
+                  currentNode := tvReports.Items.AddChildObject(parentNode,Piece(x,'^',2),MakeReportTreeObject(x));
           end;
     end;
@@ -607,7 +633,23 @@
 
 procedure TfrmReports.SetFontSize(NewFontSize: Integer);
-begin
+var
+  pnlRightMiddlePct: Real;
+  frmReportsHeight, pnlRightHeight: Integer;
+
+begin
+  pnlRightMiddlePct := (pnlRightMiddle.Height / (pnlRight.Height - (sptHorzRight.Height + pnlRightTop.Height)));
+  pnlRightMiddle.Constraints.MaxHeight := 20;
   inherited SetFontSize(NewFontSize);
   memText.Font.Size := NewFontSize;
+  frmReportsHeight := frmFrame.pnlPatientSelectedHeight - (frmFrame.pnlToolbar.Height + frmFrame.stsArea.Height + frmFrame.tabPage.Height + 2);
+  pnlRightHeight := frmReportsHeight - shpPageBottom.Height;
+  pnlRightMiddle.Constraints.MaxHeight := 0;
+  pnlRightMiddle.Height := (Round((pnlRightHeight - (sptHorzRight.Height + pnlRightTop.Height)) * pnlRightMiddlePct) - 14);
+  if frmFrame.Height <> frmFrame.frmFrameHeight then
+  begin
+    pnlRight.Height := pnlRightHeight;
+    frmReports.Height := frmReportsHeight;
+    frmFrame.Height := frmFrame.frmFrameHeight;
+  end;
 end;
 
@@ -798,26 +840,31 @@
           begin
             SmallImages := dmodShared.imgImages;
+            imgLblImages.ComponentImageListChanged;
             for i := 0 to Items.Count - 1 do
-              if Items[i].SubItems[7] = 'Y' then
+              if (Items[i].SubItems.Count > 7) and (Items[i].SubItems[7] = 'Y') then
                 Items[i].SubItemImages[1] := IMG_1_IMAGE
               else
                 Items[i].SubItemImages[1] := IMG_NO_IMAGES;
           end
-        else lvReports.SmallImages := uEmptyImageList;
+        else //lvReports.SmallImages := uEmptyImageList;
         if uRptID = 'OR_PN:PROGRESS NOTES' then with lvReports do  //set image indicator for "Progress Notes" report
           begin
             SmallImages := dmodShared.imgImages;
+            imgLblImages.ComponentImageListChanged;
             for i := 0 to Items.Count - 1 do
-              if StrToInt(Items[i].SubItems[7]) > 0 then
+              if (Items[i].SubItems.Count > 7) and (StrToInt(Items[i].SubItems[7]) > 0) then
                 Items[i].SubItemImages[2] := IMG_1_IMAGE
               else
                 Items[i].SubItemImages[2] := IMG_NO_IMAGES;
           end
-        else lvReports.SmallImages := uEmptyImageList;
+        else begin
+          lvReports.SmallImages := uEmptyImageList;
+          imgLblImages.ComponentImageListChanged;
+        end;
       end;
   end;
   if aErr = 1 then
     if User.HasKey('XUPROGMODE') then
-      ShowMessage('Programmer message: One or more Column ID''s in file 101.24 do not match ID''s coded in extract routine');
+      ShowMsg('Programmer message: One or more Column ID''s in file 101.24 do not match ID''s coded in extract routine');
 end;
 
@@ -825,5 +872,5 @@
 var
   MoreID: String;  //Restores MaxOcc value
-  aRemote, aHDR: string;
+  aRemote, aHDR, aFHIE: string;
   i: integer;
 begin
@@ -835,6 +882,12 @@
     end;
   MoreID := ';' + Piece(uQualifier,';',3);
+  if chkMaxFreq.checked = true then
+    begin
+      MoreID := '';
+      SetPiece(uQualifier,';',3,'');
+    end;
   aRemote :=  piece(uRemoteType,'^',1);
   aHDR := piece(uRemoteType,'^',7);
+  aFHIE := piece(uRemoteType,'^',8);
   SetPiece(uRemoteType,'^',5,lstQualifier.ItemID);
   uHSComponents.Clear;
@@ -933,36 +986,39 @@
         begin     //      = 5
           lvReports.SmallImages := uEmptyImageList;
+          imgLblImages.ComponentImageListChanged;
           lvReports.Items.Clear;
           memText.Lines.Clear;
           RowObjects.Clear;
           if ((aRemote = '1') or (aRemote = '2')) then
-            GoRemote(uRemoteReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState, aHDR);
-          if (length(piece(uHState,';',2)) > 0) then
-            begin
-              if not(aRemote = '2') then
+            GoRemote(uRemoteReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState, aHDR, aFHIE);
+          if not(piece(uRemoteType, '^', 9) = '1') then
+            if (length(piece(uHState,';',2)) > 0) then
+              begin
+                if not(aRemote = '2') then
+                  LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
+                LoadListView(uLocalReportData);
+              end
+            else
+              begin
+                if ((aRemote = '1') or (aRemote = '2')) then
+                  ShowTabControl;
+                pnlRightMiddle.Visible := false;
                 LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
-              LoadListView(uLocalReportData);
-            end
-          else
-            begin
-              if ((aRemote = '1') or (aRemote = '2')) then
-                ShowTabControl;
-              pnlRightMiddle.Visible := false;
-              LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
-              if uLocalReportData.Count < 1 then
-                begin
-                  uReportInstruction := '<No Report Available>';
-                  memText.Lines.Add(uReportInstruction);
-                end
-              else
-                begin
-                  QuickCopy(uLocalReportData,memText);
-                  TabControl1.OnChange(nil);
-                end;
-            end;
+                if uLocalReportData.Count < 1 then
+                  begin
+                    uReportInstruction := '<No Report Available>';
+                    memText.Lines.Add(uReportInstruction);
+                  end
+                else
+                  begin
+                    QuickCopy(uLocalReportData,memText);
+                    TabControl1.OnChange(nil);
+                  end;
+              end;
         end;
       QT_HSWPCOMPONENT:
         begin      //      = 6
           lvReports.SmallImages := uEmptyImageList;
+          imgLblImages.ComponentImageListChanged;
           lvReports.Items.Clear;
           RowObjects.Clear;
@@ -971,34 +1027,35 @@
             begin
               Screen.Cursor := crDefault;
-              GoRemote(uRemoteReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState, aHDR);
+              GoRemote(uRemoteReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState, aHDR, aFHIE);
             end;
-          if (length(piece(uHState,';',2)) > 0) then
-            begin
-              if not(aRemote = '2') then
-                LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
-              LoadListView(uLocalReportData);
-            end
-          else
-            begin
-              if ((aRemote = '1') or (aRemote = '2')) then
-                ShowTabControl;
-              pnlRightMiddle.Visible := false;
-              if not (aRemote = '2') then
-                begin
+          if not(piece(uRemoteType, '^', 9) = '1') then
+            if (length(piece(uHState,';',2)) > 0) then
+              begin
+                if not(aRemote = '2') then
                   LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
-                  if uLocalReportData.Count < 1 then
-                    begin
-                      uReportInstruction := '<No Report Available>';
-                      memText.Lines.Add(uReportInstruction);
-                    end
-                  else
-                    QuickCopy(uLocalReportData,memText);
-                end;
-            end;
+                LoadListView(uLocalReportData);
+              end
+            else
+              begin
+                if ((aRemote = '1') or (aRemote = '2')) then
+                  ShowTabControl;
+                pnlRightMiddle.Visible := false;
+                if not (aRemote = '2') then
+                  begin
+                    LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
+                    if uLocalReportData.Count < 1 then
+                      begin
+                        uReportInstruction := '<No Report Available>';
+                        memText.Lines.Add(uReportInstruction);
+                      end
+                    else
+                      QuickCopy(uLocalReportData,memText);
+                  end;
+              end;
         end
       else
         begin
           Screen.Cursor := crDefault;
-          GoRemote(uRemoteReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState, aHDR);
+          GoRemote(uRemoteReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState, aHDR, aFHIE);
           if Pos('ECS',Piece(uRptID,':',1))>0 then
           begin
@@ -1018,7 +1075,9 @@
             LoadECSReportText(uLocalReportData, uECSReport);
           end else
-            LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
-          if TabControl1.TabIndex < 1 then
-            QuickCopy(uLocalReportData,memText);
+            if not(piece(uRemoteType, '^', 9) = '1') then
+              LoadReportText(uLocalReportData, uRptID, lstQualifier.ItemID + MoreID, uReportRPC, uHState);
+          if not(piece(uRemoteType, '^', 9) = '1') then
+            if TabControl1.TabIndex < 1 then
+              QuickCopy(uLocalReportData,memText);
         end;
     end;
@@ -1139,5 +1198,4 @@
   inherited;
   PageID := CT_REPORTS;
-  memText.Color := ReadOnlyColor;
   uFrozen := False;
   uHSComponents := TStringList.Create;
@@ -1156,58 +1214,144 @@
 procedure TfrmReports.ProcessNotifications;
 var
-  i: integer;
+  j, AnIndex, IDColumn: integer;
   SelectID: string;
-  Found: boolean;
   ListItem: TListItem;
-begin
-  Found := False;
-  with tvReports do
-    begin
-      for i := 0 to Items.Count -1 do
-        if StrToIntDef(Piece(PReportTreeObject(tvReports.Items[i].Data)^.Qualifier,';',4),0) = QT_IMAGING then
-          begin
-            Found := True;
-            break;
-          end;
-    end;
-
-  if not Found then exit;  // no imaging entry in treeview would result in error below, and loss of alert
-
+  tmpRptID: string;
+
+  function FindReport(QualType: integer; var AnIndex: integer): boolean; overload;
+  var
+    Found: boolean;
+    i: integer;
+  begin
+    Found := False;
+    with tvReports do
+      begin
+        for i := 0 to Items.Count -1 do
+          if StrToIntDef(Piece(PReportTreeObject(tvReports.Items[i].Data)^.Qualifier,';',4),0) = QualType then
+            begin
+              Found := True;
+              break;
+            end;
+      end;
+    Result := Found ;
+    AnIndex := i;
+  end;
+
+  function FindReport(ReportID: string; var AnIndex: integer): boolean; overload;
+  var
+    Found: boolean;
+    i: integer;
+  begin
+    Found := False;
+    with tvReports do
+      begin
+        for i := 0 to Items.Count -1 do
+          if Piece(PReportTreeObject(tvReports.Items[i].Data)^.ID, ':', 1) = ReportID then
+            begin
+              Found := True;
+              break;
+            end;
+      end;
+    Result := Found ;
+    AnIndex := i;
+  end;
+
+begin
+  IDColumn := 0;
   case Notifications.Followup of
     NF_IMAGING_RESULTS, NF_ABNORMAL_IMAGING_RESULTS, NF_IMAGING_RESULTS_AMENDED:
       begin
-        tvReports.Selected := tvReports.Items[i];
+        if not FindReport(QT_IMAGING, AnIndex) then exit;
+        tvReports.Selected := tvReports.Items[AnIndex];
         SelectID := 'i' + Piece(Notifications.AlertData, '~', 1) +
           '-' + Piece(Notifications.AlertData, '~', 2);
-        if tvReports.Selected <> tvReports.Items[i] then
-          tvReports.Selected := tvReports.Items[i];
+        IDColumn := 0;
+        if tvReports.Selected <> tvReports.Items[AnIndex] then
+          tvReports.Selected := tvReports.Items[AnIndex];
       end;
     NF_IMAGING_REQUEST_CHANGED:
       begin
-        tvReports.Selected := tvReports.Items[i];
+        if not FindReport(QT_IMAGING, AnIndex) then exit;
+        tvReports.Selected := tvReports.Items[AnIndex];
         SelectID := 'i' + Piece(Notifications.AlertData, '/', 2) +
           '-' + Piece(Notifications.AlertData, '/', 3);
-        if tvReports.Selected <> tvReports.Items[i] then
-          tvReports.Selected := tvReports.Items[i];
+        IDColumn := 0;
+        if tvReports.Selected <> tvReports.Items[AnIndex] then
+          tvReports.Selected := tvReports.Items[AnIndex];
       end;
     NF_STAT_RESULTS                  :
       begin
-        tvReports.Selected := tvReports.Items[i];
+        if not FindReport(QT_IMAGING, AnIndex) then exit;
+        tvReports.Selected := tvReports.Items[AnIndex];
         SelectID := 'i' + Piece(Notifications.AlertData, '~', 2) +
           '-' + Piece(Piece(Notifications.AlertData, '~', 3), '@', 1);
-        if tvReports.Selected <> tvReports.Items[i] then
-          tvReports.Selected := tvReports.Items[i];
+        IDColumn := 0;
+        if tvReports.Selected <> tvReports.Items[AnIndex] then
+          tvReports.Selected := tvReports.Items[AnIndex];
       end;
-  else with tvReports do if Items.Count > 0 then Selected := Items[0];
+    NF_MAMMOGRAM_RESULTS            :
+      begin
+        if not FindReport('OR_R18', AnIndex) then exit;
+        tvReports.Selected := tvReports.Items[AnIndex];
+        SelectID := 'i' + Piece(Notifications.AlertData, '~', 1) +
+          '-' + Piece(Notifications.AlertData, '~', 2);
+        IDColumn := 8;
+        if tvReports.Selected <> tvReports.Items[AnIndex] then
+          tvReports.Selected := tvReports.Items[AnIndex];
+      end;
+    NF_ANATOMIC_PATHOLOGY_RESULTS    :
+      //OR_SP^Surgical Pathology
+      //OR_CY^Cytology
+      //OR_EM^Electron Microscopy
+      //OR_AU^Autopsy
+      begin
+        if Notifications.AlertData = '^1^^^0^0^0' then   //code snippet to handle the processing of v26 AP alerts in a v27 environment.
+          begin
+            if pnlRightMiddle.Visible then pnlRightMiddle.Visible := FALSE;
+            InfoBox('This alert was generated in a v26 environment as an informational alert and'
+            + CRLF + 'therefore cannot be processed as an action alert in a v27 environment.',
+            'Unable to Process as Action Alert', MB_OK or MB_ICONWARNING);
+            memText.Text := 'Unable to Process as an Action Alert. In order to view the associated Anatomic Pathology report, please manually'
+            + CRLF + 'locate the appropriate report under the Anatomic Pathology section (also found under Laboratory, Clinical Reports).';
+            Notifications.Delete;
+            exit;
+          end;
+        tmpRptID := Piece(Notifications.AlertData, U, 1);
+        //if tmpRptID = 'CY' then tmpRptID := 'APR';
+        //if tmpRptID = 'EM' then tmpRptID := 'APR';
+        //if tmpRptID = 'SP' then tmpRptID := 'APR';
+        if not FindReport('OR_' + tmpRptID, AnIndex) then exit;
+        tvReports.Selected := tvReports.Items[AnIndex];
+        SelectID := Piece(Notifications.AlertData, U, 2);
+        if (tmpRptID = 'CY') or (tmpRptID = 'EM') or (tmpRptID = 'SP') then
+             IDColumn := 3;
+        //if      tmpRptID = 'APR' then IDColumn := 3
+        //else if tmpRptID = 'SP' then IDColumn := 3
+        //else if tmpRptID = 'EM' then IDColumn := 3
+        //else if tmpRptID = 'CY' then IDColumn := 3 ;
+        if tvReports.Selected <> tvReports.Items[AnIndex] then
+          tvReports.Selected := tvReports.Items[AnIndex];
+      end;
+    NF_PAP_SMEAR_RESULTS            :
+      begin
+        if not FindReport('OR_CY', AnIndex) then exit;
+        tvReports.Selected := tvReports.Items[AnIndex];
+        SelectID := Piece(Notifications.AlertData, U, 2);
+        IDColumn := 3;
+        if tvReports.Selected <> tvReports.Items[AnIndex] then
+          tvReports.Selected := tvReports.Items[AnIndex];
+      end;
+    else with tvReports do if Items.Count > 0 then Selected := Items[0];
   end;
   if tvReports.Selected <> nil then
     begin
       tvReportsClick(Self);
-      for i := 0 to lvReports.Items.Count - 1 do
+      Application.ProcessMessages;
+      for j := 0 to lvReports.Items.Count - 1 do
        begin
-         ListItem := lvReports.Items[i];
-         if ListItem.Subitems[0] = SelectID then
+         ListItem := lvReports.Items[j];
+         if ListItem.Subitems[IDColumn] = SelectID then
            begin
-             lvReports.Selected := lvReports.Items[i];
+             lvReports.Selected := lvReports.Items[j];
              break;
            end;
@@ -1249,8 +1393,10 @@
           end;
         if length(piece(aRanges,';',1)) > 0 then
+          if uReportType <> 'G' then    // graphs don't display date ranges here
           begin
             d1 := ValidDateTimeStr(piece(aRanges,';',1),'');
             d2 := ValidDateTimeStr(piece(aRanges,';',2),'');
             y := FormatFMDateTime('mmm dd,yyyy',d1);
+            if Copy(y,8,2) = '18' then y := 'EARLIEST RESULT';
             z := FormatFMDateTime('mmm dd,yyyy',d2);
             x1 := ' [From: ' + y + ' to ' + z + ']';
@@ -1269,4 +1415,5 @@
         end;
       end;
+    if piece(uRemoteType, '^', 9) = '1' then x := x + ' <<ONLY REMOTE DOD DATA INCLUDED IN REPORT>>';
     Caption := x;
   end;
@@ -1483,8 +1630,8 @@
 end;
 
-procedure TfrmReports.GoRemote(Dest: TStringList; AItem: string; AQualifier, ARpc: string; AHSTag: string; AHDR: string);
+procedure TfrmReports.GoRemote(Dest: TStringList; AItem: string; AQualifier, ARpc: string; AHSTag: string; AHDR: string; aFHIE: string);
 var
   i, j: integer;
-  LocalHandle, Query, Report: string;
+  LocalHandle, Query, Report, Seq: string;
   HSType, DaysBack, ExamID, MaxOcc: string;
   Alpha, Omega, Trans: double;
@@ -1495,11 +1642,5 @@
   Alpha := 0;
   Omega := 0;
-  if UseVistaWeb then
-    begin
-      if AHDR = '1' then
-        InfoBox('You must use VistaWeb to view this report. To use RDV Classic, change your default setting.',
-                'Use VistaWeb for HDR data', MB_OK);
-      Exit;
-    end;
+  Seq := '';
   if AHDR = '1' then
     begin
@@ -1509,8 +1650,9 @@
           Exit;
         end;
+      InfoBox('You must use VistaWeb to view this report.', 'Use VistaWeb for HDR data', MB_OK);
       if (Piece(AItem, ':', 1) = 'OR_VWAL') or (Piece(AItem, ':', 1) = 'OR_VWRX') then
-        AQualifier := 'T-75000;T+75000;99999';
+        AQualifier := 'T-50000;T+50000;99999';
       if (Piece(AItem, ':', 1) = 'OR_VWVS') and (CharAt(AQualifier, 1) = ';') then
-        AQualifier := 'T-75000;T+75000;99999';
+        AQualifier := 'T-50000;T+50000;99999';
     end;
   if CharAt(AQualifier, 1) = 'd' then
@@ -1552,5 +1694,13 @@
             TRemoteSite(Items[i]).QueryStatus := '1^Not Included';
             UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'NOT INCLUDED');
+            TRemoteSite(Items[i]).RemoteHandle := '';
+            TRemoteSite(Items[i]).QueryStatus := '1^Done';
+            if uQualifierType = 6 then seq := '1^';
+            TRemoteSite(Items[i]).Data.Add(seq + TRemoteSite(Items[i]).SiteName);
+            if uQualifierType = 6 then seq := '2^';
+            TRemoteSite(Items[i]).Data.Add(seq + '<No HDR Data Included> - Use "HDR Reports" menu for HDR Data.');
             TabControl1.OnChange(nil);
+            if (length(piece(uHState,';',2)) > 0) then
+              LoadListView(TRemoteSite(Items[i]).Data);
             continue;
           end;
@@ -1559,5 +1709,28 @@
             TRemoteSite(Items[i]).QueryStatus := '1^Not Included';
             UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'NOT INCLUDED');
+            TRemoteSite(Items[i]).RemoteHandle := '';
+            TRemoteSite(Items[i]).QueryStatus := '1^Done';
+            if uQualifierType = 6 then seq := '1^';
+            TRemoteSite(Items[i]).Data.Add(seq + TRemoteSite(Items[i]).SiteName);
+            if uQualifierType = 6 then seq := '2^';
+            TRemoteSite(Items[i]).Data.Add(seq + '<No HDR Data> This site is not a source for HDR Data.');
             TabControl1.OnChange(nil);
+            if (length(piece(uHState,';',2)) > 0) then
+              LoadListView(TRemoteSite(Items[i]).Data);
+            continue;
+          end;
+        if (LeftStr(TRemoteSite(Items[i]).SiteID, 5) = '200') and not(aFHIE = '1') then
+          begin
+            TRemoteSite(Items[i]).QueryStatus := '1^Not Included';
+            UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'NOT INCLUDED');
+            TRemoteSite(Items[i]).RemoteHandle := '';
+            TRemoteSite(Items[i]).QueryStatus := '1^Done';
+            if uQualifierType = 6 then seq := '1^';
+            TRemoteSite(Items[i]).Data.Add(seq + TRemoteSite(Items[i]).SiteName);
+            if uQualifierType = 6 then seq := '2^';
+            TRemoteSite(Items[i]).Data.Add(seq + '<No DOD Data> - Use "Dept. of Defense Reports" Menu to retrieve data from DOD.');
+            TabControl1.OnChange(nil);
+            if (length(piece(uHState,';',2)) > 0) then
+              LoadListView(TRemoteSite(Items[i]).Data);
             continue;
           end;
@@ -1600,4 +1773,11 @@
                     TRemoteSite(Items[i]).QueryStatus := '-1^Communication error';
                     UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Communication error');
+                    if uQualifierType = 6 then seq := '1^';
+                    TRemoteSite(Items[i]).Data.Add(seq + TRemoteSite(Items[i]).SiteName);
+                    if uQualifierType = 6 then seq := '2^';
+                    TRemoteSite(Items[i]).Data.Add(seq + '<ERROR>- Unable to communicate with Remote site');
+                    TabControl1.OnChange(nil);
+                    if (length(piece(uHState,';',2)) > 0) then
+                      LoadListView(TRemoteSite(Items[i]).Data);
                   end
                 else
@@ -1620,4 +1800,11 @@
                     TRemoteSite(Items[i]).QueryStatus := '-1^Communication error';
                     UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID,'Communication error');
+                    if uQualifierType = 6 then seq := '1^';
+                    TRemoteSite(Items[i]).Data.Add(seq + TRemoteSite(Items[i]).SiteName);
+                    if uQualifierType = 6 then seq := '2^';
+                    TRemoteSite(Items[i]).Data.Add(seq + '<ERROR>- Unable to communicate with Remote site');
+                    TabControl1.OnChange(nil);
+                    if (length(piece(uHState,';',2)) > 0) then
+                      LoadListView(TRemoteSite(Items[i]).Data);
                   end
                 else
@@ -1646,5 +1833,5 @@
       for i := 0 to lvReports.Columns.Count - 1 do
         aColChange := aColChange + IntToStr(lvReports.Column[i].width) + ',';
-      if aColChange <> piece(uColchange,'^',2) then
+      if (Length(aColChange) > 0) and (aColChange <> piece(uColchange,'^',2)) then
         SaveColumnSizes(piece(uColChange,'^',1) + '^' + aColChange);
       uColChange := '';
@@ -1755,5 +1942,5 @@
   aHeading, aReportType, aRPC, aQualifier, aStartTime, aStopTime, aMax, aRptCode, aRemote, aCategory, aSortOrder, aDaysBack, x: string;
   aIFN: integer;
-  aID, aHSTag, aRadParam, aColChange, aDirect, aHDR, aQualifierID: string;
+  aID, aHSTag, aRadParam, aColChange, aDirect, aHDR, aFHIE, aFHIEONLY, aQualifierID: string;
   CurrentParentNode, CurrentNode: TTreeNode;
 begin
@@ -1776,4 +1963,6 @@
   aDirect     :=  PReportTreeObject(tvReports.Selected.Data)^.Direct;
   aHDR        :=  PReportTreeObject(tvReports.Selected.Data)^.HDR;
+  aFHIE       :=  PReportTreeObject(tvReports.Selected.Data)^.FHIE;
+  aFHIEONLY   :=  PReportTreeObject(tvReports.Selected.Data)^.FHIEONLY;
   aStartTime  :=  Piece(aQualifier,';',1);
   aStopTime   :=  Piece(aQualifier,';',2);
@@ -1786,5 +1975,5 @@
       for i := 0 to lvReports.Columns.Count - 1 do
         aColChange := aColChange + IntToStr(lvReports.Column[i].width) + ',';
-      if aColChange <> piece(uColchange,'^',2) then
+      if (Length(aColChange) > 0) and (aColChange <> piece(uColchange,'^',2)) then
         SaveColumnSizes(piece(uColChange,'^',1) + '^' + aColChange);
       uColChange := '';
@@ -1805,5 +1994,5 @@
   uQualifier := aQualifier;
   uSortOrder := aSortOrder;
-  uRemoteType := aRemote + '^' + aReportType + '^' + IntToStr(aIFN) + '^' + aHeading + '^' + aRptCode + '^' + aDaysBack + '^' + aHDR;
+  uRemoteType := aRemote + '^' + aReportType + '^' + IntToStr(aIFN) + '^' + aHeading + '^' + aRptCode + '^' + aDaysBack + '^' + aHDR + '^' + aFHIE + '^' + aFHIEONLY;
   pnlRightTop.Height := lblTitle.Height;  // see below
   RedrawSuspend(tvReports.Handle);
@@ -1836,4 +2025,5 @@
   lblProcTypeMsg.Visible := FALSE;
   lvReports.SmallImages := uEmptyImageList;
+  imgLblImages.ComponentImageListChanged;
   lvReports.Items.Clear;
   lvReports.Columns.Clear;
@@ -1856,6 +2046,5 @@
         with lvReports do
           begin
-            RedrawSuspend(lvReports.Handle);
-            Items.BeginUpdate;
+            Columns.BeginUpdate;
             ViewStyle := vsReport;
             ColumnHeaders(uColumns, IntToStr(aIFN));
@@ -1881,6 +2070,5 @@
                   uNewColumn.Width := 0;
               end;
-            Items.EndUpdate;
-            RedrawActivate(lvReports.Handle);
+            Columns.EndUpdate;
           end;
         pnlRightMiddle.Visible := true;
@@ -1892,5 +2080,4 @@
         memText.TabStop := true;
         memText.BringToFront;
-        RedrawActivate(memText.Handle);
       end
     else
@@ -1904,5 +2091,4 @@
         memText.TabStop := true;
         memText.BringToFront;
-        RedrawActivate(memText.Handle);
       end;
   uLocalReportData.Clear;
@@ -1981,9 +2167,12 @@
                 splitter1.Visible := false;
                 StatusText('Retrieving ' + tvReports.Selected.Text + '...');
-                GoRemote(uRemoteReportData, aID, aRptCode, aRPC, uHState, aHDR);
+                GoRemote(uRemoteReportData, aID, aRptCode, aRPC, uHState, aHDR, aFHIE);
                 uReportInstruction := #13#10 + 'Retrieving data...';
                 TabControl1.OnChange(nil);
-                LoadReportText(uLocalReportData, aID, aRptCode, aRPC, uHState);
-                memText.Lines.Assign(uLocalReportData);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  begin
+                    LoadReportText(uLocalReportData, aID, aRptCode, aRPC, uHState);
+                    QuickCopy(uLocalReportData, memText);
+                  end;
                 if uLocalReportData.Count > 0 then
                     TabControl1.OnChange(nil);
@@ -2004,4 +2193,5 @@
                   lstQualifier.ItemIndex := lstQualifier.Items.Add(aStartTime + ';' + aStopTime + '^' + aStartTime + ' to ' + aStopTime);
                   lvReports.SmallImages := uEmptyImageList;
+                  imgLblImages.ComponentImageListChanged;
                   lvReports.Items.Clear;
                   lstQualifierClick(self);
@@ -2023,8 +2213,8 @@
             with lvReports do
               begin
-                RedrawSuspend(lvReports.Handle);
                 Items.BeginUpdate;
                 ViewStyle := vsReport;
                 SmallImages := dmodShared.imgImages;
+                imgLblImages.ComponentImageListChanged;
                 CurrentParentNode := nil;
                 CurrentNode := nil;
@@ -2053,8 +2243,7 @@
                 pnlLeftBottom.Visible := FALSE;
                 pnlProcedures.Visible := TRUE;
-                Splitter1.Visible := True;                                      
+                Splitter1.Visible := True;
                 if lvReports.Columns.Count > 0 then lvReports.Columns[1].Width := 0;
                 Items.EndUpdate;
-                RedrawActivate(lvReports.Handle);
                 tvProcedures.TopItem := tvProcedures.Selected;
               end;
@@ -2079,5 +2268,4 @@
             with lvReports do
               begin
-                RedrawSuspend(lvReports.Handle);
                 Items.BeginUpdate;
                 ViewStyle := vsReport;
@@ -2092,5 +2280,4 @@
                 if lvReports.Columns.Count > 0 then lvReports.Columns[1].Width := 0;
                 Items.EndUpdate;
-                RedrawActivate(lvReports.Handle);
               end;
             if TabControl1.TabIndex > 0 then TabControl1.TabIndex := 0;
@@ -2108,5 +2295,8 @@
         QT_HSCOMPONENT:
           begin      //      = 5
-            pnlRightMiddle.Height := pnlRight.Height - (pnlRight.Height div 2);
+            if Notifications.AlertData <> '' then
+              pnlRightMiddle.Height := 75
+            else
+              pnlRightMiddle.Height := pnlRight.Height - (pnlRight.Height div 2);
             pnlLeftBottom.Visible := false;
             splitter1.Visible := false;
@@ -2114,4 +2304,5 @@
             uReportInstruction := #13#10 + 'Retrieving data...';
             lvReports.SmallImages := uEmptyImageList;
+            imgLblImages.ComponentImageListChanged;
             lvReports.Items.Clear;
             RowObjects.Clear;
@@ -2126,5 +2317,5 @@
                       begin
                         if aHDR = '1' then
-                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-75000' + ';' + 'T+75000' + '^' + 'T-75000' + ' to ' + 'T+75000')
+                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-50000' + ';' + 'T+50000' + '^' + 'T-50000' + ' to ' + 'T+50000')
                         else
                           if length(aStartTime) > 0 then lstQualifier.ItemIndex := lstQualifier.Items.Add(aStartTime + ';' + aStopTime + '^' + aStartTime + ' to ' + aStopTime);
@@ -2133,9 +2324,10 @@
                     else
                       begin
-                        GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR);
+                        GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR, aFHIE);
                         if aHDR = '1' then
-                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-75000' + ';' + 'T+75000' + '^' + 'T-75000' + ' to ' + 'T+75000')
+                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-50000' + ';' + 'T+50000' + '^' + 'T-50000' + ' to ' + 'T+50000')
                         else
                           if length(aStartTime) > 0 then lstQualifier.ItemIndex := lstQualifier.Items.Add(aStartTime + ';' + aStopTime + '^' + aStartTime + ' to ' + aStopTime);
+                        lstQualifierClick(self);
                       end;
                     lblQualifier.Caption := 'Date Range';
@@ -2146,5 +2338,6 @@
                   begin
                     if not (aRemote = '2' ) then
-                      GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR);
+                      GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR, aFHIE);
+                    if not(piece(uRemoteType, '^', 9) = '1') then
                       begin
                         LoadReportText(uLocalReportData, aID, aQualifier, aRPC, uHState);
@@ -2160,6 +2353,7 @@
                 sptHorzRight.Visible := false;
                 pnlRightMiddle.Visible := false;
-                GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR);
-                LoadReportText(uLocalReportData, aID, aQualifier, aRPC, uHState);
+                GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR, aFHIE);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  LoadReportText(uLocalReportData, aID, aQualifier, aRPC, uHState);
                 if uLocalReportData.Count < 1 then
                   uReportInstruction := '<No Report Available>'
@@ -2203,5 +2397,8 @@
         QT_HSWPCOMPONENT:
           begin      //      = 6
-            pnlRightMiddle.Height := pnlRight.Height - (pnlRight.Height div 2);
+            if Notifications.AlertData <> '' then
+              pnlRightMiddle.Height := 75
+            else
+              pnlRightMiddle.Height := pnlRight.Height - (pnlRight.Height div 2);
             pnlLeftBottom.Visible := false;
             splitter1.Visible := false;
@@ -2212,4 +2409,5 @@
             memText.Lines.Clear;
             lvReports.SmallImages := uEmptyImageList;
+            imgLblImages.ComponentImageListChanged;
             lvReports.Items.Clear;
             if (length(piece(aHSTag,';',2)) > 0) then
@@ -2222,5 +2420,5 @@
                       begin
                         if aHDR = '1' then
-                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-75000' + ';' + 'T+75000' + '^' + 'T-75000' + ' to ' + 'T+75000')
+                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-50000' + ';' + 'T+50000' + '^' + 'T-50000' + ' to ' + 'T+50000')
                         else
                           if length(aStartTime) > 0 then lstQualifier.ItemIndex := lstQualifier.Items.Add(aStartTime + ';' + aStopTime + '^' + aStartTime + ' to ' + aStopTime);
@@ -2229,9 +2427,10 @@
                     else
                       begin
-                        GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR);
+                        GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR, aFHIE);
                         if aHDR = '1' then
-                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-75000' + ';' + 'T+75000' + '^' + 'T-75000' + ' to ' + 'T+75000')
+                          lstQualifier.ItemIndex := lstQualifier.Items.Add('T-50000' + ';' + 'T+50000' + '^' + 'T-50000' + ' to ' + 'T+50000')
                         else
                           if length(aStartTime) > 0 then lstQualifier.ItemIndex := lstQualifier.Items.Add(aStartTime + ';' + aStopTime + '^' + aStartTime + ' to ' + aStopTime);
+                        lstQualifierClick(self);
                       end;
                     lblQualifier.Caption := 'Date Range';
@@ -2241,6 +2440,6 @@
                 else
                   begin
-                    GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR);
-                    if not (aRemote = '2' ) then
+                    GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR, aFHIE);
+                    if not (aRemote = '2' ) and (not(piece(uRemoteType, '^', 9) = '1')) then
                       begin
                         LoadReportText(uLocalReportData, aID, aQualifier, aRPC, uHState);
@@ -2255,6 +2454,7 @@
                 sptHorzRight.Visible := false;
                 pnlRightMiddle.Visible := false;
-                GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR);
-                LoadReportText(uLocalReportData, aID, aQualifier, aRPC, uHState);
+                GoRemote(uRemoteReportData, aID, aQualifier, aRPC, uHState, aHDR, aFHIE);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  LoadReportText(uLocalReportData, aID, aQualifier, aRPC, uHState);
                 if uLocalReportData.Count < 1 then
                   uReportInstruction := '<No Report Available>'
@@ -2295,5 +2495,4 @@
             with lvReports do
               begin
-                RedrawSuspend(lvReports.Handle);
                 Items.BeginUpdate;
                 ViewStyle := vsReport;
@@ -2308,5 +2507,4 @@
                 if lvReports.Columns.Count > 0 then lvReports.Columns[1].Width := 0;
                 Items.EndUpdate;
-                RedrawActivate(lvReports.Handle);
               end;
             if uLocalReportData.Count > 0
@@ -2328,5 +2526,4 @@
             with lvReports do
               begin
-                RedrawSuspend(lvReports.Handle);
                 Items.BeginUpdate;
                 ViewStyle := vsReport;
@@ -2341,5 +2538,4 @@
                 if lvReports.Columns.Count > 0 then lvReports.Columns[1].Width := 0;
                 Items.EndUpdate;
-                RedrawActivate(lvReports.Handle);
               end;
             if uLocalReportData.Count > 0
@@ -2357,9 +2553,10 @@
             splitter1.Visible := false;
             StatusText('Retrieving ' + tvReports.Selected.Text + '...');
-            GoRemote(uRemoteReportData, aID, aRptCode, aRPC, uHState, aHDR);
+            GoRemote(uRemoteReportData, aID, aRptCode, aRPC, uHState, aHDR, aFHIE);
             uReportInstruction := #13#10 + 'Retrieving data...';
             TabControl1.OnChange(nil);
-            LoadReportText(uLocalReportData, aID, aRptCode, aRPC, uHState);
-            LoadReportText(uLocalReportData, aID, '', aRPC, uHState);
+            //LoadReportText(uLocalReportData, aID, aRptCode, aRPC, uHState);
+            if not(piece(uRemoteType, '^', 9) = '1') then
+              LoadReportText(uLocalReportData, aID, '', aRPC, uHState);
             if uLocalReportData.Count < 1 then
               uReportInstruction := '<No Report Available>'
@@ -2383,4 +2580,5 @@
   SendMessage(tvReports.Handle, WM_HSCROLL, SB_THUMBTRACK, 0);
   RedrawActivate(tvReports.Handle);
+  RedrawActivate(memText.Handle);
   if WebBrowser1.Visible = true then
     begin
@@ -2393,5 +2591,4 @@
       memText.TabStop := true;
       memText.BringToFront;
-      RedrawActivate(memText.Handle);
     end
   else
@@ -2406,4 +2603,6 @@
       end;
     end;
+  lvReports.Columns.BeginUpdate;
+  lvReports.Columns.EndUpdate;
   Screen.Cursor := crDefault;
 end;
@@ -2577,4 +2776,5 @@
   aBasket: TStringList;
   aWPFlag: Boolean;
+  x, HasImages: string;
 
 begin
@@ -2635,11 +2835,17 @@
                 aMoreID := '#' + Item.SubItems[5];
                 SetPiece(uRemoteType,'^',5,aID + aMoreID);
-                LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
-                for i := 0 to uLocalReportData.Count - 1 do
-                  MemText.Lines.Add(uLocalReportData[i]);
-                if Item.SubItems.Count > 5 then
-                  NotifyOtherApps(NAE_REPORT, 'RA^' + aID + U + Item.SubItems[5])
-                else
-                  NotifyOtherApps(NAE_REPORT, 'RA^' + aID);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  begin
+                    LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
+                    for i := 0 to uLocalReportData.Count - 1 do
+                      MemText.Lines.Add(uLocalReportData[i]);
+                    if Item.SubItems.Count > 5 then
+                      x := 'RA^' + aID + U + Item.SubItems[5]
+                    else
+                      x := 'RA^' + aID;
+                    HasImages := BOOLCHAR[Item.SubItemImages[1] = IMG_1_IMAGE];
+                    SetPiece(x, U, 10, HasImages);
+                    NotifyOtherApps(NAE_REPORT, x);
+                  end;
               end;
             QT_NUTR:
@@ -2650,7 +2856,10 @@
                   memText.Lines.Add('===============================================================================');
                 SetPiece(uRemoteType,'^',5,aID);
-                LoadReportText(uLocalReportData, uRptID, aID, uReportRPC, '');
-                for i := 0 to uLocalReportData.Count - 1 do
-                  MemText.Lines.Add(uLocalReportData[i]);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  begin
+                    LoadReportText(uLocalReportData, uRptID, aID, uReportRPC, '');
+                    for i := 0 to uLocalReportData.Count - 1 do
+                      MemText.Lines.Add(uLocalReportData[i]);
+                  end;
               end;
             QT_HSWPCOMPONENT:
@@ -2677,5 +2886,5 @@
                                     aWPFlag := true;
                                     MemText.Lines.Add(TCellObject(RowObjects.ColumnList[j]).Name);
-                                    aBasket.Assign(TCellObject(RowObjects.ColumnList[j]).Data);
+                                    FastAssign(TCellObject(RowObjects.ColumnList[j]).Data, aBasket);
                                     for k := 0 to aBasket.Count - 1 do
                                       MemText.Lines.Add('  ' + aBasket[k]);
@@ -2698,5 +2907,5 @@
                           aWPFlag := true;
                           MemText.Lines.Add(TCellObject(RowObjects.ColumnList[i]).Name);
-                          aBasket.Assign(TCellObject(RowObjects.ColumnList[i]).Data);
+                          FastAssign(TCellObject(RowObjects.ColumnList[i]).Data, aBasket);
                           for j := 0 to aBasket.Count - 1 do
                             MemText.Lines.Add('  ' + aBasket[j]);
@@ -2708,17 +2917,31 @@
                   end;
                 if uRptID = 'OR_R18:IMAGING' then
-                  if (Item.SubItems.Count > 4) and (Item.SubItems.Count > 8) then
-                    NotifyOtherApps(NAE_REPORT, 'RA^' + Item.SubItems[8] + U + Item.SubItems[4] + U + Item.Caption)
-                  else
-                    if Item.SubItems.Count > 8 then
-                      NotifyOtherApps(NAE_REPORT, 'RA^' + Item.SubItems[8] + U + U + Item.Caption)
-                    else if Item.SubItemImages[1] = 1 then
-                      begin
-                        memText.Lines.Insert(0,'<Imaging links not active at this site>');
-                        memText.Lines.Insert(1,' ');
-                      end;
+                begin
+                  if (Item.SubItems.Count > 8) then                                             //has id, may have case (?)
+                  begin
+                    x := 'RA^' + Item.SubItems[8] + U + Item.SubItems[4] + U + Item.Caption;
+                    SetPiece(x, U, 10, BOOLCHAR[Item.SubItemImages[1] = IMG_1_IMAGE]);
+                    NotifyOtherApps(NAE_REPORT, x);
+                  end
+                  else if (Item.SubItems.Count > 4) then
+                  begin
+                    x := 'RA^' + U + U + Item.SubItems[4] + U + Item.Caption;
+                    SetPiece(x, U, 10, BOOLCHAR[Item.SubItemImages[1] = IMG_1_IMAGE]);
+                    NotifyOtherApps(NAE_REPORT, x);
+                  end
+                  else if Item.SubItemImages[1] = IMG_1_IMAGE then
+                  begin
+                    memText.Lines.Insert(0,'<Imaging links not active at this site>');
+                    memText.Lines.Insert(1,' ');
+                  end;
+                end;
                 if uRptID = 'OR_PN:PROGRESS NOTES' then
                   if (Item.SubItems.Count > 7) then
-                    NotifyOtherApps(NAE_REPORT, 'PN^' + Item.SubItems[7] + U + Item.SubItems[1] + U + Item.Caption);
+                    begin
+                      if StrToIntDef(Item.SubItems[7], 0) > 0 then HasImages := '1' else HasImages := '0';
+                      x := 'PN^' + Item.SubItems[7] + U + Item.SubItems[1] + U + Item.Caption;
+                      SetPiece(x, U, 10, HasImages);
+                      NotifyOtherApps(NAE_REPORT, x);
+                    end;
               end;
             QT_PROCEDURES:
@@ -2729,7 +2952,10 @@
                   memText.Lines.Add('===============================================================================');
                 SetPiece(uRemoteType,'^',5,aID);
-                LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
-                for i := 0 to uLocalReportData.Count - 1 do
-                  MemText.Lines.Add(uLocalReportData[i]);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  begin
+                    LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
+                    for i := 0 to uLocalReportData.Count - 1 do
+                      MemText.Lines.Add(uLocalReportData[i]);
+                  end;
               end;
             QT_SURGERY:
@@ -2740,8 +2966,11 @@
                   memText.Lines.Add('===============================================================================');
                 SetPiece(uRemoteType,'^',5,aID);
-                LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
-                for i := 0 to uLocalReportData.Count - 1 do
-                  MemText.Lines.Add(uLocalReportData[i]);
-                NotifyOtherApps(NAE_REPORT, 'SUR^' + aID);
+                if not(piece(uRemoteType, '^', 9) = '1') then
+                  begin
+                    LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
+                    for i := 0 to uLocalReportData.Count - 1 do
+                      MemText.Lines.Add(uLocalReportData[i]);
+                    NotifyOtherApps(NAE_REPORT, 'SUR^' + aID);
+                  end;
               end;
       end;
@@ -2961,4 +3190,5 @@
   FirstChild: TTreeNode;
   aID, aMoreID: string;
+  x, HasImages: string;
 begin
   inherited;
@@ -2994,12 +3224,18 @@
             uLocalReportData.Clear;
             MemText.Lines.Clear;
-            LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
-            for i := 0 to uLocalReportData.Count - 1 do
-              MemText.Lines.Add(uLocalReportData[i]);
-            memText.SelStart := 0;
-            if lvReports.Items[Associate].SubItems.Count > 5 then
-              NotifyOtherApps(NAE_REPORT, 'RA^' + aID + U + lvReports.Items[Associate].SubItems[5])
-            else
-              NotifyOtherApps(NAE_REPORT, 'RA^' + aID);
+            if not(piece(uRemoteType, '^', 9) = '1') then
+              begin
+                LoadReportText(uLocalReportData, uRptID, aID + aMoreID, uReportRPC, '');
+                for i := 0 to uLocalReportData.Count - 1 do
+                  MemText.Lines.Add(uLocalReportData[i]);
+                memText.SelStart := 0;
+                if lvReports.Items[Associate].SubItems.Count > 5 then
+                  x := 'RA^' + aID + U + lvReports.Items[Associate].SubItems[5]
+                else
+                  x := 'RA^' + aID;
+                HasImages := BOOLCHAR[lvReports.Items[Associate].SubItemImages[1] = IMG_1_IMAGE];
+                SetPiece(x, U, 10, HasImages);
+                NotifyOtherApps(NAE_REPORT, x);
+              end;
           end
        else if PProcTreeObj(Node.Data)^.MemberOfSet = '1' then    //examset - individual reports
@@ -3032,4 +3268,19 @@
 end;
 
+procedure TfrmReports.chkMaxFreqClick(Sender: TObject);
+begin
+  inherited;
+  if chkMaxFreq.Checked = true then
+    begin
+      uMaxOcc := piece(uQualifier, ';', 3);
+      SetPiece(uQualifier, ';', 3, '');
+    end
+    else
+      begin
+        SetPiece(uQualifier, ';', 3, uMaxOcc);
+      end;
+  tvReportsClick(self);
+end;
+
 procedure TfrmReports.btnChangeViewClick(Sender: TObject);
 begin
@@ -3059,8 +3310,9 @@
     GraphForm.cboDateRange.ItemIndex := lstDateRange.ItemIndex;
     GraphForm.cboDateRangeChange(self);
-    lstDateRange.Items.Assign(GraphForm.cboDateRange.Items);
+    FastAssign(GraphForm.cboDateRange.Items, lstDateRange.Items);
     lstDateRange.ItemIndex := GraphForm.cboDateRange.ItemIndex;
     //Exit;
   end;
+
 end;
 
@@ -3071,3 +3323,6 @@
 end;
 
+initialization
+  SpecifyFormIsNotADialog(TfrmReports);
+
 end.
