Module

rCore

Path

C:\CPRS\CPRS30\rCore.pas

Last Modified

7/15/2014 3:26:44 PM

Units Used in Implementation

Name Comments
uCore -

Procedures

Name Owner Declaration Scope Comments
AutoUnflagAlertedOrders - procedure AutoUnflagAlertedOrders(PatientDFN, XQAID: string); Interfaced -
CheckRemotePatient - procedure CheckRemotePatient(var Dest: string; Patient, ASite: string; var AccessStatus: Integer); Interfaced -
CheckSensitiveRecordAccess - procedure CheckSensitiveRecordAccess(const DFN: string; var AccessStatus: Integer; var MessageText: string); Interfaced -
CurrentLocationForPatient - procedure CurrentLocationForPatient(const DFN: string; var ALocation: Integer; var AName: string; var ASvc: string); Interfaced -
DeleteAlert - procedure DeleteAlert(XQAID: string); Interfaced Deletes an alert
DeleteAlertForUser - procedure DeleteAlertForUser(XQAID: string); Interfaced Deletes an alert
ForwardAlert - procedure ForwardAlert(XQAID: string; Recip: string; FWDtype: string; Comment: string); Interfaced Forwards an alert with comment to Recip[ient]
GetUserListParam - procedure GetUserListParam(Dest: TStrings; const AParamName: string); Interfaced -
KillRPLPtList - procedure KillRPLPtList(RPLJobNumber: string); Interfaced -
ListAdmitAll - procedure ListAdmitAll(Dest: TStrings; const DFN: string); Interfaced
DFN*
 lists all admissions for a patient: MovementTime^LocIEN^LocName^Type
ListApptAll - procedure ListApptAll(Dest: TStrings; const DFN: string; From: TFMDateTime = 0; Thru: TFMDateTime = 0); Interfaced
Lists appts/visits for a patient (uses same call as cover sheet)
  V|A;DateTime;LocIEN^DateTime^LocName^Status
ListClinicTop - procedure ListClinicTop(Dest: TStrings); Interfaced Checks parameters for list of commonly selected clinics
ListDateRangeClinic - procedure ListDateRangeClinic(Dest: TStrings); Interfaced Returns date ranges for displaying clinic appointments in patient lookup
ListProviderTop - procedure ListProviderTop(Dest: TStrings); Interfaced Checks parameters for list of commonly selected providers
ListPtByClinic - procedure ListPtByClinic(Dest: TStrings; ClinicIEN: Integer; FirstDt, LastDt: string); Interfaced
TFMDateTime);
 lists all patients associated with a given clinic: DFN^Patient Name^App't
ListPtByDflt - procedure ListPtByDflt(Dest: TStrings); Interfaced Loads the default patient list into Dest, Pieces: DFN^PATIENT NAME, ETC.
ListPtByFullSSN - procedure ListPtByFullSSN(Dest: TStrings; const FullSSN: string); Interfaced Lists all patients found in the SSN xref that match FullSSN: DFN^Patient Name
ListPtByLast5 - procedure ListPtByLast5(Dest: TStrings; const Last5: string); Interfaced -
ListPtByProvider - procedure ListPtByProvider(Dest: TStrings; ProviderIEN: Int64); Interfaced Lists all patients associated with a given provider: DFN^Patient Name
ListPtByRPLFullSSN - procedure ListPtByRPLFullSSN(Dest: TStrings; const FullSSN: string); Interfaced Lists all patients found in the SSN xref that match FullSSN: DFN^Patient Name
ListPtByRPLLast5 - procedure ListPtByRPLLast5(Dest: TStrings; const Last5: string); Interfaced -
ListPtBySpecialty - procedure ListPtBySpecialty(Dest: TStrings; SpecialtyIEN: Integer); Interfaced Lists all patients associated with a given specialty: DFN^Patient Name
ListPtByTeam - procedure ListPtByTeam(Dest: TStrings; TeamIEN: Integer); Interfaced Lists all patients associated with a given team: DFN^Patient Name
ListPtByWard - procedure ListPtByWard(Dest: TStrings; WardIEN: Integer); Interfaced Lists all patients associated with a given ward: DFN^Patient Name^Room/Bed
ListPtTop - procedure ListPtTop(Dest: TStrings); Interfaced Currently returns the last patient selected
ListSpecialtyAll - procedure ListSpecialtyAll(Dest: TStrings); Interfaced Lists all treating specialties: IEN^Treating Specialty Name
ListTeamAll - procedure ListTeamAll(Dest: TStrings); Interfaced Lists all patient care teams: IEN^Team Name
ListWardAll - procedure ListWardAll(Dest: TStrings); Interfaced Lists all active inpatient wards: IEN^Ward Name
LoadNotifications - procedure LoadNotifications(Dest: TStrings); Interfaced
Notifications calls
Notifications Calls
RenewAlert - procedure RenewAlert(XQAID: string); Interfaced Restores/renews an alert
ResetDfltSort - procedure ResetDfltSort; Interfaced -
SavePtListDflt - procedure SavePtListDflt(const x: string); Interfaced -
SelectPatient - procedure SelectPatient(const DFN: string; var PtSelect: TPtSelect); Interfaced
DFN*
 selects the patient (updates DISV, calls Pt Select actions) & returns key fields
  Pieces: NAME[1]^SEX[2]^DOB[3]^SSN[4]^LOCIEN[5]^LOCNAME[6]^ROOMBED[7]^CWAD[8]^SENSITIVE[9]^
          ADMITTIME[10]^CONVERTED[11]^SVCONN[12]^SC%[13]^ICN[14]^Age[15]^TreatSpec[16]
SetSortMethod - procedure SetSortMethod(Sort: string; Direction: string); Interfaced Sets alert sort method for user
UpdateExpiringFlaggedOIAlerts - procedure UpdateExpiringFlaggedOIAlerts(PatientDFN: string; FollowUp: integer); Interfaced -
UpdateExpiringMedAlerts - procedure UpdateExpiringMedAlerts(PatientDFN: string); Interfaced -
UpdateIndOrderAlerts - procedure UpdateIndOrderAlerts(); { Patient List calls } function DfltPtList: string; function DfltPtListSrc: Char; procedure SavePtListDflt(const x: string); procedure ListSpecialtyAll(Dest: TStrings); procedure ListTeamAll(Dest: TStrings); procedure ListWardAll(Dest: TStrings); procedure ListProviderTop(Dest: TStrings); function SubSetOfProviders(const StartFrom: string; Direction: Integer): TStrings; function SubSetOfCosigners(const StartFrom: string; Direction: Integer; Date: TFMDateTime; ATitle: integer; ADocType: integer): TStrings; procedure ListClinicTop(Dest: TStrings); function SubSetOfClinics(const StartFrom: string; Direction: Integer): TStrings; function GetDfltSort: string; procedure ResetDfltSort; procedure ListPtByDflt(Dest: TStrings); procedure ListPtByProvider(Dest: TStrings; ProviderIEN: Int64); procedure ListPtByTeam(Dest: TStrings; TeamIEN: Integer); procedure ListPtBySpecialty(Dest: TStrings; SpecialtyIEN: Integer); procedure ListPtByClinic(Dest: TStrings; ClinicIEN: Integer; FirstDt, LastDt: string); procedure ListPtByWard(Dest: TStrings; WardIEN: Integer); procedure ListPtByLast5(Dest: TStrings; const Last5: string); procedure ListPtByRPLLast5(Dest: TStrings; const Last5: string); procedure ListPtByFullSSN(Dest: TStrings; const FullSSN: string); procedure ListPtByRPLFullSSN(Dest: TStrings; const FullSSN: string); procedure ListPtTop(Dest: TStrings); function SubSetOfPatients(const StartFrom: string; Direction: Integer): TStrings; function DfltDateRangeClinic: string; function MakeRPLPtList(RPLList: string): string; function ReadRPLPtList(RPLJobNumber: string; const StartFrom: string; Direction: Integer) : TStrings; procedure KillRPLPtList(RPLJobNumber: string); { Patient specific calls } function CalcAge(BirthDate, DeathDate: TFMDateTime): Integer; procedure CheckSensitiveRecordAccess(const DFN: string; var AccessStatus: Integer; var MessageText: string); procedure CheckRemotePatient(var Dest: string; Patient, ASite: string; var AccessStatus: Integer); procedure CurrentLocationForPatient(const DFN: string; var ALocation: Integer; var AName: string; var ASvc: string); function DateOfDeath(const DFN: string): TFMDateTime; function GetPtIDInfo(const DFN: string): TPtIDInfo; function HasLegacyData(const DFN: string; var AMsg: string): Boolean; function LogSensitiveRecordAccess(const DFN: string): Boolean; function MeansTestRequired(const DFN: string; var AMsg: string): Boolean; function RestrictedPtRec(const DFN: string): Boolean; procedure SelectPatient(const DFN: string; var PtSelect: TPtSelect); function SimilarRecordsFound(const DFN: string; var AMsg: string): Boolean; function GetDFNFromICN(AnICN: string): string; { Encounter specific calls } function GetEncounterText(const DFN: string; Location: integer; Provider: Int64): TEncounterText; Interfaced
Patient List calls 
 Patient specific calls 
 Encounter specific calls 
 Remote Data Access calls 
 private calls 
 places the dashes in a social security number 
 Date/Time functions - not in ORFn because they make server calls to use server time
 return the current date in Fileman format 
 return the current date/time in Fileman format 
 use %DT the validate and convert a string to Fileman format (accepts T, T-1, NOW, etc.) 
 use %DT to validate & convert a string to Fileman format, accepts %DT flags 
 returns date ranges for displaying clinic appointments in patient lookup 
 returns current default date range settings for displaying clinic appointments in patient lookup 
 General calls 
 returns the external name of the IEN within a file 
 returns a pointer to a list of devices (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! 

 returns a pointer to a list of persons (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! 

  MixedCaseList(RPCBrokerV.Results);
 User specific calls 
 returns a record of user information,
  Pieces: DUZ^NAME^USRCLS^CANSIGN^ISPROVIDER^ORDERROLE^NOORDER^DTIME^CNTDN^VERORD^NOTIFYAPPS^
          MSGHANG^DOMAIN^SERVICE^AUTOSAVE^INITTAB^LASTTAB^WEBACCESS^ALLOWHOLD^ISRPL^RPLLIST^
          CORTABS^RPTTAB^STATION#^GECStatus^Production account?



 Remove next if and nested if should an "override" later be provided for RPL users,etc.:
 Following hard set to TRUE per VHA mgt decision:
    x := GetUserParam('ORWT TOOLS RPT SETTINGS OFF');
    if x = '1' then
      ToolsRptEdit := false;
 returns true if the currently logged in user has a given security key 
 returns true if the electronic signature code in ACode is valid 
 Notifications Calls 
UpdateUnsignedOrderAlerts(Patient.DFN);      //moved to AFTER signature and DC actions
UpdateUnsignedOrderAlerts - procedure UpdateUnsignedOrderAlerts(PatientDFN: string); Interfaced -
UpdateUnverifiedMedAlerts - procedure UpdateUnverifiedMedAlerts(PatientDFN: string); Interfaced -
UpdateUnverifiedOrderAlerts - procedure UpdateUnverifiedOrderAlerts(PatientDFN: string); Interfaced -

Functions

Name Owner Declaration Scope Comments
CalcAge - function CalcAge(BirthDate, DeathDate: TFMDateTime): Integer; Interfaced
Patient specific calls
Patient Specific Calls 

 calculates age based on today's date and a birthdate (in Fileman format)
CheckHL7TCPLink - function CheckHL7TCPLink: Boolean; Interfaced -
DateOfDeath - function DateOfDeath(const DFN: string): TFMDateTime; Interfaced Returns 0 or the date a patient died
DfltDateRangeClinic - function DfltDateRangeClinic: string; Interfaced Returns current default date range settings for displaying clinic appointments in patient lookup
DfltPtList - function DfltPtList: string; Interfaced
Patient List calls
Patient List Calls 

 returns the name of the current user's default patient list, null if none is defined
  Pieces: Ptr to Source File^Source Name^Source Type
DfltPtListSrc - function DfltPtListSrc: Char; Interfaced -
ExternalName - function ExternalName(IEN: Int64; FileNumber: Double): string; Interfaced
General calls
General calls 

 returns the external name of the IEN within a file
FMNow - function FMNow: TFMDateTime; Interfaced Return the current date/time in Fileman format
FMToday - function FMToday: TFMDateTime; Interfaced
Date/Time functions - right now these make server calls to use server time
Date/Time functions - not in ORFn because they make server calls to use server time

 return the current date in Fileman format
FormatSSN - function FormatSSN(const x: string): string; Global Private calls
GetActiveICDVersion - function GetActiveICDVersion(ADate: TFMDateTime = 0): String; Interfaced -
GetDefaultPrinter - function GetDefaultPrinter(DUZ: Int64; Location: integer): string; Interfaced -
GetDfltSort - function GetDfltSort: string; Interfaced Assigns uPtLstDfltSort to user's default patient list sort order (string character).
GetDFNFromICN - function GetDFNFromICN(AnICN: string): string; Interfaced -
GetEncounterText - function GetEncounterText(const DFN: string; Location: integer; Provider: Int64): TEncounterText; Interfaced
Encounter specific calls 

DFN*
Encounter specific calls 

DFN*
 returns resolved external values  Pieces: LOCNAME[1]^PROVNAME[2]^ROOMBED[3]
GetICD10ImplementationDate - function GetICD10ImplementationDate: TFMDateTime; Interfaced -
GetNotificationFollowUpText - function GetNotificationFollowUpText(PatientDFN: string; Notification: integer; XQADATA: string): TStrings; Interfaced Returns follow-up text for an alert
GetPtIDInfo - function GetPtIDInfo(const DFN: string): TPtIDInfo; Interfaced
DFN*
 returns the identifiers displayed upon patient selection
  Pieces: SSN[1]^DOB[2]^SEX[3]^VET[4]^SC%[5]^WARD[6]^RM-BED[7]^NAME[8]
GetSortMethod - function GetSortMethod: string; Interfaced Returns alert sort method
GetTIUAlertInfo - function GetTIUAlertInfo(XQAID: string): string; Interfaced Returns DFN and document type associated with a TIU alert
GetUserInfo - function GetUserInfo: TUserInfo; Interfaced
User specific calls
User specific calls 

 returns a record of user information,
  Pieces: DUZ^NAME^USRCLS^CANSIGN^ISPROVIDER^ORDERROLE^NOORDER^DTIME^CNTDN^VERORD^NOTIFYAPPS^
          MSGHANG^DOMAIN^SERVICE^AUTOSAVE^INITTAB^LASTTAB^WEBACCESS^ALLOWHOLD^ISRPL^RPLLIST^
          CORTABS^RPTTAB^STATION#^GECStatus^Production account?
GetUserParam - function GetUserParam(const AParamName: string): string; Interfaced -
GetVistaWebAddress - function GetVistaWebAddress(value: string): string; Interfaced -
GetXQAData - function GetXQAData(XQAID: string): string; Interfaced Returns data associated with an alert
GlobalRefForFile - function GlobalRefForFile(const FileID: string): string; Interfaced -
HasLegacyData - function HasLegacyData(const DFN: string; var AMsg: string): Boolean; Interfaced -
HasMenuOptionAccess - function HasMenuOptionAccess(const OptionName: string): Boolean; Interfaced -
HasRemoteData - function HasRemoteData(const DFN: string; var ALocations: TStringList): Boolean; Interfaced
Remote Data Access calls
Remote Data Access calls
HasSecurityKey - function HasSecurityKey(const KeyName: string): Boolean; Interfaced Returns true if the currently logged in user has a given security key
IsFMDate - function IsFMDate(const x: string): Boolean; Global -
IsSSN - function IsSSN(const x: string): Boolean; Global -
LogSensitiveRecordAccess - function LogSensitiveRecordAccess(const DFN: string): Boolean; Interfaced -
MakeRelativeDateTime - function MakeRelativeDateTime(FMDateTime: TFMDateTime): string; Interfaced -
MakeRPLPtList - function MakeRPLPtList(RPLList: string): string; Interfaced Creates "RPL" Restricted Patient List based on Team List info in user's record.
MeansTestRequired - function MeansTestRequired(const DFN: string; var AMsg: string): Boolean; Interfaced -
PersonHasKey - function PersonHasKey(APerson: Int64; const AKey: string): Boolean; Interfaced -
ReadRPLPtList - function ReadRPLPtList(RPLJobNumber: string; const StartFrom: string; Direction: Integer) : TStrings; Interfaced
Returns a pointer to a list of patients (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
RestrictedPtRec - function RestrictedPtRec(const DFN: string): Boolean; Interfaced
DFN*
 returns true if the record for a patient identified by DFN is restricted
SimilarRecordsFound - function SimilarRecordsFound(const DFN: string; var AMsg: string): Boolean; Interfaced -
StrToFMDateTime - function StrToFMDateTime(const AString: string): TFMDateTime; Interfaced Use %DT the validate and convert a string to Fileman format (accepts T, T-1, NOW, etc.)
SubSetOfActiveAndInactivePersons - function SubSetOfActiveAndInactivePersons(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of users (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfClinics - function SubSetOfClinics(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of clinics (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfCosigners - function SubSetOfCosigners(const StartFrom: string; Direction: Integer; Date: TFMDateTime; ATitle: integer; ADocType: integer): TStrings; Interfaced
Returns a pointer to a list of cosigners (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubsetOfDevices - function SubsetOfDevices(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of devices (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubsetOfGeneric - function SubsetOfGeneric(const StartFrom: string; Direction: Integer; const GlobalRef: string): TStrings; Interfaced -
SubSetOfInpatientLocations - function SubSetOfInpatientLocations(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of locations (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfLocations - function SubSetOfLocations(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of locations (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfNewLocs - function SubSetOfNewLocs(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of locations (for use in a long list box) -  the return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
  Filtered by C, W, and Z types - i.e., Clinics, Wards, and "Other" type locations.
SubSetOfPatients - function SubSetOfPatients(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of patients (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfPersons - function SubSetOfPersons(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of persons (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfProviders - function SubSetOfProviders(const StartFrom: string; Direction: Integer): TStrings; Interfaced
Returns a pointer to a list of providers (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfProvWithClass - function SubSetOfProvWithClass(const StartFrom: string; Direction: Integer; DateTime: string): TStrings; Interfaced
Returns a pointer to a list of providers (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
SubSetOfUsersWithClass - function SubSetOfUsersWithClass(const StartFrom: string; Direction: Integer; DateTime: string): TStrings; Interfaced
Returns a pointer to a list of users (for use in a long list box) -  The return value is
  a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
UnsignedOrderAlertFollowup - function UnsignedOrderAlertFollowup(XQAID: string): string; Interfaced -
ValidDateTimeStr - function ValidDateTimeStr(const AString, Flags: string): TFMDateTime; Interfaced Use %DT to validate & convert a string to Fileman format, accepts %DT flags
ValidESCode - function ValidESCode(const ACode: string): Boolean; Interfaced Returns true if the electronic signature code in ACode is valid

Global Variables

Name Type Declaration Comments
uPtListDfltSort UnicodeString uPtListDfltSort: string = ''; Current user's patient selection list default sort order.

Constants

Name Declaration Scope Comments
UC_CLERK 1 Interfaced User class clerk
UC_NURSE 2 Interfaced User class nurse
UC_PHYSICIAN 3 Interfaced User class physician
UC_UNKNOWN 0 Interfaced User class unknown


Module Source

1     unit rCore;
2     
3     interface
4     
5     uses SysUtils, Classes, Forms, ORNet, ORFn, ORClasses;
6     
7     { record types used to return data from the RPC's.  Generally, the delimited strings returned
8       by the RPC are mapped into the records defined below. }
9     
10    const
11      UC_UNKNOWN   = 0;                               // user class unknown
12      UC_CLERK     = 1;                               // user class clerk
13      UC_NURSE     = 2;                               // user class nurse
14      UC_PHYSICIAN = 3;                               // user class physician
15    
16    type
17      TUserInfo = record                              // record for ORWU USERINFO
18        DUZ: Int64;
19        Name: string;
20        UserClass: Integer;
21        CanSignOrders: Boolean;
22        IsProvider: Boolean;
23        OrderRole: Integer;
24        NoOrdering: Boolean;
25        DTIME: Integer;
26        CountDown: Integer;
27        EnableVerify: Boolean;
28        NotifyAppsWM: Boolean;
29        PtMsgHang: Integer;
30        Domain: string;
31        Service: Integer;
32        AutoSave: Integer;
33        InitialTab: Integer;
34        UseLastTab: Boolean;
35        WebAccess: Boolean;
36        IsRPL: string;
37        RPLList: string;
38        HasCorTabs: Boolean;
39        HasRptTab: Boolean;
40        IsReportsOnly: Boolean;
41        ToolsRptEdit: Boolean;
42        DisableHold: Boolean;
43        GECStatusCheck: Boolean;
44        StationNumber: string;
45        IsProductionAccount: boolean;
46      end;
47    
48      TPtIDInfo = record                              // record for ORWPT IDINFO
49        Name: string;
50        SSN: string;
51        DOB: string;
52        Age: string;
53        Sex: string;
54        SCSts: string;
55        Vet: string;
56        Location: string;
57        RoomBed: string;
58      end;
59    
60      TPtSelect = record                              // record for ORWPT SELECT
61        Name: string;
62        ICN: string;
63        SSN: string;
64        DOB: TFMDateTime;
65        Age: Integer;
66        Sex: Char;
67        LocationIEN: Integer;
68        Location: string;
69        WardService: string;
70        RoomBed: string;
71        SpecialtyIEN: Integer;
72        SpecialtySvc: string;
73        CWAD: string;
74        Restricted: Boolean;
75        AdmitTime: TFMDateTime;
76        ServiceConnected: Boolean;
77        SCPercent: Integer;
78        PrimaryTeam: string;
79        PrimaryProvider: string;
80        MHTC: string;
81        Attending: string;
82        Associate: string;
83        InProvider: string;
84      end;
85    
86      TEncounterText = record                         // record for ORWPT ENCTITL
87        LocationName: string;
88        LocationAbbr: string;
89        RoomBed: string;
90        ProviderName: string;
91      end;
92    
93    { Date/Time functions - right now these make server calls to use server time}
94    
95    function FMToday: TFMDateTime;
96    function FMNow: TFMDateTime;
97    function MakeRelativeDateTime(FMDateTime: TFMDateTime): string;
98    function StrToFMDateTime(const AString: string): TFMDateTime;
99    function ValidDateTimeStr(const AString, Flags: string): TFMDateTime;
100   procedure ListDateRangeClinic(Dest: TStrings);
101   
102   { General calls }
103   
104   function ExternalName(IEN: Int64; FileNumber: Double): string;
105   function PersonHasKey(APerson: Int64; const AKey: string): Boolean;
106   function GlobalRefForFile(const FileID: string): string;
107   function SubsetOfGeneric(const StartFrom: string; Direction: Integer; const GlobalRef: string): TStrings;
108   function SubsetOfDevices(const StartFrom: string; Direction: Integer): TStrings;
109   function SubSetOfPersons(const StartFrom: string; Direction: Integer): TStrings;
110   function SubSetOfActiveAndInactivePersons(const StartFrom: string; Direction: Integer): TStrings;
111   function GetDefaultPrinter(DUZ: Int64; Location: integer): string;
112   
113   { User specific calls }
114   
115   function GetUserInfo: TUserInfo;
116   function GetUserParam(const AParamName: string): string;
117   procedure GetUserListParam(Dest: TStrings; const AParamName: string);
118   function HasSecurityKey(const KeyName: string): Boolean;
119   function HasMenuOptionAccess(const OptionName: string): Boolean;
120   function ValidESCode(const ACode: string): Boolean;
121   
122   { Notifications calls }
123   
124   procedure LoadNotifications(Dest: TStrings);
125   procedure DeleteAlert(XQAID: string);
126   procedure DeleteAlertForUser(XQAID: string);
127   function  GetXQAData(XQAID: string): string;
128   function  GetTIUAlertInfo(XQAID: string): string;
129   procedure UpdateUnsignedOrderAlerts(PatientDFN: string);
130   function UnsignedOrderAlertFollowup(XQAID: string): string;
131   procedure UpdateExpiringMedAlerts(PatientDFN: string);
132   procedure UpdateExpiringFlaggedOIAlerts(PatientDFN: string; FollowUp: integer);
133   procedure AutoUnflagAlertedOrders(PatientDFN, XQAID: string);
134   procedure UpdateUnverifiedMedAlerts(PatientDFN: string);
135   procedure UpdateUnverifiedOrderAlerts(PatientDFN: string);
136   function GetNotificationFollowUpText(PatientDFN: string; Notification: integer; XQADATA: string): TStrings;
137   procedure ForwardAlert(XQAID: string; Recip: string; FWDtype: string; Comment: string);
138   procedure RenewAlert(XQAID: string);
139   function GetSortMethod: string;
140   procedure SetSortMethod(Sort: string; Direction: string);
141   procedure UpdateIndOrderAlerts();
142   
143   { Patient List calls }
144   
145   function DfltPtList: string;
146   function DfltPtListSrc: Char;
147   procedure SavePtListDflt(const x: string);
148   procedure ListSpecialtyAll(Dest: TStrings);
149   procedure ListTeamAll(Dest: TStrings);
150   procedure ListWardAll(Dest: TStrings);
151   procedure ListProviderTop(Dest: TStrings);
152   function SubSetOfProviders(const StartFrom: string; Direction: Integer): TStrings;
153   function SubSetOfCosigners(const StartFrom: string; Direction: Integer; Date: TFMDateTime;
154     ATitle: integer; ADocType: integer): TStrings;
155   procedure ListClinicTop(Dest: TStrings);
156   function SubSetOfClinics(const StartFrom: string; Direction: Integer): TStrings;
157   function GetDfltSort: string;
158   procedure ResetDfltSort;
159   procedure ListPtByDflt(Dest: TStrings);
160   procedure ListPtByProvider(Dest: TStrings; ProviderIEN: Int64);
161   procedure ListPtByTeam(Dest: TStrings; TeamIEN: Integer);
162   procedure ListPtBySpecialty(Dest: TStrings; SpecialtyIEN: Integer);
163   procedure ListPtByClinic(Dest: TStrings; ClinicIEN: Integer; FirstDt, LastDt: string);
164   procedure ListPtByWard(Dest: TStrings; WardIEN: Integer);
165   procedure ListPtByLast5(Dest: TStrings; const Last5: string);
166   procedure ListPtByRPLLast5(Dest: TStrings; const Last5: string);
167   procedure ListPtByFullSSN(Dest: TStrings; const FullSSN: string);
168   procedure ListPtByRPLFullSSN(Dest: TStrings; const FullSSN: string);
169   procedure ListPtTop(Dest: TStrings);
170   function SubSetOfPatients(const StartFrom: string; Direction: Integer): TStrings;
171   function DfltDateRangeClinic: string;
172   function MakeRPLPtList(RPLList: string): string;
173   function ReadRPLPtList(RPLJobNumber: string; const StartFrom: string; Direction: Integer) : TStrings;
174   procedure KillRPLPtList(RPLJobNumber: string);
175   
176   { Patient specific calls }
177   
178   function CalcAge(BirthDate, DeathDate: TFMDateTime): Integer;
179   procedure CheckSensitiveRecordAccess(const DFN: string; var AccessStatus: Integer;
180     var MessageText: string);
181   procedure CheckRemotePatient(var Dest: string; Patient, ASite: string; var AccessStatus: Integer);
182   procedure CurrentLocationForPatient(const DFN: string; var ALocation: Integer; var AName: string; var ASvc: string);
183   function DateOfDeath(const DFN: string): TFMDateTime;
184   function GetPtIDInfo(const DFN: string): TPtIDInfo;
185   function HasLegacyData(const DFN: string; var AMsg: string): Boolean;
186   function LogSensitiveRecordAccess(const DFN: string): Boolean;
187   function MeansTestRequired(const DFN: string; var AMsg: string): Boolean;
188   function RestrictedPtRec(const DFN: string): Boolean;
189   procedure SelectPatient(const DFN: string; var PtSelect: TPtSelect);
190   function SimilarRecordsFound(const DFN: string; var AMsg: string): Boolean;
191   function GetDFNFromICN(AnICN: string): string;
192   
193   { Encounter specific calls }
194   
195   function GetEncounterText(const DFN: string; Location: integer; Provider: Int64): TEncounterText;  //*DFN*
196   function GetActiveICDVersion(ADate: TFMDateTime = 0): String;
197   function GetICD10ImplementationDate: TFMDateTime;
198   procedure ListApptAll(Dest: TStrings; const DFN: string; From: TFMDateTime = 0;
199                                                            Thru: TFMDateTime = 0);
200   procedure ListAdmitAll(Dest: TStrings; const DFN: string);
201   function SubSetOfLocations(const StartFrom: string; Direction: Integer): TStrings;
202   function SubSetOfNewLocs(const StartFrom: string; Direction: Integer): TStrings;
203   function SubSetOfInpatientLocations(const StartFrom: string; Direction: Integer): TStrings;
204   function SubSetOfProvWithClass(const StartFrom: string; Direction: Integer; DateTime: string): TStrings;
205   function SubSetOfUsersWithClass(const StartFrom: string; Direction: Integer; DateTime: string): TStrings;
206   
207   { Remote Data Access calls }
208   function HasRemoteData(const DFN: string; var ALocations: TStringList): Boolean;
209   function CheckHL7TCPLink: Boolean;
210   function GetVistaWebAddress(value: string): string;
211   
212   implementation
213   
214   uses Hash, uCore, ShlObj, Windows;
215   
216   var
217     uPtListDfltSort: string = '';                  // Current user's patient selection list default sort order.
218   
219   { private calls }
220   
221   function FormatSSN(const x: string): string;
222   { places the dashes in a social security number }
223   begin
224     if Length(x) > 8
225       then Result := Copy(x,1,3) + '-' + Copy(x,4,2) + '-' + Copy(x,6,Length(x))
226       else Result := x;
227   end;
228   
229   function IsSSN(const x: string): Boolean;
230   var
231     i: Integer;
232   begin
233     Result := False;
234     if (Length(x) < 9) or (Length(x) > 10) then Exit;
235     for i := 1 to 9 do if not CharInSet(x[i], ['0'..'9']) then Exit;
236     Result := True;
237   end;
238   
239   function IsFMDate(const x: string): Boolean;
240   var
241     i: Integer;
242   begin
243     Result := False;
244     if Length(x) <> 7 then Exit;
245     for i := 1 to 7 do if not CharInSet(x[i], ['0'..'9']) then Exit;
246     Result := True;
247   end;
248   
249   { Date/Time functions - not in ORFn because they make server calls to use server time}
250   
251   function FMToday: TFMDateTime;
252   { return the current date in Fileman format }
253   begin
254     Result := Int(FMNow);
255   end;
256   
257   function FMNow: TFMDateTime;
258   { return the current date/time in Fileman format }
259   var
260     x: string;
261   begin
262     x := sCallV('ORWU DT', ['NOW']);
263     Result := StrToFloatDef(x, 0.0);
264   end;
265   
266   function MakeRelativeDateTime(FMDateTime: TFMDateTime): string;
267   var
268     Offset: Integer;
269     h,n,s,l: Word;
270     ADateTime: TDateTime;
271     ATime: string;
272   begin
273     Result := '';
274     if FMDateTime <= 0 then Exit;
275     ADateTime := FMDateTimeToDateTime(FMDateTime);
276     Offset := Trunc(Int(ADateTime) - Int(FMDateTimeToDateTime(FMToday)));
277     if Offset < 0 then Result := 'T' + IntToStr(Offset)
278     else if Offset = 0 then Result := 'T'
279     else Result := 'T+' + IntToStr(Offset);
280     DecodeTime(ADateTime, h, n, s, l);
281     ATime := Format('@%.2d:%.2d', [h, n]);
282     if ATime <> '@00:00' then Result := Result + ATime;
283   end;
284   
285   function StrToFMDateTime(const AString: string): TFMDateTime;
286   { use %DT the validate and convert a string to Fileman format (accepts T, T-1, NOW, etc.) }
287   var
288     x: string;
289   begin
290     x := sCallV('ORWU DT', [AString]);
291     Result := StrToFloat(x);
292   end;
293   
294   function ValidDateTimeStr(const AString, Flags: string): TFMDateTime;
295   { use %DT to validate & convert a string to Fileman format, accepts %DT flags }
296   begin
297     Result := StrToFloat(sCallV('ORWU VALDT', [AString, Flags]));
298   end;
299   
300   procedure ListDateRangeClinic(Dest: TStrings);
301   { returns date ranges for displaying clinic appointments in patient lookup }
302   begin
303     CallV('ORWPT CLINRNG', [nil]);
304     FastAssign(RPCBrokerV.Results, Dest);
305   end;
306   
307   function DfltDateRangeClinic;
308   { returns current default date range settings for displaying clinic appointments in patient lookup }
309   begin
310     Result := sCallV('ORQPT DEFAULT CLINIC DATE RANG', [nil]);
311   end;
312   
313   { General calls }
314   
315   function ExternalName(IEN: Int64; FileNumber: Double): string;
316   { returns the external name of the IEN within a file }
317   begin
318     Result := sCallV('ORWU EXTNAME', [IEN, FileNumber]);
319   end;
320   
321   function PersonHasKey(APerson: Int64; const AKey: string): Boolean;
322   begin
323     Result := sCallV('ORWU NPHASKEY', [APerson, AKey]) = '1';
324   end;
325   
326   function GlobalRefForFile(const FileID: string): string;
327   begin
328     Result := sCallV('ORWU GBLREF', [FileID]);
329   end;
330   
331   function SubsetOfGeneric(const StartFrom: string; Direction: Integer; const GlobalRef: string): TStrings;
332   begin
333     CallV('ORWU GENERIC', [StartFrom, Direction, GlobalRef]);
334     Result := RPCBrokerV.Results;
335   end;
336   
337   function SubsetOfDevices(const StartFrom: string; Direction: Integer): TStrings;
338   { returns a pointer to a list of devices (for use in a long list box) -  The return value is
339     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
340   begin
341     CallV('ORWU DEVICE', [StartFrom, Direction]);
342     Result := RPCBrokerV.Results;
343   end;
344   
345   function SubSetOfPersons(const StartFrom: string; Direction: Integer): TStrings;
346   { returns a pointer to a list of persons (for use in a long list box) -  The return value is
347     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
348   begin
349     CallV('ORWU NEWPERS', [StartFrom, Direction]);
350   //  MixedCaseList(RPCBrokerV.Results);
351     Result := RPCBrokerV.Results;
352   end;
353   
354   { User specific calls }
355   
356   function GetUserInfo: TUserInfo;
357   { returns a record of user information,
358     Pieces: DUZ^NAME^USRCLS^CANSIGN^ISPROVIDER^ORDERROLE^NOORDER^DTIME^CNTDN^VERORD^NOTIFYAPPS^
359             MSGHANG^DOMAIN^SERVICE^AUTOSAVE^INITTAB^LASTTAB^WEBACCESS^ALLOWHOLD^ISRPL^RPLLIST^
360             CORTABS^RPTTAB^STATION#^GECStatus^Production account?}
361   var
362     x: string;
363   begin
364     x := sCallV('ORWU USERINFO', [nil]);
365     with Result do
366     begin
367       DUZ := StrToInt64Def(Piece(x, U, 1), 0);
368       Name := Piece(x, U, 2);
369       UserClass := StrToIntDef(Piece(x, U, 3), 0);
370       CanSignOrders := Piece(x, U, 4) = '1';
371       IsProvider := Piece(x, U, 5) = '1';
372       OrderRole := StrToIntDef(Piece(x, U, 6), 0);
373       NoOrdering := Piece(x, U, 7) = '1';
374       DTIME := StrToIntDef(Piece(x, U, 8), 300);
375       CountDown := StrToIntDef(Piece(x, U, 9), 10);
376       EnableVerify := Piece(x, U, 10) = '1';
377       NotifyAppsWM := Piece(x, U, 11) = '1';
378       PtMsgHang := StrToIntDef(Piece(x, U, 12), 5);
379       Domain := Piece(x, U, 13);
380       Service := StrToIntDef(Piece(x, U, 14), 0);
381       AutoSave := StrToIntDef(Piece(x, U, 15), 180);
382       InitialTab := StrToIntDef(Piece(x, U, 16), 1);
383       UseLastTab := Piece(x, U, 17) = '1';
384       WebAccess := Piece(x, U, 18) <> '1';
385       DisableHold := Piece(x, U, 19) = '1';
386       IsRPL := Piece(x, U, 20);
387       RPLList := Piece(x, U, 21);
388       HasCorTabs := Piece(x, U, 22) = '1';
389       HasRptTab := Piece(x, U, 23) = '1';
390       StationNumber := Piece(x, U, 24);
391       GECStatusCheck := Piece(x, U, 25) = '1';
392       IsProductionAccount := Piece(x, U, 26) = '1';
393       IsReportsOnly := false;
394       if ((HasRptTab) and (not HasCorTabs)) then
395         IsReportsOnly := true;
396       // Remove next if and nested if should an "override" later be provided for RPL users,etc.:
397       if HasCorTabs then
398         if (IsRPL = '1') then
399           begin
400             IsRPL := '0'; // Hard set for now.
401             IsReportsOnly := false;
402           end;
403       // Following hard set to TRUE per VHA mgt decision:
404       ToolsRptEdit := true;
405        //    x := GetUserParam('ORWT TOOLS RPT SETTINGS OFF');
406        //    if x = '1' then
407       //      ToolsRptEdit := false;
408     end;
409   end;
410   
411   function GetUserParam(const AParamName: string): string;
412   begin
413     Result := sCallV('ORWU PARAM', [AParamName]);
414   end;
415   
416   procedure GetUserListParam(Dest: TStrings; const AParamName: string);
417   var
418     tmplst: TStringList;
419   begin
420     tmplst := TStringList.Create;
421     try
422       tCallV(tmplst, 'ORWU PARAMS', [AParamName]);
423       FastAssign(tmplst, Dest);
424     finally
425       tmplst.Free;
426     end;
427   end;
428   
429   function HasSecurityKey(const KeyName: string): Boolean;
430   { returns true if the currently logged in user has a given security key }
431   var
432     x: string;
433   begin
434     Result := False;
435     x := sCallV('ORWU HASKEY', [KeyName]);
436     if x = '1' then Result := True;
437   end;
438   
439   function HasMenuOptionAccess(const OptionName: string): Boolean;
440   begin
441     Result := (sCallV('ORWU HAS OPTION ACCESS', [OptionName]) = '1');
442   end;
443   
444   function ValidESCode(const ACode: string): Boolean;
445   { returns true if the electronic signature code in ACode is valid }
446   begin
447     Result := sCallV('ORWU VALIDSIG', [Encrypt(ACode)]) = '1';
448   end;
449   
450   { Notifications Calls }
451   
452   procedure LoadNotifications(Dest: TStrings);
453   var
454     tmplst: TStringList;
455   begin
456     tmplst := TStringList.Create;
457     try
458       //UpdateUnsignedOrderAlerts(Patient.DFN);      //moved to AFTER signature and DC actions
459       tCallV(tmplst, 'ORWORB FASTUSER', [nil]);
460       FastAssign(tmplst, Dest);
461     finally
462       tmplst.Free;
463     end;
464   end;
465   
466   procedure UpdateUnsignedOrderAlerts(PatientDFN: string);
467   begin
468     CallV('ORWORB KILL UNSIG ORDERS ALERT',[PatientDFN]);
469   end;
470   
471   function UnsignedOrderAlertFollowup(XQAID: string): string;
472   begin
473     Result := sCallV('ORWORB UNSIG ORDERS FOLLOWUP',[XQAID]);
474   end;
475   
476   procedure UpdateIndOrderAlerts();
477   begin
478     if Notifications.IndOrderDisplay then
479     begin
480       Notifications.IndOrderDisplay := False;
481       Notifications.Delete;
482     end;
483   end;
484   
485   procedure UpdateExpiringMedAlerts(PatientDFN: string);
486   begin
487     CallV('ORWORB KILL EXPIR MED ALERT',[PatientDFN]);
488   end;
489   
490   procedure UpdateExpiringFlaggedOIAlerts(PatientDFN: string; FollowUp: integer);
491   begin
492     CallV('ORWORB KILL EXPIR OI ALERT',[PatientDFN, FollowUp]);
493   end;
494   
495   procedure UpdateUnverifiedMedAlerts(PatientDFN: string);
496   begin
497     CallV('ORWORB KILL UNVER MEDS ALERT',[PatientDFN]);
498   end;
499   
500   procedure UpdateUnverifiedOrderAlerts(PatientDFN: string);
501   begin
502     CallV('ORWORB KILL UNVER ORDERS ALERT',[PatientDFN]);
503   end;
504   
505   procedure AutoUnflagAlertedOrders(PatientDFN, XQAID: string);
506   begin
507     CallV('ORWORB AUTOUNFLAG ORDERS',[PatientDFN, XQAID]);
508   end;
509   
510   procedure DeleteAlert(XQAID: string);
511   //deletes an alert
512   begin
513     CallV('ORB DELETE ALERT',[XQAID]);
514   end;
515   
516   procedure DeleteAlertForUser(XQAID: string);
517   //deletes an alert
518   begin
519     CallV('ORB DELETE ALERT',[XQAID, True]);
520   end;
521   
522   procedure ForwardAlert(XQAID: string; Recip: string; FWDtype: string; Comment: string);
523   // Forwards an alert with comment to Recip[ient]
524   begin
525      CallV('ORB FORWARD ALERT', [XQAID, Recip, FWDtype, Comment]);
526   end;
527   
528   procedure RenewAlert(XQAID: string);
529   // Restores/renews an alert
530   begin
531      CallV('ORB RENEW ALERT', [XQAID]);
532   end;
533   
534   function GetSortMethod: string;
535   // Returns alert sort method
536   begin
537     Result := sCallV('ORWORB GETSORT',[nil]);
538   end;
539   
540   procedure SetSortMethod(Sort: string; Direction: string);
541   // Sets alert sort method for user
542   begin
543      CallV('ORWORB SETSORT', [Sort, Direction]);
544   end;
545   
546   function GetXQAData(XQAID: string): string;
547   // Returns data associated with an alert
548   begin
549     Result := sCallV('ORWORB GETDATA',[XQAID]);
550   end;
551   
552   function  GetTIUAlertInfo(XQAID: string): string;
553   // Returns DFN and document type associated with a TIU alert
554   begin
555     Result := sCallV('TIU GET ALERT INFO',[XQAID]);
556   end;
557   
558   function GetNotificationFollowUpText(PatientDFN: string; Notification: integer; XQADATA: string): TStrings;
559   // Returns follow-up text for an alert
560   begin
561      CallV('ORWORB TEXT FOLLOWUP', [PatientDFN, Notification, XQADATA]);
562      Result := RPCBrokerV.Results;
563   end;
564   
565   { Patient List Calls }
566   
567   function DfltPtList: string;
568   { returns the name of the current user's default patient list, null if none is defined
569     Pieces: Ptr to Source File^Source Name^Source Type }
570   begin
571     Result := sCallV('ORQPT DEFAULT LIST SOURCE', [nil]);
572     if Length(Result) > 0 then Result := Pieces(Result, U, 2, 3);
573   end;
574   
575   function DfltPtListSrc: Char;
576   begin
577     Result := CharAt(sCallV('ORWPT DFLTSRC', [nil]), 1);
578   end;
579   
580   procedure SavePtListDflt(const x: string);
581   begin
582     CallV('ORWPT SAVDFLT', [x]);
583   end;
584   
585   procedure ListSpecialtyAll(Dest: TStrings);
586   { lists all treating specialties: IEN^Treating Specialty Name }
587   begin
588     CallV('ORQPT SPECIALTIES', [nil]);
589     MixedCaseList(RPCBrokerV.Results);
590     FastAssign(RPCBrokerV.Results, Dest);
591   end;
592   
593   procedure ListTeamAll(Dest: TStrings);
594   { lists all patient care teams: IEN^Team Name }
595   begin
596     CallV('ORQPT TEAMS', [nil]);
597     MixedCaseList(RPCBrokerV.Results);
598     FastAssign(RPCBrokerV.Results, Dest);
599   end;
600   
601   procedure ListWardAll(Dest: TStrings);
602   { lists all active inpatient wards: IEN^Ward Name }
603   begin
604     CallV('ORQPT WARDS', [nil]);
605     //MixedCaseList(RPCBrokerV.Results);
606     FastAssign(RPCBrokerV.Results, Dest);
607   end;
608   
609   procedure ListProviderTop(Dest: TStrings);
610   { checks parameters for list of commonly selected providers }
611   begin
612   end;
613   
614   function SubSetOfProviders(const StartFrom: string; Direction: Integer): TStrings;
615   { returns a pointer to a list of providers (for use in a long list box) -  The return value is
616     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
617   begin
618     CallV('ORWU NEWPERS', [StartFrom, Direction, 'PROVIDER']);
619   //  MixedCaseList(RPCBrokerV.Results);
620     Result := RPCBrokerV.Results;
621   end;
622   
623   function SubSetOfCosigners(const StartFrom: string; Direction: Integer; Date: TFMDateTime;
624     ATitle: integer; ADocType: integer): TStrings;
625   { returns a pointer to a list of cosigners (for use in a long list box) -  The return value is
626     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
627   begin
628     if ATitle > 0 then ADocType := 0;
629     // CQ #17218 - Correcting order of parameters for this call - jcs
630     //CallV('ORWU2 COSIGNER', [StartFrom, Direction, Date, ATitle, ADocType]);
631     CallV('ORWU2 COSIGNER', [StartFrom, Direction, Date, ADocType, ATitle]);
632   
633     //  MixedCaseList(RPCBrokerV.Results);
634     Result := RPCBrokerV.Results;
635   end;
636   
637   function SubSetOfProvWithClass(const StartFrom: string; Direction: Integer; DateTime: string): TStrings;
638   { returns a pointer to a list of providers (for use in a long list box) -  The return value is
639     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
640   begin
641     CallV('ORWU NEWPERS', [StartFrom, Direction, 'PROVIDER', DateTime]);
642     MixedCaseList(RPCBrokerV.Results);
643     Result := RPCBrokerV.Results;
644   end;
645   
646   function SubSetOfUsersWithClass(const StartFrom: string; Direction: Integer; DateTime: string): TStrings;
647   { returns a pointer to a list of users (for use in a long list box) -  The return value is
648     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
649   begin
650     CallV('ORWU NEWPERS', [StartFrom, Direction, '', DateTime]);
651     MixedCaseList(RPCBrokerV.Results);
652     Result := RPCBrokerV.Results;
653   end;
654   
655   function SubSetOfActiveAndInactivePersons(const StartFrom: string; Direction: Integer): TStrings;
656   { returns a pointer to a list of users (for use in a long list box) -  The return value is
657     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!}
658   begin
659     CallV('ORWU NEWPERS', [StartFrom, Direction, '', '', '', True]);  //TRUE = return all active and inactive users
660     MixedCaseList(RPCBrokerV.Results);
661     Result := RPCBrokerV.Results;
662   end;
663   
664   
665   procedure ListClinicTop(Dest: TStrings);
666   { checks parameters for list of commonly selected clinics }
667   begin
668   end;
669   
670   function SubSetOfClinics(const StartFrom: string; Direction: Integer): TStrings;
671   { returns a pointer to a list of clinics (for use in a long list box) -  The return value is
672     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
673   begin
674     CallV('ORWU CLINLOC', [StartFrom, Direction]);
675     MixedCaseList(RPCBrokerV.Results);
676     Result := RPCBrokerV.Results;
677   end;
678   
679   function GetDfltSort: string;
680   { Assigns uPtLstDfltSort to user's default patient list sort order (string character).}
681   begin
682     uPtListDfltSort := sCallV('ORQPT DEFAULT LIST SORT', [nil]);
683     if uPtListDfltSort = '' then uPtListDfltSort := 'A'; // Default is always "A" for alpha.
684     result := uPtListDfltSort;
685   end;
686   
687   procedure ResetDfltSort;
688   begin
689     uPtListDfltSort := '';
690   end;
691   
692   procedure ListPtByDflt(Dest: TStrings);
693   { loads the default patient list into Dest, Pieces: DFN^PATIENT NAME, ETC. }
694   var
695     i, SourceType: Integer;
696     ATime, APlace, Sort, Source, x: string;
697     tmplst: TORStringList;
698   begin
699     Sort := GetDfltSort();
700     tmplst := TORStringList.Create;
701     try
702       tCallV(tmplst, 'ORQPT DEFAULT PATIENT LIST', [nil]);
703       Source := sCallV('ORWPT DFLTSRC', [nil]);
704       if Source = 'C' then                    // Clinics.
705       begin
706         if Sort = 'P' then                    // "Appointments" sort.
707           SortByPiece(tmplst, U, 4)
708         else
709           SortByPiece(tmplst, U, 2);
710         for i := 0 to tmplst.Count - 1 do
711         begin
712           x := tmplst[i];
713           ATime := Piece(x, U, 4);
714           APlace := Piece(x, U, 3);
715           ATime := FormatFMDateTime('hh:nn  mmm dd, yyyy', MakeFMDateTime(ATime));
716           SetPiece(x, U, 3, ATime);
717           x := x + U + APlace;
718           tmplst[i] := x;
719         end;
720       end
721       else
722       begin
723         SourceType := 0;                      // Default.
724         if Source = 'M' then SourceType := 1; // Combinations.
725         if Source = 'W' then SourceType := 2; // Wards.
726         case SourceType of
727           1 : if Sort = 'S' then tmplst.SortByPieces([3, 8, 2]) // "Source" sort.
728               else if Sort = 'P' then tmplst.SortByPieces([8, 2]) // "Appointment" sort.
729                    else if Sort = 'T' then SortByPiece(tmplst, U, 5) // "Terminal Digit" sort.
730                         else SortByPiece(tmplst, U, 2); // "Alphabetical" (also the default) sort.
731           2 : if Sort = 'R' then tmplst.SortByPieces([3, 2])
732               else SortByPiece(tmplst, U, 2);
733         else SortByPiece(tmplst, U, 2);
734         end;
735       end;
736       MixedCaseList(tmplst);
737       FastAssign(tmplst, Dest);
738     finally
739       tmplst.Free;
740     end;
741   end;
742   
743   procedure ListPtByProvider(Dest: TStrings; ProviderIEN: Int64);
744   { lists all patients associated with a given provider: DFN^Patient Name }
745   begin
746     CallV('ORQPT PROVIDER PATIENTS', [ProviderIEN]);
747     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
748     MixedCaseList(RPCBrokerV.Results);
749     FastAssign(RPCBrokerV.Results, Dest);
750   end;
751   
752   procedure ListPtByTeam(Dest: TStrings; TeamIEN: Integer);
753   { lists all patients associated with a given team: DFN^Patient Name }
754   begin
755     CallV('ORQPT TEAM PATIENTS', [TeamIEN]);
756     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
757     MixedCaseList(RPCBrokerV.Results);
758     FastAssign(RPCBrokerV.Results, Dest);
759   end;
760   
761   procedure ListPtBySpecialty(Dest: TStrings; SpecialtyIEN: Integer);
762   { lists all patients associated with a given specialty: DFN^Patient Name }
763   begin
764     CallV('ORQPT SPECIALTY PATIENTS', [SpecialtyIEN]);
765     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
766     MixedCaseList(RPCBrokerV.Results);
767     FastAssign(RPCBrokerV.Results, Dest);
768   end;
769   
770   procedure ListPtByClinic(Dest: TStrings; ClinicIEN: Integer; FirstDt, LastDt: string); //TFMDateTime);
771   { lists all patients associated with a given clinic: DFN^Patient Name^App't }
772   var
773     i: Integer;
774     x, ATime, APlace, Sort: string;
775   begin
776     Sort := GetDfltSort();
777     CallV('ORQPT CLINIC PATIENTS', [ClinicIEN, FirstDt, LastDt]);
778     with RPCBrokerV do
779     begin
780       if Sort = 'P' then
781         SortByPiece(TStringList(Results), U, 4)
782       else
783         SortByPiece(TStringList(Results), U, 2);
784       for i := 0 to Results.Count - 1 do
785       begin
786         x := Results[i];
787         ATime := Piece(x, U, 4);
788         APlace := Piece(x, U, 3);
789         ATime := FormatFMDateTime('hh:nn  mmm dd, yyyy', MakeFMDateTime(ATime));
790         SetPiece(x, U, 3, ATime);
791         x := x + U + APlace;
792         Results[i] := x;
793       end;
794       MixedCaseList(Results);
795       FastAssign(Results, Dest);
796     end;
797   end;
798   
799   procedure ListPtByWard(Dest: TStrings; WardIEN: Integer);
800   { lists all patients associated with a given ward: DFN^Patient Name^Room/Bed }
801   var
802     Sort: string;
803   begin
804     Sort := GetDfltSort();
805     CallV('ORWPT BYWARD', [WardIEN]);
806     if Sort = 'R' then
807       SortByPiece(TStringList(RPCBrokerV.Results), U, 3)
808     else
809       SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
810     MixedCaseList(RPCBrokerV.Results);
811     FastAssign(RPCBrokerV.Results, Dest);
812   end;
813   
814   procedure ListPtByLast5(Dest: TStrings; const Last5: string);
815   var
816     i: Integer;
817     x, ADate, AnSSN: string;
818   begin
819   { Lists all patients found in the BS and BS5 xrefs that match Last5: DFN^Patient Name }
820     CallV('ORWPT LAST5', [UpperCase(Last5)]);
821     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
822     with RPCBrokerV do for i := 0 to Results.Count - 1 do
823     begin
824       x := Results[i];
825       ADate := Piece(x, U, 3);
826       AnSSN := Piece(x, U, 4);
827       if IsFMDate(ADate) then ADate := FormatFMDateTimeStr('mmm d, yyyy', ADate);
828       if IsSSN(AnSSN)    then AnSSN := FormatSSN(AnSSN);
829       SetPiece(x, U, 3, AnSSN + '   ' + ADate);
830       Results[i] := x;
831     end;
832     MixedCaseList(RPCBrokerV.Results);
833     FastAssign(RPCBrokerV.Results, Dest);
834   end;
835   
836   procedure ListPtByRPLLast5(Dest: TStrings; const Last5: string);
837   var
838     i: Integer;
839     x, ADate, AnSSN: string;
840   begin
841   { Lists patients from RPL list that match Last5: DFN^Patient Name }
842     CallV('ORWPT LAST5 RPL', [UpperCase(Last5)]);
843     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
844     with RPCBrokerV do for i := 0 to Results.Count - 1 do
845     begin
846       x := Results[i];
847       ADate := Piece(x, U, 3);
848       AnSSN := Piece(x, U, 4);
849       if IsFMDate(ADate) then ADate := FormatFMDateTimeStr('mmm d, yyyy', ADate);
850       if IsSSN(AnSSN)    then AnSSN := FormatSSN(AnSSN);
851       SetPiece(x, U, 3, AnSSN + '   ' + ADate);
852       Results[i] := x;
853     end;
854     MixedCaseList(RPCBrokerV.Results);
855     FastAssign(RPCBrokerV.Results, Dest);
856   end;
857   
858   procedure ListPtByFullSSN(Dest: TStrings; const FullSSN: string);
859   { lists all patients found in the SSN xref that match FullSSN: DFN^Patient Name }
860   var
861     i: integer;
862     x, ADate, AnSSN: string;
863   begin
864     x := FullSSN;
865     i := Pos('-', x);
866     while i > 0 do
867     begin
868       x := Copy(x, 1, i-1) + Copy(x, i+1, 12);
869       i := Pos('-', x);
870     end;
871     CallV('ORWPT FULLSSN', [UpperCase(x)]);
872     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
873     with RPCBrokerV do for i := 0 to Results.Count - 1 do
874     begin
875       x := Results[i];
876       ADate := Piece(x, U, 3);
877       AnSSN := Piece(x, U, 4);
878       if IsFMDate(ADate) then ADate := FormatFMDateTimeStr('mmm d, yyyy', ADate);
879       if IsSSN(AnSSN)    then AnSSN := FormatSSN(AnSSN);
880       SetPiece(x, U, 3, AnSSN + '   ' + ADate);
881       Results[i] := x;
882     end;
883     MixedCaseList(RPCBrokerV.Results);
884     FastAssign(RPCBrokerV.Results, Dest);
885   end;
886   
887   procedure ListPtByRPLFullSSN(Dest: TStrings; const FullSSN: string);
888   { lists all patients found in the SSN xref that match FullSSN: DFN^Patient Name }
889   var
890     i: integer;
891     x, ADate, AnSSN: string;
892   begin
893     x := FullSSN;
894     i := Pos('-', x);
895     while i > 0 do
896     begin
897       x := Copy(x, 1, i-1) + Copy(x, i+1, 12);
898       i := Pos('-', x);
899     end;
900     CallV('ORWPT FULLSSN RPL', [UpperCase(x)]);
901     SortByPiece(TStringList(RPCBrokerV.Results), U, 2);
902     with RPCBrokerV do for i := 0 to Results.Count - 1 do
903     begin
904       x := Results[i];
905       ADate := Piece(x, U, 3);
906       AnSSN := Piece(x, U, 4);
907       if IsFMDate(ADate) then ADate := FormatFMDateTimeStr('mmm d, yyyy', ADate);
908       if IsSSN(AnSSN)    then AnSSN := FormatSSN(AnSSN);
909       SetPiece(x, U, 3, AnSSN + '   ' + ADate);
910       Results[i] := x;
911     end;
912     MixedCaseList(RPCBrokerV.Results);
913     FastAssign(RPCBrokerV.Results, Dest);
914   end;
915   
916   procedure ListPtTop(Dest: TStrings);
917   { currently returns the last patient selected }
918   begin
919     CallV('ORWPT TOP', [nil]);
920     MixedCaseList(RPCBrokerV.Results);
921     FastAssign(RPCBrokerV.Results, Dest);
922   end;
923   
924   function SubSetOfPatients(const StartFrom: string; Direction: Integer): TStrings;
925   { returns a pointer to a list of patients (for use in a long list box) -  The return value is
926     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
927   begin
928     CallV('ORWPT LIST ALL', [StartFrom, Direction]);
929     MixedCaseList(RPCBrokerV.Results);
930     Result := RPCBrokerV.Results;
931   end;
932   
933   function MakeRPLPtList(RPLList: string): string;
934   { Creates "RPL" Restricted Patient List based on Team List info in user's record. }
935   begin
936     result := sCallV('ORQPT MAKE RPL', [RPLList]);
937   end;
938   
939   function ReadRPLPtList(RPLJobNumber: string; const StartFrom: string; Direction: Integer) : TStrings;
940   { returns a pointer to a list of patients (for use in a long list box) -  The return value is
941     a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
942   begin
943     CallV('ORQPT READ RPL', [RPLJobNumber, StartFrom, Direction]);
944     MixedCaseList(RPCBrokerV.Results);
945     Result := RPCBrokerV.Results;
946   end;
947   
948   procedure KillRPLPtList(RPLJobNumber: string);
949   begin
950     CallV('ORQPT KILL RPL', [RPLJobNumber]);
951   end;
952   
953   { Patient Specific Calls }
954   
955   function CalcAge(BirthDate, DeathDate: TFMDateTime): Integer;
956   { calculates age based on today's date and a birthdate (in Fileman format) }
957   begin
958     if (DeathDate > BirthDate) then
959       Result := Trunc(DeathDate - BirthDate) div 10000
960     else
961       Result := Trunc(FMToday - BirthDate) div 10000
962   end;
963   
964   procedure CheckSensitiveRecordAccess(const DFN: string; var AccessStatus: Integer;
965     var MessageText: string);
966   begin
967     CallV('DG SENSITIVE RECORD ACCESS', [DFN]);
968     AccessStatus := -1;
969     MessageText := '';
970     with RPCBrokerV do
971     begin
972       if Results.Count > 0 then
973       begin
974         AccessStatus := StrToIntDef(Results[0], -1);
975         Results.Delete(0);
976         if Results.Count > 0 then MessageText := Results.Text;
977       end;
978     end;
979   end;
980   
981   procedure CheckRemotePatient(var Dest: string; Patient, ASite: string; var AccessStatus: Integer);
982   
983   begin
984     CallV('XWB DIRECT RPC', [ASite, 'ORWCIRN RESTRICT', 0, Patient]);
985     AccessStatus := -1;
986     Dest := '';
987     with RPCBrokerV do
988     begin
989       if Results.Count > 0 then
990         begin
991           if Results[0] = '' then Results.Delete(0);
992         end;
993       if Results.Count > 0 then
994         begin
995           if (length(piece(Results[0],'^',2)) > 0) and ((StrToIntDef(piece(Results[0],'^',1),0) = -1)) then
996             begin
997               AccessStatus := -1;
998               Dest := piece(Results[0],'^',2);
999             end
1000          else
1001            begin
1002              AccessStatus := StrToIntDef(Results[0], -1);
1003              Results.Delete(0);
1004              if Results.Count > 0 then Dest := Results.Text;
1005            end;
1006        end;
1007    end;
1008  end;
1009  
1010  procedure CurrentLocationForPatient(const DFN: string; var ALocation: Integer; var AName: string; var ASvc: string);
1011  var
1012    x: string;
1013  begin
1014    x := sCallV('ORWPT INPLOC', [DFN]);
1015    ALocation := StrToIntDef(Piece(x, U, 1), 0);
1016    AName := Piece(x, U, 2);
1017    ASvc := Piece(x, U, 3);
1018  end;
1019  
1020  function DateOfDeath(const DFN: string): TFMDateTime;
1021  { returns 0 or the date a patient died }
1022  begin
1023    Result := MakeFMDateTime(sCallV('ORWPT DIEDON', [DFN]));
1024  end;
1025  
1026  function GetPtIDInfo(const DFN: string): TPtIDInfo;  //*DFN*
1027  { returns the identifiers displayed upon patient selection
1028    Pieces: SSN[1]^DOB[2]^SEX[3]^VET[4]^SC%[5]^WARD[6]^RM-BED[7]^NAME[8] }
1029  var
1030    x: string;
1031  begin
1032    x := sCallV('ORWPT ID INFO', [DFN]);
1033    with Result do                                    // map string into TPtIDInfo record
1034    begin
1035      Name := MixedCase(Piece(x, U, 8));                                  // Name
1036      SSN  := Piece(x, U, 1);
1037      DOB  := Piece(x, U, 2);
1038      Age  := '';
1039      if IsSSN(SSN)    then SSN := FormatSSN(Piece(x, U, 1));                // SSN (PID)
1040      if IsFMDate(DOB) then DOB := FormatFMDateTimeStr('mmm dd,yyyy', DOB);  // Date of Birth
1041      //Age := IntToStr(CalcAge(MakeFMDateTime(Piece(x, U, 2))));            // Age
1042      Sex := Piece(x, U, 3);                                                 // Sex
1043      if Length(Sex) = 0 then Sex := 'U';
1044      case Sex[1] of
1045      'F','f': Sex := 'Female';
1046      'M','m': Sex := 'Male';
1047      else     Sex := 'Unknown';
1048      end;
1049      if Piece(x, U, 4) = 'Y' then Vet := 'Veteran' else Vet := '';       // Veteran?
1050      if Length(Piece(x, U, 5)) > 0                                       // % Service Connected
1051        then SCSts := Piece(x, U, 5) + '% Service Connected'
1052        else SCSts := '';
1053      Location := Piece(x, U, 6);                                         // Inpatient Location
1054      RoomBed  := Piece(x, U, 7);                                         // Inpatient Room-Bed
1055    end;
1056  end;
1057  
1058  function HasLegacyData(const DFN: string; var AMsg: string): Boolean;
1059  var
1060    i: Integer;
1061  begin
1062    Result := False;
1063    AMsg := '';
1064    CallV('ORWPT LEGACY', [DFN]);
1065    with RPCBrokerV do if Results.Count > 0 then
1066    begin
1067      Result := Results[0] = '1';
1068      for i := 1 to Results.Count - 1 do AMsg := AMsg + Results[i] + CRLF;
1069    end;
1070  end;
1071  
1072  function LogSensitiveRecordAccess(const DFN: string): Boolean;
1073  begin
1074    Result := sCallV('DG SENSITIVE RECORD BULLETIN', [DFN]) = '1';
1075  end;
1076  
1077  function MeansTestRequired(const DFN: string; var AMsg: string): Boolean;
1078  var
1079    i: Integer;
1080  begin
1081    Result := False;
1082    AMsg := '';
1083    CallV('DG CHK PAT/DIV MEANS TEST', [DFN]);
1084    with RPCBrokerV do if Results.Count > 0 then
1085    begin
1086      Result := Results[0] = '1';
1087      for i := 1 to Results.Count - 1 do AMsg := AMsg + Results[i] + CRLF;
1088    end;
1089  end;
1090  
1091  function RestrictedPtRec(const DFN: string): Boolean;  //*DFN*
1092  { returns true if the record for a patient identified by DFN is restricted }
1093  begin
1094    Result := Piece(sCallV('ORWPT SELCHK', [DFN]), U, 1) = '1';
1095  end;
1096  
1097  procedure SelectPatient(const DFN: string; var PtSelect: TPtSelect);   //*DFN*
1098  { selects the patient (updates DISV, calls Pt Select actions) & returns key fields
1099    Pieces: NAME[1]^SEX[2]^DOB[3]^SSN[4]^LOCIEN[5]^LOCNAME[6]^ROOMBED[7]^CWAD[8]^SENSITIVE[9]^
1100            ADMITTIME[10]^CONVERTED[11]^SVCONN[12]^SC%[13]^ICN[14]^Age[15]^TreatSpec[16] }
1101  var
1102    x: string;
1103  begin
1104    x := sCallV('ORWPT SELECT', [DFN]);
1105    with PtSelect do
1106    begin
1107      Name := Piece(x, U, 1);
1108      ICN := Piece(x, U, 14);
1109      SSN := FormatSSN(Piece(x, U, 4));
1110      DOB := MakeFMDateTime(Piece(x, U, 3));
1111      Age := StrToIntDef(Piece(x, U, 15), 0);
1112      //Age := CalcAge(DOB, DateOfDeath(DFN));
1113      if Length(Piece(x, U, 2)) > 0 then Sex := Piece(x, U, 2)[1] else Sex := 'U';
1114      LocationIEN := StrToIntDef(Piece(x, U, 5), 0);
1115      Location := Piece(x, U, 6);
1116      RoomBed := Piece(x, U, 7);
1117      SpecialtyIEN := StrToIntDef(Piece(x, U, 16), 0);
1118      SpecialtySvc := Piece(x, U, 17);
1119      CWAD := Piece(x, U, 8);
1120      Restricted := Piece(x, U, 9) = '1';
1121      AdmitTime := MakeFMDateTime(Piece(x, U, 10));
1122      ServiceConnected := Piece(x, U, 12) = '1';
1123      SCPercent := StrToIntDef(Piece(x, U, 13), 0);
1124    end;
1125    x := sCallV('ORWPT1 PRCARE', [DFN]);
1126    with PtSelect do
1127    begin
1128      PrimaryTeam     := Piece(x, U, 1);
1129      PrimaryProvider := Piece(x, U, 2);
1130      Associate := Piece(x, U, 4);
1131      MHTC := Piece(x, U, 5);
1132      if Length(Location) > 0 then
1133        begin
1134          Attending := Piece(x, U, 3);
1135          InProvider := Piece(x, U, 6);
1136          x := sCallV('ORWPT INPLOC', [DFN]);
1137          WardService := Piece(x, U, 3);
1138        end;
1139    end;
1140  end;
1141  
1142  function SimilarRecordsFound(const DFN: string; var AMsg: string): Boolean;
1143  begin
1144    Result := False;
1145    AMsg := '';
1146    CallV('DG CHK BS5 XREF Y/N', [DFN]);
1147    with RPCBrokerV do if Results.Count > 0 then
1148    begin
1149      Result := Results[0] = '1';
1150      Results.Delete(0);
1151      AMsg := Results.Text;
1152    end;
1153    (*
1154    CallV('DG CHK BS5 XREF ARRAY', [DFN]);
1155    with RPCBrokerV do if Results.Count > 0 then
1156    begin
1157      Result := Results[0] = '1';
1158      for i := 1 to Results.Count - 1 do
1159      begin
1160        if Piece(Results[i], U, 1) = '0' then AMsg := AMsg + Copy(Results[i], 3, Length(Results[i])) + CRLF;
1161        if Piece(Results[i], U, 1) = '1' then AMsg := AMsg + Piece(Results[i], U, 3) + #9 +
1162          FormatFMDateTimeStr('mmm dd,yyyy', Piece(Results[i], U, 4)) + #9 + Piece(Results[i], U, 5) + CRLF;
1163      end;
1164    end;
1165    *)
1166  end;
1167  
1168  function GetDFNFromICN(AnICN: string): string;
1169  begin
1170    Result := Piece(sCallV('VAFCTFU CONVERT ICN TO DFN', [AnICN]), U, 1);
1171  end;
1172  
1173  { Encounter specific calls }
1174  
1175  function GetEncounterText(const DFN: string; Location: integer; Provider: Int64): TEncounterText;  //*DFN*
1176  { returns resolved external values  Pieces: LOCNAME[1]^PROVNAME[2]^ROOMBED[3] }
1177  var
1178    x: string;
1179  begin
1180    x := sCallV('ORWPT ENCTITL', [DFN, Location, Provider]);
1181    with Result do
1182    begin
1183      LocationName := Piece(x, U, 1);
1184      LocationAbbr := Piece(x, U, 2);
1185      RoomBed      := Piece(x, U, 3);
1186      ProviderName := Piece(x, U, 4);    
1187  //    ProviderName := sCallV('ORWU1 NAMECVT', [Provider]);
1188   end;
1189  end;
1190  
1191  function  GetActiveICDVersion(ADate: TFMDateTime = 0): String;
1192  begin
1193    Result := sCallV('ORWPCE ICDVER', [ADate]);
1194  end;
1195  
1196  function GetICD10ImplementationDate: TFMDateTime;
1197  var
1198    impDt: String;
1199  begin
1200    impDt := sCallV('ORWPCE I10IMPDT', [nil]);
1201    if impDt <> '' then
1202      Result := StrToFMDateTime(impDt)
1203    else
1204      Result := 3141001;  //Default to 10/01/2014
1205  end;
1206  
1207  procedure ListApptAll(Dest: TStrings; const DFN: string; From: TFMDateTime = 0;
1208                                                           Thru: TFMDateTime = 0);
1209  { lists appts/visits for a patient (uses same call as cover sheet)
1210    V|A;DateTime;LocIEN^DateTime^LocName^Status }
1211  const
1212    SKIP_ADMITS = 1;
1213  begin
1214    CallV('ORWCV VST', [Patient.DFN, From, Thru, SKIP_ADMITS]);
1215    with RPCBrokerV do
1216    begin
1217      InvertStringList(TStringList(Results));
1218      MixedCaseList(Results);
1219      SetListFMDateTime('mmm dd,yyyy hh:nn', TStringList(Results), U, 2);
1220      FastAssign(Results, Dest);
1221    end;
1222    (*
1223    CallV('ORWPT APPTLST', [DFN]);
1224    with RPCBrokerV do
1225    begin
1226      SortByPiece(TStringList(Results), U, 1);
1227      InvertStringList(TStringList(Results));
1228      for i := 0 to Results.Count - 1 do
1229      begin
1230        x := Results[i];
1231        ATime := Piece(x, U, 1);
1232        ATime := FormatFMDateTime('mmm dd, yyyy hh:nn', MakeFMDateTime(ATime));
1233        SetPiece(x, U, 5, ATime);
1234        Results[i] := x;
1235      end;
1236      FastAssign(Results, Dest);
1237    end;
1238    *)
1239  end;
1240  
1241  procedure ListAdmitAll(Dest: TStrings; const DFN: string);  //*DFN*
1242  { lists all admissions for a patient: MovementTime^LocIEN^LocName^Type }
1243  var
1244    i: Integer;
1245    ATime, x: string;
1246  begin
1247    CallV('ORWPT ADMITLST', [DFN]);
1248    with RPCBrokerV do
1249    begin
1250      for i := 0 to Results.Count - 1 do
1251      begin
1252        x := Results[i];
1253        ATime := Piece(x, U, 1);
1254        ATime := FormatFMDateTime('mmm dd, yyyy hh:nn', MakeFMDateTime(ATime));
1255        SetPiece(x, U, 5, ATime);
1256        Results[i] := x;
1257      end;
1258      FastAssign(Results, Dest);
1259    end;
1260  end;
1261  
1262  function SubSetOfLocations(const StartFrom: string; Direction: Integer): TStrings;
1263  { returns a pointer to a list of locations (for use in a long list box) -  The return value is
1264    a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
1265  begin
1266    CallV('ORWU HOSPLOC', [StartFrom, Direction]);
1267    Result := RPCBrokerV.Results;
1268  end;
1269  
1270  function SubSetOfNewLocs(const StartFrom: string; Direction: Integer): TStrings;
1271  { Returns a pointer to a list of locations (for use in a long list box) -  the return value is
1272    a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call!
1273    Filtered by C, W, and Z types - i.e., Clinics, Wards, and "Other" type locations.}
1274  begin
1275    CallV('ORWU1 NEWLOC', [StartFrom, Direction]);
1276    Result := RPCBrokerV.Results;
1277  end;
1278  
1279  function SubSetOfInpatientLocations(const StartFrom: string; Direction: Integer): TStrings;
1280  { returns a pointer to a list of locations (for use in a long list box) -  The return value is
1281    a pointer to RPCBrokerV.Results, so the data must be used BEFORE the next broker call! }
1282  begin
1283    CallV('ORWU INPLOC', [StartFrom, Direction]);
1284    Result := RPCBrokerV.Results;
1285  end;
1286  
1287  { Remote Data Access calls }
1288  
1289  function HasRemoteData(const DFN: string; var ALocations: TStringList): Boolean;
1290  begin
1291    CallV('ORWCIRN FACLIST', [DFN]);
1292    FastAssign(RPCBrokerV.Results, ALocations);
1293    Result := not (Piece(RPCBrokerV.Results[0], U, 1) = '-1');
1294  
1295  //   '-1^NO DFN'
1296  //   '-1^PATIENT NOT IN DATABASE'
1297  //   '-1^NO MPI Node'
1298  //   '-1^NO ICN'
1299  //   '-1^Parameter missing.'
1300  //   '-1^No patient DFN.'
1301  //   '-1^Could not find Treating Facilities'
1302  //   '-1^Remote access not allowed'     <===parameter ORWCIRN REMOTE DATA ALLOW
1303  end;
1304  
1305  function CheckHL7TCPLink: Boolean;
1306   begin
1307     CallV('ORWCIRN CHECKLINK',[nil]);
1308     Result := RPCBrokerV.Results[0] = '1';
1309   end;
1310  
1311  function GetVistaWebAddress(value: string): string;
1312  begin
1313    CallV('ORWCIRN WEBADDR', [value]);
1314    result := RPCBrokerV.Results[0];
1315  end;
1316  
1317  function GetDefaultPrinter(DUZ: Int64; Location: integer): string;
1318  begin
1319    Result := sCallV('ORWRP GET DEFAULT PRINTER', [DUZ, Location]) ;
1320  end;
1321  
1322  end.

Module Calls (2 levels)


rCore
 └uCore
   ├rCore...
   ├uConst
   ├uCombatVet
   ├rTIU
   ├rOrders
   ├rConsults
   └uOrders

Module Called-By (2 levels)


                          rCore
                      rOrders┤ 
                      fPage┤ │ 
                      uCore┤ │ 
                    uOrders┤ │ 
                    fODBase┤ │ 
                    rODBase┤ │ 
                 UBAGlobals┤ │ 
                    UBACore┤ │ 
                     fFrame┤ │ 
                    fOrders┤ │ 
                  fOCAccept┤ │ 
               fOCMonograph┤ │ 
                    uODBase┤ │ 
          fBALocalDiagnoses┤ │ 
                     fCover┤ │ 
                fOrdersSign┤ │ 
                      fMeds┤ │ 
                   fProbEdt┤ │ 
                  fConsults┤ │ 
            fReminderDialog┤ │ 
                      fLabs┤ │ 
                    fReview┤ │ 
               fCSRemaining┤ │ 
                 uSignItems┤ │ 
                  fODDietLT┤ │ 
                    rODDiet┤ │ 
               fOrdersPrint┤ │ 
              fDefaultEvent┤ │ 
               fOrdersRenew┤ │ 
                    fODDiet┤ │ 
                   fOrderVw┤ │ 
                  fOrdersDC┤ │ 
                  fOrdersCV┤ │ 
                     fODGen┤ │ 
                   fODMedIn┤ │ 
                  fODMedOut┤ │ 
                fConsultAct┤ │ 
                     fODRad┤ │ 
                     fODLab┤ │ 
                   fODBBank┤ │ 
                    fODMeds┤ │ 
                    fODAuto┤ │ 
                    fOMNavA┤ │ 
            fOrderSaveQuick┤ │ 
                     fOMSet┤ │ 
                fOrdersHold┤ │ 
              fOrdersUnhold┤ │ 
               fOrdersAlert┤ │ 
                 fOrderFlag┤ │ 
               fOrderUnflag┤ │ 
             fOrdersRelease┤ │ 
                    fOMHTML┤ │ 
                  fODMedNVA┤ │ 
   fODChangeUnreleasedRenew┤ │ 
             fOrdersOnChart┤ │ 
         fOrdersEvntRelease┤ │ 
            fOrdersComplete┤ │ 
              fOrdersVerify┤ │ 
              fOrderComment┤ │ 
            fODReleaseEvent┤ │ 
                 fOCSession┤ │ 
                  fOrdersTS┤ │ 
                 mEvntDelay┤ │ 
                  fODActive┤ │ 
                fOrdersCopy┤ │ 
                   fMedCopy┤ │ 
        fActivateDeactivate┤ │ 
              fOrdersRefill┤ │ 
           fODChangeEvtDisp┤ │ 
               fRenewOutMed┘ │ 
                     uCore...┤ 
                         rTIU┤ 
                   uCore...┤ │ 
                       uPCE┤ │ 
                     fNotes┤ │ 
               fConsults...┤ │ 
                    fDCSumm┤ │ 
                    rDCSumm┤ │ 
                   fSurgery┤ │ 
               fAddlSigners┤ │ 
                 fNoteProps┤ │ 
                   fNotePrt┤ │ 
                    fNoteDR┤ │ 
               fDCSummProps┤ │ 
             fNoteIDParents┤ │ 
                  fNoteCslt┤ │ 
             fRemCoverSheet┤ │ 
              fOptionsNotes┤ │ 
             fOptionsTitles┘ │ 
                    rConsults┤ 
                   uCore...┤ │ 
                 uOrders...┤ │ 
                 fODBase...┤ │ 
                  fNotes...┤ │ 
                   uDocTree┤ │ 
             fConsult513Prt┤ │ 
               fConsults...┤ │ 
            fTemplateEditor┤ │ 
                 fODConsult┤ │ 
                 fConsultBS┤ │ 
                fConsultBSt┤ │ 
              fConsultsView┤ │ 
             fConsultAct...┤ │ 
                    fODProc┤ │ 
              fNoteProps...┤ │ 
                  fEditProc┤ │ 
               fEditConsult┤ │ 
               fConsMedRslt┤ │ 
                 fODAuto...┤ │ 
          fOptionsTitles...┘ │ 
                   uOrders...┤ 
                   fODBase...┤ 
                UBAGlobals...┤ 
                   UBACore...┤ 
                    fFrame...┤ 
                   fOrders...┤ 
                   uTemplates┤ 
                 fODBase...┤ │ 
                    dShared┤ │ 
                   fDrawers┤ │ 
            fTemplateDialog┤ │ 
                  fNotes...┤ │ 
               fConsults...┤ │ 
                 fDCSumm...┤ │ 
         fTemplateEditor...┤ │ 
         fReminderDialog...┤ │ 
                fSurgery...┤ │ 
              fODConsult...┤ │ 
                 fODProc...┤ │ 
                 fODAuto...┤ │ 
          fFindingTemplates┤ │ 
           fTemplateObjects┤ │ 
           fTemplateAutoGen┘ │ 
              uTemplateFields┤ 
                 uOrders...┤ │ 
                 dShared...┤ │ 
              uTemplates...┤ │ 
         fTemplateDialog...┤ │ 
                 uReminders┤ │ 
         fReminderDialog...┤ │ 
       fTemplateFieldEditor┤ │ 
            fTemplateFields┤ │ 
                 fODAuto...┘ │ 
                uReminders...┤ 
                      uPCE...┤ 
         fBALocalDiagnoses...┤ 
                         rPCE┤ 
                 uOrders...┤ │ 
              uReminders...┤ │ 
                    uPCE...┤ │ 
       fBALocalDiagnoses...┤ │ 
                    fPCELex┤ │ 
            fEncounterFrame┤ │ 
                 fVisitType┤ │ 
              mVisitRelated┤ │ 
                 fDiagnoses┤ │ 
               fPCEBaseMain┤ │ 
                 fProcedure┤ │ 
                  fPCEOther┤ │ 
              fImmunization┤ │ 
                  fSkinTest┤ │ 
                 fPatientEd┤ │ 
              fHealthFactor┤ │ 
                      fExam┤ │ 
                 fEncVitals┤ │ 
                 mCoPayDesc┤ │ 
                  fNotes...┤ │ 
                     fEncnt┤ │ 
                     fProbs┤ │ 
                fProbEdt...┤ │ 
                   fProbLex┤ │ 
               fConsults...┤ │ 
                 fDCSumm...┤ │ 
         fReminderDialog...┤ │ 
        fBAOptionsDiagnoses┤ │ 
                fSurgery...┤ │ 
              fODConsult...┤ │ 
                 fODProc...┤ │ 
            fAddlSigners...┤ │ 
            fDCSummProps...┤ │ 
               fEditProc...┤ │ 
            fEditConsult...┤ │ 
                       fGAF┤ │ 
                  fHFSearch┘ │ 
           fEncounterFrame...┤ 
                fVisitType...┤ 
                fProcedure...┤ 
                      uVitals┤ 
                  fFrame...┤ │ 
              uReminders...┤ │ 
                    uPCE...┤ │ 
              fEncVitals...┤ │ 
                    fVitals┤ │ 
         fReminderDialog...┤ │ 
                       fvit┘ │ 
                       uProbs┤ 
                 fPCELex...┤ │ 
              fDiagnoses...┤ │ 
                  fProbs...┤ │ 
                fProbEdt...┤ │ 
                   fProbflt┤ │ 
                fProbLex...┤ │ 
              fProbFreetext┘ │ 
                   fVitals...┤ 
                       fPtSel┤ 
                  fFrame...┤ │ 
                fPtSelOptns┤ │ 
                    fDupPts┘ │ 
               fOrdersSign...┤ 
               fPrintLocation┤ 
                  fFrame...┤ │ 
             fOrdersSign...┤ │ 
                 fReview...┘ │ 
                    fARTAllgy┤ 
                 uOrders...┤ │ 
                  fCover...┤ │ 
                  fAllgyBox┘ │ 
                   rODAllergy┤ 
                 uOrders...┤ │ 
                  fFrame...┤ │ 
                  fCover...┤ │ 
               fAllgyBox...┤ │ 
               fARTAllgy...┤ │ 
                 fAllgyFind┤ │ 
                   fODAllgy┘ │ 
                    fNotes...┤ 
                  uDocTree...┤ 
            fConsult513Prt...┤ 
                     rReports┤ 
                  fFrame...┤ │ 
                 fVitals...┤ │ 
                    fRptBox┤ │ 
          fConsult513Prt...┤ │ 
                   fReports┤ │ 
              fReportsPrint┤ │ 
    fReportsAdhocComponent1┤ │ 
      fReportsAdhocSubItem1┤ │ 
              fDeviceSelect┤ │ 
                   fLabs...┤ │ 
                  fLabPrint┤ │ 
                    fPtDemo┤ │ 
                fNotePrt...┤ │ 
                    fPreReq┘ │ 
                  fReports...┤ 
                         rECS┤ 
                  fFrame...┤ │ 
                fReports...┤ │ 
           fReportsPrint...┘ │ 
                       fVisit┤ 
                     rOptions┤ 
                     fVisit┤ │ 
                  fEncnt...┤ │ 
                   fOptions┤ │ 
               fOptionsDays┤ │ 
          fOptionsReminders┤ │ 
          fOptionsSurrogate┤ │ 
   fOptionsPatientSelection┤ │ 
              fOptionsLists┤ │ 
            fOptionsNewList┤ │ 
              fOptionsTeams┤ │ 
       fOptionsCombinations┤ │ 
              fOptionsOther┤ │ 
           fOptionsNotes...┤ │ 
          fOptionsTitles...┤ │ 
      fOptionsReportsCustom┤ │ 
     fOptionsReportsDefault┘ │ 
                    fEncnt...┤ 
                    fProbs...┤ 
                  fProbEdt...┤ 
                  fProbflt...┤ 
                  fProbLex...┤ 
                     fProbCmt┤ 
                  fProbs...┤ │ 
                fProbEdt...┘ │ 
             fReportsPrint...┤ 
                      fGraphs┤ 
                  fFrame...┤ │ 
                fReports...┘ │ 
               fGraphProfiles┤ 
                 fGraphs...┤ │ 
                fOptions...┘ │ 
                 fConsults...┤ 
                 fPCEProvider┤ 
                    uPCE...┤ │ 
         fEncounterFrame...┘ │ 
             fDeviceSelect...┤ 
                   fDCSumm...┤ 
                   rDCSumm...┤ 
                       uSpell┤ 
                  fFrame...┤ │ 
                  fNotes...┤ │ 
               fConsults...┤ │ 
                 fDCSumm...┤ │ 
         fTemplateEditor...┤ │ 
               fSpellNotify┤ │ 
                fSurgery...┤ │ 
    fTemplateFieldEditor...┘ │ 
           fReminderDialog...┤ 
                     fLabs...┤ 
                 fLabPrint...┤ 
                   fReview...┤ 
              fClinicWardMeds┤ 
                 fOrders...┤ │ 
          fOrdersRelease...┤ │ 
          fOrdersOnChart...┘ │ 
                   rReminders┤ 
              uReminders...┤ │ 
                  fCover...┤ │ 
         fReminderDialog...┤ │ 
                    fMHTest┤ │ 
              fReminderTree┤ │ 
          fRemCoverSheet...┤ │ 
       fOptionsReminders...┘ │ 
       fBAOptionsDiagnoses...┤ 
                 fODDietLT...┤ 
                   rODDiet...┤ 
                  fSurgery...┤ 
                 fSurgeryView┤ 
                fSurgery...┘ │ 
                     rSurgery┤ 
                  fFrame...┤ │ 
                  fNotes...┤ │ 
                fSurgery...┤ │ 
            fSurgeryView...┤ │ 
                  uCaseTree┤ │ 
              fNoteProps...┤ │ 
           fOptionsOther...┘ │ 
               fPtSelOptns...┤ 
                  fPtSelDemog┤ 
                  fPtSel...┘ │ 
                fAlertForward┤ 
                  fFrame...┤ │ 
                  fPtSel...┘ │ 
              fOrdersRenew...┤ 
                   fODDiet...┤ 
                fLkUpLocation┤ 
                 uOrders...┤ │ 
                 fOrders...┤ │ 
                  fODRad...┘ │ 
                    fODGen...┤ 
                      fODText┤ 
                 uOrders...┘ │ 
                fODConsult...┤ 
                   fConsultBD┤ 
               fConsults...┘ │ 
                    fSignItem┤ 
                  fNotes...┤ │ 
               fConsults...┤ │ 
                 fDCSumm...┤ │ 
                 fReview...┤ │ 
                fSurgery...┤ │ 
          fOrdersRelease...┘ │ 
             fConsultsView...┤ 
               fConsultAct...┤ 
                   fODProc...┤ 
              fAddlSigners...┤ 
                fNoteProps...┤ 
                      fNoteBA┤ 
                  fNotes...┤ │ 
                 fDCSumm...┘ │ 
                      fNoteBD┤ 
                  fNotes...┤ │ 
                 fDCSumm...┘ │ 
                  fNotePrt...┤ 
                     fTIUView┤ 
                  fNotes...┤ │ 
                 fDCSumm...┘ │ 
              fDCSummProps...┤ 
                 fEditProc...┤ 
              fEditConsult...┤ 
              fConsMedRslt...┤ 
              fConsultAlertTo┤ 
             fConsultAct...┤ │ 
            fConsMedRslt...┘ │ 
                fNoteCPFields┤ 
               fConsults...┘ │ 
                    fODRad...┤ 
                    fODLab...┤ 
                  fODBBank...┤ 
                   fODMeds...┤ 
                     fODMedIV┤ 
                 uOrders...┘ │ 
              fOrdersAlert...┤ 
                fOrderFlag...┤ 
                 fODMedNVA...┤ 
           fOrdersComplete...┤ 
             fOrdersVerify...┤ 
                  fMedCopy...┤ 
                      fGAF...┤ 
            fRemCoverSheet...┤ 
                     fPCEEdit┤ 
                  fNotes...┤ │ 
                fSurgery...┘ │ 
         fOptionsSurrogate...┤ 
                     uOptions┤ 
                fOptions...┤ │ 
            fOptionsDays...┤ │ 
       fOptionsSurrogate...┤ │ 
fOptionsPatientSelection...┤ │ 
           fOptionsLists...┤ │ 
           fOptionsTeams...┘ │ 
  fOptionsPatientSelection...┤ 
             fOptionsLists...┤ 
             fOptionsTeams...┤ 
      fOptionsCombinations...┤ 
             fOptionsOther...┤ 
     fOptionsReportsCustom...┤ 
    fOptionsReportsDefault...┤ 
                      fvit...┤ 
                     fODAllgy┘