Module

fReview

Path

C:\CPRS\CPRS30\fReview.pas

Last Modified

7/15/2014 3:26:38 PM

Comments

.$define debug

Units Used in Interface

Name Comments
fBase508Form -
fCSRemaining -
fPrintLocation -
mCoPayDesc -
rODMeds -
UBACore -
UBAGlobals -
uConst -
uCore -
XuDsigS -

Units Used in Implementation

Name Comments
fBALocalDiagnoses -
fClinicWardMeds -
fConsults -
fDCSumm -
fFrame -
fLkUpLocation -
fNotes -
fOCSession -
fOrders -
fOrdersPrint -
fOrdersSign -
fRptBox -
fSignItem -
fSurgery -
rCore -
rODLab -
rOrders -
UBAConst -
UBAMessages -
uOrders -
uSignItems -

Classes

Name Comments
TfrmReview -

Procedures

Name Owner Declaration Scope Comments
AddCSHeader TfrmReview procedure AddCSHeader(s: string); Private Add header to review list, object is left nil
AddHeader TfrmReview procedure AddHeader(s: string); Private Add header to review list, object is left nil
AdjustSignatureTop TfrmReview procedure AdjustSignatureTop( HeightAdjustment: integer); Private This has been added to support correct anchoring for the lstReview list.
buDiagnosisClick TfrmReview procedure buDiagnosisClick(Sender: TObject); Public/Published
Begin BillingAware
End BillingAware
BuildFullList TfrmReview procedure BuildFullList; Private -
BuildList TfrmReview procedure BuildList(FullList: boolean); Private -
BuildSignList TfrmReview procedure BuildSignList; Private -
CleanupChangesList TfrmReview procedure CleanupChangesList(Sender: TObject; ChangeItem: TChangeItem); {**RV**} Private
RV**
Added for v15.3 - called by Changes.Remove, but only if fReview in progress
ClearDiagnoses1Click TfrmReview procedure ClearDiagnoses1Click(Sender: TObject); Public/Published -
cmdCancelClick TfrmReview procedure cmdCancelClick(Sender: TObject); Public/Published Cancelled - do nothing
cmdOKClick TfrmReview procedure cmdOKClick(Sender: TObject); Public/Published Validate the electronic signature & call SaveSignItem for the encounter
Copy1Click TfrmReview procedure Copy1Click(Sender: TObject); Public/Published - Copy contents of the 'source' order for copy/paste operation
Exit1Click TfrmReview procedure Exit1Click(Sender: TObject); Public/Published -
FormatListForScreenReader TfrmReview procedure FormatListForScreenReader; Private -
FormClose TfrmReview procedure FormClose(Sender: TObject; var Action: TCloseAction); Public/Published -
FormCreate TfrmReview procedure FormCreate(Sender: TObject); Public/Published -
FormDestroy TfrmReview procedure FormDestroy(Sender: TObject); Public/Published -
FormKeyDown TfrmReview procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
FormKeyUp TfrmReview procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
FormMouseDown TfrmReview procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published -
FormMouseMove TfrmReview procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Public/Published -
FormPaint TfrmReview procedure FormPaint(Sender: TObject); Public/Published -
FormResize TfrmReview procedure FormResize(Sender: TObject); Public/Published -
FormShow TfrmReview procedure FormShow(Sender: TObject); Public/Published -
fraCoPayLabel24MouseMove TfrmReview procedure fraCoPayLabel24MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Public/Published -
Log2File - procedure Log2File( crypto: tCryptography) ; Local -
lstCSReviewClick TfrmReview procedure lstCSReviewClick(Sender: TObject); Public/Published
If grid item is an order-able item, then enable the Diagnosis button
 else disable the Diagnosis button.
Begin BillingAware
End BillingAware
lstCSReviewClickCheck TfrmReview procedure lstCSReviewClickCheck(Sender: TObject); Public/Published Prevent grayed checkboxes from being changed to anything else
lstCSReviewDrawItem TfrmReview procedure lstCSReviewDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); Public/Published
Outdent the header items (thus hiding the checkbox) 
Begin BillingAware
End BillingAware
lstCSReviewKeyUp TfrmReview procedure lstCSReviewKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
lstCSReviewMeasureItem TfrmReview procedure lstCSReviewMeasureItem(Control: TWinControl; Index: Integer; var AHeight: Integer); Public/Published -
lstCSReviewMouseDown TfrmReview procedure lstCSReviewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published - Open copy/paste popup menu.
lstCSReviewMouseMove TfrmReview procedure lstCSReviewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Public/Published
Begin BillingAware
End BillingAware
lstReviewClick TfrmReview procedure lstReviewClick(Sender: TObject); Public/Published
If grid item is an order-able item, then enable the Diagnosis button
 else disable the Diagnosis button.
Begin BillingAware
End BillingAware
lstReviewClickCheck TfrmReview procedure lstReviewClickCheck(Sender: TObject); Public/Published Prevent grayed checkboxes from being changed to anything else
lstReviewDrawItem TfrmReview procedure lstReviewDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); Public/Published
Outdent the header items (thus hiding the checkbox) 
Begin BillingAware
End BillingAware
lstReviewKeyUp TfrmReview procedure lstReviewKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); Public/Published -
lstReviewMeasureItem TfrmReview procedure lstReviewMeasureItem(Control: TWinControl; Index: Integer; var AHeight: Integer); Public/Published -
lstReviewMouseDown TfrmReview procedure lstReviewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Public/Published - Open copy/paste popup menu.
lstReviewMouseMove TfrmReview procedure lstReviewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Public/Published
Begin BillingAware
End BillingAware
Paste1Click TfrmReview procedure Paste1Click(Sender: TObject); Public/Published - Populate 'target' orders of a copy/paste operation with contents of 'source' order
PlaceComponents TfrmReview procedure PlaceComponents; Private -
radReleaseClick TfrmReview procedure radReleaseClick(Sender: TObject); Public/Published -
SetCheckBoxStatus TfrmReview procedure SetCheckBoxStatus(thisOrderID: string); Public - Set the current CI checkboxes status
SetItemTextToState TfrmReview procedure SetItemTextToState; Private -
ShowTreatmentFactorHints TfrmReview procedure ShowTreatmentFactorHints(var pHintText: string; var pCompName: TVA508StaticText); Private
508
BILLING AWARE Procedure

 508
txtESCodeChange TfrmReview procedure txtESCodeChange(Sender: TObject); Public/Published -
updateAllChilds - procedure updateAllChilds(CheckedStatus: boolean; ParentOrderId: string); Local -
updateAllChilds - procedure updateAllChilds(CheckedStatus: boolean; ParentOrderId: string); Local -
UpdateTextRecord - procedure UpdateTextRecord(r: TRect); Local End BillingAware
UpdateTextRecord - procedure UpdateTextRecord(r: TRect); Local End BillingAware

Functions

Name Owner Declaration Scope Comments
AddCSItem TfrmReview function AddCSItem(ChangeItem: TChangeItem): integer; Private Add a single review item to the list with its associated TChangeItem object
AddItem TfrmReview function AddItem(ChangeItem: TChangeItem): integer; Private Add a single review item to the list with its associated TChangeItem object
AnyItemsAreChecked TfrmReview function AnyItemsAreChecked: Boolean; Private -
CSItemsAreChecked TfrmReview function CSItemsAreChecked: Boolean; Private Return true if any items in the CS Review List are checked for applying signature
GetCheckBoxStatus TfrmReview function GetCheckBoxStatus(gridItemIndex : smallint) : string; overload; Public - Obtain checkbox status for selected order - BY ORDER ID
GetCheckBoxStatus TfrmReview function GetCheckBoxStatus(sourceOrderID : string) : string; overload; Public
PASS IN ORDER ID - NOT GRID INDEX

   - Obtain checkbox status for selected order - BY ORDER ID
GetNonNilItemCount TfrmReview function GetNonNilItemCount : integer; Public
CQ5172
CQ5172
GetNumberOfSelectedOrders TfrmReview function GetNumberOfSelectedOrders : byte; Private - Return the number of orders in clstOrders that are currently selected.
IsSignatureRequired TfrmReview function IsSignatureRequired:boolean; Private -
ItemsAreChecked TfrmReview function ItemsAreChecked: Boolean; Private Return true if any items in the Review List are checked for applying signature
nonDCCSItemsAreChecked TfrmReview function nonDCCSItemsAreChecked: Boolean; Private Return true if any items in the CS Review List are checked for applying signature
OrdersSignedOrReleased - function OrdersSignedOrReleased: Boolean; Local -
OrdersToBeSignedOrReleased - function OrdersToBeSignedOrReleased: Boolean; Local -
Piece2end - function Piece2end (s,del: string): string; Local -
ReviewChanges - function ReviewChanges(TimedOut: Boolean; IsEvtChange: boolean = False): Boolean; Interfaced Display changes made to chart for this encounter, allow changes to be saved, signed, etc.
SignRequiredForAny TfrmReview function SignRequiredForAny(FullList: boolean): Boolean; Private -

Global Variables

Name Type Declaration Comments
chkBoxStatus UnicodeString chkBoxStatus: string; -
CopyBuffer TBADxRecord CopyBuffer: TBADxRecord; -
copyOrderID UnicodeString copyOrderID: string; -
crypto tCryptography crypto: tCryptography; End BillingAware
currentItems TStringList currentItems: TStringList; CQ5063
currentlySelectedItem Integer currentlySelectedItem: integer; CQ5063
DxRect TRect DxRect: TRect; -
frmReview TfrmReview frmReview: TfrmReview;
Begin BillingAware

Originally declared locally in function ReviewChanges()
FRVTFHintWindow Simple (unknown) FRVTFHintWindow: THintWindow; -
FRVTFHintWindowActive Boolean FRVTFHintWindowActive: boolean; -
srcDx UnicodeString srcDx: string; -
srcIndex Integer srcIndex: integer; -
srcOrderID UnicodeString srcOrderID: string; -
targetOrderID UnicodeString targetOrderID: string; -
tempOrderList TStringList tempOrderList: TStringList; -
tempStrList TStringList tempStrList: TStringList; -
TFactorMemo TCaptionMemo TFactorMemo: TCaptionMemo; Begin BillingAware

Constants

Name Declaration Scope Comments
SP_CLERK 1 Global -
SP_NONE 0 Global -
SP_NURSE 2 Global -
SP_SIGN 3 Global -
TC_ES_REQ 'Electronic Signature' Global -
TC_NO_DX 'Incomplete Diagnosis Entry' Global -
TC_NO_REL 'Unable to Release Orders' Global -
TX_ES_REQ 'Enter your electronic signature to release these orders.' Global -
TX_INVAL_CAP 'Unrecognized Signature Code' Global -
TX_INVAL_MSG 'Not a valid electronic signature code. Enter a valid code or press Cancel.' Global -
TX_NO_DX 'A Diagnosis must be selected prior to signing any of the following order types:' Global -
TX_NO_REL CRLF + CRLF + '- cannot be released to the service(s).' + CRLF + CRLF + 'Reason: ' Global -
TXT_BLANK ' ' Global -
TXT_DOCS 'Documents' Global -
TXT_ENCNT 'Outpatient Encounter' Global -
TXT_NODIAG 'Diagnosis: < None Selected >' Global -
TXT_NOPROC 'Procedures: none' Global -
TXT_NOVISIT 'Visit Type: < None Selected >' Global -
TXT_ORDERS 'Orders' Global -


Module Source

1     unit fReview;
2     
3     {.$define debug}
4     
5     interface                                                                                                                                
6     
7     uses
8       UBAGlobals,
9       Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
10      StdCtrls, checklst, uConst, ExtCtrls, uCore, mCoPayDesc, XuDsigS,
11      ORCtrls, Menus, UBACore, ORClasses, ORNet, fBase508Form, fPrintLocation,
12      VA508AccessibilityManager, fCSRemaining, rODMeds;
13    
14    type
15      TfrmReview = class(TfrmBase508Form)
16        fraCoPay: TfraCoPayDesc;
17        laDiagnosis: TLabel;
18        gbxDxLookup: TGroupBox;
19        buDiagnosis: TButton;
20        poBACopyPaste: TPopupMenu;
21        Copy1: TMenuItem;
22        Paste1: TMenuItem;
23        Diagnosis1: TMenuItem;
24        Exit1: TMenuItem;
25        pnlProvInfo: TPanel;
26        lblProvInfo: TLabel;
27        pnlDEAText: TPanel;
28        lblDEAText: TStaticText;
29        pnlBottom: TPanel;
30        pnlSignature: TPanel;
31        lblESCode: TLabel;
32        txtESCode: TCaptionEdit;
33        pnlOrderAction: TPanel;
34        Label1: TStaticText;
35        lblHoldSign: TStaticText;
36        radSignChart: TRadioButton;
37        radHoldSign: TRadioButton;
38        grpRelease: TGroupBox;
39        radVerbal: TRadioButton;
40        radPhone: TRadioButton;
41        radPolicy: TRadioButton;
42        radRelease: TRadioButton;
43        cmdOK: TButton;
44        cmdCancel: TButton;
45        pnlCombined: TORAutoPanel;
46        pnlReview: TPanel;
47        lstReview: TCaptionCheckListBox;
48        lblSig: TStaticText;
49        pnlCSReview: TPanel;
50        lblCSReview: TLabel;
51        lstCSReview: TCaptionCheckListBox;
52        lblSmartCardNeeded: TStaticText;
53        pnlTop: TPanel;
54        procedure FormCreate(Sender: TObject);
55        procedure lstReviewDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
56        procedure cmdOKClick(Sender: TObject);
57        procedure cmdCancelClick(Sender: TObject);
58        procedure lstReviewClickCheck(Sender: TObject);
59        procedure radReleaseClick(Sender: TObject);
60        procedure txtESCodeChange(Sender: TObject);
61        procedure lstReviewMeasureItem(Control: TWinControl; Index: Integer; var AHeight: Integer);
62        procedure FormDestroy(Sender: TObject);
63        procedure lstReviewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
64        procedure buDiagnosisClick(Sender: TObject);
65        procedure lstReviewClick(Sender: TObject);
66        procedure Exit1Click(Sender: TObject);
67        procedure lstReviewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
68        procedure Copy1Click(Sender: TObject);
69        procedure Paste1Click(Sender: TObject);
70        procedure ClearDiagnoses1Click(Sender: TObject);
71        procedure FormShow(Sender: TObject);
72        procedure FormKeyDown(Sender: TObject; var Key: Word;
73          Shift: TShiftState);
74        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
75          Y: Integer);
76        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
77          Shift: TShiftState; X, Y: Integer);
78        procedure fraCoPayLabel24MouseMove(Sender: TObject; Shift: TShiftState;
79          X, Y: Integer);
80        procedure FormClose(Sender: TObject; var Action: TCloseAction);
81        procedure lstReviewKeyUp(Sender: TObject; var Key: Word;
82          Shift: TShiftState);
83        procedure FormKeyUp(Sender: TObject; var Key: Word;
84          Shift: TShiftState);
85        procedure FormResize(Sender: TObject);
86        procedure lstCSReviewMeasureItem(Control: TWinControl; Index: Integer;
87          var AHeight: Integer);
88        procedure lstCSReviewDrawItem(Control: TWinControl; Index: Integer;
89          Rect: TRect; State: TOwnerDrawState);
90        procedure lstCSReviewClickCheck(Sender: TObject);
91        procedure lstCSReviewMouseMove(Sender: TObject; Shift: TShiftState; X,
92          Y: Integer);
93        procedure lstCSReviewMouseDown(Sender: TObject; Button: TMouseButton;
94          Shift: TShiftState; X, Y: Integer);
95        procedure lstCSReviewKeyUp(Sender: TObject; var Key: Word;
96          Shift: TShiftState);
97        procedure lstCSReviewClick(Sender: TObject);
98        procedure FormPaint(Sender: TObject);
99    
100     private
101       { Private declarations }
102       FOKPressed: Boolean;
103       FShowPanel: Integer;
104       FSilent: Boolean;
105       FCouldSign: Boolean;
106       FLastHintItem: integer;
107       FOldHintPause: integer;
108       FOldHintHidePause: integer;
109       FIsEvtChange: boolean;
110       procedure AddHeader(s: string);
111       procedure AddCSHeader(s: string);
112       function AddItem(ChangeItem: TChangeItem): integer;
113       function AddCSItem(ChangeItem: TChangeItem): integer;
114       procedure BuildList(FullList: boolean);
115       procedure BuildFullList;
116       procedure BuildSignList;
117       procedure PlaceComponents;
118       procedure CleanupChangesList(Sender: TObject; ChangeItem: TChangeItem);  {**RV**}
119       function ItemsAreChecked: Boolean;
120       function CSItemsAreChecked: Boolean;
121       function nonDCCSItemsAreChecked: Boolean;
122       function AnyItemsAreChecked: Boolean;
123       function SignRequiredForAny(FullList: boolean): Boolean;
124       procedure AdjustSignatureTop( HeightAdjustment: integer);
125       function IsSignatureRequired:boolean;
126       function GetNumberOfSelectedOrders : byte;
127       procedure ShowTreatmentFactorHints(var pHintText: string; var pCompName: TVA508StaticText); // 508
128       procedure SetItemTextToState;
129       procedure FormatListForScreenReader;
130     public
131       procedure SetCheckBoxStatus(thisOrderID: string);
132       function GetCheckBoxStatus(sourceOrderID : string) : string; overload;
133       function GetCheckBoxStatus(gridItemIndex : smallint) : string; overload; 
134       function GetNonNilItemCount : integer; //CQ5172
135     end;
136   
137   function ReviewChanges(TimedOut: Boolean; IsEvtChange: boolean = False): Boolean;
138   
139   var
140   {Begin BillingAware}
141     frmReview: TfrmReview; //Originally declared locally in function ReviewChanges()
142     DxRect: TRect;
143   {End BillingAware}
144   
145     {Begin BillingAware}
146       TFactorMemo: TCaptionMemo;
147       chkBoxStatus: string;
148       srcOrderID: string;
149       targetOrderID: string;
150       tempStrList: TStringList;
151       srcDx: string;
152       tempOrderList: TStringList;
153       copyOrderID: string;
154       srcIndex: integer;
155       CopyBuffer: TBADxRecord;
156       FRVTFHintWindowActive: boolean;
157       FRVTFHintWindow: THintWindow;
158       {End BillingAware}
159       crypto: tCryptography;
160       currentlySelectedItem: integer; //CQ5063
161       currentItems: TStringList; //CQ5063
162   
163   implementation
164   
165   {$R *.DFM}
166   
167   uses ORFn, rCore, fNotes, fConsults, fOrders, rOrders, Hash, fDCSumm, fOCSession, uOrders,
168        fSignItem, fOrdersPrint, fLkUpLocation, fFrame, uSignItems, fSurgery,
169        fBALocalDiagnoses, UBAConst, UBAMessages, fOrdersSign, fClinicWardMeds,
170        rODLab, fRptBox, VAUtils;
171   
172   const
173     SP_NONE  = 0;
174     SP_CLERK = 1;
175     SP_NURSE = 2;
176     SP_SIGN  = 3;
177     TXT_ENCNT     = 'Outpatient Encounter';
178     TXT_NOVISIT   = 'Visit Type: < None Selected >';
179     TXT_NODIAG    = 'Diagnosis: < None Selected >';
180     TXT_NOPROC    = 'Procedures: none';
181     TXT_DOCS      = 'Documents';
182     TXT_ORDERS    = 'Orders';
183     TXT_BLANK     = ' ';
184     TX_INVAL_MSG  = 'Not a valid electronic signature code.  Enter a valid code or press Cancel.';
185     TX_INVAL_CAP  = 'Unrecognized Signature Code';
186     TX_ES_REQ     = 'Enter your electronic signature to release these orders.';
187     TC_ES_REQ     = 'Electronic Signature';
188     TX_NO_REL     = CRLF + CRLF + '- cannot be released to the service(s).' + CRLF + CRLF + 'Reason: ';
189     TC_NO_REL     = 'Unable to Release Orders';
190     TC_NO_DX      =  'Incomplete Diagnosis Entry';
191     TX_NO_DX      =  'A Diagnosis must be selected prior to signing any of the following order types:'
192                      + CRLF + 'Outpatient Lab,Radiology, Outpatient Medications, Prosthetics.';
193   
194   procedure TfrmReview.SetCheckBoxStatus(thisOrderID: string);
195   {
196      - Set the current CI checkboxes status
197   }
198   begin
199     if BILLING_AWARE then
200        begin
201           uSignItems.uSigItems.SetSigItems(lstReview, thisOrderID);
202        end;
203   end;
204   
205   function TfrmReview.GetCheckBoxStatus(gridItemIndex: smallint) : string;
206   {
207     - Obtain checkbox status for selected order - BY ORDER ID
208   }
209   var
210     itemsList: TStringList;
211     i: smallint;
212   begin
213     Result := '';
214     itemsList := TStringList.Create;
215     itemsList.Clear;
216     itemsList := uSigItems.GetSigItems; //Get FItems list
217   
218     if BILLING_AWARE then
219        begin
220        for i := 0 to itemsList.Count-1 do
221           begin
222           if i = gridItemIndex then   //compare to order ID of source order
223              begin
224              Result := Piece(itemsList[i],U,4);  //return TF status'
225              Break;
226              end;
227           end;
228        end;
229   end;
230   
231   function TfrmReview.GetCheckBoxStatus(sourceOrderID: string) : string;  //PASS IN ORDER ID - NOT GRID INDEX
232   {
233      - Obtain checkbox status for selected order - BY ORDER ID
234   }
235   var
236     itemsList: TStringList;
237     i: smallint;
238     thisOrderID: string;
239   begin
240     Result := '';
241     itemsList := TStringList.Create;
242     itemsList.Clear;
243     itemsList := uSigItems.GetSigItems; //Get FItems list
244   
245     if BILLING_AWARE then
246        begin
247        for i := 0 to itemsList.Count-1 do
248           begin
249           thisOrderID := Piece(itemsList[i],'^',1); //get the order ID
250           if thisOrderID = sourceOrderID then   //compare to order ID of source order
251              begin
252              Result := Piece(itemsList[i],U,4);  //return TF status'
253              Break;
254              end;
255           end;
256        end;
257   end;
258   
259   function TfrmReview.GetNumberOfSelectedOrders : byte;
260   {
261     - Return the number of orders in clstOrders that are currently selected.
262   }
263   var
264     i: integer;
265     numSelected: byte;
266   begin
267     result := 0;
268     if BILLING_AWARE then
269        begin
270        numSelected := 0;
271        for i := 1 to frmReview.lstReview.Items.Count-1 do
272            if (frmReview.lstReview.Selected[i]) then
273              Inc(numSelected);
274   
275        Result := numSelected;
276        end;
277   end;
278   
279   function ReviewChanges(TimedOut: Boolean; IsEvtChange: boolean = False): Boolean;
280   { display changes made to chart for this encounter, allow changes to be saved, signed, etc. }
281   var
282     i: integer;
283   begin
284     Result := True;
285     if Changes.Count = 0 then Exit;
286     if assigned(frmReview) then Exit;
287     frmReview := TfrmReview.Create(Application);
288   
289     CallV('ORDEA DEATEXT', []);
290     frmReview.lblDEAText.Caption := '';
291     for i := 0 to RPCBrokerV.Results.Count -1 do
292        frmReview.lblDEAText.Caption := frmReview.lblDEAText.Caption + ' ' + RPCBrokerV.Results.Strings[i];
293   
294     CallV('ORDEA SIGINFO', [Patient.DFN, User.DUZ]);
295     frmReview.lblProvInfo.Caption := '';
296     for i := 0 to RPCBrokerV.Results.Count -1 do
297     begin
298       if not (frmReview.lblProvInfo.Caption = '') then frmReview.lblProvInfo.Caption := frmReview.lblProvInfo.Caption + #13#10;
299       
300        frmReview.lblProvInfo.Caption := frmReview.lblProvInfo.Caption + RPCBrokerV.Results.Strings[i];
301     end;
302     frmReview.lblDeaText.Visible := FALSE;
303     frmReview.lblSmartCardNeeded.Visible := FALSE;
304     try
305       Changes.OnRemove := frmReview.CleanupChangesList;     {**RV**}
306       frmReview.FIsEvtChange := IsEvtChange;
307   
308       if TimedOut and (Changes.Count > 0) then
309          begin
310            frmReview.FSilent := True;
311            frmReview.BuildFullList;
312            with frmReview.lstReview do for i := 0 to Items.Count - 1 do
313              Checked[i] := False;
314            frmReview.cmdOKClick(frmReview);
315            Result := True;
316          end
317       // if user not timed out, execute as before
318       else
319         begin
320            if ((uCore.User.OrderRole = OR_NURSE) or (uCore.User.OrderRole = OR_CLERK)) and Changes.CanSign then
321            begin
322              frmReview.FCouldSign := True;
323              frmReview.BuildSignList;  // ok will remove from changes, exit leaves altogether
324              if ((frmReview.lstReview.Count>0) or (frmReview.lstCSReview.Count>0)) then
325              begin
326                 frmReview.PlaceComponents;
327                 frmReview.ShowModal;
328                 Result := frmReview.FOKPressed;
329                 CSRemaining(frmReview.lstReview.items,frmReview.lstCSReview.items);
330                 LastPINvalue := '';
331              end
332              else
333              begin
334                Result := True;
335              end;
336            end;
337   
338         if Result and (Changes.Count > 0) then
339         begin
340           frmReview.FCouldSign := Changes.CanSign;
341           frmReview.BuildFullList;
342   
343            if BILLING_AWARE then
344               //  build list of orders that are not billable based on package type
345               UBAGlobals.NonBillableOrderList := rpcNonBillableOrders(tempOrderList);
346   
347              if ((frmReview.lstReview.Count>0) or (frmReview.lstCSReview.Count>0)) then
348              begin
349                 frmReview.PlaceComponents;
350                 frmReview.ShowModal;
351                 Result := frmReview.FOKPressed;
352                 CSRemaining(frmReview.lstReview.items,frmReview.lstCSReview.items);
353              end
354              else
355              begin
356                Result := True;
357              end;
358         end;
359   
360       end;
361   
362     finally
363      Changes.OnRemove := nil;     {**RV**}
364      frmReview.Release;
365      frmReview := nil;
366     end;
367   end;
368   
369   procedure TfrmReview.FormCreate(Sender: TObject);
370   const
371     TX_FORM_CAPTION = 'Review / Sign Changes  ';
372   begin
373     FOKPressed := False;
374     FSilent := False;
375     FLastHintItem := -1;
376     Self.Caption := TX_FORM_CAPTION + '(' + Patient.Name + ' - ' + Patient.SSN + ')';
377     FOldHintPause := Application.HintPause;
378     Application.HintPause := 250;
379     FOldHintHidePause := Application.HintHidePause;
380     Application.HintHidePause := 30000;
381      {Begin BillingAware}
382        if  BILLING_AWARE then
383        begin
384           gbxDxLookup.Visible := TRUE;
385           laDiagnosis.Top :=  Lblsig.Top;
386           laDiagnosis.Left := 270;
387           laDiagnosis.Visible := TRUE;
388           rectIndex := 0;
389        end;
390        {End BillingAware}
391   end;
392   
393   procedure TfrmReview.AddHeader(s: string);
394   { add header to review list, object is left nil }
395   begin
396     lstReview.Items.AddObject(s, nil);
397   end;
398   
399   procedure TfrmReview.AddCSHeader(s: string);
400   { add header to review list, object is left nil }
401   begin
402     lstCSReview.Items.AddObject(s, nil);
403   end;
404   
405   function TfrmReview.AddItem(ChangeItem: TChangeItem): integer;
406   { add a single review item to the list with its associated TChangeItem object }
407   begin
408     Result := lstReview.Items.AddObject(ChangeItem.Text, ChangeItem);
409   
410     //Begin BillingAware
411     if  BILLING_AWARE then
412     begin
413       UBAGlobals.ChangeItemOrderNum := ChangeItem.ID; // GE 2/21/2006 removed "Copy(ChangeItem.ID,0,8)" issue when sites have order number > 8 digits
414        // HDS00005025
415   
416       if ChangeItem.ItemType = CH_DOC then    // documents are not orderable, code is necessary
417         UBAGlobals.ChangeItemOrderNum := '0'; // document id can be same as order id, orderid = 0 will be nonbillable
418   
419       tempOrderList.Add(UBAGlobals.ChangeItemOrderNum);
420     end;
421      //end BillingAware
422   
423     case ChangeItem.SignState of
424     CH_SIGN_YES: lstReview.Checked[Result] := True;
425     CH_SIGN_NO:  lstReview.Checked[Result] := False;
426     CH_SIGN_NA:  lstReview.State[Result] := cbGrayed;
427     end;
428     //hds00006047
429    // this will override the signstate from above for all non-va med orders...  no signature required.
430     if ChangeItem.GroupName = '' then
431     begin
432     if ChangeItem.OrderDG = NONVAMEDGROUP then
433            lstReview.State[Result] := cbGrayed;
434      end;
435     //hds00006047
436   end;
437   
438   function TfrmReview.AddCSItem(ChangeItem: TChangeItem): integer;
439   { add a single review item to the list with its associated TChangeItem object }
440   begin
441     Result := lstCSReview.Items.AddObject(ChangeItem.Text, ChangeItem);
442   
443     //Begin BillingAware
444     if  BILLING_AWARE then
445     begin
446       UBAGlobals.ChangeItemOrderNum := ChangeItem.ID; // GE 2/21/2006 removed "Copy(ChangeItem.ID,0,8)" issue when sites have order number > 8 digits
447        // HDS00005025
448   
449       if ChangeItem.ItemType = CH_DOC then    // documents are not orderable, code is necessary
450         UBAGlobals.ChangeItemOrderNum := '0'; // document id can be same as order id, orderid = 0 will be nonbillable
451   
452       tempOrderList.Add(UBAGlobals.ChangeItemOrderNum);
453     end;
454      //end BillingAware
455      if ChangeItem.DCOrder then lstCSReview.Checked[Result] := TRUE
456      else lstCSReview.Checked[Result] := False;
457   
458     if ChangeItem.SignState=CH_SIGN_NA then lstCSReview.State[Result] := cbGrayed;
459    // this will override the signstate from above for all non-va med orders...  no signature required.
460     if ChangeItem.GroupName = '' then
461     begin
462     if ChangeItem.OrderDG = NONVAMEDGROUP then
463            lstCSReview.State[Result] := cbGrayed;
464      end;
465     //hds00006047
466   end;
467   
468   procedure TfrmReview.AdjustSignatureTop( HeightAdjustment: integer);
469   //This has been added to support correct anchoring for the lstReview list.
470   begin
471     Height := Height + HeightAdjustment;
472     lblSig.Top := lblSig.Top + HeightAdjustment;
473     lstReview.Top := lstReview.Top + HeightAdjustment;
474     lstReview.Height := lstReview.Height - HeightAdjustment;
475     //for 24 pt font, we need to make sure that lstreview is resized before the main form is.
476   end;
477   
478   function TfrmReview.IsSignatureRequired:boolean;
479   var
480     i: integer;
481   begin
482    Result := FALSE;
483       with lstReview do for i := 0 to Items.Count-1 do
484       begin
485         if Checked[i] then
486         begin
487           if TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]) = nil then
488              Continue;
489            if (TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).SIGNSTATE) <> CH_SIGN_NA then
490               Result := TRUE;
491            end;
492       end;
493       with lstCSReview do for i := 0 to Items.Count-1 do
494       begin
495         if Checked[i] then
496         begin
497           if TChangeItem(fReview.frmReview.lstCSReview.Items.Objects[i]) = nil then
498              Continue;
499            if (TChangeItem(fReview.frmReview.lstCSReview.Items.Objects[i]).SIGNSTATE) <> CH_SIGN_NA then
500               Result := TRUE;
501            end;
502       end;
503   end;
504   
505   procedure TfrmReview.BuildList(FullList: boolean);
506   var
507     GrpIndex, ChgIndex, lbIdx: Integer;
508     ChangeItem: TChangeItem;
509     LabelHeight: integer;
510     PrevGrpName, temp: string;
511     displayHeader, displaySpacer, displayCSHeader, displayCSSpacer, otherUserOrders, otherhdradded, othercshdradded: boolean;
512     I, ColHeight: Integer;
513     t1, t2{, NVAinNonCSList, otherinNonCSList}: Boolean;
514   begin
515     tempOrderList := TStringList.Create;
516     tempOrderList.Clear;
517     PrevGrpName := '';
518   //  NVAinNonCSList := false;
519   //  otherinNonCSList := false;
520     lstReview.Clear;  // ok to clear without freeing objects since they're part of Changes
521     if(FullList) then
522     begin
523       SigItems.ResetOrders;
524       SigItemsCS.ResetOrders;
525       with Changes do
526       if PCE.Count > 0 then
527       begin
528         for GrpIndex := 0 to PCEGrp.Count - 1 do
529         begin
530           AddHeader('Outpatient Encounter ' + PCEGrp[GrpIndex]);
531           for ChgIndex := 0 to PCE.Count - 1 do
532           begin
533             ChangeItem := PCE[ChgIndex];
534             if ChangeItem.GroupName = PCEGrp[GrpIndex] then AddItem(ChangeItem);
535           end;
536           AddHeader('   ');
537         end;
538       end; {if PCE}
539     end;
540     with Changes do
541     if Documents.Count > 0 then
542     begin
543       AddHeader('Documents');
544       for ChgIndex := 0 to Documents.Count - 1 do
545       begin
546         ChangeItem := Documents[ChgIndex];
547         if(FullList or (ChangeItem.SignState <> CH_SIGN_NA)) then
548            AddItem(ChangeItem);
549       end;
550       if(FullList) then
551          AddHeader('   ');
552     end; {if Documents}
553     if(FullList) then
554     begin
555       //otherUserOrders := False;
556       displaySpacer := False;
557       displayCSSpacer := False;
558       with Changes do
559       if Orders.Count > 0 then
560       begin
561         OrderGrp.Sorted := True;
562         otherUserOrders := False;
563         for GrpIndex := 0 to OrderGrp.Count - 1 do
564         begin
565           displayHeader := True;
566           displayCSHeader := True;
567           if (GrpIndex > 0 ) and (AnsiCompareText(PrevGrpName,OrderGrp[GrpIndex])=0) then
568             Continue;
569           if OrderGrp[GrpIndex] = '' then Temp := 'My Unsigned Orders - This Session'
570           else if OrderGrp[GrpIndex] = 'Other Unsigned' then Temp := 'My Unsigned Orders - Previous Sessions'
571           else Temp := 'Orders - ' + OrderGrp[GrpIndex];
572           {billing aware}
573           if BILLING_AWARE then
574           begin
575              UBACore.rpcBuildSCIEList(Orders);            // build list of orders and Billable Status
576              UBACore.CompleteUnsignedBillingInfo(rpcGetUnsignedOrdersBillingData(OrderListSCEI) );
577           end;
578           {billing aware}
579   
580           for ChgIndex := 0 to Orders.Count - 1 do
581           begin
582             ChangeItem := Orders[ChgIndex];
583             if (ChangeItem.GroupName = OrderGrp[GrpIndex]) and ((ChangeItem.User = 0) or (ChangeItem.User = User.DUZ)) then
584             begin
585               if ((ChangeItem.CSValue = False) or ChangeItem.DCOrder or IsPendingHold(ChangeItem.ID)) then
586               begin
587                 if displayHeader = True then
588                   begin
589                    AddHeader(Temp);
590                     displayHeader := False;
591                    displaySpacer := True;
592                  end;
593                 lbIdx := AddItem(ChangeItem);
594                 SigItems.Add(CH_ORD, ChangeItem.ID, lbIdx);
595   //              if (ChangeItem.OrderDG = 'Non-VA Meds') or (Pos('Non-VA',ChangeItem.Text)>0) then NVAinNonCSList := true
596   //              else otherinNonCSList := true;
597               end
598               else
599               begin
600                 if not(GetPKISite) or not(GetPKIUse) or (DEACheckFailedAtSignature(GetOrderableIen(Piece(ChangeItem.ID,';',1)),False)='1') then ChangeItem.SignState := CH_SIGN_NA;
601   
602                 if displayCSHeader = True then
603                   begin
604                    AddCSHeader(Temp);
605                     displayCSHeader := False;
606                    displayCSSpacer := True;
607                  end;
608                 lbIdx := AddCSItem(ChangeItem);
609                 SigItemsCS.Add(CH_ORD, ChangeItem.ID, lbIdx);
610               end;
611               
612            end
613            else if ((ChangeItem.User > 0) and (ChangeItem.User <> User.DUZ)) then
614              otherUserOrders := True;
615           end;
616           if displayHeader = False then AddHeader('   ');
617           if displayCSHeader = False then AddCSHeader('   ');
618           PrevGrpName := OrderGrp[GrpIndex];
619       end;
620       //AGP fix for CQ 10073
621       if otherUserOrders = True then
622             begin
623               othercshdradded := false;
624               otherhdradded := false;
625               for ChgIndex := 0 to Orders.Count - 1 do
626                begin
627                   ChangeItem := Orders[ChgIndex];
628                   if (ChangeItem.GroupName = 'Other Unsigned') and ((ChangeItem.User >0) and (ChangeItem.User <> User.DUZ)) then
629                     begin
630   
631                       if ((ChangeItem.CSValue = False) or ChangeItem.DCOrder or IsPendingHold(ChangeItem.ID)) then
632                       begin
633                         if not otherhdradded then
634                         begin
635                           otherhdradded := true;
636                           if displaySpacer = True then AddHeader('   ');
637                           AddHeader('Others'' Unsigned Orders Orders - All Sessions');
638                         end;         
639                         lbIdx := AddItem(ChangeItem);
640                         SigItems.Add(CH_ORD, ChangeItem.ID, lbIdx);
641   //                      if (ChangeItem.OrderDG = 'Non-VA Meds') or (Pos('Non-VA',ChangeItem.Text)>0) then NVAinNonCSList := true
642   //                      else otherinNonCSList := true;
643                       end
644                       else
645                       begin
646                         if not(GetPKIUse) or not(GetPKISite) or (DEACheckFailedAtSignature(GetOrderableIen(Piece(ChangeItem.ID,';',1)),False)='1') then ChangeItem.SignState := CH_SIGN_NA;
647                         if not othercshdradded then
648                         begin
649                           othercshdradded := true;
650                           if displayCSSpacer = True then AddCSHeader('   ');
651                           AddCSHeader('Others'' Unsigned Orders - All Sessions');
652                         end;
653                         lbIdx := AddCSItem(ChangeItem);
654                         SigItemsCS.Add(CH_ORD, ChangeItem.ID, lbIdx);
655                       end;
656                     end;
657               end;
658           end;
659       OrderGrp.Sorted := false;
660     end; {if Orders}
661       // determine the appropriate panel to display
662       case User.OrderRole of
663           OR_CLERK: FShowPanel := SP_CLERK;
664           OR_NURSE: FShowPanel := SP_NURSE;
665       OR_PHYSICIAN: FShowPanel := SP_SIGN;
666         OR_STUDENT: if Changes.CanSign then FShowPanel := SP_SIGN else FShowPanel := SP_NONE;
667       else          FShowPanel := SP_NONE;
668       end; {case User}
669     end
670     else
671       FShowPanel := SP_SIGN;
672   
673     case FShowPanel of
674     SP_CLERK: begin
675                 pnlSignature.Visible := False;
676                 pnlOrderAction.Visible := SignRequiredForAny(FullList);
677               end;
678     SP_NURSE: begin
679                 pnlSignature.Visible := False;
680                 radRelease.Visible := True;
681                 grpRelease.Visible := True;
682                 pnlOrderAction.Visible := SignRequiredForAny(FullList);
683               end;
684      SP_SIGN: begin
685                 pnlOrderAction.Visible := False;
686                 pnlSignature.Visible := ItemsAreChecked;
687               end;
688     else      begin                                // SP_NONE
689                 pnlOrderAction.Visible := False;
690                 pnlSignature.Visible := False;
691               end;
692     end; {case FShowPanel}
693     pnlSignature.Visible := AnyItemsAreChecked;
694     
695   
696     txtESCodeChange(Self);
697     if pnlOrderAction.Visible then
698     begin
699   //    lblSig.Caption := 'Documents / Orders';
700       if FShowPanel = SP_NURSE then
701       begin
702         if GetUserParam('OR SIGNATURE DEFAULT ACTION') = 'OC'
703           then radHoldSign.Checked  := True
704           else radRelease.Checked   := True;
705       end;
706       if (radHoldSign.Checked) and (GetUserParam('OR SIGNED ON CHART') = '1')
707         then radSignChart.Checked := True;
708       if radRelease.Checked then radReleaseClick(Self);
709     end {if pnlOrderAction}
710     else
711     begin
712   //    if (User.OrderRole = OR_STUDENT) or (User.OrderRole = OR_NOKEY) or (User.OrderRole = OR_BADKEYS) then
713   //    begin
714   //      if otherinNonCSList then lblSig.Caption := 'These Non-Controlled Substance orders will be held until signed. '
715   //      else lblSig.Caption := ' ';
716   //      if NVAinNonCSList then lblSig.Caption := lblSig.Caption + 'Non-VA documentation will become active.';
717   //
718   //      lblCSReview.Caption := 'These Controlled Substance orders will be held until signed';
719   //    end
720   //    else
721   //    begin
722   //      lblSig.Caption := 'All Orders Except Controlled Substance EPCS Orders';
723   //    end;
724   
725     end;
726     //Make sure there is enough width for the buttons and lblSig
727      //begin BillingAware
728     if  BILLING_AWARE then
729     begin
730        LabelHeight := lstReview.Top - fraCoPay.Height;
731        AdjustSignatureTop( ResizeHeight( BaseFont, MainFont, LabelHeight) - LabelHeight);
732     end;
733      //end BillingAware
734   
735   
736       if frmReview.lstCSReview.Count>0 then
737       begin
738         if not(GetPKISite) then
739         begin
740           ShowMsg('Digital Signing of Controlled Substances is currently disabled for your site. Controlled Substance Orders will not be signed.');
741   //          frmReview.lstCSReview.Clear;
742   //          SigItemsCS.ResetOrders;
743         end
744         else if not(GetPKIUse ) then
745         begin
746           ShowMsg('You are not currently permitted to digitally sign Controlled Substances. Controlled Substance Orders will not be signed.');
747   //          frmReview.lstCSReview.Clear;
748   //          SigItemsCS.ResetOrders;
749         end;
750       end;
751   
752   
753      SigItems.ClearDrawItems;
754      SigItems.ClearFcb;
755      SigItemsCS.ClearDrawItems;
756      SigItemsCS.ClearFcb;
757      t1 := SigItems.UpdateListBox(lstReview);
758      t2 := SigItemsCS.UpdateListBox(lstCSReview);
759   
760     if (FullList and (t1 or t2)) then
761     begin
762       fraCoPay.Visible := TRUE;
763       if  BILLING_AWARE then frmReview.gbxDxLookup.Visible := TRUE;
764     end
765     else
766     begin
767       fraCoPay.Visible := FALSE;
768       if  BILLING_AWARE then frmReview.gbxDxLookup.Visible := FALSE;
769     end;
770   
771     if lstReview.Count > 0 then begin
772      for I := 1 to lstReview.Count - 1 do begin
773       lstReviewMeasureItem(lstReview, I, ColHeight);
774       lstReview.Perform(LB_SETITEMHEIGHT,I,ColHeight);
775      end;
776     end;
777     RedrawWindow(lstReview.Handle, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
778     if frmReview.pnlSignature.Visible and frmReview.txtESCode.Visible then  frmReview.ActiveControl := frmReview.txtESCode;
779   end; {BuildFullList}
780   
781   
782   procedure TfrmReview.BuildFullList;
783   begin
784        BuildList(TRUE);
785   end;
786   
787   procedure TfrmReview.BuildSignList;
788   begin
789      BuildList(FALSE);
790   end;
791   
792   procedure TfrmReview.PlaceComponents;
793   var
794     ShrinkHeight,oheight,newheight: Integer;
795   begin
796       with frmReview do
797       begin
798         pnlDeaText.Visible := TRUE;
799         if ((lstReview.Count = 0) and (lstCSReview.Count = 0)) then  Exit;
800         pnlProvInfo.Height := lblProvInfo.Height+5+lblProvInfo.Top;
801   
802         if lstCSReview.Count = 0 then
803         begin     
804           oheight := pnlReview.height;
805           pnlProvInfo.Visible := False;  
806           if fraCoPay.Visible = FALSE then
807           begin
808             pnlTop.Visible := False;
809           end;
810           pnlDEAText.Visible := False;   
811           pnlCSReview.Visible := False;
812           pnlReview.Align := alClient;
813           newheight := Height - pnlReview.height + oheight;
814           if newheight < Constraints.MinHeight then Constraints.MinHeight := newheight;
815           Height := newheight;
816         end
817         else if lstReview.Count = 0 then
818         begin
819           oheight := pnlCSReview.height;
820           pnlReview.Visible := False;
821           pnlCSReview.Align := alClient;
822           newheight := Height - pnlCSReview.height + oheight;  
823           if newheight < Constraints.MinHeight then Constraints.MinHeight := newheight;
824           Height := newheight;
825         end
826         else if fraCoPay.Visible = FALSE then
827         begin
828           fraCoPay.Visible := TRUE;
829           ShrinkHeight := fraCoPay.Height - pnlProvInfo.Height;
830           fraCoPay.Visible := FALSE;
831   
832   		    pnlTop.Height := pnlTop.Height - ShrinkHeight;
833           pnlCombined.Top := pnlCombined.Top - ShrinkHeight; 
834   		    pnlCombined.Height := pnlCombined.Height + ShrinkHeight;
835   
836         end;
837         
838   
839   
840         lblDEAText.Visible := FALSE;
841         lblSmartCardNeeded.Visible := FALSE;
842         if AnyItemsAreChecked then pnlsignature.visible := IsSignatureRequired;
843       end;
844   
845   end;
846   
847   function TfrmReview.ItemsAreChecked: Boolean;
848   { return true if any items in the Review List are checked for applying signature }
849   var
850     i: Integer;
851   begin
852     Result := False;
853     with lstReview do for i := 0 to Items.Count - 1 do if Checked[i] then
854     begin
855       Result := True;
856       break;
857     end;
858   end;
859   
860   function TfrmReview.CSItemsAreChecked: Boolean;
861   { return true if any items in the CS Review List are checked for applying signature }
862   var
863     i: Integer;
864   begin
865     Result := False;
866     with lstCSReview do for i := 0 to Items.Count - 1 do if Checked[i] then
867     begin
868       Result := True;
869       break;
870     end;
871   end;
872   
873   function TfrmReview.nonDCCSItemsAreChecked: Boolean;
874   { return true if any items in the CS Review List are checked for applying signature }
875   var
876     i: Integer;
877   begin
878     Result := False;
879     with lstCSReview do for i := 0 to Items.Count - 1 do if Checked[i] and not(TChangeItem(Items.Objects[i])=nil) then
880     begin
881       if not(TChangeItem(Items.Objects[i]).DCOrder) then
882       begin
883         Result := True;
884         break;
885       end;
886     end;
887   end;
888   
889   function TfrmReview.AnyItemsAreChecked: Boolean;
890   begin
891     Result := ItemsAreChecked or CSItemsAreChecked;
892   end;
893   
894   function TfrmReview.SignRequiredForAny(FullList: boolean): Boolean;
895   var
896     i: Integer;
897     tmpOrders: TStringList;
898     ChangeItem: TChangeItem;
899   begin
900     Result := True;
901     if Changes.Documents.Count > 0 then Exit;
902     if(FullList) then
903     begin
904       tmpOrders := TStringList.Create;
905       try
906         for i := 0 to Pred(Changes.Orders.Count) do
907         begin
908           ChangeItem := Changes.Orders[i];
909           tmpOrders.Add(ChangeItem.ID);
910         end;
911         Result := AnyOrdersRequireSignature(tmpOrders);
912       finally
913         FreeAndNil(tmpOrders);
914       end;
915     end
916     else
917       Result := FALSE;
918   end;
919   
920   procedure TfrmReview.lstReviewClickCheck(Sender: TObject);
921   { prevent grayed checkboxes from being changed to anything else }
922   var
923     ChangeItem: TChangeItem;
924   
925     procedure updateAllChilds(CheckedStatus: boolean; ParentOrderId: string);
926     var
927       idx: integer;
928       AChangeItem: TChangeItem;
929     begin
930       for idx := 0 to lstReview.Items.Count - 1 do
931       begin
932         AChangeItem := TChangeItem(lstReview.Items.Objects[idx]);
933         if Assigned(AChangeItem) and (AChangeItem.ParentID = ParentOrderId) then
934             if lstReview.Checked[idx] <> CheckedStatus then
935             begin
936               lstReview.Checked[idx] := CheckedStatus;
937               SigItems.EnableSettings(idx, lstReview.checked[Idx]);
938             end;
939       end;
940     end;
941   
942   begin
943     with lstReview do
944     begin
945       ChangeItem := TChangeItem(Items.Objects[ItemIndex]);
946       if ItemIndex > 0 then
947       begin
948          if (ChangeItem <> nil) then
949          begin
950            if (ChangeItem.SignState = CH_SIGN_NA) then State[ItemIndex] := cbGrayed
951            else
952            begin
953              SigItems.EnableSettings(ItemIndex, checked[ItemIndex]);
954              if Length(ChangeItem.ParentID) > 0 then
955                updateAllChilds(checked[ItemIndex], ChangeItem.ParentID);
956            end;
957          end;
958        end;
959        pnlSignature.Visible := IsSignatureRequired;
960     end;
961     if pnlSignature.Visible then txtESCode.SetFocus;
962   
963   end;
964   
965   procedure TfrmReview.lstReviewDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
966   { outdent the header items (thus hiding the checkbox) }
967   var
968     x: string;
969     ARect, TextRecord: TRect;
970     i, dy: integer;
971     tempID: string;
972     thisRec: UBAGlobals.TBADxRecord;
973   
974   {Begin BillingAware}
975     str: string;
976   {End BillingAware}
977   
978     procedure UpdateTextRecord(r: TRect);
979     begin
980       TextRecord := r;
981       inc(TextRecord.Top, dy);
982       dec(TextRecord.Bottom, dy);
983     end;
984   
985   begin
986     inherited;
987     dy := SIG_ITEM_VERTICAL_PAD div 2;
988     x := '';
989     ARect := Rect;
990   
991     if  BILLING_AWARE then
992     begin
993        ARect.Right := ARect.Right - 50;
994   
995     with lstReview do
996     begin
997       if Items.Objects[Index] = nil then
998           ARect.Left := 0;
999       Canvas.Pen.Color := Get508CompliantColor(clSilver);
1000      Canvas.FillRect(ARect);
1001  
1002      if Index < Items.Count then
1003        begin
1004         x := Trim(FilteredString(Items[Index]));
1005  
1006         if (ARect.Left = 0) and ( Length(x)>0 ) then
1007           Canvas.TextOut(ARect.Left + 2, ARect.Top + dy, x)
1008         else
1009            if (ARect.Left > 0 ) and ( Length(x)>0 ) then
1010               begin
1011               //ARect.Right below controls the right-hand side of the Dx Column
1012               //Adjust ARect.Right in conjunction with procedure uSignItems.TSigItems.lbDrawItem(), because the
1013               //two rectangles overlap each other.
1014  
1015               if  BILLING_AWARE then
1016                  begin
1017                  arRect[Index] := Classes.Rect(ARect.Right+2, ARect.Top, ARect.Right + 108, ARect.Bottom);
1018                  Canvas.FillRect(arRect[Index]);
1019                  end;
1020  
1021               //Draw ORDER TEXT
1022              UpdateTextRecord(ARect);
1023              DrawText(Canvas.handle, PChar(x), Length(x), TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
1024  
1025             if  BILLING_AWARE then
1026                  begin
1027                       //Dx Column lines
1028                       Canvas.Pen.Color := Get508CompliantColor(clSilver);
1029                       Canvas.MoveTo(DxRect.Left-1, ARect.Top);
1030                       Canvas.LineTo(DxRect.Left-1, ARect.Bottom);
1031                       //Adjust position of 'Diagnosis' column label for font size
1032                       laDiagnosis.Left := DxRect.Left + 14;
1033                       if uSignItems.GetAllBtnLeftPos > 0 then
1034                          laDiagnosis.left := uSignItems.GetAllBtnLeftPos - (laDiagnosis.Width +5);
1035                       laDiagnosis.Top := lblSig.Top;
1036                       //Assign DxRect for drawing Dx column and Dx string
1037                       DxRect.Left := ARect.Right + 1;
1038                       DxRect.Top := ARect.Top;
1039                       DxRect.Right := DxRect.Left + 80;
1040                       DxRect.Bottom := ARect.Bottom;
1041  
1042                      //Display all saved Dx's
1043                        for i := 0 to lstReview.Items.Count-1 do
1044                          with TOrder(lstReview.Items[i]) do
1045                            begin
1046                             // HDS00005025
1047                            if TChangeItem(lstReview.Items.Objects[Index]).ITEMTYPE = CH_DOC then
1048                               tempID := '0' // if document id is equal to valid order id identify billable orders
1049                            else
1050                               tempID := TChangeItem(lstReview.Items.Objects[Index]).ID;
1051                              // HDS00005025
1052                             //WORKS FOR MULTIPLE Dx
1053                             if Assigned(UBAGlobals.tempDxList) then
1054                               if UBAGlobals.tempDxNodeExists(tempID) then
1055                                   begin
1056                                      thisRec := TBADxRecord.Create;
1057                                      UBAGlobals.GetBADxListForOrder(thisRec, tempID);
1058                                      str := Piece(thisRec.FBADxCode, '^', 1); // Display Dx text only - not the ICD-9 code
1059                                      str := Piece(str, ':', 1);   //in case has : vs. ^
1060                                      UpdateTextRecord(arRect[Index]);
1061                                      DrawText(Canvas.handle, PChar(str), Length(str), TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
1062  
1063                                      if (Not UBACore.IsOrderBillable(tempID)) then
1064                                      begin
1065                                         Canvas.Font.Color := Get508CompliantColor(clBlue);
1066                                         UpdateTextRecord(arRect[Index]);
1067                                         DrawText(Canvas.handle, PChar(NOT_APPLICABLE), Length(NOT_APPLICABLE) , TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
1068                                      end;
1069                                   end
1070                                else
1071                                   begin
1072                                   //Determine if order is billable. If NOT billable then insert NA in Dx field
1073                                      if Not UBACore.IsOrderBillable(tempID) then
1074                                      begin
1075                                          Canvas.Font.Color := Get508CompliantColor(clBlue);
1076                                          UpdateTextRecord(arRect[Index]);
1077                                          DrawText(Canvas.handle, PChar(NOT_APPLICABLE), Length(NOT_APPLICABLE) , TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
1078                                      end;
1079                                   end;
1080                            end;
1081                      end;
1082          end; //if
1083        end; //if
1084    end; //with
1085   end
1086   else
1087      begin
1088         with lstReview do
1089            begin
1090            if Items.Objects[Index] = nil then
1091                ARect.Left := 0;
1092  
1093            Canvas.FillRect(ARect);
1094  
1095            if Index < Items.Count then
1096               begin
1097                  x := Trim(FilteredString(Items[Index]));
1098  
1099               if (ARect.Left = 0) and ( Length(x) > 0 ) then
1100                  Canvas.TextOut(ARect.Left + 2, ARect.Top + dy, x)
1101               else
1102                  if (ARect.Left > 0 ) and ( Length(x)>0 ) then
1103                     begin
1104                       Canvas.Pen.Color := Get508CompliantColor(clSilver);
1105                       Canvas.MoveTo(0, ARect.Bottom-1);
1106                       Canvas.LineTo(ARect.Right, ARect.Bottom-1);
1107                       UpdateTextRecord(ARect);
1108                       DrawText(Canvas.handle, PChar(x), Length(x), TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
1109                     end;
1110               end;
1111         end;
1112      end;
1113  end;
1114  
1115  procedure TfrmReview.radReleaseClick(Sender: TObject);
1116  begin
1117    if not grpRelease.Visible then Exit;
1118    if radHoldSign.Checked then lblHoldSign.Visible := True
1119    else lblHoldSign.Visible := False;
1120    if radRelease.Checked then
1121    begin
1122      radVerbal.Enabled := True;
1123      radPhone.Enabled  := True;
1124      radPolicy.Enabled := True;
1125      if Encounter.Provider = User.DUZ
1126        then radPolicy.Checked := True
1127        else radVerbal.Checked := True;
1128    end else
1129    begin
1130      radVerbal.Enabled := False;
1131      radPhone.Enabled  := False;
1132      radPolicy.Enabled := False;
1133      radVerbal.Checked := False;
1134      radPhone.Checked  := False;
1135      radPolicy.Checked := False;
1136    end;
1137  end;
1138  
1139  procedure TfrmReview.txtESCodeChange(Sender: TObject);
1140  begin
1141    if(not pnlSignature.Visible) then
1142    begin
1143      if (FCouldSign and not AnyItemsAreChecked) then cmdOK.Caption := 'Don''t Sign'
1144      else cmdOK.Caption := 'OK'
1145    end
1146    else
1147    begin
1148      if Length(txtESCode.Text) > 0 then cmdOK.Caption := 'Sign' else
1149      begin
1150        if FCouldSign then cmdOK.Caption := 'Don''t Sign' else cmdOK.Caption := 'OK';
1151      end;
1152    end;
1153  end;
1154  
1155  procedure TfrmReview.cmdOKClick(Sender: TObject);
1156  { validate the electronic signature & call SaveSignItem for the encounter }
1157  const
1158    TX_NOSIGN  = 'Save items without signing?';
1159    TC_NOSIGN  = 'No Signature Entered';
1160    TX_SAVERR1 = 'The error, ';
1161    TX_SAVERR2 = ', occurred while trying to save:' + CRLF + CRLF;
1162    TC_SAVERR  = 'Error Saving Order';
1163  var
1164    i, k, idx, AType, PrintLoc, theSts, wardIEN, checki,checkj: Integer;
1165    SigSts, RelSts, Nature: Char;
1166    ESCode, AnID, AnErrMsg: string;
1167    ChangeItem, TempChangeItem: TChangeItem;
1168    OrderList, CSOrderList, TotalOrderList, OrderPrintList: TStringList;
1169    SaveCoPay, PINRetrieved: boolean;
1170    DigSigErr, DigStoreErr, CryptoChecked, displayEncSwitch, DelayOnly: Boolean;
1171    SigData, SigUser, SigDrugSch, SigDEA: string;
1172    cSignature, cHashData, cCrlUrl, cErr, WardName, ASvc: string;
1173    UsrAltName, IssuanceDate, PatientName, PatientAddress, DetoxNumber, ProviderName, ProviderAddress: string;
1174    DrugName, Quantity, Directions: string;
1175    cProvDUZ: Int64;
1176    AList, ClinicList, WardList: TStringList;
1177    IsOk, ContainsIMOOrders, DoNotPrint, checkfound : Boolean;
1178    EncLocName, EncLocText, tempInpLoc: string;
1179    EncLocIEN: integer;
1180    EncDT: TFMDateTime;
1181    EncVC: Char;  
1182    PINResult : TPINResult;
1183    PINLock : string;
1184  
1185    function OrdersSignedOrReleased: Boolean;
1186    var
1187      i: Integer;
1188    begin
1189      Result := False;
1190      for i := 0 to Pred(OrderList.Count) do
1191      begin
1192        if Pos('R', Piece(OrderList[i], U, 2)) > 0 then Result := True;
1193        if Pos('S', Piece(OrderList[i], U, 2)) > 0 then Result := True;
1194        if Result then Break;
1195      end;
1196    end;
1197  
1198    function OrdersToBeSignedOrReleased: Boolean;
1199    var
1200      i: Integer;
1201      s,x: string;
1202    begin
1203      Result := FALSE;
1204  
1205      for i := 0 to Pred(OrderList.Count) do
1206      begin
1207        s := Piece(OrderList[i], U, 2);
1208        x := s[1];
1209        if ((s <> '') and (s[1] in [SS_ONCHART, SS_ESIGNED, SS_NOTREQD])) or
1210           (Piece(OrderList[i], U, 3) = RS_RELEASE) then
1211        begin
1212           Result := TRUE;
1213           Break;
1214        end;
1215      end;
1216  
1217      for i := 0 to Pred(csOrderList.Count) do
1218      begin
1219        s := Piece(CSOrderList[i], U, 2);
1220        x := s[1];
1221        if ((s <> '') and (s[1] in [SS_ONCHART, SS_ESIGNED, SS_NOTREQD])) or
1222           (Piece(CSOrderList[i], U, 3) = RS_RELEASE) then
1223        begin
1224           Result := TRUE;
1225           Break;
1226        end;
1227      end;
1228    end; 
1229  
1230    function Piece2end (s,del: string): string;
1231    var
1232      i: Integer;
1233    begin
1234      i := Pos(del,s);
1235      Result := copy(s,i+1,length(s));
1236    end;
1237  
1238    procedure Log2File(  crypto: tCryptography) ;
1239    var
1240      f: TextFile;
1241    begin
1242      AssignFile(f,'c:\hashLog.txt');
1243      if not(FileExists('c:\hashLog.txt')) then
1244      begin
1245        ReWrite(f) ;
1246        Write(f,'cprs 29 hash log' + CRLF + CRLF);
1247        CloseFile(f);
1248      end;
1249  
1250      Append(f);
1251      WriteLn(f, '==============' + crypto.OrderNumber + CRLF +
1252                        'IssuanceDate: "' + crypto.IssuanceDate + '"' + CRLF +
1253                        'DrugName: "' + crypto.DrugName + '"' + CRLF +
1254                        'Quantity: "' + crypto.Quantity + '"' + CRLF +
1255                        'Directions: "' + crypto.Directions + '"' + CRLF +
1256                        'DetoxNumber: "' + crypto.DetoxNumber + '"' + CRLF +
1257                        'DeaNumber: "' + crypto.DeaNumber + '"' + CRLF +
1258                        'OrderNumber: "' + crypto.OrderNumber + '"' + CRLF +
1259                        CRLF);
1260      CloseFile(f);
1261    end;
1262  
1263  begin
1264    IsOk := True;
1265    ESCode := '';
1266    SaveCoPay := FALSE;
1267    PrintLoc := 0;
1268    EncLocIEN := 0;
1269    DoNotPrint := False;
1270    tempInpLoc := '';
1271    DelayOnly := false;
1272    if BILLING_AWARE then
1273    begin
1274       if Assigned(UBAGlobals.UnsignedOrders) then
1275          UBAGlobals.UnsignedOrders.Clear;
1276    end;
1277    if pnlSignature.Visible then
1278    begin
1279      ESCode := txtESCode.Text;
1280  
1281      if AnyItemsAreChecked and (Length(ESCode) > 0) and (not ValidESCode(ESCode)) then
1282      begin
1283        InfoBox(TX_INVAL_MSG, TX_INVAL_CAP, MB_OK);
1284        frmReview.ActiveControl := frmReview.txtESCode;
1285        txtESCode.SelectAll;
1286        Exit;
1287      end;
1288      if Length(ESCode) > 0 then ESCode := Encrypt(ESCode);
1289    end; {if pnlSignature}
1290  
1291    if not frmFrame.Closing then
1292    begin
1293      { save/sign orders }
1294      OrderList := TStringList.Create;
1295      CSOrderList := TStringList.Create;
1296      TotalOrderList := TStringList.Create;
1297      OrderPrintList := TStringList.create;
1298      ClinicList := TStringList.Create;
1299      WardList := TStringList.Create;
1300      ContainsIMOOrders := False;
1301      try
1302        Nature := NO_PROVIDER;
1303        case User.OrderRole of
1304        OR_NOKEY, OR_CLERK, OR_NURSE, OR_STUDENT:
1305          begin
1306            SigSts := SS_UNSIGNED;                   // default to med student values
1307            RelSts := RS_HOLD;
1308            Nature := NO_WRITTEN;
1309            if User.OrderRole in [OR_CLERK, OR_NURSE] then
1310            begin
1311              if radSignChart.Checked then SigSts := SS_ONCHART else SigSts := SS_UNSIGNED;
1312              if radRelease.Checked or radSignChart.Checked
1313                then RelSts := RS_RELEASE
1314                else RelSts := RS_HOLD;
1315              if radSignChart.Checked or radHoldSign.Checked then Nature := NO_WRITTEN
1316              else if radVerbal.Checked then Nature := NO_VERBAL
1317              else if radPhone.Checked  then Nature := NO_PHONE
1318              else if radPolicy.Checked then Nature := NO_POLICY
1319              else Nature := NO_WRITTEN;
1320              if not pnlOrderAction.Visible then     // if no orders require a signature
1321              begin
1322                RelSts := RS_RELEASE;
1323                Nature := NO_PROVIDER;
1324                SigSts := SS_NOTREQD;
1325              end;
1326              // the following was added due to patch OR*3.0*86
1327              if RelSts = RS_RELEASE then
1328              begin
1329                StatusText('Validating Release...');
1330                AnErrMsg := '';
1331                for i := 0 to lstReview.Items.Count - 1 do
1332                begin
1333                  ChangeItem := TChangeItem(lstReview.Items.Objects[i]);
1334                  if (ChangeItem <> nil) and (ChangeItem.ItemType = CH_ORD) then
1335                  begin
1336                    ValidateOrderActionNature(ChangeItem.ID, OA_RELEASE, Nature, AnErrMsg);
1337                    if Length(AnErrMsg) > 0 then
1338                    begin
1339                      if IsInvalidActionWarning(ChangeItem.Text, ChangeItem.ID) then Break;
1340                      InfoBox(ChangeItem.Text + TX_NO_REL + AnErrMsg, TC_NO_REL, MB_OK);
1341                      Break;
1342                    end; {if Length(AnErrMsg)}
1343                  end; {if ChangeItem=CH_ORD}
1344                end; {for}
1345                StatusText('');
1346                if Length(AnErrMsg) > 0 then Exit;
1347              end; {if RelSts}
1348              // the following supports the change to allow nurses to sign policy orders
1349              if FSilent then RelSts := RS_HOLD;
1350              if (RelSts = RS_RELEASE) and pnlOrderAction.Visible then
1351              begin
1352                SignatureForItem(Font.Size, TX_ES_REQ, TC_ES_REQ, ESCode);
1353                if ESCode = '' then Exit;
1354                if Nature = NO_POLICY then SigSts := SS_ESIGNED;
1355              end;
1356            end; {if..ORCLERK, OR_NURSE}
1357  
1358            with lstReview do for i := 0 to Items.Count - 1 do
1359            begin
1360              ChangeItem := TChangeItem(Items.Objects[i]);
1361              if (ChangeItem <> nil) and (ChangeItem.ItemType = CH_ORD) and (not radSignChart.Checked) then
1362              begin
1363                OrderList.Add(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature);
1364                if BILLING_AWARE then
1365                  if not (User.DUZ = 0) and PersonHasKey(User.DUZ, 'PROVIDER') then
1366                     UBACore.SaveUnsignedOrders(ChangeItem.ID+ '1' + GetCheckBoxStatus(ChangeItem.ID) )
1367              end
1368              else if (ChangeItem <> nil) and (ChangeItem.ItemType = CH_ORD) and (radSignChart.Checked) then
1369                OrderList.Add(ChangeItem.ID + U + SS_ONCHART + U + RS_RELEASE + U + NO_WRITTEN);
1370  
1371            end; {with lstReview}
1372  		  
1373  		 with lstCSReview do for i := 0 to Items.Count - 1 do
1374            begin
1375              ChangeItem := TChangeItem(Items.Objects[i]);
1376              if (ChangeItem <> nil) and (ChangeItem.ItemType = CH_ORD) then
1377              begin
1378                OrderList.Add(ChangeItem.ID + U + SS_UNSIGNED + U + RS_HOLD + U + Nature);
1379                if BILLING_AWARE then
1380                  if not (User.DUZ = 0) and PersonHasKey(User.DUZ, 'PROVIDER') then
1381                     UBACore.SaveUnsignedOrders(ChangeItem.ID+ '1' + GetCheckBoxStatus(ChangeItem.ID) )
1382              end
1383            end;     {with lstCSReview}
1384  
1385          end; {OR_NOKEY, OR_CLERK, OR_NURSE, OR_STUDENT}
1386  
1387        OR_PHYSICIAN:
1388          begin
1389            Nature := NO_PROVIDER;
1390            with lstReview do for i := 0 to Items.Count - 1 do
1391            begin
1392              ChangeItem := TChangeItem(Items.Objects[i]);
1393              if (ChangeItem <> nil) and (ChangeItem.ItemType = CH_ORD) then
1394                begin
1395                  case State[i] of
1396                  cbChecked:   if Length(ESCode) > 0 then
1397                               begin
1398                                 SigSts := SS_ESIGNED;
1399                                 RelSts := RS_RELEASE;
1400                                 OrderList.Add(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature);
1401                               end else
1402                               begin
1403                                 if BILLING_AWARE then
1404                                    UBACore.SaveUnsignedOrders(ChangeItem.ID+ '1' + GetCheckBoxStatus(ChangeItem.ID) );
1405                                 SigSts := SS_UNSIGNED;
1406                                 RelSts := RS_HOLD;
1407                               end;
1408                  cbGrayed:    if OrderRequiresSignature(ChangeItem.ID) then
1409                               begin
1410                                 SigSts := SS_UNSIGNED;
1411                                 RelSts := RS_HOLD;
1412                               end else
1413                               begin
1414                                 SigSts := SS_NOTREQD;
1415                                 RelSts := RS_RELEASE;
1416                               end;
1417                  else         begin                   // (cbUnchecked)
1418                                 SigSts := SS_UNSIGNED;
1419                                 RelSts := RS_HOLD;
1420                               end;
1421                  end; {case State}
1422  
1423                  if (ChangeItem.GroupName = 'Other Unsigned') and (SigSts = SS_UNSIGNED) and (RelSts = RS_HOLD)
1424                    then //NoOp - don't add unsigned orders from outside session to the list
1425                    else
1426                    begin
1427                      if not(State[i] = cbChecked) and (OrderList.IndexOf(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature) < 0) then
1428                        OrderList.Add(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature)
1429                      else if (cmdOK.Caption = 'Don''t Sign') and (OrderList.IndexOf(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature) < 0) then
1430                        OrderList.Add(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature);
1431                    end;
1432              end; {if ItemType}
1433            end; {with lstReview}
1434  
1435  
1436  
1437            with lstCSReview do for i := 0 to Items.Count - 1 do
1438            begin
1439              ChangeItem := TChangeItem(Items.Objects[i]);
1440              if (ChangeItem <> nil) and (ChangeItem.ItemType = CH_ORD) then
1441                begin
1442                  case State[i] of
1443                  cbChecked:   if Length(ESCode) > 0 then
1444                               begin
1445                                 SigSts := SS_ESIGNED;
1446                                 RelSts := RS_RELEASE;
1447                                 if ChangeItem.DCOrder then OrderList.Add(ChangeItem.ID + U + SS_ESIGNED + U + RelSts + U + Nature)
1448                                 else CSOrderList.Add(ChangeItem.ID + U + SS_DIGSIG + U + RelSts + U + Nature);
1449                               end else
1450                               begin
1451                                 if BILLING_AWARE then
1452                                    UBACore.SaveUnsignedOrders(ChangeItem.ID+ '1' + GetCheckBoxStatus(ChangeItem.ID) );
1453                                 SigSts := SS_UNSIGNED;
1454                                 RelSts := RS_HOLD;
1455                               end;
1456                  cbGrayed:    if OrderRequiresSignature(ChangeItem.ID) then
1457                               begin
1458                                 SigSts := SS_UNSIGNED;
1459                                 RelSts := RS_HOLD;
1460                               end else
1461                               begin
1462                                 SigSts := SS_NOTREQD;
1463                                 RelSts := RS_RELEASE;
1464                               end;
1465                  else         begin                   // (cbUnchecked)
1466                                 SigSts := SS_UNSIGNED;
1467                                 RelSts := RS_HOLD;
1468                               end;
1469                  end; {case State}
1470  
1471                  if (ChangeItem.GroupName = 'Other Unsigned') and (SigSts = SS_UNSIGNED) and (RelSts = RS_HOLD)
1472                    then //NoOp - don't add unsigned orders from outside session to the list
1473                  else
1474                    begin
1475                      if not(State[i] = cbChecked) and (OrderList.IndexOf(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature) < 0) then
1476                        OrderList.Add(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature)
1477                      else if (cmdOK.Caption = 'Don''t Sign') and (OrderList.IndexOf(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature) < 0) then
1478                        OrderList.Add(ChangeItem.ID + U + SigSts + U + RelSts + U + Nature);
1479                    end;
1480              end; {if ItemType}
1481            end; {with lstCSReview}
1482  
1483  //add csorderlist to totalorderlist in order to do order checking
1484  for i := 0 to CSOrderList.Count - 1 do
1485  begin
1486    TotalOrderList.add(CSOrderList.strings[i]);
1487  end;
1488  
1489  //add orderlist to totalorderlist in order to do order checking
1490  for i := 0 to OrderList.Count - 1 do
1491  begin
1492    TotalOrderList.add(OrderList.strings[i]);
1493  end;
1494  //do order checkign on totalorderlist.  Any order's cancelled will no longer be in totalorderlist
1495  While (TotalOrderList.Count > 0) do
1496  begin
1497    IsOk := ExecuteSessionOrderChecks(TotalOrderList);  // any cancelled orders will be removed from OrderList
1498    if IsOk then Break;
1499  end;
1500  //remove any orders from csorderlist that are no longer part of totalorderlist
1501  i := CSOrderList.Count - 1;
1502  while i>=0 do
1503  begin
1504    if (TotalOrderList.IndexOf(CSOrderList.strings[i])=-1) then CSOrderList.Delete(i);
1505    i := i - 1;
1506  end;
1507  
1508  //remove any orders from orderlist that are no longer part of totalorderlist   
1509  i := OrderList.Count - 1;
1510  while i>=0 do
1511  begin
1512    if (TotalOrderList.IndexOf(OrderList.strings[i])=-1) then OrderList.Delete(i);
1513    i := i - 1;
1514  end;
1515  
1516            if CSOrderList.Count > 0 then
1517            begin
1518            //check if sc boxes were answered here before dig signing process
1519            inherited;
1520            if not IsUserNurseProvider(User.DUZ) then
1521            begin
1522                 if (not SigItems.OK2SaveSettings) or (not SigItemsCS.OK2SaveSettings) then
1523                 begin
1524                   if (cmdOk.Caption = 'Don''t Sign') then
1525                      //
1526                   else
1527                   begin
1528                      InfoBox(TX_Order_Error, 'Review/Sign Orders', MB_OK);
1529                      Exit;
1530                   end
1531                 end;
1532            end;
1533            
1534            LastPINvalue := '';
1535            //isXuDSigSLogging := true;
1536            PINRetrieved := false;
1537            //get altusername
1538            UsrAltName := sCallV('XUS PKI GET UPN', []);
1539            //if SAN is blank then attempt to retrieve from card to set it
1540            if UsrAltName='' then
1541            begin
1542              UsrAltName := SetSAN(fReview.frmReview);
1543              if not(UsrAltName='')  then
1544              begin
1545                PINRetrieved := true;
1546              end;
1547            end;
1548            //if still blank then cancel digital signing
1549            if UsrAltName='' then PINResult := prCancel
1550            else if not(PINRetrieved) then
1551            try
1552            begin
1553              PINLock := sCallV('ORDEA PINLKCHK', []);
1554              if PINLock = '1' then PINResult := prLocked
1555              else PINResult := checkPINValue(fReview.frmReview);
1556            end
1557            except
1558             PINResult := prError;
1559            end;
1560  
1561            if PINResult = prError then ShowMsg('Problem getting PIN.  Cannot Digitally Sign.')
1562            else if PINResult=prLocked then
1563            begin
1564              if PINLock = '0' then sCallV('ORDEA PINLKSET', []);
1565              ShowMsg('Card has been locked.  Cannot Digitally Sign.')
1566            end
1567            else if PINResult=prCancel then ShowMsg('Digital Signing has been cancelled.')
1568            else
1569              begin
1570                try
1571                begin
1572                  crypto := tCryptography.Create;
1573                  //call rpc to get hash fields other than drug info
1574                  CallV('ORDEA HASHINFO', [Patient.DFN, User.DUZ]);
1575                  for i := 0 to RPCBrokerV.Results.Count -1 do
1576                  begin
1577                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'IssuanceDate' then IssuanceDate := Piece2end(RPCBrokerV.Results.Strings[i],':');
1578                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'PatientName' then PatientName := Piece2end(RPCBrokerV.Results.Strings[i],':');
1579                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'PatientAddress' then PatientAddress := Piece2end(RPCBrokerV.Results.Strings[i],':');
1580                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'DetoxNumber' then DetoxNumber := Piece2end(RPCBrokerV.Results.Strings[i],':');
1581                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'ProviderName' then ProviderName := Piece2end(RPCBrokerV.Results.Strings[i],':');
1582                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'ProviderAddress' then ProviderAddress := Piece2end(RPCBrokerV.Results.Strings[i],':');
1583                    if Piece(RPCBrokerV.Results.Strings[i],':',1) = 'DeaNumber' then SigDEA := Piece2end(RPCBrokerV.Results.Strings[i],':');
1584                  end;
1585                  for i := 0 to CSOrderList.Count - 1 do
1586                  begin
1587                    CallV('ORDEA ORDHINFO', [Piece(Piece(CSOrderList.strings[i],U,1),';',1)]);
1588                    DrugName := '';
1589                    Quantity := '';
1590                    Directions := '';
1591                    for k := 0 to RPCBrokerV.Results.Count -1 do
1592                    begin
1593                      if Piece(RPCBrokerV.Results.Strings[k],':',1) = 'DrugName' then DrugName := Piece2end(RPCBrokerV.Results.Strings[k],':');
1594                      if Piece(RPCBrokerV.Results.Strings[k],':',1) = 'Quantity' then Quantity := Piece2end(RPCBrokerV.Results.Strings[k],':');
1595                      if Piece(RPCBrokerV.Results.Strings[k],':',1) = 'Directions' then Directions := Piece(Piece2end(RPCBrokerV.Results.Strings[k],':'),U,1);
1596                    end;
1597                    try
1598                      crypto.Reset;
1599                      crypto.isDEAsig := true;
1600                      crypto.UsrName := User.Name;
1601                      crypto.UsrAltName := UsrAltName;
1602                      crypto.IssuanceDate :=  IssuanceDate;
1603                      crypto.PatientName :=   PatientName;
1604                      crypto.PatientAddress :=  PatientAddress;
1605                      crypto.DrugName :=     DrugName;
1606                      crypto.Quantity :=   Quantity;
1607                      crypto.Directions :=  Directions;
1608                      crypto.DetoxNumber :=  ''; //DetoxNumber;  don't include detox in hash calc
1609                      crypto.ProviderName :=  ProviderName;
1610                      crypto.ProviderAddress :=  ProviderAddress;
1611                      crypto.DeaNumber :=      SigDEA;
1612                      crypto.OrderNumber :=   Piece(Piece(CSOrderList.strings[i],U,1),';',1);
1613  
1614                      if false then Log2File(crypto);
1615                      
1616  
1617                      if crypto.SignData = true then
1618                      begin
1619                        cSignature := crypto.SignatureStr;
1620                        cHashData := crypto.HashStr;
1621                        cCrlUrl := crypto.CrlUrl;
1622                      end
1623                      else
1624                      begin
1625                        ShowMsg('Could not digitally sign. An error has occurred: Hash generation failed'+CRLF+CRLF+crypto.Reason);
1626                      DigStoreErr := true;
1627                      end;
1628  
1629                    except
1630                      on  E: Exception do
1631                        begin
1632                          ShowMsg('Could not digitally sign. An error has occurred: '+ E.Message);
1633                          DigStoreErr := true;
1634                        end;
1635                    end;
1636  
1637                    if DigStoreErr then
1638                      //messages shown above
1639                    else
1640                    begin
1641                      cErr := '';
1642                      StoreDigitalSig(Piece(CSOrderList.Strings[i],U,1), cHashData, User.DUZ, cSignature, cCrlUrl, Patient.DFN, cErr);
1643                      if cErr = '' then
1644                      begin
1645                        UpdateOrderDGIfNeeded(Piece(CSOrderList.Strings[i],U,1));
1646                        OrderList.Add(CSOrderList.Strings[i]);
1647                        BAOrderList.Add(Piece(CSOrderList.Strings[i],U,1));
1648                      end;
1649                    end;
1650                  end;
1651                end;
1652                finally
1653                  if not(crypto=nil) then
1654                  begin
1655                    crypto.Free;
1656                    crypto := nil;
1657                  end;
1658                end;
1659              end;
1660            end;
1661          end; {OR_PHYSICIAN}
1662        end; {case User.OrderRole}
1663        if BILLING_AWARE then
1664           if UBAGlobals.UnsignedOrders.Count > 0 then
1665             UBACore.BuildSaveUnsignedList(UBAGlobals.UnsignedOrders);
1666  
1667            // if true BA data in not mandatory.
1668            if not IsUserNurseProvider(User.DUZ) then
1669            begin
1670               if OrdersToBeSignedOrReleased then
1671               begin
1672                 if (not SigItems.OK2SaveSettings) or (not SigItemsCS.OK2SaveSettings) then
1673                 begin
1674                   if (cmdOk.Caption = 'Don''t Sign') then
1675                      SaveCoPay := TRUE
1676                   else
1677                   begin
1678                      InfoBox(TX_Order_Error, 'Review/Sign Orders', MB_OK);
1679                      Exit;
1680                   end
1681                 end
1682                 else
1683                   SaveCoPay := TRUE;
1684              end
1685              else
1686                 SaveCoPay := TRUE;
1687  
1688             {Begin BillingAware}
1689              if  BILLING_AWARE then
1690              begin
1691                if (cmdOk.Caption = 'Sign') then
1692                  begin
1693                    if Not UBACore.BADxEntered then
1694                    begin
1695                       InfoBox(TX_NO_DX, TC_NO_DX, MB_OK);
1696                       Exit;
1697                    end;
1698                  end;
1699                {End BillingAware}
1700               end;
1701            end;
1702  
1703        // make sure all cs orders are in the orderlist.  if not add them as usnigned/hold
1704        for checki := 0 to CSOrderList.Count -1 do
1705        begin
1706          checkfound := false;
1707          for checkj := 0 to OrderList.Count - 1 do
1708          begin
1709            if Piece(OrderList[checkj],U,1) = Piece(CSOrderList[checki],U,1) then checkfound := true;
1710          end;
1711          if not(checkfound) then OrderList.Add(Piece(CSOrderList[checki],U,1) + U + SS_UNSIGNED + U + RS_HOLD + U + Piece(CSOrderList[checki],U,4));
1712        end;
1713  
1714  
1715        {release & print orders}
1716        // test for LockedForOrdering is to make sure patient is locked if pulling in all unsigned
1717        if (User.OrderRole in [OR_NOKEY..OR_STUDENT]) and (OrderList.Count > 0)and LockedForOrdering then
1718        begin
1719          StatusText('Sending Orders to Service(s)...');
1720          if (OrderList.Count > 0) then
1721          begin
1722          //hds7591  Clinic/Ward movement.  Nurse orders
1723            if (cmdOk.Caption = 'Sign') or (cmdOK.Caption = 'OK') and (not frmFrame.TimedOut) then
1724            begin
1725               tempInpLoc := frmPrintLocation.rpcIsPatientOnWard(patient.dfn);
1726               if ((Patient.Inpatient = false) and (tempInpLoc <> '')) or
1727                   ((Patient.Inpatient = True) and (Encounter.Location <> Patient.Location)) or
1728                   ((Patient.Inpatient = True) and (Encounter.Location = Patient.Location) and
1729                   (encounter.Location <> uCore.TempEncounterLoc) and (uCore.TempEncounterLoc <> 0))
1730                   or((Patient.Inpatient) and (tempInpLoc <> '') and (Piece(tempInpLoc, U, 2) <> InttoStr(Encounter.location))) then
1731               begin
1732                   if (Encounter.Location <> Patient.Location) or
1733                       ((tempInpLoc <> '') and ((InttoStr(Encounter.location)) <> (Piece(tempInpLoc,U,2)))) then
1734                     begin
1735                       EncLocName := Encounter.LocationName;
1736                       EncLocIEN  := Encounter.Location;
1737                       EncLocText := Encounter.LocationText;
1738                       EncDT := Encounter.DateTime;
1739                       EncVC := Encounter.VisitCategory;
1740                     end
1741                   else
1742                      begin
1743                       EncLocName := uCore.TempEncounterLocName;
1744                       EncLocIEN  := uCore.TempEncounterLoc;
1745                       EncLocText := uCore.TempEncounterText;
1746                       EncDT := uCore.TempEncounterDateTime;
1747                       EncVC := uCore.TempEncounterVistCat;
1748                      end;
1749                   if frmFrame.mnuFile.Tag = 0 then displayEncSwitch := false
1750                   else displayEncSwitch := true;
1751                   if Encounter.Location = 0  then
1752                     begin
1753                       DisplayEncSwitch := True;
1754                       DelayOnly := True;
1755                     end;
1756                   for i := 0 to lstReview.Items.Count-1 do
1757                     begin
1758                      //disregard orders that are not signed
1759                      if (lstReview.Checked[i] = false) and (lstReview.State[i] <> cbGrayed) then continue;
1760                      TempChangeItem := TChangeItem(lstReview.Items.Objects[i]);
1761                      //DC Orders should print at the ward location
1762                      if TempChangeItem.DCOrder = True then
1763                        begin
1764                          WardList.Add(tempChangeItem.ID);
1765                          continue;
1766                        end;
1767                      //disregard Non-VA Meds orders
1768                      if TempChangeItem.OrderDG = NONVAMEDGROUP then continue;
1769                      if TempChangeItem.OrderDG = 'Clinic Orders' then ContainsIMOORders := true;
1770                      if (tempChangeItem.OrderDG = '') then continue;
1771                      //Delay orders should be printed when the order is release to service not when the order is sign
1772                      if tempChangeItem.Delay = True then continue;
1773                      OrderPrintList.Add(tempChangeItem.ID + ':' + tempChangeItem.Text);
1774                     end;
1775                   if (OrderPrintList.Count > 0) and (DelayOnly = False) then
1776                      frmPrintLocation.PrintLocation(OrderPrintList, EncLocIEN, EncLocName, EncLocText, EncDT, EncVC, ClinicList,
1777                                                     WardList, wardIEN, wardName, ContainsIMOOrders, displayEncSwitch)
1778                    //Only Display encounter switch form if staying in the patient chart
1779                    else if displayEncSwitch = true then
1780                      begin
1781                        frmPrintLocation.SwitchEncounterLoction(EncLocIEN, EncLocName, EncLocText, EncDT, EncVC);
1782                        fFrame.frmFrame.OrderPrintForm := True;
1783                        DoNotPrint := True;
1784                      end;
1785                   if (WardIEN = 0) and (WardName = '') then CurrentLocationForPatient(Patient.DFN, WardIEN, WardName, ASvc);
1786                    //All other scenarios should not print
1787                   if (ClinicList.count = 0) and (WardList.count = 0) then DoNotPrint := True;
1788               end;
1789            end;
1790            if (cmdOk.Caption = 'Don''t Sign') and (not frmFrame.TimedOut) and (frmFrame.mnuFile.Tag <> 0) then
1791                 begin
1792                   tempInpLoc := frmPrintLocation.rpcIsPatientOnWard(patient.dfn);
1793                   if ((Patient.Inpatient = false) and (tempInpLoc <> '')) or
1794                   ((Patient.Inpatient = True) and (Encounter.Location <> Patient.Location)) or
1795                   ((Patient.Inpatient = True) and (Encounter.Location = Patient.Location) and
1796                   (encounter.Location <> uCore.TempEncounterLoc) and (uCore.TempEncounterLoc <> 0))
1797                   or((Patient.Inpatient) and (tempInpLoc <> '') and (Piece(tempInpLoc, U, 2) <> InttoStr(Encounter.location))) then
1798                      begin
1799                        if (Encounter.Location <> Patient.Location) or
1800                            ((tempInpLoc <> '') and ((InttoStr(Encounter.location)) <> (Piece(tempInpLoc,U,2)))) then
1801                          begin
1802                            EncLocName := Encounter.LocationName;
1803                            EncLocIEN  := Encounter.Location;
1804                            EncLocText := Encounter.LocationText;
1805                            EncDT := Encounter.DateTime;
1806                            EncVC := Encounter.VisitCategory;
1807                          end
1808                        else
1809                          begin
1810                            EncLocName := uCore.TempEncounterLocName;
1811                            EncLocIEN  := uCore.TempEncounterLoc;
1812                            EncLocText := uCore.TempEncounterText;
1813                            EncDT := uCore.TempEncounterDateTime;
1814                            EncVC := uCore.TempEncounterVistCat;
1815                          end;
1816                          frmPrintLocation.SwitchEncounterLoction(EncLocIEN, EncLocName, EncLocText, EncDT, EncVC);
1817                          fFrame.frmFrame.OrderPrintForm := True;
1818                      end;
1819                 end;
1820            uCore.TempEncounterLoc := 0;
1821            uCore.TempEncounterLocName := '';
1822            tempInpLoc := '';
1823          end;
1824          //hds7591  Clinic/Ward movement.
1825          
1826            if SaveCoPay then
1827              begin
1828                SigItems.SaveSettings; // Save CoPay FIRST
1829                SigItemsCS.SaveSettings;
1830              end;
1831  
1832            SendOrders(OrderList, ESCode);   {*KCM*}
1833  
1834  
1835        //CQ #15813 Modired code to look for error string mentioned in CQ and change strings to conts - JCS
1836          with OrderList do for i := 0 to Count - 1 do
1837          begin
1838            if Pos('E', Piece(OrderList[i], U, 2)) > 0 then
1839            begin
1840              ChangeItem := Changes.Locate(CH_ORD, Piece(OrderList[i], U, 1));
1841              if not FSilent then
1842                begin
1843                  if Piece(OrderList[i],U,4) = TX_SAVERR_PHARM_ORD_NUM_SEARCH_STRING then
1844                    InfoBox(TX_SAVERR1 + Piece(OrderList[i], U, 4) + TX_SAVERR2 + ChangeItem.Text + CRLF + CRLF +
1845                          TX_SAVERR_PHARM_ORD_NUM, TC_SAVERR, MB_OK)
1846                  else if Piece(OrderList[i],U,4) = TX_SAVERR_IMAGING_PROC_SEARCH_STRING then
1847                    InfoBox(TX_SAVERR1 + Piece(OrderList[i], U, 4) + TX_SAVERR2 + ChangeItem.Text + CRLF + CRLF +
1848                          TX_SAVERR_IMAGING_PROC, TC_SAVERR, MB_OK)
1849                  else
1850                   InfoBox(TX_SAVERR1 + Piece(OrderList[i], U, 4) + TX_SAVERR2 + ChangeItem.Text,
1851                      TC_SAVERR, MB_OK);
1852                end;
1853            end;
1854            if Pos('R', Piece(OrderList[i], U, 2)) > 0 then
1855              NotifyOtherApps(NAE_ORDER, 'RL' + U + Piece(OrderList[i], U, 1));
1856          end;
1857          if OrdersSignedOrReleased and (not FSilent) then
1858          begin
1859            for idx := OrderList.Count - 1 downto 0 do
1860            begin
1861              if Pos('E', Piece(OrderList[idx], U, 2)) > 0 then
1862              begin
1863                OrderList.Delete(idx);
1864                Continue;
1865              end;
1866              theSts := GetOrderStatus(Piece(OrderList[idx],U,1));
1867              if theSts = 10 then  OrderList.Delete(idx);  //signed delayed order should not be printed.
1868            end;
1869            //  CQ 10226, PSI-05-048 - advise of auto-change from LC to WC on lab orders
1870            AList := TStringList.Create;
1871            try
1872              CheckForChangeFromLCtoWCOnRelease(AList, Encounter.Location, OrderList);
1873              if AList.Text <> '' then
1874                ReportBox(AList, 'Changed Orders', TRUE);
1875            finally
1876              AList.Free;
1877            end;
1878            if (ClinicList.Count > 0) or (WardList.Count > 0) then
1879                  PrintOrdersOnSignReleaseMult(OrderList, CLinicList, WardList, Nature, EncLocIEN, WardIEN, EncLocName, wardName)
1880            else if DoNotPrint = False then PrintOrdersOnSignRelease(OrderList, Nature, PrintLoc);
1881          end;
1882          StatusText('');
1883          UpdateUnsignedOrderAlerts(Patient.DFN);
1884          with Notifications do
1885            if Active and (FollowUp = NF_ORDER_REQUIRES_ELEC_SIGNATURE) then
1886              UnsignedOrderAlertFollowup(Piece(RecordID, U, 2));
1887          UpdateExpiringMedAlerts(Patient.DFN);
1888          UpdateUnverifiedMedAlerts(Patient.DFN);
1889          UpdateUnverifiedOrderAlerts(Patient.DFN);
1890          SendMessage(Application.MainForm.Handle, UM_NEWORDER, ORDER_SIGN, 0);
1891        end; {if User.OrderRole}
1892  
1893      finally
1894        FreeAndNil(OrderList);
1895        FreeAndNil(OrderPrintList);
1896        FreeAndNil(ClinicList);
1897        FreeAndNil(WardList);
1898      end;
1899      if not(crypto=nil) then
1900      begin
1901        crypto.Free;
1902        crypto := nil;
1903      end;
1904    end;
1905  
1906    { save/sign documents }
1907    with lstReview do for i := 0 to Items.Count - 1 do
1908    begin
1909      ChangeItem := TChangeItem(Items.Objects[i]);
1910      if ChangeItem <> nil then with ChangeItem do
1911        case ItemType of
1912        CH_DOC: if Checked[i]
1913                  then frmNotes.SaveSignItem(ChangeItem.ID, ESCode)
1914                  else frmNotes.SaveSignItem(ChangeItem.ID, '');
1915        CH_CON: if Checked[i]
1916                  then frmConsults.SaveSignItem(ChangeItem.ID, ESCode)
1917                  else frmConsults.SaveSignItem(ChangeItem.ID, '');
1918        CH_SUM: if Checked[i]
1919                  then frmDCSumm.SaveSignItem(ChangeItem.ID, ESCode)
1920                  else frmDCSumm.SaveSignItem(ChangeItem.ID, '');
1921        CH_SUR: if Assigned(frmSurgery) then
1922                begin
1923                  if Checked[i]
1924                    then frmSurgery.SaveSignItem(ChangeItem.ID, ESCode)
1925                    else frmSurgery.SaveSignItem(ChangeItem.ID, '');
1926                end;
1927        end; {case}
1928    end; {with lstReview}
1929    if frmFrame.Closing then exit;
1930  
1931    // clear all the items that were on the list (but not all in Changes)
1932    with lstReview do for i := Items.Count - 1 downto 0  do
1933    begin
1934      if (not Assigned(Items.Objects[i])) then continue;   {**RV**}
1935      ChangeItem := TChangeItem(Items.Objects[i]);
1936      if ChangeItem <> nil then
1937      begin
1938        AnID := ChangeItem.ID;
1939        AType := ChangeItem.ItemType;
1940        Changes.Remove(AType, AnID);
1941      end;
1942    end;
1943    with lstCSReview do for i := Items.Count - 1 downto 0  do
1944    begin
1945      if (not Assigned(Items.Objects[i])) then continue;   {**RV**}
1946      ChangeItem := TChangeItem(Items.Objects[i]);
1947      if ChangeItem <> nil then
1948      begin
1949        AnID := ChangeItem.ID;
1950        AType := ChangeItem.ItemType;
1951        Changes.Remove(AType, AnID);
1952      end;
1953    end;
1954    UnlockIfAble;
1955    FOKPressed := IsOk;
1956    Close;
1957  end;
1958  
1959  procedure TfrmReview.CleanupChangesList(Sender: TObject; ChangeItem: TChangeItem);
1960  {Added for v15.3 - called by Changes.Remove, but only if fReview in progress}
1961  var
1962    i: integer;
1963  begin
1964    with lstReview do
1965      begin
1966        i := Items.IndexOfObject(ChangeItem);
1967        if i > -1 then
1968          begin
1969            TChangeItem(Items.Objects[i]).Free;
1970            Items.Objects[i] := nil;
1971          end;
1972      end;
1973  end;
1974  
1975  procedure TfrmReview.cmdCancelClick(Sender: TObject);
1976  { cancelled - do nothing }
1977  begin
1978    Inherited;
1979    Close;
1980  end;
1981  
1982  procedure TfrmReview.lstReviewMeasureItem(Control: TWinControl;
1983    Index: Integer; var AHeight: Integer);
1984  var
1985    x:string;
1986    ARect: TRect;
1987  begin
1988    inherited;
1989    AHeight := SigItemHeight;
1990    with lstReview do if Index < Items.Count then
1991    begin
1992      ARect := ItemRect(Index);
1993      ARect.Left := lstReview.CheckWidth;
1994      Canvas.FillRect(ARect);
1995      x := FilteredString(Items[Index]);
1996      AHeight := WrappedTextHeightByFont( lstReview.Canvas, Font, x, ARect) + SIG_ITEM_VERTICAL_PAD;
1997      if AHeight > 255 then AHeight := 255;
1998      if AHeight <  13 then AHeight := 15;
1999    end;
2000  end;
2001  
2002  procedure TfrmReview.FormDestroy(Sender: TObject);
2003  begin
2004    Application.HintPause := FOldHintPause;
2005    Application.HintHidePause := FOldHintHidePause;
2006  end;
2007  
2008  
2009  procedure TfrmReview.lstReviewMouseMove(Sender: TObject;
2010    Shift: TShiftState; X, Y: Integer);
2011  var
2012    Itm: integer;
2013  
2014   {Begin BillingAware}
2015    tempRec: UBAGlobals.TBADxRecord;
2016    i: smallint;
2017    thisOrderID: string;
2018   {End BillingAware}
2019  
2020  begin
2021    inherited;
2022    Itm := lstReview.ItemAtPos(Point(X, Y), TRUE);
2023    if (Itm >= 0) then
2024    begin
2025      if (Itm <> FLastHintItem) then
2026      begin
2027        Application.CancelHint;
2028    {Begin BillingAware}
2029     if  BILLING_AWARE then
2030     begin
2031         if frmFrame.TimedOut then Exit;
2032          //Billing Awareness 'flyover' hint includes Dx code(s) when Dx code(s) have been assigned to an order
2033  
2034            if Assigned(frmReview) then
2035                if Assigned(fReview.frmReview.lstReview.Items.Objects[Itm]) then
2036                      thisOrderID := TOrder(fReview.frmReview.lstReview.Items.Objects[Itm]).ID;
2037  
2038             if UBAGlobals.tempDxNodeExists(thisOrderID) then
2039                   begin
2040                   if Assigned(tempDxList) then
2041                      try
2042                        for i := 0 to (tempDxList.Count - 1) do
2043                           begin
2044                            tempRec := TBADxRecord(tempDxList.Items[i]);
2045  
2046                            if Assigned(tempRec) then
2047                              if (tempRec.FOrderID = thisOrderID) then
2048                                  begin
2049                                  with tempRec do
2050                                     begin
2051                                     FBADxCode := StringReplace(tempRec.FBADxCode,'^',':',[rfReplaceAll]);
2052                                     FBASecDx1 := StringReplace(tempRec.FBASecDx1,'^',':',[rfReplaceAll]);
2053                                     FBASecDx2 := StringReplace(tempRec.FBASecDx2,'^',':',[rfReplaceAll]);;
2054                                     FBASecDx3 := StringReplace(tempRec.FBASecDx3,'^',':',[rfReplaceAll]);
2055                                     end;
2056  
2057                                     lstReview.Hint := TrimRight(lstReview.Items[Itm] + #13 +
2058                                        tempRec.FBADxCode + #13 + tempRec.FBASecDx1 + #13 + tempRec.FBASecDx2 + #13 + tempRec.FBASecDx3);
2059                                  end
2060                           end //for
2061                        except
2062                            on EListError do
2063                               begin
2064                               {$ifdef debug}Show508Message('EListError in fReview.lstReviewMouseMove()');{$endif}
2065                               raise;
2066                               end;
2067                        end;
2068                   end
2069             else
2070                 lstReview.Hint := TrimRight(lstReview.Items[Itm]);
2071     end;
2072  {End BillingAware}
2073  
2074        FLastHintItem := Itm;
2075        Application.ActivateHint(Point(X, Y));
2076      end;
2077    end
2078    else
2079    begin
2080      lstReview.Hint := '';
2081      FLastHintItem := -1;
2082      Application.CancelHint;
2083    end;
2084  end;
2085  
2086  procedure TfrmReview.buDiagnosisClick(Sender: TObject);
2087  {Begin BillingAware}
2088  var
2089    i: smallint;
2090    thisOrderID: string;
2091    match: boolean;
2092    allBlank: boolean;
2093    numSelected: smallint;
2094    tmpOrderIDList: TStringList;
2095    thisChangeItem: TChangeItem;
2096  {End BillingAware}
2097  begin
2098  {Begin BillingAware}
2099  try
2100   if  BILLING_AWARE then
2101   begin
2102  
2103    tmpOrderIDList := TStringList.Create;
2104    if Assigned(tmpOrderIDList) then tmpOrderIDList.Clear;
2105    BAtmpOrderList.Clear;
2106    UBAGlobals.PLFactorsIndexes.Clear;
2107  
2108    match := false;
2109    allBlank := false;
2110  
2111    try
2112        // User has selected no orders to sign
2113       for i := 0 to fReview.frmReview.lstReview.Items.Count-1 do
2114          begin
2115           if (fReview.frmReview.lstReview.Selected[i]) then
2116           //*********************************
2117              begin    //Access Violation fix
2118              thisChangeItem := TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]);
2119              if thisChangeItem = nil then
2120                begin
2121                fReview.frmReview.lstReview.Selected[i] := false;
2122                Continue;
2123                end;
2124            //*********************************
2125                thisOrderID := TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).ID;
2126                {BAV25 Code} //Used to pass selected orders to Lookup DX form
2127                BAtmpOrderList.Add(TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).TEXT);
2128                tmpOrderIDList.Add(thisOrderID);
2129                chkBoxStatus := GetCheckBoxStatus(thisOrderID);
2130                UBAGlobals.PLFactorsIndexes.Add(IntToStr(i)+ U + chkBoxStatus);
2131               {BAV25 Code}
2132               
2133              // Test for blank Dx on current grid item
2134              if Not (tempDxNodeExists(thisOrderID)) then
2135                 if Assigned(UBAGlobals.GlobalDxRec) then
2136                    InitializeNewDxRec(UBAGlobals.globalDxRec);
2137              begin
2138                 if (tempDxNodeExists(thisOrderID) ) then
2139                   if not Assigned(UBAGlobals.globalDxRec) then
2140                      begin
2141                      UBAGlobals.globalDxRec := UBAGlobals.TBADxRecord.Create;
2142                      InitializeNewDxRec(UBAGlobals.globalDxRec);
2143                      GetBADxListForOrder(UBAGlobals.globalDxRec, thisOrderID);
2144                      end
2145                   else
2146                      GetBADxListForOrder(UBAGlobals.globalDxRec, thisOrderID);
2147  
2148                    end
2149             end; //if
2150          end; //for
2151    except
2152       on EListError do
2153          begin
2154          {$ifdef debug}Show508Message('EListError in fReview.buDiagnosisClick()');{$endif}
2155          raise;
2156          end;
2157    end;
2158  
2159    numSelected  := CountSelectedOrders(UBAConst.F_REVIEW);
2160  
2161    if numSelected = 0 then
2162       begin
2163       ShowMsg(UBAMessages.BA_NO_ORDERS_SELECTED);
2164       Exit;
2165       end
2166    else
2167       if numSelected = 1 then
2168          match := true;
2169  
2170    if (UBAGlobals.CompareOrderDx(UBAConst.F_REVIEW)) then
2171       match := true;
2172  
2173  
2174    if UBAGlobals.AllSelectedDxBlank(UBAConst.F_REVIEW) then
2175       allBlank := true;
2176  
2177    if ((match and allBlank) or (match and (not allBlank))) then  // All selected are blank or matching-not-blank
2178       begin
2179          frmBALocalDiagnoses.Enter(UBAConst.F_REVIEW,  tmpOrderIDList);
2180       end
2181    else
2182       begin
2183       //Warning message
2184       //If 'Yes' on warning message then open localDiagnosis
2185       if (not allBlank) then
2186           if MessageDlg(UBAMessages.BA_CONFIRM_DX_OVERWRITE, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
2187                    begin
2188                    if Assigned(UBAGlobals.globalDxRec) then
2189                       InitializeNewDxRec(UBAGlobals.globalDxRec);
2190  
2191                    frmBALocalDiagnoses := TfrmBALocalDiagnoses.Create(frmReview);
2192                    frmBALocalDiagnoses.ShowModal;
2193                    frmBALocalDiagnoses.Release;
2194  
2195                    end;
2196       end;
2197       // TFactors come from FBALocalDiagnoses(Problem List Dx's Only).
2198       if Length(UBAGlobals.TFactors) > 0 then
2199       begin
2200          UBACore.SetTreatmentFactors(UBAGlobals.TFactors);
2201          SigItems.DisplayPlTreatmentFactors;
2202       end;
2203   {End BillingAware}
2204   if pnlSignature.Visible then
2205      txtESCode.SetFocus;
2206     end;
2207   finally
2208       if Assigned(tmpOrderIDList) then FreeAndNil(tmpOrderIDList);
2209   end;
2210  end;
2211  
2212  procedure TfrmReview.lstCSReviewClick(Sender: TObject);
2213  //If grid item is an order-able item, then enable the Diagnosis button
2214  // else disable the Diagnosis button.
2215  {Begin BillingAware}
2216  var
2217    thisChangeItem: TChangeItem;
2218    i: smallint;
2219    thisOrderList: TStringList;
2220  {End BillingAware}
2221  begin
2222  thisOrderList := TStringList.Create;
2223  
2224  {Begin BillingAware}
2225   if  BILLING_AWARE then
2226   begin
2227      if lstCSReview.Items.Count > 1 then
2228         Copy1.Enabled := True
2229      else
2230         Copy1.Enabled := False;
2231  
2232    try
2233       for i := 0 to lstCSReview.Items.Count - 1 do
2234       begin
2235          if lstCSReview.Selected[i] then
2236             begin
2237             thisChangeItem := TChangeItem(lstCSReview.Items.Objects[i]);
2238  
2239             //Disallow copying of a grid HEADER item on LEFT MOUSE CLICK
2240             if thisChangeItem = nil then
2241                begin
2242                buDiagnosis.Enabled := false;
2243                Copy1.Enabled := false;
2244                Paste1.Enabled := false;
2245                Diagnosis1.Enabled := false;
2246                Exit;
2247                end;
2248  
2249             if (thisChangeItem <> nil) then
2250                begin
2251                thisOrderList.Clear;
2252                thisOrderList.Add(thisChangeItem.ID);
2253                // Returns True if All selected orders are N/A, Order selected are NON CIDC or DC'd
2254                if UBACore.IsAllOrdersNA(thisOrderList) then
2255                   begin
2256                   Diagnosis1.Enabled := false;
2257                   buDiagnosis.Enabled := false;
2258                   end
2259                else
2260                   begin
2261                   Diagnosis1.Enabled := true;
2262                   buDiagnosis.Enabled := true;
2263                   end
2264                end
2265             else
2266                begin
2267                buDiagnosis.Enabled := false;
2268                Diagnosis1.Enabled := False;
2269                Break;
2270                end;
2271             end;
2272          end;
2273    except
2274       on EListError do
2275          begin
2276          {$ifdef debug}Show508Message('EListError in fReview.lstCSReviewClick()');{$endif}
2277          raise;
2278          end;
2279    end;
2280   {End BillingAware}
2281   end;    
2282   if Assigned(thisOrderList) then thisOrderList.Free;
2283  end;
2284  
2285  procedure TfrmReview.lstCSReviewClickCheck(Sender: TObject);
2286  { prevent grayed checkboxes from being changed to anything else }
2287  var
2288    ChangeItem: TChangeItem;
2289  
2290    procedure updateAllChilds(CheckedStatus: boolean; ParentOrderId: string);
2291    var
2292      idx: integer;
2293      AChangeItem: TChangeItem;
2294    begin
2295      for idx := 0 to lstCSReview.Items.Count - 1 do
2296      begin
2297        AChangeItem := TChangeItem(lstCSReview.Items.Objects[idx]);
2298        if Assigned(AChangeItem) and (AChangeItem.ParentID = ParentOrderId) then
2299            if lstCSReview.Checked[idx] <> CheckedStatus then
2300            begin
2301              lstCSReview.Checked[idx] := CheckedStatus;
2302              SigItemsCS.EnableSettings(idx, lstCSReview.checked[Idx]);
2303            end;
2304      end;
2305    end;
2306  
2307  begin
2308    with lstCSReview do
2309    begin
2310      ChangeItem := TChangeItem(Items.Objects[ItemIndex]);
2311      if ChangeItem = nil then Exit;
2312      
2313      if ItemIndex > 0 then
2314      begin
2315        if (ChangeItem <> nil) then
2316        begin
2317          if (ChangeItem.SignState = CH_SIGN_NA) then State[ItemIndex] := cbGrayed
2318          else
2319          begin
2320            SigItemsCS.EnableSettings(ItemIndex, checked[ItemIndex]);
2321            if Length(ChangeItem.ParentID) > 0 then
2322              updateAllChilds(checked[ItemIndex], ChangeItem.ParentID);
2323          end;
2324        end;
2325      end;
2326      if CSItemsAreChecked and nonDCCSItemsAreChecked then
2327      begin
2328         lblDeaText.Visible := TRUE;
2329         lblSmartCardNeeded.Visible := TRUE;
2330      end
2331      else
2332      begin
2333         lblDeaText.Visible := FALSE;
2334         lblSmartCardNeeded.Visible := FALSE;
2335      end;
2336      pnlSignature.Visible := IsSignatureRequired;
2337    end;
2338    if pnlSignature.Visible then
2339    begin
2340      txtESCode.SetFocus;
2341      txtESCodeChange(Self);
2342    end;
2343  end;
2344  
2345  procedure TfrmReview.lstCSReviewDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
2346  { outdent the header items (thus hiding the checkbox) }
2347  var
2348    x: string;
2349    ARect, TextRecord: TRect;
2350    i, dy: integer;
2351    tempID: string;
2352    thisRec: UBAGlobals.TBADxRecord;
2353  
2354  {Begin BillingAware}
2355    str: string;
2356  {End BillingAware}
2357  
2358    procedure UpdateTextRecord(r: TRect);
2359    begin
2360      TextRecord := r;
2361      inc(TextRecord.Top, dy);
2362      dec(TextRecord.Bottom, dy);
2363    end;
2364  
2365  begin
2366    inherited;
2367    dy := SIG_ITEM_VERTICAL_PAD div 2;
2368    x := '';
2369    ARect := Rect;
2370  
2371    if  BILLING_AWARE then
2372    begin
2373       ARect.Right := ARect.Right - 50;
2374  
2375    with lstCSReview do
2376    begin
2377      if Items.Objects[Index] = nil then
2378          ARect.Left := 0;
2379      Canvas.Pen.Color := Get508CompliantColor(clSilver);
2380      Canvas.FillRect(ARect);
2381  
2382      if Index < Items.Count then
2383        begin
2384         x := Trim(FilteredString(Items[Index]));
2385  
2386         if (ARect.Left = 0) and ( Length(x)>0 ) then
2387           Canvas.TextOut(ARect.Left + 2, ARect.Top + dy, x)
2388         else
2389            if (ARect.Left > 0 ) and ( Length(x)>0 ) then
2390               begin
2391               //ARect.Right below controls the right-hand side of the Dx Column
2392               //Adjust ARect.Right in conjunction with procedure uSignItems.TSigItems.lbDrawItem(), because the
2393               //two rectangles overlap each other.
2394  
2395               if  BILLING_AWARE then
2396                  begin
2397                  arRect[Index] := Classes.Rect(ARect.Right+2, ARect.Top, ARect.Right + 108, ARect.Bottom);
2398                  Canvas.FillRect(arRect[Index]);
2399                  end;
2400  
2401               //Draw ORDER TEXT
2402              UpdateTextRecord(ARect);
2403              DrawText(Canvas.handle, PChar(x), Length(x), TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
2404  
2405             if  BILLING_AWARE then
2406                  begin
2407                       //Dx Column lines
2408                       Canvas.Pen.Color := Get508CompliantColor(clSilver);
2409                       Canvas.MoveTo(DxRect.Left-1, ARect.Top);
2410                       Canvas.LineTo(DxRect.Left-1, ARect.Bottom);
2411                       //Adjust position of 'Diagnosis' column label for font size
2412                       laDiagnosis.Left := DxRect.Left + 14;
2413                       if uSignItems.GetAllBtnLeftPos > 0 then
2414                          laDiagnosis.left := uSignItems.GetAllBtnLeftPos - (laDiagnosis.Width +5);
2415                       laDiagnosis.Top := lblSig.Top;
2416                       //Assign DxRect for drawing Dx column and Dx string
2417                       DxRect.Left := ARect.Right + 1;
2418                       DxRect.Top := ARect.Top;
2419                       DxRect.Right := DxRect.Left + 80;
2420                       DxRect.Bottom := ARect.Bottom;
2421  
2422                      //Display all saved Dx's
2423                        for i := 0 to lstCSReview.Items.Count-1 do
2424                          with TOrder(lstCSReview.Items[i]) do
2425                            begin
2426                             // HDS00005025
2427                            if TChangeItem(lstCSReview.Items.Objects[Index]).ITEMTYPE = CH_DOC then
2428                               tempID := '0' // if document id is equal to valid order id identify billable orders
2429                            else
2430                               tempID := TChangeItem(lstCSReview.Items.Objects[Index]).ID;
2431                              // HDS00005025
2432                             //WORKS FOR MULTIPLE Dx
2433                             if Assigned(UBAGlobals.tempDxList) then
2434                               if UBAGlobals.tempDxNodeExists(tempID) then
2435                                   begin
2436                                      thisRec := TBADxRecord.Create;
2437                                      UBAGlobals.GetBADxListForOrder(thisRec, tempID);
2438                                      str := Piece(thisRec.FBADxCode, '^', 1); // Display Dx text only - not the ICD-9 code
2439                                      str := Piece(str, ':', 1);   //in case has : vs. ^
2440                                      UpdateTextRecord(arRect[Index]);
2441                                      DrawText(Canvas.handle, PChar(str), Length(str), TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
2442  
2443                                      if (Not UBACore.IsOrderBillable(tempID)) then// and
2444                                      begin
2445                                         Canvas.Font.Color := Get508CompliantColor(clBlue);
2446                                         UpdateTextRecord(arRect[Index]);
2447                                         DrawText(Canvas.handle, PChar(NOT_APPLICABLE), Length(NOT_APPLICABLE) , TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
2448                                      end;
2449                                   end
2450                                else
2451                                   begin
2452                                   //Determine if order is billable. If NOT billable then insert NA in Dx field
2453                                      if Not UBACore.IsOrderBillable(tempID) then
2454                                      begin
2455                                          Canvas.Font.Color := Get508CompliantColor(clBlue);
2456                                          UpdateTextRecord(arRect[Index]);
2457                                          DrawText(Canvas.handle, PChar(NOT_APPLICABLE), Length(NOT_APPLICABLE) , TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
2458                                      end;
2459                                   end;
2460                            end;
2461                      end;
2462          end; //if
2463        end; //if
2464    end; //with
2465   end
2466   else
2467      begin
2468         with lstCSReview do
2469            begin
2470            if Items.Objects[Index] = nil then
2471                ARect.Left := 0;
2472  
2473            Canvas.FillRect(ARect);
2474  
2475            if Index < Items.Count then
2476               begin
2477                  x := Trim(FilteredString(Items[Index]));
2478  
2479               if (ARect.Left = 0) and ( Length(x) > 0 ) then
2480                  Canvas.TextOut(ARect.Left + 2, ARect.Top + dy, x)
2481               else
2482                  if (ARect.Left > 0 ) and ( Length(x)>0 ) then
2483                     begin
2484                       Canvas.Pen.Color := Get508CompliantColor(clSilver);
2485                       Canvas.MoveTo(0, ARect.Bottom-1);
2486                       Canvas.LineTo(ARect.Right, ARect.Bottom-1);
2487                       UpdateTextRecord(ARect);
2488                       DrawText(Canvas.handle, PChar(x), Length(x), TextRecord, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
2489                     end;
2490               end;
2491         end;
2492      end;
2493  end;
2494  
2495  
2496  procedure TfrmReview.lstCSReviewKeyUp(Sender: TObject; var Key: Word;
2497    Shift: TShiftState);
2498  begin
2499    if (Key = VK_Space) then
2500      FormatListForScreenReader
2501  end;
2502  
2503  procedure TfrmReview.lstCSReviewMeasureItem(Control: TWinControl;
2504    Index: Integer; var AHeight: Integer);
2505  var
2506    x:string;
2507    ARect: TRect;
2508  begin
2509    inherited;
2510    AHeight := SigItemHeight;
2511    with lstCSReview do if Index < Items.Count then
2512    begin
2513      ARect := ItemRect(Index);
2514      ARect.Left := lstCSReview.CheckWidth;
2515      Canvas.FillRect(ARect);
2516      x := FilteredString(Items[Index]);
2517      AHeight := WrappedTextHeightByFont( lstCSReview.Canvas, Font, x, ARect) + SIG_ITEM_VERTICAL_PAD;
2518      if AHeight > 255 then AHeight := 255;
2519      if AHeight <  13 then AHeight := 15;
2520    end;
2521  end;
2522  
2523  procedure TfrmReview.lstCSReviewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
2524  {
2525     - Open copy/paste popup menu.
2526  }
2527  var
2528    ClientPoint: TPoint;
2529    ScreenPoint: TPoint;
2530    thisChangeItem: TChangeItem;
2531    i: integer;
2532  begin
2533    if not BILLING_AWARE then lstCSReview.PopupMenu := nil;
2534  
2535    if BILLING_AWARE then
2536       begin
2537          if Button = mbRight then  //Right-click to open copy/paste popup menu
2538             begin
2539             //CQ3325
2540             if frmReview.lstCSReview.Items.Count = 3 then
2541                begin
2542                Copy1.Enabled := false;
2543                Paste1.Enabled := false
2544                end
2545             else
2546                begin
2547                Copy1.Enabled := true;
2548                end;
2549             //End CQ3325
2550  
2551       //CQ HDS00002954 Fix
2552       if Button = mbRight then
2553           //Disallow copying of a grid HEADER item
2554          for i := 0 to lstCSReview.Items.Count - 1 do
2555                if lstCSReview.Selected[i] then
2556                   begin
2557                  
2558                   thisChangeItem := TChangeItem(lstCSReview.Items.Objects[i]);
2559  
2560                    if thisChangeItem = nil then
2561                       begin
2562                       lstCSReview.Selected[i] := false;
2563                       Copy1.Enabled := false;
2564                       Paste1.Enabled := false;
2565                       Exit;
2566                       end;
2567                    end;
2568                      
2569           if not frmReview.lstCSReview.Selected[lstCSReview.ItemIndex] then
2570              (Sender as TCheckListBox).Selected[lstCSReview.ItemIndex] := true;
2571  
2572           ClientPoint.X := X;
2573           ClientPoint.Y := Y;
2574           ScreenPoint := lstCSReview.ClientToScreen(ClientPoint);
2575           poBACopyPaste.Popup(ScreenPoint.X, ScreenPoint.Y);
2576           end;
2577        end;
2578  end;
2579  
2580  procedure TfrmReview.lstCSReviewMouseMove(Sender: TObject;
2581    Shift: TShiftState; X, Y: Integer);
2582  var
2583    Itm: integer;
2584  
2585   {Begin BillingAware}
2586    tempRec: UBAGlobals.TBADxRecord;
2587    i: smallint;
2588    thisOrderID: string;
2589   {End BillingAware}
2590  
2591  begin
2592    inherited;
2593    Itm := lstCSReview.ItemAtPos(Point(X, Y), TRUE);
2594    if (Itm >= 0) then
2595    begin
2596      if (Itm <> FLastHintItem) then
2597      begin
2598        Application.CancelHint;
2599    {Begin BillingAware}
2600     if  BILLING_AWARE then
2601     begin
2602         if frmFrame.TimedOut then Exit;
2603          //Billing Awareness 'flyover' hint includes Dx code(s) when Dx code(s) have been assigned to an order
2604  
2605            if Assigned(frmReview) then
2606                if Assigned(fReview.frmReview.lstCSReview.Items.Objects[Itm]) then
2607                      thisOrderID := TOrder(fReview.frmReview.lstCSReview.Items.Objects[Itm]).ID;
2608  
2609             if UBAGlobals.tempDxNodeExists(thisOrderID) then
2610                   begin
2611                   if Assigned(tempDxList) then
2612                      try
2613                        for i := 0 to (tempDxList.Count - 1) do
2614                           begin
2615                            tempRec := TBADxRecord(tempDxList.Items[i]);
2616  
2617                            if Assigned(tempRec) then
2618                              if (tempRec.FOrderID = thisOrderID) then
2619                                  begin
2620                                  with tempRec do
2621                                     begin
2622                                     FBADxCode := StringReplace(tempRec.FBADxCode,'^',':',[rfReplaceAll]);
2623                                     FBASecDx1 := StringReplace(tempRec.FBASecDx1,'^',':',[rfReplaceAll]);
2624                                     FBASecDx2 := StringReplace(tempRec.FBASecDx2,'^',':',[rfReplaceAll]);;
2625                                     FBASecDx3 := StringReplace(tempRec.FBASecDx3,'^',':',[rfReplaceAll]);
2626                                     end;
2627  
2628                                     lstCSReview.Hint := TrimRight(lstCSReview.Items[Itm] + #13 +
2629                                        tempRec.FBADxCode + #13 + tempRec.FBASecDx1 + #13 + tempRec.FBASecDx2 + #13 + tempRec.FBASecDx3);
2630                                  end
2631                           end //for
2632                        except
2633                            on EListError do
2634                               begin
2635                               {$ifdef debug}Show508Message('EListError in fReview.lstCSReviewMouseMove()');{$endif}
2636                               raise;
2637                               end;
2638                        end;
2639                   end
2640             else
2641                 lstCSReview.Hint := TrimRight(lstCSReview.Items[Itm]);
2642     end;
2643  {End BillingAware}
2644  
2645        FLastHintItem := Itm;
2646        Application.ActivateHint(Point(X, Y));
2647      end;
2648    end
2649    else
2650    begin
2651      lstCSReview.Hint := '';
2652      FLastHintItem := -1;
2653      Application.CancelHint;
2654    end;
2655  end;
2656  
2657  procedure TfrmReview.lstReviewClick(Sender: TObject);
2658  //If grid item is an order-able item, then enable the Diagnosis button
2659  // else disable the Diagnosis button.
2660  {Begin BillingAware}
2661  var
2662    thisChangeItem: TChangeItem;
2663    i: smallint;
2664    thisOrderList: TStringList;
2665  {End BillingAware}
2666  begin
2667  thisOrderList := TStringList.Create;
2668  
2669  {Begin BillingAware}
2670   if  BILLING_AWARE then
2671   begin
2672      if lstReview.Items.Count > 1 then
2673         Copy1.Enabled := True
2674      else
2675         Copy1.Enabled := False;
2676  
2677    try
2678       for i := 0 to lstReview.Items.Count - 1 do
2679       begin
2680          if lstReview.Selected[i] then
2681             begin
2682             thisChangeItem := TChangeItem(lstReview.Items.Objects[i]);
2683  
2684             //Disallow copying of a grid HEADER item on LEFT MOUSE CLICK
2685             if thisChangeItem = nil then
2686                begin
2687                buDiagnosis.Enabled := false;
2688                Copy1.Enabled := false;
2689                Paste1.Enabled := false;
2690                Diagnosis1.Enabled := false;
2691                Exit;
2692                end;
2693  
2694             if (thisChangeItem <> nil) then
2695                begin
2696                thisOrderList.Clear;
2697                thisOrderList.Add(thisChangeItem.ID);
2698                // Returns True if All selected orders are N/A, Order selected are NON CIDC or DC'd
2699                if UBACore.IsAllOrdersNA(thisOrderList) then
2700                   begin
2701                   Diagnosis1.Enabled := false;
2702                   buDiagnosis.Enabled := false;
2703                   end
2704                else
2705                   begin
2706                   Diagnosis1.Enabled := true;
2707                   buDiagnosis.Enabled := true;
2708                   end
2709                end
2710             else
2711                begin
2712                buDiagnosis.Enabled := false;
2713                Diagnosis1.Enabled := False;
2714                Break;
2715                end;
2716             end;
2717          end;
2718    except
2719       on EListError do
2720          begin
2721          {$ifdef debug}Show508Message('EListError in fReview.lstReviewClick()');{$endif}
2722          raise;
2723          end;
2724    end;
2725   {End BillingAware}
2726   end;    
2727   if Assigned(thisOrderList) then thisOrderList.Free;
2728  end;
2729  
2730  procedure TfrmReview.Exit1Click(Sender: TObject);
2731  begin
2732    Close;
2733  end;
2734  
2735  procedure TfrmReview.lstReviewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
2736  {
2737     - Open copy/paste popup menu.
2738  }
2739  var
2740    ClientPoint: TPoint;
2741    ScreenPoint: TPoint;
2742    thisChangeItem: TChangeItem;
2743    i: integer;
2744  begin
2745    if not BILLING_AWARE then lstReview.PopupMenu := nil;
2746  
2747    if BILLING_AWARE then
2748       begin
2749          if Button = mbRight then  //Right-click to open copy/paste popup menu
2750             begin
2751             //CQ3325
2752             if frmReview.lstReview.Items.Count = 3 then
2753                begin
2754                Copy1.Enabled := false;
2755                Paste1.Enabled := false
2756                end
2757             else
2758                begin
2759                Copy1.Enabled := true;
2760                end;
2761  
2762       //CQ HDS00002954 Fix
2763       if Button = mbRight then
2764           //Disallow copying of a grid HEADER item
2765          for i := 0 to lstReview.Items.Count - 1 do
2766                if lstReview.Selected[i] then
2767                   begin
2768                  
2769                   thisChangeItem := TChangeItem(lstReview.Items.Objects[i]);
2770  
2771                    if thisChangeItem = nil then
2772                       begin
2773                       lstReview.Selected[i] := false;
2774                       Copy1.Enabled := false;
2775                       Paste1.Enabled := false;
2776                       Exit;
2777                       end;
2778                    end;
2779                      
2780           if not frmReview.lstReview.Selected[lstReview.ItemIndex] then
2781              (Sender as TCheckListBox).Selected[lstReview.ItemIndex] := true;
2782  
2783           ClientPoint.X := X;
2784           ClientPoint.Y := Y;
2785           ScreenPoint := lstReview.ClientToScreen(ClientPoint);
2786           poBACopyPaste.Popup(ScreenPoint.X, ScreenPoint.Y);
2787           end;
2788        end;
2789  end;
2790  
2791  procedure TfrmReview.Copy1Click(Sender: TObject);
2792  {
2793     - Copy contents of the 'source' order for copy/paste operation
2794  }
2795  var
2796    i : byte;
2797    numSelected: byte;
2798    thisChangeItem: TChangeItem;
2799  begin
2800    try
2801       if BILLING_AWARE then
2802          begin
2803          Paste1.Enabled := true;
2804  
2805           numSelected := GetNumberOfSelectedOrders;
2806  
2807           if numSelected > 1 then
2808             begin
2809             ShowMsg('Only 1 order at a time may be selected for ''Copying''');
2810             Exit;
2811             end;
2812  
2813              
2814           for i := 1 to frmReview.lstReview.Items.Count-1 do
2815               if (frmReview.lstReview.Selected[i]) then
2816                 begin
2817                 thisChangeItem := TChangeItem.Create;
2818                 thisChangeItem := nil;
2819                 thisChangeItem := TChangeItem(lstReview.Items.Objects[i]);
2820                 
2821                 //Skip this one if it's a "header" on the grid
2822                   if (thisChangeItem = nil) then 
2823                      begin
2824                      if Assigned(thisChangeItem) then FreeAndNil(thisChangeItem);
2825                      Exit;
2826                      end;
2827  
2828                 fReview.srcOrderID := TChangeItem(frmReview.lstReview.Items.Objects[i]).ID;
2829  
2830                 //Copy source order to COPY BUFFER and add it to the Dx List
2831                 CopyBuffer := TBADxRecord.Create;
2832                 InitializeNewDxRec(CopyBuffer);
2833                 GetBADxListForOrder(CopyBuffer, fReview.srcOrderID);
2834                 fReview.CopyBuffer.FOrderID := BUFFER_ORDER_ID;
2835                 UBAGlobals.tempDxList.Add(CopyBuffer);
2836  
2837                 //***********************************************************************
2838                 if Not UBACore.IsOrderBillable(fReview.srcOrderID) then 
2839                   begin
2840                   ShowMsg(BA_NA_COPY_DISALLOWED);
2841                   fReview.srcOrderID := '';
2842                   Exit;
2843                   end;
2844                   //***********************************************************************
2845  
2846                 fReview.srcIndex := lstReview.ItemIndex;
2847                 fReview.chkBoxStatus := GetCheckBoxStatus(fReview.srcOrderID);
2848                 Break;
2849                 end;
2850          end; //if BILLING_AWARE
2851     except
2852       on EListError do
2853          begin
2854          {$ifdef debug}Show508Message('EListError in fReview.Copy1Click()');{$endif}
2855          raise
2856          end;
2857     end;
2858  end;
2859  
2860  procedure TfrmReview.Paste1Click(Sender: TObject);
2861  {
2862    - Populate 'target' orders of a copy/paste operation with contents of 'source' order
2863  }
2864  var
2865    i: byte;
2866    thisChangeItem: TChangeItem;
2867    newRec: TBADxRecord;
2868  begin
2869    if BILLING_AWARE then
2870       begin
2871        if not Assigned(fReview.CopyBuffer) then //CQ5414
2872          fReview.CopyBuffer := TBADxRecord.Create; //CQ5414
2873          
2874    try
2875        for i := 1 to lstReview.Count - 1 do
2876            begin
2877            if (frmReview.lstReview.Selected[i]) then
2878              begin
2879              thisChangeItem := TChangeItem(lstReview.Items.Objects[i]);
2880  
2881              //Skip this one if it's a "header" on the grid
2882              if (thisChangeItem = nil) then
2883                Continue;
2884  
2885              if (fReview.frmReview.lstReview.Selected[i]) then
2886                begin
2887                fReview.targetOrderID := TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).ID;
2888  
2889                 if fReview.targetOrderID = fReview.srcOrderID then //disallow copying an order to itself
2890                    Continue
2891                 else
2892                    begin
2893                    fReview.CopyBuffer.FOrderID := BUFFER_ORDER_ID;
2894  
2895                    //***************************************************************
2896                    if (NOT UBACore.IsOrderBillable(fReview.targetOrderID) ) then
2897                     begin
2898                      ShowMsg(BA_NA_PASTE_DISALLOWED);
2899                      fReview.targetOrderID := '';
2900                      Continue;
2901                      end;
2902                    //***************************************************************
2903  
2904                    newRec := TBADxRecord.Create;
2905                    with newRec do
2906                      begin
2907                        FOrderID := fReview.targetOrderID;
2908                        FBADxCode := CopyBuffer.FBADxCode;
2909                        FBASecDx1 := CopyBuffer.FBASecDx1;
2910                        FBASecDx2 := CopyBuffer.FBASecDx2;
2911                        FBASecDx3 := CopyBuffer.FBASecDx3;
2912                      end;
2913  
2914                      tempDxList.Add(newRec);
2915  
2916                      CopyTFCIToTargetOrder(fReview.targetOrderID, fReview.chkBoxStatus);
2917                       SetCheckBoxStatus(fReview.targetOrderID);  //calls uSignItems.SetSigItems()
2918                  end; //else
2919              end; //if
2920            end //if
2921        else
2922          Continue
2923          end; //for
2924    except
2925       on EListError do
2926          begin
2927          {$ifdef debug}Show508Message('EListError in fReview.Paste1Click()');{$endif}
2928          raise;
2929          end;
2930    end;
2931  
2932    end; //if BILLING_AWARE
2933  
2934    lstReview.Refresh; //Update grid to show pasted Dx/TF/CI
2935  
2936  end;
2937  
2938  procedure TfrmReview.ClearDiagnoses1Click(Sender: TObject);
2939  var
2940    selectedOrderIDList: TStringList;
2941    i:integer;
2942  begin
2943    selectedOrderIDList := TStringList.Create;
2944    selectedOrderIDList.Clear;
2945  
2946    try
2947     for i := 0 to fReview.frmReview.lstReview.Items.Count-1 do
2948        begin
2949           if (fReview.frmReview.lstReview.Selected[i]) then
2950              selectedOrderIDList.Add(TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).ID);
2951        end;
2952     except
2953       on EListError do
2954          begin
2955          {$ifdef debug}Show508Message('EListError in fReview.ClearDiagnoses1Click()');{$endif}
2956          raise;
2957          end;
2958     end;
2959  
2960     UBACore.ClearSelectedOrderDiagnoses(selectedOrderIDList);
2961  end;
2962  
2963  function TfrmReview.GetNonNilItemCount : integer;
2964  //CQ5172
2965  var
2966    i: integer;
2967    thisItem: TChangeItem;
2968    howMany: integer;
2969  begin
2970    howMany := 0;
2971  
2972    for i := 0 to lstReview.Items.Count-1 do
2973       begin
2974       thisItem := TChangeItem(lstReview.Items.Objects[i]);
2975       if thisItem <> nil then
2976          Inc(howMany);
2977       end;
2978    Result := howMany;
2979  end;
2980  
2981  procedure TfrmReview.FormShow(Sender: TObject);
2982  var
2983    numOrderItems: integer;
2984  begin
2985    if pnlSignature.Visible then
2986    else
2987    if pnlOrderAction.Visible then
2988    else
2989      
2990       //INITIALIZATIONS
2991        Paste1.Enabled := false;
2992        fReview.srcOrderID := '';
2993        fReview.srcDx := '';
2994  
2995       if  BILLING_AWARE then
2996          frmReview.lstReview.Multiselect := true;
2997  
2998    FormatListForScreenReader;
2999  
3000    //CQ5172
3001    numOrderItems := GetNonNilItemCount;
3002   if BILLING_AWARE then
3003   begin
3004    if (numOrderItems = 1) then
3005    begin
3006     lstReview.Selected[0] := false;
3007     buDiagnosis.Enabled := True;
3008     Diagnosis1.Enabled := True;
3009     lstReview.Selected[1] := true;
3010       // ** if number of orders is 1 and order is billable select order and disable diagnosis button
3011     if NOT UBACore.IsOrderBillable(TChangeItem(frmReview.lstReview.Items.Objects[1]).ID) then
3012     begin
3013        buDiagnosis.Enabled := False;
3014        Diagnosis1.Enabled := False;
3015        lstReview.Selected[1] := false;
3016     end
3017     else
3018        if Piece(TChangeItem(frmReview.lstReview.Items.Objects[1]).ID,';',2) = DISCONTINUED_ORDER then
3019        begin
3020             buDiagnosis.Enabled := False;
3021             Diagnosis1.Enabled :=False ;
3022        end;
3023    end
3024    else
3025       lstReview.Selected[0] := false;
3026    //end CQ5172
3027  end;
3028  end;
3029  
3030  procedure TfrmReview.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
3031  var
3032    j: integer; //CQ5054
3033  begin
3034    inherited;
3035    currentlySelectedItem := frmReview.lstReview.ItemIndex; //CQ5063
3036  
3037      case Key of
3038          67,99:  if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorSC,fraCoPay.lblSC2); //C,c
3039          86,118: if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorCV,fraCoPay.lblCV2); //V,v
3040          79,111: if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorAO,fraCoPay.lblAO2); //O,o
3041          82,114: if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorIR,fraCoPay.lblIR2); //R,r
3042          65,97:  if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorEC,fraCoPay.lblSWAC2); //A,a
3043          77,109: if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorMST,fraCoPay.lblMST2); //M,m
3044          78,110: if (ssAlt in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorHNC,fraCoPay.lblHNC2); //N,n
3045          72,104: if (ssALT in Shift) then ShowTreatmentFactorHints(BAFactorsRec.FBAFactorSHAD,fraCopay.lblSHAD2); // H,h
3046          //CQ5054
3047          83,115: if (ssAlt in Shift) then
3048                  begin
3049                  for j := 0 to lstReview.Items.Count-1 do
3050                          lstReview.Selected[j] := false;
3051                  lstReview.Selected[1] := true;
3052                  lstReview.SetFocus;
3053                  end;
3054          09:
3055              if FRVTFhintWindowActive then
3056               begin
3057                  FRVTFHintWindow.ReleaseHandle;
3058                  FRVTFHintWindowActive := False;
3059               end;
3060  
3061          //end CQ5054
3062      end;
3063  end;
3064  
3065  procedure TfrmReview.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
3066  begin
3067    //CQ5063
3068    if Key = VK_SPACE then
3069       begin
3070       if lstReview.Focused then //CQ6657
3071       begin
3072       lstReview.Selected[lstReview.Items.Count-1] := false;
3073       lstReview.Selected[currentlySelectedItem] := true;
3074       end;
3075       end;
3076    //end CQ5063
3077  end;
3078  
3079  //BILLING AWARE Procedure
3080  procedure TfrmReview.ShowTreatmentFactorHints(var pHintText: string; var pCompName: TVA508StaticText); // 508
3081  var
3082   HRect: TRect;
3083   thisRect: TRect;
3084   x,y: integer;
3085  
3086  begin
3087    if FRVTFhintWindowActive then
3088    begin
3089       FRVTFHintWindow.ReleaseHandle;
3090       FRVTFHintWindowActive := False;
3091    end;
3092  
3093     FRVTFHintWindow := THintWindow.Create(frmReview); //(frmReview);
3094     FRVTFHintWindow.Color := clInfoBk;
3095     GetWindowRect(pCompName.Handle,thisRect);
3096     x := thisRect.Left;
3097     y := thisRect.Top;
3098     hrect := FRVTFHintWindow.CalcHintRect(Screen.Width, pHintText,nil);
3099     hrect.Left   := hrect.Left + X;
3100     hrect.Right  := hrect.Right + X;
3101     hrect.Top    := hrect.Top + Y;
3102     hrect.Bottom := hrect.Bottom + Y;
3103  
3104     fraCoPay.LabelCaptionsOn(not FRVTFHintWindowActive);
3105  
3106     FRVTFHintWindow.ActivateHint(hrect, pHintText);
3107     FRVTFHintWindowActive := True;
3108  end;
3109  
3110  
3111  procedure TfrmReview.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
3112    Y: Integer);
3113  begin
3114      if FRVTFHintWindowActive then
3115      begin
3116         FRVTFHintWindow.ReleaseHandle;
3117         FRVTFHintWindowActive := False;
3118      end;
3119  end;
3120  
3121  procedure TfrmReview.FormPaint(Sender: TObject);
3122  begin
3123    inherited;
3124  
3125    if frmReview.lstCSReview.count = 0 then
3126    begin
3127     frmReview.lstReview.Height := frmReview.pnlReview.Height - frmReview.lstReview.Top - 4;
3128     frmReview.lstReview.Width := frmReview.pnlReview.Width - frmReview.lstReview.Left - 4;
3129    end;
3130    if frmReview.lstReview.count = 0 then
3131    begin
3132     frmReview.lstCSReview.Height := frmReview.pnlCSReview.Height - frmReview.lstCSReview.Top - 4;
3133     frmReview.lstCSReview.Width := frmReview.pnlCSReview.Width - frmReview.lstCSReview.Left - 4;
3134    end;
3135  end;
3136  
3137  procedure TfrmReview.FormResize(Sender: TObject);
3138  VAR
3139   I, ColHeight: Integer;
3140  begin
3141    inherited;  
3142  
3143    if frmReview.lstCSReview.count = 0 then
3144    begin
3145     frmReview.lstReview.Height := frmReview.pnlReview.Height - frmReview.lstReview.Top - 4;
3146     frmReview.lstReview.Width := frmReview.pnlReview.Width - frmReview.lstReview.Left - 4;
3147    end;
3148    if frmReview.lstReview.count = 0 then
3149    begin
3150     frmReview.lstCSReview.Height := frmReview.pnlCSReview.Height - frmReview.lstCSReview.Top - 4;
3151     frmReview.lstCSReview.Width := frmReview.pnlCSReview.Width - frmReview.lstCSReview.Left - 4;
3152    end;
3153    if lstReview.Count > 0 then begin
3154     for I := 1 to lstReview.Count - 1 do begin
3155      lstReviewMeasureItem(lstReview, I, ColHeight);
3156      lstReview.Perform(LB_SETITEMHEIGHT,I,ColHeight);
3157     end;
3158    end;
3159    RedrawWindow(lstReview.Handle, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
3160  end;
3161  
3162  procedure TfrmReview.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
3163  begin
3164    if FRVTFHintWindowActive then
3165    begin
3166       FRVTFHintWindow.ReleaseHandle;
3167       FRVTFHintWindowActive := False;
3168       Application.ProcessMessages;
3169    end;
3170  end;
3171  
3172  procedure TfrmReview.fraCoPayLabel24MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
3173  begin
3174    fraCoPay.LabelCaptionsOn(not FRVTFHintWindowActive);
3175  end;
3176  
3177  procedure TfrmReview.FormClose(Sender: TObject; var Action: TCloseAction);
3178  begin
3179  
3180      if FRVTFHintWindowActive then
3181      begin
3182         FRVTFhintWindow.ReleaseHandle ;
3183         FRVTFHintWindowActive := False ;
3184  
3185        with fraCopay do
3186          begin
3187          //Long captions
3188          lblSC.ShowHint := false;
3189          lblCV.ShowHint := false;
3190          lblAO.ShowHint := false;
3191          lblIR.ShowHint := false;
3192          lblSWAC.ShowHint := false;
3193          lblHNC.ShowHint  := false;
3194          lblHNC2.ShowHint := false;
3195          lblSHAD2.ShowHint := false;
3196          end;
3197   end;
3198  
3199  // HDS00005143 - if cidc master sw is on and  BANurseConsultOrders.Count > 0 then
3200  // save those orders with selected DX enteries.  Resulting in dx populated for provider.
3201   if rpcGetBAMasterSwStatus then
3202   begin
3203      if  BANurseConsultOrders.Count > 0 then
3204      begin
3205         rpcSaveNurseConsultOrder(BANurseConsultOrders);
3206         BANurseConsultOrders.Clear;
3207      end;
3208   end;
3209  end;
3210  
3211  procedure TfrmReview.SetItemTextToState;
3212  var
3213    i : integer;
3214  begin
3215  
3216    if fReview.frmReview.lstReview.Count < 1 then Exit;
3217    for i := 0 to fReview.frmReview.lstReview.Count-1 do
3218      if fReview.frmReview.lstReview.Items.Objects[i] <> nil then //Not a Group Title
3219      begin
3220        if fReview.frmReview.lstReview.Items.Objects[i] is TChangeItem then
3221        if fReview.frmReview.lstReview.Checked[i] then
3222          fReview.frmReview.lstReview.Items[i] := 'Checked '+TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).Text
3223        else
3224          fReview.frmReview.lstReview.Items[i] := 'Not Checked '+TChangeItem(fReview.frmReview.lstReview.Items.Objects[i]).Text;
3225      end;
3226    if fReview.frmReview.lstReview.ItemIndex >= 0 then
3227      fReview.frmReview.lstReview.Selected[fReview.frmReview.lstReview.ItemIndex] := True;
3228  end;
3229  
3230  procedure TfrmReview.lstReviewKeyUp(Sender: TObject; var Key: Word;
3231    Shift: TShiftState);
3232  begin
3233    if (Key = VK_Space) then
3234      FormatListForScreenReader
3235  end;
3236  
3237  procedure TfrmReview.FormatListForScreenReader;
3238  begin
3239    if ScreenReaderActive then
3240      SetItemTextToState;
3241  end;
3242  
3243  end.

Module Calls (2 levels)


fReview
 ├UBAGlobals
 │ ├uConst
 │ ├rOrders
 │ ├fBALocalDiagnoses
 │ ├fOrdersSign
 │ ├fReview...
 │ ├uCore
 │ ├rCore
 │ ├UBAConst
 │ └UBACore
 ├uConst
 ├uCore...
 ├mCoPayDesc
 │ ├rPCE
 │ └UBAGlobals...
 ├XuDsigS
 │ ├wcrypt2
 │ ├XuDsigU
 │ ├XlfMime
 │ ├XuDsigConst
 │ ├WinSCard
 │ └fPINPrompt
 ├UBACore...
 ├fBase508Form
 │ ├uConst
 │ └uHelpManager
 ├fPrintLocation
 │ ├fAutoSz
 │ ├rCore...
 │ ├uCore...
 │ └fFrame
 ├fCSRemaining
 │ ├uCore...
 │ └rOrders...
 ├rODMeds
 │ ├uCore...
 │ └uConst
 ├rCore...
 ├fNotes
 │ ├fHSplit
 │ ├uConst
 │ ├uPCE
 │ ├fDrawers
 │ ├rTIU
 │ ├uTIU
 │ ├uDocTree
 │ ├fRptBox
 │ ├fPrintList
 │ ├fNoteST
 │ ├fNoteSTStop
 │ ├fFrame...
 │ ├fEncnt
 │ ├rCore...
 │ ├uCore...
 │ ├fNoteBA
 │ ├fNoteBD
 │ ├fSignItem
 │ ├fEncounterFrame
 │ ├rPCE...
 │ ├fNotePrt
 │ ├fAddlSigners
 │ ├fNoteDR
 │ ├fConsults
 │ ├uSpell
 │ ├fTIUView
 │ ├fTemplateEditor
 │ ├uReminders
 │ ├fReminderDialog
 │ ├uOrders
 │ ├rConsults
 │ ├fReminderTree
 │ ├fNoteProps
 │ ├fNotesBP
 │ ├fTemplateFieldEditor
 │ ├dShared
 │ ├rTemplates
 │ ├fIconLegend
 │ ├fPCEEdit
 │ ├fNoteIDParents
 │ ├rSurgery
 │ ├uTemplates
 │ ├fTemplateDialog
 │ ├uInit
 │ └uVA508CPRSCompatibility
 ├fConsults...
 ├rOrders...
 ├fDCSumm
 │ ├fHSplit...
 │ ├uConst
 │ ├uPCE...
 │ ├fDrawers...
 │ ├rDCSumm
 │ ├uDocTree...
 │ ├uDCSumm
 │ ├uTIU
 │ ├fPrintList...
 │ ├fFrame...
 │ ├fEncnt...
 │ ├rCore...
 │ ├uCore...
 │ ├fNoteBA...
 │ ├fNoteBD...
 │ ├fSignItem...
 │ ├fEncounterFrame...
 │ ├rPCE...
 │ ├fNotePrt...
 │ ├fAddlSigners...
 │ ├fNoteDR...
 │ ├uSpell...
 │ ├fTIUView...
 │ ├fTemplateEditor...
 │ ├rTIU...
 │ ├fDCSummProps
 │ ├fNotesBP...
 │ ├fTemplateFieldEditor...
 │ ├uTemplates...
 │ ├fReminderDialog...
 │ ├dShared...
 │ ├rTemplates...
 │ ├fIconLegend...
 │ ├fNoteIDParents...
 │ ├fTemplateDialog...
 │ └uVA508CPRSCompatibility...
 ├fOCSession
 │ ├fOCMonograph
 │ ├fAutoSz...
 │ ├uConst
 │ ├rOrders...
 │ ├uCore...
 │ ├rMisc
 │ └fFrame...
 ├uOrders...
 ├fSignItem...
 ├fFrame...
 ├uSignItems
 │ ├fODBase
 │ ├UBACore...
 │ ├uConst
 │ ├rOrders...
 │ ├fOrdersSign...
 │ ├fReview...
 │ ├UBAGlobals...
 │ └uCore...
 ├fSurgery
 │ ├fHSplit...
 │ ├uConst
 │ ├uPCE...
 │ ├fDrawers...
 │ ├fSurgeryView
 │ ├rSurgery...
 │ ├uSurgery
 │ ├uCaseTree
 │ ├uTIU
 │ ├fFrame...
 │ ├fEncnt...
 │ ├rCore...
 │ ├uCore...
 │ ├fSignItem...
 │ ├fEncounterFrame...
 │ ├rPCE...
 │ ├fNotePrt...
 │ ├fAddlSigners...
 │ ├fNoteDR...
 │ ├fConsults...
 │ ├uSpell...
 │ ├fTemplateEditor...
 │ ├uReminders...
 │ ├fReminderDialog...
 │ ├fReminderTree...
 │ ├fNoteProps...
 │ ├fNotesBP...
 │ ├fTemplateFieldEditor...
 │ ├uTemplates...
 │ ├dShared...
 │ ├rTemplates...
 │ ├fIconLegend...
 │ ├fPCEEdit...
 │ ├rTIU...
 │ └fTemplateDialog...
 ├fBALocalDiagnoses...
 ├UBAConst
 ├UBAMessages
 ├fOrdersSign...
 ├rODLab
 │ └uCore...
 └fRptBox...

Module Called-By (2 levels)


                fReview
           UBAGlobals┤ 
            rOrders┤ │ 
            uOrders┤ │ 
            fODBase┤ │ 
            UBACore┤ │ 
             fFrame┤ │ 
            fOrders┤ │ 
  fBALocalDiagnoses┤ │ 
            fPCELex┤ │ 
               rPCE┤ │ 
         fDiagnoses┤ │ 
             fPtSel┤ │ 
        fOrdersSign┤ │ 
         mCoPayDesc┤ │ 
         fReview...┤ │ 
fBAOptionsDiagnoses┤ │ 
         uSignItems┤ │ 
       fOrdersRenew┤ │ 
         fODConsult┤ │ 
       fEditConsult┤ │ 
     fOrdersRelease┘ │ 
           UBACore...┤ 
            fFrame...┤ 
 fBALocalDiagnoses...┤ 
               fEncnt┤ 
         uOrders...┤ │ 
          fFrame...┤ │ 
            fVitals┤ │ 
             fNotes┤ │ 
             fProbs┤ │ 
          fConsults┤ │ 
            fDCSumm┤ │ 
           fSurgery┤ │ 
           fPCEEdit┘ │ 
        uSignItems...┘