Index: cprs/branches/foia-cprs/CPRS-Chart/Orders/fODMedNVA.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/Orders/fODMedNVA.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/Orders/fODMedNVA.pas	(revision 460)
@@ -1,5 +1,5 @@
 unit fODMedNVA;
 
-interface                         
+interface
 
 uses
@@ -41,4 +41,6 @@
     Label2: TLabel;
     btnSelect: TButton;
+    Image1: TImage;
+    memDrugMsg: TMemo;
     procedure FormCreate(Sender: TObject);
     procedure btnSelectClick(Sender: TObject);
@@ -68,5 +70,5 @@
     procedure cboScheduleClick(Sender: TObject);
     procedure cboRouteExit(Sender: TObject);
-
+    procedure DispOrderMessage(const AMessage: string);
 
 
@@ -89,4 +91,5 @@
       Change: TItemChange);
     procedure FormKeyPress(Sender: TObject; var Key: Char);
+
   private
     {selection}
@@ -121,4 +124,5 @@
     FPtInstruct: string;
     FAltChecked: Boolean;
+    FShrinkDrugMsg: boolean;
     FQOQuantity: Double;
     FQODosage: string;
@@ -129,4 +133,5 @@
     FDisabledCancelButton: TButton;
     FShrinked: boolean;
+    FQOInitial: boolean;
     FRemoveText : Boolean;
     {selection}
@@ -291,5 +296,5 @@
   TX_NO_FUTURE_DATES  = 'Dates in the future are not allowed.';
   TX_BAD_DATE         = 'Dates must be in the format mm/dd/yy or mm/yy';
-
+  TX_CAP_FUTURE       = 'Invalid date';
 
 { procedures inherited from fODBase --------------------------------------------------------- }
@@ -300,19 +305,26 @@
 var
   ListCount: Integer;
-  Restriction, x : string;
-begin
+  Restriction, x: string;
+begin
+  frmFrame.pnlVisit.Enabled := false;
   AutoSizeDisabled := True;
  // ActivateOrderDialog(Piece(DialogInfo, ';', 1), DelayEvent, Self, 0);
   inherited;
+  AllowQuickOrder := True;
+
   if User.OrderRole in[OR_CLERK] then   // if user is clerk check restrictions else ok to write NonVA Order.
-  begin
-     CheckAuthForNVAMeds(Restriction);
-     if Length(Restriction) > 0 then
-     begin
-       InfoBox(Restriction, TC_RESTRICT, MB_OK);
-       Close;
-       Exit;
-     end;
-  end;
+    begin
+      CheckAuthForNVAMeds(Restriction);
+      if Length(Restriction) > 0 then
+        begin
+          CheckAuthForNVAMeds(Restriction);
+          if Length(Restriction) > 0 then
+            begin
+              InfoBox(Restriction, TC_RESTRICT, MB_OK);
+              Close;
+              Exit;
+            end;
+        end;
+    end;  // clerk restrictions
 
   if DlgFormID = OD_MEDNONVA  then FNonVADlg := TRUE;
@@ -363,4 +375,5 @@
   LoadOTCStatements(lbStatements.Items);
   FRemoveText := True;
+  FShrinkDrugMsg := False;
 end;
 
@@ -376,4 +389,5 @@
  // TAccessibleStringGrid.UnwrapControl(grdDoses);
   inherited;
+  frmFrame.pnlVisit.Enabled := true;
 end;
 
@@ -401,4 +415,5 @@
 procedure TfrmODMedNVA.SetupDialog(OrderAction: Integer; const ID: string);
 var
+  //AnInstr: string;
   OrderID: string;
 begin
@@ -429,5 +444,18 @@
     Changing := False;
   end;
-
+  { prevent the SIG from being part of the comments on pre-CPRS prescriptions }
+  {if (OrderAction in [ORDER_COPY, ORDER_EDIT]) and (cboDosage.Text = '') then  //commented out by cla 2/27/04 - CQ 2591
+  begin
+    OrderID := Copy(Piece(ID, ';', 1), 2, Length(ID));
+    AnInstr := TextForOrder(OrderID);
+    pnlMessage.TabOrder := 0;
+    OrderMessage(AnInstr);
+    if OrderAction = ORDER_COPY
+      then AnInstr := 'Copy: ' + AnInstr
+      else AnInstr := 'Change: ' + AnInstr;
+    Caption := AnInstr;
+    memComment.Clear;  // sometimes the sig is in the comment
+    lbStatements.Clear;
+  end;}
   ControlChange(Self);
 end;
@@ -527,5 +555,4 @@
 end;
 
-
 { Navigate medication selection lists ------------------------------------------------------- }
 
@@ -607,6 +634,9 @@
 var
   Offset: Integer;
+  SelRect: TRect;
 begin
   AListView.Selected.MakeVisible(FALSE);
+  SelRect := AListView.Selected.DisplayRect(drBounds);   //  CQ: 6636
+  FRowHeight := SelRect.Bottom - SelRect.Top;
   Offset := AListView.Selected.Index - AListView.TopItem.Index;
   Application.ProcessMessages;
@@ -803,5 +833,31 @@
     Changing := True;
     ResetOnMedChange;
-  if (FActiveMedList = lstAll) and (lstAll.Selected <> nil) then  // orderable item
+    if (FActiveMedList = lstQuick) and (lstQuick.Selected <> nil) then   // quick order
+    begin
+      ErrMsg := '';
+      FIsQuickOrder := True;
+      FQOInitial := True;
+      Responses.QuickOrder := Integer(lstQuick.Selected.Data);
+      txtMed.Tag  := StrToIntDef(Responses.IValueFor('ORDERABLE', 1), 0);
+      IsActivateOI(ErrMsg, txtMed.Tag);
+      if Length(ErrMsg)>0 then
+      begin
+        //btnSelect.Visible := False;
+        btnSelect.Enabled := False;
+        ShowMessage(ErrMsg);
+        Exit;
+      end;
+      if txtMed.Tag = 0 then
+      begin
+        //btnSelect.Visible := False;
+        btnSelect.Enabled := False;
+        txtMed.SetFocus;
+        Exit;
+      end;
+      SetOnMedSelect;   // set up for this medication
+      SetOnQuickOrder;  // insert quick order responses
+      ShowMedFields;
+    end
+    else if (FActiveMedList = lstAll) and (lstAll.Selected <> nil) then  // orderable item
     begin
       MedIEN := Integer(lstAll.Selected.Data);
@@ -831,5 +887,5 @@
       ShowMedFields;
     end
-    else                                                                 // no selection
+    else                                           // no selection
     begin
       MessageBeep(0);
@@ -842,5 +898,4 @@
   else ShowMedSelect;                             // show the selection fields
   FNoZERO   := False;
-
 end;
 
@@ -848,4 +903,8 @@
 begin
   cboDosage.Items.Clear;
+  chkPRN.Checked := False;
+  cboSchedule.ItemIndex := -1;
+  cboSchedule.Text := '';  // leave items intact
+  memComment.Lines.Clear;
   cboDosage.Text := '';
   cboRoute.Items.Clear;
@@ -867,23 +926,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
@@ -950,5 +991,6 @@
  //   end;
     pnlMessage.TabOrder := cboDosage.TabOrder + 1;
-    OrderMessage(TextOf('Message'));
+
+ //   DispOrderMessage(TextOf('Message'));
   end;
 end;
@@ -971,4 +1013,5 @@
         with cboDosage do
           if ItemIndex > -1 then x := Text + TAB + Items[ItemIndex] else x := Text;
+
         SetControl(cboRoute,  'ROUTE', i);
         with cboRoute do
@@ -1001,5 +1044,5 @@
       else
         SetDosage(IValueFor('INSTR', 1));
-        SetControl(cboRoute,  'ROUTE',     1);
+        SetControl(cboDosage, 'DOSAGE', 1); // CQ: HDS00007776
         SetSchedule(IValueFor('SCHEDULE',  1));
       if (cboSchedule.Text = '') and FIsQuickOrder then
@@ -1174,4 +1217,5 @@
   NonPRNPart: string;
 begin
+ 
   cboSchedule.ItemIndex := -1;
   if Pos('PRN', x) > 0 then
@@ -1179,14 +1223,35 @@
     NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
     cboSchedule.SelectByID(NonPRNPart);
-    if cboSchedule.ItemIndex > -1 then chkPRN.Checked := True else
-    begin
-      cboSchedule.SelectByID(x);
-      if cboSchedule.ItemIndex < 0 then cboSchedule.Text := x;
-    end;
+    if cboSchedule.ItemIndex < 0 then
+    begin
+      if NSSchedule then
+      begin
+        chkPRN.Checked := False;
+        cboSchedule.Text := '';
+      end else
+      begin
+        chkPRN.Checked := True;
+        cboSchedule.Items.Add(NonPRNPart);
+        cboSchedule.Text := NonPRNPart;
+      end;
+    end else
+      chkPRN.Checked := True;
   end else
   begin
     chkPRN.Checked := False;
     cboSchedule.SelectByID(x);
-    if cboSchedule.ItemIndex < 0 then cboSchedule.Text := x;
+    if cboSchedule.ItemIndex < 0 then
+    begin
+      if NSSchedule then
+      begin
+        cboSchedule.Text := '';
+      end
+      else
+      begin
+        cboSchedule.Items.Add(x);
+        cboSchedule.Text := x;
+        cboSchedule.SelectByID(x);
+      end;
+    end;
   end;
 end;
@@ -1246,8 +1311,7 @@
 var
   DispDrug: Integer;
-  x: string;
-begin
-  inherited;
-  UpdateRelated(False);
+begin
+  inherited;
+UpdateRelated(False);
   DispDrug := StrToIntDef(ValueOf(FLD_DRUG_ID), 0);
   if cboDosage.Text = '' then    //cla 3/18/04
@@ -1256,13 +1320,15 @@
     cboDosage.ItemIndex := -1;
   end;
+  {  hds8084
   if DispDrug > 0 then
   begin
     if not FSuppressMsg then begin
       pnlMessage.TabOrder := cboDosage.TabOrder + 1;
-      OrderMessage(DispenseMessage(DispDrug));
+      DispOrderMessage(DispenseMessage(DispDrug));
     end;
     x := QuantityMessage(DispDrug);
   end
   else x := '';
+  }
   with cboDosage do
     if (ItemIndex > -1) and (Piece(Items[ItemIndex], U, 3) = 'NF')
@@ -1589,5 +1655,5 @@
                                 then Responses.Update('ROUTE',    1, ValueOf(FLD_ROUTE_ID), x)
                                 else Responses.Update('ROUTE',    1, '', x);
- //     x := ValueOf(FLD_SCHEDULE);    Responses.Update('SCHEDULE', 1, x,  x);
+      x := ValueOf(FLD_SCHEDULE);    Responses.Update('SCHEDULE', 1, x,  x); // CQ:7297, 7534
     end;
   end; {case TabDose.TabIndex}
@@ -1598,5 +1664,5 @@
   if Length(calStart.Text) > 0 then
      Responses.Update('START', 1, calStart.Text, 'Start Date: ' + calStart.Text);  //cla 7-17-03
-
+     
   x := ValueOf(FLD_STATEMENTS);
   Responses.Update('STATEMENTS',1, TX_WPTYPE, x);
@@ -1697,5 +1763,5 @@
                      if ItemIndex > -1  then Result := Piece(Items[ItemIndex], U, 4);
     FLD_SCHEDULE  : begin
-                      Result := cboSchedule.Text;
+                      Result := UpperCase(cboSchedule.Text);
                       if chkPRN.Checked then Result := Result + ' PRN';
                       if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN'
@@ -1768,11 +1834,11 @@
   if Length(CurSchedule)=0 then Exit;
   ASchedule := Trim(CurSchedule);
-  if (Pos('^',ASchedule)=0) then
+  {if (Pos('^',ASchedule)=0) then  //GE  CQ7506
   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
+  end  }
+  if (Pos('^',ASchedule)>0) then
   begin
     PrnPos := Pos('PRN',ASchedule);
@@ -1929,4 +1995,5 @@
     begin
       Val(TabletNum, ie, code);
+      if ie = 0 then begin end;
       if code <> 0 then
         Exit;
@@ -1967,10 +2034,32 @@
 
 procedure TfrmODMedNVA.chkPRNClick(Sender: TObject);
-begin
-  inherited;
-  if chkPRN.Checked then lblAdminTime.Caption := ''
+var
+  tempSch: string;
+  PRNPos: integer;
+begin
+  inherited;
+  {if chkPRN.Checked then lblAdminTime.Caption := ''
   else
   begin
     lblAdminTime.Caption := FAdminTimeLbl;
+  end;
+  ControlChange(Self);
+  }
+  if chkPRN.Checked then
+  begin
+     lblAdminTime.Caption := '';
+     PrnPos := Pos('PRN',cboSchedule.Text);
+     if (PrnPos < 1) then
+        UpdateStartExpires(cboSchedule.Text + ' PRN');
+  end
+  else
+  begin
+    if Length(Trim(cboSchedule.Text))>0 then
+    begin
+      tempSch := ';'+Trim(cboSchedule.Text);
+      UpdateStartExpires(tempSch);
+    end;
+    lblAdminTime.Caption := FAdminTimeLbl;
+    
   end;
   ControlChange(Self);
@@ -2194,3 +2283,29 @@
 end;
 
+procedure TfrmODMedNVA.DispOrderMessage(const AMessage: string);
+begin
+  if ContainsVisibleChar(AMessage) then
+  begin
+    image1.Visible := True;
+    memDrugMsg.Visible := True;
+    image1.Picture.Icon.Handle := LoadIcon(0, IDI_ASTERISK);
+    memDrugMsg.Lines.Clear;
+    memDrugMsg.Lines.SetText(PChar(AMessage));
+    if fShrinkDrugMsg then
+    begin
+      pnlBottom.Height := pnlBottom.Height + memDrugMsg.Height + 2;
+      fShrinkDrugMsg := False;
+    end;
+  end else
+  begin
+    image1.Visible := False;
+    memDrugMsg.Visible := False;
+    if not fShrinkDrugMsg then
+  //  begin
+  //    pnlBottom.Height := pnlBottom.Height - memDrugMsg.Height - 2;
+      fShrinkDrugMsg := True;
+ //   end;
+  end;
+end;
+
 end.
