Module

uOrders

Path

C:\CPRS\CPRS30\Orders\uOrders.pas

Last Modified

7/15/2014 3:26:42 PM

Initialization Code

initialization
  uPatientLocked := False;
  uKeepLock      := False;
  uLastConfirm   := '';
  uOrderSetTime  := 0;
  uNewMedDialog  := 0;
  uOrderAction   := nil;
  uOrderDialog   := nil;
  uOrderHTML     := nil;
  uOrderMenu     := nil;
  uOrderSet      := nil;
  NSSchedule     := False;
  OriginalMedsOutHeight   := 0;
  OriginalMedsInHeight    := 0;
  OriginalNonVAMedsHeight := 0;

end.

Units Used in Interface

Name Comments
fODBase -
fODMedOIFA -
rConsults -
rOrders -
uConst -
XuDsigS -

Units Used in Implementation

Name Comments
fARTAllgy -
fClinicWardMeds -
fEffectDate -
fEncnt -
fFrame -
fLkUpLocation -
fMeds -
fODAuto -
fODBBank -
fODChangeUnreleasedRenew -
fODChild -
fODConsult -
fODDiet -
fODGen -
fODLab -
fODMedIn -
fODMedIV -
fODMedNVA -
fODMedOut -
fODMeds -
fODMisc -
fODProc -
fODRad -
fODText -
fODVitals -
fOMAction -
fOMHTML -
fOMNavA -
fOMSet -
fOMVerify -
fOrders -
fOrderSaveQuick -
fOrdersPrint -
fRptBox -
rCore -
rMeds -
rMisc -
rODAllergy -
rODBase -
rODMeds -
rPCE -
UBAGlobals -
uCore -
uODBase -
uTemplateFields -

Classes

Name Comments
EOrderDlgFail -

Procedures

Name Owner Declaration Scope Comments
AddSelectedToChanges - procedure AddSelectedToChanges(AList: TList); Interfaced Update Changes with orders that were created by taking actions
ChangeOrders - procedure ChangeOrders(AList: TStringList; AnEvent: TOrderDelayEvent); Interfaced -
DeselectChild - procedure DeselectChild(AnIdxList: TStringList); Local -
DestroyingOrderAction - procedure DestroyingOrderAction; Interfaced -
DestroyingOrderDialog - procedure DestroyingOrderDialog; Interfaced -
DestroyingOrderHTML - procedure DestroyingOrderHTML; Interfaced -
DestroyingOrderMenu - procedure DestroyingOrderMenu; Interfaced -
DestroyingOrderSet - procedure DestroyingOrderSet; Interfaced -
InitialOrderVariables - procedure InitialOrderVariables; Interfaced -
NextMove - procedure NextMove(var NMRec: TNextMoveRec; LastIndex: Integer; NewIndex: Integer); Interfaced -
PopLastMenu - procedure PopLastMenu; Interfaced Always called from fOMSet
PrintOrdersOnSignRelease - procedure PrintOrdersOnSignRelease(OrderList: TStringList; Nature: Char; PrintLoc : Integer =0; PrintName: string = ''); Interfaced -
PrintOrdersOnSignReleaseMult - procedure PrintOrdersOnSignReleaseMult(OrderList, ClinicLst, WardLst: TStringList; Nature: Char; EncLoc, WardLoc: integer; EncLocName, WardLocName: string); Interfaced -
QuickOrderListEdit - procedure QuickOrderListEdit; Interfaced -
QuickOrderSave - procedure QuickOrderSave; Interfaced -
ResetDialogProperties - procedure ResetDialogProperties(const AnID: string; AnEvent: TOrderDelayEvent; var ResolvedDialog: TOrderDialogResolved); Interfaced -
RetrieveOrderTextPSI - procedure RetrieveOrderTextPSI(AOrderList: TStringList; var AODTextList, AnIdxList: TStringList; TheAction: string; AParentID: string = ''); Local -
SetConfirmEventDelay - procedure SetConfirmEventDelay; Interfaced -
SetFontSize - procedure SetFontSize( FontSize: integer); Interfaced -
UnlockIfAble - procedure UnlockIfAble; Interfaced -
UnlockOrderIfAble - procedure UnlockOrderIfAble(OrderID: string); Interfaced -

Functions

Name Owner Declaration Scope Comments
ActivateAction - function ActivateAction(const AnID: string; AnOwner: TComponent; ARefNum: Integer): Boolean; Interfaced
Write Orders
Write New Orders 

 AnID: DlgIEN {;FormID;DGroup}
ActivateOrderDialog - function ActivateOrderDialog(const AnID: string; AnEvent: TOrderDelayEvent; AnOwner: TComponent; ARefNum: Integer; ANeedVerify: boolean = True): Boolean; Interfaced CsltFrmID: integer;
ActivateOrderHTML - function ActivateOrderHTML(const AnID: string; AnEvent: TOrderDelayEvent; AnOwner: TComponent; ARefNum: Integer): Boolean; Interfaced -
ActivateOrderList - function ActivateOrderList(AList: TStringList; AnEvent: TOrderDelayEvent; AnOwner: TComponent; ARefNum: Integer; const KeyVarStr, ACaption: string): Boolean; Interfaced -
ActivateOrderMenu - function ActivateOrderMenu(const AnID: string; AnEvent: TOrderDelayEvent; AnOwner: TComponent; ARefNum: Integer): Boolean; Interfaced -
ActivateOrderSet - function ActivateOrderSet(const AnID: string; AnEvent: TOrderDelayEvent; AnOwner: TComponent; ARefNum: Integer): Boolean; Interfaced -
ActiveOrdering - function ActiveOrdering: Boolean; Interfaced -
AllowActionOnIMO - function AllowActionOnIMO(AnEvtTyp: char): boolean; Interfaced -
AuthorizedToVerify - function AuthorizedToVerify: Boolean; Interfaced -
AuthorizedUser - function AuthorizedUser: Boolean; Interfaced Ordering Environment
ChangeOrdersEvt - function ChangeOrdersEvt(AnOrderID: string; AnEvent: TOrderDelayEvent): boolean; Interfaced -
CloseOrdering - function CloseOrdering: Boolean; Interfaced -
CopyOrders - function CopyOrders(AList: TStringList; AnEvent: TOrderDelayEvent; var DoesEventOccur: boolean; ANeedVerify: boolean = True): boolean; Interfaced -
CreateOrderDialog - function CreateOrderDialog(Sender: TComponent; FormID: integer; AnEvent: TOrderDelayEvent; ODEvtID: integer = 0): TfrmODBase; Global -
EncounterPresent - function EncounterPresent(ErrorMsg: String = ''): Boolean; Interfaced Make sure a location and provider are selected, returns false if not
EncounterPresentEDO - function EncounterPresentEDO: Boolean; Interfaced -
GMRCCanCloseDialog - function GMRCCanCloseDialog(dialog : TfrmODBase) : Boolean; Global -
IMOActionValidation - function IMOActionValidation(AnId: string; var IsIMOOD: boolean; var x: string; AnEventType: char): boolean; Interfaced -
IMOTimeFrame - function IMOTimeFrame: TFMDateTime; Interfaced CQ #15188 - New function to allow IMO functionality 23 hours after encounter date/time - TDP
IsIMODialog - function IsIMODialog(DlgID: integer): boolean; Interfaced
Inpatient medication for Outpatient
function GetQOAltOI: integer;
begin
  Result := QOAltOI.OI;
end; 

IMO
IsInvalidActionWarning - function IsInvalidActionWarning(const AnOrderText,AnOrderID: String): boolean; Interfaced -
IsValidActionOnComplexOrder - function IsValidActionOnComplexOrder(AnOrderID, AnAction: string; AListBox: TListBox; var CheckedList: TStringList; var ErrMsg: string; var ParentOrderID: string): boolean; Interfaced -
LockedForOrdering - function LockedForOrdering: Boolean; Interfaced -
MakeMessage - function MakeMessage(ErrMsg1,ErrMsg2,ErrMsg3: string): string; Local -
OrderCanBeLocked - function OrderCanBeLocked(OrderID: string): Boolean; Interfaced -
OrderIsLocked - function OrderIsLocked(const AnOrderID, AnAction: string): Boolean; Interfaced -
ReadyForNewOrder - function ReadyForNewOrder(AnEvent: TOrderDelayEvent): Boolean; Interfaced -
ReadyForNewOrder1 - function ReadyForNewOrder1(AnEvent: TOrderDelayEvent): Boolean; Interfaced -
RefNumFor - function RefNumFor(AnOwner: TComponent): Integer; Interfaced -
RetrieveOrderText - function RetrieveOrderText(AnOrderID: string): string; Interfaced I: integer;
SetSAN - function SetSAN(Self: TComponent): string; Interfaced -
TakeoutDuplicateDlg - function TakeoutDuplicateDlg(var AdlgList: TStringList; ANeedle: string): boolean; Local -
TransferOrders - function TransferOrders(AList: TStringList; AnEvent: TOrderDelayEvent; var DoesEventOccur: boolean; ANeedVerify: boolean = True): boolean; Interfaced
DoesEventOccur: boolean;
OccuredEvtID: integer;
OccuredEvtName: string;

Global Variables

Name Type Declaration Comments
ClinDisp Integer ClinDisp : Integer; IMO
CsltDisp Integer CsltDisp : Integer; -
DietDisp Integer DietDisp : Integer; -
ImgDisp Integer ImgDisp : Integer; -
InptDisp Integer InptDisp : Integer; -
IVDisp Integer IVDisp : Integer; -
MedsDisp Integer MedsDisp : Integer; -
MedsInDlgFormId Integer MedsInDlgFormId : Integer; -
MedsInDlgIen Integer MedsInDlgIen : Integer; -
MedsIVDlgFormID Integer MedsIVDlgFormID: Integer; -
MedsIVDlgIen Integer MedsIVDlgIen: Integer; -
MedsNVADlgFormID Integer MedsNVADlgFormID : Integer; -
MedsNVADlgIen Integer MedsNVADlgIen : Integer; -
MedsOutDlgFormId Integer MedsOutDlgFormId : Integer; -
MedsOutDlgIen Integer MedsOutDlgIen : Integer; -
NonVADisp Integer NonVADisp: Integer; -
NSSchedule Boolean NSSchedule: boolean; -
NurDisp Integer NurDisp : Integer; -
OriginalMedsInHeight Integer OriginalMedsInHeight: Integer; -
OriginalMedsOutHeight Integer OriginalMedsOutHeight: Integer; -
OriginalNonVAMedsHeight Integer OriginalNonVAMedsHeight: Integer; -
OutptDisp Integer OutptDisp: Integer; -
PassDrugTstCall Boolean PassDrugTstCall: boolean; -
ProcDisp Integer ProcDisp : Integer; -
uAutoAc Boolean uAutoAc: Boolean; -
uKeepLock Boolean uKeepLock: Boolean; -
uLastConfirm UnicodeString uLastConfirm: string; -
uNewMedDialog Integer uNewMedDialog: Integer; -
uOrderAction TfrmOMAction uOrderAction: TfrmOMAction; -
uOrderDialog TfrmODBase uOrderDialog: TfrmODBase; -
uOrderHTML TfrmOMHTML uOrderHTML: TfrmOMHTML; -
uOrderMenu TfrmOMNavA uOrderMenu: TfrmOMNavA; -
uOrderSet TfrmOMSet uOrderSet: TfrmOMSet; -
uOrderSetTime TFMDateTime uOrderSetTime: TFMDateTime; -
uPatientLocked Boolean uPatientLocked: Boolean; -

Constants

Name Declaration Scope Comments
STEP_BACK -1 Global -
STEP_FORWARD 1 Global -
TC_BADKEYS 'Multiple Keys' Global -
TC_DELAY 'Ordering Information' Global -
TC_DISABLED 'Item Disabled' Global -
TC_DLG_ERR 'Dialog Error' Global -
TC_DLG_REJECT 'Unable to Order' Global -
TC_NO_CHANGE 'Unable to Change Order' Global -
TC_NO_COPY 'Unable to Copy Order' Global -
TC_NO_EDIT_QO 'Edit Common List' Global -
TC_NO_LOCK 'Unable to Lock' Global -
TC_NO_QUICK 'Save/Edit Quick Orders' Global -
TC_NO_SAVE_QO 'Save as Quick Order' Global -
TC_NO_XFER 'Unable to Transfer Order' Global -
TC_NOFORM 'Missing Form ID' Global -
TC_NOKEY 'Insufficient Authority' Global -
TC_NOLOCK 'Unable to Lock Order' Global -
TC_PROV_KEY 'PROVIDER Key Required' Global -
TC_PROV_LOC 'Incomplete Information' Global -
TC_STOP_SET 'Interupt order set' Global -
TX_BADKEYS 'You have mutually exclusive order entry keys (ORES, ORELSE, or OREMAS).' + Global -
TX_CANT_SAVE_QO 'This order contains TIU objects, which may result in patient-specific' + CRLF + Global -
TX_COMPLEX 'You can not take this action on a complex medication.' + #13 + 'You must enter a new order.' Global -
TX_DELAY 'Now writing orders for ' Global -
TX_DELAY1 CRLF + CRLF + '(To write orders for current release rather than delayed release,' + CRLF + Global -
TX_DLG_ERR 'Error in activating order dialog.' Global -
TX_IMO_WARNING1 'You are ' Global -
TX_IMO_WARNING2 ' Clinic Orders. The New orders will be saved as Clinic Orders and MAY NOT be available in BCMA' Global -
TX_NO_CHANGE CRLF + CRLF + '- cannot be changed.' + CRLF + CRLF + 'Reason: ' Global -
TX_NO_COPY CRLF + CRLF + '- cannot be copied.' + CRLF + CRLF + 'Reason: ' Global -
TX_NO_EDIT_QO 'An ordering dialog must be active to use this action.' Global -
TX_NO_QUICK 'This ordering dialog does not support quick orders.' Global -
TX_NO_SAVE_QO 'An ordering dialog must be active to use this action.' Global -
TX_NOFORM 'This selection does not have an associated windows form.' Global -
TX_NOINPT ': You cannot place inpatient medication orders from a clinic location for selected patient.' Global -
TX_NOKEY 'You do not have the keys required to take this action.' Global -
TX_ONHOLD 'The following order has been put on-hold, do you still want to continue?' Global -
TX_PROV_KEY 'The provider selected for this encounter must' + CRLF + Global -
TX_PROV_LOC 'A provider and location must be selected before entering orders.' Global -
TX_STOP_SET 'Do you want to stop entering the current set of orders?' Global -


Module Source

1     unit uOrders;
2     
3     interface
4     
5     uses
6       Windows, Messages, SysUtils, Classes, Controls, Forms, uConst, rConsults,
7       rOrders, ORFn, Dialogs, ORCtrls, stdCtrls, strUtils, fODBase, fODMedOIFA,
8       VA508AccessibilityRouter, XuDsigS, ORNet;
9     
10    type
11      EOrderDlgFail = class(Exception);
12    
13      //FQOAltOI = record
14      //OI: integer;
15      //end;
16    
17    { Ordering Environment }
18    function AuthorizedUser: Boolean;
19    function AuthorizedToVerify: Boolean;
20    function EncounterPresent(ErrorMsg: String = ''): Boolean;
21    function EncounterPresentEDO: Boolean;
22    function LockedForOrdering: Boolean;
23    function IsValidActionOnComplexOrder(AnOrderID, AnAction: string;
24        AListBox: TListBox; var CheckedList: TStringList; var ErrMsg: string; var ParentOrderID: string): boolean;  //PSI-COMPLEX
25    procedure UnlockIfAble;
26    function SetSAN(Self: TComponent): string;
27    function OrderCanBeLocked(OrderID: string): Boolean;
28    procedure UnlockOrderIfAble(OrderID: string);
29    procedure AddSelectedToChanges(AList: TList);
30    procedure ResetDialogProperties(const AnID: string; AnEvent: TOrderDelayEvent; var ResolvedDialog: TOrderDialogResolved);
31    function IsInvalidActionWarning(const AnOrderText,AnOrderID: String): boolean;
32    procedure InitialOrderVariables;
33    
34    { Write Orders }
35    function ActivateAction(const AnID: string; AnOwner: TComponent; ARefNum: Integer): Boolean;
36    function ActivateOrderDialog(const AnID: string; AnEvent: TOrderDelayEvent;
37      AnOwner: TComponent; ARefNum: Integer; ANeedVerify: boolean = True): Boolean;
38    function RetrieveOrderText(AnOrderID: string): string;
39    function ActivateOrderHTML(const AnID: string; AnEvent: TOrderDelayEvent;
40      AnOwner: TComponent; ARefNum: Integer): Boolean;
41    function ActivateOrderMenu(const AnID: string; AnEvent: TOrderDelayEvent;
42      AnOwner: TComponent; ARefNum: Integer): Boolean;
43    function ActivateOrderSet(const AnID: string; AnEvent: TOrderDelayEvent;
44      AnOwner: TComponent; ARefNum: Integer): Boolean;
45    function ActivateOrderList(AList: TStringList; AnEvent: TOrderDelayEvent;
46      AnOwner: TComponent; ARefNum: Integer; const KeyVarStr, ACaption: string): Boolean;
47    function ActiveOrdering: Boolean;
48    function CloseOrdering: Boolean;
49    function ReadyForNewOrder(AnEvent: TOrderDelayEvent): Boolean;
50    function ReadyForNewOrder1(AnEvent: TOrderDelayEvent): Boolean;
51    function ChangeOrdersEvt(AnOrderID: string; AnEvent: TOrderDelayEvent): boolean;
52    function CopyOrders(AList: TStringList; AnEvent: TOrderDelayEvent; var DoesEventOccur: boolean; ANeedVerify: boolean = True): boolean;
53    function TransferOrders(AList: TStringList; AnEvent: TOrderDelayEvent; var DoesEventOccur: boolean; ANeedVerify: boolean = True): boolean;
54    procedure SetConfirmEventDelay;
55    procedure ChangeOrders(AList: TStringList; AnEvent: TOrderDelayEvent);
56    procedure DestroyingOrderAction;
57    procedure DestroyingOrderDialog;
58    procedure DestroyingOrderHTML;
59    procedure DestroyingOrderMenu;
60    procedure DestroyingOrderSet;
61    function OrderIsLocked(const AnOrderID, AnAction: string): Boolean;
62    procedure PopLastMenu;
63    procedure QuickOrderSave;
64    procedure QuickOrderListEdit;
65    function RefNumFor(AnOwner: TComponent): Integer;
66    procedure PrintOrdersOnSignReleaseMult(OrderList, ClinicLst, WardLst: TStringList; Nature: Char; EncLoc, WardLoc: integer; EncLocName, WardLocName: string);
67    procedure PrintOrdersOnSignRelease(OrderList: TStringList; Nature: Char; PrintLoc : Integer =0; PrintName: string = '');
68    procedure SetFontSize( FontSize: integer);
69    procedure NextMove(var NMRec: TNextMoveRec; LastIndex: Integer; NewIndex: Integer);
70    //function GetQOAltOI: integer;
71    
72    { Inpatient medication for Outpatient}
73    function IsIMODialog(DlgID: integer): boolean;
74    function AllowActionOnIMO(AnEvtTyp: char): boolean;
75    function IMOActionValidation(AnId: string; var IsIMOOD: boolean; var x: string; AnEventType: char): boolean;
76    function IMOTimeFrame: TFMDateTime;
77    
78    
79    var
80    uAutoAc: Boolean;
81    InptDisp : Integer;
82    OutptDisp: Integer;
83    MedsDisp : Integer;
84    ClinDisp : Integer; //IMO
85    NurDisp  : Integer;
86    IVDisp   : Integer;
87    CsltDisp : Integer;
88    ProcDisp : Integer;
89    ImgDisp  : Integer;
90    DietDisp : Integer;
91    NonVADisp: Integer;
92    MedsInDlgIen  : Integer;
93    MedsOutDlgIen : Integer;
94    MedsNVADlgIen : Integer;
95    MedsInDlgFormId  : Integer;
96    MedsOutDlgFormId : Integer;
97    MedsNVADlgFormID : Integer;
98    MedsIVDlgIen: Integer;
99    MedsIVDlgFormID: Integer;
100   NSSchedule: boolean;
101   OriginalMedsOutHeight: Integer;
102   OriginalMedsInHeight: Integer;
103   OriginalNonVAMedsHeight: Integer;
104   PassDrugTstCall: boolean;
105   
106   implementation
107   
108   uses fODDiet, fODMisc, fODGen, fODMedIn, fODMedOut, fODText, fODConsult, fODProc, fODRad,
109        fODLab, fODBBank, fODMeds, fODMedIV, fODVitals, fODAuto, (*fODAllgy,*) fOMNavA, rCore, uCore, fFrame,
110        fEncnt, fEffectDate, fOMVerify, fOrderSaveQuick, fOMSet, rMisc, uODBase, rODMeds,
111        fLkUpLocation, fOrdersPrint, fOMAction, fARTAllgy, fOMHTML, fOrders, rODBase,
112        fODChild, fMeds, rMeds, rPCE, fRptBox, fODMedNVA, fODChangeUnreleasedRenew, rODAllergy,
113        UBAGlobals, fClinicWardMeds, uTemplateFields, VAUtils;
114   
115   var
116     uPatientLocked: Boolean;
117     uKeepLock: Boolean;
118     uOrderAction: TfrmOMAction;
119     uOrderDialog: TfrmODBase;
120     uOrderHTML: TfrmOMHTML;
121     uOrderMenu: TfrmOMNavA;
122     uOrderSet: TfrmOMSet;
123     uLastConfirm: string;
124     uOrderSetTime: TFMDateTime;
125     uNewMedDialog: Integer;
126     //QOALTOI: FQOAltOI;
127   
128   const
129     TX_PROV_LOC   = 'A provider and location must be selected before entering orders.';
130     TC_PROV_LOC   = 'Incomplete Information';
131     TX_PROV_KEY   = 'The provider selected for this encounter must' + CRLF +
132                     'hold the PROVIDER key to enter orders.';
133     TC_PROV_KEY   = 'PROVIDER Key Required';
134     TX_NOKEY      = 'You do not have the keys required to take this action.';
135     TC_NOKEY      = 'Insufficient Authority';
136     TX_BADKEYS    = 'You have mutually exclusive order entry keys (ORES, ORELSE, or OREMAS).' +
137                      CRLF + 'This must be resolved before you can take actions on orders.';
138     TC_BADKEYS    = 'Multiple Keys';
139     TC_NO_LOCK    = 'Unable to Lock';
140     TC_DISABLED   = 'Item Disabled';
141     TX_DELAY      = 'Now writing orders for ';
142     TX_DELAY1     = CRLF + CRLF + '(To write orders for current release rather than delayed release,' + CRLF +
143                                    'close the next window and select Active Orders from the View Orders pane.)';
144     TC_DELAY      = 'Ordering Information';
145     TX_STOP_SET   = 'Do you want to stop entering the current set of orders?';
146     TC_STOP_SET   = 'Interupt order set';
147     TC_DLG_REJECT = 'Unable to Order';
148     TX_NOFORM     = 'This selection does not have an associated windows form.';
149     TC_NOFORM     = 'Missing Form ID';
150     TX_DLG_ERR    = 'Error in activating order dialog.';
151     TC_DLG_ERR    = 'Dialog Error';
152     TX_NO_SAVE_QO = 'An ordering dialog must be active to use this action.';
153     TC_NO_SAVE_QO = 'Save as Quick Order';
154     TX_NO_EDIT_QO = 'An ordering dialog must be active to use this action.';
155     TC_NO_EDIT_QO = 'Edit Common List';
156     TX_NO_QUICK   = 'This ordering dialog does not support quick orders.';
157     TC_NO_QUICK   = 'Save/Edit Quick Orders';
158     TX_CANT_SAVE_QO = 'This order contains TIU objects, which may result in patient-specific' + CRLF +
159                       'information being included in the order.  For this reason, it may not' + CRLF +
160                       'be saved as a personal quick order for later reuse.';
161     TX_NO_COPY    = CRLF + CRLF + '- cannot be copied.' + CRLF + CRLF + 'Reason: ';
162     TC_NO_COPY    = 'Unable to Copy Order';
163     TX_NO_CHANGE  = CRLF + CRLF + '- cannot be changed.' + CRLF + CRLF + 'Reason: ';
164     TC_NO_CHANGE  = 'Unable to Change Order';
165     TC_NO_XFER    = 'Unable to Transfer Order';
166     TC_NOLOCK     = 'Unable to Lock Order';
167     TX_ONHOLD     = 'The following order has been put on-hold, do you still want to continue?';
168     TX_COMPLEX    = 'You can not take this action on a complex medication.' + #13 + 'You must enter a new order.';
169     STEP_FORWARD  = 1;
170     STEP_BACK     = -1;
171     TX_NOINPT     = ': You cannot place inpatient medication orders from a clinic location for selected patient.';
172     TX_IMO_WARNING1 = 'You are ';
173     TX_IMO_WARNING2 = ' Clinic Orders. The New orders will be saved as Clinic Orders and MAY NOT be available in BCMA';
174   
175   
176   function CreateOrderDialog(Sender: TComponent; FormID: integer; AnEvent: TOrderDelayEvent; ODEvtID: integer = 0): TfrmODBase;
177   { creates an order dialog based on the FormID and returns a pointer to it }
178   type
179     TDialogClass = class of TfrmODBase;
180   var
181     DialogClass: TDialogClass;
182   begin
183     Result := nil;
184     // allows the FormCreate to check event under which dialog is created
185     if AnEvent.EventType in ['A','D','T','M','O'] then
186     begin
187      SetOrderEventTypeOnCreate(AnEvent.EventType);
188      SetOrderEventIDOnCreate(AnEvent.EventIFN);
189     end else
190     begin
191      SetOrderEventTypeOnCreate(#0);
192      SetOrderEventIDOnCreate(0);
193     end;
194     SetOrderFormIDOnCreate(FormID);  
195     // check to see if we should use the new med dialogs
196     if uNewMedDialog = 0 then
197     begin
198       if UseNewMedDialogs then uNewMedDialog := 1 else uNewMedDialog := -1;
199     end;
200     if (uNewMedDialog > 0) and ((FormID = OD_MEDOUTPT) or (FormID = OD_MEDINPT)) then
201         FormID := OD_MEDS;
202     // create the form for a given ordering dialog
203     case FormID of
204     OD_MEDIV:     DialogClass := TfrmODMedIV;
205     OD_MEDINPT:   DialogClass := TfrmODMedIn;
206     OD_MEDS:      DialogClass := TfrmODMeds;
207     OD_MEDOUTPT:  DialogClass := TfrmODMedOut;
208     OD_MEDNONVA:  DialogClass := TfrmODMedNVA;
209     OD_MISC:      DialogClass := TfrmODMisc;
210     OD_GENERIC:
211        begin
212         if ODEvtID>0 then
213          SetOrderEventIDOnCreate(ODEvtID);
214         DialogClass := TfrmODGen;
215        end;
216     OD_IMAGING:   DialogClass := TfrmODRad;
217     OD_DIET:      DialogClass := TfrmODDiet;
218     OD_LAB:       DialogClass := TfrmODLab;
219     OD_BB:        DialogClass := TfrmODBBank;
220     OD_CONSULT:   DialogClass := TfrmODCslt;
221     OD_PROCEDURE: DialogClass := TfrmODProc;
222     OD_TEXTONLY:  DialogClass := TfrmODText;
223     OD_VITALS:    DialogClass := TfrmODVitals;
224     //OD_ALLERGY:   DialogClass := TfrmODAllergy;
225     OD_AUTOACK:   DialogClass := TfrmODAuto;
226     else Exit;
227     end;
228     if Sender = nil then Sender := Application;
229     Result := DialogClass.Create(Sender);
230     if Result <> nil then Result.CallOnExit := DestroyingOrderDialog;
231     SetOrderEventTypeOnCreate(#0);
232     SetOrderEventIDOnCreate(0);
233     SetOrderFormIDOnCreate(0);
234   end;
235   
236   function SetSAN(Self: TComponent): string;
237   var
238     crypto: tCryptography;
239     i: Integer;
240     setUPN, successMsg: string;
241   begin
242       Result := '';
243       if InfoBox(
244         '        '
245         + User.name
246         + CRLF
247         + 'Your VistA account has not been linked to a PIV card.'
248         + CRLF
249         + 'CPRS will now attempt to retrieve some information'
250         + CRLF
251         + 'from your PIV card in order for you to digitally sign orders.'
252         + CRLF
253         + 'This will require entry of the PIN associated with your PIV card.'
254         + CRLF
255         + 'Would you like to continue?',
256         'Digital Signing Setup',MB_YESNO or MB_ICONQUESTION) = IDYES then
257         begin
258           crypto := tCryptography.Create();
259           crypto.VistaUserName := RPCBrokerV.User.Name;
260           Result := getSANFromCard(Self,crypto);
261           if Result='' then ShowMsg('CPRS was not able to link your VistA account to a PIV card.')
262           else
263           begin
264             setUPN := sCallV('XUS PKI SET UPN', [Result]);
265             if setUPN = '1' then
266             begin
267               fFrame.frmFrame.DigitalSigningSetup1.Visible := False;
268               successMsg :=
269                 '        '
270                 + User.name
271                 + CRLF
272                 + 'Your PIV card (' + Result + ') has been successfully linked'
273                 + CRLF
274                 + 'to this VistA account, which will allow you to digitally sign orders.'
275                 + CRLF
276                 + 'This process does not however provide you the authorization to place'
277                 + CRLF
278                 + 'controlled substance prescription orders.'
279                 + CRLF;
280               CallV('ORDEA LNKMSG',[]);
281               for i := 0 to RPCBrokerV.Results.Count - 1 do
282               begin
283                 successMsg := successMsg + CRLF + RPCBrokerV.Results.Strings[i];
284               end;
285               ShowMsg(successMsg);
286               end
287             else begin
288               ShowMsg(
289                 '        '
290                 + User.name
291                 + CRLF
292                 + 'CPRS was not able to link your VistA account to a PIV card.'
293                 + CRLF
294                 + 'One possible cause is that your card is already linked to another VistA account.');
295                 Result:='';
296             end;
297           end;
298           crypto.Free;
299         end;
300   end; 
301   
302   function AuthorizedUser: Boolean;
303   begin
304     Result := True;
305     if User.NoOrdering then Result := False;
306     if User.OrderRole = OR_BADKEYS then
307     begin
308       InfoBox(TX_BADKEYS, TC_BADKEYS, MB_OK);
309       Result := False;
310     end;
311   end;
312   
313   function AuthorizedToVerify: Boolean;
314   begin
315     Result := True;
316     if not User.EnableVerify then Result := False;
317     if User.OrderRole = OR_BADKEYS then
318     begin
319       InfoBox(TX_BADKEYS, TC_BADKEYS, MB_OK);
320       Result := False;
321     end;
322   end;
323   
324   function EncounterPresent(ErrorMsg: String = ''): Boolean;
325   { make sure a location and provider are selected, returns false if not }
326   begin
327     Result := True;
328      //If ErrorMsg was not passed in then use the default
329     If ErrorMsg = '' then ErrorMsg := TX_PROV_LOC;
330   
331     if (Encounter.Provider > 0) and not PersonHasKey(Encounter.Provider, 'PROVIDER')
332       then InfoBox(TX_PROV_KEY, TC_PROV_KEY, MB_OK);
333     if (Encounter.Provider = 0) or (Encounter.Location = 0) or
334       ((Encounter.Provider > 0) and (not PersonHasKey(Encounter.Provider, 'PROVIDER'))) then
335     begin
336       // don't prompt provider if current user has ORES and is the provider
337       if (User.OrderRole = OR_PHYSICIAN) and (Encounter.Provider = User.DUZ) and (User.IsProvider)
338         then UpdateEncounter(NPF_SUPPRESS)
339         else UpdateEncounter(NPF_PROVIDER);
340       frmFrame.DisplayEncounterText;
341     end;
342     if (Encounter.Provider = 0) or (Encounter.Location = 0) then
343     begin
344       if not frmFrame.CCOWDrivedChange then   //jdccow
345         InfoBox(ErrorMsg, TC_PROV_LOC, MB_OK or MB_ICONWARNING);  {!!!}
346       Result := False;
347     end;
348     if (Encounter.Provider > 0) and not PersonHasKey(Encounter.Provider, 'PROVIDER') then
349     begin
350       if not frmFrame.CCOWDrivedChange then   //jdccow
351         InfoBox(TX_PROV_KEY, TC_PROV_KEY, MB_OK);
352       Result := False;
353     end;
354   end;
355   
356   function EncounterPresentEDO: Boolean;
357   begin
358     Result := True;
359     if (Encounter.Provider > 0) and not PersonHasKey(Encounter.Provider, 'PROVIDER')
360       then InfoBox(TX_PROV_KEY, TC_PROV_KEY, MB_OK);
361     if (Encounter.Provider = 0) or
362       ((Encounter.Provider > 0) and (not PersonHasKey(Encounter.Provider, 'PROVIDER'))) then
363     begin
364       UpdateEncounter(NPF_PROVIDER, 0, 0, True);
365       frmFrame.DisplayEncounterText;
366     end;
367     if (Encounter.Provider = 0) then
368     begin
369       InfoBox(TX_PROV_LOC, TC_PROV_LOC, MB_OK or MB_ICONWARNING);  {!!!}
370       Result := False;
371     end;
372     if (Encounter.Provider > 0) and not PersonHasKey(Encounter.Provider, 'PROVIDER') then
373     begin
374       InfoBox(TX_PROV_KEY, TC_PROV_KEY, MB_OK);
375       Result := False;
376     end;
377   end;
378   
379   function LockedForOrdering: Boolean;
380   var
381     ErrMsg: string;
382   begin
383     if uPatientLocked then Result := True else
384     begin
385       LockPatient(ErrMsg);
386       if ErrMsg = '' then
387       begin
388         Result := True;
389         uPatientLocked := True;
390         frmFrame.stsArea.Panels.Items[4].Text := 'LOCK';
391       end else
392       begin
393         Result := False;
394         InfoBox(ErrMsg, TC_NO_LOCK, MB_OK);
395       end;
396     end;
397   end;
398   
399   procedure UnlockIfAble;
400   begin
401     if (Changes.Orders.Count = 0) and not uKeepLock then
402     begin
403       UnlockPatient;
404       uPatientLocked := False;
405       frmFrame.stsArea.Panels.Items[4].Text := '';
406     end;
407   end;
408   
409   function OrderCanBeLocked(OrderID: string): Boolean;
410   var
411     ErrMsg: string;
412   begin
413     LockOrder(OrderID, ErrMsg);
414     if ErrMsg = '' then
415     begin
416       Result := True;
417       frmFrame.stsArea.Panels.Items[4].Text := 'LOCK';
418     end else
419     begin
420       Result := False;
421       InfoBox(ErrMsg, TC_NO_LOCK, MB_OK);
422     end;
423   end;
424   
425   procedure UnlockOrderIfAble(OrderID: string);
426   begin
427     UnlockOrder(OrderID);
428     frmFrame.stsArea.Panels.Items[4].Text := '';
429   end;
430   
431   procedure AddSelectedToChanges(AList: TList);
432   { update Changes with orders that were created by taking actions }
433   var
434     i, CanSign: Integer;
435     AnOrder: TOrder;
436   begin
437     if (Encounter.Provider = User.DUZ) and User.CanSignOrders
438       then CanSign := CH_SIGN_YES
439       else CanSign := CH_SIGN_NA;
440     with AList do for i := 0 to Count - 1 do
441     begin
442       AnOrder := TOrder(Items[i]);
443       with AnOrder do Changes.Add(CH_ORD, ID, Text, '', CanSign);
444       if (Length(AnOrder.ActionOn) > 0)
445         and not Changes.ExistForOrder(Piece(AnOrder.ActionOn, ';', 1))
446         then UnlockOrder(AnOrder.ActionOn);
447     end;
448   end;
449   
450   procedure ResetDialogProperties(const AnID: string; AnEvent: TOrderDelayEvent; var ResolvedDialog: TOrderDialogResolved);
451   begin
452     if StrToIntDef(AnID,0)>0 then
453       Exit;
454     if XfInToOutNow then
455     begin
456       ResolvedDialog.DisplayGroup := OutptDisp;
457       ResolvedDialog.DialogIEN    := MedsOutDlgIen;
458       ResolvedDialog.FormID       := MedsOutDlgFormID;
459       ResolvedDialog.QuickLevel   := 0;
460       Exit;
461     end;
462     //if ResolvedDialog.DisplayGroup in [MedsDisp, OutptDisp, InptDisp, NonVADisp, ClinDisp] then
463     if (ResolvedDialog.DisplayGroup = InptDisp) or
464       (ResolvedDialog.DisplayGroup = OutptDisp) or
465       (ResolvedDialog.DisplayGroup = MedsDisp) or
466       (ResolvedDialog.DisplayGroup =  NonVADisp) or
467       (ResolvedDialog.DisplayGroup =  ClinDisp) then
468     begin
469       if (AnEvent.EventType <> 'D') and (AnEvent.EventIFN > 0) then
470       begin
471         if (AnEvent.EventType = 'T') and IsPassEvt(AnEvent.PtEventIFN,'T') then
472         begin
473           ResolvedDialog.DisplayGroup := OutptDisp;
474           ResolvedDialog.DialogIEN    := MedsOutDlgIen;
475           ResolvedDialog.FormID       := MedsOutDlgFormID;
476           ResolvedDialog.QuickLevel   := 0;
477         end
478         else
479         begin
480           //AGP changes to handle IMO INV Dialog opening the unit dose dialog.
481           if (ResolvedDialog.DisplayGroup = ClinDisp) and (Resolveddialog.DialogIEN = MedsIVDlgIEN) and (ResolvedDialog.FormID = MedsIVDlgFormId) then
482             begin
483               ResolvedDialog.DisplayGroup := IVDisp;
484               ResolvedDialog.DialogIEN    := MedsIVDlgIen;
485               ResolvedDialog.FormID       := MedsIVDlgFormId;
486             end
487           else
488             begin
489               ResolvedDialog.DisplayGroup := InptDisp;
490               ResolvedDialog.DialogIEN    := MedsInDlgIen;
491               ResolvedDialog.FormID       := MedsInDlgFormId;
492             end;
493           if Length(ResolvedDialog.ShowText)>0 then
494             ResolvedDialog.QuickLevel   := 2;
495         end;
496       end
497       else if (AnEvent.EventType = 'D') and (AnEvent.EventIFN > 0) then
498       begin
499         ResolvedDialog.DisplayGroup := OutptDisp;
500         ResolvedDialog.DialogIEN    := MedsOutDlgIen;
501         ResolvedDialog.FormID       := MedsOutDlgFormID;
502         ResolvedDialog.QuickLevel   := 0;
503       end;
504   
505       if XferOutToInOnMeds then
506       begin
507         ResolvedDialog.DisplayGroup := InptDisp;
508         ResolvedDialog.DialogIEN    := MedsInDlgIen;
509         ResolvedDialog.FormID       := MedsInDlgFormId;
510         ResolvedDialog.QuickLevel := 0;
511       end;
512     end;
513     if ResolvedDialog.DisplayGroup = IVDisp then
514     begin
515       if Length(ResolvedDialog.ShowText)>0 then
516         ResolvedDialog.QuickLevel   := 2;
517     end;
518     if (CharAt(AnID,1) = 'C') and (ResolvedDialog.DisplayGroup in [CsltDisp, ProcDisp]) then
519       ResolvedDialog.QuickLevel   := 0;  // CSV - force dialog, to validate ICD code being copied into new order {RV}
520   end;
521   
522   function IsInvalidActionWarning(const AnOrderText,AnOrderID: String): boolean;
523   var
524     AnErrLst, tmpList: TStringList;
525   begin
526     Result := False;
527     AnErrlst := TStringList.Create;
528     IsLatestAction(AnOrderID,AnErrLst);
529     if AnErrLst.Count > 0 then
530     begin
531       tmpList := TStringList.Create;
532       PiecesToList(AnsiReplaceStr(AnOrderText,'#D#A','^'),'^',tmpList);
533       tmpList.Add(' ');
534       tmpList.Add('Cannot be released to service(s) because of the following happened action(s):');
535       tmpList.Add(' ');
536       FastAddStrings(TStrings(AnErrLst), tmpList);
537       ReportBox(tmpList,'Cannot be released to service(s)',False);
538       tmpList.Free;
539       AnErrLst.Free;
540       Result := True;
541     end;
542   end;
543   
544   procedure InitialOrderVariables;
545   begin
546     InptDisp := DisplayGroupByName('UD RX');
547     OutptDisp := DisplayGroupByName('O RX');
548     MedsDisp := DisplayGroupByName('RX');
549     IVDisp   := DisplayGroupByName('IV RX');
550     ClinDisp := DisplayGroupByName('C RX');
551     NurDisp  := DisplayGroupByName('NURS');
552     CsltDisp := DisplayGroupByName('CSLT');
553     ProcDisp := DisplayGroupByName('PROC');
554     ImgDisp  := DisplayGroupByName('XRAY');
555     DietDisp := DisplayGroupByName('DO');
556     NonVADisp := DisplayGroupByName('NV RX');
557     MedsInDlgIen  := DlgIENForName('PSJ OR PAT OE');
558     MedsOutDlgIen := DlgIENForName('PSO OERR');
559     MedsNVADlgIen := DlgIENForName('PSH OERR');
560     MedsIVDlgIen := DlgIENForName('PSJI OR PAT FLUID OE');
561     MedsInDlgFormId  := FormIDForDialog(MedsInDlgIen);
562     MedsOutDlgFormId := FormIDForDialog(MedsOutDlgIen);
563     MedsNVADlgFormID := FormIDForDialog(MedsNVADlgIen);
564     MedsIVDlgFormID := FormIDForDialog(MedsIVDlgIen);
565   end;
566   
567   function GMRCCanCloseDialog(dialog : TfrmODBase) : Boolean;
568   begin
569     //wat-added 'GMRC' to name to show only applies to GMRC order dialogs
570     //other dialogs could be added in the future as needed w/name updated accordingly
571     result := True;
572     if uOrderDialog.FillerID = 'GMRC' then
573       result := fODConsult.CanFreeConsultDialog(dialog)
574               or fODProc.CanFreeProcDialog(dialog);
575   end;
576   
577   function IsValidActionOnComplexOrder(AnOrderID, AnAction: string;
578       AListBox: TListBox; var CheckedList: TStringList; var ErrMsg: string; var ParentOrderID: string): boolean;  //PSI-COMPLEX
579   const
580     COMPLEX_SIGN  = 'You have requested to sign a medication order which was entered as part of a complex order.' +
581       'The following are the orders associated with the same complex order.';
582     COMPLEX_SIGN1 = ' Do you want to sign all of these orders?';
583   
584     COMPLEX_DC  = 'You have requested to discontinue a medication order which was entered as part of a complex order.' +
585       ' The following are all of the associated orders.';
586     COMPLEX_DC1 =' Do you want to dicscontinue all of them?';
587   
588     COMPLEX_HD  = 'You have requested to hold a medication order which was entered as part of a complex order.' +
589       ' The following are all of the associated orders.';
590     COMPLEX_HD1 = ' Do you want to hold all of them?';
591   
592     COMPLEX_UNHD  = 'You have requested to release the hold of a medication order which was entered as part of a complex order.' +
593       ' The following are all of the associated orders.';
594     COMPLEX_UNHD1 = ' Do you want to release all of them?';
595   
596     COMPLEX_RENEW = 'You can not take the renew action on a complex medication which has the following associated orders.';
597     COMPLEX_RENEW1 = ' You must enter a new order.';
598   
599     COMPLEX_VERIFY ='You have requested to verify a medication order which was entered as part of a complex order.' +
600       ' The following are all of the associated orders.';
601     COMPLEX_VERIFY1 =' Do you want to verify all of them?';
602   
603     COMPLEX_OTHER = 'You can not take this action on a complex medication which has the following associated orders.'
604       + ' You must enter a new order.';
605   
606     COMPLEX_CANRENEW1 = 'The selected order for renew: ';
607     COMPLEX_CANRENEW2 = ' is a part of a complex order.';
608     COMPLEX_CANRENEW3 = 'The following whole complex order will be renewed.';
609   var
610     CurrentActID, POrderTxt, AChildOrderTxt, CplxOrderMsg: string;
611     ChildList,ChildIdxList,ChildTxtList, CategoryList: TStringList;
612     ShowCancelButton: boolean;
613     procedure RetrieveOrderTextPSI(AOrderList: TStringList; var AODTextList, AnIdxList: TStringList;
614       TheAction: string; AParentID: string = '');
615     var
616       ix,jx: integer;
617       tempid: string;
618     begin
619       for ix := 0 to AOrderList.count - 1  do
620       begin
621         if AListBox.Name = 'lstOrders' then  with AListBox do
622         begin
623           for jx := 0 to Items.Count - 1 do
624             if TOrder(Items.Objects[jx]).ID = AOrderList[ix] then
625             begin
626               TOrder(Items.Objects[jx]).ParentID := AParentID;
627               if CategoryList.IndexOf(TheAction)>-1 then
628                 Selected[jx] := True;
629               AODTextList.Add(TOrder(Items.Objects[jx]).ID + '^' + TOrder(Items.Objects[jx]).Text);
630               if AnIdxList.IndexOf(IntToStr(jx)) > -1 then
631                 continue;
632               AnIdxList.Add(IntToStr(jx));
633             end;
634         end
635         else if (AListBox.Name = 'lstMedsOut' ) or (AListBox.Name = 'lstMedsIn')
636                 or (AListBox.Name = 'lstMedsNonVA') then with AListBox do
637         begin
638            for jx := 0 to Items.Count - 1 do
639            begin
640             tempid := TMedListRec(AListBox.Items.Objects[jx]).OrderID;
641             if tempid = AOrderList[ix] then
642             begin
643               if CategoryList.IndexOf(TheAction)>-1 then
644                 Selected[jx] := True;
645               AODTextList.Add(tempid + '^' + Items[jx]);
646               AnIdxList.Add(IntToStr(jx));
647             end;
648            end;
649         end;
650       end;
651     end;
652   
653     procedure DeselectChild(AnIdxList: TStringList);
654     var
655       dix: integer;
656     begin
657       for dix := 0 to AnIdxList.Count - 1 do
658       begin
659         try
660          if StrToInt(AnIdxList[dix]) < AListBox.Items.Count then
661           AListBox.Selected[StrToInt(AnIdxList[dix])] := False;
662         except
663           // do nothing
664         end;
665       end;
666     end;
667   
668     function MakeMessage(ErrMsg1,ErrMsg2,ErrMsg3: string): string;
669     begin
670       if Length(ErrMsg1)>0 then
671         Result := ErrMsg1 + ErrMsg2
672       else
673         Result := ErrMsg2 + ErrMsg3;
674     end;
675   
676   begin
677     Result := True;
678     if AnAction = OA_COPY then Exit;
679     CurrentActID := Piece(AnOrderID,';',2);
680     CplxOrderMsg := '';
681     CategoryList := TStringList.Create;
682     CategoryList.Add('DC');
683     CategoryList.Add('HD');
684     CategoryList.Add('RL');
685     CategoryList.Add('VR');
686     CategoryList.Add('ES');
687     ShowCancelButton := False;
688   
689     if Length(ErrMsg)>0 then ErrMsg := ErrMsg + #13#13;
690     ValidateComplexOrderAct(AnOrderID,CplxOrderMsg);
691     if Pos('COMPLEX-PSI',CplxOrderMsg)>0 then
692     begin
693       ParentOrderID := Piece(CplxOrderMsg,'^',2);
694       if CheckedList.IndexOf(ParentOrderID) >= 0 then
695       begin
696         ErrMsg := '';
697         Exit;
698       end;
699       if CheckedList.Count = 0 then
700         CheckedList.Add(ParentOrderID)
701       else
702       begin
703         if CheckedList.IndexOf(ParentOrderID) < 0 then
704           CheckedList.Add(ParentOrderID);
705       end;
706       ChildList := TStringList.Create;
707       GetChildrenOfComplexOrder(ParentOrderID,CurrentActID,ChildList);
708       ChildtxtList := TStringList.Create;
709       ChildIdxList := TStringList.Create;
710       RetrieveOrderTextPSI(ChildList,ChildtxtList,ChildIdxList,AnAction,ParentOrderID);
711       if ChildtxtList.Count > 0 then
712       begin
713         if (AnAction = 'RN') or (AnAction = 'EV') then
714         begin
715           if not IsValidSchedule(ParentOrderID) then
716           begin
717             POrderTxt := RetrieveOrderText(ParentOrderID);
718             if CharAt(POrderTxt,1)='+' then
719               POrderTxt := Copy(POrderTxt,2,Length(POrderTxt));
720             if Pos('First Dose NOW',POrderTxt)>1 then
721               Delete(POrderTxt, Pos('First Dose NOW',POrderTxt), Length('First Dose Now'));
722             InfoBox('Invalid schedule!' + #13#13 + 'The selected order is a part of a complex order:' + #13
723               + POrderTxt + #13#13 + ' It contains an invalid schedule.',
724               'Warning', MB_OK or MB_ICONWARNING);
725             DeselectChild(ChildIdxList);
726             Result := False;
727             ErrMsg := '';
728             ChildtxtList.Free;
729             ChildList.Clear;
730             ChildList.Free;
731             CategoryList.Clear;
732             Exit;
733           end;
734         end;
735         if AnAction = OA_DC then
736         begin
737           if not ActionOnComplexOrder(ChildtxtList,MakeMessage(ErrMsg,COMPLEX_DC,COMPLEX_DC1),True) then
738           begin
739             DeselectChild(ChildIdxList);
740             Result := False;
741           end;
742         end
743         else if AnAction = OA_SIGN then
744         begin
745           if not ActionOnComplexOrder(ChildtxtList,MakeMessage(ErrMsg,COMPLEX_SIGN,COMPLEX_SIGN1),True) then
746           begin
747             DeselectChild(ChildIdxList);
748             Result := False;
749           end;
750         end
751         else if AnAction = OA_HOLD then
752         begin
753           if Length(ErrMsg) < 1 then ShowCancelButton := True;
754           if not ActionOnComplexOrder(ChildtxtList,MakeMessage(ErrMsg,COMPLEX_HD,COMPLEX_HD1),ShowCancelButton) then
755           begin
756             DeselectChild(ChildIdxList);
757             Result := False;
758           end;
759         end
760         else if AnAction = OA_UNHOLD then
761         begin
762           if Length(ErrMsg) < 1 then ShowCancelButton := True;
763           if not ActionOnComplexOrder(ChildtxtList,MakeMessage(ErrMsg,COMPLEX_UNHD,COMPLEX_UNHD1),ShowCancelButton) then
764           begin
765             DeselectChild(ChildIdxList);
766             Result := False;
767           end;
768         end
769         else if AnAction = OA_VERIFY then
770         begin
771           if Length(ErrMsg) < 1 then ShowCancelButton := True;
772           if not ActionOnComplexOrder(ChildtxtList,MakeMessage(ErrMsg,COMPLEX_VERIFY,COMPLEX_VERIFY1),ShowCancelButton) then
773           begin
774             DeselectChild(ChildIdxList);
775             Result := False;
776           end;
777         end
778         else if AnAction = OA_RENEW then
779         begin
780           if not IsRenewableComplexOrder(ParentOrderID) then
781           begin
782             if not ActionOnComplexOrder(ChildtxtList,MakeMessage(ErrMsg,COMPLEX_RENEW,COMPLEX_RENEW1),False) then
783             begin
784               DeselectChild(ChildIdxList);
785               Result := False;
786             end;
787           end
788           else
789           begin
790             POrderTxt := RetrieveOrderText(ParentOrderID);
791             if CharAt(POrderTxt,1)='+' then
792               POrderTxt := Copy(POrderTxt,2,Length(POrderTxt));
793             if Pos('First Dose NOW',POrderTxt)>1 then
794               Delete(POrderTxt, Pos('First Dose NOW',POrderTxt), Length('First Dose Now'));
795             AChildOrderTxt := RetrieveOrderText(AnOrderID);
796             if InfoBox(COMPLEX_CANRENEW1 + #13 + AChildOrderTxt
797               + COMPLEX_CANRENEW2 + #13#13
798               + COMPLEX_CANRENEW3 + #13 +  POrderTxt,
799               'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDOK then
800             begin
801               if AListBox.Name = 'lstOrders' then
802                 frmOrders.ParentComplexOrderID := ParentOrderID;
803               if (AListBox.Name = 'lstMedsOut' ) or (AListBox.Name = 'lstMedsIn') then
804                 frmMeds.ParentComplexOrderID := ParentOrderID;
805             end;
806             DeselectChild(ChildIdxList);
807           end;
808         end;
809       end;
810       ErrMsg := '';
811       ChildtxtList.Free;
812       ChildList.Clear;
813       ChildList.Free;
814     end;
815     CategoryList.Clear;
816   end;
817   
818   { Write New Orders }
819   
820   function ActivateAction(const AnID: string; AnOwner: TComponent; ARefNum: Integer): Boolean;
821   // AnID: DlgIEN {;FormID;DGroup}
822   type
823     TDialogClass = class of TfrmOMAction;
824   var
825     DialogClass: TDialogClass;
826     AFormID: Integer;
827   begin
828     Result := False;
829     AFormID := FormIDForDialog(StrToIntDef(Piece(AnID, ';', 1), 0));
830     if AFormID > 0 then
831     begin
832       case AFormID of
833         OM_ALLERGY:     if ARTPatchInstalled then
834                         begin
835   //                        DialogClass := TfrmARTAllergy;
836                             EnterEditAllergy(0, TRUE, FALSE, AnOwner, ARefNum);
837                             Result := True;
838   //                          uOrderMenu.Close;
839                             Exit;
840                         end
841                         else
842                           begin
843                             Result := False;
844                             Exit;
845                           end;
846         OM_HTML:        DialogClass := TfrmOMHTML;
847         999999:         DialogClass := TfrmOMAction;  // for testing!!!
848       else
849         Exit;
850       end;
851       if AnOwner = nil then AnOwner := Application;
852       uOrderAction := DialogClass.Create(AnOwner);
853       if (uOrderAction <> nil) (*and (not uOrderAction.AbortAction) *)then
854       begin
855         uOrderAction.CallOnExit := DestroyingOrderAction;
856         uOrderAction.RefNum := ARefNum;
857         uOrderAction.OrderDialog := StrToIntDef(Piece(AnID, ';', 1), 0);
858         Result := True;
859         if (not uOrderAction.AbortAction) then uOrderAction.ShowModal;
860       end;
861     end else
862     begin
863       //Show508Message('Order Dialogs of type "Action" are available in List Manager only.');
864       Result := False;
865     end;
866   end;
867   
868   function ActivateOrderDialog(const AnID: string; AnEvent: TOrderDelayEvent;
869     AnOwner: TComponent; ARefNum: Integer; ANeedVerify: boolean = True): Boolean;
870   const
871     TX_DEAFAIL1   = 'Order for controlled substance,' + CRLF;
872     TX_DEAFAIL2   = CRLF + 'could not be completed. Provider does not have a' + CRLF +
873                     'current, valid DEA# on record and is ineligible' + CRLF + 'to sign the order.';
874     TX_SCHFAIL    = CRLF + 'could not be completed. Provider is not authorized' + CRLF +
875                     'to prescribe medications in Federal Schedule ';
876     TX_NO_DETOX   = CRLF + 'could not be completed. Provider does not have a' + CRLF +
877                     'valid Detoxification/Maintenance ID number on' + CRLF +
878                     'record and is ineligible to sign the order.';
879     TX_EXP_DETOX1 = CRLF + 'could not be completed. Provider''s Detoxification/Maintenance' + CRLF +
880                     'ID number expired due to an expired DEA# on ';
881     TX_EXP_DETOX2 = '.' + CRLF + 'Provider is ineligible to sign the order.';
882     TX_EXP_DEA1   = CRLF + 'could not be completed. Provider''s DEA# expired on ';
883     TX_EXP_DEA2   = CRLF + 'and no VA# is assigned. Provider is ineligible to sign the order.';
884     TX_INSTRUCT   = CRLF + CRLF + 'Click RETRY to select another provider.' + CRLF + 'Click CANCEL to cancel the current order.';
885     TC_DEAFAIL    = 'Order not completed';
886     TC_IMO_ERROR  = 'Inpatient medication order on outpatient authorization required';
887     TX_EVTDEL_DIET_CONFLICT = 'Have you done either of the above?';
888     TC_EVTDEL_DIET_CONFLICT = 'Possible delayed order conflict';
889     TX_INACTIVE_SVC = 'This consult service is currently inactive and not receiving requests.' + CRLF +
890                       'Please contact your Clinical Coordinator/IRM staff to fix this order.';
891     TX_INACTIVE_SVC_CAP = 'Inactive Service';
892     TX_NO_SVC = 'The order or quick order you have selected does not specify a consult service.' + CRLF +
893                 'Please contact your Clinical Coordinator/IRM staff to fix this order.';
894     TC_NO_SVC = 'No service specified';
895   var
896     ResolvedDialog: TOrderDialogResolved;
897     x, EditedOrder, chkCopay, OrderID, PkgInfo,OrderPtEvtID,OrderEvtID,NssErr, tempUnit, tempSupply, tempDrug, tempSch: string;
898     temp,tempDur,tempQuantity, tempRefills: string;
899     i, ODItem, tempOI, ALTOI: integer;
900     DrugCheck, InptDlg, IsAnIMOOrder, DrugTestDlgType: boolean;
901     IsPsoSupply,IsDischargeOrPass,IsPharmacyOrder,IsConsultOrder,ForIMO, IsNewOrder: boolean;
902     tmpResp: TResponse;
903     CxMsg: string;
904     AButton: TButton;
905     SvcIEN: string;
906     //CsltFrmID: integer;
907     FirstNumericPos: Integer;
908     DEAFailStr, TX_INFO: string;
909   
910   begin
911     IsPsoSupply := False;
912     Result := False;
913     IsDischargeOrPass := False;
914     IsAnIMOOrder  := False;
915     ForIMO := False;
916     IsNewOrder := True;
917     PassDrugTstCall := False;
918     DrugCheck := false;
919     DrugTestDlgType := false;
920     InptDlg := False;
921     //We need to get the first numeric postion
922     for FirstNumericPos := 1 to Length(AnID) do begin
923      if AnID[FirstNumericPos] in ['0'..'9'] then break;
924     end;
925   
926     //QOAltOI.OI := 0;
927     Application.ProcessMessages;
928     // double check environment before continuing with order
929     if uOrderDialog <> nil then uOrderDialog.Close; // then x := uOrderDialog.Name else x := '';
930     //if ShowMsgOn(uOrderDialog <> nil, TX_DLG_ERR + CRLF + x, TC_DLG_ERR) then Exit;
931   
932     if CharAt(AnID, 1) = 'X' then
933     begin
934       IsNewOrder := False;
935      // if PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E')=false then Exit;
936       ValidateOrderAction(Copy(AnID, 2, Length(AnID)), OA_CHANGE,   x);
937       if ( Length(x)<1 ) and not (AnEvent.EventIFN > 0) then
938         ValidateComplexOrderAct(Copy(AnID, 2, Length(AnID)),x);
939       if (Pos('COMPLEX-PSI',x)>0) then
940         x := TX_COMPLEX;
941       if Length(x) > 0 then
942         x := RetrieveOrderText(Copy(AnID, 2, Length(AnID))) + #13#10 + x;
943       if ShowMsgOn(Length(x) > 0, x, TC_NO_CHANGE) then Exit;
944       DrugCheck := true;
945     end;
946     if CharAt(AnID, 1) = 'C' then
947     begin
948       IsNewOrder := False;
949       //if PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E')=false then Exit;
950       ValidateOrderAction(Copy(AnID, 2, Length(AnID)), OA_COPY,     x);
951       if Length(x) > 0 then
952         x := RetrieveOrderText(Copy(AnID, 2, Length(AnID))) + #13#10 + x;
953       if ShowMsgOn(Length(x) > 0, x, TC_NO_COPY) then Exit;
954       DrugCheck := true;
955    end;
956     if CharAt(AnID, 1) = 'T' then
957     begin
958       IsNewOrder := False;
959       if (XfInToOutNow = true) and (PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E', false)=false) then Exit;
960       if (XfInToOutNow = false) then
961         begin
962          if (XferOuttoInOnMeds = True) and (PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E', true)=false) then Exit;
963          if (XferOuttoInOnMeds = False) and (PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E', False)=false) then Exit;
964         end;
965       ValidateOrderAction(Copy(AnID, 2, Length(AnID)), OA_TRANSFER, x);
966       if Length(x) > 0 then
967         x := RetrieveOrderText(Copy(AnID, 2, Length(AnID))) + #13#10 + x;
968       if ShowMsgOn(Length(x) > 0, x, TC_NO_XFER) then Exit;
969     end;
970     if not IMOActionValidation(AnID, IsAnIMOOrder, x, AnEvent.EventType) then
971     begin
972       ShowMsgOn(Length(x) > 0, x, TC_IMO_ERROR);
973       Exit;
974     end;
975     if ( (StrToIntDef(AnId,0)>0) and (AnEvent.EventIFN <= 0) ) then
976       ForIMO := IsIMODialog(StrToInt(AnId))
977     else if ( (IsAnIMOOrder) and (AnEvent.EventIFN <= 0) ) then
978       ForIMO := True;
979     OrderPtEvtID := GetOrderPtEvtID(Copy(AnID, 2, Length(AnID)));
980     OrderEvtID := Piece(EventInfo(OrderPtEvtID),'^',2);
981     //CQ 18660 Orders for events should be modal. Orders for non-event should not be modal
982     if AnEvent.EventIFN > 0 then frmOrders.NeedShowModal := true
983     else frmOrders.NeedShowModal := false;
984     // evaluate order dialog, build response list & see what form should be presented
985     FillChar(ResolvedDialog, SizeOf(ResolvedDialog), #0);
986     ResolvedDialog.InputID := AnID;
987     BuildResponses(ResolvedDialog, GetKeyVars, AnEvent, ForIMO);
988     if (ResolvedDialog.DisplayGroup = InPtDisp) or (ResolvedDialog.DisplayGroup = ClinDisp) then DrugTestDlgType := true;
989     if (DrugCheck = true) and (ResolvedDialog.DisplayGroup = OutPtDisp) and
990     (PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E', false)=false) then Exit;
991     if (DrugCheck = true) and (DrugTestDlgType = true) and (PassDrugTest(StrtoINT(Copy(AnID, FirstNumericPos, (Pos(';', AnID) - FirstNumericPos))), 'E', true)=false) then Exit;
992     if (IsNewOrder = True) and (ResolvedDialog.DialogType = 'Q') and
993        ((ResolvedDialog.DisplayGroup = OutptDisp) or (DrugTestDlgType = true)) then
994       begin
995         if (PassDrugTest(ResolvedDialog.DialogIEN, 'Q', DrugTestDlgType)=false) then Exit
996         else PassDrugTstCall := True;
997       end;
998     if (ForIMO and ( (ResolvedDialog.DialogIEN = MedsInDlgIen)
999       or (ResolvedDialog.DialogIEN = MedsIVDlgIen)) ) then
1000      ResolvedDialog.DisplayGroup := ClinDisp;
1001    ResetDialogProperties(AnID, AnEvent, ResolvedDialog);
1002   {* AGP CHANGE 26.20 Remove restriction to allowed for ordering of inpatient medication for an inpatient from an outpatient location
1003     //jd imo change
1004     if (ResolvedDialog.DisplayGroup = InptDisp) and (Patient.Inpatient) and (AnEvent.EventIFN < 1) then
1005     begin
1006       if IsClinicLoc(Encounter.Location) then
1007       begin
1008         MessageDlg(TX_NOINPT, mtWarning, [mbOK], 0);
1009         Exit;
1010       end;
1011     end;
1012     //jd imo change end  *}
1013     if (ResolvedDialog.DisplayGroup = InptDisp) or
1014        (ResolvedDialog.DisplayGroup = OutptDisp) or
1015        (ResolvedDialog.DisplayGroup = MedsDisp) or
1016        (ResolvedDialog.DisplayGroup = IVDisp) or
1017        (ResolvedDialog.DisplayGroup =  NonVADisp) or
1018        (ResolvedDialog.DisplayGroup =  ClinDisp) then  IsPharmacyOrder := True
1019     else
1020        IsPharmacyOrder := False;
1021     (*  IsPharmacyOrder := ResolvedDialog.DisplayGroup in [InptDisp, OutptDisp,
1022          MedsDisp,IVDisp, NonVADisp, ClinDisp];*)   //v25.27 range check error - RV
1023    IsConsultOrder := ResolvedDialog.DisplayGroup in [CsltDisp,ProcDisp];
1024    if (uAutoAC) and (not (ResolvedDialog.QuickLevel in [QL_REJECT,QL_CANCEL]))
1025      and (not IsPharmacyOrder) and (not IsConsultOrder) then
1026      ResolvedDialog.QuickLevel := QL_AUTO;
1027    if (ResolvedDialog.DialogType = 'Q')
1028      and (ResolvedDialog.DisplayGroup = InptDisp) then
1029    begin
1030       NssErr := IsValidQOSch(ResolvedDialog.InputID);
1031       if (Length(NssErr) > 1) then
1032       begin
1033         if (NssErr <> 'OTHER') and (NssErr <> 'schedule is not defined.') then
1034           ShowMsg('The order contains invalid non-standard schedule.');
1035         NSSchedule := True;
1036         ResolvedDialog.QuickLevel := 0;
1037       end;
1038    end;
1039    if ResolvedDialog.DisplayGroup = InptDisp then       //nss
1040    begin
1041      if (CharAt(AnID, 1) = 'C') or (CharAt(AnID, 1) = 'T') or (CharAt(AnID, 1) = 'X') then
1042      begin
1043        if not IsValidSchedule(Copy(AnID, 2, Length(AnID))) then
1044        begin
1045          ShowMsg('The order contains invalid non-standard schedule.');
1046          NSSchedule := True;
1047        end;
1048      end;
1049      if NSSchedule then ResolvedDialog.QuickLevel := 0;
1050    end;
1051   (* if (ResolvedDialog.DialogType = 'Q') and ((ResolvedDialog.FormID = OD_MEDINPT) or (ResolvedDialog.FormID = OD_MEDOUTPT)) then
1052      begin
1053        temp := '';
1054        tempOI := GetQOOrderableItem(ResolvedDialog.InputID);
1055        if tempOI >0 then
1056          begin
1057            ALTOI := tempOI;
1058            CheckFormularyOI(AltOI,temp,True);
1059            if ALTOI <> tempOI then
1060              begin
1061                ResolvedDialog.QuickLevel := 0;
1062                QOAltOI.OI := ALTOI;
1063              end;
1064          end;
1065      end; *)
1066    //   ((ResolvedDialog.DisplayGroup = InptDisp) or (ResolvedDialog.DisplayGroup = OutptDisp) or (ResolvedDialog.DisplayGroup = MedsDisp)) then
1067   //    ResolvedDialog.QuickLevel := 0;
1068    with ResolvedDialog do if (QuickLevel = QL_VERIFY) and (HasTemplateField(ShowText)) then QuickLevel := QL_DIALOG;
1069  
1070    // Check for potential conflicting auto-accept delayed-release diet orders (CQ #10946 - v27.36 - RV)
1071    with ResolvedDialog do if (QuickLevel = QL_AUTO) and (DisplayGroup = DietDisp) and (AnEvent.EventType <> 'C') then
1072    begin
1073      AButton := TButton.Create(Application);
1074      try
1075        CheckForAutoDCDietOrders(AnEvent.EventIFN, DisplayGroup, '', CxMsg, AButton);
1076        if CxMsg <> '' then
1077        begin
1078          if InfoBox(CxMsg + CRLF + CRLF + TX_EVTDEL_DIET_CONFLICT,
1079             TC_EVTDEL_DIET_CONFLICT,
1080             MB_ICONWARNING or MB_YESNO) = ID_NO
1081             then QuickLevel := QL_DIALOG;
1082        end;
1083      finally
1084        AButton.Free;
1085      end;
1086    end;
1087  
1088    with ResolvedDialog do
1089    begin
1090      if QuickLevel = QL_REJECT then InfoBox(ShowText, TC_DLG_REJECT, MB_OK);
1091      if (QuickLevel = QL_VERIFY) and (IsPharmacyOrder or ANeedVerify) then  ShowVerifyText(QuickLevel, ShowText, DisplayGroup=InptDisp);
1092      if QuickLevel = QL_AUTO then
1093      begin
1094        //CsltFrmID := FormID;
1095        FormID := OD_AUTOACK;
1096      end;
1097      if (QuickLevel = QL_REJECT) or (QuickLevel = QL_CANCEL) then Exit;
1098      PushKeyVars(ResolvedDialog.QOKeyVars);
1099    end;
1100    if ShowMsgOn(not (ResolvedDialog.FormID > 0), TX_NOFORM, TC_NOFORM) then Exit;
1101    with ResolvedDialog do if DialogType = 'X' then
1102    begin
1103      EditedOrder := Copy(Piece(ResponseID, '-', 1), 2, Length(ResponseID));
1104    end
1105    else EditedOrder := '';
1106    if XfInToOutNow then
1107    begin
1108       //if Transfer an order to outpatient and release immediately
1109       // then changing the Eventtype to 'C' instead of 'D'
1110       IsDischargeOrPass := True;
1111       AnEvent.EventType := 'C';
1112       AnEvent.Effective := 0;
1113    end;
1114    uOrderDialog := CreateOrderDialog(AnOwner, ResolvedDialog.FormID, AnEvent, StrToIntDef(OrderEvtID,0));
1115    uOrderDialog.IsSupply := IsPsoSupply;
1116  
1117    {For copy, change, transfer actions on an None-IMO order, the new order should not be treated as IMO order
1118     although the IMO criteria could be met. }
1119    //if (uOrderDialog.IsIMO) and (CharAt(AnID, 1) in ['X','C','T']) then
1120    if not uOrderDialog.IsIMO then
1121      uOrderDialog.IsIMO := ForIMO;
1122  
1123    if (ResolvedDialog.DialogType = 'Q') and (ResolvedDialog.DisplayGroup in [MedsDisp, OutptDisp, InptDisp]) then
1124       begin
1125         if DoesOIPIInSigForQO(StrToInt(ResolvedDialog.InputID))=1 then
1126           uOrderDialog.IncludeOIPI := True
1127         else
1128           uOrderDialog.IncludeOIPI := False;
1129       end;
1130  
1131    if (uOrderDialog <> nil) and not uOrderDialog.Closing then with uOrderDialog do
1132          begin
1133            SetKeyVariables(GetKeyVars);
1134  
1135            if IsDischargeOrPass then
1136              EvtForPassDischarge  := 'D'
1137            else
1138              EvtForPassDischarge  := #0;
1139  
1140            Responses.SetEventDelay(AnEvent);
1141            Responses.LogTime := uOrderSetTime;
1142            DisplayGroup := ResolvedDialog.DisplayGroup;  // used to pass ORTO
1143            DialogIEN    := ResolvedDialog.DialogIEN;     // used to pass ORIT
1144            RefNum := ARefNum;
1145  
1146            case ResolvedDialog.DialogType of
1147            'C': SetupDialog(ORDER_COPY,  ResolvedDialog.ResponseID);
1148            'D': SetupDialog(ORDER_NEW,   '');
1149            'X':
1150                  begin
1151                     SetupDialog(ORDER_EDIT,  ResolvedDialog.ResponseID);
1152                     OrderID := Copy(ResolvedDialog.ResponseID,2,Length(ResolvedDialog.ResponseID));
1153                     //IsInpatient := OrderForInpatient;
1154                     ODItem := StrToIntDef(Responses.IValueFor('ORDERABLE', 1), 0);
1155                     PkgInfo := '';
1156                     DEAFailStr := '';
1157                     if Length(OrderID)>0 then
1158                       PkgInfo := GetPackageByOrderID(OrderID);
1159                     if Pos('PS',PkgInfo)=1 then
1160                     begin
1161                       if PkgInfo = 'PSO' then InptDlg := False
1162                       else if PkgInfo = 'PSJ' then InptDlg := True;
1163                       DEAFailStr := DEACheckFailed(ODItem, InptDlg);
1164                       while (StrToIntDef(Piece(DEAFailStr,U,1),0) in [1..5]) and (uOrderDialog.FillerID <> 'PSH') do
1165                       begin
1166                         case StrToIntDef(Piece(DEAFailStr,U,1),0) of
1167                           1: TX_INFO := TX_DEAFAIL1 + #13 + Responses.OrderText + #13 + TX_DEAFAIL2;  //prescriber has an invalid or no DEA#
1168                           2: TX_INFO := TX_DEAFAIL1 + #13 + Responses.OrderText + #13 + TX_SCHFAIL + Piece(DEAFailStr,U,2) + '.';  //prescriber has no schedule privileges in 2,2N,3,3N,4, or 5
1169                           3: TX_INFO := TX_DEAFAIL1 + #13 + Responses.OrderText + #13 + TX_NO_DETOX;  //prescriber has an invalid or no Detox#
1170                           4: TX_INFO := TX_DEAFAIL1 + #13 + Responses.OrderText + #13 + TX_EXP_DEA1 + Piece(DEAFailStr,U,2) + TX_EXP_DEA2;  //prescriber's DEA# expired and no VA# is assigned
1171                           5: TX_INFO := TX_DEAFAIL1 + #13 + Responses.OrderText + #13 + TX_EXP_DETOX1 + Piece(DEAFailStr,U,2) + TX_EXP_DETOX2;  //valid detox#, but expired DEA#
1172                         end;
1173                         if InfoBox(TX_INFO + TX_INSTRUCT, TC_DEAFAIL, MB_RETRYCANCEL) = IDRETRY then
1174                           begin
1175                             DEAContext := True;
1176                             fFrame.frmFrame.mnuFileEncounterClick(uOrderDialog);
1177                             DEAFailStr := '';
1178                             DEAFailStr := DEACheckFailed(ODItem, InptDlg);
1179                           end
1180                         else
1181                           begin
1182                             if (ResolvedDialog.DialogType = 'X') and not Changes.ExistForOrder(EditedOrder)
1183                             then UnlockOrder(EditedOrder);
1184                             uOrderDialog.Close;
1185                             Exit;
1186                           end;
1187                       end;
1188                     end;
1189                  end;
1190            'Q':
1191                  begin
1192                    if IsPSOSupplyDlg(ResolvedDialog.DialogIEN,1) then
1193                      uOrderDialog.IsSupply := True;
1194                    SetupDialog(ORDER_QUICK, ResolvedDialog.ResponseID);
1195                    {if ((ResolvedDialog.DisplayGroup = CsltDisp)
1196                      and (ResolvedDialog.QuickLevel = QL_AUTO)) then
1197                      TfrmODCslt.SetupDialog(ORDER_QUICK, ResolvedDialog.ResponseID);}
1198                  end;
1199            end;
1200  
1201             if Assigned(uOrderDialog) then
1202              with uOrderDialog do
1203                if AbortOrder and GMRCCanCloseDialog(uOrderDialog) then
1204                  begin
1205                    Close;
1206                    if Assigned(uOrderDialog) then
1207                      uOrderDialog.Destroy;
1208                    Exit;
1209                  end;
1210  
1211            if CharAt(AnID, 1) = 'T' then
1212               begin
1213                 if ARefNum = -2 then
1214                   Responses.TransferOrder := '';
1215                 if ARefNum = -1 then
1216                   Responses.TransferOrder := AnID;
1217               end;
1218  
1219            if CharAt(AnID,1) = 'C' then            ////////////////////////////////////////////////////////////////////////
1220               begin
1221                 chkCopay := Copy(AnID,2,length(AnID)); //STRIP prepended C, T, or X from first position in order ID.
1222                 SetDefaultCoPay(chkCopay);
1223               end;                                    ////////////////////////////////////////////////////////////////////////'
1224  
1225            if IsConsultOrder and (CharAt(AnID,1) = 'C') then
1226               begin
1227                 tmpResp := uOrderDialog.Responses.FindResponseByName('CODE', 1);
1228                 if (tmpResp <> nil) then
1229                   begin
1230                   if IsActiveICDCode(tmpResp.EValue) then
1231                      ResolvedDialog.QuickLevel := QL_AUTO
1232                   else
1233                      ResolvedDialog.QuickLevel := QL_DIALOG;
1234                   end
1235                 else
1236                   ResolvedDialog.QuickLevel := QL_AUTO
1237               end;
1238  
1239            if ResolvedDialog.QuickLevel <> QL_AUTO then
1240               begin
1241                 if CharAt(AnID, 1) in ['C','T','X'] then
1242                    begin
1243                    Position := poScreenCenter;
1244                    FormStyle := fsNormal;
1245                    ShowModal;
1246                    Result := uOrderDialog.AcceptOK;
1247                    end
1248                 else
1249                    begin
1250                      SetBounds(frmFrame.Left + 112, frmFrame.Top + frmFrame.Height - Height, Width, Height);
1251                      SetFormPosition(uOrderDialog);
1252                      FormStyle := fsStayOnTop;
1253                      if frmOrders.NeedShowModal then
1254                         begin
1255                         ShowModal;
1256                         Result := uOrderDialog.AcceptOK;
1257                         uOrderDialog.Destroy;
1258                         end
1259                      else
1260                         begin
1261                         Show;
1262                         Result := True;
1263                         end;
1264                   end;
1265               end
1266            else
1267               begin
1268               if uOrderDialog.DisplayGroup = OutptDisp then
1269                 begin
1270                   tempUnit := '';
1271                   tempSupply := '';
1272                   tempDrug := '';
1273                   tempSch := '';
1274                   tempDur := '';
1275                   tmpResp := uOrderDialog.Responses.FindResponseByName('SUPPLY', 1);
1276                   if tmpResp = nil then tempSupply := '0'
1277                   else tempSupply := tmpResp.EValue;
1278                   tmpResp := uOrderDialog.Responses.FindResponseByName('QTY', 1);
1279                   if tmpResp = nil then tempQuantity := '0'
1280                   else tempQuantity := tmpResp.EValue;
1281                   tmpResp := uOrderDialog.Responses.FindResponseByName('REFILLS', 1);
1282                   if tmpResp = nil then tempRefills := '0'
1283                   else tempRefills := tmpResp.EValue;
1284                   tmpResp := uOrderDialog.Responses.FindResponseByName('ORDERABLE', 1);
1285                   tempOI := StrToIntDef(tmpResp.IValue,0);
1286                   i := uORderDialog.Responses.NextInstance('DOSE',0);
1287                   while i > 0 do
1288                     begin
1289                        x := Piece(uOrderDialog.Responses.IValueFor('DOSE',i), '&', 3);
1290                        tempUnit := tempUnit + X + U;
1291                        x := uOrderDialog.Responses.IValueFor('SCHEDULE',i);
1292                        tempSch := tempSch + x + U;
1293                        x := uOrderDialog.Responses.IValueFor('DRUG', i);
1294                        tempDrug := Piece(x, U, 1);
1295                        i := Responses.NextInstance('DOSE', i);
1296                        x := UORderDialog.Responses.IValueFor('DAYS', i);
1297                        tempDur := tempDur + x + '~';
1298                        x := uOrderDialog.Responses.IValueFor('CONJ', i);
1299                        tempDur := tempDur + x + U;
1300                     end;
1301                   if ValidateDrugAutoAccept(tempDrug, tempUnit, tempSch, tempDur, tempOI, StrtoInt(tempSupply), StrtoInt(tempRefills), StrToFloat(tempQuantity)) = false then Exit;
1302                 end;
1303               if ((ResolvedDialog.DisplayGroup = CsltDisp) and (ResolvedDialog.QuickLevel = QL_AUTO)) then
1304               begin
1305                 with Responses do
1306                 begin
1307                   Changing := True;
1308                   tmpResp := TResponse(FindResponseByName('ORDERABLE',1));
1309                   if tmpResp <> nil then
1310                     SvcIEN := GetServiceIEN(tmpResp.IValue)
1311                   else
1312                   begin
1313                     InfoBox(TX_NO_SVC, TC_NO_SVC, MB_ICONERROR or MB_OK);
1314                     //AbortOrder := True;
1315                     //Close;
1316                     Exit;
1317                   end;
1318                   if SvcIEN = '-1' then
1319                   begin
1320                     InfoBox(TX_INACTIVE_SVC, TX_INACTIVE_SVC_CAP, MB_OK);
1321                     //AbortOrder := True;
1322                     //Close;
1323                     Exit;
1324                   end;
1325                 end;
1326               end;
1327               cmdAcceptClick(Application);  // auto-accept order
1328               Result := uOrderDialog.AcceptOK;
1329               if (result = true) and (ScreenReaderActive) then
1330                 GetScreenReader.Speak('Auto Accept Quick Order '+ Responses.DialogDisplayName + ' placed.');
1331  
1332               //BAPHII 1.3.2
1333               //Show508Message('DEBUG: About to copy BA CI''s to copied order from Order: '+AnID+'#13'+' in uOrders.ActivateOrderDialog()');
1334  
1335               //End BAPHII 1.3.2
1336  
1337               if Assigned(uOrderDialog) then
1338                 uOrderDialog.Destroy;
1339               end;
1340  
1341          end
1342    else
1343       begin
1344         uOrderDialog.Release;
1345         Result := False;
1346       //Application.ProcessMessages;       // to allow dialog to finish closing
1347       //Exit;                              // so result is not returned true
1348       end;
1349  
1350    if NSSchedule then
1351      NSSchedule := False;
1352  
1353    if (ResolvedDialog.DialogType = 'X') and not Changes.ExistForOrder(EditedOrder)
1354      then UnlockOrder(EditedOrder);
1355    //QOAltOI.OI := 0;
1356  end;
1357  
1358  function RetrieveOrderText(AnOrderID: string): string;
1359  var
1360    OrdList: TList;
1361    theOrder: TOrder;
1362   // i: integer;
1363  begin
1364   // if Assigned(OrdList) then
1365   // begin
1366   //    for i := 0 to pred(OrdList.Count) do
1367   //       TObject(OrdList[i]).Free;
1368    //   UBAGlobals.tempDxList := nil;
1369   // end;
1370    OrdList := TList.Create;
1371    theOrder := TOrder.Create;
1372    theOrder.ID := AnOrderID;
1373    OrdList.Add(theOrder);
1374    RetrieveOrderFields(OrdList, 0, 0);
1375    Result := TOrder(OrdList.Items[0]).Text;
1376    if Assigned(OrdList) then OrdList.Free; //CQ:7554
1377  end;
1378  
1379  function ActivateOrderHTML(const AnID: string; AnEvent: TOrderDelayEvent;
1380    AnOwner: TComponent; ARefNum: Integer): Boolean;
1381  var
1382    DialogIEN: Integer;
1383    x: string;
1384    ASetList: TStringList;
1385  begin
1386    Result := False;
1387    DialogIEN := StrToIntDef(AnID, 0);
1388    x := OrderDisabledMessage(DialogIEN);
1389    if ShowMsgOn(Length(x) > 0, x, TC_DISABLED) then Exit;
1390    if uOrderHTML = nil then
1391    begin
1392      uOrderHTML := TfrmOMHTML.Create(AnOwner);
1393      with uOrderHTML do
1394      begin
1395        SetBounds(frmFrame.Left + 112, frmFrame.Top + frmFrame.Height - Height, Width, Height);
1396        SetFormPosition(uOrderHTML);
1397        FormStyle := fsStayOnTop;
1398        SetEventDelay(AnEvent);
1399      end;
1400    end;
1401    uOrderHTML.Dialog  := DialogIEN;
1402    uOrderHTML.RefNum  := ARefNum;
1403    uOrderHTML.OwnedBy := AnOwner;
1404    uOrderHTML.ShowModal;
1405    ASetList := TStringList.Create;
1406    FastAssign(uOrderHTML.SetList, ASetList);
1407    uOrderHTML.Release;
1408    if ASetList.Count = 0 then Exit;
1409    Result := ActivateOrderList(ASetList, AnEvent, AnOwner, ARefNum, '', '');
1410  end;
1411  
1412  function ActivateOrderMenu(const AnID: string; AnEvent: TOrderDelayEvent;
1413    AnOwner: TComponent; ARefNum: Integer): Boolean;
1414  var
1415    MenuIEN: Integer;
1416    x: string;
1417  begin
1418    Result := False;
1419    MenuIEN := StrToIntDef(AnID, 0);
1420    x := OrderDisabledMessage(MenuIEN);
1421    if ShowMsgOn(Length(x) > 0, x, TC_DISABLED) then Exit;
1422    if uOrderMenu = nil then
1423    begin
1424      uOrderMenu := TfrmOMNavA.Create(AnOwner);
1425      with uOrderMenu do
1426      begin
1427        SetBounds(frmFrame.Left + 112, frmFrame.Top + frmFrame.Height - Height, Width, Height);
1428        SetFormPosition(uOrderMenu);
1429        FormStyle := fsStayOnTop;
1430        SetEventDelay(AnEvent);
1431      end;
1432    end;
1433    uOrderMenu.SetNewMenu(MenuIEN, AnOwner, ARefNum);
1434    if not uOrderMenu.Showing then uOrderMenu.Show else uOrderMenu.BringToFront;
1435    Result := True;
1436  end;
1437  
1438  function ActivateOrderSet(const AnID: string; AnEvent: TOrderDelayEvent;
1439    AnOwner: TComponent; ARefNum: Integer): Boolean;
1440  var
1441    x, ACaption, KeyVarStr: string;
1442    SetList: TStringList;
1443    EvtDefaultDlg, PtEvtID: string;
1444  
1445    function TakeoutDuplicateDlg(var AdlgList: TStringList; ANeedle: string): boolean;
1446    var
1447      i: integer;
1448    begin
1449      Result := False;
1450      for i := 0 to AdlgList.Count - 1 do
1451      begin
1452        if Piece(AdlgList[i],'^',1)=ANeedle then
1453        begin
1454          ADlgList.Delete(i);
1455          Result := True;
1456          Break;
1457        end;
1458      end;
1459    end;
1460  
1461  begin
1462    Result := False;
1463    x := OrderDisabledMessage(StrToIntDef(AnID, 0));
1464    if ShowMsgOn(Length(x) > 0, x, TC_DISABLED) then Exit;
1465    SetList := TStringList.Create;
1466    try
1467      if uOrderSetTime = 0 then uOrderSetTime := FMNow;
1468      LoadOrderSet(SetList, StrToIntDef(AnID, 0), KeyVarStr, ACaption);
1469      if (AnEvent.EventIFN>0) and isExistedEvent(Patient.DFN, IntToStr(AnEvent.EventIFN), PtEvtID) then
1470      begin
1471        EvtDefaultDlg := GetEventDefaultDlg(AnEvent.EventIFN);
1472        while TakeoutDuplicateDlg(SetList,EvtDefaultDlg) do
1473          TakeoutDuplicateDlg(SetList,EvtDefaultDlg);
1474      end;
1475      Result := ActivateOrderList(SetList, AnEvent, AnOwner, ARefNum, KeyVarStr, ACaption);
1476    finally
1477      SetList.Free;
1478    end;
1479  end;
1480  
1481  function ActivateOrderList(AList: TStringList; AnEvent: TOrderDelayEvent;
1482    AnOwner: TComponent; ARefNum: Integer; const KeyVarStr, ACaption: string): Boolean;
1483  var
1484    InitialCall: Boolean;
1485    i: integer;
1486    str: string;
1487  begin
1488    InitialCall := False;
1489    if ScreenReaderActive then
1490      begin
1491        for i := 0 to AList.Count - 1 do
1492           begin
1493             if Piece(Alist.Strings[i],U,2) = 'Q' then str := str + CRLF + 'Quick Order ' + Piece(Alist.Strings[i],U,3)
1494             else if Piece(Alist.Strings[i],U,2) = 'S' then str := str + CRLF + 'Order Set ' + Piece(Alist.Strings[i],U,3)
1495             else if Piece(Alist.Strings[i],U,2) = 'M' then str := str + CRLF + 'Order Menu ' + Piece(Alist.Strings[i],U,3)
1496             else if Piece(Alist.Strings[i],U,2) = 'A' then str := str + CRLF + 'Order Action ' + Piece(Alist.Strings[i],U,3)
1497             else str := str + CRLF + 'Order Dialog ' + Piece(Alist.Strings[i],U,3);
1498           end;
1499        if infoBox('This order set contains the following items:'+ CRLF + str + CRLF+ CRLF + 'Select the OK button to start this order set.' +
1500                   'To stop the order set while it is in process, press “Alt +F6” to navigate to the order set dialog, and select the Stop Order Set Button.', 'Starting Order Set'  ,MB_OKCANCEL) = IDCANCEL then
1501          begin
1502            Result := False;
1503            exit;
1504          end;
1505      end;
1506    if uOrderSet = nil then
1507    begin
1508      uOrderSet := TfrmOMSet.Create(AnOwner);
1509      uOrderSet.SetEventDelay(AnEvent);
1510      uOrderSet.RefNum := ARefNum;
1511      InitialCall := True;
1512    end;
1513    if InitialCall then with uOrderSet do
1514    begin
1515      if Length(ACaption) > 0 then Caption := ACaption;
1516      SetBounds(frmFrame.Left, frmFrame.Top + frmFrame.Height - Height, Width, Height);
1517      SetFormPosition(uOrderSet);
1518      Show;
1519    end;
1520    uOrderSet.InsertList(AList, AnOwner, ARefNum, KeyVarStr, AnEvent.EventType);
1521    Application.ProcessMessages;
1522    Result := uOrderSet <> nil;
1523  end;
1524  
1525  function ActiveOrdering: Boolean;
1526  begin
1527    if (uOrderDialog = nil) and (uOrderMenu = nil) and (uOrderSet = nil) and
1528       (uOrderAction = nil) and (uOrderHTML = nil)
1529      then Result := False
1530      else Result := True;
1531  end;
1532  
1533  function CloseOrdering: Boolean;
1534  begin
1535    Result := False;
1536    { if an order set is being processed, see if want to interupt }
1537    if uOrderSet <> nil then
1538    begin
1539      uOrderSet.Close;
1540      Application.ProcessMessages;
1541      if uOrderSet <> nil then Exit;
1542    end;
1543    { if another ordering dialog is showing, make sure it is closed first }
1544    if uOrderDialog <> nil then
1545    begin
1546      uOrderDialog.Close;
1547      Application.ProcessMessages;  // allow close to finish
1548      if uOrderDialog <> nil then Exit;
1549    end;
1550    if uOrderHTML <> nil then
1551    begin
1552      uOrderHTML.Close;
1553      Application.ProcessMessages;  // allow browser to close
1554      Assert(uOrderHTML = nil);
1555    end;
1556    { close any open ordering menu }
1557    if uOrderMenu <> nil then
1558    begin
1559      uOrderMenu.Close;
1560      Application.ProcessMessages;  // allow menu to close
1561      Assert(uOrderMenu = nil);
1562    end;
1563    if uOrderAction <> nil then
1564    begin
1565      uOrderAction.Close;
1566      Application.ProcessMessages;
1567      if uOrderAction <> nil then Exit;
1568    end;
1569    if frmARTAllergy <> nil then   //SMT Add to account for allergies.
1570    begin
1571      frmARTAllergy.Close;
1572      Application.ProcessMessages;
1573      if frmARTAllergy <> nil then Exit;
1574    end;
1575  
1576    Result := True;
1577  end;
1578  
1579  function ReadyForNewOrder(AnEvent: TOrderDelayEvent): Boolean;
1580  var
1581    x,tmpPtEvt: string;
1582  begin
1583    Result := False;
1584    { make sure a location and provider are selected before ordering }
1585    if not AuthorizedUser then Exit;
1586    //Added to force users without the Provider or ORES key to select an a provider when adding new orders to existing delay orders
1587    if (not Patient.Inpatient) and (AnEvent.EventIFN > 0 ) then
1588      begin
1589        if (User.OrderRole = OR_PHYSICIAN) and (Encounter.Provider = User.DUZ) and (User.IsProvider) then
1590          x := ''
1591        else if not EncounterPresentEDO then Exit;
1592        x := '';
1593      end
1594    else
1595    begin
1596      if not EncounterPresent then Exit;
1597    end;
1598    { then try to lock the patient (provider & encounter checked first to not leave lock) }
1599    if not LockedForOrdering then Exit;
1600    { make sure any current ordering process has completed, but don't drop patient lock }
1601    uKeepLock := True;
1602    if not CloseOrdering then Exit;
1603    uKeepLock := False;
1604    { get the delay event for this order (if applicable) }
1605    if AnEvent.EventType in ['A','D','T','M','O'] then
1606    begin
1607      if (AnEvent.EventName = '') and (AnEvent.EventType <> 'D') then
1608        Exit;
1609      x := AnEvent.EventType + IntToStr(AnEvent.Specialty);
1610      if (uLastConfirm <> x ) and (not XfInToOutNow) then
1611      begin
1612        uLastConfirm := x;
1613        case AnEvent.EventType of
1614        'A','M','O','T': x := AnEvent.EventName;
1615        'D': x := 'Discharge';
1616        end;
1617        if isExistedEvent(Patient.DFN,IntToStr(AnEvent.EventIFN),tmpPtEvt) then
1618          if PtEvtEmpty(tmpPtEvt)then
1619            InfoBox(TX_DELAY + x + TX_DELAY1, TC_DELAY, MB_OK or MB_ICONWARNING);
1620      end;
1621    end
1622    else uLastConfirm := '';
1623    Result := True;
1624  end;
1625  
1626  function ReadyForNewOrder1(AnEvent: TOrderDelayEvent): Boolean;
1627  var
1628    x: string;
1629  begin
1630    Result := False;
1631    { make sure a location and provider are selected before ordering }
1632    if not AuthorizedUser then Exit;
1633    if (not Patient.Inpatient) and (AnEvent.EventIFN > 0 ) then x := ''
1634    else
1635    begin
1636      if not EncounterPresent then Exit;
1637    end;
1638    { then try to lock the patient (provider & encounter checked first to not leave lock) }
1639    if not LockedForOrdering then Exit;
1640    { make sure any current ordering process has completed, but don't drop patient lock }
1641    uKeepLock := True;
1642    if not CloseOrdering then Exit;
1643    uKeepLock := False;
1644    { get the delay event for this order (if applicable) }
1645    if AnEvent.EventType in ['A','D','T','M','O'] then
1646    begin
1647      x := AnEvent.EventType + IntToStr(AnEvent.Specialty);
1648      if (uLastConfirm <> x ) and (not XfInToOutNow) then
1649      begin
1650        uLastConfirm := x;
1651        case AnEvent.EventType of
1652        'A','M','T','O': x := AnEvent.EventName;
1653        'D': x := AnEvent.EventName;  //'D': x := 'Discharge';
1654        end;
1655      end;
1656    end
1657    else uLastConfirm := '';
1658    Result := True;
1659  end;
1660  
1661  procedure SetConfirmEventDelay;
1662  begin
1663    uLastConfirm := '';
1664  end;
1665  
1666  procedure ChangeOrders(AList: TStringList; AnEvent: TOrderDelayEvent);
1667  var
1668    i,txtOrder: Integer;
1669    FieldsForEditRenewOrder: TOrderRenewFields;
1670    param1, param2 : string;
1671    OrSts: integer;
1672    AnOrder: TOrder;
1673  begin
1674    if uOrderDialog <> nil then
1675    begin
1676      uOrderDialog.Close;
1677      Application.ProcessMessages;  // allow close to finish
1678    end;
1679  
1680    if not ActiveOrdering then      // allow change while entering new
1681      if not ReadyForNewOrder(AnEvent) then Exit;
1682    for i := 0 to AList.Count - 1 do
1683    begin
1684      //if it's for unreleased renewed orders, then go to fODChangeUnreleasedRenew and continue
1685      txtOrder := 0;
1686      FieldsForEditRenewOrder := TOrderRenewFields.Create;
1687      LoadRenewFields(FieldsForEditRenewOrder, AList[i]);
1688      if FieldsForEditRenewOrder.BaseType = OD_TEXTONLY then
1689        txtOrder := 1;
1690      if CanEditSuchRenewedOrder(AList[i], txtOrder) then
1691      begin
1692        param1 := '0';
1693        if txtOrder = 0 then
1694        begin
1695          param1 := IntToStr(FieldsForEditRenewOrder.Refills);
1696          param2 := FieldsForEditRenewOrder.Pickup;
1697        end else if txtOrder = 1 then
1698        begin
1699          param1 := FieldsForEditRenewOrder.StartTime;
1700          param2 := FieldsForEditRenewOrder.StopTime;
1701        end;
1702        UBAGlobals.SourceOrderID := AList[i]; //hds6265 added
1703        ExecuteChangeRenewedOrder(AList[i], param1, param2, txtOrder, AnEvent);
1704        AnOrder := TOrder.Create;
1705        SaveChangesOnRenewOrder(AnOrder, AList[i], param1, param2, txtOrder);
1706        AnOrder.ActionOn := AnOrder.ID + '=RN';
1707        SendMessage(Application.MainForm.Handle, UM_NEWORDER, ORDER_ACT, Integer(AnOrder));
1708        Application.ProcessMessages;
1709        Continue;
1710      end else FieldsForEditRenewOrder.Free;
1711  
1712      OrSts := GetOrderStatus(AList[i]);
1713      if ( AnsiCompareText(NameOfStatus(OrSts),'active') = 0 ) and (AnEvent.PtEventIFN > 0) then
1714        EventDefaultOD := 1;
1715      ActivateOrderDialog('X' + AList[i], AnEvent, Application, -1);  // X + ORIFN for change
1716      if EventDefaultOD = 1 then
1717        EventDefaultOD := 0;
1718      Application.ProcessMessages;  // give uOrderDialog a chance to go back to nil
1719      if BILLING_AWARE then //hds6265
1720      begin              //hds6265
1721        UBAGlobals.SourceOrderID := AList[i]; //hds6265
1722        UBAGlobals.CopyTreatmentFactorsDxsToCopiedOrder(UBAGlobals.SourceOrderID,UBAGlobals.TargetOrderID); //hds6265
1723      end;
1724    end;
1725    UnlockIfAble;
1726  end;
1727  
1728  function ChangeOrdersEvt(AnOrderID: string; AnEvent: TOrderDelayEvent): boolean;
1729  begin
1730    Result := False;
1731    if uOrderDialog <> nil then
1732    begin
1733      uOrderDialog.Close;
1734      Application.ProcessMessages;
1735    end;
1736    if not ActiveOrdering then
1737      if not ReadyForNewOrder(AnEvent) then Exit;
1738    Result := ActivateOrderDialog('X' + AnOrderID, AnEvent, Application, -1);
1739    Application.ProcessMessages;
1740    UnlockIfAble;
1741  end;
1742  
1743  function CopyOrders(AList: TStringList; AnEvent: TOrderDelayEvent; var DoesEventOccur: boolean; ANeedVerify: boolean = True): boolean;
1744  var
1745    i: Integer;
1746    xx: string;
1747    IsIMOOD,ForIVAlso: boolean;
1748  begin
1749    Result := False;
1750    if not ReadyForNewOrder(AnEvent) then Exit;              // no copy while entering new
1751    for i := 0 to AList.Count - 1 do
1752       begin
1753         if (not DoesEventOccur) and (AnEvent.PtEventIFN>0) and IsCompletedPtEvt(AnEvent.PtEventIFN) then
1754            begin
1755              DoesEventOccur := True;
1756              AnEvent.EventType := #0;
1757              AnEvent.TheParent := TParentEvent.Create;
1758              AnEvent.EventIFN  := 0;
1759              AnEvent.EventName := '';
1760              AnEvent.PtEventIFN := 0;
1761            end;
1762  
1763         if CheckOrderGroup(AList[i])=1 then IsUDGroup := True
1764         else IsUDGroup := False;
1765  
1766         if (AnEvent.EventIFN>0) and isOnholdMedOrder(AList[i]) then
1767            begin
1768              xx := RetrieveOrderText(AList[i]);
1769              if InfoBox(TX_ONHOLD+#13#13+xx, 'Warning', MB_YESNO or MB_ICONWARNING) = IDNO then
1770                Continue;
1771            end;
1772  
1773         DEASig := GetDrugSchedule(AList[i]);
1774         ForIVAlso := ForIVandUD(AList[i]);
1775         IsIMOOD := IsIMOOrder(AList[i]);
1776         if (IsUDGroup) and (ImmdCopyAct) and (not Patient.Inpatient) and (AnEvent.EventType = 'C') and (not IsIMOOD) and (not ForIVAlso) then
1777              XfInToOutNow := True;
1778  
1779         OrderSource := 'C';
1780  
1781         if ActivateOrderDialog('C' + AList[i], AnEvent, Application, -1, ANeedVerify) then
1782           Result := True;
1783  
1784         Application.ProcessMessages;  // give uOrderDialog a chance to go back to nil
1785         OrderSource := '';
1786  
1787         if (not DoesEventOccur) and (AnEvent.PtEventIFN>0) and IsCompletedPtEvt(AnEvent.PtEventIFN) then
1788           DoesEventOccur := True;
1789  
1790         if IsUDGroup then IsUDGroup := False;
1791         if XfInToOutNOw then XfInToOutNow := False;
1792  
1793         if BILLING_AWARE then
1794         begin
1795            UBAGlobals.SourceOrderID := AList[i]; //BAPHII 1.3.2
1796            UBAGlobals.CopyTreatmentFactorsDxsToCopiedOrder(UBAGlobals.SourceOrderID,UBAGlobals.TargetOrderID);
1797         end;
1798       end; //for
1799  
1800    UnlockIfAble;
1801  end;
1802  
1803  function TransferOrders(AList: TStringList; AnEvent: TOrderDelayEvent; var DoesEventOccur: boolean; ANeedVerify: boolean = True): boolean;
1804  var
1805    i, CountOfTfOrders: Integer;
1806    xx: string;
1807    //DoesEventOccur: boolean;
1808    //OccuredEvtID: integer;
1809    //OccuredEvtName: string;
1810  begin
1811    //DoesEventOccur := False;
1812    //OccuredEvtID := 0;
1813    Result := False;
1814    if not ReadyForNewOrder(AnEvent) then Exit;              // no xfer while entering new
1815    CountOfTfOrders := AList.Count;
1816    for i := 0 to CountOfTfOrders - 1 do
1817    begin
1818      if (not DoesEventOccur) and (AnEvent.PtEventIFN>0) and IsCompletedPtEvt(AnEvent.PtEventIFN) then
1819      begin
1820        DoesEventOccur := True;
1821        //OccuredEvtID := AnEvent.PtEventIFN;
1822        //OccuredEvtName := AnEvent.EventName;
1823        AnEvent.EventType := #0;
1824        AnEvent.TheParent := TParentEvent.Create;
1825        AnEvent.EventIFN  := 0;
1826        AnEvent.EventName := '';
1827        AnEvent.PtEventIFN := 0;
1828      end;
1829      if i = CountOfTfOrders - 1 then
1830      begin
1831        if (AnEvent.EventIFN>0) and isOnholdMedOrder(AList[i]) then
1832        begin
1833          xx := RetrieveOrderText(AList[i]);
1834          if InfoBox(TX_ONHOLD+#13#13+xx, 'Warning', MB_YESNO or MB_ICONWARNING) = IDNO then
1835            Continue;
1836        end;
1837        OrderSource := 'X';
1838        if ActivateOrderDialog('T' + AList[i], AnEvent, Application, -2, ANeedVerify) then
1839          Result := True;
1840      end  else
1841      begin
1842        if (AnEvent.EventIFN>0) and isOnholdMedOrder(AList[i]) then
1843        begin
1844          xx := RetrieveOrderText(AList[i]);
1845          if InfoBox(TX_ONHOLD+#13#13+xx, 'Warning', MB_YESNO or MB_ICONWARNING) = IDNO then
1846            Continue;
1847        end;
1848        OrderSource := 'X';
1849        if ActivateOrderDialog('T' + AList[i], AnEvent, Application, -1, ANeedVerify) then
1850          Result := True;
1851      end;
1852      Application.ProcessMessages;  // give uOrderDialog a chance to go back to nil
1853      OrderSource := '';
1854      if (not DoesEventOccur) and (AnEvent.PtEventIFN>0) and IsCompletedPtEvt(AnEvent.PtEventIFN) then
1855        DoesEventOccur := True;
1856  
1857     UBAGlobals.SourceOrderID := AList[i];
1858     UBAGlobals.CopyTreatmentFactorsDxsToCopiedOrder(UBAGlobals.SourceOrderID, UBAGlobals.TargetOrderID);
1859  
1860    end;
1861    UnlockIfAble;
1862  
1863  end;
1864  
1865  procedure DestroyingOrderAction;
1866  begin
1867    uOrderAction := nil;
1868    if not ActiveOrdering then
1869    begin
1870      ClearOrderRecall;
1871      UnlockIfAble;
1872    end;
1873  end;
1874  
1875  procedure DestroyingOrderDialog;
1876  begin
1877    uOrderDialog := nil;
1878    if not ActiveOrdering then
1879    begin
1880      ClearOrderRecall;
1881      UnlockIfAble;
1882    end;
1883  end;
1884  
1885  procedure DestroyingOrderHTML;
1886  begin
1887    uOrderHTML := nil;
1888    if not ActiveOrdering then
1889    begin
1890      ClearOrderRecall;
1891      UnlockIfAble;
1892    end;
1893  end;
1894  
1895  procedure DestroyingOrderMenu;
1896  begin
1897    uOrderMenu := nil;
1898    if not ActiveOrdering then
1899    begin
1900      ClearOrderRecall;
1901      UnlockIfAble;
1902    end;
1903  end;
1904  
1905  procedure DestroyingOrderSet;
1906  begin
1907    uOrderSet := nil;
1908    uOrderSetTime := 0;
1909    if not ActiveOrdering then
1910    begin
1911      ClearOrderRecall;
1912      UnlockIfAble;
1913    end;
1914  end;
1915  
1916  function OrderIsLocked(const AnOrderID, AnAction: string): Boolean;
1917  var
1918    ErrorMsg: string;
1919  begin
1920    Result := True;
1921    if (AnAction = OA_COPY) then
1922      Exit;
1923    if ((AnAction = OA_HOLD) or (AnAction = OA_UNHOLD) or (AnAction = OA_RENEW)  or
1924        (AnAction = OA_DC) or (AnAction = OA_CHANGE)) and Changes.ExistForOrder(AnOrderID)
1925        then Exit;
1926    LockOrder(AnOrderID, ErrorMsg);
1927    if Length(ErrorMsg) > 0 then
1928    begin
1929      Result := False;
1930      InfoBox(ErrorMsg + CRLF + CRLF + TextForOrder(AnOrderID), TC_NOLOCK, MB_OK);
1931    end;
1932  end;
1933  
1934  procedure PopLastMenu;
1935  { always called from fOMSet }
1936  begin
1937    if uOrderMenu <> nil then uOrderMenu.cmdDoneClick(uOrderSet);
1938  end;
1939  
1940  procedure QuickOrderSave;
1941  begin
1942    // would be better to prompt for dialog
1943    if uOrderDialog = nil then
1944    begin
1945      InfoBox(TX_NO_SAVE_QO, TC_NO_SAVE_QO, MB_OK);
1946      Exit;
1947    end;
1948    with uOrderDialog do
1949    begin
1950      if not AllowQuickOrder then
1951      begin
1952        InfoBox(TX_NO_QUICK, TC_NO_QUICK, MB_OK);
1953        Exit;
1954      end;
1955      if Responses.OrderContainsObjects then
1956      begin
1957        InfoBox(TX_CANT_SAVE_QO, TC_NO_QUICK, MB_ICONERROR or MB_OK);
1958        Exit;
1959      end;
1960      SaveAsQuickOrder(Responses);
1961    end;
1962  end;
1963  
1964  procedure QuickOrderListEdit;
1965  begin
1966    // would be better to prompt for dialog
1967    if uOrderDialog = nil then
1968    begin
1969      InfoBox(TX_NO_EDIT_QO, TC_NO_EDIT_QO, MB_OK);
1970      Exit;
1971    end;
1972    with uOrderDialog do
1973    begin
1974      if not AllowQuickOrder then
1975      begin
1976        InfoBox(TX_NO_QUICK, TC_NO_QUICK, MB_OK);
1977        Exit;
1978      end;
1979      EditCommonList(DisplayGroup);
1980    end;
1981  end;
1982  
1983  function RefNumFor(AnOwner: TComponent): Integer;
1984  begin
1985    if (uOrderDialog <> nil) and (uOrderDialog.Owner = AnOwner)
1986      then Result := uOrderDialog.RefNum
1987    else if (uOrderMenu <> nil) and (uOrderMenu.Owner = AnOwner)
1988      then Result := uOrderMenu.RefNum
1989    else if (uOrderHTML <> nil) and (uOrderHTML.Owner = AnOwner)
1990      then Result := uOrderHTML.RefNum
1991    else if (uOrderSet <> nil) and (uOrderSet.Owner = AnOwner)
1992      then Result := uOrderSet.RefNum
1993    else Result := -1;
1994  end;
1995  
1996  procedure PrintOrdersOnSignReleaseMult(OrderList, ClinicLst, WardLst: TStringList; Nature: Char; EncLoc, WardLoc: integer;
1997  EncLocName, WardLocName: string);
1998  var
1999  i,j: integer;
2000  tempOrder: string;
2001  tempOrderList: TStringList;
2002  begin
2003    tempOrderList := TStringList.Create;
2004    if (ClinicLst <> nil) and (ClinicLst.Count > 0) then
2005      begin
2006        for i := 0 to ClinicLst.Count - 1 do
2007          begin
2008            tempOrder := ClinicLst.Strings[i];
2009            for j := 0 to OrderList.Count - 1 do
2010              if Piece(OrderList.Strings[j], U,1) = tempOrder then tempOrderList.Add(OrderList.Strings[j]);
2011          end;
2012        if tempOrderList.Count > 0 then PrintOrdersOnSignRelease(tempOrderList, Nature, EncLoc, EncLocName);
2013      end;
2014    if (WardLst <> nil) and (WardLst.Count > 0) then
2015      begin
2016        if tempOrderList.Count > 0 then
2017          begin
2018            tempOrderList.Free;
2019            tempOrderList := TStringList.Create;
2020          end;
2021        for i := 0 to WardLst.Count - 1 do
2022          begin
2023            tempOrder := WardLst.Strings[i];
2024            for j := 0 to OrderList.Count - 1 do
2025              if Piece(OrderList.Strings[j], U,1) = tempOrder then tempOrderList.Add(OrderList.Strings[j]);
2026          end;
2027        if tempOrderList.Count > 0 then PrintOrdersOnSignRelease(tempOrderList, Nature, WardLoc, WardLocName);
2028      end;
2029      tempOrderList.Free;
2030  end;
2031  
2032  procedure PrintOrdersOnSignRelease(OrderList: TStringList; Nature: Char; PrintLoc : Integer =0; PrintName: string = '');
2033  const
2034    TX_NEW_LOC1   = 'The patient''s location has changed to ';
2035    TX_NEW_LOC2   = '.' + CRLF + 'Should the orders be printed using the new location?';
2036    TC_NEW_LOC    = 'New Patient Location';
2037    TX_SIGN_LOC   = 'No location was selected.  Orders could not be printed!';
2038    TC_REQ_LOC    = 'Orders Not Printed';
2039    TX_LOC_PRINT  = 'The selected location will be used to determine where orders are printed.';
2040  var
2041    ALocation: Integer;
2042    AName, ASvc, DeviceInfo: string;
2043    PrintIt: Boolean;
2044  begin
2045    if PrintLoc = 0 then
2046      begin
2047        CurrentLocationForPatient(Patient.DFN, ALocation, AName, ASvc);
2048        if (ALocation > 0) and (ALocation <> Encounter.Location) then
2049          begin
2050            if InfoBox(TX_NEW_LOC1 + AName + TX_NEW_LOC2, TC_NEW_LOC, MB_YESNO) = IDYES
2051            then Encounter.Location := ALocation;
2052          end;
2053      end;
2054    //else
2055    //Encounter.Location := PrintLoc;
2056    if (PrintLoc = 0) and (Encounter.Location > 0) then PrintLoc := Encounter.Location;
2057    if PrintLoc = 0
2058      then PrintLoc := CommonLocationForOrders(OrderList);
2059    if PrintLoc = 0 then                      // location required for DEVINFO
2060    begin
2061      LookupLocation(ALocation, AName, LOC_ALL, TX_LOC_PRINT);
2062      if ALocation > 0 then
2063        begin
2064          PrintLoc := ALocation;
2065          Encounter.Location := ALocation;
2066        end;
2067    end;
2068    if printLoc = 0 then frmFrame.DisplayEncounterText;
2069    if PrintLoc <> 0 then
2070    begin
2071      SetupOrdersPrint(OrderList, DeviceInfo, Nature, False, PrintIt, PrintName, PrintLoc);
2072      if PrintIt then
2073        PrintOrdersOnReview(OrderList, DeviceInfo, PrintLoc)
2074      else
2075        PrintServiceCopies(OrderList, PrintLoc);
2076    end
2077    else InfoBox(TX_SIGN_LOC, TC_REQ_LOC, MB_OK or MB_ICONWARNING);
2078  end;
2079  
2080  procedure SetFontSize( FontSize: integer);
2081  begin
2082    if uOrderDialog <> nil then
2083      uOrderDialog.SetFontSize( FontSize);
2084    if uOrderMenu <> nil then
2085      uOrderMenu.ResizeFont;
2086  end;
2087  
2088  procedure NextMove(var NMRec: TNextMoveRec; LastIndex: Integer; NewIndex: Integer);
2089  begin
2090     if LastIndex = 0 then
2091        LastIndex  := NewIndex;
2092     if (LastIndex - NewIndex) <= 0 then
2093         NMRec.NextStep := STEP_FORWARD
2094     else
2095         NMRec.NextStep := STEP_BACK;
2096     NMRec.LastIndex := NewIndex;
2097  end;
2098  
2099  (*function GetQOAltOI: integer;
2100  begin
2101    Result := QOAltOI.OI;
2102  end; *)
2103  
2104  function IsIMODialog(DlgID: integer): boolean; //IMO
2105  var
2106    IsInptDlg, IsIMOLocation: boolean;
2107    Td: TFMDateTime;
2108  begin
2109    result := False;
2110    IsInptDlg := False;
2111    //CQ #15188 - allow IMO functionality 23 hours after encounter date/time - TDP
2112    //Td := FMToday;
2113    Td := IMOTimeFrame;
2114    if ( (DlgID = MedsInDlgIen) or (DlgID = MedsIVDlgIen) or (IsInptQO(dlgId)) or (IsIVQO(dlgId))) then IsInptDlg := TRUE;
2115    IsIMOLocation := IsValidIMOLoc(Encounter.Location,Patient.DFN);
2116    if (IsInptDlg or IsInptQO(DlgID)) and (not Patient.Inpatient) and IsIMOLocation and (Encounter.DateTime > Td) then
2117      result := True;
2118  end;
2119  
2120  function AllowActionOnIMO(AnEvtTyp: char): boolean;
2121  var
2122    Td: TFMDateTime;
2123  begin
2124    Result := False;
2125    if (Patient.Inpatient) then
2126    begin
2127      Td := FMToday;
2128      if IsValidIMOLoc(Encounter.Location,Patient.DFN) and (Encounter.DateTime > Td) then
2129        Result := True;
2130    end
2131    else
2132    begin
2133      //CQ #15188 - allow IMO functionality 23 hours after encounter date/time - TDP
2134      //Td := FMToday;
2135      Td := IMOTimeFrame;
2136      if IsValidIMOLoc(Encounter.Location,Patient.DFN) and (Encounter.DateTime > Td) then
2137        Result := True
2138      else if AnEvtTyp in ['A','T'] then
2139        Result := True;
2140    end;
2141  end;
2142  
2143  function IMOActionValidation(AnId: string; var IsIMOOD: boolean; var x: string; AnEventType: char): boolean;
2144  var
2145    actName: string;
2146  begin
2147    // jd imo change
2148    Result := True;
2149    if CharAt(AnID, 1) in ['X','C'] then  // transfer IMO order doesn't need check
2150    begin
2151      IsIMOOD := IsIMOOrder(Copy(AnID, 2, Length(AnID)));
2152      If IsIMOOD then
2153      begin
2154        if (not AllowActionOnIMO(AnEventType)) then
2155        begin
2156          if CharAt(AnID,1) = 'X' then actName := 'change';
2157          if CharAt(AnID,1) = 'C' then actName := 'copy';
2158          x := 'You cannot ' + actName + ' the clinical medication order.';
2159          x := RetrieveOrderText(Copy(AnID, 2, Length(AnID))) + #13#13#10 + x;
2160          UnlockOrder(Copy(AnID, 2, Length(AnID)));
2161          result := False;
2162        end
2163        else
2164        begin
2165          if patient.Inpatient then
2166          begin
2167            if CharAt(AnID,1) = 'X' then actName := 'changing';
2168            if CharAt(AnID,1) = 'C' then actName := 'copying';
2169            if MessageDlg(TX_IMO_WARNING1 + actName +  TX_IMO_WARNING2 + #13#13#10 + x, mtWarning,[mbOK,mbCancel],0) = mrCancel then
2170            begin
2171              UnlockOrder(Copy(AnID, 2, Length(AnID)));
2172              result := False;
2173            end;
2174          end;
2175        end;
2176      end;
2177    end;
2178    if Piece(AnId,'^',1)='RENEW' then
2179    begin
2180      IsIMOOD := IsIMOOrder(Piece(AnID,'^',2));
2181      If IsIMOOD then
2182      begin
2183        if (not AllowActionOnIMO(AnEventType)) then
2184        begin
2185          x := 'You cannot renew the clinical medication order.';
2186          x := RetrieveOrderText(Piece(AnID,'^',2)) + #13#13#10 + x;
2187          UnlockOrder(Piece(AnID,'^',2));
2188          result := False;
2189        end
2190        else
2191        begin
2192          if Patient.Inpatient then
2193          begin
2194            if MessageDlg(TX_IMO_WARNING1 + 'renewing' + TX_IMO_WARNING2, mtWarning,[mbOK,mbCancel],0) = mrCancel then
2195            begin
2196              UnlockOrder(Copy(AnID, 2, Length(AnID)));
2197              result := False;
2198            end;
2199          end;
2200        end;
2201      end;
2202    end;
2203  end;
2204  
2205  //CQ #15188 - New function to allow IMO functionality 23 hours after encounter date/time - TDP
2206  function IMOTimeFrame: TFMDateTime;
2207  begin
2208    Result := DateTimeToFMDateTime(FMDateTimeToDateTime(FMNow) - (23/24));
2209  end;
2210  
2211  initialization
2212    uPatientLocked := False;
2213    uKeepLock      := False;
2214    uLastConfirm   := '';
2215    uOrderSetTime  := 0;
2216    uNewMedDialog  := 0;
2217    uOrderAction   := nil;
2218    uOrderDialog   := nil;
2219    uOrderHTML     := nil;
2220    uOrderMenu     := nil;
2221    uOrderSet      := nil;
2222    NSSchedule     := False;
2223    OriginalMedsOutHeight   := 0;
2224    OriginalMedsInHeight    := 0;
2225    OriginalNonVAMedsHeight := 0;
2226  
2227  end.

Module Calls (2 levels)


uOrders
 ├uConst
 ├rConsults
 │ ├rCore
 │ ├uCore
 │ ├uConsults
 │ └uTIU
 ├rOrders
 │ ├uCore...
 │ ├rCore...
 │ ├uConst
 │ ├UBAGlobals
 │ └UBACore
 ├fODBase
 │ ├fAutoSz
 │ ├uConst
 │ ├rOrders...
 │ ├rODBase
 │ ├uCore...
 │ ├UBAGlobals...
 │ ├UBACore...
 │ ├fOCAccept
 │ ├uODBase
 │ ├rCore...
 │ ├rMisc
 │ ├fTemplateDialog
 │ ├uEventHooks
 │ ├uTemplates
 │ ├rConsults...
 │ ├fOrders
 │ ├uOrders...
 │ ├fFrame
 │ ├fODDietLT
 │ └rODDiet
 ├XuDsigS
 │ ├wcrypt2
 │ ├XuDsigU
 │ ├XlfMime
 │ ├XuDsigConst
 │ ├WinSCard
 │ └fPINPrompt
 ├fODDiet
 │ ├fODBase...
 │ ├uConst
 │ ├uCore...
 │ ├rODBase...
 │ ├rODDiet...
 │ ├rCore...
 │ ├rOrders...
 │ ├fODDietLT...
 │ └uODBase...
 ├fODMisc
 │ ├fODBase...
 │ ├uConst
 │ └rODBase...
 ├fODGen
 │ ├fODBase...
 │ ├rODBase...
 │ ├fBase508Form
 │ ├rCore...
 │ ├rOrders...
 │ └uConst
 ├fODMedIn
 │ ├fODBase...
 │ ├uConst
 │ ├rOrders...
 │ ├rODBase...
 │ └fODMedFA
 ├fODMedOut
 │ ├fODBase...
 │ ├uConst
 │ ├uCore...
 │ ├rOrders...
 │ ├rODBase...
 │ ├fODMedFA...
 │ └fODMedComplex
 ├fODText
 │ ├fODBase...
 │ ├uConst
 │ └rCore...
 ├fODConsult
 │ ├fODBase...
 │ ├uConst
 │ ├UBAGlobals...
 │ ├fBALocalDiagnoses
 │ ├UBAConst
 │ ├UBACore...
 │ ├rODBase...
 │ ├rConsults...
 │ ├uCore...
 │ ├uConsults...
 │ ├rCore...
 │ ├fPCELex
 │ ├rPCE
 │ ├fPreReq
 │ ├uTemplates...
 │ ├fFrame...
 │ ├uODBase...
 │ └uVA508CPRSCompatibility
 ├fODProc
 │ ├fODBase...
 │ ├uConst
 │ ├rODBase...
 │ ├rConsults...
 │ ├uCore...
 │ ├uConsults...
 │ ├rCore...
 │ ├fPCELex...
 │ ├rPCE...
 │ ├fPreReq...
 │ ├uTemplates...
 │ ├fFrame...
 │ ├uODBase...
 │ └uVA508CPRSCompatibility...
 ├fODRad
 │ ├fODBase...
 │ ├uConst
 │ ├rODBase...
 │ ├rODRad
 │ ├rOrders...
 │ ├uCore...
 │ ├rCore...
 │ ├fODRadApproval
 │ ├fODRadConShRes
 │ ├fLkUpLocation
 │ ├fFrame...
 │ └uFormMonitor
 ├fODLab
 │ ├fODBase...
 │ ├uConst
 │ ├rODBase...
 │ ├rODLab
 │ ├uCore...
 │ ├rCore...
 │ ├fODLabOthCollSamp
 │ ├fODLabOthSpec
 │ ├fODLabImmedColl
 │ ├fLabCollTimes
 │ ├rOrders...
 │ ├fRptBox
 │ └fFrame...
 ├fODBBank
 │ ├fODBase...
 │ ├uConst
 │ ├rODBase...
 │ ├rODLab...
 │ ├uCore...
 │ ├rCore...
 │ ├fODLabOthCollSamp...
 │ ├fODLabOthSpec...
 │ ├fODLabImmedColl...
 │ ├fLabCollTimes...
 │ └rOrders...
 ├fODMeds
 │ ├fODBase...
 │ ├uConst
 │ ├XuDigSigSC_TLB
 │ ├rCore...
 │ ├uCore...
 │ ├rODMeds
 │ ├rODBase...
 │ ├rOrders...
 │ ├fRptBox...
 │ ├fODMedOIFA
 │ ├uOrders...
 │ ├fOtherSchedule
 │ └fFrame...
 ├fODMedIV
 │ ├fODBase...
 │ ├fIVRoutes
 │ ├uConst
 │ ├rODMeds...
 │ ├rODBase...
 │ ├fFrame...
 │ ├uCore...
 │ ├fOtherSchedule...
 │ └rCore...
 ├fODVitals
 │ ├fODBase...
 │ ├uConst
 │ ├rODBase...
 │ └fFrame...
 ├fODAuto
 │ ├fODBase...
 │ ├rODBase...
 │ ├rOrders...
 │ ├fTemplateDialog...
 │ ├uTemplateFields
 │ ├rTemplates
 │ ├uConst
 │ ├uTemplates...
 │ ├rConsults...
 │ ├uCore...
 │ ├uODBase...
 │ ├rODMeds...
 │ └fFrame...
 ├fOMNavA
 │ ├uConst
 │ ├rOrders...
 │ ├uOrders...
 │ ├fBase508Form...
 │ ├rODBase...
 │ ├fODBase...
 │ ├rMisc...
 │ ├uODBase...
 │ └fOrders...
 ├rCore...
 ├uCore...
 ├fFrame...
 ├fEncnt
 │ ├rOptions
 │ ├fBase508Form...
 │ ├fFrame...
 │ ├rCore...
 │ ├uCore...
 │ ├uConst
 │ ├fReview
 │ └rPCE...
 ├fOMVerify
 │ ├fAutoSz...
 │ ├uConst
 │ ├rMisc...
 │ └uODBase...
 ├fOrderSaveQuick
 │ ├fAutoSz...
 │ ├fODBase...
 │ ├uOrders...
 │ ├rODBase...
 │ ├rOrders...
 │ └fRename
 ├fOMSet
 │ ├rOrders...
 │ ├uConst
 │ ├rODMeds...
 │ ├fODBase...
 │ ├fOrders...
 │ ├fFrame...
 │ ├fBase508Form...
 │ ├uOrders...
 │ ├rMisc...
 │ └uODBase...
 ├rMisc...
 ├uODBase...
 ├rODMeds...
 ├fLkUpLocation...
 ├fOrdersPrint
 │ ├rOrders...
 │ ├fFrame...
 │ ├fBase508Form...
 │ ├fDeviceSelect
 │ └uCore...
 ├fOMAction
 │ ├fAutoSz...
 │ └uConst
 ├fARTAllgy
 │ ├uConst
 │ ├fOMAction...
 │ ├rODAllergy
 │ ├uOrders...
 │ ├uCore...
 │ ├rCore...
 │ ├rCover
 │ ├fCover
 │ ├fAllgyFind
 │ └fRptBox...
 ├fOMHTML
 │ ├fOMAction...
 │ ├rOrders...
 │ ├uConst
 │ ├uCore...
 │ ├uOrders...
 │ └rMisc...
 ├fOrders...
 ├rODBase...
 ├fODChild
 │ └fAutoSz...
 ├fMeds
 │ ├fPage
 │ ├rOrders...
 │ ├uConst
 │ ├rMeds
 │ ├uCore...
 │ ├fFrame...
 │ ├fRptBox...
 │ ├uOrders...
 │ ├fODBase...
 │ ├fOrdersDC
 │ ├fOrdersHold
 │ ├fOrdersUnhold
 │ ├fOrdersRenew
 │ ├fOrdersRefill
 │ ├fMedCopy
 │ ├fOrders...
 │ ├rODBase...
 │ └fActivateDeactivate
 ├rMeds...
 ├rPCE...
 ├fRptBox...
 ├fODMedNVA
 │ ├fODBase...
 │ ├uConst
 │ ├XuDigSigSC_TLB
 │ ├uOrders...
 │ ├rCore...
 │ ├uCore...
 │ ├rODMeds...
 │ ├rODBase...
 │ ├rOrders...
 │ ├fRptBox...
 │ ├fODMedOIFA...
 │ └fFrame...
 ├fODChangeUnreleasedRenew
 │ ├fAutoSz...
 │ ├uOrders...
 │ ├rOrders...
 │ ├rODBase...
 │ └rODMeds...
 ├rODAllergy...
 ├UBAGlobals...
 └uTemplateFields...

Module Called-By (2 levels)


                    uOrders
                    uCore┤ 
                rOrders┤ │ 
                  rCore┤ │ 
                   rTIU┤ │ 
              rConsults┤ │ 
             uOrders...┤ │ 
                fODBase┤ │ 
                rODBase┤ │ 
             UBAGlobals┤ │ 
                UBACore┤ │ 
                 fFrame┤ │ 
               fTimeout┤ │ 
                rODMeds┤ │ 
                fOrders┤ │ 
                dShared┤ │ 
             uTemplates┤ │ 
             rTemplates┤ │ 
        uTemplateFields┤ │ 
         uDlgComponents┤ │ 
             uReminders┤ │ 
                   uPCE┤ │ 
      fBALocalDiagnoses┤ │ 
                fPCELex┤ │ 
                   rPCE┤ │ 
        fEncounterFrame┤ │ 
             fVisitType┤ │ 
             fDiagnoses┤ │ 
             fEncVitals┤ │ 
                uVitals┤ │ 
                 uProbs┤ │ 
                 rProbs┤ │ 
                fVitals┤ │ 
                 fCover┤ │ 
                 rCover┤ │ 
              fPtSelMsg┤ │ 
                 fPtSel┤ │ 
            fOrdersSign┤ │ 
         fPrintLocation┤ │ 
                  fMeds┤ │ 
                  rMeds┤ │ 
              fARTAllgy┤ │ 
             rODAllergy┤ │ 
                 fNotes┤ │ 
               uDocTree┤ │ 
         fConsult513Prt┤ │ 
               rReports┤ │ 
               fReports┤ │ 
                   rECS┤ │ 
                 fVisit┤ │ 
                 fEncnt┤ │ 
                 fProbs┤ │ 
               fProbEdt┤ │ 
               fProbLex┤ │ 
          fReportsPrint┤ │ 
                fGraphs┤ │ 
             fGraphData┤ │ 
         fGraphProfiles┤ │ 
           fGraphOthers┤ │ 
                  rLabs┤ │ 
              fConsults┤ │ 
           fPCEProvider┤ │ 
          fDeviceSelect┤ │ 
                fDCSumm┤ │ 
                rDCSumm┤ │ 
        fTemplateEditor┤ │ 
            uEventHooks┤ │ 
        fReminderDialog┤ │ 
                fMHTest┤ │ 
                  fLabs┤ │ 
         fLabTestGroups┤ │ 
              fLabPrint┤ │ 
                fPtDemo┤ │ 
                fPtCWAD┤ │ 
                fReview┤ │ 
        fClinicWardMeds┤ │ 
           fCSRemaining┤ │ 
             rReminders┤ │ 
               fOptions┤ │ 
    fBAOptionsDiagnoses┤ │ 
             uSignItems┤ │ 
              fODDietLT┤ │ 
                rODDiet┤ │ 
           fOrdersPrint┤ │ 
               fSurgery┤ │ 
               rSurgery┤ │ 
uVA508CPRSCompatibility┤ │ 
          fDefaultEvent┤ │ 
      fPatientFlagMulti┤ │ 
           fOrdersRenew┤ │ 
                fODDiet┤ │ 
              fOrdersDC┤ │ 
              fOrdersCV┤ │ 
              fODMedOut┤ │ 
             fODConsult┤ │ 
             fConsultBS┤ │ 
          fConsultsView┤ │ 
            fConsultAct┤ │ 
                fODProc┤ │ 
              fCsltNote┤ │ 
             fNoteProps┤ │ 
                fNoteBA┤ │ 
               fNotePrt┤ │ 
               fTIUView┤ │ 
           fDCSummProps┤ │ 
              fEditProc┤ │ 
           fEditConsult┤ │ 
           fConsMedRslt┤ │ 
          fNoteCPFields┤ │ 
             fCombatVet┤ │ 
                 fODRad┤ │ 
                 fODLab┤ │ 
                 rODLab┤ │ 
          fLabCollTimes┤ │ 
               fODBBank┤ │ 
                fODMeds┤ │ 
               fODMedIV┤ │ 
                fODAuto┤ │ 
         fOrdersRelease┤ │ 
                fOMHTML┤ │ 
              fODMedNVA┤ │ 
         fOrdersOnChart┤ │ 
     fOrdersEvntRelease┤ │ 
        fODReleaseEvent┤ │ 
             fOCSession┤ │ 
              fOrdersTS┤ │ 
             mEvntDelay┤ │ 
              fODActive┤ │ 
            fOrdersCopy┤ │ 
               fMedCopy┤ │ 
                   fGAF┤ │ 
         fRemCoverSheet┤ │ 
               fPCEEdit┤ │ 
  fOptionsReportsCustom┤ │ 
 fOptionsReportsDefault┤ │ 
                   fvit┤ │ 
               fODAllgy┘ │ 
               fODBase...┤ 
               rODBase...┤ 
                fFrame...┤ 
               fOrders...┤ 
           fOrdersSign...┤ 
                 fMeds...┤ 
             fARTAllgy...┤ 
                fNotes...┤ 
             fConsults...┤ 
       fReminderDialog...┤ 
               fReview...┤ 
          fOrdersRenew...┤ 
             fOrdersCV...┤ 
               fODMeds...┤ 
                  fOMNavA┤ 
             uOrders...┘ │ 
          fOrderSaveQuick┤ 
             uOrders...┘ │ 
                   fOMSet┤ 
             uOrders...┘ │ 
        fOrdersRelease...┤ 
               fOMHTML...┤ 
             fODMedNVA...┤ 
 fODChangeUnreleasedRenew┤ 
             uOrders...┘ │ 
        fOrdersOnChart...┤ 
       fODReleaseEvent...┤ 
             fODActive...┘