Index: cprs/branches/foia-cprs/CPRS-Chart/fLabs.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/fLabs.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/fLabs.pas	(revision 460)
@@ -7,5 +7,5 @@
   fHSplit, StdCtrls, ExtCtrls, ORCtrls, ComCtrls, Grids, Buttons, fLabTest,
   fLabTests, fLabTestGroups, ORFn, TeeProcs, TeEngine, Chart, Series, Menus,
-  uConst, ORDtTmRng, OleCtrls, SHDocVw, Variants;
+  uConst, ORDtTmRng, OleCtrls, SHDocVw, Variants, StrUtils;
 
 type
@@ -83,4 +83,5 @@
     TabControl1: TTabControl;
     WebBrowser1: TWebBrowser;
+    lblGraph: TLabel;
     procedure FormCreate(Sender: TObject);
     procedure DisplayHeading;
@@ -133,4 +134,5 @@
     procedure Memo1KeyUp(Sender: TObject; var Key: Word;
       Shift: TShiftState);
+    procedure UpdateRemoteStatus(aSiteID, aStatus: string);
   private
     { Private declarations }
@@ -159,4 +161,5 @@
     function FMToDateTime(FMDateTime: string): TDateTime;
     procedure RequestPrint; override;
+    procedure ExtlstReportsClick(Sender: TObject; Ext: boolean);
 
 end;
@@ -169,9 +172,10 @@
   uLabLocalReportData: TStringList;  //Storage for Local report data
   uLabRemoteReportData: TStringList; //Storage for Remote lab query
+  uUpdateStat: boolean;             //flag turned on when remote status is being updated
 
 implementation
 
 uses uCore, rLabs, rCore, rCover, rOrders, fLabPrint, fFrame, fRptBox, Printers,
-     clipbrd, rReports, activex, mshtml, uAccessibleStringGrid;
+     clipbrd, rReports, rGraphs, activex, mshtml, uAccessibleStringGrid;
 
 const
@@ -189,4 +193,5 @@
 var
   uFrozen: Boolean;
+  uGraphingActivated: Boolean;
   uRemoteCount: Integer;
   uHTMLDoc: string;
@@ -240,4 +245,6 @@
 
 procedure TfrmLabs.FormCreate(Sender: TObject);
+var
+  aList: TStrings;
 begin
   inherited;
@@ -246,4 +253,8 @@
   memLab.Color := ReadOnlyColor;
   uFrozen := False;
+  aList := TStringList.Create;
+  FastAssign(rpcGetGraphSettings, aList);
+  uGraphingActivated := aList.Count > 0;
+  aList.Free;
   uRemoteCount := 0;
   tmpGrid := TStringList.Create;
@@ -258,4 +269,25 @@
   SerTest.GetHorizAxis.Increment := DateTimeStep[dtOneMinute];
   TAccessibleStringGrid.WrapControl(grdLab);
+end;
+
+procedure TfrmLabs.UpdateRemoteStatus(aSiteID, aStatus: string);
+var
+  j: integer;
+  s: string;
+  c: boolean;
+begin
+  if uUpdateStat = true then exit;                 //uUpdateStat also looked at in fFrame
+  uUpdateStat := true;
+  for j := 0 to frmFrame.lstCIRNLocations.Items.Count - 1 do
+    begin
+      s := frmFrame.lstCIRNLocations.Items[j];
+      c := frmFrame.lstCIRNLocations.checked[j];
+      if piece(s, '^', 1) = aSiteID then
+        begin
+          frmFrame.lstCIRNLocations.Items[j] := pieces(s, '^', 1, 3) + '^' + aStatus;
+          frmFrame.lstCIRNLocations.checked[j] := c;
+        end;
+    end;
+  uUpdateStat := false;
 end;
 
@@ -296,4 +328,5 @@
   TabControl1.Tabs.Clear;
   TabControl1.Visible := false;
+  tmpGrid.Clear;
   with grdLab do
   begin
@@ -374,4 +407,9 @@
 
 procedure TfrmLabs.lstReportsClick(Sender: TObject);
+begin
+  ExtlstReportsClick(Sender, false);
+end;
+
+procedure TfrmLabs.ExtlstReportsClick(Sender: TObject; Ext: boolean);
 var
   i,iCat: integer;
@@ -436,5 +474,5 @@
          lblSpecimen.Caption := '';
        end;
-       SelectTests(Font.Size);
+       if not Ext then SelectTests(Font.Size);
        if lstTests.Items.Count > 0 then
        begin
@@ -445,8 +483,8 @@
          RedrawActivate(memLab.Handle);
          lstDatesClick(self);
-         cmdOtherTests.SetFocus;
+         if not Ext then cmdOtherTests.SetFocus;
          cmdOtherTests.Default := true;
        end
-       else uPrevReportIndex := lstReports.ItemIndex;
+       else lstReports.ItemIndex := uPrevReportIndex;
      end;
   5: begin               // Worksheet
@@ -456,5 +494,5 @@
          lblSpecimen.Caption := '';
        end;
-       SelectTestGroups(Font.Size);
+       if not Ext then SelectTestGroups(Font.Size);
        if lstTests.Items.Count > 0 then
        begin
@@ -472,27 +510,45 @@
          //chkZoomClick(self);
          lstDatesClick(self);
-         cmdOtherTests.SetFocus;
+         if not Ext then cmdOtherTests.SetFocus;
          cmdOtherTests.Default := true;
        end
-       else uPrevReportIndex := lstReports.ItemIndex;
+       else lstReports.ItemIndex := uPrevReportIndex;
      end;
   6: begin               // Graph
-       if uPrevReportIndex <> lstReports.ItemIndex then
+        // do if graphing is activiated
+       if uGraphingActivated then
        begin
-         lblSingleTest.Caption := '';
-         lblSpecimen.Caption := '';
-       end;
-       SelectTest(Font.Size);
-       if (length(lblSingleTest.Caption) > 2) and (length(lblSpecimen.Caption) > 2) then
+         memLab.Clear;
+         chkBrowser;
+         FormResize(self);
+         memLab.Align := alClient;
+         CommonComponentVisible(false,false,false,false,false,false,false,false,false);
+         RedrawActivate(memLab.Handle);
+         StatusText('');
+         memLab.Lines.Insert(0, ' ');
+         memLab.Lines.Insert(1, 'Graphing activated');
+         memLab.SelStart := 0;
+         frmFrame.mnuToolsGraphingClick(self);  // make it just lab tests ??
+         //lstReports.ItemIndex := uPrevReportIndex;
+       end
+       else  // otherwise, do lab graph
        begin
-         CommonComponentVisible(false,false,true,true,true,true,false,false,true);
-         pnlChart.Visible := true;
-         chtChart.Visible := true;
-         pnlButtons.Visible := false;
-         pnlWorksheet.Visible := false;
-         pnlGraph.Visible := true;
-         memLab.Height := pnlRight.Height div 5;
-         memLab.Clear;
-         if uReportType = 'H' then
+         if uPrevReportIndex <> lstReports.ItemIndex then
+         begin
+           lblSingleTest.Caption := '';
+           lblSpecimen.Caption := '';
+         end;
+         if not Ext then SelectTest(Font.Size);
+         if (length(lblSingleTest.Caption) > 2) and (length(lblSpecimen.Caption) > 2) then
+         begin
+           CommonComponentVisible(false,false,true,true,true,true,false,false,true);
+           pnlChart.Visible := true;
+           chtChart.Visible := true;
+           pnlButtons.Visible := false;
+           pnlWorksheet.Visible := false;
+           pnlGraph.Visible := true;
+           memLab.Height := pnlRight.Height div 5;
+           memLab.Clear;
+           if uReportType = 'H' then
            begin
              WebBrowser1.Visible := true;
@@ -502,27 +558,29 @@
              memLab.Visible := false;
            end
+           else
+           begin
+             WebBrowser1.Visible := false;
+             WebBrowser1.SendToBack;
+             memLab.Visible := true;
+             memLab.BringToFront;
+           end;
+           lstTestGraph.Items.Clear;
+           lstTestGraph.Width := 0;
+           FormResize(self);
+           RedrawActivate(memLab.Handle);
+           lblFooter.Caption := '';
+           chkGraphZoom.Checked := false;
+           chkGraphZoomClick(self);
+           chkGraph3DClick(self);
+           chkGraphValuesClick(self);
+           lstDatesClick(self);
+           if not Ext then cmdOtherTests.SetFocus;
+           cmdOtherTests.Default := true;
+         end
          else
-          begin
-            WebBrowser1.Visible := false;
-            WebBrowser1.SendToBack;
-            memLab.Visible := true;
-            memLab.BringToFront;
-          end;
-         lstTestGraph.Items.Clear;
-         lstTestGraph.Width := 0;
-         FormResize(self);
-         RedrawActivate(memLab.Handle);
-         lblFooter.Caption := '';
-         chkGraphZoom.Checked := false;
-         chkGraphZoomClick(self);
-         chkGraph3DClick(self);
-         chkGraphValuesClick(self);
-         lstDatesClick(self);
-         cmdOtherTests.SetFocus;
-         cmdOtherTests.Default := true;
-       end
-       else uPrevReportIndex := lstReports.ItemIndex;
-     end;
-  else
+           lstReports.ItemIndex := uPrevReportIndex;
+       end;
+     end
+    else // case
     begin
       //added to deal with other reports from file 101.24
@@ -734,41 +792,50 @@
      end;
   6: begin            // Graph
-       chtChart.BottomAxis.Automatic := true;
-       chkGraphZoom.Checked := false;
-       chkGraphZoomClick(self);
-       memLab.Clear;
-       uLabLocalReportData.Clear;
-       uLabRemoteReportData.Clear;
-       tmpList := TStringList.Create;
-       try
-         StatusText('Retrieving data for graph...');
-         tmpList.Assign(GetChart(Patient.DFN, date1, date2,
-           Piece(lblSpecimen.Caption, '^', 1),
-           Piece(lblSingleTest.Caption, '^', 1)));
-         if tmpList.Count > 1 then
-         begin
-           chtChart.Visible := true;
-           GraphChart(lblSingleTest.Caption, tmpList);
-           chtChart.ZoomPercent(ZOOM_PERCENT);
-           for i := strtoint(Piece(tmpList[0], '^', 1)) + 1 to tmpList.Count - 1
-             do memLab.Lines.Add(tmpList[i]);
-           if memLab.Lines.Count < 2 then
-             memLab.Lines.Add('<No comments on specimens.>');
-           memLab.SelStart := 0;
-         end
-         else
-         begin
-           if Piece(lblSpecimen.Caption, '^', 1) = '0' then
-             pnlChart.Caption := '<No results can be graphed for ' +
-               Piece(lblSingleTest.Caption, '^', 2) + ' in this date range.>'
+       if not uGraphingActivated then
+       begin
+         chtChart.BottomAxis.Automatic := true;
+         chkGraphZoom.Checked := false;
+         chkGraphZoomClick(self);
+         memLab.Clear;
+         uLabLocalReportData.Clear;
+         uLabRemoteReportData.Clear;
+         tmpList := TStringList.Create;
+         try
+           StatusText('Retrieving data for graph...');
+           tmpList.Assign(GetChart(Patient.DFN, date1, date2,
+             Piece(lblSpecimen.Caption, '^', 1),
+             Piece(lblSingleTest.Caption, '^', 1)));
+           if tmpList.Count > 1 then
+           begin
+             chtChart.Visible := true;
+             GraphChart(lblSingleTest.Caption, tmpList);
+             chtChart.ZoomPercent(ZOOM_PERCENT);
+             for i := strtoint(Piece(tmpList[0], '^', 1)) + 1 to tmpList.Count - 1
+               do memLab.Lines.Add(tmpList[i]);
+             if memLab.Lines.Count < 2 then
+               memLab.Lines.Add('<No comments on specimens.>');
+             memLab.SelStart := 0;
+             lblGraph.Visible := false;
+           end
            else
-             pnlChart.Caption := '<No results can be graphed for ' +
-               Piece(lblSingleTest.Caption, '^', 2)
-               + ' (' + Piece(lblSpecimen.Caption, '^', 2) +
-                 ') in this date range.>';
-           chtChart.Visible := false;
+           begin
+             lblGraph.Left := chtChart.Left + ((chtChart.Width - lblGraph.Width) div 2);
+             lblGraph.Top := 2;
+             lblGraph.Visible := true;
+             if Piece(lblSpecimen.Caption, '^', 1) = '0' then
+               pnlChart.Caption := '<No results can be graphed for ' +
+                 Piece(lblSingleTest.Caption, '^', 2) + ' in this date range.> '
+                 + 'Results may be available, but cannot be graphed. Please try an alternate view.'
+             else
+               pnlChart.Caption := '<No results can be graphed for ' +
+                 Piece(lblSingleTest.Caption, '^', 2)
+                 + ' (' + Piece(lblSpecimen.Caption, '^', 2) +
+                   ') in this date range.> '
+                 + 'Results may be available, but cannot be graphed. Please try an alternate view.';
+             chtChart.Visible := false;
+           end;
+         finally
+           tmpList.Free;
          end;
-       finally
-         tmpList.Free;
        end;
      end;
@@ -1285,10 +1352,15 @@
   if valuecount = 0 then
   begin
+    lblGraph.Left := chtChart.Left + ((chtChart.Width - lblGraph.Width) div 2);
+    lblGraph.Top := 2;
+    lblGraph.Visible := true;
     if length(Piece(specimen, '^', 2)) > 0 then
-      pnlChart.Caption := '<No results can be graphed for ' + serTest.Title + ' in this date range.>'
+      pnlChart.Caption := '<No results can be graphed for ' + serTest.Title + ' in this date range.> '
     else
       pnlChart.Caption := '<No results can be graphed for ' + Piece(test, '^', 2) + ' in this date range.>';
     chtChart.Visible := false;
-  end;
+  end
+  else
+    lblGraph.Visible := false;
   if not chkZoom.Checked then
   begin
@@ -1350,4 +1422,5 @@
        memLab.Align := alBottom;
        grdLab.Align := alClient;
+       if tmpGrid.Count > 0 then HGrid(tmpGrid);
        if (grdLab.VisibleRowCount + 1) < grdLab.RowCount then
          grdLab.ColWidths[4] := grdLab.ColWidths[4] - 18;
@@ -1387,11 +1460,14 @@
      end;
   6: begin               // Graph
-       memLab.Height := pnlLeft.Height div 4;
-       memLab.Align := alBottom;
-       pnlChart.Top := pnlHeader.Height;
-       pnlChart.Align := alClient;
-       memLab.Height := pnlLeft.Height div 4;
-       memLab.Align := alBottom;
-       memLab.Repaint;
+       if not uGraphingActivated then
+       begin
+         memLab.Height := pnlLeft.Height div 4;
+         memLab.Align := alBottom;
+         pnlChart.Top := pnlHeader.Height;
+         pnlChart.Align := alClient;
+         memLab.Height := pnlLeft.Height div 4;
+         memLab.Align := alBottom;
+         memLab.Repaint;
+       end;
      end;
   7: begin               // Anatomic Path
@@ -1985,4 +2061,5 @@
                     Timer1.Enabled := False;
                     TRemoteSite(Items[i]).LabQueryStatus := '-1^Timed out';
+                    UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'Timed out');
                     StatusText('');
                     TabControl1.OnChange(nil);
@@ -2034,4 +2111,11 @@
         begin
           TRemoteSite(Items[i]).LabClear;
+          if (LeftStr(TRemoteSite(Items[i]).SiteID, 5) = '200HD') then
+          begin
+            TRemoteSite(Items[i]).LabQueryStatus := '1^Not Included';
+            UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'NOT INCLUDED');
+            TabControl1.OnChange(nil);
+            continue;
+          end;
           TRemoteSite(Items[i]).CurrentLabQuery := 'Lab' + Patient.DFN + ';' + Patient.ICN +
             '^' + IntToStr(AItem) + '^' + IntToStr(AReportID) + '^^' + ARpc + '^' + AHSType +
@@ -2055,4 +2139,5 @@
                 TRemoteSite(Items[i]).LabRemoteHandle := '';
                 TRemoteSite(Items[i]).LabQueryStatus := '1^Done';
+                UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'Done');
                 TabControl1.OnChange(nil);
               end
@@ -2084,9 +2169,13 @@
               end;
               if Dest[0] = '' then
-                TRemoteSite(Items[i]).LabQueryStatus := '-1^Communication error'
+                begin
+                  TRemoteSite(Items[i]).LabQueryStatus := '-1^Communication error';
+                  UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'Communication error');
+                end
               else
                 begin
                   TRemoteSite(Items[i]).LabRemoteHandle := Dest[0];
                   TRemoteSite(Items[i]).LabQueryStatus := '0^initialization...';
+                  UpdateRemoteStatus(TRemoteSite(Items[i]).SiteID, 'Initialization');
                   Timer1.Enabled := True;
                   StatusText('Retrieving reports from '
