Index: cprs/trunk/CPRS-Chart/fNotes.pas
===================================================================
--- cprs/trunk/CPRS-Chart/fNotes.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/fNotes.pas	(revision 830)
@@ -8,5 +8,6 @@
   fHSplit, StdCtrls, ExtCtrls, Menus, ComCtrls, ORCtrls, ORFn, uConst, ORDtTm,
   uPCE, ORClasses, fDrawers, ImgList, rTIU, uTIU, uDocTree, fRptBox, fPrintList,
-  fNoteST, ORNet, fNoteSTStop;
+  fNoteST, ORNet, fNoteSTStop, fBase508Form, VA508AccessibilityManager,
+  VA508ImageListLabeler;
 
 type
@@ -148,4 +149,8 @@
     mnuViewRemoteData: TMenuItem;
     mnuViewPostings: TMenuItem;
+    popNoteMemoViewCslt: TMenuItem;
+    mnuEncounter: TMenuItem;
+    imgLblNotes: TVA508ImageListLabeler;
+    imgLblImages: TVA508ImageListLabeler;
     procedure mnuChartTabClick(Sender: TObject);
     procedure lstNotesClick(Sender: TObject);
@@ -222,6 +227,4 @@
     procedure popNoteMemoInsTemplateClick(Sender: TObject);
     procedure popNoteMemoPreviewClick(Sender: TObject);
-    procedure tvNotesAddition(Sender: TObject; Node: TTreeNode);
-    procedure tvNotesDeletion(Sender: TObject; Node: TTreeNode);
     procedure tvNotesExit(Sender: TObject);
     procedure pnlReadExit(Sender: TObject);
@@ -229,6 +232,4 @@
     procedure FormHide(Sender: TObject);
     procedure FormShow(Sender: TObject);
-    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
-      Y: Integer);
     procedure memNewNoteKeyPress(Sender: TObject; var Key: Char);
     procedure memNewNoteKeyUp(Sender: TObject; var Key: Word;
@@ -239,4 +240,5 @@
     procedure ViewInfo(Sender: TObject);
     procedure mnuViewInformationClick(Sender: TObject);
+    procedure popNoteMemoViewCsltClick(Sender: TObject);
   private
     FNavigatingTab : Boolean; //Currently Using tab to navigate
@@ -261,5 +263,4 @@
     FOldDrawerPnlEncounterButtonExit: TNotifyEvent;
     FOldDrawerEdtSearchExit: TNotifyEvent;
-    FMousing: TDateTime;
     FStarting: boolean;
     procedure frmFramePnlPatientExit(Sender: TObject);
@@ -311,4 +312,5 @@
     property  OrderID: string read FOrderID;
     procedure LstNotesToPrint;
+    procedure UpdateFormForInput;
   published
     property Drawers: TFrmDrawers read GetDrawers; // Keep Drawers published
@@ -328,5 +330,6 @@
      fNoteProps, fNotesBP, fTemplateFieldEditor, dShared, rTemplates,
      FIconLegend, fPCEEdit, fNoteIDParents, rSurgery, uSurgery, uTemplates,
-     uAccessibleTreeView, uAccessibleTreeNode, fTemplateDialog, DateUtils;
+     fTemplateDialog, DateUtils, uInit, uVA508CPRSCompatibility, VA508AccessibilityRouter,
+  VAUtils;
      
 const
@@ -589,18 +592,12 @@
 begin
   with AForm.lbIDParents do
-  begin
-    for i := 0 to Items.Count - 1 do
-     begin
-       if Selected[i] then
-        begin
-         NoteIEN := StrToInt64def(Piece(TStringList(Items.Objects[i])[0],U,1),0);
-         if NoteIEN > 0 then PrintNote(NoteIEN, Items[i], TRUE) else
-         begin
-           if NoteIEN = 0 then InfoBox(TX_NONOTE, TX_NONOTE_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}
+  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 PrintNote(NoteIEN, DisplayText[i], TRUE)
+    else if NoteIEN = 0 then InfoBox(TX_NONOTE, TX_NONOTE_CAP, MB_OK)
+    else InfoBox(TX_NOPRT_NEW, TX_NOPRT_NEW_CAP, MB_OK);
+  end;
 end;
 
@@ -611,4 +608,5 @@
   frmDrawers.Font.Size  := NewFontSize;
   SetEqualTabStops(memNewNote);
+  pnlWriteResize(Self);
 end;
 
@@ -651,4 +649,6 @@
   // clear the editing controls (also clear the new labels?)
   txtSubject.Text := '';
+  //lblNotes.Caption := '';
+  SearchTextStopFlag := false;
   if memNewNote <> nil then memNewNote.Clear; //CQ7012 Added test for nil
   timAutoSave.Enabled := False;
@@ -745,4 +745,5 @@
       ShowPCEControls(FALSE);
   end; {if ItemIndex}
+  mnuEncounter.Enabled := cmdPCE.Visible;
 end;
 
@@ -774,5 +775,5 @@
     if (DocType = TYP_ADDENDUM) then
     begin
-      if AskCosignerForDocument(Addend, Author) and (Cosigner <= 0) then Result := True;
+      if AskCosignerForDocument(Addend, Author, DateTime) and (Cosigner <= 0) then Result := True;
     end else
     begin
@@ -981,5 +982,5 @@
           if PRF_IEN <> 0 then
             if sCallV('TIU LINK TO FLAG', [CreatedNote.IEN,PRF_IEN,ActionIEN,Patient.DFN]) = '0' then
-              ShowMessage('TIU LINK TO FLAG: FAILED');
+              ShowMsg('TIU LINK TO FLAG: FAILED');
         end;
 
@@ -1041,5 +1042,5 @@
       DocInfo := MakeXMLParamTIU(IntToStr(CreatedNote.IEN), FEditNote);
       ExecuteTemplateOrBoilerPlate(TmpBoilerPlate, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-      memNewNote.Lines.Assign(TmpBoilerPlate);
+      QuickCopyWith508Msg(TmpBoilerPlate, memNewNote);
       UpdateNoteAuthor(DocInfo);
       TmpBoilerPlate.Free;
@@ -1276,7 +1277,4 @@
   inherited;
   PageID := CT_NOTES;
-  memNote.Color := ReadOnlyColor;
-  memPCEShow.Color := ReadOnlyColor;
-  lblNewTitle.Color := ReadOnlyColor;
   EditingIndex := -1;
   FEditNote.LastCosigner := 0;
@@ -1289,11 +1287,6 @@
   frmDrawers.Splitter := splDrawers;
   frmDrawers.DefTempPiece := 1;
-  tvNotes.Images := dmodShared.imgNotes;
-  tvNotes.StateImages := dmodShared.imgImages;
-  lvNotes.StateImages := dmodShared.imgImages;
-  lvNotes.SmallImages := dmodShared.imgNotes;
   FImageFlag := TBitmap.Create;
   FDocList := TStringList.Create;
-  TAccessibleTreeView.WrapControl(tvNotes);
 end;
 
@@ -1319,4 +1312,5 @@
    if (Self <> nil) and (pnlLeft <> nil) and (pnlWrite <> nil) and (sptHorz <> nil) then
      pnlLeft.Width := self.ClientWidth - pnlWrite.Width - sptHorz.Width;
+  UpdateFormForInput;
 end;
 
@@ -1325,4 +1319,6 @@
 procedure TfrmNotes.lstNotesClick(Sender: TObject);
 { loads the text for the selected note or displays the editing panel for the selected note }
+var
+  x: string;
 begin
   inherited;
@@ -1339,4 +1335,5 @@
     mnuActLoadBoiler.Enabled := True;
     UpdateReminderFinish;
+    UpdateFormForInput;
   end else
   begin
@@ -1366,5 +1363,7 @@
   memNewNote.Repaint;
   memNote.Repaint;
-  NotifyOtherApps(NAE_REPORT, 'TIU^' + lstNotes.ItemID);
+  x := 'TIU^' + lstNotes.ItemID;
+  SetPiece(x, U, 10, Piece(lstNotes.Items[lstNotes.ItemIndex], U, 11));
+  NotifyOtherApps(NAE_REPORT, x);
 end;
 
@@ -1374,5 +1373,5 @@
   inherited;
   mnuActNewClick(Self);
-end;
+ end;
 
 procedure TfrmNotes.cmdPCEClick(Sender: TObject);
@@ -1449,5 +1448,5 @@
   begin
     ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-    memNewNote.Lines.Assign(BoilerText);
+    QuickCopyWith508Msg(BoilerText, memNewNote);
     UpdateNoteAuthor(DocInfo);
     FChanged := False;
@@ -1471,5 +1470,5 @@
         1: begin
              ExecuteTemplateOrBoilerPlate(BoilerText, FEditNote.Title, ltTitle, Self, 'Title: ' + FEditNote.TitleName, DocInfo);
-             memNewNote.Lines.AddStrings(BoilerText);  // append
+             QuickAddWith508Msg(BoilerText, memNewNote);  // append
              UpdateNoteAuthor(DocInfo);
            end;
@@ -1563,5 +1562,5 @@
   if PRF_IEN <> 0 then
     if sCallV('TIU LINK TO FLAG', [lstNotes.ItemIEN,PRF_IEN,ActionIEN,Patient.DFN]) = '0' then
-      ShowMessage('TIU LINK TO FLAG: FAILED');
+      ShowMsg('TIU LINK TO FLAG: FAILED');
   end;
 
@@ -1582,4 +1581,5 @@
   if lblRefDate.Left < (lblNewTitle.Left + lblNewTitle.Width + 6)
     then lblRefDate.Left := (lblNewTitle.Left + lblNewTitle.Width);
+  UpdateFormForInput;
 end;
 
@@ -1588,4 +1588,5 @@
   ErrMsg: string;
 begin
+  if fFrame.frmFrame.DLLActive = true then Exit;
   if (EditingIndex > -1) and FChanged then
   begin
@@ -1739,5 +1740,5 @@
   If FCurrentContext.SearchString <> '' then
     lblNotes.Caption := lblNotes.Caption+', containing "'+FCurrentContext.SearchString+'"';
-  If SearchTextStopFlag=True then begin;
+  If SearchTextStopFlag = True then begin;
     lblNotes.Caption := 'Search for "'+FCurrentContext.SearchString+'" was stopped!';
   end;
@@ -2289,8 +2290,9 @@
 
   UnlockConsultRequest(IEN);
-  if (AnIndex = lstNotes.ItemIndex) and (not frmFrame.ContextChanging) then
+  // GE 14926; added if (AnIndex> -1) to by pass LoadNotes when creating on narking Allerg Entered In error.
+  if (AnIndex > -1) and (AnIndex = lstNotes.ItemIndex) and (not frmFrame.ContextChanging) then
     begin
       LoadNotes;
-      with tvNotes do Selected := FindPieceNode(IntToStr(IEN), U, Items.GetFirstNode);
+        with tvNotes do Selected := FindPieceNode(IntToStr(IEN), U, Items.GetFirstNode);
     end;
 end;
@@ -2325,4 +2327,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); // if editing consult title
   end else
   begin
@@ -2333,4 +2336,5 @@
     popNoteMemoPreview.Enabled  := False;
     popNoteMemoInsTemplate.Enabled  := False;
+    popNoteMemoViewCslt.Enabled := FALSE;
   end;
 end;
@@ -2452,4 +2456,23 @@
     DoAutoSave(0);
     timAutoSave.Enabled := True;
+  end;
+end;
+
+procedure TfrmNotes.popNoteMemoViewCsltClick(Sender: TObject);
+var
+  CsltIEN: integer ;
+  ConsultDetail: TStringList;
+  x: string;
+begin
+  inherited;
+  if (Screen.ActiveControl <> memNewNote) or (FEditNote.PkgPtr <> PKG_CONSULTS) then Exit;
+  CsltIEN := 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;
@@ -2792,5 +2815,4 @@
 procedure TfrmNotes.FormDestroy(Sender: TObject);
 begin
-  TAccessibleTreeView.UnwrapControl(tvNotes);
   FDocList.Free;
   FImageFlag.Free;
@@ -2905,5 +2927,5 @@
                     Continue;
                   CallV('TIU GET RECORD TEXT', [Piece(FDocList.Strings[x],'^',1)]);
-                  Dest.Assign(RPCBrokerV.Results);
+                  FastAssign(RPCBrokerV.Results, Dest);
                   If Dest.Count > 0 then
                      for xx := 0 to Dest.Count-1 do
@@ -3001,5 +3023,5 @@
       uChanging := True;
       Items.BeginUpdate;
-      lstNotes.Items.AddStrings(DocList);
+      FastAddStrings(DocList, lstNotes.Items);
       BuildDocumentTree(DocList, '0', Tree, nil, FCurrentContext, CT_NOTES);
       Items.EndUpdate;
@@ -3628,16 +3650,4 @@
 end;
 
-procedure TfrmNotes.tvNotesAddition(Sender: TObject; Node: TTreeNode);
-begin
-  inherited;
-  TAccessibleTreeNode.WrapControl(Node as TORTreeNode);
-end;
-
-procedure TfrmNotes.tvNotesDeletion(Sender: TObject; Node: TTreeNode);
-begin
-  TAccessibleTreeNode.UnwrapControl(Node as TORTreeNode);
-  inherited;
-end;
-
 {Tab Order tricks.  Need to change
   tvNotes
@@ -3665,5 +3675,5 @@
 procedure TfrmNotes.tvNotesExit(Sender: TObject);
 begin
-  if IncSecond(FMousing,1) < Now then
+  if TabIsPressed or ShiftTabIsPressed then
   begin
     if (Screen.ActiveControl = frmDrawers.pnlTemplatesButton) or
@@ -3673,5 +3683,4 @@
       FindNextControl( cmdPCE, True, True, False).SetFocus;
   end;
-  FMousing := 0;
 end;
 
@@ -3679,5 +3688,5 @@
 begin
   inherited;
-  if IncSecond(FMousing,1) < Now then
+  if TabIsPressed or ShiftTabIsPressed then
   begin
     if (Screen.ActiveControl = frmFrame.pnlPatient) then
@@ -3690,5 +3699,4 @@
       FindNextControl( frmDrawers.pnlTemplatesButton, False, True, False).SetFocus;
   end;
-  FMousing := 0;
 end;
 
@@ -3696,5 +3704,5 @@
 begin
   inherited;
-  if IncSecond(FMousing,1) < Now then
+  if TabIsPressed or ShiftTabIsPressed then
   begin
     if (Screen.ActiveControl = lvNotes) or
@@ -3705,5 +3713,4 @@
       FindNextControl( frmFrame.pnlPatient, False, True, False).SetFocus;
   end;
-  FMousing := 0;
 end;
 
@@ -3711,11 +3718,15 @@
 begin
   FOldFramePnlPatientExit(Sender);
-  if IncSecond(FMousing,1) < Now then
+  if TabIsPressed or ShiftTabIsPressed then
   begin
     if (Screen.ActiveControl = lvNotes) or
         (Screen.ActiveControl = memNote) then
       FindNextControl( lvNotes, False, True, False).SetFocus;
-  end;
-  FMousing := 0;
+    if Screen.ActiveControl = memPCEShow then
+      if cmdPCE.CanFocus then
+        cmdPCE.SetFocus
+      else if cmdNewNote.CanFocus then
+        cmdNewNote.SetFocus;
+  end;
 end;
 
@@ -3764,11 +3775,4 @@
 end;
 
-procedure TfrmNotes.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
-  Y: Integer);
-begin
-  inherited;
-  FMousing := Now;
-end;
-
 procedure TfrmNotes.memNewNoteKeyPress(Sender: TObject; var Key: Char);
 begin
@@ -3803,9 +3807,7 @@
   inherited;
   //Fix the Tab Order  Make Drawers Buttons Accessible
-  if Boolean(Hi(GetKeyState(VK_TAB))) then
-    if Boolean(Hi(GetKeyState(VK_SHIFT))) then
-      cmdPCE.SetFocus
-    else
-      frmFrame.pnlPatient.SetFocus;
+  if TabIsPressed then
+    if frmDrawers.pnlTemplatesButton.CanFocus then
+      frmDrawers.pnlTemplatesButton.SetFocus
 end;
 
@@ -3823,8 +3825,7 @@
   inherited;
   //Fix the Tab Order  Make Drawers Buttons Accessible
-  if Boolean(Hi(GetKeyState(VK_TAB))) and
-     Not Boolean(Hi(GetKeyState(VK_SHIFT))) then
-        if memPCEShow.Visible then //CQ7120
-           memPCEShow.SetFocus; //CQ7120
+  if TabIsPressed then
+    if frmFrame.pnlPatient.CanFocus then
+      frmFrame.pnlPatient.SetFocus;
 end;
 
@@ -3849,5 +3850,31 @@
 end;
 
+procedure TfrmNotes.UpdateFormForInput;
+var
+  idx, offset: integer;
+
+begin
+  if (not pnlWrite.Visible) or uInit.TimedOut then exit;
+
+  if (frmFrame.WindowState = wsMaximized) then
+    idx := GetSystemMetrics(SM_CXFULLSCREEN)
+  else
+    idx := GetSystemMetrics(SM_CXSCREEN);
+  if idx > frmFrame.Width then
+    idx := frmFrame.Width;
+
+  offset := 5;
+  if(MainFontSize <> 8) then
+    offset := ResizeWidth(BaseFont, Font, offset);
+  dec(idx, offset + 10);
+  dec(idx, pnlLeft.Width);
+  dec(idx, sptHorz.Width);
+  dec(idx, cmdChange.Width);
+
+  cmdChange.Left := idx;
+end;
+
 initialization
+  SpecifyFormIsNotADialog(TfrmNotes);
   uPCEEdit := TPCEData.Create;
   uPCEShow := TPCEData.Create;
@@ -3856,5 +3883,5 @@
   if (uPCEEdit <> nil) then uPCEEdit.Free; //CQ7012 Added test for nil
   if (uPCEShow <> nil) then uPCEShow.Free; //CQ7012 Added test for nil
-
+   
 end.
 
