Index: cprs/trunk/CPRS-Chart/Orders/fODBase.pas
===================================================================
--- cprs/trunk/CPRS-Chart/Orders/fODBase.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/Orders/fODBase.pas	(revision 829)
@@ -8,5 +8,5 @@
   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, fAutoSz, StdCtrls,
   ORCtrls, ORFn, uConst, rOrders, rODBase, uCore, ComCtrls, ExtCtrls, Menus, Mask,
-  Buttons, UBAGlobals, UBACore;
+  Buttons, UBAGlobals, UBACore, VA508AccessibilityManager;
 
 type
@@ -182,4 +182,5 @@
     procedure SetDialogIEN(Value: Integer); virtual;
     procedure Validate(var AnErrMsg: string); virtual;
+    procedure updateSig; virtual;
     function ValidSave: Boolean;
     procedure ShowOrderMessage(Show: boolean);
@@ -221,5 +222,5 @@
 
 var
-  frmODBase: TfrmODBase;
+  frmODBase: TfrmODBase = nil;
   XfInToOutNow :boolean = False;       // it's used only for transfering Inpatient Meds to OutPatient Med for
                                        // immediately release (NO EVENT DELAY)
@@ -246,5 +247,5 @@
 uses fOCAccept, uODBase, rCore, rMisc, fODMessage,
   fTemplateDialog, uEventHooks, uTemplates, rConsults,fOrders,uOrders,
-  fFrame, uTemplateFields, fClinicWardMeds;
+  fFrame, uTemplateFields, fClinicWardMeds, fODDietLT, rODDiet, VAUtils;
 
 const
@@ -425,16 +426,16 @@
   else if AControl is TButton then with TButton(AControl) do Caption := CtrlInit.Text
   else if AControl is TEdit then with TEdit(AControl) do Text := CtrlInit.Text
-  else if AControl is TMemo then with TMemo(AControl) do Lines.Assign(CtrlInit.List)
-  else if AControl is TRichEdit then with TRichEdit(AControl) do Lines.Assign(CtrlInit.List)
-  else if AControl is TORListBox then with TORListBox(AControl) do Items.Assign(CtrlInit.List)
-  else if AControl is TListBox then with TListBox(AControl) do Items.Assign(CtrlInit.List)
+  else if AControl is TMemo then FastAssign(CtrlInit.List, TMemo(AControl).Lines)
+  else if AControl is TRichEdit then QuickCopy(CtrlInit.List, TRichEdit(AControl))
+  else if AControl is TORListBox then FastAssign(CtrlInit.List, TORListBox(AControl).Items)
+  else if AControl is TListBox then FastAssign(CtrlInit.List, TListBox(AControl).Items)
   else if AControl is TComboBox then with TComboBox(AControl) do
   begin
-    Items.Assign(CtrlInit.List);
+    FastAssign(CtrlInit.List, TComboBox(AControl).Items);
     Text := CtrlInit.Text;
   end
   else if AControl is TORComboBox then with TORComboBox(AControl) do
   begin
-    Items.Assign(CtrlInit.List);
+    FastAssign(CtrlInit.List, TORComboBox(AControl).Items);
     if LongList then InitLongList(Text) else Text := CtrlInit.Text;
     SelectByID(CtrlInit.ListID);
@@ -450,9 +451,9 @@
   CtrlInit := FindInitByName(ASection);
   if CtrlInit = nil then Exit;
-  if      AControl is TMemo       then with TMemo(AControl)       do Lines.Assign(CtrlInit.List)
-  else if AControl is TORListBox  then with TORListBox(AControl)  do Items.Assign(CtrlInit.List)
-  else if AControl is TListBox    then with TListBox(AControl)    do Items.Assign(CtrlInit.List)
-  else if AControl is TComboBox   then with TComboBox(AControl)   do Items.Assign(CtrlInit.List)
-  else if AControl is TORComboBox then with TORComboBox(AControl) do Items.Assign(CtrlInit.List);
+  if      AControl is TMemo       then FastAssign(CtrlInit.List, TMemo(AControl).Lines)
+  else if AControl is TORListBox  then FastAssign(CtrlInit.List, TORListBox(AControl).Items)
+  else if AControl is TListBox    then FastAssign(CtrlInit.List, TListBox(AControl).Items)
+  else if AControl is TComboBox   then FastAssign(CtrlInit.List, TComboBox(AControl).Items)
+  else if AControl is TORComboBox then FastAssign(CtrlInit.List, TORComboBox(AControl).Items);
 end;
 
@@ -1028,5 +1029,5 @@
     //AGP Text orders are only treated as IMO if the order display group is a nursing display group
     if (Patient.Inpatient = False) and (IsValidIMOLoc(encounter.Location,Patient.DFN)=true) and
-       (((pos('OR GXTEXT WORD PROCESSING ORDE',ConstructOrder.DialogName)>0) and (ConstructOrder.DGroup = NurDisp)) or
+       (((pos('OR GXTEXT WORD PROCESSING ORDER',ConstructOrder.DialogName)>0) and (ConstructOrder.DGroup = NurDisp)) or
        ((ConstructOrder.DialogName = 'OR GXMISC GENERAL') and (ConstructOrder.DGroup = NurDisp)) or
        ((ConstructOrder.DialogName = 'OR GXTEXT TEXT ONLY ORDER') and (ConstructOrder.DGroup = NurDisp))) and //AGP Change CQ #10757
@@ -1144,5 +1145,10 @@
         //  CheckBoilerplate4Fields(tmp, cptn)
         //else
-          ExecuteTemplateOrBoilerPlate(tmp, IEN, LType, nil, cptn, DocInfo);
+
+        // CQ #11669 - changing an existing order shouldn't restart template - JM
+          if assigned(frmODBase) and (frmODBase.FOrderAction = ORDER_EDIT) then
+            CheckBoilerplate4Fields(tmp, cptn)
+          else
+            ExecuteTemplateOrBoilerPlate(tmp, IEN, LType, nil, cptn, DocInfo);
       end
     else
@@ -1391,5 +1397,5 @@
 begin
   inherited;
-  memOrder.Color := ReadOnlyColor;
+  frmODBase   := Self;
   FAcceptOK   := False;
   FAutoAccept := False;
@@ -1420,8 +1426,10 @@
   FEvtType   := OrderEventTypeOnCreate;
   FEvtName   := OrderEventNameOnCreate;
+  DefaultButton := cmdAccept;
 end;
 
 procedure TfrmODBase.FormDestroy(Sender: TObject);
 begin
+  frmODBase := nil;
   FCtrlInits.Free;
   FResponses.Free;
@@ -1478,8 +1486,10 @@
   NewOrder: TOrder;
   CanSign, OrderAction: Integer;
+  IsDelayOrder: boolean;
   //thisSourceOrder: TOrder;
 begin
   Result := True;
   Validate(ErrMsg);
+  IsDelayOrder := False;
   if Length(ErrMsg) > 0 then
   begin
@@ -1531,5 +1541,6 @@
         else CanSign := CH_SIGN_NA;
       if NewOrder.Signature = OSS_NOT_REQUIRE then CanSign := CH_SIGN_NA;
-      Changes.Add(CH_ORD, NewOrder.ID, NewOrder.Text, Responses.FViewName, CanSign);
+      if NewOrder.EventPtr <> '' then IsDelayOrder := True;
+      Changes.Add(CH_ORD, NewOrder.ID, NewOrder.Text, Responses.FViewName, CanSign,'',0, NewOrder.DGroupName, False,IsDelayOrder);
 
     UBAGlobals.TargetOrderID := NewOrder.ID;
@@ -1558,4 +1569,6 @@
   theGrpName: string;
   alreadyClosed: boolean;
+  LateTrayFields: TLateTrayFields;
+  x, CxMsg: string;
 begin
   FAcceptOK := False;
@@ -1571,4 +1584,37 @@
     end;
   end;
+
+  // check for diet orders that will be auto-DCd because of start/stop overlaps
+  if Responses.Dialog = 'FHW1' then
+  begin
+    if (Self.EvtID <> 0) then
+    begin
+      CheckForAutoDCDietOrders(Self.EvtID, Self.DisplayGroup, '', CxMsg, cmdAccept);
+      if CxMsg <> '' then
+      begin
+        if InfoBox(CxMsg + CRLF + CRLF +
+           'Have you done either of the above?', 'Possible delayed order conflict',
+           MB_ICONWARNING or MB_YESNO) = ID_NO
+           then exit;
+      end;
+    end
+    else if FAutoAccept then
+    begin
+      x := CurrentDietText;
+      CheckForAutoDCDietOrders(0, Self.DisplayGroup, x, CxMsg, nil);
+      if CxMsg <> '' then
+      begin
+        if InfoBox(CxMsg + CRLF +
+                  'Are you sure?', 'Confirm', MB_ICONWARNING or MB_YESNO) = ID_NO then
+        begin
+          //AbortOrder := True;
+          FAcceptOK := FALSE;
+          //cmdQuitClick(Self);
+          exit;
+        end;
+      end;
+    end;
+  end;
+
   if ValidSave then
   begin
@@ -1581,5 +1627,12 @@
         else
         begin
+          LateTrayFields.LateMeal := #0;
+          with Responses do
+            if FAutoAccept and ((Dialog = 'FHW1') or (Dialog = 'FHW OP MEAL') or (Dialog ='FHW SPECIAL MEAL')) then
+            begin
+              LateTrayCheck(Responses, Self.EvtID, not OrderForInpatient, LateTrayFields);
+            end;
           ClearDialogControls;    // to allow form to close without prompting to save order
+          with LateTrayFields do if LateMeal <> #0 then LateTrayOrder(LateTrayFields, OrderForInpatient);
           Close;
           alreadyClosed := True;
@@ -1627,4 +1680,5 @@
 begin
   inherited;
+  FFromQuit := True;
   Close;
 end;
@@ -1665,4 +1719,5 @@
       exit;
     end;
+  if FFromQuit = False then updateSig;
   if Length(memOrder.Text) > 0 then
   begin
@@ -1681,4 +1736,9 @@
       if not ValidSave then CanClose := False;
   if CanClose then InitDialog;
+end;
+
+procedure TfrmODBase.updateSig;
+begin
+
 end;
 
@@ -1785,5 +1845,5 @@
         if Length(TempMSG)>0 then
         begin
-          ShowMessage(TempMSG);
+          ShowMsg(TempMSG);
           Result := False;
         end;
