Index: cprs/branches/HealthSevak-CPRS/CPRS-Chart/fReports.pas
===================================================================
--- cprs/branches/HealthSevak-CPRS/CPRS-Chart/fReports.pas	(revision 1676)
+++ cprs/branches/HealthSevak-CPRS/CPRS-Chart/fReports.pas	(revision 1693)
@@ -172,7 +172,5 @@
 uses ORFn, rCore, rReports, fFrame, uCore, uReports, fReportsPrint,
      fReportsAdhocComponent1, activex, mshtml, dShared, fGraphs, fGraphData, rGraphs,
-     VA508AccessibilityRouter, VAUtils
-     { TODO -oRV -cWVEHR Long Age : Changed to use long age }
-     , rWVEHR;
+     VA508AccessibilityRouter, VAUtils;  
 
 const
@@ -278,15 +276,37 @@
   else if GraphForm.btnClose.Tag = 1 then
     Exit
-  else
-  begin
+  else if GraphFormActive and (frmGraphData.pnlData.Hint = Patient.DFN) then
+  begin   // displaying same patient
+    if Tag <> reportien then
     with GraphForm do
-    if pnlMain.Tag <> reportien then
-    begin  // different report
+    begin  // new report
       pnlMain.Tag := reportien;
       Initialize;
+      //DisplayData('top');
+      //DisplayData('bottom');
       GtslCheck.Clear;
       GraphPanel(true);
       BringToFront;
     end;
+    //no action
+  end
+  else if frmGraphData.pnlData.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');
+    GtslCheck.Clear;
+    frmGraphData.pnlData.Hint := Patient.DFN;
+    GraphPanel(true);
+    BringToFront;
+    GraphFormActive := true;
   end;
 end;
@@ -420,5 +440,8 @@
 procedure TfrmReports.DisplayPage;
 var
-  i: integer;
+  i{, OrigSelection}: integer;
+  {OrigDateIEN: Int64;
+  OrigDateItemID: Variant;
+  OrigReportCat, OrigProcedure: TTreeNode; }
 begin
   inherited DisplayPage;
@@ -436,13 +459,10 @@
                   + '<TD nowrap><B>Patient: ' + Patient.Name + '</B></TD>'
                   + '<TD nowrap><B>' + Patient.SSN + '</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>'
-{}
+                  + '<TD nowrap><B>Age: ' + IntToStr(Patient.Age) + '</B></TD>'
                   + '</TR></TABLE></DIV><HR>';
                   //the preferred method would be to use headers and footers
                   //so this is just an interim solution.
-  if not GraphFormActive then
-    pnlLeftBottom.Visible := False;
+  {if not GraphFormActive then
+    pnlLeftBottom.Visible := False;  } //This was keeping Date Range selection box from appearing when leaving and coming back to this Tab
   if InitPage then
     begin
@@ -503,5 +523,55 @@
                         end;
     CC_NOTIFICATION:  ProcessNotifications;
-  end;
+    
+    //This corrects the reload of the reports when switching back to the tab.
+     {Remove this since it has already been corrected. Related code was also removed from fLabs.
+    CC_CLICK: if not InitPatient then
+      begin
+        //Clear our local variables
+        OrigReportCat := nil;
+        OrigDateIEN := -1;
+        OrigSelection := -1;
+        OrigDateItemID := '';
+        OrigProcedure := nil;
+
+        //What was last selected before they switched tabs.
+        if tvReports.Selected <> nil then OrigReportCat := tvReports.Selected;
+        if lstDateRange.ItemIEN > 0 then OrigDateIEN := lstDateRange.ItemIEN;
+        if lvReports.Selected <> nil then OrigSelection := lvReports.Selected.Index;
+        if lstQualifier.ItemID <> '' then OrigDateItemID := lstQualifier.ItemID;
+        if tvProcedures.Selected <> nil then OrigProcedure := tvProcedures.Selected;
+
+        //Load the tree and select the last selected
+        if OrigReportCat <> nil then begin
+         tvReports.Select(OrigReportCat);
+         tvReportsClick(self);
+        end;
+
+        //Did they click on a date (lstDates box)
+        if OrigDateIEN > -1 then begin
+          lstDateRange.SelectByIEN(OrigDateIEN);
+          lstDateRangeClick(self);
+        end;
+
+        //Did they click on a date (lstQualifier)
+         if OrigDateItemID <> '' then begin
+          lstQualifier.SelectByID(OrigDateItemID);
+          lstQualifierClick(self);
+        end;
+
+        //Did they click on a procedure
+        if OrigProcedure <> nil then begin
+          tvProcedures.Select(OrigProcedure);
+          tvProceduresClick(tvProcedures);
+        end;
+
+
+        //Did they click on a report
+        if OrigSelection > -1 then begin
+         lvReports.Selected := lvReports.Items[OrigSelection];
+         lvReportsSelectItem(self, lvReports.Selected, true);
+        end;
+      end;  }
+  end;  
 end;
 
@@ -872,5 +942,5 @@
 var
   MoreID: String;  //Restores MaxOcc value
-  aRemote, aHDR, aFHIE: string;
+  aRemote, aHDR, aFHIE, aMax: string;
   i: integer;
 begin
@@ -887,4 +957,9 @@
       SetPiece(uQualifier,';',3,'');
     end;
+  aMax := piece(uQualifier,';',3);
+  if (CharAt(lstQualifier.ItemID,1) = 'd')
+    and (length(aMax)>0)
+    and (StrToInt(aMax)<101) then
+      MoreID := ';101';
   aRemote :=  piece(uRemoteType,'^',1);
   aHDR := piece(uRemoteType,'^',7);
@@ -1097,39 +1172,17 @@
 
 procedure TfrmReports.GotoTop1Click(Sender: TObject);
-var
-  Current, Desired : Longint;
-begin
-  inherited;
-  with memText do
-  begin
-    SetFocus;
-    SelStart :=0;
-    SelLength :=0;
-    Current := SendMessage(memText.handle, EM_GETFIRSTVISIBLELINE, 0, 0);
-    Desired := SendMessage(memText.handle, EM_LINEFROMCHAR,
-               memText.SelStart + memText.SelLength ,0) - 1;
-    SendMessage(memText.Handle,EM_LINESCROLL, 0, Desired - Current);
-  end;
+begin
+  inherited;
+  SendMessage(memText.Handle, WM_VSCROLL, SB_TOP, 0);
+  {GoToTop1.Enabled := false;
+  GoToBottom1.Enabled := true;    }
 end;
 
 procedure TfrmReports.GotoBottom1Click(Sender: TObject);
-var
-  Current, Desired : Longint;
-  I,LineCount : Integer;
 begin
   Inherited;
-  LineCount :=0;
-  with memText do
-    begin
-      for I := 0 to lines.count-1 do
-        LineCount := LineCount + Length(Lines[I]) + 2;
-      SetFocus;
-      SelStart := LineCount;
-      SelLength :=0;
-    end;
-  Current := SendMessage(memText.handle, EM_GETFIRSTVISIBLELINE, 0, 0);
-  Desired := SendMessage(memText.handle, EM_LINEFROMCHAR,
-             memText.SelStart + memText.SelLength ,0);
-  SendMessage(memText.Handle,EM_LINESCROLL, 0, Desired - Current - 5);
+  SendMessage(memText.Handle, WM_VSCROLL, SB_BOTTOM, 0);
+  {GoToTop1.Enabled := true;
+  GoToBottom1.Enabled := false;    }
 end;
 
@@ -1183,5 +1236,5 @@
   If Memo1.Visible Then
     UnFreezeText1.Enabled := True;
-  If memText.SelStart > 0 then
+  {If memText.SelStart > 0 then
     GotoTop1.Enabled := True
   Else
@@ -1191,5 +1244,5 @@
     GotoBottom1.Enabled := True
   Else
-    GotoBottom1.Enabled := False;
+    GotoBottom1.Enabled := False;   }
 end;
 
@@ -1306,5 +1359,5 @@
       //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.
+        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;
@@ -1393,5 +1446,4 @@
           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),'');
@@ -1415,5 +1467,5 @@
         end;
       end;
-    if piece(uRemoteType, '^', 9) = '1' then x := x + ' <<ONLY REMOTE DOD DATA INCLUDED IN REPORT>>';
+    if piece(uRemoteType, '^', 9) = '1' then x := x + ' <<ONLY REMOTE DATA INCLUDED IN REPORT>>';
     Caption := x;
   end;
@@ -1647,8 +1699,8 @@
       if HDRActive = '0' then
         begin
-          InfoBox('The HDR is currently inactive.' + CRLF + 'Unable to retrieve HDR data at this time.', 'HDR Error', MB_OK);
+          InfoBox('The HDR is currently inactive in CPRS.' + CRLF + 'You must use VistaWeb to view this report.', 'Use VistaWeb for HDR data', MB_OK);
           Exit;
         end;
-      InfoBox('You must use VistaWeb to view this report.', 'Use VistaWeb for HDR data', MB_OK);
+      //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-50000;T+50000;99999';
@@ -1684,6 +1736,6 @@
     if (AHDR='1') and (LeftStr(TRemoteSite(Items[i]).SiteID, 5) = '200HD') then
       begin
-        TRemoteSite(Items[i]).Selected := true;
-        frmFrame.lstCIRNLocations.Checked[i+2] := true;
+        //TRemoteSite(Items[i]).Selected := true;
+        //frmFrame.lstCIRNLocations.Checked[i+1] := true;
       end;
     if TRemoteSite(Items[i]).Selected then
@@ -1990,4 +2042,5 @@
   uReportRPC := aRPC;
   uRptID := aID;
+  uReportID := aID;
   uDirect := aDirect;
   uReportType := aReportType;
@@ -2243,5 +2296,5 @@
                 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;
@@ -2888,5 +2941,5 @@
                                     FastAssign(TCellObject(RowObjects.ColumnList[j]).Data, aBasket);
                                     for k := 0 to aBasket.Count - 1 do
-                                      MemText.Lines.Add('  ' + aBasket[k]);
+                                      MemText.Lines.Add(' ' + aBasket[k]);
                                   end;
                           if aWPFlag = true then
@@ -2909,5 +2962,5 @@
                           FastAssign(TCellObject(RowObjects.ColumnList[i]).Data, aBasket);
                           for j := 0 to aBasket.Count - 1 do
-                            MemText.Lines.Add('  ' + aBasket[j]);
+                            MemText.Lines.Add(' ' + aBasket[j]);
                         end;
                 if aWPFlag = true then
