Index: cprs/branches/foia-cprs/CPRS-Chart/Orders/fODMeds.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/Orders/fODMeds.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/Orders/fODMeds.pas	(revision 460)
@@ -86,4 +86,5 @@
     memDrugMsg: TMemo;
     txtNSS: TLabel;
+    SpeedButton1: TSpeedButton;
     procedure FormCreate(Sender: TObject);
     procedure btnSelectClick(Sender: TObject);
@@ -186,4 +187,13 @@
     procedure cboScheduleExit(Sender: TObject);
     procedure cboXScheduleExit(Sender: TObject);
+    procedure cboDosageKeyUp(Sender: TObject; var Key: Word;
+      Shift: TShiftState);
+    procedure cboXDosageKeyUp(Sender: TObject; var Key: Word;
+      Shift: TShiftState);
+    procedure txtSupplyClick(Sender: TObject);
+    procedure txtQuantityClick(Sender: TObject);
+    procedure txtRefillsClick(Sender: TObject);
+    procedure WMClose(var Msg : TWMClose); message WM_CLOSE;
+    procedure cboXScheduleEnter(Sender: TObject);
     //procedure btnNSSClick(Sender: TObject);
   private
@@ -236,8 +246,8 @@
     FOrigiMsgDisp: boolean;
     FNSSOther: boolean;
-    FFromClick: boolean;
+    {selection}
     FShowPnlXScheduleOk : boolean;
     FRemoveText : Boolean;
-    {selection}
+    FSmplPRNChkd: Boolean;
     procedure ChangeDelayed;
     function FindQuickOrder(const x: string): Integer;
@@ -302,8 +312,10 @@
 //    function ValidateRoute(RouteCombo: TORComboBox) : Boolean; Removed based on Site feeback. See CQ: 7518
     function IsSupplyAndOutPatient : boolean;
+    function GetSchedListIndex(SchedCombo: TORComboBox; pSchedule: String):integer;
   protected
     procedure InitDialog; override;
     procedure Validate(var AnErrMsg: string); override;
   public
+    ARow1: integer;
     procedure SetupDialog(OrderAction: Integer; const ID: string); override;
     procedure CheckDecimal(var AStr: string);
@@ -319,5 +331,5 @@
 
 uses rCore, uCore, ORFn, rODMeds, rODBase, rOrders, fRptBox, fODMedOIFA,
-  uAccessibleStringGrid, uOrders, fOtherSchedule, StrUtils;
+  uAccessibleStringGrid, uOrders, fOtherSchedule, StrUtils, fFrame;
 
 const
@@ -329,4 +341,5 @@
   COL_DURATION =  4;
   COL_SEQUENCE =  5;
+  COL_CHKXPRN  =  6;
   VAL_DOSAGE   = 10;
   VAL_ROUTE    = 20;
@@ -334,4 +347,5 @@
   VAL_DURATION = 40;
   VAL_SEQUENCE = 50;
+  VAL_CHKXPRN  = 60;
   TAB          = #9;
   {field identifiers}
@@ -387,4 +401,5 @@
   TC_NO_DEA     = 'DEA# Required';
   TX_NO_MED     = 'Medication must be selected.';
+  TX_NO_SEQ     = 'Missing one or more conjunction.';
   TX_NO_DOSE    = 'Dosage must be entered.';
   TX_DOSE_NUM   = 'Dosage may not be numeric only';
@@ -422,8 +437,10 @@
   x: string;
 begin
+  frmFrame.pnlVisit.Enabled := false;
   AutoSizeDisabled := True;
   inherited;
   btnXDuration.Align := alClient;
   AllowQuickOrder := True;
+  FSmplPRNChkd := False; // GE CQ7585
   CheckAuthForMeds(x);
   if Length(x) > 0 then
@@ -456,5 +473,7 @@
   {if not FInptDlg then } Responses.SetPromptFormat('INSTR', '@');
   StatusText('Loading Schedules');
-  LoadSchedules(cboSchedule.Items, FInptDlg);
+  //if (Self.EvtID > 0) then LoadSchedules(cboSchedule.Items)
+  //else LoadSchedules(cboSchedule.Items, FInptDlg);
+  LoadSchedules(cboSchedule.Items, FInptDlg);  
   StatusText('');
   if FInptDlg then SetControlsInpatient else SetControlsOutpatient;
@@ -466,4 +485,6 @@
   begin
     txtNss.Visible := True;
+    //cboSchedule.ListItemsOnly := True;
+    //cboXSchedule.ListItemsOnly := True;
   end;
   with grdDoses do
@@ -537,4 +558,5 @@
   FAllDrugs.Free;
   TAccessibleStringGrid.UnwrapControl(grdDoses);
+  frmFrame.pnlVisit.Enabled := true;
   inherited;
 end;
@@ -558,10 +580,9 @@
   FQOInitial  := False;
   FNSSOther   := False;
-  FFromClick  := False;
 end;
 
 procedure TfrmODMeds.SetupDialog(OrderAction: Integer; const ID: string);
 var
-  AnInstr, OrderID, nsSch: string;
+  AnInstr, OrderID, nsSch, Text: string;
   ix: integer;
 begin
@@ -606,4 +627,10 @@
              begin
                 SetSchedule(nsSch);
+                {cboSchedule.SelectByID(nsSch);
+                if cboSchedule.ItemIndex < 0 then
+                begin
+                  cboSchedule.Items.Add(nsSch);
+                  cboSchedule.ItemIndex := cboSchedule.Items.IndexOf(nsSch);
+                end;}
              end;
            end;
@@ -611,5 +638,6 @@
        end;
     end;  //nss
-    UpdateRelated(FALSE);
+    if ((OrderAction <> Order_COPY) and (OrderAction <> Order_EDIT)) or
+    (XfInToOutNow = true) then UpdateRelated(FALSE); //AGP Change
     Changing := False;
   end;
@@ -624,5 +652,6 @@
       then AnInstr := 'Copy: ' + AnInstr
       else AnInstr := 'Change: ' + AnInstr;
-    Caption := AnInstr;
+    Text := AnsiReplaceText(AnInstr,CRLF,'');
+    Caption := Text;
     memComment.Clear;  // sometimes the sig is in the comment
   end;
@@ -654,10 +683,17 @@
     // and is not an outpaitent order, then display error text to require route
     if (Length(x) = 0) and (Not IsSupplyAndOutPatient) then
+    begin
+      if cboRoute.Showing = true then cboRoute.SetFocus;  //CQ: 7467
       SetError(TX_NO_ROUTE);
+    end;
     if (Length(x) > 0) and NeedLookup then
     begin
       LookupRoute(x, RouteID, RouteAbbr);
       if RouteID = '0'
-        then SetError(TX_NF_ROUTE)
+        then
+        begin
+         if cboRoute.Showing = true then cboRoute.SetFocus;    //CQ: 7467
+        SetError(TX_NF_ROUTE);
+        end
         else Responses.Update('ROUTE', AnInstance, RouteID, RouteAbbr);
     end;
@@ -678,5 +714,4 @@
     else if (Length(tmpX) = 0) and FInptDlg and ScheduleRequired(txtMed.Tag, ARoute, ADrug)
       then SetError(TX_NO_SCHED);
-
     if Length(tmpX) > 0 then
     begin
@@ -706,6 +741,15 @@
     if (ValueOfResponse(FLD_DRUG_ID, i) = '') then
     begin
-      if not ContainsAlpha(Responses.IValueFor('INSTR', i)) then SetError(TX_DOSE_NUM);
-      if Length(Responses.IValueFor('INSTR', i)) > 60       then SetError(TX_DOSE_LEN);
+      if not ContainsAlpha(Responses.IValueFor('INSTR', i)) then
+      begin
+         SetError(TX_DOSE_NUM);
+         if tabDose.TabIndex = TI_DOSE then
+            cboDosage.SetFocus;    //CQ: 7467
+      end;
+      if Length(Responses.IValueFor('INSTR', i)) > 60       then
+      begin
+         SetError(TX_DOSE_LEN);
+         cboDosage.SetFocus;  //CQ: 7467
+      end;
     end;
     ValidateRoute(Responses.EValueFor('ROUTE', i), Responses.IValueFor('ROUTE', i) = '', i);
@@ -713,4 +757,16 @@
     i := Responses.NextInstance('INSTR', i);
   end;
+  //AGP Change 26.45 Fix for then/and conjucntion PSI-04-069
+  if self.tabDose.TabIndex = 1 then
+    begin
+       for i := 2 to self.grdDoses.RowCount do
+         begin
+           if ((ValFor(COL_DOSAGE, i-1) <> '') and (ValFor(COL_DOSAGE, i) <> '')) and (ValFor(COL_SEQUENCE,i-1) = '') then
+             begin
+              SetError(TX_NO_SEQ);
+              Exit;
+             end;
+         end;
+    end;
   if not FInptDlg then                            // outpatient stuff
   begin
@@ -953,4 +1009,11 @@
     UniqueText := False;
   FFromSelf := True;
+  {AutoSelection is only based upon uniquely matching characters.
+   Several CQs have been resolved relating to this issue:
+   See CQ:
+   7326 - Auto complete does not work correctly if user has quick orders in Medication list
+   7328 - PSI-05-016: TAM-0205-31170  Med Error due to pre-populated med screen
+   6715 PSI-04-044 Orders: NJH-0804-20315  Physician unable to enter medication order
+  }
   if UniqueText then
   begin
@@ -1129,4 +1192,5 @@
   QOQuantityStr := '';
   btnSelect.SetFocus;                             // let the exit events finish
+
   if pnlMeds.Visible then                         // display the medication fields
   begin
@@ -1294,4 +1358,5 @@
   lblQtyMsg.Caption := '';
   lblQuantity.Caption := 'Quantity';
+  FSmplPRNChkd := chkPRN.Checked;  //  GE  CQ7585
   chkPRN.Checked := False;
   FLastUnits    := '';
@@ -1318,23 +1383,5 @@
   QOPiUnChk := False;
   PKIEnviron := False;
-  if GetPKISite and GetPKIUse then  //PKI check for crypto object on workstation
-    begin
-      try  //PKI object creation
-        crypto := CoXuDigSigS.Create;
-        crypto.GetCSP;
-        StatusText(crypto.Reason);
-        PKIEnviron := True;
-      except
-        on  E: Exception do
-          begin
-            {ShowMessage('An error has been encountered while trying to create PKI environment: '+ E.Message +
-            '.  This order will be processed without Digital Signature encryption.');}
-            PKIEnviron := False;
-          end;
-      end;
-      crypto := nil;
-    end;
-  if PKIEnviron = False then
-    if GetPKISite then PKIEnviron := True;
+  if GetPKISite then PKIEnviron := True;
   with CtrlInits do
   begin
@@ -1381,9 +1428,9 @@
       end;
       pnlTop.Height := pnlFields.Height - pnlBottom.Height;
-      chkDoseNow.Top := memComment.Top + memComment.Height + 4;
+      chkDoseNow.Top := memComment.Top + memComment.Height + 1;
       lblPriority.Top := memcomment.Top + memComment.Height + 1;
       cboPriority.Top := lblPriority.Top + lblPriority.Height;
       lblAdminTime.Left := chkDoseNow.Left;
-      lblAdminTime.Top := chkDoseNow.Top + chkDoseNow.Height + 1;
+      lblAdminTime.Top := chkDoseNow.Top + chkDoseNow.Height - 1;
     end else
     begin
@@ -1456,5 +1503,6 @@
         SetDosage(IValueFor('INSTR', i));
         with cboDosage do
-          if ItemIndex > -1 then x := Text + TAB + Items[ItemIndex] else x := Text;
+          if ItemIndex > -1 then x := Text + TAB + Items[ItemIndex]
+         else x := IValueFor('INSTR',i); //AGP Change 26.41 for CQ 9102 PSI-05-015 affect copy and edit functionality
         grdDoses.Cells[COL_DOSAGE, i] := x;
         SetControl(cboRoute,  'ROUTE', i);
@@ -1474,4 +1522,5 @@
           if ItemIndex > -1 then x := x + TAB + Items[ItemIndex];
         grdDoses.Cells[COL_SCHEDULE, i] := x;
+        if chkPRN.Checked = True then grdDoses.Cells[COL_CHKXPRN,i] := '1';
         grdDoses.Cells[COL_DURATION, i] := IValueFor('DAYS', i);
         if      IValueFor('CONJ', i) = 'A' then x := 'AND'
@@ -1597,5 +1646,5 @@
   txtMed.SetFocus;
   FDrugID := '';
-  ShowOrderMessage( False );
+  //ShowOrderMessage( False );
 end;
 
@@ -1628,6 +1677,6 @@
 
 procedure TfrmODMeds.ShowControlsSimple;
-var
-  dosagetxt: string;
+//var
+  //dosagetxt: string;
 begin
   //Commented out, no longer using CharsNeedMatch Property
@@ -1661,19 +1710,43 @@
 procedure TfrmODMeds.ShowControlsComplex;
 
-  procedure MoveCombo(SrcCombo, DestCombo: TORComboBox);
-  begin
-    DestCombo.Items.Clear;
-    DestCombo.Items.Assign(SrcCombo.Items);
-    DestCombo.ItemIndex := SrcCombo.ItemIndex;
-    DestCombo.Text := Piece(SrcCombo.Text, TAB, 1);
-  end;
-
-var
-  dosagetxt: string;
+  procedure MoveCombo(SrcCombo, DestCombo: TORComboBox; CompSch: boolean = false); //AGP Changes 26.12 PSI-04-63
+  var
+  cnt,i,index: integer;
+  node,text: string;
+  begin
+  if (CompSch = false) or not (FInptDlg)then
+    begin
+      DestCombo.Items.Clear;
+      DestCombo.Items.Assign(SrcCombo.Items);
+      DestCombo.ItemIndex := SrcCombo.ItemIndex;
+      DestCombo.Text := Piece(SrcCombo.Text, TAB, 1);
+    end;
+  if (CompSch = true) and (FInptDlg) then     // AGP Changes 26.12 PSI-04-63
+    begin
+    //AGP change 26.34 CQ 7201,6902 fix the problem with one time schedule still showing for inpatient complex orders
+    DestCombo.ItemIndex := -1;
+    Text := SrcCombo.Text;
+    index := SrcCombo.ItemIndex;
+    cnt := 0;
+    for i := 0 to SrcCombo.Items.Count - 1 do
+      begin
+        node := SrcCombo.Items.Strings[i];
+        if piece(node,U,3) <> 'O' then
+          begin
+            DestCombo.Items.Add(SrcCombo.Items.Strings[i]);
+            if Piece(node,U,1) = text then DestCombo.ItemIndex := index - cnt;
+          end
+        else cnt := cnt+1;
+      end;
+    end;
+  end;
+
+//var
+  //dosagetxt: string;
 begin
   tabDose.TabIndex := TI_COMPLEX;
   MoveCombo(cboDosage,   cboXDosage);
   MoveCombo(cboRoute,    cboXRoute);
-  MoveCombo(cboSchedule, cboXSchedule);
+  MoveCombo(cboSchedule, cboXSchedule, true);  //AGP Changes 26.12 PSI-04-063
   grdDoses.Visible := True;
   btnXInsert.Visible := True;
@@ -1689,5 +1762,5 @@
   ActiveControl := grdDoses;
   //Commented out, no longer using CharsNeedMatch Property
- { NumCharsForMatch := 0;
+{  NumCharsForMatch := 0;
   for i := 0 to cboXDosage.Items.Count - 1 do         //find the shortest unit dose text on fifth piece
   begin
@@ -1719,6 +1792,8 @@
         Break;
       end;
-    if ((DoseIndex < 0) and (not IsTransferAction)) then Text := x
-    else if ((DoseIndex < 0) and IsTransferAction) then Text := ''
+    if DoseIndex <0 then Text := x
+  (*  if ((DoseIndex < 0) and (not IsTransferAction)) then Text := x
+    else if ((DoseIndex < 0) and IsTransferAction) and (DosageTab = False) then Text := ''
+    else if ((DoseIndex < 0) and IsTransferAction) and (DosageTab = True) then Text := x *)
     else ItemIndex := DoseIndex;
   end;
@@ -1740,8 +1815,10 @@
 procedure TfrmODMeds.SetSchedule(const x: string);
 var
-  NonPRNPart: string;
+NonPRNPart: string;
 begin
   cboSchedule.ItemIndex := -1;
-  if Pos('PRN', x) > 0 then
+  //AGP change CQ 10593, remove code to match the new expected first dose code
+  //PSI-05-026
+ (* if Pos('PRN', x) > 0 then
   begin
     NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
@@ -1762,5 +1839,5 @@
       chkPRN.Checked := True;
   end else
-  begin
+  begin  *)
     chkPRN.Checked := False;
     cboSchedule.SelectByID(x);
@@ -1773,26 +1850,55 @@
       else
       begin
-        cboSchedule.Items.Add(x);
-        cboSchedule.Text := x;
-        cboSchedule.SelectByID(x);
+      if Pos('PRN', x) > 0 then
+        begin
+         NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
+         chkPRN.Checked := True;
+         cboSchedule.SelectByID(NonPRNPart);
+         if cboSchedule.ItemIndex > -1 then  EXIT;
+         cboSchedule.Items.Add(NonPRNPart);
+         cboSchedule.Text := NonPRNPart;
+         cboSchedule.SelectByID(NonPRNPart);
+         EXIT;
+        end;
+         cboSchedule.Items.Add(x);
+         cboSchedule.Text := x;
+         cboSchedule.SelectByID(x);
       end;
-    end;
   end;
 end;
 
 { Medication edit --------------------------------------------------------------------------- }
-
 procedure TfrmODMeds.tabDoseChange(Sender: TObject);
 var
-  x: string;
-
-begin
-  inherited;
+  //text,x, tmpsch: string;
+  text, x: string;
+  reset: integer;
+begin
+  inherited;
+  reset := 0;
+  //AGP change for CQ 6521 added warning message
+  //AGP Change for CQ 7508 added tab information
+  //GE  Change warning message functionality show only   cq 7590
+  //    when tab changes from complex to simple.
+  //AGP Change for CQ 7834 and 7832 change text and added check to see if some values have been completed in row 1
+  if (tabDose.TabIndex = 0) and ((ValFor(COL_DOSAGE, 1)<>'') or (ValFor(COL_SCHEDULE, 1)<>'') or (ValFor(COL_DURATION, 1)<>'') or
+      (ValFor(COL_SEQUENCE, 1)<>''))  then
+      begin
+        text := 'By switching to the Dosage Tab, ' ;
+         if (InfoBox(text +'you will lose all data on this screen. Click OK to continue or Cancel','Warning',MB_OKCANCEL)=IDCANCEL) then
+            begin
+             if tabDose.TabIndex = 1 then tabDose.TabIndex := 0
+             else tabDose.TabIndex := 1;
+             reset := 1;
+            end;
+      end;
   case tabDose.TabIndex of
   TI_DOSE:    begin
+                cboXSchedule.Clear;                       // Added to Fix CQ: 9603
                 // clean up responses?
                 FSuppressMsg := FOrigiMsgDisp;
                 ShowControlsSimple;
-                ResetOnTabChange;
+                if reset = 0 then ResetOnTabChange;
+                txtNss.Left := lblSchedule.Left + lblSchedule.Width + 2;
                 if (FInptDlg) then txtNss.Visible := True
                 else txtNss.Visible := False;
@@ -1805,8 +1911,9 @@
   TI_COMPLEX: begin
                 FSuppressMsg := FOrigiMsgDisp;
+                if reset = 1 then exit;
                 ShowControlsComplex;
                 ResetOnTabChange;
+                txtNss.Left := grdDoses.Left + grdDoses.ColWidths[0] + grdDoses.ColWidths[1] + grdDoses.ColWidths[2] + 3;
                 txtNss.Visible := False;
-                if txtNss.Visible then txtNss.Visible := False;           
                 x := cboXDosage.Text + TAB;
                 with cboXDosage   do if ItemIndex > -1 then x := x + Items[ItemIndex];
@@ -1818,8 +1925,10 @@
                 with cboXSchedule do if ItemIndex > -1 then x := x + Items[ItemIndex];
                 grdDoses.Cells[COL_SCHEDULE, 1] := x;
+                UpdateStartExpires(ValFor(VAL_SCHEDULE,1));
                 ControlChange(Self);
              end; {TI_COMPLEX}
   end; {case}
 end;
+
 
 procedure TfrmODMeds.lblGuidelineClick(Sender: TObject);
@@ -1901,11 +2010,6 @@
 
 procedure TfrmODMeds.cboDosageChange(Sender: TObject);
-var
-  tmpIdx: integer;
-  tmpTxt,tmpTxt1: string;
-begin
-  inherited;
-  //if length(cboDosage.Text) < 1 then
-  //  cboDosage.ItemIndex := -1;
+begin
+  inherited;
   UpdateRelated;
 end;
@@ -1946,6 +2050,4 @@
 begin
   inherited;
-//if cboRoute.Text = '' then
-//  cboRoute.ItemIndex := -1;
   with cboRoute do
     if ItemIndex > -1 then
@@ -1994,5 +2096,5 @@
 begin
   inherited;
-  if (FInptDlg) and (cboSchedule.Text = 'OTHER') then
+  if  (FInptDlg) and (cboSchedule.Text = 'OTHER') then
   begin
     othSch := CreateOtherScheduel;
@@ -2004,6 +2106,4 @@
     end;
   end;
-//if cboSchedule.Text = '' then
-//  cboSchedule.ItemIndex := -1;
 //Remove Deletion of Text, since we are changing the validation to be on exit of the control.
 {  if (Length(cboSchedule.Text)>0) and (cboSchedule.ItemIndex < 0) and FInptDlg then
@@ -2116,5 +2216,19 @@
       if Length(Route) = 0 then Route := ValueOf(FLD_ROUTE_NM);
       Schedule := ValueOf(FLD_SCHED_EX);
-      if Length(Schedule) = 0 then Schedule := ValueOf(FLD_SCHEDULE);
+      (* Schedule := Piece(Temp,U,1);
+      if Piece(Temp,U,3) = '1' then Schedule := Schedule + ' AS NEEDED';
+      if UpperCase(Copy(Schedule, Length(Schedule) - 18, Length(Schedule))) = 'AS NEEDED AS NEEDED'
+      then Schedule := Copy(Schedule, 1, Length(Schedule) - 10); *)
+      if Length(Schedule) = 0 then
+        begin
+          Schedule := ValueOf(FLD_SCHEDULE);
+          if RightStr(Schedule,3) = 'PRN' then
+             begin
+               Schedule := Copy(Schedule,1,Length(Schedule)-3); //Remove the Trailing PRN
+               if (RightStr(Schedule,1) = ' ') or (RightStr(Schedule,1) = '-') then
+               Schedule := Copy(Schedule,1,Length(Schedule)-1);
+               Schedule := Schedule + ' AS NEEDED'
+             end;
+        end;
       Result := FSIGVerb + ' ' + Dose + ' ' + Route + ' ' + Schedule;
     end;
@@ -2140,5 +2254,16 @@
         if Length(Route) = 0 then Route := ValueOf(FLD_ROUTE_NM, i);
         Schedule := ValueOf(FLD_SCHED_EX, i);
-        if Length(Schedule) = 0 then Schedule := ValueOf(FLD_SCHEDULE, i);
+        //if Length(Schedule) = 0 then Schedule := ValueOf(FLD_SCHEDULE, i);
+        if Length(Schedule) = 0 then
+        begin
+          Schedule := ValueOf(FLD_SCHEDULE);
+          if RightStr(Schedule,3) = 'PRN' then
+             begin
+               Schedule := Copy(Schedule,1,Length(Schedule)-3); //Remove the Trailing PRN
+               if (RightStr(Schedule,1) = ' ') or (RightStr(Schedule,1) = '-') then
+               Schedule := Copy(Schedule,1,Length(Schedule)-1);
+               Schedule := Schedule + ' AS NEEDED'
+             end;
+        end;
         Duration := ValueOf(FLD_DURATION, i);
         if Length(Duration) > 0 then Duration := 'FOR ' + Duration;
@@ -2241,5 +2366,8 @@
 begin
   Result := Piece(Piece(grdDoses.Cells[COL_DOSAGE, ARow], TAB, 2), U, 4);
-  if (not FInptDlg) and (Length(FDrugID) > 0) then
+  //AGP CHANGE 26.33 change for Remedy ticket 87476 fix for quick orders for complex
+  //inpatient orders not displaying the correct unit dose in Pharmacy
+  //if (not FInptDlg) and (Length(FDrugID) > 0) then
+  if Length(FDrugID) > 0 then
   begin
     Result := '';
@@ -2454,5 +2582,5 @@
   TI_COMPLEX:
     begin
-      if txtNss.Visible then txtNss.Visible := False;
+      //if txtNss.Visible then txtNss.Visible := False;
       with grdDoses do for i := 1 to Pred(RowCount) do
       begin
@@ -2491,4 +2619,11 @@
                                    else Responses.Update('ROUTE',    i, '', x);
         x := ValueOf(FLD_SCHEDULE, i);  Responses.Update('SCHEDULE', i, x, x);
+        if FSmplPRNChkd then   // GE CQ7585  Carry PRN checked from simple to complex tab
+        begin
+           pnlXSchedule.Tag := 1;
+           chkXPRN.Checked := True;
+          //cboXScheduleClick(Self);// force onclick to fire when complex tab is entered
+           FSmplPRNChkd := False;
+        end;
         x := ValueOf(FLD_DURATION, i);  Responses.Update('DAYS',     i, UpperCase(x), x);
         x := ValueOf(FLD_SEQUENCE, i);
@@ -2508,5 +2643,6 @@
   begin
     Responses.Update('NOW',     1, ValueOf(FLD_NOW_ID), ValueOf(FLD_NOW_NM));
-    x := InpatientSig;                  Responses.Update('SIG',     1, TX_WPTYPE, x);
+    x := InpatientSig;
+    Responses.Update('SIG',     1, TX_WPTYPE, x);
   end else                                        // outpatient orders
   begin
@@ -2548,4 +2684,5 @@
     VAL_DURATION : Result := Piece(Cells[COL_DURATION, ARow], TAB, 1);
     VAL_SEQUENCE : Result := Piece(Cells[COL_SEQUENCE, ARow], TAB, 1);
+    VAL_CHKXPRN  : Result := Cells[COL_CHKXPRN, ARow];
     end;
 end;
@@ -2729,5 +2866,5 @@
 procedure TfrmODMeds.ShowEditor(ACol, ARow: Integer; AChar: Char);
 var
-  x, NonPRNPart: string;
+  x,tmpText: string;
 
   procedure PlaceControl(AControl: TWinControl);
@@ -2759,4 +2896,5 @@
 begin
   inherited;
+  txtNSS.Visible := False;
   //Make space just select editor.  This blows up as soon as some joker makes a
   //dosage starting with a space.
@@ -2784,10 +2922,11 @@
                       //grdDoses.Cells[COL_SCHEDULE, ARow] := grdDoses.Cells[COL_SCHEDULE, Pred(ARow)];
                     end;
-                    if grdDoses.Cells[COL_SEQUENCE, Pred(ARow)] = '' then
+                //AGP Change 26.45 remove auto-populate of the sequence field
+                {*    if grdDoses.Cells[COL_SEQUENCE, Pred(ARow)] = '' then
                     begin
                       if StrToIntDef(Piece(grdDoses.Cells[COL_DURATION, Pred(ARow)], ' ', 1), 0) > 0
                         then grdDoses.Cells[COL_SEQUENCE, Pred(ARow)] := 'THEN'
                         else grdDoses.Cells[COL_SEQUENCE, Pred(ARow)] := 'AND';
-                    end;
+                    end;  *}
                   end;
                   // set appropriate value for cboDosage
@@ -2806,7 +2945,18 @@
   COL_SCHEDULE: begin
                   // set appropriate value for cboSchedule
+                  if FInptDlg then txtNSS.Visible := True;
                   x := Piece(grdDoses.Cells[COL_SCHEDULE, ARow], TAB, 1);
                   Changing := TRUE;
-                  chkXPRN.Checked := False;
+                  if ValFor(VAL_CHKXPRN,Arow)='1' then chkXPRN.Checked := true
+                  else chkXPRN.Checked := False;
+                  if Pos('PRN',x)>0 then
+                    begin
+                      cboXSchedule.SelectByID(x);
+                      if cboXSchedule.ItemIndex <0 then
+                        begin
+                          x := Trim(Copy(x, 1, Pos('PRN', x) - 1));
+                          chkXPRN.Checked := true;
+                        end;
+                    end;
                   if Length(x) > 0 then
                   begin
@@ -2815,5 +2965,5 @@
                   end
                   else cboXSchedule.ItemIndex := -1;
-                  if Pos('PRN', x) > 0 then
+                (*  if Pos('PRN', x) > 0 then
                   begin
                     NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
@@ -2825,5 +2975,5 @@
                       if cboXSchedule.ItemIndex < 0 then cboXSchedule.Text := x;
                     end;
-                  end;
+                  end; *)
                   Changing := FALSE;
                   pnlXSequence.Tag := ARow;
@@ -2844,20 +2994,23 @@
                     btnXDuration.Caption := 'days';
                   end;
+                  tmpText := txtXDuration.Text;  //Fix for CQ: 8107 - Kloogy but works.
                   UpdateDurationControls(False);
-
                   Changing := FALSE;
                   pnlXDuration.Tag := ARow;
                   PlaceControl(pnlXDuration);
                   txtXDuration.SetFocus;
+                  ARow1 := ARow;
+                  txtXDuration.Text := tmpText;  //Fix for CQ: 8107 - Kloogy but works.
                   if AChar <> #0 then PostMessage(Handle, UM_DELAYEVENT, Ord(AChar), COL_DURATION);
                 end;
   COL_SEQUENCE: begin
                   x := ValFor(COL_SEQUENCE, ARow);
-                  if x = '' then x := 'then';
+                  //if x = '' then x := 'and';  AGP Change 26.46 remove for CQ 9535
                   btnXSequence.Caption := x;
                   pnlXSequence.Caption := btnXSequence.Caption;
                   pnlXSequence.Tag := ARow;
+                  ARow1 := ARow;
                   PlaceControl(pnlXSequence);
-                  btnXSequence.Width := pnlXSequence.Width;                  
+                  btnXSequence.Width := pnlXSequence.Width;
                 end;
   end; {case ACol}
@@ -2929,5 +3082,4 @@
     then lblQtyMsg.Caption := TX_QTY_PRE + x + TX_QTY_POST
     else lblQtyMsg.Caption := '';
-
 end;
 
@@ -2985,5 +3137,5 @@
     cboXRoute.ItemIndex := -1;
     Exit;
-  end;
+  end;  
   cboXRouteClick(Self);
   cboXRoute.Tag := -1;
@@ -3013,5 +3165,5 @@
 procedure TfrmODMeds.cboXScheduleChange(Sender: TObject);
 var
-  othSch, x, PRN: string;
+  othSch, x: string;
   idx : integer;
 begin
@@ -3031,9 +3183,13 @@
       end;
     end;
-    if chkXPRN.Checked then PRN := ' PRN' else PRN := '';
+  (* if chkXPRN.Checked then PRN := ' PRN' else PRN := '';
     with cboXSchedule do if ItemIndex > -1
       then x := Text + PRN + TAB + Items[ItemIndex]
-      else x := Text + PRN;
+      else x := Text + PRN; *)
+    with cboXSchedule do if ItemIndex > -1
+      then x := Text + TAB + Items[ItemIndex]
+      else x := Text;
     grdDoses.Cells[COL_SCHEDULE, pnlXSchedule.Tag] := x;
+    self.cboSchedule.Text := x;
     UpdateRelated;
   end;
@@ -3042,21 +3198,30 @@
 procedure TfrmODMeds.cboXScheduleClick(Sender: TObject);
 var
-  x, PRN: string;
-begin
-  inherited;
-  if chkXPRN.Checked then PRN := ' PRN' else PRN := '';
+  x: string;
+begin
+  inherited;
+  //if chkXPRN.Checked then PRN := ' PRN' else PRN := '';
+ (* with cboXSchedule do if ItemIndex > -1
+    then x := Text + PRN + TAB + Items[ItemIndex]
+    else x := Text + PRN;  *)
   with cboXSchedule do if ItemIndex > -1
-    then x := Text + PRN + TAB + Items[ItemIndex]
-    else x := Text + PRN;
-  if (Pos('PRN',X)>0) and (pnlXSchedule.Tag = 1) then
+    then x := Text + TAB + Items[ItemIndex]
+    else x := Text;
+   (* if (Pos('PRN',X)>0) and (pnlXSchedule.Tag = 1) then
     if lblAdmintime.visible then
-      lblAdmintime.Caption := '';
+      lblAdmintime.Caption := ''; *)
   grdDoses.Cells[COL_SCHEDULE, pnlXSchedule.Tag] := x;
+  UpdateStartExpires(x);
   UpdateRelated;
 end;
 
 procedure TfrmODMeds.chkXPRNClick(Sender: TObject);
-begin
-  inherited;
+var
+check: string;
+begin
+  inherited;
+  if self.chkXPRN.Checked = True then check := '1'
+  else check := '0';
+  self.grdDoses.Cells[COL_CHKXPRN, self.grdDoses.Row] := check;
   if not Changing then cboXScheduleClick(Self);
 end;
@@ -3096,4 +3261,5 @@
 var
   I, Code: Integer;
+  OrgValue: string;
 begin
   inherited;
@@ -3103,8 +3269,13 @@
     Val(txtXDuration.Text, I, Code);
     UpdateDurationControls(Code <> 0);
-    if (Code <> 0) and (I=0) then
-    begin
-      ShowMessage('Free text input is not allowed!');
-      txtXDuration.Text := '0';
+    //Commented out the "and" to resolve CQ: 7557
+    if (Code <> 0) {and (I=0)} then
+    begin
+      ShowMessage('Please use numeric characters only.');
+      with txtXDuration do
+      begin
+        Text := IntToStr(I);
+        SelStart := Length(Text);
+      end;
       Exit;
       btnXDuration.Width := 8;
@@ -3114,12 +3285,35 @@
       PopDuration.Items.Tag := 0;
       btnXDuration.Caption := '';
-    end
+    end;
+   {AGP change 26.19 for PSI-05-018 cq #7322
     else if PopDuration.Items.Tag = 0 then
     begin
       PopDuration.Items.Tag := 3;  //Days selection
       btnXDuration.Caption := 'days';
-    end;
+    end; }
     grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := txtXDuration.Text + ' ' + Uppercase(btnXDuration.Caption);
-  end else grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := '';
+  end else   //AGP CHANGE ORDER
+       begin
+         if not(FInptDlg) then grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := '';
+         OrgValue := ValFor(COL_DURATION, pnlxDuration.tag);
+         //if ((txtXDuration.Text = '0') or (txtXDuration.Text = '')) and ((ValFor(COL_SEQUENCE, ARow1) = 'THEN') and (FInptDlg)) then //AGP CHANGE ORDER
+         //AGP change 26.33 Then/And conjunction requiring a duration to include outpatient orders also
+         if ((txtXDuration.Text = '0') or (txtXDuration.Text = '')) and (ValFor(COL_SEQUENCE, ARow1) = 'THEN') then //AGP CHANGE ORDER
+             begin
+               if (InfoBox('A duration is required when using "Then" as a sequence.'+CRLF+'"Then" will be remove from the sequence field if you continue'+
+                    CRLF+'Click "OK" to continue or click "Cancel"','Duration Warning', MB_OKCANCEL)=1) then
+                    begin
+                        grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := '';
+                        pnlXSequence.Tag := ARow1;
+                        pnlXSequence.Caption := '';
+                        grdDoses.Cells[COL_SEQUENCE, pnlXSequence.Tag] := '';
+                        btnXSequence.Click;
+                    end
+                    else
+                    grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := OrgValue;
+               end
+             else grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := txtXDuration.Text;
+       end;
+   // end;
   ControlChange(Self);
   UpdateRelated;
@@ -3151,7 +3345,21 @@
 begin
   inherited;
+  inherited;
   with TSpeedButton(Sender) do APoint := ClientToScreen(Point(0, Height));
   popXSequence.Popup(APoint.X, APoint.Y);
   pnlXSequence.Caption := btnXSequence.Caption;
+  {
+  with TSpeedButton(Sender) do APoint := ClientToScreen(Point(0, Height));
+  popXSequence.Popup(APoint.X, APoint.Y);
+  pnlXSequence.Caption := btnXSequence.Caption;
+  if (pnlXSequence.Caption = 'then') and
+      ((ValFor(COL_DURATION, ARow1) = '') or
+       (ValFor(COL_DURATION, ARow1) = '0')) then
+     begin
+       InfoBox('A duration is required when using "Then" as a conjunction','Duration Warning',MB_OK);
+       pnlXSequence.Caption := '';
+       btnXSequence.Caption := '';
+     end;
+     }
 end;
 
@@ -3162,4 +3370,13 @@
   inherited;
   with TMenuItem(Sender) do if Tag > 0 then x := Caption else x := '';
+ //AGP Changes 26.12 PSI-04-63
+ //if ((x = 'then') and (FInptDlg)) and ((ValFor(COL_DURATION, ARow1) = '') or (ValFor(COL_DURATION, ARow1) = '0')) then
+ //AGP change 26.32 Then/And conjunction requiring a duration to include outpatient orders
+ if (x = 'then') and ((ValFor(COL_DURATION, ARow1) = '') or (ValFor(COL_DURATION, ARow1) = '0')) then
+     begin
+       InfoBox('A duration is required when using "Then" as a conjunction' + CRLF + CRLF+
+           'The patient will be instructed to take these doses consecutively, not concurrently.','Duration Warning',MB_OK);
+       x := '';
+     end;
   btnXSequence.Caption := x;
   pnlXSequence.Caption := btnXSequence.Caption;
@@ -3279,5 +3496,5 @@
     FLD_ROUTE_EX  : with cboRoute do
                      if ItemIndex > -1  then Result := Piece(Items[ItemIndex], U, 4);
-    FLD_SCHEDULE  : begin
+    FLD_SCHEDULE  : begin        //gary)
                       Result := UpperCase(Trim(cboSchedule.Text));
                       if chkPRN.Checked then Result := Result + ' PRN';
@@ -3287,8 +3504,38 @@
     FLD_SCHED_EX  : begin
                       with cboSchedule do
+                        begin
                         if ItemIndex > -1 then Result := Piece(Items[ItemIndex], U, 2);
+                   (*     if (Length(Result)=0) and (ItemIndex > -1) then
+                            begin
+                              Result := Piece(Items[ItemIndex], U, 1);
+                              if Piece(Items[ItemIndex], U, 3) = 'P' then
+                              begin
+                                if RightStr(Result,3) = 'PRN' then
+                                  begin
+                                    Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
+                                    if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
+                                    Result := Copy(Result,1,Length(Result)-1);
+                                  end;
+                               Result := Result + ' AS NEEDED';
+                              end;
+                            end;
+                        end; *)
+                      if RightStr(Result,3) = 'PRN' then
+                           begin
+                              Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
+                              if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
+                              Result := Copy(Result,1,Length(Result)-1);
+                              Result := Result + ' AS NEEDED'
+                           end;
                       if (Length(Result) > 0) and chkPRN.Checked then Result := Result + ' AS NEEDED';
                       if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
                         then Result := Copy(Result, 1, Length(Result) - 10);
+                      if UpperCase(Copy(Result, Length(Result) - 12, Length(Result))) = 'PRN AS NEEDED' then
+                          begin
+                            Result := Copy(Result, 1, Length(Result) - 13);
+                            if RightStr(Result,1)=' ' then Result := Result + 'AS NEEDED'
+                            else Result := Result + ' AS NEEDED';
+                          end;
+                    end;
                     end;
     FLD_SCHED_TYP : with cboSchedule do
@@ -3330,7 +3577,13 @@
       FLD_ROUTE_AB  : Result := Piece(Piece(Cells[COL_ROUTE, ARow], TAB, 2), U, 3);
       FLD_ROUTE_EX  : Result := Piece(Piece(Cells[COL_ROUTE, ARow], TAB, 2), U, 4);
-      FLD_SCHEDULE  : Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
+      FLD_SCHEDULE  : begin
+                         Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 1);
+                         if Result = '' then Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
+                         if valFor(VAL_CHKXPRN,ARow)='1' then Result := Result + ' PRN';
+                         if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN' then
+                         Result := Copy(Result, 1, Length(Result) - 4);
+                      end;
       FLD_SCHED_EX  : begin
-                        Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 2);
+                        (*Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 2);
                         if Result = '' then //Added for CQ: 7639
                         begin
@@ -3343,4 +3596,24 @@
                            (Pos('PRN', Piece(Cells[COL_SCHEDULE, ARow], TAB, 1)) > 0)
                            then Result := Result + ' AS NEEDED';
+                      end;*)
+                        Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2),U,2);
+                        if Result = '' then Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2),U,1); //Added for CQ: 7639
+                        if Result = '' then Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
+                        if RightStr(Result,3) = 'PRN' then
+                           begin
+                              Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
+                              if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
+                              Result := Copy(Result,1,Length(Result)-1);
+                              Result := Result + ' AS NEEDED';
+                           end;
+                        if valFor(VAL_CHKXPRN,ARow)='1' then Result := Result + ' AS NEEDED';
+                        if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
+                        then Result := Copy(Result, 1, Length(Result) - 10);
+                        if UpperCase(Copy(Result, Length(Result) - 12, Length(Result))) = 'PRN AS NEEDED' then
+                          begin
+                            Result := Copy(Result, 1, Length(Result) - 13);
+                            if RightStr(Result,1)=' ' then Result := Result + 'AS NEEDED'
+                            else Result := Result + ' AS NEEDED';
+                          end;
                       end;
       FLD_SCHED_TYP : Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 3);
@@ -3552,17 +3825,11 @@
 procedure TfrmODMeds.UpdateStartExpires(const CurSchedule: string);
 var
-  ShowText, Duration, ASchedule: string;
+  CompSch, ShowText, Duration, ASchedule: string;
   AdminTime:    TFMDateTime;
-  Interval, PrnPos: Integer;
+  i, j, Interval, PrnPos: Integer;
 begin
   if Length(CurSchedule)=0 then Exit;
   ASchedule := Trim(CurSchedule);
-  if (Pos('^',ASchedule)=0) then
-  begin
-    PrnPos := Pos('PRN',ASchedule);
-    if (PrnPos > 1) and (CharAt(ASchedule,PrnPos-1) <> ';') then
-      Delete(ASchedule, PrnPos, Length(ASchedule));
-  end
-  else if (Pos('^',ASchedule)>0) then
+  if (Pos('^',ASchedule)>0) then
   begin
     PrnPos := Pos('PRN',ASchedule);
@@ -3571,7 +3838,50 @@
   end;
   ASchedule := Trim(ASchedule);
+  if self.tabDose.TabIndex = TI_COMPLEX then
+    begin
+      CompSch := valFor(VAL_SCHEDULE,1);
+      if CompSch = '' then
+        begin
+          ASchedule := '';
+          AdminTime := -1;
+        end;
+      if CompSch <> '' then
+        begin
+          for i := 0 to self.cboXSchedule.Items.Count-1 do
+            begin
+              if (Piece(self.cboXSchedule.Items.Strings[i],U,1) = CompSch) and (Piece(self.cboXSchedule.Items.Strings[i],U,3)='P') then
+                begin
+                  AdminTime := -1;
+                  Aschedule := '';
+                end;
+            end;
+        end;
+        if valFor(VAL_CHKXPRN,1)='1' then
+          begin
+            AdminTime := -1;
+            Aschedule := '';
+          end;
+      if (ASchedule <> '') and (CompSch <> '') then ASchedule := ';' + CompSch;
+    end;
   if Length(ASchedule)>0 then
-      LoadAdminInfo(ASchedule, txtMed.Tag, ShowText, AdminTime, Duration)
-  else Exit;
+      LoadAdminInfo(ASchedule, txtMed.Tag, ShowText, AdminTime, Duration);
+  //else Exit;
+  if (AdminTime > 0) and (self.tabDose.TabIndex = TI_DOSE) then
+    begin
+     if self.cboSchedule.ItemIndex = -1 then
+       begin
+         for j := 0 to self.cboSchedule.items.Count -1 do
+           begin
+             if (Piece(self.cboSchedule.Items.Strings[j],U,1) = Piece(Aschedule,';',2)) and (Piece(self.cboSchedule.Items.Strings[j],U,3)='P') then
+               begin
+                 AdminTime := -1;
+                 break;
+               end;
+           end;
+       end;
+     if (self.cboSchedule.ItemIndex > -1) and (Piece(self.cboSchedule.Items.Strings[self.cboSchedule.ItemIndex],U,3)='P') then
+       AdminTime := -1;
+     if self.chkPRN.Checked = true then AdminTime := -1
+    end;
   if AdminTime > 0 then
   begin
@@ -3630,5 +3940,5 @@
   CurSupply, i, pNum, j: Integer;
   CurQuantity: double;
-  LackQtyInfo, SaveChanging: Boolean;
+  LackQtyInfo, SaveChanging, DispFirstDose: Boolean;
 begin
   inherited;
@@ -3637,4 +3947,5 @@
   SaveChanging := Changing;
   Changing := TRUE;
+  DispFirstDose := FALSE;
   // don't allow Exit procedure so Changing gets reset appropriately
   CurUnits    := '';
@@ -3700,11 +4011,22 @@
       or ((Length(cboSchedule.Text)>0) and (cboSchedule.ItemIndex < 0)) then
     begin
-        if (chkDoseNow.Checked) and (chkDoseNow.Visible) then
+      if (chkDoseNow.Checked) and (chkDoseNow.Visible) then
+      begin
+        chkDoseNowClick(Self);
+        chkDoseNow.Checked := False;
+      end;
+      for i := 0 to cboSchedule.Items.Count-1 do
         begin
-          chkDoseNowClick(Self);
-          chkDoseNow.Checked := False;
+                  if Piece(cboSchedule.Items.Strings[i],U,1) = Uppercase(cboSchedule.Text) then
+            begin
+              DispFirstDose := True;
+              break;
+            end;
         end;
-        chkDoseNow.Visible := False;
-        lblAdminTime.Visible := False;
+      if not DispFirstDose then
+        begin
+          chkDoseNow.Visible := False;
+          lblAdminTime.Visible := False;
+        end;
     end
     else
@@ -3715,8 +4037,8 @@
     if Responses.EventType in ['A','D','T','M','O'] then lblAdminTime.Visible := False;
   end;
-  if not FInptDlg then
+    if not FInptDlg then
   begin
     CurSchedule := CurScheduleOut;
-    if CurInstruct <> FLastInstruct
+    if (CurInstruct <> FLastInstruct) and (CurUnits <> U) //AGP Change 26.48 Do not update quantity and day supply if no matching dose on the server
       then UpdateDefaultSupply(CurUnits, CurSchedule, CurDuration, CurDispDrug, CurSupply, CurQuantity,
                                LackQtyInfo);
@@ -3751,16 +4073,38 @@
 
 procedure TfrmODMeds.cmdAcceptClick(Sender: TObject);
-begin
-  if (cboSchedule.Text = 'OTHER') and (FInptDlg)then
+var
+i: integer;
+begin
+  if (FInptDlg) and (cboSchedule.Text = 'OTHER') then
   begin
     cboScheduleClick(Self);
     Exit;
   end;
+  //AGP Change for 26.45 PSI-04-069
+  if self.tabDose.TabIndex = 1 then
+    begin
+       for i := 2 to self.grdDoses.RowCount do
+         begin
+           if ((ValFor(COL_DOSAGE, i-1) <> '') and (ValFor(COL_DOSAGE, i) <> '')) and (ValFor(COL_SEQUENCE,i-1) = '') then
+             begin
+              infoBox('To be able to complete a complex order every row except for the last row must have a conjunction defined. ' + CRLF
+              + CRLF + 'Verify that all rows have a conjunction defined.','Sequence Error',MB_OK);
+              Exit;
+             end;
+           //text := Self.cboXDosage.Items.Strings[i];
+         end;
+    end;
   if FInptDlg and (not FOutptIV)
     then DisplayGroup := DisplayGroupByName('UD RX')
   else DisplayGroup := DisplayGroupByName('O RX');
+  //timCheckChangesTimer(Self);
   DropLastSequence;
   cmdAccept.SetFocus;
   inherited;
+  (*if self.Responses.Cancel = true then
+    begin
+      self.Destroy;
+      exit;
+    end; *)
 end;
 
@@ -3791,5 +4135,5 @@
     if length(theSch)>0 then
     begin
-      if (ValueOf(FLD_SCHED_TYP) <> 'O') and (InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) then
+      if ( (ValueOf(FLD_SCHED_TYP) <> 'O') and (InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) )then
       begin
         chkDoseNow.Checked := False;
@@ -3808,7 +4152,7 @@
   if (tabDose.TabIndex = TI_COMPLEX) and chkDoseNow.Checked  then
   begin
-    if (ValueOf(FLD_SCHED_TYP) <> 'O') and ( InfoBox('Give Additional Dose Now is in addition to those listed in the table.' + CRLF +
+    if ( (ValueOf(FLD_SCHED_TYP) <> 'O') and (InfoBox('Give Additional Dose Now is in addition to those listed in the table.' + CRLF +
                  'Please adjust the duration of the first row, if necessary.',
-                 'Give Additional Dose Now for Complex Order', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) then
+                 'Give Additional Dose Now for Complex Order', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) ) then
     begin
       chkDoseNow.Checked := False;
@@ -3908,7 +4252,15 @@
 var
   tempSch: string;
-begin
-  inherited;
-  if chkPRN.Checked then lblAdminTime.Caption := ''
+  PRNPos: integer;
+begin
+  inherited;
+  //GE  CQ 7552
+  if chkPRN.Checked then
+  begin
+     lblAdminTime.Caption := '';
+     PrnPos := Pos('PRN',cboSchedule.Text);
+     if (PrnPos < 1) then
+        UpdateStartExpires(cboSchedule.Text + ' PRN');
+  end
   else
   begin
@@ -3918,5 +4270,5 @@
       UpdateStartExpires(tempSch);
     end;
-    lblAdminTime.Caption := FAdminTimeLbl;
+    //lblAdminTime.Caption := FAdminTimeLbl;
     if txtQuantity.visible then
       cboScheduleClick(Self);
@@ -4031,7 +4383,5 @@
   end
   else if (Key = #13) and (ActiveControl = txtMed) then
-    Key := #0   //Don't let the base class turn it into a forward tab!
-  else
-    inherited;
+    Key := #0;   //Don't let the base class turn it into a forward tab!
 end;
 
@@ -4284,5 +4634,5 @@
   inherited;
   if MessageDlg('You can also select ' + '"' + 'Other' + '"' + ' from the schedule list'
-    + ' to create a day-of-week or admin-time only schedule.'
+    + ' to create a day-of-week schedule.'
     + #13#10 + 'Click OK to launch schedule builder',
     mtInformation, [mbOK, mbCancel],0) = mrOK then
@@ -4292,4 +4642,9 @@
       cboSchedule.SelectByID('OTHER');
       cboScheduleClick(Self);
+    end;
+    if  (tabDose.TabIndex = TI_COMPLEX) then
+    begin
+      cboXSchedule.SelectByID('OTHER');
+      CBOXScheduleChange(Self);
     end;
   end;
@@ -4325,13 +4680,26 @@
 
 procedure TfrmODMeds.ValidateInpatientSchedule(ScheduleCombo: TORComboBox);
-begin
-  //CQ 7575  Schedule coming across lower-case, change all schedules to Upper-Case.
+var
+  tmpIndex : Integer;
+begin
+
+{CQ: 6690 - Orders - autopopulation of schedule field - overtyping only 1 character
+ CQ: 7280 - PTM 32-34, 42 Meds: NJH-0205-20901 MED DIALOG DROPPING FIRST LETTER (schedule)}
+
+ //CQ 7575  Schedule coming across lower-case, change all schedules to Upper-Case.
   if (Length(ScheduleCombo.Text) > 0) then
-     ScheduleCombo.Text := UpperCase(ScheduleCombo.Text);
+    ScheduleCombo.Text := TrimLeft(UpperCase(ScheduleCombo.Text));
+    {if user entered schedule verify it is in list}
+  if ScheduleCombo.ItemIndex < 0 then // CQ: 7397
+  begin //Fix for CQ: 9299 - Outpatient Med orders will not accept free text schedule
+    tmpIndex := GetSchedListIndex(ScheduleCombo,ScheduleCombo.Text);
+    if tmpIndex > -1 then
+      ScheduleCombo.ItemIndex := tmpIndex;
+  end;
   if (Length(ScheduleCombo.Text) > 0) and (ScheduleCombo.ItemIndex < 0) and FInptDlg then
   begin
     FShowPnlXScheduleOk := False; //Added for CQ: 7370
     Application.MessageBox('Please select a valid schedule from the list.'+#13+#13+
-                           'If you would like to create a non-standard schedule please'+
+                           'If you would like to create a Day-of-Week schedule please'+
                            ' select ''OTHER'' from the list.',
                            'Incorrect Schedule.');
@@ -4344,6 +4712,7 @@
 
 //Removed based on Site feeback. See CQ: 7518
-{function TfrmODMeds.ValidateRoute(RouteCombo: TORComboBox) : Boolean;
-begin
+(*function TfrmODMeds.ValidateRoute(RouteCombo: TORComboBox) : Boolean;
+begin
+{CQ: 7331 - Medications - Route - Can not enter any route not listed in Route field in window}
   Result := True;
   if (Length(RouteCombo.Text) > 0) and (RouteCombo.ItemIndex < 0) and (Not IsSupplyAndOutPatient) then
@@ -4356,5 +4725,5 @@
     Result := False;
   end;
-end;}
+end;*)
 
 function TfrmODMeds.isUniqueQuickOrder(iText: string): Boolean;
@@ -4373,4 +4742,5 @@
 function TfrmODMeds.IsSupplyAndOutPatient: boolean;
 begin
+{CQ: 7331 - Medications - Route - Can not enter any route not listed in Route field in window}
   Result := False;
   if (MedIsSupply(txtMed.Tag)) and (not FInptDlg) then
@@ -4378,10 +4748,89 @@
 end;
 
+// CQ: 7397 - Inpatient med orders with PRN cancel due to invalid schedule.
+function TfrmODMeds.GetSchedListIndex(SchedCombo: TORComboBox; pSchedule: String):integer;
+var i: integer;
+begin
+    result := -1;
+    for i := 0 to SchedCombo.items.Count-1 do
+    begin
+         if pSchedule = SchedCombo.DisplayText[i] then
+         begin
+           result := i;   // match found
+           break;
+         end;
+    end;
+end;
+
 
 procedure TfrmODMeds.cboXScheduleExit(Sender: TObject);
 begin
   inherited;
+{CQ: 7344 - Inconsistency with Schedule box: Allows free-text entry for Complex orders,
+            doesn't for simple orders }
   ValidateInpatientSchedule(cboXSchedule);
 end;
 
+procedure TfrmODMeds.cboDosageKeyUp(Sender: TObject; var Key: Word;
+  Shift: TShiftState);
+begin
+  inherited;
+  //Fix for CQ: 7545
+  if cboDosage.ItemIndex > -1 then
+    cboDosageClick(Sender);
+end;
+
+procedure TfrmODMeds.cboXDosageKeyUp(Sender: TObject; var Key: Word;
+  Shift: TShiftState);
+begin
+  inherited;
+  //Fix for CQ: 7545
+  if cboXDosage.ItemIndex > -1 then
+    cboXDosageClick(Sender);
+end;
+
+procedure TfrmODMeds.txtSupplyClick(Sender: TObject);
+begin
+  inherited;
+  Self.txtSupply.SelectAll;
+end;
+
+procedure TfrmODMeds.txtQuantityClick(Sender: TObject);
+begin
+  inherited;
+   self.txtQuantity.SelectAll;
+end;
+
+procedure TfrmODMeds.txtRefillsClick(Sender: TObject);
+begin
+  inherited;
+  self.txtRefills.SelectAll;
+end;
+
+procedure TfrmODMeds.WMClose(var Msg: TWMClose);
+begin
+   if self <> nil then
+     begin
+       if (self.tabDose.TabIndex = TI_Dose) then
+         begin
+            if Trim(cboSchedule.Text) = '' then cboSchedule.ItemIndex := -1;
+            ValidateInpatientSchedule(cboSchedule);
+            if self.cboSchedule.Focused = true then exit;
+         end;
+       if (self.tabDose.TabIndex = TI_Complex) then
+         begin
+           ValidateInpatientSchedule(cboXSchedule);
+           if self.cboXSchedule.Focused = true then exit;
+         end;
+     end;
+    inherited
+end;
+
+procedure TfrmODMeds.cboXScheduleEnter(Sender: TObject);
+begin
+  inherited;
+  //agp Change CQ 10719 
+   self.chkXPRN.OnClick(self.chkXPRN);
+end;
+
 end.
