Index: cprs/branches/foia-cprs/CPRS-Chart/fReview.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/fReview.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/fReview.pas	(revision 460)
@@ -97,4 +97,5 @@
     procedure SetItemTextToState;
     procedure FormatListForScreenReader;
+
   public
     procedure SetCheckBoxStatus(thisOrderID: string);
@@ -136,5 +137,5 @@
 uses ORFn, rCore, fNotes, fConsults, fOrders, rOrders, Hash, fDCSumm, fOCSession, uOrders,
      fSignItem, fOrdersPrint, fLkUpLocation, fFrame, uSignItems, fSurgery,
-     fBALocalDiagnoses, UBAConst, UBAMessages, fOrdersSign;
+     fBALocalDiagnoses, UBAConst, UBAMessages, fOrdersSign, fClinicWardMeds;
 
 const
@@ -293,7 +294,8 @@
 
     end;
-    // if Result then Changes.Clear;  possibly clear changes here ??
+
   finally
    Changes.OnRemove := nil;     {**RV**}
+   frmReview.Release;
   end;
 end;
@@ -340,5 +342,5 @@
   if  BILLING_AWARE then
   begin
-    UBAGlobals.ChangeItemOrderNum := Copy(ChangeItem.ID, 0, 8);
+    UBAGlobals.ChangeItemOrderNum := ChangeItem.ID; // GE 2/21/2006 removed "Copy(ChangeItem.ID,0,8)" issue when sites have order number > 8 digits
      // HDS00005025
 
@@ -836,5 +838,5 @@
   TC_SAVERR  = 'Error Saving Order';
 var
-  i, idx, AType, theSts: Integer;
+  i, idx, AType, PrintLoc, theSts: Integer;
   SigSts, RelSts, Nature: Char;
   ESCode, AnID, AnErrMsg: string;
@@ -842,5 +844,5 @@
   OrderList: TStringList;
   SaveCoPay: boolean;
-  DigSigErr, DigStoreErr: Boolean;
+  DigSigErr, DigStoreErr, CryptoChecked: Boolean;
   SigData, SigUser, SigDrugSch, SigDEA: string;
   cSignature, cHashData, cCrlUrl, cErr: string;
@@ -884,4 +886,5 @@
   ESCode := '';
   SaveCoPay := FALSE;
+  PrintLoc := 0;
   if BILLING_AWARE then
   begin
@@ -908,19 +911,5 @@
     OrderList := TStringList.Create;
     DigSigErr := True;
-    DigStoreErr := False;
-    if GetPKISite and GetPKIUse then
-      begin
-        try  //PKI object creation
-          crypto := CoXuDigSigS.Create;
-          crypto.GetCSP;
-          StatusText(crypto.Reason);
-          DigSigErr := False;
-        except
-        on  E: Exception do
-          begin
-            DigSigErr := True;
-          end;
-        end;
-      end;
+    CryptoChecked := False;
     try
       Nature := NO_PROVIDER;
@@ -993,5 +982,4 @@
               OrderList.Add(ChangeItem.ID + U + SS_ONCHART + U + RS_RELEASE + U + NO_WRITTEN);
 
-
           end; {with lstReview}
         end; {OR_NOKEY, OR_CLERK, OR_NURSE, OR_STUDENT}
@@ -1011,4 +999,20 @@
                                SigSts := SS_ESIGNED;
                                RelSts := RS_RELEASE;
+                               if (OrderRequiresDigitalSignature(ChangeItem.ID)) and (CryptoChecked = false)
+                                 and GetPKISite and GetPKIUse then
+                                  begin
+                                    Cryptochecked := true;
+                                    try  //PKI object creation
+                                      crypto := CoXuDigSigS.Create;
+                                      crypto.GetCSP;
+                                      StatusText(crypto.Reason);
+                                      DigSigErr := False;
+                                    except
+                                    on  E: Exception do
+                                      begin
+                                        DigSigErr := True;
+                                      end;
+                                    end;
+                                  end;
                                if (DigSigErr = false) and (OrderRequiresDigitalSignature(ChangeItem.ID))
                                  and (SigItems.OK2SaveSettings) then
@@ -1122,5 +1126,8 @@
              else
              begin
-                InfoBox(TX_Order_Error, 'Review/Sign Orders', MB_OK);
+                if BILLING_AWARE then
+                   InfoBox(TX_Order_Error, 'Review/Sign Orders', MB_OK)
+                   else
+                      InfoBox(TC_Order_Error, 'Review/Sign Orders', MB_OK);
                 Exit;
              end
@@ -1137,7 +1144,6 @@
             if (cmdOk.Caption = 'Sign') then
               begin
-                if Not BADxEntered then
+                if Not UBACore.BADxEntered then
                 begin
-                   SaveCoPay := FALSE;
                    InfoBox(TX_NO_DX, TC_NO_DX, MB_OK);
                    Exit;
@@ -1156,8 +1162,23 @@
         if OrderList.Count > 0 then
         begin
+
+        //hds7591  Clinic/Ward movement.  Nurse orders
+          if (cmdOk.Caption = 'Sign') or (cmdOK.Caption = 'OK') and (not frmFrame.TimedOut) then
+          begin
+             if IsValidIMOLoc(uCore.TempEncounterLoc,Patient.DFN) then
+                frmClinicWardMeds.ClinicOrWardLocation(OrderList, uCore.TempEncounterLoc,uCore.TempEncounterLocName, PrintLoc)
+             else
+                if (IsValidIMOLoc(Encounter.Location,Patient.DFN)) and ((frmClinicWardMeds.rpcIsPatientOnWard(patient.DFN)) and (Patient.Inpatient = false)) then
+                   frmClinicWardMeds.ClinicOrWardLocation(OrderList, Encounter.Location,Encounter.LocationName, PrintLoc);
+          end;
+          uCore.TempEncounterLoc := 0;
+          uCore.TempEncounterLocName := '';
+        end;
+        //hds7591  Clinic/Ward movement.
+        
           if SaveCoPay then
             SigItems.SaveSettings; // Save CoPay FIRST
           SendOrders(OrderList, ESCode);   {*KCM*}
-        end;
+
         with OrderList do for i := 0 to Count - 1 do
         begin
@@ -1183,5 +1204,5 @@
             if theSts = 10 then  OrderList.Delete(idx);  //signed delayed order should not be printed.
           end;
-          PrintOrdersOnSignRelease(OrderList, Nature);
+          PrintOrdersOnSignRelease(OrderList, Nature, PrintLoc);
         end;
         StatusText('');
@@ -1323,5 +1344,4 @@
        if frmFrame.TimedOut then Exit;
         //Billing Awareness 'flyover' hint includes Dx code(s) when Dx code(s) have been assigned to an order
-          tempRec := TBADxRecord.Create;
 
           if Assigned(frmReview) then
@@ -1402,5 +1422,4 @@
   UBAGlobals.PLFactorsIndexes.Clear;
 
-  numSelected := 0;
   match := false;
   allBlank := false;
@@ -1550,5 +1569,5 @@
               thisOrderList.Add(thisChangeItem.ID);
               // Returns True if All selected orders are N/A, Order selected are NON CIDC or DC'd
-              if IsAllOrdersNA(thisOrderList) then
+              if uBACore.IsAllOrdersNA(thisOrderList) then
                  begin
                  Diagnosis1.Enabled := false;
@@ -1712,8 +1731,4 @@
         end;
    end;
-
-  //CopyActive := true; //CQ6225
-  //Paste1.Enabled := true; //CQ6225  
-
 end;
 
@@ -1737,6 +1752,4 @@
           if (frmReview.lstReview.Selected[i]) then
             begin
-            thisChangeItem := TChangeItem.Create;
-            thisChangeItem := nil;
             thisChangeItem := TChangeItem(lstReview.Items.Objects[i]);
 
@@ -1756,7 +1769,6 @@
 
                   //***************************************************************
-                  if (NOT UBACore.IsOrderBillable(fReview.targetOrderID) ) then// and
-                  //   (NOT tempDxNodeExists(fReview.targetOrderID) )then   // added to allow copy to NON CIDC consult orders that requires a DX.
-                    begin
+                  if (NOT UBACore.IsOrderBillable(fReview.targetOrderID) ) then
+                   begin
                     ShowMessage(BA_NA_PASTE_DISALLOWED);
                     fReview.targetOrderID := '';
@@ -1768,9 +1780,9 @@
                   with newRec do
                     begin
-                    FOrderID := fReview.targetOrderID;
-                    FBADxCode := CopyBuffer.FBADxCode;
-                    FBASecDx1 := CopyBuffer.FBASecDx1;
-                    FBASecDx2 := CopyBuffer.FBASecDx2;
-                    FBASecDx3 := CopyBuffer.FBASecDx3;
+                      FOrderID := fReview.targetOrderID;
+                      FBADxCode := CopyBuffer.FBADxCode;
+                      FBASecDx1 := CopyBuffer.FBASecDx1;
+                      FBASecDx2 := CopyBuffer.FBASecDx2;
+                      FBASecDx3 := CopyBuffer.FBASecDx3;
                     end;
 
@@ -1796,13 +1808,5 @@
 
   lstReview.Refresh; //Update grid to show pasted Dx/TF/CI
-{
-  //CQ6225
-  if CopyActive then
-     begin
-     Paste1.Enabled := false;
-     CopyActive := false;
-     end;
-  //end CQ6225
-}
+
 end;
 
@@ -1840,6 +1844,5 @@
 begin
   howMany := 0;
-  thisItem := TChangeItem.Create;
-  
+
   for i := 0 to lstReview.Items.Count-1 do
      begin
@@ -1958,6 +1961,4 @@
      FRVTFHintWindowActive := False;
   end;
-   x := 0;
-   y := 0;
 
    FRVTFHintWindow := THintWindow.Create(frmReview); //(frmReview);
@@ -2033,5 +2034,5 @@
   Y: Integer);
 begin
-  IF BILLING_AWARE then
+//  IF BILLING_AWARE then
     if FRVTFHintWindowActive then
     begin
@@ -2043,6 +2044,4 @@
 procedure TfrmReview.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 begin
-if BILLING_AWARE then
-begin
   if FRVTFHintWindowActive then
   begin
@@ -2051,5 +2050,4 @@
      Application.ProcessMessages;
   end;
-  end;
 end;
 
@@ -2061,24 +2059,24 @@
         begin
         //Abbreviated captions
-        Label23.ShowHint := false;
-        StaticText1.ShowHint := false;
-        Label17.ShowHint := false;
-        Label15.ShowHint := false;
-        Label13.ShowHint := false;
-        Label11.ShowHint := false;
-        lblHNC.ShowHint := false;
+          Label23.ShowHint := false;
+          StaticText1.ShowHint := false;
+          Label17.ShowHint := false;
+          Label15.ShowHint := false;
+          Label13.ShowHint := false;
+          Label11.ShowHint := false;
+          lblHNC.ShowHint := false;
         //Long captions
-        Label24.ShowHint := false;
-        staticText4.ShowHint := false;
-        Label17.ShowHint := false;
-        Label18.ShowHint := false;
-        Label15.ShowHint := false;
-        Label16.ShowHint := false;
-        Label13.ShowHint := false;
-        Label14.ShowHint := false;
-        Label11.ShowHint := false;
-        Label12.ShowHint := false;
-        lblHNC.ShowHint := false;
-        lblHNC2.ShowHint := false;
+          Label24.ShowHint := false;
+          staticText4.ShowHint := false;
+          Label17.ShowHint := false;
+          Label18.ShowHint := false;
+          Label15.ShowHint := false;
+          Label16.ShowHint := false;
+          Label13.ShowHint := false;
+          Label14.ShowHint := false;
+          Label11.ShowHint := false;
+          Label12.ShowHint := false;
+          lblHNC.ShowHint := false;
+          lblHNC2.ShowHint := false;
         end;
      end
@@ -2088,34 +2086,31 @@
         begin
         //Abbreviated captions
-        Label23.ShowHint := true;
-        StaticText1.ShowHint := true;
-        Label17.ShowHint := true;
-        Label15.ShowHint := true;
-        Label13.ShowHint := true;
-        Label11.ShowHint := true;
-        lblHNC.ShowHint := true;
-        //Long captions
-        Label24.ShowHint := true;
-        staticText4.ShowHint := true;
-        Label17.ShowHint := true;
-        Label18.ShowHint := true;
-        Label15.ShowHint := true;
-        Label16.ShowHint := true;
-        Label13.ShowHint := true;
-        Label14.ShowHint := true;
-        Label11.ShowHint := true;
-        Label12.ShowHint := true;
-        lblHNC.ShowHint := true;
-        lblHNC2.ShowHint := true;
+          Label23.ShowHint := true;
+          StaticText1.ShowHint := true;
+          Label17.ShowHint := true;
+          Label15.ShowHint := true;
+          Label13.ShowHint := true;
+          Label11.ShowHint := true;
+          lblHNC.ShowHint := true;
+          //Long captions
+          Label24.ShowHint := true;
+          staticText4.ShowHint := true;
+          Label17.ShowHint := true;
+          Label18.ShowHint := true;
+          Label15.ShowHint := true;
+          Label16.ShowHint := true;
+          Label13.ShowHint := true;
+          Label14.ShowHint := true;
+          Label11.ShowHint := true;
+          Label12.ShowHint := true;
+          lblHNC.ShowHint := true;
+          lblHNC2.ShowHint := true;
         end;
      end;
 end;
 
-// determines if BA switch is on, user is provider and has orelse key
-// is true, BA data is not mandatory.
 procedure TfrmReview.FormClose(Sender: TObject; var Action: TCloseAction);
 begin
- if BILLING_AWARE then
- begin
+
     if FRVTFHintWindowActive then
     begin
@@ -2125,13 +2120,12 @@
       with fraCopay do
         begin
-        Label24.ShowHint := false;
-        staticText4.ShowHint := false;
-        Label18.ShowHint := false;
-        Label16.ShowHint := false;
-        Label14.ShowHint := false;
-        Label12.ShowHint := false;
-        lblHNC2.ShowHint := false;
+          Label24.ShowHint := false;
+          staticText4.ShowHint := false;
+          Label18.ShowHint := false;
+          Label16.ShowHint := false;
+          Label14.ShowHint := false;
+          Label12.ShowHint := false;
+          lblHNC2.ShowHint := false;
         end;
-    end;
  end;
 
@@ -2164,8 +2158,5 @@
   i : integer;
 begin
-  //The with statement below would cause access violations on other Delphi machines.
-{    with lstReview do
-    begin }
-  //Must use fully qualifying path includeing the unit... very wierd!
+
   if fReview.frmReview.lstReview.Count < 1 then Exit;
   for i := 0 to fReview.frmReview.lstReview.Count-1 do
@@ -2180,5 +2171,4 @@
   if fReview.frmReview.lstReview.ItemIndex >= 0 then
     fReview.frmReview.lstReview.Selected[fReview.frmReview.lstReview.ItemIndex] := True;
- //   end;
 end;
 
@@ -2192,9 +2182,10 @@
 procedure TfrmReview.FormatListForScreenReader;
 var
-  ListStateOn : boolean;
+  ListStateOn : longbool;
+  Success: longbool;
 begin
   //Determine if a screen reader is currently being used.
-  SystemParametersInfo(SPI_GETSCREENREADER, 0, @ListStateOn,0);
-  if ListStateOn then
+  Success := SystemParametersInfo(SPI_GETSCREENREADER, 0, @ListStateOn,0);
+  if Success and ListStateOn then
     SetItemTextToState;
 end;
