Module

rOrders

Path

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

Last Modified

7/15/2014 3:26:42 PM

Initialization Code

initialization
  uDGroupAll := 0;
  uOrderChecksOn := #0;

Finalization Code

finalization
  if uDGroupMap <> nil then uDGroupMap.Free;

end.

Units Used in Interface

Name Comments
uCore -

Units Used in Implementation

Name Comments
rCore -
UBACore -
UBAGlobals -
uConst -

Classes

Name Comments
TOrder -
TOrderMenu -
TOrderMenuItem -
TOrderRenewFields -
TOrderView -
TParentEvent -
TSelectedOrder -

Procedures

Name Owner Declaration Scope Comments
AlertOrder - procedure AlertOrder(AnOrder: TOrder; AlertRecip: Int64); Interfaced -
Assign TOrder procedure Assign(Source: TOrder); Public TOrder methods
Assign TOrderView procedure Assign(Src: TOrderView); Public TOrderView methods
Assign TParentEvent procedure Assign(AnEvtID: string); Public TParentEvent
BuildResponses - procedure BuildResponses(var ResolvedDialog: TOrderDialogResolved; const KeyVars: string; AnEvent: TOrderDelayEvent; ForIMO: boolean = False); Interfaced
Write Orders
Write Orders
ChangeEvent - procedure ChangeEvent(AnOrderList: TStringList; APtEvtId: string); Interfaced -
ChangeOrder - procedure ChangeOrder(AnOrder: TOrder; ResponseList: TList); Interfaced -
Clear TOrder procedure Clear; Public -
ClearOrderRecall - procedure ClearOrderRecall; Interfaced -
ClearOrders - procedure ClearOrders(AList: TList); Interfaced -
CompleteOrder - procedure CompleteOrder(AnOrder: TOrder; const ESCode: string); Interfaced -
DCOrder - procedure DCOrder(AnOrder: TOrder; AReason: Integer; NewOrder: boolean; var DCType: Integer); Interfaced -
DeleteDefaultEvt - procedure DeleteDefaultEvt; Interfaced -
DeleteMonograph - procedure DeleteMonograph(); procedure GetMonographList(ListOfMonographs: TStringList); procedure GetMonograph(Monograph: TStringList; x: Integer); procedure GetXtraTxt(OCText: TStringList; x: String; y: String); function FillerIDForDialog(IEN: Integer): string; function OrderChecksEnabled: Boolean; function OrderChecksOnDisplay(const FillerID: string): string; procedure OrderChecksOnAccept(ListOfChecks: TStringList; const FillerID, StartDtTm: string; OIList: TStringList; DupORIFN: string; Renewal: string); procedure OrderChecksOnDelay(ListOfChecks: TStringList; const FillerID, StartDtTm: string; OIList: TStringList); procedure OrderChecksForSession(ListOfChecks, OrderList: TStringList); procedure SaveOrderChecksForSession(const AReason: string; ListOfChecks: TStringList); function DeleteCheckedOrder(const OrderID: string): Boolean; function DataForOrderCheck(const OrderID: string): string; { Copay } procedure GetCoPay4Orders; procedure SaveCoPayStatus(AList: TStrings); {IMO: inpatient medication for outpatient} function IsValidIMOLoc(LocID: integer; PatientID: string): boolean; Interfaced
Copay 
IMO: inpatient medication for outpatient
None-standard Schedule} //nss
 TOrderView methods 
 TOrder methods 
 Order List functions 
Return FM date/time to begin search for expired orders
 Result = 1     Inpatient Medication Display Group;
 Result = 2     OutPatient Medication Display Group;
 Result = 0     None of In or Out patient display group;
           1   2    3     4      5     6   7   8   9    10    11    12    13    14     15     16  17    18    19     20         21          22              23               24
{Pieces: ~IFN^Grp^ActTm^StrtTm^StopTm^Sts^Sig^Nrs^Clk^PrvID^PrvNam^ActDA^Flag^DCType^ChrtRev^DEA#^VA#^DigSig^IMO^DCOrigOrder^ISDCOrder^IsDelayOrder^IsControlledSubstance^IsDetox

AGP Changes 26.15 PSI-04-063
if DGroupName = 'Non-VA Meds' then Text := 'Non-VA  ' + Text;
Filter, Specialty, Groups: Integer; var TextView: Integer;
  var CtxtTime: TFMDateTime);
if (Piece(RPCBrokerV.Results[0], U, 1) = '0') or (Piece(RPCBrokerV.Results[0], U, 1) = '') then      // if no orders found (0 element is count)
  begin
    AnOrder := TOrder.Create;
    with AnOrder do
    begin
      ID := '0';
      DGroup := 0;
      OrderTime := FMNow;
      Status := 97;
      Text := 'No orders found.';
      Retrieved := True;
    end;
    Dest.Add(AnOrder);
    Exit;
  end;














 MOVE THESE FUNCTIONS INTO UORDERS??? 
 < 0 if Item1 is less and Item2, 0 if they are equal and > 0 if Item1 is greater than Item2 
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
 Write Orders 
FLDS=DFN^LOC^ORNP^INPT^SEX^AGE^EVENT^SC%^^^Key Variables
 LST(0)=QuickLevel^ResponseID(ORIT;$H)^Dialog^Type^FormID^DGrp
 Results[0] = Name^Cols^PathSwitch^^^LRFZX^LRFSAMP^LRFSPEC^LRFDATE^LRFURG^LRFSCH^PSJNPOC^
              GMRCNOPD^GMRCNOAT^GMRCREAF^^^^^
 prepending the space to ESCode is temporary way to keep broker from crashing 
 this is a stop gap way to prevent an undesired error message when user chooses not to sign 
 prepending the space to ESCode is temporary way to keep broker from crashing 
 this is a stop gap way to prevent an undesired error message when user chooses not to sign 
 Order Actions 
 put RenewFields into tmplst[0]=BaseType^Start^Stop^Refills^Pickup, tmplst[n]=comments 
Begin Billing Aware
End Billing Aware
 put quotes around everything to prevent broker from choking
Begin Billing Aware
End Billing Aware
AGP Change 26.15 for PSI-04-63
DefaultIEN := StrToIntDef(Piece(ExtractDefault(RPCBrokerV.Results, 'DCReason'), U, 1), 0);
 don't worry about results
 Order Information 

 Order Checking
DeletePtEvent - procedure DeletePtEvent(APtEvtID: string); Interfaced -
ExecutePrintOrders - procedure ExecutePrintOrders(SelectedList: TStringList; const DeviceInfo: string); Interfaced -
FlagOrder - procedure FlagOrder(AnOrder: TOrder; const FlagReason: string; AlertRecip: Int64); Interfaced -
GetChildEvent - procedure GetChildEvent(var AChildList: TStringList; APtEvtID: string); Interfaced -
GetChildrenOfComplexOrder - procedure GetChildrenOfComplexOrder(AnParentID,CurrAct: string; var ChildList: TStringList); Interfaced
PSI-COMPLEX
PSI-COMPLEX
GetCoPay4Orders - procedure GetCoPay4Orders; Interfaced
Copay
Copay
GetMonograph - procedure GetMonograph(Monograph: TStringList; x: Integer); Interfaced -
GetMonographList - procedure GetMonographList(ListOfMonographs: TStringList); Interfaced -
GetTSListForEvt - procedure GetTSListForEvt(Dest: TStrings; AnEvtID:integer); Interfaced -
GetXtraTxt - procedure GetXtraTxt(OCText: TStringList; x: String; y: String); Interfaced -
HoldOrder - procedure HoldOrder(AnOrder: TOrder); Interfaced -
IsLatestAction - procedure IsLatestAction(const ID: string; var ErrList: TStringList); Interfaced -
LESValidationForChangedLabOrder - procedure LESValidationForChangedLabOrder(var RejectedReason: TStringList; AnOrderInfo: string); Interfaced -
ListDCReasons - procedure ListDCReasons(Dest: TStrings; var DefaultIEN: Integer); Interfaced -
ListDGroupAll - procedure ListDGroupAll(Dest: TStrings); Interfaced -
ListOrderFilters - procedure ListOrderFilters(Dest: TStrings); Interfaced -
ListOrderFiltersAll - procedure ListOrderFiltersAll(Dest: TStrings); Interfaced -
ListSpecialties - procedure ListSpecialties(Dest: TStrings); Interfaced -
ListSpecialtiesED - procedure ListSpecialtiesED(AType: Char; Dest: TStrings); Interfaced -
LoadDGroupMap - procedure LoadDGroupMap; Global -
LoadFlagReason - procedure LoadFlagReason(Dest: TStrings; const ID: string); Interfaced -
LoadOrderMenu - procedure LoadOrderMenu(AnOrderMenu: TOrderMenu; AMenuIEN: Integer); Interfaced -
LoadOrders - procedure LoadOrders(Dest: TList; Filter, Groups: Integer); Interfaced -
LoadOrdersAbbr - procedure LoadOrdersAbbr(DestDC,DestRL: TList; AView: TOrderView; APtEvtID: string); overload; Interfaced -
LoadOrdersAbbr - procedure LoadOrdersAbbr(Dest: TList; AView: TOrderView; APtEvtID: string); overload; Interfaced
Filter, Specialty, Groups: Integer; var TextView: Integer;
  var CtxtTime: TFMDateTime);
LoadOrderSet - procedure LoadOrderSet(SetItems: TStrings; AnIEN: Integer; var KeyVars, ACaption: string); Interfaced -
LoadOrderSheets - procedure LoadOrderSheets(Dest: TStrings); Interfaced -
LoadOrderSheetsED - procedure LoadOrderSheetsED(Dest: TStrings); Interfaced -
LoadOrderViewDefault - procedure LoadOrderViewDefault(AView: TOrderView); Interfaced -
LoadRenewFields - procedure LoadRenewFields(RenewFields: TOrderRenewFields; const ID: string); Interfaced Order Information
LoadUnsignedOrders - procedure LoadUnsignedOrders(IDList, HaveList: TStrings); Interfaced -
LoadWardComments - procedure LoadWardComments(Dest: TStrings; const ID: string); Interfaced -
LoadWriteOrders - procedure LoadWriteOrders(Dest: TStrings); Interfaced -
LoadWriteOrdersED - procedure LoadWriteOrdersED(Dest: TStrings; EvtID: string); Interfaced -
LockOrder - procedure LockOrder(OrderID: string; var ErrMsg: string); Interfaced -
LockPatient - procedure LockPatient(var ErrMsg: string); Interfaced -
OrderChecksForSession - procedure OrderChecksForSession(ListOfChecks, OrderList: TStringList); Interfaced -
OrderChecksOnAccept - procedure OrderChecksOnAccept(ListOfChecks: TStringList; const FillerID, StartDtTm: string; OIList: TStringList; DupORIFN: string; Renewal: string); Interfaced -
OrderChecksOnDelay - procedure OrderChecksOnDelay(ListOfChecks: TStringList; const FillerID, StartDtTm: string; OIList: TStringList); Interfaced -
OrderPrintDeviceInfo - procedure OrderPrintDeviceInfo(OrderList: TStringList; var PrintParams: TPrintParams; Nature: Char; PrintLoc: Integer = 0); {*KCM*} Interfaced
KCM*
TEMPORARILY COMMENTED OUT WHILE TESTING
function GetPromptandDeviceParameters(Location: integer; OrderList: TStringList; Nature: string): TPrintParams;
var
  TempParams: TPrintParams;
  x: string;
begin
  tempParams.OrdersToPrint := TStringList.Create;
  try
    CallV('ORWD1 PARAM', [Location, Nature, OrderList]);
    x := RPCBrokerV.Results[0];
    with TempParams do
      begin
        PromptForChartCopy    := CharAt(Piece(x, U, 1),1);
        if Piece(x, U, 5) <> '' then
          ChartCopyDevice     := Piece(Piece(x, U, 5),';',1) + '^' + Piece(Piece(x, U, 5),';',2);
        PromptForLabels       := CharAt(Piece(x, U, 2),1);
        if Piece(x, U, 6) <> '' then
          LabelDevice         := Piece(Piece(x, U, 6),';',1) + '^' + Piece(Piece(x, U, 6),';',2);
        PromptForRequisitions := CharAt(Piece(x, U, 3),1);
        if Piece(x, U, 7) <> '' then
          RequisitionDevice   := Piece(Piece(x, U, 7),';',1) + '^' + Piece(Piece(x, U, 7),';',2);
        PromptForWorkCopy     := CharAt(Piece(x, U, 4),1);
        if Piece(x, U, 8) <> '' then
          WorkCopyDevice      := Piece(Piece(x, U, 8),';',1) + '^' + Piece(Piece(x, U, 8),';',2);
        AnyPrompts            := ((PromptForChartCopy    in ['1','2']) or
                                  (PromptForLabels       in ['1','2']) or
                                  (PromptForRequisitions in ['1','2']) or
                                  (PromptForWorkCopy     in ['1','2']));
        RPCBrokerV.Results.Delete(0);
        FastAssign(RPCBrokerV.Results, OrdersToPrint);
      end;
    Result := TempParams;
  finally
    tempParams.OrdersToPrint.Free;
  end;
end;
PrintOrdersOnReview - procedure PrintOrdersOnReview(OrderList: TStringList; const DeviceInfo: string; PrintLoc: Integer = 0); {*KCM*} Interfaced KCM*
PrintServiceCopies - procedure PrintServiceCopies(OrderList: TStringList; PrintLoc: Integer = 0); {*REV*} Interfaced
REV*
REV*
PutWardComments - procedure PutWardComments(Src: TStrings; const ID: string; var ErrMsg: string); Interfaced -
ReleaseOrderHold - procedure ReleaseOrderHold(AnOrder: TOrder); Interfaced -
RenewOrder - procedure RenewOrder(AnOrder: TOrder; RenewFields: TOrderRenewFields; IsComplex: integer; AnIMOOrderAppt: double; OCList: TStringList); Interfaced Put RenewFields into tmplst[0]=BaseType^Start^Stop^Refills^Pickup, tmplst[n]=comments
RetrieveOrderFields - procedure RetrieveOrderFields(OrderList: TList; ATextView: Integer; ACtxtTime: TFMDateTime); Interfaced -
SaveChangesOnRenewOrder - procedure SaveChangesOnRenewOrder(var AnOrder: TOrder; AnID, TheRefills, ThePickup: string; IsTxtOrder: integer); Interfaced -
SaveCoPayStatus - procedure SaveCoPayStatus(AList: TStrings); Interfaced -
SaveEvtForOrder - procedure SaveEvtForOrder(APtDFN: string; AEvt: integer; AnOrderID: string); Interfaced -
SaveOrderChecksForSession - procedure SaveOrderChecksForSession(const AReason: string; ListOfChecks: TStringList); Interfaced -
SaveOrderViewDefault - procedure SaveOrderViewDefault(AView: TOrderView); Interfaced -
SendAndPrintOrders - procedure SendAndPrintOrders(OrderList, ErrList: TStrings; const ESCode: string; const DeviceInfo: string); Interfaced -
SendOrders - procedure SendOrders(OrderList: TStringList; const ESCode: string); Interfaced -
SendReleaseOrders - procedure SendReleaseOrders(OrderList: TStringList); Interfaced -
SetOrderFields - procedure SetOrderFields(AnOrder: TOrder; const x, y, z: string); Interfaced
1   2    3     4      5     6   7   8   9    10    11    12    13    14     15     16  17    18    19     20         21          22              23               24
{Pieces: ~IFN^Grp^ActTm^StrtTm^StopTm^Sts^Sig^Nrs^Clk^PrvID^PrvNam^ActDA^Flag^DCType^ChrtRev^DEA#^VA#^DigSig^IMO^DCOrigOrder^ISDCOrder^IsDelayOrder^IsControlledSubstance^IsDetox
SetOrderFromResults - procedure SetOrderFromResults(AnOrder: TOrder); Interfaced -
SetPtEvtList - procedure SetPtEvtList(Dest: TStrings; APtDFN: string; var ATotal: integer); Interfaced -
SortOrders - procedure SortOrders(AList: TList; ByGroup, InvChron: Boolean); Interfaced -
StoreDigitalSig - procedure StoreDigitalSig(AID, AHash: string; AProvider: Int64; ASig, ACrlUrl, DFN: string; var AError: string); Interfaced -
TerminatePtEvt - procedure TerminatePtEvt(APtEvtID: integer); Interfaced -
UnflagOrder - procedure UnflagOrder(AnOrder: TOrder; const AComment: string); Interfaced -
UnlockOrder - procedure UnlockOrder(OrderID: string); Interfaced -
UnlockPatient - procedure UnlockPatient; Interfaced -
UpdateOrderDGIfNeeded - procedure UpdateOrderDGIfNeeded(AnID: string); Interfaced -
ValidateComplexOrderAct - procedure ValidateComplexOrderAct(AnOrderID: string; var ErrMsg: string); Interfaced
PSI-COMPLEX
PSI-COMPLEX
ValidateOrderAction - procedure ValidateOrderAction(const ID, Action: string; var ErrMsg: string); Interfaced -
ValidateOrderActionNature - procedure ValidateOrderActionNature(const ID, Action, Nature: string; var ErrMsg: string); Interfaced -
VerifyOrder - procedure VerifyOrder(AnOrder: TOrder; const ESCode: string); Interfaced -
VerifyOrderChartReview - procedure VerifyOrderChartReview(AnOrder: TOrder; const ESCode: string); Interfaced -

Functions

Name Owner Declaration Scope Comments
AnyOrdersRequireSignature - function AnyOrdersRequireSignature(OrderList: TStringList): Boolean; Interfaced -
CanEditSuchRenewedOrder - function CanEditSuchRenewedOrder(AnID: string; IsTxtOrder: integer): boolean; Interfaced -
CanManualRelease - function CanManualRelease: boolean; Interfaced -
CheckOrderGroup - function CheckOrderGroup(AOrderID: string): integer; Interfaced -
CheckQOGroup - function CheckQOGroup(AQOId:string): Boolean; Interfaced -
CommonLocationForOrders - function CommonLocationForOrders(OrderList: TStringList): Integer; Interfaced -
CompleteEvt - function CompleteEvt(APtEvntID: string; APtEvntName: string; Ask: boolean = True): boolean; Interfaced -
DataForOrderCheck - function DataForOrderCheck(const OrderID: string): string; Interfaced -
DeleteCheckedOrder - function DeleteCheckedOrder(const OrderID: string): Boolean; Interfaced -
DeleteEmptyEvt - function DeleteEmptyEvt(APtEvntID: string; var APtEvntName: string; Ask: boolean = True): boolean; Interfaced Event Delay Enhancement
DetailOrder - function DetailOrder(const ID: string): TStrings; Interfaced
Order List functions
Order List functions
DGroupAll - function DGroupAll: Integer; Interfaced Display Group & List functions
DGroupIEN - function DGroupIEN(AName: string): Integer; Interfaced -
DialogForOrder - function DialogForOrder(const ID: string): Integer; Interfaced
Order Actions
Order Actions
DispOrdersForEvent - function DispOrdersForEvent(AEvtId: string): boolean; Interfaced -
DlgIENForName - function DlgIENForName(DlgName: string): Integer; Interfaced -
DoesOIPIInSigForQO - function DoesOIPIInSigForQO(AnQOID: integer): integer; Interfaced -
DoesOrderStatusMatch - function DoesOrderStatusMatch(OrderArray: TStringList): boolean; Interfaced -
EventExist - function EventExist(APtDFN:string; AEvt: integer): integer; Interfaced -
EventInfo - function EventInfo(APtEvtID: string): string; Interfaced Ptr to #100.2
EventInfo1 - function EventInfo1(AnEvtID: string): string; Interfaced Ptr to #100.5
ExpiredOrdersStartDT - function ExpiredOrdersStartDT: TFMDateTime; Interfaced Return FM date/time to begin search for expired orders
FillerIDForDialog - function FillerIDForDialog(IEN: Integer): string; Interfaced Order Checking
ForIVandUD - function ForIVandUD(AnOrderID: string): boolean; Interfaced -
FormIDForDialog - function FormIDForDialog(IEN: Integer): Integer; Interfaced -
FormIDForOrder - function FormIDForOrder(const ID: string): Integer; Interfaced -
ForwardByGroup - function ForwardByGroup(Item1, Item2: Pointer): Integer; Global -
ForwardChrono - function ForwardChrono(Item1, Item2: Pointer): Integer; Global -
GetConsultOrderNumber - function GetConsultOrderNumber(ConsultIEN: string): string; Interfaced -
GetCurrentSpec - function GetCurrentSpec(const APtIFN: string): string; Interfaced -
GetDEA - function GetDEA(const ID: string): string; Interfaced -
GetDefaultEvt - function GetDefaultEvt(const AProviderIFN: string): string; Interfaced -
GetDefaultTSForEvt - function GetDefaultTSForEvt(AnEvtID: integer): string; Interfaced -
GetDigitalSignature - function GetDigitalSignature(const ID: string): string; Interfaced -
GetDispGroupForLES - function GetDispGroupForLES: string; Interfaced -
GetDlgData - function GetDlgData(ADlgID: string): string; Interfaced -
GetDrugSchedule - function GetDrugSchedule(const ID: string): string; Interfaced -
GetEventDefaultDlg - function GetEventDefaultDlg(AEvtID: integer): string; Interfaced -
GetEventDiv - function GetEventDiv(const APtEvntID: string): string; Interfaced -
GetEventDiv1 - function GetEventDiv1(const AnEvntID: string): string; Interfaced -
GetEventIFN - function GetEventIFN(const AEvntID: string): string; Interfaced -
GetEventLoc - function GetEventLoc(const APtEvntID: string): string; Interfaced -
GetEventLoc1 - function GetEventLoc1(const AnEvntID: string): string; Interfaced -
GetEventName - function GetEventName(const AEvntID: string): string; Interfaced -
GetEventPromptID - function GetEventPromptID: integer; Interfaced -
GetExternalText - function GetExternalText(const ID: string): string; Interfaced -
GetOrderableIen - function GetOrderableIen(AnOrderId:string): integer; Interfaced -
GetOrderByIFN - function GetOrderByIFN(const ID: string): TOrder; Interfaced -
GetOrderPtEvtID - function GetOrderPtEvtID(AnOrderID: string): string; Interfaced -
GetOrderStatus - function GetOrderStatus(AnOrderId: string): integer; Interfaced -
GetPackageByOrderID - function GetPackageByOrderID(const OrderID: string): string; Interfaced -
GetPKISite - function GetPKISite: Boolean; Interfaced -
GetPKIUse - function GetPKIUse: Boolean; Interfaced -
GetPromptIDs - function GetPromptIDs: string; Interfaced -
GetREQReason - function GetREQReason: Integer; Interfaced -
InverseByGroup - function InverseByGroup(Item1, Item2: Pointer): Integer; Global < 0 if Item1 is less and Item2, 0 if they are equal and > 0 if Item1 is greater than Item2
InverseChrono - function InverseChrono(Item1, Item2: Pointer): Integer; Global -
IsClinicLoc - function IsClinicLoc(ALoc: integer): boolean; Interfaced -
IsCompletedPtEvt - function IsCompletedPtEvt(APtEvtID: integer): boolean; Interfaced -
IsComplexOrder - function IsComplexOrder(AnOrderID: string): boolean; Interfaced
PSI-COMPLEX
PSI-COMPLEX
isDCedOrder - function isDCedOrder(const AnOrderID: string): Boolean; Interfaced -
isExistedEvent - function isExistedEvent(const APtDFN: string; const AEvtID: string; var APtEvtID: string): Boolean; Interfaced -
IsIMOOrder - function IsIMOOrder(OrderID: string): boolean; Interfaced IMO
IsInptQO - function IsInptQO(DlgID: integer): boolean; Interfaced -
IsIVQO - function IsIVQO(DlgID: integer): boolean; Interfaced -
isMatchedEvent - function isMatchedEvent(const APtDFN: string; const AEvtID: string; var ATs: string): Boolean; Interfaced -
IsMonograph - function IsMonograph(): Boolean; procedure DeleteMonograph(); procedure GetMonographList(ListOfMonographs: TStringList); procedure GetMonograph(Monograph: TStringList; x: Integer); procedure GetXtraTxt(OCText: TStringList; x: String; y: String); function FillerIDForDialog(IEN: Integer): string; function OrderChecksEnabled: Boolean; function OrderChecksOnDisplay(const FillerID: string): string; procedure OrderChecksOnAccept(ListOfChecks: TStringList; const FillerID, StartDtTm: string; OIList: TStringList; DupORIFN: string; Renewal: string); procedure OrderChecksOnDelay(ListOfChecks: TStringList; const FillerID, StartDtTm: string; OIList: TStringList); procedure OrderChecksForSession(ListOfChecks, OrderList: TStringList); procedure SaveOrderChecksForSession(const AReason: string; ListOfChecks: TStringList); function DeleteCheckedOrder(const OrderID: string): Boolean; function DataForOrderCheck(const OrderID: string): string; { Copay } procedure GetCoPay4Orders; procedure SaveCoPayStatus(AList: TStrings); {IMO: inpatient medication for outpatient} function IsValidIMOLoc(LocID: integer; PatientID: string): boolean; Interfaced
Order Checking 

 Copay 
IMO: inpatient medication for outpatient
None-standard Schedule} //nss
 TOrderView methods 
 TOrder methods 
 Order List functions 
Return FM date/time to begin search for expired orders
 Result = 1     Inpatient Medication Display Group;
 Result = 2     OutPatient Medication Display Group;
 Result = 0     None of In or Out patient display group;
           1   2    3     4      5     6   7   8   9    10    11    12    13    14     15     16  17    18    19     20         21          22              23               24
{Pieces: ~IFN^Grp^ActTm^StrtTm^StopTm^Sts^Sig^Nrs^Clk^PrvID^PrvNam^ActDA^Flag^DCType^ChrtRev^DEA#^VA#^DigSig^IMO^DCOrigOrder^ISDCOrder^IsDelayOrder^IsControlledSubstance^IsDetox

AGP Changes 26.15 PSI-04-063
if DGroupName = 'Non-VA Meds' then Text := 'Non-VA  ' + Text;
Filter, Specialty, Groups: Integer; var TextView: Integer;
  var CtxtTime: TFMDateTime);
if (Piece(RPCBrokerV.Results[0], U, 1) = '0') or (Piece(RPCBrokerV.Results[0], U, 1) = '') then      // if no orders found (0 element is count)
  begin
    AnOrder := TOrder.Create;
    with AnOrder do
    begin
      ID := '0';
      DGroup := 0;
      OrderTime := FMNow;
      Status := 97;
      Text := 'No orders found.';
      Retrieved := True;
    end;
    Dest.Add(AnOrder);
    Exit;
  end;














 MOVE THESE FUNCTIONS INTO UORDERS??? 
 < 0 if Item1 is less and Item2, 0 if they are equal and > 0 if Item1 is greater than Item2 
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
MixedCaseList(RPCBrokerV.Results);
 Write Orders 
FLDS=DFN^LOC^ORNP^INPT^SEX^AGE^EVENT^SC%^^^Key Variables
 LST(0)=QuickLevel^ResponseID(ORIT;$H)^Dialog^Type^FormID^DGrp
 Results[0] = Name^Cols^PathSwitch^^^LRFZX^LRFSAMP^LRFSPEC^LRFDATE^LRFURG^LRFSCH^PSJNPOC^
              GMRCNOPD^GMRCNOAT^GMRCREAF^^^^^
 prepending the space to ESCode is temporary way to keep broker from crashing 
 this is a stop gap way to prevent an undesired error message when user chooses not to sign 
 prepending the space to ESCode is temporary way to keep broker from crashing 
 this is a stop gap way to prevent an undesired error message when user chooses not to sign 
 Order Actions 
 put RenewFields into tmplst[0]=BaseType^Start^Stop^Refills^Pickup, tmplst[n]=comments 
Begin Billing Aware
End Billing Aware
 put quotes around everything to prevent broker from choking
Begin Billing Aware
End Billing Aware
AGP Change 26.15 for PSI-04-63
DefaultIEN := StrToIntDef(Piece(ExtractDefault(RPCBrokerV.Results, 'DCReason'), U, 1), 0);
 don't worry about results
 Order Information 

 Order Checking
isOnholdMedOrder - function isOnholdMedOrder(AnOrderID: string): Boolean; Interfaced -
IsPassEvt - function IsPassEvt(APtEvtID: integer; APtEvtType: char): boolean; Interfaced -
IsPassEvt1 - function IsPassEvt1(AnEvtID: integer; AnEvtType: char): boolean; Interfaced -
IsPendingHold - function IsPendingHold(OrderID: string): boolean; Interfaced -
IsPSOSupplyDlg - function IsPSOSupplyDlg(DlgID, QODlg: integer): boolean; Interfaced -
IsRenewableComplexOrder - function IsRenewableComplexOrder(AnParentID: string): boolean; Interfaced
PSI-COMPLEX
PSI-COMPLEX
IsValidIMOLoc - function IsValidIMOLoc(LocID: integer; PatientID: string): boolean; Interfaced
IMO: inpatient medication for outpatient

IMO
IMO
IsValidQOSch - function IsValidQOSch(QOID: string): string; Interfaced
NSS
nss
IsValidSchedule - function IsValidSchedule(AnOrderID: string): boolean; Interfaced
None-standard Schedule} //nss

NSS
nss
IsValidSchStr - function IsValidSchStr(ASchStr: string): boolean; Interfaced -
NameOfDGroup - function NameOfDGroup(IEN: Integer): string; Interfaced -
NameOfStatus - function NameOfStatus(IEN: Integer): string; Interfaced -
OrderChecksEnabled - function OrderChecksEnabled: Boolean; Interfaced -
OrderChecksOnDisplay - function OrderChecksOnDisplay(const FillerID: string): string; Interfaced -
OrderDisabledMessage - function OrderDisabledMessage(DlgIEN: Integer): string; Interfaced -
OrderIsReleased - function OrderIsReleased(const ID: string): Boolean; Interfaced Order Information
OrderRequiresDigitalSignature - function OrderRequiresDigitalSignature(const ID: string): Boolean; Interfaced -
OrderRequiresSignature - function OrderRequiresSignature(const ID: string): Boolean; Interfaced -
PtEvtEmpty - function PtEvtEmpty(APtEvtID: string): Boolean; Interfaced -
ResultOrder - function ResultOrder(const ID: string): TStrings; Interfaced -
ResultOrderHistory - function ResultOrderHistory(const ID: string): TStrings; Interfaced -
SeqOfDGroup - function SeqOfDGroup(IEN: Integer): Integer; Interfaced -
SetDefaultEvent - function SetDefaultEvent(var AErrMsg: string; EvtID: string): Boolean; Interfaced -
SetExternalText - function SetExternalText(const ID: string; ADrugSch: string; AUser: Int64): string; Interfaced -
ShortNameOfDGroup - function ShortNameOfDGroup(IEN: Integer): string; Interfaced -
TextForOrder - function TextForOrder(const ID: string): string; Interfaced -
TheParentPtEvt - function TheParentPtEvt(APtEvt: string): string; Interfaced -
TopNameOfDGroup - function TopNameOfDGroup(IEN: Integer): string; Global -
TypeOfExistedEvent - function TypeOfExistedEvent(APtDFN: string; AEvtID: Integer): Integer; Interfaced -
UseNewMedDialogs - function UseNewMedDialogs: Boolean; Interfaced -
VerbTelPolicyOrder - function VerbTelPolicyOrder(AnOrderID: string): boolean; Interfaced -

Global Variables

Name Type Declaration Comments
uDGroupAll Integer uDGroupAll: Integer; -
uDGroupMap TStringList uDGroupMap: TStringList; Each string is DGroupIEN=Sequence^TopName^Name
uOrderChecksOn Char uOrderChecksOn: Char; -


Module Source

1     unit rOrders;
2     {$OPTIMIZATION OFF}
3     interface
4     
5     uses SysUtils, Classes, ORFn, ORNet, uCore, Dialogs, Controls;
6     
7     type
8       TOrder = class
9       public
10        ICD9Code:      string;
11        ID:           string;
12        DGroup:       Integer;
13        OrderTime:    TFMDateTime;
14        StartTime:    string;
15        StopTime:     string;
16        Status:       Integer;
17        Signature:    Integer;
18        VerNurse:     string;
19        VerClerk:     string;
20        ChartRev:     string;
21        Provider:     Int64;
22        ProviderName: string;
23        ProviderDEA:  string;
24        ProviderVa:   string;
25        DigSigReq:    string;
26        XMLText:      string;
27        Text:         string;
28        DGroupSeq:    Integer;
29        DGroupName:   string;
30        Flagged:      Boolean;
31        Retrieved:    Boolean;
32        EditOf:       string;
33        ActionOn:     string;
34        EventPtr:     string; //ptr to #100.2
35        EventName:    string; //Event name in #100.5
36        OrderLocIEN:  string; //imo
37        OrderLocName: string; //imo
38        ParentID    : string;
39        LinkObject:   TObject;
40        EnteredInError:     Integer; //AGP Changes 26.12 PSI-04-053
41        DCOriginalOrder: boolean;
42        IsOrderPendDC: boolean;
43        IsDelayOrder: boolean;
44        IsControlledSubstance: boolean;
45        IsDetox       : boolean;
46        procedure Assign(Source: TOrder);
47        procedure Clear;
48      end;
49    
50      TParentEvent = class
51      public
52        ParentIFN:  integer;
53        ParentName: string;
54        ParentType: Char;
55        ParentDlg:  string;
56        constructor Create;
57        procedure Assign(AnEvtID: string);
58      end;
59    
60      TOrderDelayEvent = record
61        EventType: Char;             // A=admit, T=transfer, D=discharge, C=current
62        TheParent: TParentEvent;     // Parent Event
63        EventIFN : Integer;          // Pointer to OE/RR EVENTS file (#100.5)
64        EventName: String;           // Event name from OR/RR EVENTS file (#100.5)
65        PtEventIFN: Integer;         // Patient event IFN ptr to #100.2
66        Specialty: Integer;          // pointer to facility treating specialty file
67        Effective: TFMDateTime;      // effective date/time (estimated start time)
68        IsNewEvent: Boolean;         // is new event for an patient
69      end;
70    
71      TOrderDialogResolved = record
72        InputID: string;             // can be dialog IEN or '#ORIFN'
73        QuickLevel: Integer;         // 0=dialog,1=auto,2=verify,8=reject,9=cancel
74        ResponseID: string;          // DialogID + ';' + $H
75        DialogIEN: Integer;          // pointer to 101.41 for dialog (may be quick order IEN)
76        DialogType: Char;            // type of dialog (Q or D)
77        FormID: Integer;             // windows form to display
78        DisplayGroup: Integer;       // pointer to 100.98, display group for dialog
79        ShowText: string;            // text to show for verify or rejection
80        QOKeyVars: string;           // from entry action of quick order
81      end;
82    
83      TNextMoveRec = record
84        NextStep:     Integer;
85        LastIndex:    Integer;
86      end;
87    
88      TOrderMenu = class
89        IEN: Integer;
90        NumCols: Integer;
91        Title: string;
92        KeyVars: string;
93        MenuItems: TList; {of TOrderMenuItem}
94      end;
95    
96      TOrderMenuItem = class
97        IEN: Integer;
98        Row: Integer;
99        Col: Integer;
100       DlgType: Char;
101       FormID: Integer;
102       AutoAck: Boolean;
103       ItemText: string;
104       Mnemonic: string;
105       Display: Integer;
106       Selected: Boolean;
107     end;
108   
109     TSelectedOrder = class
110     public
111       Position: Integer;
112       Order: TOrder;
113     end;
114   
115     TOrderRenewFields = class
116     public
117       BaseType:  Integer;
118       StartTime: string;
119       StopTime:  string;
120       Refills:   Integer;
121       Pickup:    string;
122       Comments:  string;
123       NewText:   string;
124     end;
125   
126     TPrintParams = record
127       PromptForChartCopy    :  char;
128       ChartCopyDevice       :  string;
129       PromptForLabels       :  char;
130       LabelDevice           :  string;
131       PromptForRequisitions :  char;
132       RequisitionDevice     :  string;
133       PromptForWorkCopy     :  char;
134       WorkCopyDevice        :  string;
135       AnyPrompts            :  boolean;
136   //    OrdersToPrint         :  TStringList; {*KCM*}
137     end;
138   
139     TOrderView = class
140       Changed:    Boolean;                         // true when view has been modified
141       DGroup:     Integer;                         // display group (pointer value)
142       Filter:     Integer;                         // FLGS parameter passed to ORQ
143       InvChrono:  Boolean;                         // true for inverse chronological order
144       ByService:  Boolean;                         // true for grouping orders by service
145       TimeFrom:   TFMDateTime;                     // beginning time for orders in list
146       TimeThru:   TFMDateTime;                     // ending time for orders in list
147       CtxtTime:   TFMDateTime;                     // set by server, context hours begin time
148       TextView:   Integer;                         // set by server, 0 if mult views of same order
149       ViewName:   string;                          // display name for the view
150       EventDelay: TOrderDelayEvent;                // fields for event delay view
151     public
152       procedure Assign(Src: TOrderView);
153   
154     end;
155   
156   { Order List functions }
157   function DetailOrder(const ID: string): TStrings;
158   function ResultOrder(const ID: string): TStrings;
159   function ResultOrderHistory(const ID: string): TStrings;
160   function NameOfStatus(IEN: Integer): string;
161   function GetOrderStatus(AnOrderId: string): integer;
162   function ExpiredOrdersStartDT: TFMDateTime;
163   procedure ClearOrders(AList: TList);
164   procedure LoadOrders(Dest: TList; Filter, Groups: Integer);
165   procedure LoadOrdersAbbr(Dest: TList; AView: TOrderView; APtEvtID: string); overload;
166   procedure LoadOrdersAbbr(DestDC,DestRL: TList; AView: TOrderView; APtEvtID: string); overload;
167   procedure LoadOrderSheets(Dest: TStrings);
168   procedure LoadOrderSheetsED(Dest: TStrings);
169   procedure LoadOrderViewDefault(AView: TOrderView);
170   procedure LoadUnsignedOrders(IDList, HaveList: TStrings);
171   procedure SaveOrderViewDefault(AView: TOrderView);
172   procedure RetrieveOrderFields(OrderList: TList; ATextView: Integer; ACtxtTime: TFMDateTime);
173   procedure SetOrderFields(AnOrder: TOrder; const x, y, z: string);
174   procedure SetOrderFromResults(AnOrder: TOrder);
175   procedure SortOrders(AList: TList; ByGroup, InvChron: Boolean);
176   
177   { Display Group & List functions }
178   function DGroupAll: Integer;
179   function DGroupIEN(AName: string): Integer;
180   procedure ListDGroupAll(Dest: TStrings);
181   procedure ListSpecialties(Dest: TStrings);
182   procedure ListSpecialtiesED(AType: Char; Dest: TStrings);
183   procedure ListOrderFilters(Dest: TStrings);
184   procedure ListOrderFiltersAll(Dest: TStrings);
185   function NameOfDGroup(IEN: Integer): string;
186   function ShortNameOfDGroup(IEN: Integer): string;
187   function SeqOfDGroup(IEN: Integer): Integer;
188   function CheckOrderGroup(AOrderID: string): integer;
189   function CheckQOGroup(AQOId:string): Boolean;
190   
191   { Write Orders }
192   procedure BuildResponses(var ResolvedDialog: TOrderDialogResolved; const KeyVars: string;
193     AnEvent: TOrderDelayEvent; ForIMO: boolean = False);
194   procedure ClearOrderRecall;
195   function CommonLocationForOrders(OrderList: TStringList): Integer;
196   function FormIDForDialog(IEN: Integer): Integer;
197   function DlgIENForName(DlgName: string): Integer;
198   procedure LoadOrderMenu(AnOrderMenu: TOrderMenu; AMenuIEN: Integer);
199   procedure LoadOrderSet(SetItems: TStrings; AnIEN: Integer; var KeyVars, ACaption: string);
200   procedure LoadWriteOrders(Dest: TStrings);
201   procedure LoadWriteOrdersED(Dest: TStrings; EvtID: string);
202   function OrderDisabledMessage(DlgIEN: Integer): string;
203   procedure SendOrders(OrderList: TStringList; const ESCode: string);
204   procedure SendReleaseOrders(OrderList: TStringList);
205   procedure SendAndPrintOrders(OrderList, ErrList: TStrings; const ESCode: string; const DeviceInfo: string);
206   procedure ExecutePrintOrders(SelectedList: TStringList; const DeviceInfo: string);
207   procedure PrintOrdersOnReview(OrderList: TStringList; const DeviceInfo: string; PrintLoc: Integer = 0);  {*KCM*}
208   procedure PrintServiceCopies(OrderList: TStringList; PrintLoc: Integer = 0);  {*REV*}
209   procedure OrderPrintDeviceInfo(OrderList: TStringList; var PrintParams: TPrintParams; Nature: Char; PrintLoc: Integer = 0); {*KCM*}
210   function UseNewMedDialogs: Boolean;
211   
212   { Order Actions }
213   function DialogForOrder(const ID: string): Integer;
214   procedure LockPatient(var ErrMsg: string);
215   procedure UnlockPatient;
216   procedure LockOrder(OrderID: string; var ErrMsg: string);
217   procedure UnlockOrder(OrderID: string);
218   function FormIDForOrder(const ID: string): Integer;
219   procedure ValidateOrderAction(const ID, Action: string; var ErrMsg: string);
220   procedure ValidateOrderActionNature(const ID, Action, Nature: string; var ErrMsg: string);
221   procedure IsLatestAction(const ID: string; var ErrList: TStringList);
222   procedure ChangeOrder(AnOrder: TOrder; ResponseList: TList);
223   procedure RenewOrder(AnOrder: TOrder; RenewFields: TOrderRenewFields; IsComplex: integer;
224     AnIMOOrderAppt: double; OCList: TStringList);
225   procedure HoldOrder(AnOrder: TOrder);
226   procedure ListDCReasons(Dest: TStrings; var DefaultIEN: Integer);
227   function GetREQReason: Integer;
228   procedure DCOrder(AnOrder: TOrder; AReason: Integer; NewOrder: boolean; var DCType: Integer);
229   procedure ReleaseOrderHold(AnOrder: TOrder);
230   procedure AlertOrder(AnOrder: TOrder; AlertRecip: Int64);
231   procedure FlagOrder(AnOrder: TOrder; const FlagReason: string; AlertRecip: Int64);
232   procedure UnflagOrder(AnOrder: TOrder; const AComment: string);
233   procedure LoadFlagReason(Dest: TStrings; const ID: string);
234   procedure LoadWardComments(Dest: TStrings; const ID: string);
235   procedure PutWardComments(Src: TStrings; const ID: string; var ErrMsg: string);
236   procedure CompleteOrder(AnOrder: TOrder; const ESCode: string);
237   procedure VerifyOrder(AnOrder: TOrder; const ESCode: string);
238   procedure VerifyOrderChartReview(AnOrder: TOrder; const ESCode: string);
239   function GetOrderableIen(AnOrderId:string): integer;
240   procedure StoreDigitalSig(AID, AHash: string; AProvider: Int64; ASig, ACrlUrl, DFN: string; var AError: string);
241   procedure UpdateOrderDGIfNeeded(AnID: string);
242   function CanEditSuchRenewedOrder(AnID: string; IsTxtOrder: integer): boolean;
243   function IsPSOSupplyDlg(DlgID, QODlg: integer): boolean;
244   procedure SaveChangesOnRenewOrder(var AnOrder: TOrder; AnID, TheRefills, ThePickup: string; IsTxtOrder: integer);
245   function DoesOrderStatusMatch(OrderArray: TStringList): boolean;
246   //function GetPromptandDeviceParameters(Location: integer; OrderList: TStringList; Nature: string): TPrintParams;
247   
248   { Order Information }
249   procedure LoadRenewFields(RenewFields: TOrderRenewFields; const ID: string);
250   procedure GetChildrenOfComplexOrder(AnParentID,CurrAct: string; var ChildList: TStringList); //PSI-COMPLEX
251   procedure LESValidationForChangedLabOrder(var RejectedReason: TStringList; AnOrderInfo: string);
252   procedure ValidateComplexOrderAct(AnOrderID: string; var ErrMsg: string); //PSI-COMPLEX
253   function IsRenewableComplexOrder(AnParentID: string): boolean; //PSI-COMPLEX
254   function IsComplexOrder(AnOrderID: string): boolean; //PSI-COMPLEX
255   function GetDlgData(ADlgID: string): string;
256   function OrderIsReleased(const ID: string): Boolean;
257   function TextForOrder(const ID: string): string;
258   function GetConsultOrderNumber(ConsultIEN: string): string;
259   function GetOrderByIFN(const ID: string): TOrder;
260   function GetPackageByOrderID(const OrderID: string): string;
261   function AnyOrdersRequireSignature(OrderList: TStringList): Boolean;
262   function OrderRequiresSignature(const ID: string): Boolean;
263   function OrderRequiresDigitalSignature(const ID: string): Boolean;
264   function GetDrugSchedule(const ID: string): string;
265   function GetExternalText(const ID: string): string;
266   function SetExternalText(const ID: string; ADrugSch: string; AUser: Int64): string;
267   function GetDEA(const ID: string): string;
268   function GetDigitalSignature(const ID: string): string;
269   function GetPKIUse: Boolean;
270   function GetPKISite: Boolean;
271   function DoesOIPIInSigForQO(AnQOID: integer): integer;
272   function GetDispGroupForLES: string;
273   function GetOrderPtEvtID(AnOrderID: string): string;
274   function VerbTelPolicyOrder(AnOrderID: string): boolean;
275   function ForIVandUD(AnOrderID: string): boolean;
276   
277   {Event Delay Enhancement}
278   function DeleteEmptyEvt(APtEvntID: string; var APtEvntName: string; Ask: boolean = True): boolean;
279   function DispOrdersForEvent(AEvtId: string): boolean;
280   function EventInfo(APtEvtID: string): string; // ptr to #100.2
281   function EventInfo1(AnEvtID: string): string; // ptr to #100.5
282   function EventExist(APtDFN:string; AEvt: integer): integer;
283   function CompleteEvt(APtEvntID: string; APtEvntName: string; Ask: boolean = True): boolean;
284   function PtEvtEmpty(APtEvtID: string): Boolean;
285   function GetEventIFN(const AEvntID: string): string;
286   function GetEventName(const AEvntID: string): string;
287   function GetEventLoc(const APtEvntID: string): string;
288   function GetEventLoc1(const AnEvntID: string): string;
289   function GetEventDiv(const APtEvntID: string): string;
290   function GetEventDiv1(const AnEvntID: string): string;
291   function GetCurrentSpec(const APtIFN: string): string;
292   function GetDefaultEvt(const AProviderIFN: string): string;
293   function isExistedEvent(const APtDFN: string; const AEvtID: string; var APtEvtID: string): Boolean;
294   function TypeOfExistedEvent(APtDFN: string; AEvtID: Integer): Integer;
295   function isMatchedEvent(const APtDFN: string; const AEvtID: string; var ATs: string): Boolean;
296   function isDCedOrder(const AnOrderID: string): Boolean;
297   function isOnholdMedOrder(AnOrderID: string): Boolean;
298   function SetDefaultEvent(var AErrMsg: string; EvtID: string): Boolean;
299   function GetEventPromptID: integer;
300   function GetDefaultTSForEvt(AnEvtID: integer): string;
301   function GetPromptIDs: string;
302   function GetEventDefaultDlg(AEvtID: integer): string;
303   function CanManualRelease: boolean;
304   function TheParentPtEvt(APtEvt: string): string;
305   function IsCompletedPtEvt(APtEvtID: integer): boolean;
306   function IsPassEvt(APtEvtID: integer; APtEvtType: char): boolean;
307   function IsPassEvt1(AnEvtID: integer; AnEvtType: char): boolean;
308   procedure DeleteDefaultEvt;
309   procedure TerminatePtEvt(APtEvtID: integer);
310   procedure ChangeEvent(AnOrderList: TStringList; APtEvtId: string);
311   procedure DeletePtEvent(APtEvtID: string);
312   procedure SaveEvtForOrder(APtDFN: string; AEvt: integer; AnOrderID: string);
313   procedure SetPtEvtList(Dest: TStrings; APtDFN: string; var ATotal: integer);
314   procedure GetTSListForEvt(Dest: TStrings; AnEvtID:integer);
315   procedure GetChildEvent(var AChildList: TStringList; APtEvtID: string);
316   
317   { Order Checking }
318   function IsMonograph(): Boolean; 
319   procedure DeleteMonograph();
320   procedure GetMonographList(ListOfMonographs: TStringList);
321   procedure GetMonograph(Monograph: TStringList; x: Integer);
322   procedure GetXtraTxt(OCText: TStringList; x: String; y: String);
323   function FillerIDForDialog(IEN: Integer): string;
324   function OrderChecksEnabled: Boolean;
325   function OrderChecksOnDisplay(const FillerID: string): string;
326   procedure OrderChecksOnAccept(ListOfChecks: TStringList; const FillerID, StartDtTm: string;
327     OIList: TStringList; DupORIFN: string; Renewal: string);
328   procedure OrderChecksOnDelay(ListOfChecks: TStringList; const FillerID, StartDtTm: string;
329     OIList: TStringList);
330   procedure OrderChecksForSession(ListOfChecks, OrderList: TStringList);
331   procedure SaveOrderChecksForSession(const AReason: string; ListOfChecks: TStringList);
332   function DeleteCheckedOrder(const OrderID: string): Boolean;
333   function DataForOrderCheck(const OrderID: string): string;
334   
335   { Copay }
336   procedure GetCoPay4Orders;
337   procedure SaveCoPayStatus(AList: TStrings);
338   
339   {IMO: inpatient medication for outpatient}
340   function IsValidIMOLoc(LocID: integer; PatientID: string): boolean;   //IMO
341   function IsIMOOrder(OrderID: string): boolean;
342   function IsInptQO(DlgID: integer): boolean;
343   function IsIVQO(DlgID: integer): boolean;
344   function IsClinicLoc(ALoc: integer): boolean;
345   
346   {None-standard Schedule} //nss
347   function IsValidSchedule(AnOrderID: string): boolean; //NSS
348   function IsValidQOSch(QOID: string): string; //NSS
349   function IsValidSchStr(ASchStr: string): boolean;
350   
351   function IsPendingHold(OrderID: string): boolean;
352   
353   implementation
354   
355   uses Windows, rCore, uConst, TRPCB, ORCtrls, UBAGlobals, UBACore, VAUtils;
356   
357   var
358     uDGroupMap: TStringList;          // each string is DGroupIEN=Sequence^TopName^Name
359     uDGroupAll: Integer;
360     uOrderChecksOn: Char;
361   
362   { TOrderView methods }
363   
364   procedure TOrderView.Assign(Src: TOrderView);
365   begin
366     Self.Changed   := Src.Changed;
367     Self.DGroup    := Src.DGroup;
368     Self.Filter    := Src.Filter;
369     Self.InvChrono := Src.InvChrono;
370     Self.ByService := Src.ByService;
371     Self.TimeFrom  := Src.TimeFrom;
372     Self.TimeThru  := Src.TimeThru;
373     Self.CtxtTime  := Src.CtxtTime;
374     Self.TextView  := Src.TextView;
375     Self.ViewName  := Src.ViewName;
376     Self.EventDelay.EventIFN   := Src.EventDelay.EventIFN;
377     Self.EventDelay.EventName  := Src.EventDelay.EventName;
378     Self.EventDelay.EventType  := Src.EventDelay.EventType;
379     Self.EventDelay.Specialty  := Src.EventDelay.Specialty;
380     Self.EventDelay.Effective  := Src.EventDelay.Effective;
381   end;
382   
383   { TOrder methods }
384   
385   procedure TOrder.Assign(Source: TOrder);
386   begin
387     ID           := Source.ID;
388     DGroup       := Source.DGroup;
389     OrderTime    := Source.OrderTime;
390     StartTime    := Source.StartTime;
391     StopTime     := Source.StopTime;
392     Status       := Source.Status;
393     Signature    := Source.Signature;
394     VerNurse     := Source.VerNurse;
395     VerClerk     := Source.VerClerk;
396     ChartRev     := Source.ChartRev;
397     Provider     := Source.Provider;
398     ProviderName := Source.ProviderName;
399     ProviderDEA  := Source.ProviderDEA;
400     ProviderVA   := Source.ProviderVA;
401     DigSigReq    := Source.DigSigReq;
402     XMLText      := Source.XMLText;
403     Text         := Source.Text;
404     DGroupSeq    := Source.DGroupSeq;
405     DGroupName   := Source.DGroupName;
406     Flagged      := Source.Flagged;
407     Retrieved    := Source.Retrieved;
408     EditOf       := Source.EditOf;
409     ActionOn     := Source.ActionOn;
410     EventPtr     := Source.EventPtr;
411     EventName    := Source.EventName;
412     OrderLocIEN  := Source.OrderLocIEN;
413     OrderLocName := Source.OrderLocName;
414     ParentID     := Source.ParentID;  
415     LinkObject   := Source.LinkObject;
416     IsControlledSubstance   := Source.IsControlledSubstance;
417     IsDetox   := Source.IsDetox;
418   end;
419   
420   procedure TOrder.Clear;
421   begin
422     ID           := '';
423     DGroup       := 0;
424     OrderTime    := 0;
425     StartTime    := '';
426     StopTime     := '';
427     Status       := 0;
428     Signature    := 0;
429     VerNurse     := '';
430     VerClerk     := '';
431     ChartRev     := '';
432     Provider     := 0;
433     ProviderName := '';
434     ProviderDEA  := '';
435     ProviderVA   :='';
436     DigSigReq    :='';
437     XMLText      := '';
438     Text         := '';
439     DGroupSeq    := 0;
440     DGroupName   := '';
441     Flagged      := False;
442     Retrieved    := False;
443     EditOf       := '';
444     ActionOn     := '';
445     OrderLocIEN  := '';         //imo
446     OrderLocName := '';         //imo
447     ParentID     := '';
448     LinkObject   := nil;
449     IsControlledSubstance := False;
450     IsDetox := False;
451   end;
452   
453   { Order List functions }
454   
455   function DetailOrder(const ID: string): TStrings;
456   begin
457     CallV('ORQOR DETAIL', [ID, Patient.DFN]);
458     Result := RPCBrokerV.Results;
459   end;
460   
461   function ResultOrder(const ID: string): TStrings;
462   begin
463     CallV('ORWOR RESULT', [Patient.DFN,ID,ID]);
464     Result := RPCBrokerV.Results;
465   end;
466   
467   function ResultOrderHistory(const ID: string): TStrings;
468   begin
469    CallV('ORWOR RESULT HISTORY', [Patient.DFN,ID,ID]);
470    Result := RPCBrokerV.Results;
471   end;
472   
473   procedure LoadDGroupMap;
474   begin
475     if uDGroupMap = nil then
476     begin
477       uDGroupMap := TStringList.Create;
478       tCallV(uDGroupMap, 'ORWORDG MAPSEQ', [nil]);
479     end;
480   end;
481   
482   function NameOfStatus(IEN: Integer): string;
483   begin
484     case IEN of
485        0: Result := 'error';
486        1: Result := 'discontinued';
487        2: Result := 'complete';
488        3: Result := 'hold';
489        4: Result := 'flagged';
490        5: Result := 'pending';
491        6: Result := 'active';
492        7: Result := 'expired';
493        8: Result := 'scheduled';
494        9: Result := 'partial results';
495       10: Result := 'delayed';
496       11: Result := 'unreleased';
497       12: Result := 'dc/edit';
498       13: Result := 'cancelled';
499       14: Result := 'lapsed';
500       15: Result := 'renewed';
501       97: Result := '';                  { null status, used for 'No Orders Found.' }
502       98: Result := 'new';
503       99: Result := 'no status';
504     end;
505   end;
506   
507   function GetOrderStatus(AnOrderId: string): integer;
508   begin
509     Result := StrToIntDef(SCallV('OREVNTX1 GETSTS',[AnOrderId]),0);
510   end;
511   
512   function ExpiredOrdersStartDT: TFMDateTime;
513   //Return FM date/time to begin search for expired orders
514   begin
515     Result := MakeFMDateTime(sCallV('ORWOR EXPIRED', [nil]));
516   end;
517   
518   function DispOrdersForEvent(AEvtId: string): boolean;
519   var
520     theResult: integer;
521   begin
522     Result := False;
523     theResult := StrToIntDef(SCallV('OREVNTX1 CPACT',[AEvtId]),0);
524     if theResult > 0 then
525       Result := True;
526   end;
527   
528   function EventInfo(APtEvtID: string): string;
529   begin
530     Result := SCallV('OREVNTX1 GTEVT', [APtEvtID]);
531   end;
532   
533   function EventInfo1(AnEvtID: string): string;
534   begin
535     Result := SCallV('OREVNTX1 GTEVT1', [AnEvtID]);
536   end;
537   
538   function NameOfDGroup(IEN: Integer): string;
539   begin
540     if uDGroupMap = nil then LoadDGroupMap;
541     Result := uDGroupMap.Values[IntToStr(IEN)];
542     Result := Piece(Result, U, 3);
543   end;
544   
545   function ShortNameOfDGroup(IEN: Integer): string;
546   begin
547     if uDGroupMap = nil then LoadDGroupMap;
548     Result := uDGroupMap.Values[IntToStr(IEN)];
549     Result := Piece(Result, U, 4);
550   end;
551   
552   function SeqOfDGroup(IEN: Integer): Integer;
553   var
554     x: string;
555   begin
556     if uDGroupMap = nil then LoadDGroupMap;
557     x := uDGroupMap.Values[IntToStr(IEN)];
558     Result := StrToIntDef(Piece(x, U, 1), 0);
559   end;
560   
561   function CheckOrderGroup(AOrderID: string): integer;
562   begin
563     // Result = 1     Inpatient Medication Display Group;
564     // Result = 2     OutPatient Medication Display Group;
565     // Result = 0     None of In or Out patient display group;
566     Result := StrToInt(SCallV('ORWDPS2 CHKGRP',[AOrderID]));
567   end;
568   
569   function CheckQOGroup(AQOId:string): Boolean;
570   var
571     rst: integer;
572   begin
573     rst := StrToInt(SCallV('ORWDPS2 QOGRP',[AQOId]));
574     Result := False;
575     if rst > 0 then
576       Result := True;
577   end;
578   
579   function TopNameOfDGroup(IEN: Integer): string;
580   begin
581     if uDGroupMap = nil then LoadDGroupMap;
582     Result := uDGroupMap.Values[IntToStr(IEN)];
583     Result := Piece(Result, U, 2);
584   end;
585   
586   procedure ClearOrders(AList: TList);
587   var
588     i: Integer;
589   begin
590     with AList do for i := 0 to Count - 1 do with TOrder(Items[i]) do Free;
591     AList.Clear;
592   end;
593   
594   procedure SetOrderFields(AnOrder: TOrder; const x, y, z: string);
595   {           1   2    3     4      5     6   7   8   9    10    11    12    13    14     15     16  17    18    19     20         21          22              23               24
596   { Pieces: ~IFN^Grp^ActTm^StrtTm^StopTm^Sts^Sig^Nrs^Clk^PrvID^PrvNam^ActDA^Flag^DCType^ChrtRev^DEA#^VA#^DigSig^IMO^DCOrigOrder^ISDCOrder^IsDelayOrder^IsControlledSubstance^IsDetox}
597   begin
598     with AnOrder do
599     begin
600       Clear;
601       ID := Copy(Piece(x, U, 1), 2, Length(Piece(x, U, 1)));
602       DGroup := StrToIntDef(Piece(x, U, 2), 0);
603       OrderTime := MakeFMDateTime(Piece(x, U, 3));
604       StartTime := Piece(x, U, 4);
605       StopTime  := Piece(x, U, 5);
606       Status    := StrToIntDef(Piece(x, U, 6), 0);
607       Signature := StrToIntDef(Piece(x, U, 7), 0);
608       VerNurse  := Piece(x, U, 8);
609       VerClerk  := Piece(x, U, 9);
610       ChartRev  := Piece(x, U, 15);
611       Provider  := StrToInt64Def(Piece(x, U, 10), 0);
612       ProviderName := Piece(x, U, 11);
613       ProviderDEA  := Piece(x, U, 16);
614       ProviderVA   := Piece(x, U, 17);
615       DigSigReq    := Piece(x, U, 18);
616       Flagged   := Piece(x, U, 13) = '1';
617       Retrieved := True;
618       OrderLocIEN  := Piece(Piece(x,U,19),':',2);   //imo
619       if Piece(Piece(x,U,19),':',1) = '0;SC(' then OrderLocName := 'Unknown'
620       else OrderLocName := Piece(Piece(x,U,19),':',1);   //imo
621       Text := y;
622       XMLText := z;
623       DGroupSeq  := SeqOfDGroup(DGroup);
624       DGroupName := TopNameOfDGroup(DGroup);
625       //AGP Changes 26.15 PSI-04-063
626       if (pos('Entered in error',Text)>0) then AnOrder.EnteredInError := 1
627       else AnOrder.EnteredInError := 0;
628       //if DGroupName = 'Non-VA Meds' then Text := 'Non-VA  ' + Text;
629       if Piece(x,U,20) = '1' then DCOriginalOrder := True
630       else DCOriginalOrder := False;
631       if Piece(X,u,21) = '1' then  IsOrderPendDC := True
632       else IsOrderPendDC := False;
633       if Piece(x,u,22) = '1' then IsDelayOrder := True
634       else IsDelayOrder := False;
635       if Piece(x,u,23) = '1' then IsControlledSubstance := True
636       else IsControlledSubstance := False;
637       if Piece(x,u,24) = '1' then IsDetox := True
638       else IsDetox := False;
639     end;
640   end;
641   
642   procedure LoadOrders(Dest: TList; Filter, Groups: Integer);
643   var
644     x, y, z: string;
645     AnOrder: TOrder;
646   begin
647     ClearOrders(Dest);
648     if uDGroupMap = nil then LoadDGroupMap;  // to make sure broker not called while looping thru Results
649     CallV('ORWORR GET', [Patient.DFN, Filter, Groups]);
650     with RPCBrokerV do while Results.Count > 0 do
651     begin
652       x := Results[0];
653       Results.Delete(0);
654       if CharAt(x, 1) <> '~' then Continue;        // only happens if out of synch
655       y := '';
656       while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
657       begin
658         y := y + Copy(Results[0], 2, Length(Results[0])) + CRLF;
659         Results.Delete(0);
660       end;
661       if Length(y) > 0 then y := Copy(y, 1, Length(y) - 2);  // take off last CRLF
662       z := '';
663       if (Results.Count > 0) and (Results[0] = '|') then
664         begin
665           Results.Delete(0);
666           while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
667             begin
668               z := z + Copy(Results[0], 2, Length(Results[0]));
669               Results.Delete(0);
670             end;
671         end;
672       AnOrder := TOrder.Create;
673       SetOrderFields(AnOrder, x, y, z);
674       Dest.Add(AnOrder);
675     end;
676   end;
677   
678   procedure LoadOrdersAbbr(Dest: TList; AView: TOrderView; APtEvtID: string);
679   //Filter, Specialty, Groups: Integer; var TextView: Integer;
680   //  var CtxtTime: TFMDateTime);
681   var
682     i: Integer;
683     AnOrder: TOrder;
684     FilterTS: string;
685     AlertedUserOnly: boolean;
686   begin
687     ClearOrders(Dest);
688     if uDGroupMap = nil then LoadDGroupMap;  // to make sure broker not called while looping thru Results
689     FilterTS := IntToStr(AView.Filter) + U + IntToStr(AView.EventDelay.Specialty);
690     AlertedUserOnly := (Notifications.Active and (AView.Filter = 12));
691     CallV('ORWORR AGET', [Patient.DFN, FilterTS, AView.DGroup, AView.TimeFrom, AView.TimeThru, APtEvtID, AlertedUserOnly]);
692     if ((Piece(RPCBrokerV.Results[0], U, 1) = '0') or (Piece(RPCBrokerV.Results[0], U, 1) = '')) and (AView.Filter = 5) then      // if no expiring orders found display expired orders)
693     begin
694       CallV('ORWORR AGET', [Patient.DFN, '27^0', AView.DGroup, ExpiredOrdersStartDT, FMNow, APtEvtID]);
695       AView.ViewName := 'Recently Expired Orders (No Expiring Orders Found) -' + Piece(AView.ViewName, '-', 2);
696     end;
697     {if (Piece(RPCBrokerV.Results[0], U, 1) = '0') or (Piece(RPCBrokerV.Results[0], U, 1) = '') then      // if no orders found (0 element is count)
698     begin
699       AnOrder := TOrder.Create;
700       with AnOrder do
701       begin
702         ID := '0';
703         DGroup := 0;
704         OrderTime := FMNow;
705         Status := 97;
706         Text := 'No orders found.';
707         Retrieved := True;
708       end;
709       Dest.Add(AnOrder);
710       Exit;
711     end;}
712     AView.TextView := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0);
713     AView.CtxtTime := MakeFMDateTime(Piece(RPCBrokerV.Results[0], U, 3));
714     with RPCBrokerV do for i := 1 to Results.Count - 1 do   // if orders found (skip 0 element)
715     begin
716       if (Piece(RPCBrokerV.Results[i], U, 1) = '0') or (Piece(RPCBrokerV.Results[i], U, 1) = '') then Continue;  
717       if (DelimCount(Results[i],U) = 2) then Continue;  
718       AnOrder := TOrder.Create;
719       with AnOrder do
720       begin
721         ID := Piece(Results[i], U, 1);
722         DGroup := StrToIntDef(Piece(Results[i], U, 2), 0);
723         OrderTime := MakeFMDateTime(Piece(Results[i], U, 3));
724         EventPtr  := Piece(Results[i],U,4);
725         EventName := Piece(Results[i],U,5);
726         DGroupSeq  := SeqOfDGroup(DGroup);
727       end;
728       Dest.Add(AnOrder);
729     end;
730   end;
731   
732   procedure LoadOrdersAbbr(DestDC,DestRL: TList; AView: TOrderView; APtEvtID: string);
733   var
734     i: Integer;
735     AnOrder: TOrder;
736     FilterTS: string;
737     DCStart: boolean;
738   begin
739     DCStart := False;
740     if uDGroupMap = nil then LoadDGroupMap;
741     FilterTS := IntToStr(AView.Filter) + U + IntToStr(AView.EventDelay.Specialty);
742     CallV('ORWORR RGET', [Patient.DFN, FilterTS, AView.DGroup, AView.TimeFrom, AView.TimeThru, APtEvtID]);
743     if RPCBrokerV.Results[0] = '0' then   // if no orders found (0 element is count)
744     begin
745       AnOrder := TOrder.Create;
746       with AnOrder do
747       begin
748         ID := '0';
749         DGroup := 0;
750         OrderTime := FMNow;
751         Status := 97;
752         Text := 'No orders found.';
753         Retrieved := True;
754       end;
755       DestDC.Add(AnOrder);
756       Exit;
757     end;
758     AView.TextView := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 2), 0);
759     AView.CtxtTime := MakeFMDateTime(Piece(RPCBrokerV.Results[0], U, 3));
760     with RPCBrokerV do for i := 1 to Results.Count - 1 do   // if orders found (skip 0 element)
761     begin
762       if AnsiCompareText('DC START', Results[i]) = 0 then
763       begin
764         DCStart := True;
765         Continue;
766       end;
767       AnOrder := TOrder.Create;
768       with AnOrder do
769       begin
770         ID := Piece(Results[i], U, 1);
771         DGroup := StrToIntDef(Piece(Results[i], U, 2), 0);
772         OrderTime := MakeFMDateTime(Piece(Results[i], U, 3));
773         EventPtr  := Piece(Results[i],U,4);
774         EventName := Piece(Results[i],U,5);
775         DGroupSeq  := SeqOfDGroup(DGroup);
776       end;
777       if DCStart then
778         DestDC.Add(AnOrder)
779       else
780         DestRL.Add(AnOrder);
781     end;
782   end;
783   
784   procedure LoadOrderSheets(Dest: TStrings);
785   begin
786     CallV('ORWOR SHEETS', [Patient.DFN]);
787     MixedCaseByPiece(RPCBrokerV.Results, U, 2);
788     FastAssign(RPCBrokerV.Results, Dest);
789    end;
790   
791   procedure LoadOrderSheetsED(Dest: TStrings);
792   var
793     i: integer;
794   begin
795     CallV('OREVNTX PAT', [Patient.DFN]);
796     MixedCaseByPiece(RPCBrokerV.Results, U, 2);
797     Dest.Add('C;O^Current View');
798     if RPCBrokerV.Results.Count > 1 then
799     begin
800       RPCBrokerV.Results.Delete(0);
801       for i := 0 to RPCbrokerV.Results.Count - 1 do
802         RPCBrokerV.Results[i] := RPCBrokerV.Results[i] + ' Orders';
803       FastAddStrings(RPCBrokerV.Results, Dest);
804     end;
805   end;
806   
807   procedure LoadOrderViewDefault(AView: TOrderView);
808   var
809     x: string;
810   begin
811     x := sCallV('ORWOR VWGET', [nil]);
812     with AView do
813     begin
814       Changed   := False;
815       DGroup    := StrToIntDef(Piece(x, ';', 4), 0);
816       Filter    := StrToIntDef(Piece(x, ';', 3), 0);
817       InvChrono := Piece(x, ';', 6) = 'R';
818       ByService := Piece(x, ';', 7) = '1';
819       TimeFrom  := StrToFloat(Piece(x, ';', 1));
820       TimeThru  := StrToFloat(Piece(x, ';', 2));
821       CtxtTime  := 0;
822       TextView  := 0;
823       ViewName  := Piece(x, ';', 8);
824       EventDelay.EventType := 'C';
825       EventDelay.Specialty := 0;
826       EventDelay.Effective := 0;
827     end;
828   end;
829   
830   procedure LoadUnsignedOrders(IDList, HaveList: TStrings);
831   var
832     i: Integer;
833   begin
834     with RPCBrokerV do
835     begin
836       ClearParameters := True;
837       RemoteProcedure := 'ORWOR UNSIGN';
838       Param[0].PType := literal;
839       Param[0].Value := Patient.DFN;
840       Param[1].PType := list;
841       Param[1].Mult['0'] := '';  // (to prevent broker from hanging if empty list)
842       for i := 0 to Pred(HaveList.Count) do Param[1].Mult['"' + HaveList[i] + '"'] := '';
843       CallBroker;
844       FastAssign(RPCBrokerV.Results,IDList);
845     end;
846   end;
847   
848   procedure RetrieveOrderFields(OrderList: TList; ATextView: Integer; ACtxtTime: TFMDateTime);
849   var
850     i, OrderIndex: Integer;
851     x, y, z: string;
852     AnOrder: TOrder;
853     IDList: TStringList;
854   begin
855     IDList := TStringList.Create;
856     try
857       with OrderList do for i := 0 to Count - 1 do IDList.Add(TOrder(Items[i]).ID);
858       CallV('ORWORR GET4LST', [ATextView, ACtxtTime, IDList]);
859     finally
860       IDList.Free;
861     end;
862     OrderIndex := -1;
863     with RPCBrokerV do while Results.Count > 0 do
864     begin
865       Inc(OrderIndex);
866       if (OrderIndex >= OrderList.Count) then
867       begin
868         Results.Delete(0);
869         Continue;
870       end;
871       AnOrder := TOrder(OrderList.Items[OrderIndex]);
872       x := Results[0];
873       Results.Delete(0);
874       if CharAt(x, 1) <> '~' then Continue;                  // only happens if out of synch
875       if Piece(x, U, 1) <> '~' + AnOrder.ID then Continue;   // only happens if out of synch
876       y := '';
877       while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
878       begin
879         y := y + Copy(Results[0], 2, Length(Results[0])) + CRLF;
880         Results.Delete(0);
881       end;
882       if Length(y) > 0 then y := Copy(y, 1, Length(y) - 2);  // take off last CRLF
883       z := '';
884       if (Results.Count > 0) and (Results[0] = '|') then
885         begin
886           Results.Delete(0);
887           while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
888             begin
889               z := z + Copy(Results[0], 2, Length(Results[0]));
890               Results.Delete(0);
891             end;
892         end;
893       SetOrderFields(AnOrder, x, y, z);
894     end;
895   end;
896   
897   procedure SaveOrderViewDefault(AView: TOrderView);
898   var
899     x: string;
900   begin
901     with AView do
902     begin
903       x := MakeRelativeDateTime(TimeFrom) + ';' +            // 1
904            MakeRelativeDateTime(TimeThru) + ';' +            // 2
905            IntToStr(Filter)               + ';' +            // 3
906            IntToStr(DGroup)               + ';;';            // 4, skip 5
907       if InvChrono then x := x + 'R;' else x := x + 'F;';    // 6
908       if ByService then x := x + '1'  else x := x + '0';     // 7
909       CallV('ORWOR VWSET', [x]);
910     end;
911   end;
912   
913   { MOVE THESE FUNCTIONS INTO UORDERS??? }
914   
915   { < 0 if Item1 is less and Item2, 0 if they are equal and > 0 if Item1 is greater than Item2 }
916   function InverseByGroup(Item1, Item2: Pointer): Integer;
917   var
918     Order1, Order2: TOrder;
919     DSeq1, DSeq2, IFN1, IFN2: Integer;
920   begin
921     Order1 := TOrder(Item1);
922     Order2 := TOrder(Item2);
923     if ( (Piece(Order1.ID, ';', 2) = '1') and (Changes.Exist(CH_ORD, Order1.ID)) )
924       and ( StrToIntDef(Order1.EventPtr,0) = 0 ) then
925         DSeq1 := 0
926       else DSeq1 := Order1.DGroupSeq;
927     if ((Piece(Order2.ID, ';', 2) = '1') and (Changes.Exist(CH_ORD, Order2.ID)))
928       and ( StrToIntDef(Order1.EventPtr,0) = 0 ) then
929         DSeq2 := 0
930       else DSeq2 := Order2.DGroupSeq;
931     if DSeq1 = DSeq2 then
932     begin
933       if Order1.OrderTime > Order2.OrderTime then Result := -1
934       else if Order1.OrderTime < Order2.OrderTime then Result := 1
935       else Result := 0;
936       if Result = 0 then
937       begin
938         IFN1 := StrToIntDef(Piece(Order1.ID, ';', 1), 0);
939         IFN2 := StrToIntDef(Piece(Order2.ID, ';', 1), 0);
940         if IFN1 < IFN2 then Result := -1;
941         if IFN1 > IFN2 then Result := 1;
942       end;
943     end
944     else if DSeq1 < DSeq2 then Result := -1
945     else Result := 1;
946   end;
947   
948   function ForwardByGroup(Item1, Item2: Pointer): Integer;
949   var
950     Order1, Order2: TOrder;
951     DSeq1, DSeq2, IFN1, IFN2: Integer;
952   begin
953     Order1 := TOrder(Item1);
954     Order2 := TOrder(Item2);
955     if (Piece(Order1.ID, ';', 2) = '1') and (Changes.Exist(CH_ORD, Order1.ID))
956       then DSeq1 := 0
957       else DSeq1 := Order1.DGroupSeq;
958     if (Piece(Order2.ID, ';', 2) = '1') and (Changes.Exist(CH_ORD, Order2.ID))
959       then DSeq2 := 0
960       else DSeq2 := Order2.DGroupSeq;
961     if DSeq1 = DSeq2 then
962     begin
963       if Order1.OrderTime < Order2.OrderTime then Result := -1
964       else if Order1.OrderTime > Order2.OrderTime then Result := 1
965       else Result := 0;
966       if Result = 0 then
967       begin
968         IFN1 := StrToIntDef(Piece(Order1.ID, ';', 1), 0);
969         IFN2 := StrToIntDef(Piece(Order2.ID, ';', 1), 0);
970         if IFN1 < IFN2 then Result := -1;
971         if IFN1 > IFN2 then Result := 1;
972       end;
973     end
974     else if DSeq1 < DSeq2 then Result := -1
975     else Result := 1;
976   end;
977   
978   function InverseChrono(Item1, Item2: Pointer): Integer;
979   var
980     Order1, Order2: TOrder;
981     IFN1, IFN2: Integer;
982   begin
983     Order1 := TOrder(Item1);
984     Order2 := TOrder(Item2);
985     if Order1.OrderTime > Order2.OrderTime then Result := -1
986     else if Order1.OrderTime < Order2.OrderTime then Result := 1
987     else Result := 0;
988     if Result = 0 then
989     begin
990       IFN1 := StrToIntDef(Piece(Order1.ID, ';', 1), 0);
991       IFN2 := StrToIntDef(Piece(Order2.ID, ';', 1), 0);
992       if IFN1 < IFN2 then Result := -1;
993       if IFN1 > IFN2 then Result := 1;
994     end;
995   end;
996   
997   function ForwardChrono(Item1, Item2: Pointer): Integer;
998   var
999     Order1, Order2: TOrder;
1000    IFN1, IFN2: Integer;
1001  begin
1002    Order1 := TOrder(Item1);
1003    Order2 := TOrder(Item2);
1004    if Order1.OrderTime < Order2.OrderTime then Result := -1
1005    else if Order1.OrderTime > Order2.OrderTime then Result := 1
1006    else Result := 0;
1007    if Result = 0 then
1008    begin
1009      IFN1 := StrToIntDef(Piece(Order1.ID, ';', 1), 0);
1010      IFN2 := StrToIntDef(Piece(Order2.ID, ';', 1), 0);
1011      if IFN1 < IFN2 then Result := -1;
1012      if IFN1 > IFN2 then Result := 1;
1013    end;
1014  end;
1015  
1016  procedure SortOrders(AList: TList; ByGroup, InvChron: Boolean);
1017  begin
1018    if ByGroup then
1019    begin
1020      if InvChron then AList.Sort(InverseByGroup) else AList.Sort(ForwardByGroup);
1021    end else
1022    begin
1023      if InvChron then AList.Sort(InverseChrono)  else AList.Sort(ForwardChrono);
1024    end;
1025  end;
1026  
1027  function DGroupAll: Integer;
1028  var
1029    x: string;
1030  begin
1031    if uDGroupAll = 0 then
1032    begin
1033      x := sCallV('ORWORDG IEN', ['ALL']);
1034      uDGroupAll := StrToIntDef(x, 1);
1035    end;
1036    Result := uDGroupAll;
1037  end;
1038  
1039  function DGroupIEN(AName: string): Integer;
1040  begin
1041    Result := StrToIntDef(sCallV('ORWORDG IEN', [AName]), 0);
1042  end;
1043  
1044  procedure ListDGroupAll(Dest: TStrings);
1045  begin
1046    CallV('ORWORDG ALLTREE', [nil]);
1047    FastAssign(RPCBrokerV.Results, Dest);
1048  end;
1049  
1050  procedure ListSpecialties(Dest: TStrings);
1051  begin
1052    CallV('ORWOR TSALL', [nil]);
1053    MixedCaseList(RPCBrokerV.Results);
1054    FastAssign(RPCBrokerV.Results, Dest);
1055  end;
1056  
1057  procedure ListSpecialtiesED(AType: Char; Dest: TStrings);
1058  var
1059    i :integer;
1060    Currloc: integer;
1061    admitEvts: TStringList;
1062    otherEvts: TStringList;
1063    commonList: TStringList;
1064    IsObservation: boolean;
1065  begin
1066    if Encounter <> nil then
1067      Currloc := Encounter.Location
1068    else
1069      Currloc := 0;
1070    IsObservation := (Piece(GetCurrentSpec(Patient.DFN), U, 3) = '1');
1071    commonList := TStringList.Create;
1072    CallV('OREVNTX1 CMEVTS',[Currloc]);
1073    //MixedCaseList(RPCBrokerV.Results);
1074    if RPCBrokerV.Results.Count > 0 then with RPCBrokerV do for i := 0 to Results.Count - 1 do
1075    begin
1076      if AType = 'D' then
1077      begin
1078        if AType = Piece(Results[i],'^',3) then
1079          commonList.Add(Results[i]);
1080      end
1081      else if AType = 'A' then
1082      begin
1083        if (Piece(Results[i],'^',3) = 'T') or (Piece(Results[i],'^',3) = 'D') then
1084          Continue;
1085        commonList.Add(Results[i]);
1086      end
1087      else if IsObservation then
1088      begin
1089        if (Piece(Results[i],'^',3) = 'T') then
1090          Continue;
1091        commonList.Add(Results[i]);
1092      end
1093      else
1094      begin
1095       if Length(Results[i])> 0 then
1096        commonList.Add(Results[i]);
1097      end;
1098    end;
1099    if commonList.Count > 0 then
1100    begin
1101      FastAddStrings(TStrings(commonList), Dest);
1102      Dest.Add('^^^^^^^^___________________________________________________________________________________________');
1103      Dest.Add(LLS_SPACE);
1104    end;
1105    if AType = #0 then
1106    begin
1107      admitEvts := TStringList.Create;
1108      otherEvts := TSTringList.Create;
1109      CallV('OREVNTX ACTIVE',['A']);
1110      //MixedCaseList(RPCBrokerV.Results);
1111      if RPCBrokerV.Results.Count > 0 then
1112      begin
1113        RPCBrokerV.Results.Delete(0);
1114        FastAddStrings(RPCBrokerV.Results, admitEvts);
1115      end;
1116      if IsObservation then
1117        CallV('OREVNTX ACTIVE',['O^M^D'])
1118      else
1119        CallV('OREVNTX ACTIVE',['T^O^M^D']);
1120      //MixedCaseList(RPCBrokerV.Results);
1121      if RPCBrokerV.Results.Count > 0 then
1122      begin
1123        RPCBrokerV.Results.Delete(0);
1124        FastAddStrings(RPCBrokerV.Results, otherEvts);
1125      end;
1126      FastAddStrings(TStrings(otherEvts), Dest);
1127      Dest.Add('^^^^^^^^_____________________________________________________________________________________________');
1128      Dest.Add(LLS_SPACE);
1129      FastAddStrings(TStrings(admitEvts), Dest);
1130      admitEvts.Free;
1131      otherEvts.Free;
1132    end
1133    else if AType = 'A' then
1134    begin
1135      CallV('OREVNTX ACTIVE',['A^O^M']);
1136      //MixedCaseList(RPCBrokerV.Results);
1137      if RPCBrokerV.Results.Count > 0 then
1138        RPCBrokerV.Results.Delete(0);
1139      FastAddStrings(RPCBrokerV.Results, Dest);
1140    end
1141    else
1142    begin
1143      CallV('OREVNTX ACTIVE',[AType]);
1144      //MixedCaseList(RPCBrokerV.Results);
1145      if RPCBrokerV.Results.Count > 0 then
1146        RPCBrokerV.Results.Delete(0);
1147      FastAddStrings(RPCBrokerV.Results, Dest);
1148    end;
1149  end;
1150  
1151  procedure ListOrderFilters(Dest: TStrings);
1152  begin
1153    CallV('ORWORDG REVSTS', [nil]);
1154    FastAssign(RPCBrokerV.Results, Dest);
1155  end;
1156  
1157  
1158  procedure ListOrderFiltersAll(Dest: TStrings);
1159  begin
1160    CallV('ORWORDG REVSTS', [nil]);
1161    FastAssign(RPCBrokerV.Results, Dest);
1162  end;
1163  
1164  { Write Orders }
1165  
1166  procedure BuildResponses(var ResolvedDialog: TOrderDialogResolved; const KeyVars: string;
1167    AnEvent: TOrderDelayEvent; ForIMO: boolean);
1168  const
1169    BoolChars: array[Boolean] of Char = ('0', '1');
1170    RESERVED_PIECE = '';
1171  var
1172    DelayEvent, x, TheOrder: string;
1173    Idx, tmpOrderGroup, PickupIdx, ForIMOResponses: integer;
1174    IfUDGrp: Boolean;
1175    IfUDGrpForQO: Boolean;
1176    temp: string;
1177  begin
1178    ForIMOResponses := 0;
1179    tmpOrderGroup := 0;
1180    temp := '';
1181    if ForIMO then ForIMOResponses := 1;
1182    PickupIdx := 0;
1183    IfUDGrp := False;
1184    TheOrder := ResolvedDialog.InputID;
1185    IfUDGrpForQO := CheckQOGroup(TheOrder);
1186    if (CharAt(TheOrder,1) in ['C','T']) then
1187    begin
1188      Delete(TheOrder,1,1);
1189      tmpOrderGroup := CheckOrderGroup(TheOrder);
1190      if tmpOrderGroup = 1 then IfUDGrp := True else IfUDGrp := False;
1191    end;
1192    if (not IfUDGrp) and (AnEvent.EventType in ['A','T']) then
1193      IfUDGrp := True;
1194    //FLDS=DFN^LOC^ORNP^INPT^SEX^AGE^EVENT^SC%^^^Key Variables
1195    if (Patient.Inpatient = true) and (tmpOrderGroup = 2) then temp := '0';
1196    if temp <> '0' then temp := BoolChars[Patient.Inpatient];
1197    with AnEvent do
1198    begin
1199      if isNewEvent then
1200        DelayEvent := '0;'+ EventType + ';' + IntToStr(Specialty) + ';' + FloatToStr(Effective)
1201      else
1202        DelayEvent := IntToStr(AnEvent.PtEventIFN) + ';' + EventType + ';' + IntToStr(Specialty) + ';' + FloatToStr(Effective);
1203    end;
1204    x := Patient.DFN                  + U +   // 1
1205         IntToStr(Encounter.Location) + U +   // 2
1206         IntToStr(Encounter.Provider) + U +   // 3
1207         BoolChars[Patient.Inpatient] + U +   // 4
1208         Patient.Sex                  + U +   // 5
1209         IntToStr(Patient.Age)        + U +   // 6
1210         DelayEvent                   + U +   // 7 (for OREVENT)
1211         IntToStr(Patient.SCPercent)  + U +   // 8
1212         RESERVED_PIECE               + U +   // 9
1213         RESERVED_PIECE               + U +   // 10
1214         KeyVars;
1215    CallV('ORWDXM1 BLDQRSP', [ResolvedDialog.InputID, x, ForIMOResponses, Encounter.Location]);
1216    // LST(0)=QuickLevel^ResponseID(ORIT;$H)^Dialog^Type^FormID^DGrp
1217    with RPCBrokerV do
1218    begin
1219      x := Results[0];
1220      with ResolvedDialog do
1221      begin
1222        QuickLevel   := StrToIntDef(Piece(x, U, 1), 0);
1223        ResponseID   := Piece(x, U, 2);
1224        DialogIEN    := StrToIntDef(Piece(x, U, 3), 0);
1225        DialogType   := CharAt(Piece(x, U, 4), 1);
1226        FormID       := StrToIntDef(Piece(x, U, 5), 0);
1227        DisplayGroup := StrToIntDef(Piece(x, U, 6), 0);
1228        QOKeyVars    := Pieces(x, U, 7, 7 + MAX_KEYVARS);
1229        Results.Delete(0);
1230        if Results.Count > 0 then
1231        begin
1232          if (IfUDGrp) or (IfUDGrpForQO) then
1233          begin
1234            for Idx := 0 to Results.Count - 1 do
1235            begin
1236              if(Pos('PICK UP',UpperCase(Results[idx])) > 0) or (Pos('PICK-UP',UpperCase(Results[idx])) > 0) then
1237              begin
1238                PickupIdx := Idx;
1239                Break;
1240              end;
1241            end;
1242          end;
1243          if PickupIdx > 0 then
1244            Results.Delete(PickupIdx);
1245          SetString(ShowText, Results.GetText, StrLen(Results.GetText));
1246        end;
1247      end;
1248    end;
1249  end;
1250  
1251  procedure ClearOrderRecall;
1252  begin
1253    CallV('ORWDXM2 CLRRCL', [nil]);
1254  end;
1255  
1256  function CommonLocationForOrders(OrderList: TStringList): Integer;
1257  begin
1258    Result := StrToIntDef(sCallV('ORWD1 COMLOC', [OrderList]), 0);
1259  end;
1260  
1261  function FormIDForDialog(IEN: Integer): Integer;
1262  begin
1263    Result := StrToIntDef(sCallV('ORWDXM FORMID', [IEN]), 0);
1264  end;
1265  
1266  function DlgIENForName(DlgName: string): Integer;
1267  begin
1268    Result := StrToIntDef(sCallV('OREVNTX1 DLGIEN',[DlgName]),0);
1269  end;
1270  
1271  procedure LoadOrderMenu(AnOrderMenu: TOrderMenu; AMenuIEN: Integer);
1272  var
1273    OrderMenuItem: TOrderMenuItem;
1274    i: Integer;
1275    OrderTitle: String;
1276  begin
1277    CallV('ORWDXM MENU', [AMenuIEN]);
1278    with RPCBrokerV do if Results.Count > 0 then
1279    begin
1280      // Results[0] = Name^Cols^PathSwitch^^^LRFZX^LRFSAMP^LRFSPEC^LRFDATE^LRFURG^LRFSCH^PSJNPOC^
1281      //              GMRCNOPD^GMRCNOAT^GMRCREAF^^^^^
1282     OrderTitle := Piece(Results[0], U, 1);
1283     if (Pos('&', OrderTitle) > 0) and
1284     (Copy(OrderTitle, Pos('&', OrderTitle) + 1, 1) <> '&') then
1285     OrderTitle := Copy(OrderTitle, 1, Pos('&', OrderTitle)) + '&' + Copy(OrderTitle, Pos('&', OrderTitle) + 1, Length(OrderTitle));
1286  
1287      AnOrderMenu.Title   := OrderTitle;
1288      AnOrderMenu.NumCols := StrToIntDef(Piece(Results[0], U, 2), 1);
1289      AnOrderMenu.KeyVars := Pieces(Results[0], U, 6, 6 + MAX_KEYVARS);
1290      for i := 1 to Results.Count - 1 do
1291      begin
1292        OrderMenuItem := TOrderMenuItem.Create;
1293        with OrderMenuItem do
1294        begin
1295          Col      := StrToIntDef(Piece(Results[i], U, 1), 0) - 1;
1296          Row      := StrToIntDef(Piece(Results[i], U, 2), 0) - 1;
1297          DlgType  := CharAt(Piece(Results[i], U, 3), 1);
1298          IEN      := StrToIntDef(Piece(Results[i], U, 4), 0);
1299          FormID   := StrToIntDef(Piece(Results[i], U, 5), 0);
1300          AutoAck  := Piece(Results[i], U, 6) = '1';
1301          ItemText := Piece(Results[i], U, 7);
1302          Mnemonic := Piece(Results[i], U, 8);
1303          Display  := StrToIntDef(Piece(Results[i], U, 9), 0);
1304        end; {with OrderItem}
1305        AnOrderMenu.MenuItems.Add(OrderMenuItem);
1306      end; {for i}
1307    end; {with RPCBrokerV}
1308  end;
1309  
1310  procedure LoadOrderSet(SetItems: TStrings; AnIEN: Integer; var KeyVars, ACaption: string);
1311  var
1312    x: string;
1313  begin
1314    CallV('ORWDXM LOADSET', [AnIEN]);
1315    KeyVars := '';
1316    ACaption := '';
1317    if RPCBrokerV.Results.Count > 0 then
1318    begin
1319      x := RPCBrokerV.Results[0];
1320      ACaption := Piece(x, U, 1);
1321      KeyVars  := Copy(x, Pos(U, x) + 1, Length(x));
1322      RPCBrokerV.Results.Delete(0);
1323    end;
1324    FastAssign(RPCBrokerV.Results, SetItems);
1325  end;
1326  
1327  procedure LoadWriteOrders(Dest: TStrings);
1328  begin
1329    CallV('ORWDX WRLST', [Encounter.Location]);
1330    FastAssign(RPCBrokerV.Results, Dest);
1331  end;
1332  
1333  procedure LoadWriteOrdersED(Dest: TStrings; EvtID: string);
1334  begin
1335    CallV('OREVNTX1 WRLSTED', [Encounter.Location,EvtID]);
1336    if RPCBrokerV.Results.count > 0 then
1337    begin
1338      Dest.Clear;
1339    FastAssign(RPCBrokerV.Results, Dest);
1340    end
1341  end;
1342  
1343  function OrderDisabledMessage(DlgIEN: Integer): string;
1344  begin
1345    Result := sCallV('ORWDX DISMSG', [DlgIEN]);
1346  end;
1347  
1348  procedure SendOrders(OrderList: TStringList; const ESCode: string);
1349  var
1350    i: Integer;
1351  begin
1352    { prepending the space to ESCode is temporary way to keep broker from crashing }
1353    CallV('ORWDX SEND', [Patient.DFN, Encounter.Provider, Encounter.Location, ' ' + ESCode, OrderList]);
1354    { this is a stop gap way to prevent an undesired error message when user chooses not to sign }
1355    with RPCBrokerV do for i := 0 to Results.Count - 1 do
1356      if Piece(Results[i], U, 4) = 'This order requires a signature.'
1357        then Results[i] := Piece(Results[i], U, 1);
1358    OrderList.Clear;
1359    FastAssign(RPCBrokerV.Results, OrderList);
1360  end;
1361  
1362  procedure SendReleaseOrders(OrderList: TStringList);
1363  var
1364    loc: string;
1365    CurrTS: Integer;
1366    PtTS: string;
1367  begin
1368    PtTS := Piece(GetCurrentSpec(Patient.DFN),'^',2);
1369    CurrTS := StrToIntDef(PtTS,0);
1370    Loc := IntToStr(Encounter.Location);
1371    CallV('ORWDX SENDED',[OrderList,CurrTS,Loc]);
1372    OrderList.Clear;
1373    FastAssign(RPCBrokerV.Results, OrderList);
1374  end;
1375  
1376  procedure SendAndPrintOrders(OrderList, ErrList: TStrings; const ESCode: string; const DeviceInfo: string);
1377  var
1378    i: Integer;
1379  begin
1380    { prepending the space to ESCode is temporary way to keep broker from crashing }
1381    CallV('ORWDX SENDP', [Patient.DFN, Encounter.Provider, Encounter.Location, ' ' + ESCode, DeviceInfo, OrderList]);
1382    { this is a stop gap way to prevent an undesired error message when user chooses not to sign }
1383    with RPCBrokerV do for i := 0 to Results.Count - 1 do
1384      if Piece(Results[i], U, 3) <> 'This order requires a signature.'
1385        then ErrList.Add(Results[i]);
1386  end;
1387  
1388  procedure PrintOrdersOnReview(OrderList: TStringList; const DeviceInfo: string; PrintLoc: Integer = 0);
1389  var
1390  Loc: Integer;
1391  begin
1392    if (PrintLoc > 0) and (PrintLoc <> Encounter.Location) then Loc := PrintLoc
1393    else Loc := Encounter.Location;
1394    CallV('ORWD1 RVPRINT',  [Loc, DeviceInfo, OrderList]);
1395  end;
1396  
1397  procedure PrintServiceCopies(OrderList: TStringList; PrintLoc: Integer = 0);  {*REV*}
1398  var
1399  Loc: Integer;
1400  begin
1401    if (PrintLoc > 0) and (PrintLoc <> Encounter.Location) then Loc := PrintLoc
1402    else Loc := Encounter.Location;
1403    CallV('ORWD1 SVONLY',  [Loc, OrderList]);
1404  end;
1405  
1406  procedure ExecutePrintOrders(SelectedList: TStringList; const DeviceInfo: string);
1407  begin
1408    CallV('ORWD1 PRINTGUI', [Encounter.Location, DeviceInfo, SelectedList]);
1409  end;
1410  
1411  { Order Actions }
1412  
1413  function DialogForOrder(const ID: string): Integer;
1414  begin
1415    Result := StrToIntDef(sCallV('ORWDX DLGID', [ID]), 0);
1416  end;
1417  
1418  function FormIDForOrder(const ID: string): Integer;
1419  begin
1420    Result := StrToIntDef(sCallV('ORWDX FORMID', [ID]), 0);
1421  end;
1422  
1423  procedure SetOrderFromResults(AnOrder: TOrder);
1424  var
1425    x, y, z: string;
1426  begin
1427    with RPCBrokerV do while Results.Count > 0 do
1428    begin
1429      x := Results[0];
1430      Results.Delete(0);
1431      if CharAt(x, 1) <> '~' then Continue;        // only happens if out of synch
1432      y := '';
1433      while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
1434      begin
1435        y := y + Copy(Results[0], 2, Length(Results[0])) + CRLF;
1436        Results.Delete(0);
1437      end;
1438      if Length(y) > 0 then y := Copy(y, 1, Length(y) - 2);  // take off last CRLF
1439      z := '';
1440      if (Results.Count > 0) and (Results[0] = '|') then
1441        begin
1442          Results.Delete(0);
1443          while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
1444            begin
1445              z := z + Copy(Results[0], 2, Length(Results[0])); //PKI Change
1446              Results.Delete(0);
1447            end;
1448        end;
1449      SetOrderFields(AnOrder, x, y, z);
1450    end;
1451  end;
1452  
1453  procedure LockPatient(var ErrMsg: string);
1454  begin
1455    ErrMsg := sCallV('ORWDX LOCK', [Patient.DFN]);
1456    if Piece(ErrMsg, U, 1) = '1' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
1457  end;
1458  
1459  procedure UnlockPatient;
1460  begin
1461    sCallV('ORWDX UNLOCK', [Patient.DFN]);
1462  end;
1463  
1464  procedure LockOrder(OrderID: string; var ErrMsg: string);
1465  begin
1466    ErrMsg := sCallV('ORWDX LOCK ORDER', [OrderID]);
1467    if Piece(ErrMsg, U, 1) = '1' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
1468  end;
1469  
1470  procedure UnlockOrder(OrderID: string);
1471  begin
1472    sCallV('ORWDX UNLOCK ORDER', [OrderID]);
1473  end;
1474  
1475  procedure ValidateOrderAction(const ID, Action: string; var ErrMsg: string);
1476  begin
1477    if Action = OA_SIGN then ErrMsg := sCallV('ORWDXA VALID', [ID, Action, User.DUZ])
1478    else ErrMsg := sCallV('ORWDXA VALID', [ID, Action, Encounter.Provider]);
1479  end;
1480  
1481  procedure ValidateOrderActionNature(const ID, Action, Nature: string; var ErrMsg: string);
1482  begin
1483    ErrMsg := sCallV('ORWDXA VALID', [ID, Action, Encounter.Provider, Nature]);
1484  end;
1485  
1486  procedure IsLatestAction(const ID: string; var ErrList: TStringList);
1487  begin
1488    CallV('ORWOR ACTION TEXT',[ID]);
1489    if RPCBrokerV.Results.Count > 0 then
1490      FastAssign(RPCBrokerV.Results, Errlist);
1491  end;
1492  
1493  procedure ChangeOrder(AnOrder: TOrder; ResponseList: TList);
1494  begin
1495  end;
1496  
1497  procedure RenewOrder(AnOrder: TOrder; RenewFields: TOrderRenewFields; IsComplex: integer; AnIMOOrderAppt: double; OCList: TStringList);
1498  { put RenewFields into tmplst[0]=BaseType^Start^Stop^Refills^Pickup, tmplst[n]=comments }
1499  var
1500    tmplst: TStringList;
1501    i: integer;
1502    y: string;
1503  begin
1504  
1505    tmplst := TStringList.Create;
1506  
1507    {Begin Billing Aware}
1508    UBAGlobals.SourceOrderID := AnOrder.ID;
1509    {End Billing Aware}
1510  
1511    try
1512      with RenewFields do
1513         begin
1514         tmplst.SetText(PChar(Comments));
1515         tmplst.Insert(0, IntToStr(BaseType) + U + StartTime + U + StopTime + U + IntToStr(Refills) + U + Pickup);
1516         end;
1517  
1518      with RPCBrokerV do
1519      begin
1520        ClearParameters := True;
1521        RemoteProcedure := 'ORWDXR RENEW';
1522        Param[0].PType := literal;
1523        Param[0].Value := AnOrder.ID;
1524        Param[1].PType := literal;
1525        Param[1].Value := Patient.DFN;
1526        Param[2].PType := literal;
1527        Param[2].Value := IntToStr(Encounter.Provider);
1528        Param[3].PType := literal;
1529        Param[3].Value := IntToStr(Encounter.Location);
1530        Param[4].PType := list;
1531        for i := 0 to tmplst.Count - 1 do
1532          Param[4].Mult[IntToStr(i+1)] := tmplst[i];
1533        Param[4].Mult['"ORCHECK"'] := IntToStr(OCList.Count);
1534        for i := 0 to OCList.Count - 1 do
1535        begin
1536        // put quotes around everything to prevent broker from choking
1537        y := '"ORCHECK","' + Piece(OCList[i], U, 1) + '","' + Piece(OCList[i], U, 3) +
1538          '","' + IntToStr(i+1) + '"';
1539        Param[4].Mult[y] := Pieces(OCList[i], U, 2, 4);
1540      end;
1541      Param[5].PType := literal;
1542      Param[5].Value := IntToStr(IsComplex);
1543      Param[6].PType := literal;
1544      Param[6].Value := FloatToStr(AnIMOOrderAppt);
1545      CallBroker;
1546      SetOrderFromResults(AnOrder);
1547  
1548       {Begin Billing Aware}
1549         UBAGlobals.TargetOrderID := AnOrder.ID; //the ID of the renewed order
1550         UBAGlobals.CopyTreatmentFactorsDxsToRenewedOrder;
1551       {End Billing Aware}
1552  
1553    end;
1554    finally
1555      tmplst.Free;
1556    end;
1557  end;
1558  
1559  procedure HoldOrder(AnOrder: TOrder);
1560  begin
1561    CallV('ORWDXA HOLD', [AnOrder.ID, Encounter.Provider]);
1562    SetOrderFromResults(AnOrder);
1563  end;
1564  
1565  procedure ReleaseOrderHold(AnOrder: TOrder);
1566  begin
1567    CallV('ORWDXA UNHOLD', [AnOrder.ID, Encounter.Provider]);
1568    SetOrderFromResults(AnOrder);
1569  end;
1570  
1571  procedure ListDCReasons(Dest: TStrings; var DefaultIEN: Integer);
1572  begin
1573    CallV('ORWDX2 DCREASON', [nil]);
1574    ExtractItems(Dest, RPCBrokerV.Results, 'DCReason');
1575    //AGP Change 26.15 for PSI-04-63
1576    //DefaultIEN := StrToIntDef(Piece(ExtractDefault(RPCBrokerV.Results, 'DCReason'), U, 1), 0);
1577  end;
1578  
1579  function GetREQReason: Integer;
1580  begin
1581    Result := StrToIntDef(sCallV('ORWDXA DCREQIEN', [nil]), 0);
1582  end;
1583  
1584  procedure DCOrder(AnOrder: TOrder; AReason: Integer; NewOrder: boolean; var DCType: Integer);
1585  var
1586    AParentID, DCOrigOrder: string;
1587  begin
1588    AParentID := AnOrder.ParentID;
1589    if AnOrder.DCOriginalOrder = true then DCOrigOrder := '1'
1590    else DCOrigOrder := '0';
1591    CallV('ORWDXA DC', [AnOrder.ID, Encounter.Provider, Encounter.Location, AReason, DCOrigOrder, NewOrder]);
1592    UBACore.DeleteDCOrdersFromCopiedList(AnOrder.ID);
1593    DCType := StrToIntDef(Piece(RPCBrokerV.Results[0], U, 14), 0);
1594    SetOrderFromResults(AnOrder);
1595    AnOrder.ParentID := AParentID;
1596  end;
1597  
1598  procedure AlertOrder(AnOrder: TOrder; AlertRecip: Int64);
1599  begin
1600    CallV('ORWDXA ALERT', [AnOrder.ID, AlertRecip]);
1601    // don't worry about results
1602  end;
1603  
1604  procedure FlagOrder(AnOrder: TOrder; const FlagReason: string; AlertRecip: Int64);
1605  begin
1606    CallV('ORWDXA FLAG', [AnOrder.ID, FlagReason, AlertRecip]);
1607    SetOrderFromResults(AnOrder);
1608  end;
1609  
1610  procedure LoadFlagReason(Dest: TStrings; const ID: string);
1611  begin
1612    CallV('ORWDXA FLAGTXT', [ID]);
1613    FastAssign(RPCBrokerV.Results, Dest);
1614  end;
1615  
1616  procedure UnflagOrder(AnOrder: TOrder; const AComment: string);
1617  begin
1618    CallV('ORWDXA UNFLAG', [AnOrder.ID, AComment]);
1619    SetOrderFromResults(AnOrder);
1620  end;
1621  
1622  procedure LoadWardComments(Dest: TStrings; const ID: string);
1623  begin
1624    CallV('ORWDXA WCGET', [ID]);
1625    FastAssign(RPCBrokerV.Results, Dest);
1626  end;
1627  
1628  procedure PutWardComments(Src: TStrings; const ID: string; var ErrMsg: string);
1629  begin
1630    ErrMsg := sCallV('ORWDXA WCPUT', [ID, Src]);
1631  end;
1632  
1633  procedure CompleteOrder(AnOrder: TOrder; const ESCode: string);
1634  begin
1635    CallV('ORWDXA COMPLETE', [AnOrder.ID, ESCode]);
1636    SetOrderFromResults(AnOrder);
1637  end;
1638  
1639  procedure VerifyOrder(AnOrder: TOrder; const ESCode: string);
1640  begin
1641    CallV('ORWDXA VERIFY', [AnOrder.ID, ESCode]);
1642    SetOrderFromResults(AnOrder);
1643  end;
1644  
1645  procedure VerifyOrderChartReview(AnOrder: TOrder; const ESCode: string);
1646  begin
1647    CallV('ORWDXA VERIFY', [AnOrder.ID, ESCode, 'R']);
1648    SetOrderFromResults(AnOrder);
1649  end;
1650  
1651  function GetOrderableIen(AnOrderId:string): integer;
1652  begin
1653    Result := StrToIntDef(sCallV('ORWDXR GTORITM', [AnOrderId]),0);
1654  end;
1655  
1656  procedure StoreDigitalSig(AID, AHash: string; AProvider: Int64; ASig, ACrlUrl, DFN: string; var AError: string);
1657  var
1658    len, ix: integer;
1659    ASigAray: TStringList;
1660  begin
1661    ASigAray := TStringList.Create;
1662    ix := 1;
1663    len := length(ASig);
1664    while len >= ix do
1665      begin
1666          ASigAray.Add(copy(ASig, ix, 240));
1667          inc(ix, 240);
1668      end;   //while
1669    try
1670      CallV('ORWOR1 SIG', [AID, AHash, len, '100', AProvider, ASigAray, ACrlUrl, DFN]);
1671      with RPCBrokerV do
1672        if piece(Results[0],'^',1) = '-1' then
1673          begin
1674            ShowMsg('Storage of Digital Signature FAILED: ' + piece(Results[0],'^',2) + CRLF + CRLF +
1675              'This error will prevent this order from being sent to the service for processing. Please cancel the order and try again.' + CRLF + CRLF +
1676              'If this problem persists, then there is a problem in the CPRS PKI interface, and it needs to be reported through the proper channels, to the developer Cary Malmrose.');
1677            AError := '1';
1678          end;
1679    finally
1680      ASigAray.Free;
1681    end;
1682  end;
1683  
1684  procedure UpdateOrderDGIfNeeded(AnID: string);
1685  var
1686    NeedUpdate: boolean;
1687    tmpDFN: string;
1688  begin
1689    tmpDFN := Patient.DFN;
1690    Patient.Clear;
1691    Patient.DFN := tmpDFN;
1692    NeedUpdate := SCallV('ORWDPS4 IPOD4OP', [AnID]) = '1';
1693    if Patient.Inpatient and needUpdate then
1694      SCallV('ORWDPS4 UPDTDG',[AnID]);
1695  end;
1696  
1697  function CanEditSuchRenewedOrder(AnID: string; IsTxtOrder: integer): boolean;
1698  begin
1699    Result := SCallV('ORWDXR01 CANCHG',[AnID,IsTxtOrder]) = '1';
1700  end;
1701  
1702  function IsPSOSupplyDlg(DlgID, QODlg: integer): boolean;
1703  begin
1704    Result := SCallV('ORWDXR01 ISSPLY',[DlgID,QODlg])='1';
1705  end;
1706  
1707  procedure SaveChangesOnRenewOrder(var AnOrder: TOrder; AnID, TheRefills, ThePickup: string; IsTxtOrder: integer);
1708  begin
1709    SCallV('ORWDXR01 SAVCHG',[AnID,TheRefills,ThePickup,IsTxtOrder]);
1710    SetOrderFromResults(AnOrder);
1711  end;
1712  
1713  function DoesOrderStatusMatch(OrderArray: TStringList): boolean;
1714  begin
1715   Result := StrtoIntDef(SCallV('ORWDX1 ORDMATCH',[Patient.DFN, OrderArray]),0)=1;
1716  end;
1717  
1718  { Order Information }
1719  
1720  function OrderIsReleased(const ID: string): Boolean;
1721  begin
1722    Result := sCallV('ORWDXR ISREL', [ID]) = '1';
1723  end;
1724  
1725  procedure LoadRenewFields(RenewFields: TOrderRenewFields; const ID: string);
1726  var
1727    i: Integer;
1728  begin
1729    CallV('ORWDXR RNWFLDS', [ID]);
1730    with RPCBrokerV, RenewFields do
1731    begin
1732      BaseType  := StrToIntDef(Piece(Results[0], U, 1), 0);
1733      StartTime := Piece(Results[0], U, 2);
1734      StopTime  := Piece(Results[0], U, 3);
1735      Refills   := StrToIntDef(Piece(Results[0], U, 4), 0);
1736      Pickup    := Piece(Results[0], U, 5);
1737      Comments  := '';
1738      for i := 1 to Results.Count - 1 do Comments := Comments + CRLF + Results[i];
1739      if Copy(Comments, 1, 2) = CRLF then Delete(Comments, 1, 2);
1740    end;
1741  end;
1742  
1743  procedure GetChildrenOfComplexOrder(AnParentID,CurrAct: string; var ChildList: TStringList); //PSI-COMPLEX
1744  var
1745    i: integer;
1746  begin
1747   CallV('ORWDXR ORCPLX',[AnParentID,CurrAct]);
1748   if RPCBrokerV.Results.Count = 0 then Exit;
1749   With RPCBrokerV do
1750   begin
1751     for i := 0 to Results.Count - 1 do
1752     begin
1753       if (Piece(Results[i],'^',1) <> 'E') and (Length(Results[i])>0) then
1754         ChildList.Add(Results[i]);
1755     end;
1756   end;
1757  end;
1758  
1759  procedure LESValidationForChangedLabOrder(var RejectedReason: TStringList; AnOrderInfo: string);
1760  begin
1761    CallV('ORWDPS5 LESAPI',[AnOrderInfo]);
1762    if RPCBrokerV.Results.Count > 0 then
1763      FastAssign(RPCBrokerV.Results, RejectedReason);
1764  end;
1765  
1766  procedure ChangeEvent(AnOrderList: TStringList; APtEvtId: string);
1767  begin
1768    SCallV('OREVNTX1 CHGEVT', [APtEvtId,AnOrderList]);
1769  end;
1770  
1771  procedure DeletePtEvent(APtEvtID: string);
1772  begin
1773    SCallV('OREVNTX1 DELPTEVT',[APtEvtID]);
1774  end;
1775  
1776  function IsRenewableComplexOrder(AnParentID: string): boolean; //PSI-COMPLEX
1777  var
1778    rst: integer;
1779  begin
1780    Result := False;
1781    rst := StrToIntDef(SCallV('ORWDXR CANRN',[AnParentID]),0);
1782    if rst>0 then
1783      Result := True;
1784  end;
1785  
1786  function IsComplexOrder(AnOrderID: string): boolean; //PSI-COMPLEX
1787  var
1788    rst: integer;
1789  begin
1790    Result := False;
1791    rst := StrToIntDef(SCallV('ORWDXR ISCPLX',[AnOrderID]),0);
1792    if rst > 0 then
1793      Result := True;
1794  end;
1795  
1796  procedure ValidateComplexOrderAct(AnOrderID: string; var ErrMsg: string); //PSI-COMPLEX
1797  begin
1798    ErrMsg := SCallV('ORWDXA OFCPLX',[AnOrderID]);
1799  end;
1800  
1801  function GetDlgData(ADlgID: string): string;
1802  begin
1803    Result := SCallV('OREVNTX1 GETDLG',[ADlgID]);
1804  end;
1805  
1806  function PtEvtEmpty(APtEvtID: string): Boolean;
1807  begin
1808    Result := False;
1809    if StrToIntDef(SCallV('OREVNTX1 EMPTY',[APtEvtID]),0)>0 then
1810      Result := True;
1811  end;
1812  
1813  
1814  function TextForOrder(const ID: string): string;
1815  begin
1816    CallV('ORWORR GETTXT', [ID]);
1817    Result := RPCBrokerV.Results.Text;
1818  end;
1819  
1820  function GetConsultOrderNumber(ConsultIEN: string): string;
1821  begin
1822    Result := sCallv('ORQQCN GET ORDER NUMBER',[ConsultIEN]);
1823  end;
1824  
1825  function GetOrderByIFN(const ID: string): TOrder;
1826  var
1827    x, y, z: string;
1828    AnOrder: TOrder;
1829  begin
1830    AnOrder := TOrder.Create;
1831    CallV('ORWORR GETBYIFN', [ID]);
1832    with RPCBrokerV do while Results.Count > 0 do
1833    begin
1834      x := Results[0];
1835      Results.Delete(0);
1836      if CharAt(x, 1) <> '~' then Continue;        // only happens if out of synch
1837      y := '';
1838      while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
1839      begin
1840        y := y + Copy(Results[0], 2, Length(Results[0])) + CRLF;
1841        Results.Delete(0);
1842      end;
1843      if Length(y) > 0 then y := Copy(y, 1, Length(y) - 2);  // take off last CRLF
1844      z := '';
1845      if (Results.Count > 0) and (Results[0] = '|') then
1846        begin
1847          Results.Delete(0);
1848          while (Results.Count > 0) and (CharAt(Results[0], 1) <> '~') and (CharAt(Results[0], 1) <> '|') do
1849            begin
1850              z := z + Copy(Results[0], 2, Length(Results[0])); //PKI Change
1851              Results.Delete(0);
1852            end;
1853        end;
1854      SetOrderFields(AnOrder, x, y, z);
1855    end;
1856    Result := AnOrder;
1857  end;
1858  
1859  function GetPackageByOrderID(const OrderID: string): string;
1860  begin
1861    Result := SCallV('ORWDXR GETPKG',[OrderID]);
1862  end;
1863  
1864  function AnyOrdersRequireSignature(OrderList: TStringList): Boolean;
1865  begin
1866    Result := sCallV('ORWD1 SIG4ANY', [OrderList]) = '1';
1867  end;
1868  
1869  function OrderRequiresSignature(const ID: string): Boolean;
1870  begin
1871    Result := sCallV('ORWD1 SIG4ONE', [ID]) = '1';
1872  end;
1873  
1874  function OrderRequiresDigitalSignature(const ID: string): Boolean;
1875  begin
1876    Result := sCallV('ORWOR1 CHKDIG', [ID]) = '1';
1877  end;
1878  
1879  function GetDrugSchedule(const ID: string): string;
1880  begin
1881    Result := sCallV('ORWOR1 GETDSCH', [ID]);
1882  end;
1883  
1884  function GetExternalText(const ID: string): string;
1885  var
1886    x,y: string;
1887  begin
1888    CallV('ORWOR1 GETDTEXT', [ID]);
1889    y := '';
1890    with RPCBrokerV do while Results.Count > 0 do
1891      begin
1892        x := Results[0];
1893        Results.Delete(0);
1894        y := y + x;
1895      end;
1896    Result := y;
1897  end;
1898  
1899  function SetExternalText(const ID: string; ADrugSch: string; AUser: Int64): string;
1900  var
1901    x,y: string;
1902  begin
1903    CallV('ORWOR1 SETDTEXT', [ID, ADrugSch, AUser]);
1904    y := '';
1905    with RPCBrokerV do while Results.Count > 0 do
1906      begin
1907        x := Results[0];
1908        Results.Delete(0);
1909        y := y + x;
1910      end;
1911    Result := y;
1912  end;
1913  
1914  function GetDigitalSignature(const ID: string): string;
1915  begin
1916    CallV('ORWORR GETDSIG', [ID]);
1917    Result := RPCBrokerV.Results.Text;
1918  end;
1919  
1920  function GetDEA(const ID: string): string;
1921  begin
1922    CallV('ORWORR GETDEA', [ID]);
1923    Result := RPCBrokerV.Results.Text;
1924  end;
1925  
1926  function GetPKISite: Boolean;
1927  begin
1928    Result := sCallV('ORWOR PKISITE', [nil]) = '1';
1929  end;
1930  
1931  function GetPKIUse: Boolean;
1932  begin
1933    Result := sCallV('ORWOR PKIUSE', [nil]) = '1';
1934  end;
1935  
1936  function DoesOIPIInSigForQO(AnQOID: integer): integer;
1937  begin
1938    Result := StrToIntDef(SCallV('ORWDPS1 HASOIPI',[AnQOID]),0);
1939  end;
1940  
1941  function GetDispGroupForLES: string;
1942  begin
1943    Result := SCallV('ORWDPS5 LESGRP',[nil]);  
1944  end;
1945  
1946  function GetOrderPtEvtID(AnOrderID: string): string;
1947  begin
1948    Result := SCallV('OREVNTX1 ODPTEVID',[AnOrderID]);
1949  end;
1950  
1951  function VerbTelPolicyOrder(AnOrderID: string): boolean;
1952  begin
1953    Result := SCallV('ORWDPS5 ISVTP',[AnOrderID]) = '1';
1954  end;
1955  
1956  function ForIVandUD(AnOrderID: string): boolean;
1957  begin
1958    Result := SCallV('ORWDPS4 ISUDIV',[AnOrderID]) = '1';
1959  end;
1960  
1961  function GetEventIFN(const AEvntID: string): string;
1962  begin
1963    Result := sCallV('OREVNTX1 EVT',[AEvntID]);
1964  end;
1965  
1966  function GetEventName(const AEvntID: string): string;
1967  begin
1968    Result := sCallV('OREVNTX1 NAME',[AEvntID]);
1969  end;
1970  
1971  function GetEventLoc(const APtEvntID: string): string;
1972  begin
1973    Result := SCallV('OREVNTX1 LOC', [APtEvntID]);
1974  end;
1975  
1976  function GetEventLoc1(const AnEvntID: string): string;
1977  begin
1978    Result := SCallV('OREVNTX1 LOC1', [AnEvntID]);
1979  end;
1980  
1981  function GetEventDiv(const APtEvntID: string): string;
1982  begin
1983    Result := SCallV('OREVNTX1 DIV',[APtEvntID]);
1984  end;
1985  
1986  function GetEventDiv1(const AnEvntID: string): string;
1987  begin
1988    Result := SCallV('OREVNTX1 DIV1',[AnEvntID]);
1989  end;
1990  
1991  function GetCurrentSpec(const APtIFN: string): string;
1992  begin
1993    Result := SCallV('OREVNTX1 CURSPE', [APtIFN]);
1994  end;
1995  
1996  function GetDefaultEvt(const AProviderIFN: string): string;
1997  begin
1998    Result := SCallV('OREVNTX1 DFLTEVT',[AProviderIFN]);
1999  end;
2000  
2001  procedure DeleteDefaultEvt;
2002  begin
2003    SCallV('OREVNTX1 DELDFLT',[User.DUZ]);
2004  end;
2005  
2006  function isExistedEvent(const APtDFN: string; const AEvtID: string; var APtEvtID: string): Boolean;
2007  begin
2008    Result := False;
2009    APtEvtID := SCallV('OREVNTX1 EXISTS', [APtDFN,AEvtID]);
2010    if StrToIntDef(APtEvtID,0) > 0 then
2011     Result := True;
2012  end;
2013  
2014  function TypeOfExistedEvent(APtDFN: string; AEvtID: Integer): Integer;
2015  begin
2016    Result := StrToIntDef(SCallV('OREVNTX1 TYPEXT', [APtDFN,AEvtID]),0);
2017  end;
2018  
2019  function isMatchedEvent(const APtDFN: string; const AEvtID: string; var ATs:string): Boolean;
2020  var
2021    rst: string;
2022  begin
2023    Result := False;
2024    rst := SCallV('OREVNTX1 MATCH',[APtDFN,AEvtID]);
2025    if StrToIntDef(Piece(rst,'^',1),0)>0 then
2026    begin
2027      ATs := Piece(rst,'^',2);
2028      Result := True;
2029    end;
2030  end;
2031  
2032  function isDCedOrder(const AnOrderID: string): Boolean;
2033  var
2034    rst: string;
2035  begin
2036    Result := False;
2037    rst := SCAllV('OREVNTX1 ISDCOD',[AnOrderID]);
2038    if STrToIntDef(rst,0)>0 then
2039      Result := True;
2040  end;
2041  
2042  function isOnholdMedOrder(AnOrderID: string): Boolean;
2043  var
2044    rst: string;
2045  begin
2046    Result := False;
2047    rst := SCAllV('OREVNTX1 ISHDORD',[AnOrderID]);
2048    if StrToIntDef(rst,0)>0 then
2049      Result := True;
2050  end;
2051  
2052  function SetDefaultEvent(var AErrMsg: string; EvtID: string): Boolean;
2053  begin
2054    AErrMsg := SCallV('OREVNTX1 SETDFLT',[EvtID]);
2055    Result := True;
2056  end;
2057  
2058  function GetEventPromptID: integer;
2059  var
2060    evtPrompt: string;
2061  begin
2062    evtPrompt := SCallV('OREVNTX1 PRMPTID',[nil]);
2063    Result := StrToIntDef(evtPrompt,0);
2064  end;
2065  
2066  function GetDefaultTSForEvt(AnEvtID: integer): string;
2067  begin
2068    Result := SCallV('OREVNTX1 DEFLTS',[AnEvtID]);
2069  end;
2070  
2071  function GetPromptIDs: string;
2072  begin
2073    Result := SCallV('OREVNTX1 PROMPT IDS',[nil]);
2074  end;
2075  
2076  function GetEventDefaultDlg(AEvtID: integer): string;
2077  begin
2078    Result := SCallV('OREVNTX1 DFLTDLG',[AEvtID]);
2079  end;
2080  
2081  function CanManualRelease: boolean;
2082  var
2083    rst: integer;
2084  begin
2085    Result := False;
2086    rst := StrToIntDef(SCallV('OREVNTX1 AUTHMREL',[nil]),0);
2087    if rst > 0 then
2088      Result := True;
2089  end;
2090  
2091  function TheParentPtEvt(APtEvt: string): string;
2092  begin
2093    Result := SCallV('OREVNTX1 HAVEPRT',[APtEvt]);
2094  end;
2095  
2096  function IsCompletedPtEvt(APtEvtID: integer): boolean;
2097  var
2098    rst : integer;
2099  begin
2100    Result := False;
2101    rst := StrToIntDef(SCallV('OREVNTX1 COMP',[APtEvtID]),0);
2102    if rst > 0 then
2103      Result := True;
2104  end;
2105  
2106  function IsPassEvt(APtEvtID: integer; APtEvtType: char): boolean;
2107  var
2108    rst: integer;
2109  begin
2110    Result := False;
2111    rst := StrToIntDef(SCallV('OREVNTX1 ISPASS',[APtEvtID, APtEvtType]),0);
2112    if rst = 1 then
2113      Result := True;
2114  end;
2115  
2116  function IsPassEvt1(AnEvtID: integer; AnEvtType: char): boolean;
2117  var
2118    rst: integer;
2119  begin
2120    Result := False;
2121    rst := StrToIntDef(SCallV('OREVNTX1 ISPASS1',[AnEvtID, AnEvtType]),0);
2122    if rst = 1 then
2123      Result := True;
2124  end;
2125  
2126  procedure TerminatePtEvt(APtEvtID: integer);
2127  begin
2128    SCallV('OREVNTX1 DONE',[APtEvtID]);
2129  end;
2130  
2131  procedure SetPtEvtList(Dest: TStrings; APtDFN: string; var ATotal: Integer);
2132  begin
2133    CallV('OREVNTX LIST',[APtDFN]);
2134    if RPCBrokerV.Results.Count > 0 then
2135    begin
2136      ATotal := StrToIntDef(RPCBrokerV.Results[0],0);
2137      if ATotal > 0 then
2138      begin
2139        MixedCaseList( RPCBrokerV.Results );
2140        RPCBrokerV.Results.Delete(0);
2141        FastAssign(RPCBrokerV.Results, Dest);
2142      end;
2143    end;
2144  end;
2145  
2146  procedure GetTSListForEvt(Dest: TStrings; AnEvtID:integer);
2147  begin
2148    CallV('OREVNTX1 MULTS',[AnEvtID]);
2149    if RPCBrokerV.Results.Count > 0 then
2150    begin
2151      SortByPiece(TStringList(RPCBrokerV.Results),'^',2);
2152      FastAssign(RPCBrokerV.Results, Dest);
2153    end;
2154  end;
2155  
2156  procedure GetChildEvent(var AChildList: TStringList; APtEvtID: string);
2157  begin
2158  //
2159  end;
2160  
2161  function DeleteEmptyEvt(APtEvntID: string; var APtEvntName: string; Ask: boolean): boolean;
2162  const
2163    TX_EVTDEL1 = 'There are no orders tied to ';
2164    TX_EVTDEL2 = ', Would you like to cancel it?';
2165  begin
2166    Result := false;
2167    if APtEvntID = '0' then
2168    begin
2169      Result := True;
2170      Exit;
2171    end;
2172    if PtEvtEmpty(APtEvntID) then
2173    begin
2174      if Length(APtEvntName)=0 then
2175        APtEvntName := GetEventName(APtEvntID);
2176      if Ask then
2177      begin
2178        if InfoBox(TX_EVTDEL1 + APtEvntName + TX_EVTDEL2, 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then
2179        begin
2180          DeletePtEvent(APtEvntID);
2181          Result := True;
2182        end;
2183      end;
2184      if not Ask then
2185      begin
2186        DeletePtEvent(APtEvntID);
2187        Result := True;
2188      end;
2189  
2190    end;
2191  end;
2192  
2193  function CompleteEvt(APtEvntID: string; APtEvntName: string; Ask: boolean): boolean;
2194  const
2195    TX_EVTFIN1 = 'All of the orders tied to ';
2196    TX_EVTFIN2 = ' have been released to a service, ' + #13 + 'Would you like to terminate this event?';
2197  var
2198    ThePtEvtName: string;
2199  begin
2200    Result := false;
2201    if APtEvntID = '0' then
2202    begin
2203      Result := True;
2204      Exit;
2205    end;
2206    if PtEvtEmpty(APtEvntID) then
2207    begin
2208      if Length(APtEvntName)=0 then
2209        ThePtEvtName := GetEventName(APtEvntID)
2210      else
2211        ThePtEvtName := APtEvntName;
2212      if Ask then
2213      begin
2214        if InfoBox(TX_EVTFIN1 + ThePtEvtName + TX_EVTFIN2, 'Confirmation', MB_OKCANCEL or MB_ICONQUESTION) = IDOK then
2215        begin
2216          SCallV('OREVNTX1 DONE',[APtEvntID]);
2217          Result := True;
2218        end;
2219      end else
2220      begin
2221        SCallV('OREVNTX1 DONE',[APtEvntID]);
2222        Result := True;
2223      end;
2224    end;
2225  end;
2226  
2227  { Order Checking }
2228  
2229  function FillerIDForDialog(IEN: Integer): string;
2230  begin
2231    Result := sCallV('ORWDXC FILLID', [IEN]);
2232  end;  
2233  function IsMonograph(): Boolean;
2234  var ret: string;
2235  begin
2236    ret := CharAt(sCallV('ORCHECK ISMONO', [nil]), 1);
2237    Result := ret = '1';
2238  end;
2239  
2240  procedure GetMonographList(ListOfMonographs: TStringList);
2241  begin
2242    CallV('ORCHECK GETMONOL', []);
2243    FastAssign(RPCBrokerV.Results, ListOfMonographs);
2244  end;
2245  
2246  procedure GetMonograph(Monograph: TStringList; x: Integer);
2247  begin
2248    CallV('ORCHECK GETMONO', [x]);
2249    FastAssign(RPCBrokerV.Results, Monograph);
2250  end;
2251  
2252  procedure DeleteMonograph();
2253  begin
2254    CallV('ORCHECK DELMONO', []);
2255  end;  
2256  
2257  procedure GetXtraTxt(OCText: TStringList; x: String; y: String);
2258  begin
2259    CallV('ORCHECK GETXTRA', [x,y]);
2260    FastAssign(RPCBrokerV.Results, OCText);
2261  end;
2262  
2263  function OrderChecksEnabled: Boolean;
2264  begin
2265    if uOrderChecksOn = #0 then uOrderChecksOn := CharAt(sCallV('ORWDXC ON', [nil]), 1);
2266    Result := uOrderChecksOn = 'E';
2267  end;
2268  
2269  function OrderChecksOnDisplay(const FillerID: string): string;
2270  begin
2271    CallV('ORWDXC DISPLAY', [Patient.DFN, FillerID]);
2272    with RPCBrokerV.Results do SetString(Result, GetText, Length(Text));
2273  end;
2274  
2275  procedure OrderChecksOnAccept(ListOfChecks: TStringList; const FillerID, StartDtTm: string;
2276    OIList: TStringList; DupORIFN: string; Renewal: string);
2277  begin
2278    // don't pass OIList if no items, since broker pauses 5 seconds per order
2279    if OIList.Count > 0
2280      then CallV('ORWDXC ACCEPT', [Patient.DFN, FillerID, StartDtTm, Encounter.Location, OIList, DupORIFN, Renewal])
2281      else CallV('ORWDXC ACCEPT', [Patient.DFN, FillerID, StartDtTm, Encounter.Location]);
2282    FastAssign(RPCBrokerV.Results, ListOfChecks);
2283  end;
2284  
2285  procedure OrderChecksOnDelay(ListOfChecks: TStringList; const FillerID, StartDtTm: string;
2286    OIList: TStringList);
2287  begin
2288    // don't pass OIList if no items, since broker pauses 5 seconds per order
2289    if OIList.Count > 0
2290      then CallV('ORWDXC DELAY', [Patient.DFN, FillerID, StartDtTm, Encounter.Location, OIList])
2291      else CallV('ORWDXC DELAY', [Patient.DFN, FillerID, StartDtTm, Encounter.Location]);
2292    FastAssign(RPCBrokerV.Results, ListOfChecks);
2293  end;
2294  
2295  procedure OrderChecksForSession(ListOfChecks, OrderList: TStringList);
2296  begin
2297    CallV('ORWDXC SESSION', [Patient.DFN, OrderList]);
2298    FastAssign(RPCBrokerV.Results, ListOfChecks);
2299  end;
2300  
2301  procedure SaveOrderChecksForSession(const AReason: string; ListOfChecks: TStringList);
2302  var
2303   i, inc, len, numLoop, remain: integer;
2304   OCStr, TmpStr: string;
2305  begin
2306    //CallV('ORWDXC SAVECHK', [Patient.DFN, AReason, ListOfChecks]);
2307    { no result used currently }
2308    RPCBrokerV.ClearParameters := True;
2309    RPCBrokerV.RemoteProcedure := 'ORWDXC SAVECHK';
2310    RPCBrokerV.Param[0].PType := literal;
2311    RPCBrokerV.Param[0].Value := Patient.DFN;  //*DFN*
2312    RPCBrokerV.Param[1].PType := literal;
2313    RPCBrokerV.Param[1].Value := AReason;
2314    RPCBrokerV.Param[2].PType := list;
2315    RPCBrokerV.Param[2].Mult['"ORCHECKS"'] := IntToStr(ListOfChecks.count);
2316    for i := 0 to ListOfChecks.Count - 1 do
2317      begin
2318         OCStr := ListofChecks.Strings[i];
2319         len := Length(OCStr);
2320         if len > 255 then
2321          begin
2322            numLoop := len div 255;
2323            remain := len mod 255;
2324            inc := 0;
2325            while inc <= numLoop do
2326              begin
2327                tmpStr := Copy(OCStr, 1, 255);
2328                OCStr := Copy(OCStr, 256, Length(OcStr));
2329                RPCBrokerV.Param[2].Mult['"ORCHECKS",' + InttoStr(i) + ',' + InttoStr(inc)] := tmpStr;
2330                inc := inc +1;
2331              end;
2332            if remain > 0 then  RPCBrokerV.Param[2].Mult['"ORCHECKS",' + InttoStr(i) + ',' + inttoStr(inc)] := OCStr;
2333  
2334          end
2335        else
2336         RPCBrokerV.Param[2].Mult['"ORCHECKS",' + InttoStr(i)] := OCStr;
2337      end;
2338     CallBroker;
2339  end;
2340  
2341  function DeleteCheckedOrder(const OrderID: string): Boolean;
2342  begin
2343    Result := sCallV('ORWDXC DELORD', [OrderID]) = '1';
2344  end;
2345  
2346  function DataForOrderCheck(const OrderID: string): string;
2347  begin
2348    Result := sCallV('ORWDXR01 OXDATA',[OrderID]);
2349  end;
2350  
2351  (*
2352    TEMPORARILY COMMENTED OUT WHILE TESTING
2353  function GetPromptandDeviceParameters(Location: integer; OrderList: TStringList; Nature: string): TPrintParams;
2354  var
2355    TempParams: TPrintParams;
2356    x: string;
2357  begin
2358    tempParams.OrdersToPrint := TStringList.Create;
2359    try
2360      CallV('ORWD1 PARAM', [Location, Nature, OrderList]);
2361      x := RPCBrokerV.Results[0];
2362      with TempParams do
2363        begin
2364          PromptForChartCopy    := CharAt(Piece(x, U, 1),1);
2365          if Piece(x, U, 5) <> '' then
2366            ChartCopyDevice     := Piece(Piece(x, U, 5),';',1) + '^' + Piece(Piece(x, U, 5),';',2);
2367          PromptForLabels       := CharAt(Piece(x, U, 2),1);
2368          if Piece(x, U, 6) <> '' then
2369            LabelDevice         := Piece(Piece(x, U, 6),';',1) + '^' + Piece(Piece(x, U, 6),';',2);
2370          PromptForRequisitions := CharAt(Piece(x, U, 3),1);
2371          if Piece(x, U, 7) <> '' then
2372            RequisitionDevice   := Piece(Piece(x, U, 7),';',1) + '^' + Piece(Piece(x, U, 7),';',2);
2373          PromptForWorkCopy     := CharAt(Piece(x, U, 4),1);
2374          if Piece(x, U, 8) <> '' then
2375            WorkCopyDevice      := Piece(Piece(x, U, 8),';',1) + '^' + Piece(Piece(x, U, 8),';',2);
2376          AnyPrompts            := ((PromptForChartCopy    in ['1','2']) or
2377                                    (PromptForLabels       in ['1','2']) or
2378                                    (PromptForRequisitions in ['1','2']) or
2379                                    (PromptForWorkCopy     in ['1','2']));
2380          RPCBrokerV.Results.Delete(0);
2381          FastAssign(RPCBrokerV.Results, OrdersToPrint);
2382        end;
2383      Result := TempParams;
2384    finally
2385      tempParams.OrdersToPrint.Free;
2386    end;
2387  end;
2388  *)
2389  
2390  procedure OrderPrintDeviceInfo(OrderList: TStringList; var PrintParams: TPrintParams; Nature: Char; PrintLoc: Integer = 0);
2391  var
2392    x: string;
2393  begin
2394    if Nature <> #0 then
2395      begin
2396         if PrintLoc > 0 then CallV('ORWD2 DEVINFO', [PrintLoc, Nature, OrderList])
2397         else CallV('ORWD2 DEVINFO', [Encounter.Location, Nature, OrderList]);
2398      end
2399    else
2400      begin
2401        if PrintLoc > 0 then CallV('ORWD2 MANUAL', [PrintLoc, OrderList])
2402        else CallV('ORWD2 MANUAL', [Encounter.Location, OrderList]);
2403      end;
2404    x := RPCBrokerV.Results[0];
2405    FillChar(PrintParams, SizeOf(PrintParams), #0);
2406    with PrintParams do
2407    begin
2408      PromptForChartCopy    := CharAt(Piece(x, U, 1),1);
2409      if Piece(x, U, 5) <> '' then
2410        ChartCopyDevice     := Piece(Piece(x, U, 5),';',1) + '^' + Piece(Piece(x, U, 5),';',2);
2411      PromptForLabels       := CharAt(Piece(x, U, 2),1);
2412      if Piece(x, U, 6) <> '' then
2413        LabelDevice         := Piece(Piece(x, U, 6),';',1) + '^' + Piece(Piece(x, U, 6),';',2);
2414      PromptForRequisitions := CharAt(Piece(x, U, 3),1);
2415      if Piece(x, U, 7) <> '' then
2416        RequisitionDevice   := Piece(Piece(x, U, 7),';',1) + '^' + Piece(Piece(x, U, 7),';',2);
2417      PromptForWorkCopy     := CharAt(Piece(x, U, 4),1);
2418      if Piece(x, U, 8) <> '' then
2419      WorkCopyDevice      := Piece(Piece(x, U, 8),';',1) + '^' + Piece(Piece(x, U, 8),';',2);
2420      AnyPrompts            := ((PromptForChartCopy    in ['1','2']) or
2421                                (PromptForLabels       in ['1','2']) or
2422                                (PromptForRequisitions in ['1','2']) or
2423                                (PromptForWorkCopy     in ['1','2']));
2424    end;
2425    if Nature <> #0 then
2426      begin
2427        RPCBrokerV.Results.Delete(0);
2428        OrderList.Clear;
2429        FastAssign(RPCBrokerV.Results, OrderList);
2430      end;
2431  end;
2432  
2433  procedure SaveEvtForOrder(APtDFN: string; AEvt: integer; AnOrderID: string);
2434  var
2435    TheEventID: string;
2436  begin
2437    TheEventID :=  SCallV('OREVNTX1 PUTEVNT',[APtDFN,IntToStr(AEvt),AnOrderID]);
2438  end;
2439  
2440  function EventExist(APtDFN:string; AEvt: integer): integer;
2441  var
2442    AOutCome: string;
2443  begin
2444    AOutCome := SCallV('OREVNTX1 EXISTS', [APtDFN,IntToStr(AEvt)]);
2445    if AOutCome = '' then
2446      Result := 0
2447    else
2448      Result := StrToInt(AOutCome);
2449  end;
2450  
2451  function UseNewMedDialogs: Boolean;
2452  begin
2453    Result := sCallV('ORWDPS1 CHK94', [nil]) = '1';
2454  end;
2455  
2456  { Copay }
2457  procedure GetCoPay4Orders;
2458  begin
2459    RPCBrokerV.RemoteProcedure := 'ORWDPS4 CPLST';
2460    RPCBrokerV.Param[0].PType := literal;
2461    RPCBrokerV.Param[0].Value := Patient.DFN;
2462    CallBroker;
2463  end;
2464  
2465  procedure SaveCoPayStatus(AList: TStrings);
2466  var
2467    i: integer;
2468  
2469  begin
2470    if AList.Count > 0 then
2471    begin
2472      RPCBrokerV.ClearParameters := True;
2473      RPCBrokerV.RemoteProcedure := 'ORWDPS4 CPINFO';
2474      RPCBrokerV.Param[0].PType := list;
2475      for i := 0 to AList.Count-1 do
2476        RPCBrokerV.Param[0].Mult[IntToStr(i+1)] := AList[i];
2477      CallBroker;
2478    end;
2479  end;
2480  
2481  
2482  
2483  function IsValidIMOLoc(LocID: integer; PatientID: string): boolean;   //IMO
2484  var
2485    rst: string;
2486  begin
2487    rst := SCallV('ORIMO IMOLOC',[LocID, PatientID]);
2488    Result := StrToIntDef(rst,-1) > -1;
2489  end;
2490  
2491  function IsIMOOrder(OrderID: string): boolean;          //IMO
2492  begin
2493    Result := SCallV('ORIMO IMOOD',[OrderId])='1';
2494  end;
2495  
2496  function IsInptQO(DlgID: integer): boolean;
2497  begin
2498    Result := SCallV('ORWDXM3 ISUDQO', [DlgID]) = '1';
2499  end;
2500  
2501  function IsIVQO(DlgID: integer): boolean;
2502  begin
2503    Result := SCallV('ORIMO ISIVQO', [DlgID]) = '1';
2504  end;
2505  
2506  function IsClinicLoc(ALoc: integer): boolean;
2507  begin
2508    Result := SCallV('ORIMO ISCLOC', [ALoc]) = '1';
2509  end;
2510  
2511  function IsValidSchedule(AnOrderID: string): boolean; //nss
2512  begin
2513    result := SCallV('ORWNSS VALSCH', [AnOrderID]) = '1';
2514  end;
2515  
2516  function IsValidQOSch(QOID: string): string;  //nss
2517  begin
2518    Result := SCallV('ORWNSS QOSCH',[QOID]);
2519  end;
2520  
2521  function IsValidSchStr(ASchStr: string): boolean;
2522  begin
2523    Result := SCallV('ORWNSS CHKSCH',[ASchStr]) = '1';
2524  end;
2525  
2526  function IsPendingHold(OrderID: string): boolean;
2527  var
2528    ret: string;
2529  begin
2530    ret := sCallV('ORDEA PNDHLD', [OrderID]);
2531    if ret = '1' then Result :=  True
2532    else Result := False;
2533  end;
2534  
2535  { TParentEvent }
2536  
2537  procedure TParentEvent.Assign(AnEvtID: string);
2538  var
2539    evtInfo: string;
2540  begin
2541  // ORY = EVTTYPE_U_EVT_U_EVTNAME_U_EVTDISP_U_EVTDLG
2542    evtInfo := EventInfo1(AnEvtID);
2543    ParentIFN := StrToInt(AnEvtID);
2544    if Length(Piece(evtInfo,'^',4)) < 1 then
2545      ParentName := Piece(evtInfo,'^',3)
2546    else
2547      ParentName := Piece(evtInfo,'^',4);
2548    ParentType := CharAt(Piece(evtInfo,'^',1),1);
2549    ParentDlg := Piece(evtInfo,'^',5);
2550  end;
2551  
2552  constructor TParentEvent.Create;
2553  begin
2554    ParentIFN  := 0;
2555    ParentName := '';
2556    ParentType := #0;
2557    ParentDlg  := '0';
2558  end;
2559  
2560  initialization
2561    uDGroupAll := 0;
2562    uOrderChecksOn := #0;
2563  
2564  finalization
2565    if uDGroupMap <> nil then uDGroupMap.Free;
2566  
2567  end.

Module Calls (2 levels)


rOrders
 ├uCore
 │ ├rCore
 │ ├uConst
 │ ├uCombatVet
 │ ├rTIU
 │ ├rOrders...
 │ ├rConsults
 │ └uOrders
 ├rCore...
 ├uConst
 ├UBAGlobals
 │ ├uConst
 │ ├rOrders...
 │ ├fBALocalDiagnoses
 │ ├fOrdersSign
 │ ├fReview
 │ ├uCore...
 │ ├rCore...
 │ ├UBAConst
 │ └UBACore
 └UBACore...

Module Called-By (2 levels)


                    rOrders
                    fPage┤ 
                 fFrame┤ │ 
                fHSplit┤ │ 
                 fCover┤ │ 
                  fMeds┤ │ 
                    fHP┤ │ 
               fAResize┘ │ 
                    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┘ │ 
               uOrders...┤ 
               fODBase...┤ 
               rODBase...┤ 
            UBAGlobals...┤ 
               UBACore...┤ 
                fFrame...┤ 
               fOrders...┤ 
                fOCAccept┤ 
             fODBase...┤ │ 
        fOrdersRenew...┘ │ 
             fOCMonograph┤ 
           fOCAccept...┤ │ 
          fOCSession...┘ │ 
                  uODBase┤ 
             uOrders...┤ │ 
             fODBase...┤ │ 
             rODBase...┤ │ 
             fOrders...┤ │ 
        fOrdersRenew...┤ │ 
             fODDiet...┤ │ 
          fODConsult...┤ │ 
             fODProc...┤ │ 
             fODAuto...┤ │ 
                fOMNavA┤ │ 
              fOMVerify┤ │ 
                 fOMSet┘ │ 
     fBALocalDiagnoses...┤ 
                fCover...┤ 
           fOrdersSign...┤ 
                 fMeds...┤ 
              fProbEdt...┤ 
             fConsults...┤ 
       fReminderDialog...┤ 
                 fLabs...┤ 
               fReview...┤ 
          fCSRemaining...┤ 
            uSignItems...┤ 
             fODDietLT...┤ 
               rODDiet...┤ 
          fOrdersPrint...┤ 
            fDefaultEvent┤ 
          fOrdersRenew...┤ 
               fODDiet...┤ 
                 fOrderVw┤ 
             fOrders...┘ │ 
             fOrdersDC...┤ 
             fOrdersCV...┤ 
                   fODGen┤ 
             uOrders...┘ │ 
                 fODMedIn┤ 
             uOrders...┘ │ 
             fODMedOut...┤ 
           fConsultAct...┤ 
                fODRad...┤ 
                fODLab...┤ 
              fODBBank...┤ 
               fODMeds...┤ 
               fODAuto...┤ 
               fOMNavA...┤ 
          fOrderSaveQuick┤ 
             uOrders...┘ │ 
                fOMSet...┤ 
              fOrdersHold┤ 
             fOrders...┤ │ 
               fMeds...┘ │ 
            fOrdersUnhold┤ 
             fOrders...┤ │ 
               fMeds...┘ │ 
             fOrdersAlert┤ 
             fOrders...┘ │ 
               fOrderFlag┤ 
             fOrders...┘ │ 
             fOrderUnflag┤ 
             fOrders...┘ │ 
        fOrdersRelease...┤ 
               fOMHTML...┤ 
             fODMedNVA...┤ 
 fODChangeUnreleasedRenew┤ 
             uOrders...┘ │ 
        fOrdersOnChart...┤ 
    fOrdersEvntRelease...┤ 
          fOrdersComplete┤ 
             fOrders...┘ │ 
            fOrdersVerify┤ 
             fOrders...┘ │ 
            fOrderComment┤ 
             fOrders...┘ │ 
       fODReleaseEvent...┤ 
            fOCSession...┤ 
             fOrdersTS...┤ 
            mEvntDelay...┤ 
             fODActive...┤ 
           fOrdersCopy...┤ 
              fMedCopy...┤ 
      fActivateDeactivate┤ 
             fOrders...┤ │ 
               fMeds...┘ │ 
            fOrdersRefill┤ 
               fMeds...┘ │ 
         fODChangeEvtDisp┤ 
           fOrdersCV...┘ │ 
             fRenewOutMed┘ 
        fOrdersRenew...┘