Index: cprs/trunk/CPRS-Chart/Consults/fConsults.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Consults/fConsults.pas	(revision 829)
+++ cprs/trunk/CPRS-Chart/Consults/fConsults.pas	(revision 1679)
@@ -180,4 +180,5 @@
     imgLblImages: TVA508ImageListLabeler;
     imgLblConsults: TVA508ImageListLabeler;
+    popNoteMemoViewCslt: TMenuItem;   //wat cq 17586
     procedure mnuChartTabClick(Sender: TObject);
     procedure lstConsultsClick(Sender: TObject);
@@ -285,4 +286,5 @@
     procedure cmdEditResubmitExit(Sender: TObject);
     procedure cmdNewConsultExit(Sender: TObject);
+    procedure popNoteMemoViewCsltClick(Sender: TObject);   //wat cq 17586
   private
     FocusToRightPanel : Boolean;
@@ -348,4 +350,6 @@
     function UserIsSigner(NoteIEN: integer): boolean;
   public
+    function CustomCanFocus(Control: TWinControl): Boolean; //CB
+    function LinesVisible(richedit: Trichedit): integer; //CB
     function ActiveEditOf(AnIEN: Int64): Boolean;
     function  AllowContextChange(var WhyNot: string): Boolean; override;
@@ -364,4 +368,5 @@
     property Drawers: TFrmDrawers read GetDrawers; // Keep Drawers published
   end;
+
 
 var
@@ -638,6 +643,7 @@
   CurrNotifIEN := 0;
   EditingIndex := -1;
-  tvConsults.Enabled := True;
-  lstConsults.Enabled := True ;
+  pnlConsultList.Enabled := True; //CQ#15785
+//  tvConsults.Enabled := True;
+//  lstConsults.Enabled := True ;
   lstNotes.Enabled := True ;
   pnlRead.BringToFront ;
@@ -769,6 +775,7 @@
   try
     ClearEditControls;
-    tvConsults.Enabled := False;
-    lstConsults.Enabled := False ;
+    pnlConsultList.Enabled := False; //CQ#15785
+//    tvConsults.Enabled := False;
+//    lstConsults.Enabled := False ;
     FillChar(FEditNote, SizeOf(FEditNote), 0);  //v15.7
     with FEditNote do
@@ -899,6 +906,7 @@
       begin
         ClearEditControls;
-        lstConsults.Enabled := True;
-        tvConsults.Enabled := True;
+        pnlConsultList.Enabled := True; //CQ#15785
+//        lstConsults.Enabled := True;
+//        tvConsults.Enabled := True;
       end;
     SetResultMenus ;
@@ -930,6 +938,7 @@
   AClassName := DCL_CONSULTS;
   ClearEditControls;
-  lstConsults.Enabled := False ;
-  tvConsults.Enabled := False;
+  pnlConsultList.Enabled := False; //CQ#15785
+//  lstConsults.Enabled := False ;
+//  tvConsults.Enabled := False;
   with FEditNote do
   begin
@@ -1008,6 +1017,7 @@
       InfoBox(CreatedNote.ErrorText, TX_CREATE_ERR, MB_OK);
       HaveRequired := False;
-      lstConsults.Enabled := True;
-      tvConsults.Enabled := True;
+      pnlConsultList.Enabled := True; //CQ#15785
+//      lstConsults.Enabled := True;
+//      tvConsults.Enabled := True;
     end; {if CreatedNote.IEN}
   end; {if HaveRequired}
@@ -1559,4 +1569,24 @@
 end;
 
+//wat cq 17586
+procedure TfrmConsults.popNoteMemoViewCsltClick(Sender: TObject);
+var
+  CsltIEN: integer ;
+  ConsultDetail: TStringList;
+  x: string;
+begin
+  inherited;
+  if (Screen.ActiveControl <> memResults) or (FEditNote.PkgPtr <> PKG_CONSULTS) then Exit;
+  CsltIEN := frmConsults.FEditNote.PkgIEN;
+  x := FindConsult(CsltIEN);
+  ConsultDetail := TStringList.Create;
+  try
+    LoadConsultDetail(ConsultDetail, CsltIEN) ;
+    ReportBox(ConsultDetail, 'Consult Details: #' + IntToStr(CsltIEN) + ' - ' + Piece(x, U, 4), TRUE);
+  finally
+    ConsultDetail.Free;
+  end;
+end;  //END cq 17586
+
 procedure TfrmConsults.mnuActAddIDEntryClick(Sender: TObject);
 const
@@ -1792,6 +1822,7 @@
       popNoteMemoEncounter.Visible := FALSE;
       UpdateList;
-      lstConsults.Enabled := True ;
-      tvConsults.Enabled := True;
+      pnlConsultList.Enabled := True; //CQ#15785
+//      lstConsults.Enabled := True ;
+//      tvConsults.Enabled := True;
       with tvConsults do Selected := FindPieceNode(IntToStr(SaveConsult), 1, U, Items.GetFirstNode);
       tvConsultsClick(Self);
@@ -1851,6 +1882,7 @@
           pnlResults.Visible := False;
           pnlResults.SendToBack;
-          lstConsults.Enabled := True;
-          tvConsults.Enabled := True;
+          pnlConsultList.Enabled := True; //CQ#15785
+//          lstConsults.Enabled := True;
+//          tvConsults.Enabled := True;
           if Notifications.Active then
             with tvConsults do
@@ -1971,6 +2003,7 @@
           pnlResults.Visible := False;
           pnlResults.SendToBack;
-          lstConsults.Enabled := True;
-          tvConsults.Enabled := True;
+          pnlConsultList.Enabled := True; //CQ#15785
+//          lstConsults.Enabled := True;
+//          tvConsults.Enabled := True;
           if Notifications.Active then
             with tvConsults do
@@ -2182,6 +2215,7 @@
   ClearEditControls ;
   lstNotes.Enabled := False ;
-  lstConsults.Enabled  := False ;
-  tvConsults.Enabled := False;
+  pnlConsultList.Enabled := False; //CQ#15785
+//  lstConsults.Enabled  := False ;
+//  tvConsults.Enabled := False;
   x := Piece(lstConsults.Items[lstConsults.ItemIndex], U, 12);
   if x <> '' then
@@ -2223,6 +2257,7 @@
   //UnlockConsultRequest(lstNotes.ItemIEN, lstConsults.ItemIEN);
   lstNotes.Enabled := True ;
-  lstConsults.Enabled := True ;
-  tvConsults.Enabled := True;
+  pnlConsultList.Enabled := True; //CQ#15785
+//  lstConsults.Enabled := True ;
+//  tvConsults.Enabled := True;
 end;
 
@@ -2396,5 +2431,4 @@
                                         (MenuAccessRec.UserLevel = UL_UNRESTRICTED))
                                         and
-                                        (ConsultRec.ORStatus=ST_COMPLETE) and
                                        ((lstNotes.ItemIndex > -1) and
                                        ((ConsultRec.TIUResultNarrative>0) or
@@ -2625,6 +2659,7 @@
    if ItemIndex = EditingIndex then
      begin
-       lstConsults.Enabled := False ;
-       tvConsults.Enabled := False;
+       pnlConsultList.Enabled := False; //CQ#15785
+//       lstConsults.Enabled := False ;
+//       tvConsults.Enabled := False;
        pnlResults.Visible := True;
        pnlResults.BringToFront;
@@ -2639,6 +2674,7 @@
        if EditingIndex = -1 then
          begin
-           lstConsults.Enabled := True ;
-           tvConsults.Enabled := True;
+           pnlConsultList.Enabled := True; //CQ#15785
+//           lstConsults.Enabled := True ;
+//           tvConsults.Enabled := True;
          end;
        lblTitle.Caption := MakeConsultNoteDisplayText(lstNotes.Items[lstNotes.ItemIndex]);
@@ -2710,4 +2746,5 @@
     popNoteMemoPreview.Enabled  := (frmDrawers.TheOpenDrawer = odTemplates) and Assigned(frmDrawers.tvTemplates.Selected);
     popNoteMemoInsTemplate.Enabled  := (frmDrawers.TheOpenDrawer = odTemplates) and Assigned(frmDrawers.tvTemplates.Selected);
+    popNoteMemoViewCslt.Enabled := (FEditNote.PkgPtr = PKG_CONSULTS);  //wat cq 17586
   end else
   begin
@@ -2718,4 +2755,5 @@
     popNoteMemoPreview.Enabled  := False;
     popNoteMemoInsTemplate.Enabled := False;
+    popNoteMemoViewCslt.Enabled := FALSE; //wat cq 17586
   end;
 end;
@@ -2838,5 +2876,4 @@
 end;
 
-{for printing multiple notes}
 procedure TfrmConsults.RequestMultiplePrint(AForm: TfrmPrintList);
 var
@@ -2844,13 +2881,20 @@
   i: integer;
 begin
+  inherited;
   with AForm.lbIDParents do
-  for i := 0 to Items.Count - 1 do
-  if Selected[i] then
-  begin
-    NoteIEN := StrToInt64def(Piece(Items[i], U, 1), 0);
-    if NoteIEN > 0 then PrintSF513(NoteIEN, DisplayText[i])
-    else if NoteIEN = 0 then InfoBox(TX_NOCONSULT, TX_NOCSLT_CAP, MB_OK)
-    else InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
-  end;
+  begin
+    for i := 0 to Items.Count - 1 do
+     begin
+       if Selected[i] then
+        begin
+         NoteIEN := ItemIEN;  //StrToInt64def(Piece(TStringList(Items.Objects[i])[0],U,1),0);
+         if NoteIEN > 0 then PrintSF513(NoteIEN, DisplayText[i]) else
+          begin
+           if NoteIEN = 0 then InfoBox(TX_NOCONSULT, TX_NOCSLT_CAP, MB_OK);
+           if NoteIEN < 0 then InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
+          end;
+        end; {if selected}
+     end; {for}
+  end; {with}
 end;
 
@@ -3104,4 +3148,8 @@
   AnObject: PDocTreeObject;
   tmpNode: TORTreeNode;
+  I:Integer;
+  CommentDate: String;
+  Format: CHARFORMAT2;
+  VisibleLineCount: integer;
 begin
   if EditingIndex <> -1 then
@@ -3116,6 +3164,7 @@
   tvConsults.Caption := Notifications.Text;
   EditingIndex := -1;
-  lstConsults.Enabled := True ;
-  tvConsults.Enabled := True;
+  pnlConsultList.Enabled := True; //CQ#15785
+//  lstConsults.Enabled := True ;
+//  tvConsults.Enabled := True;
   lstNotes.Enabled := True ;
   pnlRead.BringToFront ;
@@ -3204,7 +3253,38 @@
       tvCsltNotesChange(Self, tvCsltNotes.Selected);
     end
-  else if (ConsultRec.ORStatus = ST_COMPLETE) and ((ConsultRec.TIUDocuments.Count + ConsultRec.MedResults.Count) > 0) then
+  else if (ConsultRec.ORStatus = ST_COMPLETE) and ((ConsultRec.TIUDocuments.Count + ConsultRec.MedResults.Count) > 0)
+  and (Pos(UpperCase('Comment added'), UpperCase(Notifications.Text)) = 0) then //CB
     mnuActDisplayResultsClick(Self);
-    
+
+  //CB
+   If (Notifications.HighLightSection <> '') and (Pos(UpperCase('Comment added'), UpperCase(Notifications.Text)) > 0) then begin
+   CommentDate := FormatDateTime('mm/dd/yy hh:mm', StrToDateTime(StringReplace(Notifications.HighLightSection, '@', ' ', [rfReplaceAll])) );
+   for I := 0 to memConsult.Lines.Count - 1 do begin
+     If (Pos(CommentDate, memConsult.Lines.Strings[i]) > 0) and (Pos(UpperCase('ADDED COMMENT'), UpperCase(memConsult.Lines.Strings[i])) > 0) then begin
+      if CustomCanFocus(memconsult) then
+        memConsult.SetFocus;
+      memConsult.SelStart := memConsult.Perform(EM_LINEINDEX, i,0);
+      memConsult.SelLength := Length(memConsult.Lines.Strings[i]);
+
+      //Set the background color
+      Format.cbSize := SizeOf(Format);
+      Format.dwMask := CFM_BACKCOLOR;
+
+      Format.crBackColor := clRed;
+      memConsult.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
+          //Get visible Line Couunt
+       VisibleLineCount := LinesVisible(memConsult);
+
+      if (I + VisibleLineCount)>= memConsult.Lines.Count - 1 then
+        memConsult.SelStart := memConsult.Perform(EM_LINEINDEX, memConsult.Lines.Count - 1,0)
+      else memConsult.SelStart := memConsult.Perform(EM_LINEINDEX,I + VisibleLineCount - 1,0);
+
+      memConsult.Perform($00B7, 0, 0);  //EM_SETCARRET DEFINED WRONG in Richedit.pas
+      memConsult.SelLength := 0;
+      break;
+     end;
+   end;
+  end;
+
   case Notifications.Followup of
     NF_CONSULT_REQUEST_RESOLUTION   :  Notifications.Delete;
@@ -3221,4 +3301,51 @@
   FNotifPending := False;
 end;
+
+// *****************************************************************
+//                  Delphi's Can Focus has a bug.
+//     Source: http://qc.embarcadero.com/wc/qcmain.aspx?d=11229
+// *****************************************************************
+function TfrmConsults.CustomCanFocus(Control: TWinControl): Boolean;
+var
+  Form: TCustomForm;
+begin
+  Result := False;
+  Form := GetParentForm(Self);
+  if Form <> nil then
+  begin
+    Control := Self;
+    repeat
+      if not (Control.Visible and Control.Enabled) then
+       Exit;
+      Control := Control.Parent;
+    until Control = nil;
+    Result := True;
+  end;
+end;
+
+ function TfrmConsults.LinesVisible(richedit: Trichedit): integer;
+    Var
+      OldFont : HFont;
+      Hand : THandle;
+      TM : TTextMetric;
+      Rect  : TRect;
+      tempint : integer;
+    begin
+      Hand := GetDC(richedit.Handle);
+      try
+        OldFont := SelectObject(Hand, richedit.Font.Handle);
+        try
+          GetTextMetrics(Hand, TM);
+          richedit.Perform(EM_GETRECT, 0, longint(@Rect));
+          tempint := (Rect.Bottom - Rect.Top) div
+             (TM.tmHeight + TM.tmExternalLeading);
+        finally
+          SelectObject(Hand, OldFont);
+        end;
+      finally
+        ReleaseDC(richedit.Handle, Hand);
+      end;
+      Result := tempint;
+    end;
 
 procedure TfrmConsults.mnuActEditResubmitClick(Sender: TObject);
@@ -3948,6 +4075,7 @@
       if not LockConsultRequest(AConsult) then Exit;
       lstNotes.Enabled := False ;
-      lstConsults.Enabled  := False ;
-      tvConsults.Enabled := False;
+      pnlConsultList.Enabled := False; //CQ#15785
+//      lstConsults.Enabled  := False ;
+//      tvConsults.Enabled := False;
       if ActionType = 'ATTACH' then
         begin
@@ -3980,6 +4108,7 @@
     end;
   lstNotes.Enabled := True ;
-  lstConsults.Enabled  := True ;
-  tvConsults.Enabled := True;
+  pnlConsultList.Enabled := True; //CQ#15785
+//  lstConsults.Enabled  := True ;
+//  tvConsults.Enabled := True;
   FOrderID := GetConsultOrderIEN(AConsult);
   UnlockOrderIfAble(FOrderID);
@@ -4068,6 +4197,7 @@
           cmdPCE.Visible := FALSE;
           popNoteMemoEncounter.Visible := FALSE;
-          lstConsults.Enabled := True ;
-          tvConsults.Enabled := True;
+          pnlConsultList.Enabled := True; //CQ#15785
+//          lstConsults.Enabled := True ;
+//          tvConsults.Enabled := True;
           lstNotes.Enabled := True;
           lblTitle.Caption := '';
@@ -4435,6 +4565,7 @@
       popNoteListExpandSelected.Enabled := Selected.HasChildren;
       popNoteListCollapseSelected.Enabled := Selected.HasChildren;
-      lstConsults.Enabled := True ;
-      tvConsults.Enabled := True;
+      pnlConsultList.Enabled := True; //CQ#15785
+//      lstConsults.Enabled := True ;
+//      tvConsults.Enabled := True;
       lstNotes.Enabled := True;
       if (Selected.ImageIndex in [IMG_GMRC_TOP_LEVEL, IMG_GMRC_GROUP_OPEN, IMG_GMRC_GROUP_SHUT]) then
@@ -4450,6 +4581,7 @@
           cmdPCE.Visible := FALSE;
           popNoteMemoEncounter.Visible := FALSE;
-          lstConsults.Enabled := True ;
-          tvConsults.Enabled := True;
+          pnlConsultList.Enabled := True; //CQ#15785
+//          lstConsults.Enabled := True ;
+//          tvConsults.Enabled := True;
           KillDocTreeObjects(tvCsltNotes);
           tvCsltNotes.Items.Clear;
