source: cprs/trunk/CPRS-Chart/rCore.pas@ 792

Last change on this file since 792 was 456, checked in by Kevin Toppenberg, 16 years ago

Initial Upload of Official WV CPRS 1.0.26.76

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