Index: cprs/branches/foia-cprs/CPRS-Chart/Orders/fODRad.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/Orders/fODRad.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/Orders/fODRad.pas	(revision 460)
@@ -56,5 +56,4 @@
     procedure FormCreate(Sender: TObject);
     procedure cboImTypeChange(Sender: TObject);
-    procedure FormPaint(Sender: TObject);
     procedure memReasonExit(Sender: TObject);
     procedure FormResize(Sender: TObject);
@@ -65,4 +64,8 @@
     procedure cboProcedureExit(Sender: TObject);
     procedure cboImTypeExit(Sender: TObject);
+    procedure FormClose(Sender: TObject; var Action: TCloseAction);
+    procedure chkIsolationExit(Sender: TObject);
+    procedure calPreOpExit(Sender: TObject);
+    procedure cboImTypeDropDownClose(Sender: TObject);
   private
     FLastRadID: string;
@@ -71,8 +74,13 @@
     FEvtDelayDiv: string;
     FPredefineOrder: boolean;
+    ImageTypeChanged : boolean;
+    FFormFirstOpened: boolean;
+    function NoPregnantSelection : Boolean;
+    procedure ImageTypeChange;
+    procedure FormFirstOpened(Sender: TObject);
   protected
     procedure InitDialog; override;
     procedure Validate(var AnErrMsg: string); override;
-    procedure SetDefaultPregant;    
+    procedure SetDefaultPregant;
   public
     procedure SetupDialog(OrderAction: Integer; const ID: string); override;
@@ -83,5 +91,6 @@
 {$R *.DFM}
 
-uses rODBase, rODRad, rOrders, uCore, rCore, fODRadApproval, fODRadConShRes, fLkUpLocation;
+uses rODBase, rODRad, rOrders, uCore, rCore, fODRadApproval, fODRadConShRes, fLkUpLocation, fFrame,
+  uFormMonitor;
 
 const
@@ -103,7 +112,7 @@
 var
   Radiologist, Contract, Research: string ;
-  AName: string;
+  AName, IsPregnant: string;
   ALocation, AType: integer;
-
+  
 { TfrmODBase common methods }
 
@@ -116,5 +125,5 @@
   if OrderAction in [ORDER_COPY, ORDER_EDIT, ORDER_QUICK] then with Responses do
   begin
-    if (OrderAction = ORDER_QUICK) or (OrderAction = ORDER_COPY) then
+    if (OrderAction = ORDER_QUICK) or (OrderAction = ORDER_EDIT) or (OrderAction = ORDER_COPY) then
       FPredefineOrder := True;
     FEditCopy := True;
@@ -125,4 +134,9 @@
         for i := 0 to Items.Count-1 do
           if StrToIntDef(Piece(Items[i],U,4), 0) = DisplayGroup then ItemIndex := i;
+        if OrderAction = ORDER_EDIT then
+        begin
+          Enabled := False;
+          Color := clBtnFace;
+        end;
      end;
     if Self.EvtID>0 then
@@ -171,8 +185,25 @@
           end;
       end;
+    //hds00007460
+    tmpResp := FindResponseByName('PREGNANT',1);
+    if tmpResp <> nil then
+       if Length(tmpResp.EValue)>0 then
+       begin
+          IsPregnant := tmpResp.EValue;
+          if IsPregnant = 'YES' then
+             radPregnant.Checked := True
+          else
+          if IsPregnant = 'NO' then
+             radPregnantNo.Checked := True
+          else
+          if IsPregnant = 'UNKNOWN' then
+             radPregnantUnknown.Checked := True;
+       end;
+    //hds00007460
     Changing := False;
     FEditCopy := False;
     OrderMessage(ImagingMessage(cboProcedure.ItemIEN)) ;
     ControlChange(Self);
+    FPredefineOrder := False;
   end;
 end;
@@ -184,4 +215,5 @@
 begin
   if not FEditCopy then inherited;
+
   FPreOpDate := '';
   FLastRadID := '';
@@ -203,4 +235,5 @@
       cboProcedure.Items.Add(FRadCommonCombo.Items[i]);
     if FRadCommonCombo.Items.Count>0 then cboProcedure.InsertSeparator;
+
     calRequestDate.Text := 'TODAY';
     SetControl(cboAvailMod, 'Modifiers');
@@ -286,5 +319,5 @@
   with cboCategory do if Length(ItemID)  > 0 then Responses.Update('CLASS',     1, ItemID, Text);
   with cboSubmit do if Length(ItemID)    > 0 then Responses.Update('IMLOC',     1, ItemID, Text);
-  with radPregnant do if Checked             then Responses.Update('PREGNANT',  1, 'Y'   , 'Yes')
+  with radPregnant do if Checked                then Responses.Update('PREGNANT',  1, 'Y'   , 'Yes')
                  else if not Enabled         then Responses.Update('PREGNANT',  1, ''    , '');
   with radPregnantNo do if Checked           then Responses.Update('PREGNANT',  1, 'N'   , 'No');
@@ -387,12 +420,14 @@
   with calRequestDate do
     if FMDateTime = 0 then SetError(TX_NO_DATE);
+
 end;
 
 procedure TfrmODRad.cboProcedureNeedData(Sender: TObject;
   const StartFrom: string; Direction, InsertAt: Integer);
+
 begin
   inherited ;
   cboProcedure.ForDataUse(SubSetOfRadProcs(DisplayGroup, StartFrom, Direction));
-end;
+ end;
 
 procedure TfrmODRad.cboAvailModMouseClick(Sender: TObject);
@@ -402,4 +437,6 @@
   Found: boolean;
 begin
+  if (cboAvailMod.Items.Count < 1) or  //GE 04-30-05 prevent list index out of bounds when empty
+     (cboAvailMod.ItemIndex < 0) then Exit;
   Found := False;
   with cboAvailMod do x := Items[ItemIndex];
@@ -445,9 +482,9 @@
    begin
     if ItemID <> FLastRadID then
-    begin
-      FLastRadID := ItemID;
-      if FPredefineOrder then
-        FPredefineOrder := False;
-    end else Exit;
+     begin
+       FLastRadID := ItemID;
+       if FPredefineOrder then
+         FPredefineOrder := False;
+     end else Exit;
     Changing := True;
     if Sender <> Self then
@@ -539,4 +576,7 @@
 procedure TfrmODRad.FormCreate(Sender: TObject);
 begin
+  FFormFirstOpened := TRUE;
+  ImageTypeChanged := false;
+  frmFrame.pnlVisit.Enabled := false;
   AutoSizeDisabled := True;
   inherited;
@@ -567,4 +607,5 @@
     radPregnantUnknown.Enabled := False;
   end else SetDefaultPregant;
+  FormMonitorBringToFrontEvent(Self, FormFirstOpened);
 end;
 
@@ -575,20 +616,5 @@
 begin
   inherited;
-  if FPredefineOrder then
-    FPredefineOrder := False;
-  if Changing or (cboImtype.ItemIndex = -1) then exit;
-  with cboImType do DisplayGroup := StrToIntDef(Piece(Items[ItemIndex], U, 4), 0) ;
-  if DisplayGroup = 0 then exit;
-  CtrlInits.LoadDefaults(ODForRad(Patient.DFN, FEvtDelayDiv, DisplayGroup));   // ODForRad returns TStrings with defaults
-  FPredefineOrder := False;
-  InitDialog;
-end;
-
-procedure TfrmODRad.FormPaint(Sender: TObject);
-begin
-  inherited;
-  with cboImType do
-    if not FEditCopy and (ItemIEN = 0) and (DroppedDown = False) and (Application.Active)
-      then DroppedDown := True;
+  ImageTypeChanged := true;
 end;
 
@@ -679,9 +705,74 @@
 end;
 
+
 procedure TfrmODRad.cboImTypeExit(Sender: TObject);
 begin
   inherited;
-  if FPredefineOrder then Exit
-  else cboImTypeChange(Self);
+  ImageTypeChange;
+end;
+
+procedure TfrmODRad.FormClose(Sender: TObject; var Action: TCloseAction);
+begin
+  inherited;
+  frmFrame.pnlVisit.Enabled := true;
+  FormMonitorBringToFrontEvent(Self, nil);
+end;
+
+procedure TfrmODRad.chkIsolationExit(Sender: TObject);
+begin
+  inherited;
+  //Fix for CQ: 10025
+  if TabIsPressed() then
+    if NoPregnantSelection() then
+      if radPregnant.CanFocus then
+        radPregnant.SetFocus();
+end;
+
+procedure TfrmODRad.calPreOpExit(Sender: TObject);
+begin
+  inherited;
+  //Fix for CQ: 10025
+  if ShiftTabIsPressed() then
+    if NoPregnantSelection() then
+      if radPregnant.CanFocus then
+        radPregnant.SetFocus();
+end;
+
+function TfrmODRad.NoPregnantSelection : Boolean;
+begin
+  result := not ((radPregnant.Checked) or (radPregnantNo.Checked) or (radPregnantUnknown.Checked));
+end;
+
+procedure TfrmODRad.cboImTypeDropDownClose(Sender: TObject);
+begin
+  inherited;
+  ImageTypeChange;
+end;
+
+procedure TfrmODRad.ImageTypeChange;
+begin
+  if not ImageTypeChanged then Exit;
+  ImageTypeChanged := false;
+  if FPredefineOrder then
+    FPredefineOrder := False;
+  if Changing or (cboImtype.ItemIndex = -1) then exit;
+  with cboImType do DisplayGroup := StrToIntDef(Piece(Items[ItemIndex], U, 4), 0) ;
+  if DisplayGroup = 0 then exit;
+  CtrlInits.LoadDefaults(ODForRad(Patient.DFN, FEvtDelayDiv, DisplayGroup));   // ODForRad returns TStrings with defaults
+  FPredefineOrder := False;
+  InitDialog;
+end;
+
+procedure TfrmODRad.FormFirstOpened(Sender: TObject);
+begin
+  if(FFormFirstOpened) then
+  begin
+    FFormFirstOpened := FALSE;
+    with cboImType do
+      if not FEditCopy and (ItemIEN = 0) and (DroppedDown = False) and (Application.Active) then
+      begin
+        cboImType.DroppedDown := TRUE;
+      end;
+  end;
 end;
 
