source: cprs/branches/foia-cprs/CPRS-Chart/Consults/rConsults.pas@ 459

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

Adding foia-cprs branch

File size: 30.0 KB
Line 
1unit rConsults;
2
3interface
4
5uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, TRPCB, dialogs, uConsults, rTIU, uTIU;
6
7{Consult Titles }
8function DfltConsultTitle: integer;
9function DfltConsultTitleName: string;
10function DfltClinProcTitle: integer;
11function DfltClinProcTitleName: string;
12function IdentifyConsultsClass: integer;
13function IdentifyClinProcClass: integer;
14procedure ListConsultTitlesShort(Dest: TStrings);
15procedure ListClinProcTitlesShort(Dest: TStrings);
16function SubSetOfConsultTitles(const StartFrom: string; Direction: Integer; IDNoteTitlesOnly: boolean): TStrings;
17function SubSetOfClinProcTitles(const StartFrom: string; Direction: Integer; IDNoteTitlesOnly: boolean): TStrings;
18procedure ResetConsultTitles;
19procedure ResetClinProcTitles;
20
21{ Data Retrieval }
22procedure GetConsultsList(Dest: TStrings; Early, Late: double;
23 Service, Status: string; SortAscending: Boolean);
24procedure LoadConsultDetail(Dest: TStrings; IEN: integer) ;
25function GetCurrentContext: TSelectContext;
26procedure SaveCurrentContext(AContext: TSelectContext) ;
27procedure DisplayResults(Dest: TStrings; IEN: integer) ;
28procedure GetConsultRec(IEN: integer) ;
29function ShowSF513(ConsultIEN: integer): TStrings ;
30procedure PrintSF513ToDevice(AConsult: Integer; const ADevice: string; ChartCopy: string;
31 var ErrMsg: string);
32function GetFormattedSF513(AConsult: Integer; ChartCopy: string): TStrings;
33function UnresolvedConsultsExist: boolean;
34
35{list box fillers}
36function SubSetOfStatus: TStrings;
37function SubSetOfUrgencies(ConsultIEN: integer): TStrings;
38function LoadServiceList(Purpose: integer): TStrings ;
39function LoadServiceListWithSynonyms(Purpose: integer): TStrings ; overload;
40function LoadServiceListWithSynonyms(Purpose, ConsultIEN: integer): TStrings ; overload;
41function SubSetOfServices(const StartFrom: string; Direction: Integer): TStrings;
42function FindConsult(ConsultIEN: integer): string ;
43
44{user access level functions}
45function ConsultServiceUser(ServiceIEN: integer; DUZ: int64): boolean ;
46function GetActionMenuLevel(ConsultIEN: integer): TMenuAccessRec ;
47
48{consult result functions}
49function GetAssignableMedResults(ConsultIEN: integer): TStrings;
50function GetRemovableMedResults(ConsultIEN: integer): TStrings;
51function GetDetailedMedicineResults(ResultID: string): TStrings;
52procedure AttachMedicineResult(ConsultIEN: integer; ResultID: string; DateTime: TFMDateTime; ResponsiblePerson: int64; AlertTo: string);
53procedure RemoveMedicineResult(ConsultIEN: integer; ResultID: string; DateTime: TFMDateTime; ResponsiblePerson: int64);
54
55{Consult Request Actions}
56procedure ReceiveConsult(Dest: TStrings; IEN: integer; ReceivedBy: int64; RcptDate: TFMDateTime; Comments: TStrings);
57procedure ScheduleConsult(Dest: TStrings; IEN: integer; ScheduledBy: Int64; SchdDate: TFMDateTime; Alert: integer;
58 AlertTo: string; Comments: TStrings);
59procedure DiscontinueConsult(Dest: TStrings; IEN: integer; DiscontinuedBy: int64;
60 DiscontinueDate: TFMDateTime; Comments: TStrings);
61procedure DenyConsult(Dest: TStrings; IEN: integer; DeniedBy: int64;
62 DenialDate: TFMDateTime; Comments: TStrings);
63procedure ForwardConsult(Dest: TStrings; IEN, ToService: integer; Forwarder, AttentionOf: int64;
64 Urgency: integer; ActionDate: TFMDateTime; Comments: TStrings);
65procedure AddComment(Dest: TStrings; IEN: integer; Comments: TStrings; ActionDate: TFMDateTime; Alert: integer;
66 AlertTo: string) ;
67procedure SigFindings(Dest: TStrings; IEN: integer; SigFindingsFlag: string; Comments: TStrings; ActionDate: TFMDateTime;Alert: integer;
68 AlertTo: string) ;
69procedure AdminComplete(Dest: TStrings; IEN: integer; SigFindingsFlag: string; Comments: TStrings;
70 RespProv: Int64; ActionDate: TFMDateTime; Alert: integer; AlertTo: string) ;
71
72 { Consults Ordering Calls }
73function ODForConsults: TStrings;
74function ODForProcedures: TStrings;
75function ConsultMessage(AnIEN: Integer): string;
76function LoadConsultsQuickList: TStrings ;
77function GetProcedureServices(ProcIEN: integer): TStrings;
78function ConsultCanBeResubmitted(ConsultIEN: integer): string;
79function LoadConsultForEdit(ConsultIEN: integer): TEditResubmitRec;
80function ResubmitConsult(EditResubmitRec: TEditResubmitRec): string;
81function SubSetOfProcedures(const StartFrom: string; Direction: Integer): TStrings;
82function GetDefaultReasonForRequest(Service: string; Resolve: Boolean): TStrings;
83function ReasonForRequestEditable(Service: string): string;
84function GetNewDialog(OrderType: string): string;
85function GetServiceIEN(ORIEN: string): string;
86function GetProcedureIEN(ORIEN: string): string;
87function GetConsultOrderIEN(ConsultIEN: integer): string;
88function GetServicePrerequisites(Service: string): TStrings;
89procedure GetProvDxMode(var ProvDx: TProvisionalDiagnosis; SvcIEN: string);
90
91{ Clinical Procedures Specific}
92function GetSavedCPFields(NoteIEN: integer): TEditNoteRec;
93
94var
95 uConsultsClass: integer;
96 uConsultTitles: TConsultTitles;
97 uClinProcClass: integer;
98 uClinProcTitles: TClinProcTitles;
99
100implementation
101
102uses rODBase;
103
104var
105 uLastOrderedIEN: Integer;
106 uLastOrderMsg: string;
107
108{ -------------------------- Consult Titles --------------------------------- }
109
110function IdentifyConsultsClass: integer;
111begin
112 if uConsultsClass = 0 then
113 uConsultsClass := StrToIntDef(sCallV('TIU IDENTIFY CONSULTS CLASS',[nil]), 0) ;
114 Result := uConsultsClass;
115end;
116
117procedure LoadConsultTitles;
118{ private - called one time to set up the uConsultTitles object }
119var
120 x: string;
121begin
122 if uConsultTitles <> nil then Exit;
123 CallV('TIU PERSONAL TITLE LIST', [User.DUZ, IdentifyConsultsClass]);
124 RPCBrokerV.Results.Insert(0, '~SHORT LIST'); // insert so can call ExtractItems
125 uConsultTitles := TConsultTitles.Create;
126 ExtractItems(uConsultTitles.ShortList, RPCBrokerV.Results, 'SHORT LIST');
127 x := ExtractDefault(RPCBrokerV.Results, 'SHORT LIST');
128 uConsultTitles.DfltTitle := StrToIntDef(Piece(x, U, 1), 0);
129 uConsultTitles.DfltTitleName := Piece(x, U, 2);
130end;
131
132procedure ResetConsultTitles;
133begin
134 if uConsultTitles <> nil then
135 begin
136 uConsultTitles.Free;
137 uConsultTitles := nil;
138 LoadConsultTitles;
139 end;
140end;
141
142function DfltConsultTitle: integer;
143{ returns the user defined default Consult title (if any) }
144begin
145 if uConsultTitles = nil then LoadConsultTitles;
146 Result := uConsultTitles.DfltTitle;
147end;
148
149function DfltConsultTitleName: string;
150{ returns the name of the user defined default progress note title (if any) }
151begin
152 if uConsultTitles = nil then LoadConsultTitles;
153 Result := uConsultTitles.DfltTitleName;
154end;
155
156procedure ListConsultTitlesShort(Dest: TStrings);
157{ returns the user defined list (short list) of Consult titles }
158begin
159 if uConsultTitles = nil then LoadConsultTitles;
160 Dest.AddStrings(uConsultTitles.ShortList);
161 if uConsultTitles.ShortList.Count > 0 then
162 begin
163 Dest.Add('0^________________________________________________________________________');
164 Dest.Add('0^ ');
165 end;
166end;
167
168function SubSetOfConsultTitles(const StartFrom: string; Direction: Integer; IDNoteTitlesOnly: boolean): TStrings;
169{ returns a pointer to a list of consults progress note titles (for use in a long list box) -
170 The return value is a pointer to RPCBrokerV.Results, so the data must be used BEFORE
171 the next broker call! }
172begin
173(* if IDNoteTitlesOnly then // This RPC not changed for initial ID Notes release
174 CallV('TIU LONG LIST CONSULT TITLES', [StartFrom, Direction, IDNoteTitlesOnly])
175 else*)
176 CallV('TIU LONG LIST CONSULT TITLES', [StartFrom, Direction]);
177 //MixedCaseList(RPCBrokerV.Results);
178 Result := RPCBrokerV.Results;
179end;
180
181
182{ -------------------------- Clinical Procedures Titles --------------------------------- }
183function IdentifyClinProcClass: integer;
184begin
185 if uClinProcClass = 0 then
186 uClinProcClass := StrToIntDef(sCallV('TIU IDENTIFY CLINPROC CLASS',[nil]), 0) ;
187 Result := uClinProcClass;
188end;
189
190procedure LoadClinProcTitles;
191{ private - called one time to set up the uConsultTitles object }
192var
193 x: string;
194begin
195 if uClinProcTitles <> nil then Exit;
196 CallV('TIU PERSONAL TITLE LIST', [User.DUZ, IdentifyClinProcClass]);
197 RPCBrokerV.Results.Insert(0, '~SHORT LIST'); // insert so can call ExtractItems
198 uClinProcTitles := TClinProcTitles.Create;
199 ExtractItems(uClinProcTitles.ShortList, RPCBrokerV.Results, 'SHORT LIST');
200 x := ExtractDefault(RPCBrokerV.Results, 'SHORT LIST');
201 uClinProcTitles.DfltTitle := StrToIntDef(Piece(x, U, 1), 0);
202 uClinProcTitles.DfltTitleName := Piece(x, U, 2);
203end;
204
205procedure ResetClinProcTitles;
206begin
207 if uClinProcTitles <> nil then
208 begin
209 uClinProcTitles.Free;
210 uClinProcTitles := nil;
211 LoadClinProcTitles;
212 end;
213end;
214
215function DfltClinProcTitle: integer;
216{ returns the user defined default ClinProc title (if any) }
217begin
218 if uClinProcTitles = nil then LoadClinProcTitles;
219 Result := uClinProcTitles.DfltTitle;
220end;
221
222function DfltClinProcTitleName: string;
223{ returns the name of the user defined default progress note title (if any) }
224begin
225 if uClinProcTitles = nil then LoadClinProcTitles;
226 Result := uClinProcTitles.DfltTitleName;
227end;
228
229procedure ListClinProcTitlesShort(Dest: TStrings);
230{ returns the user defined list (short list) of ClinProc titles }
231begin
232 if uClinProcTitles = nil then LoadClinProcTitles;
233 Dest.AddStrings(uClinProcTitles.ShortList);
234 if uClinProcTitles.ShortList.Count > 0 then
235 begin
236 Dest.Add('0^________________________________________________________________________');
237 Dest.Add('0^ ');
238 end;
239end;
240
241function SubSetOfClinProcTitles(const StartFrom: string; Direction: Integer; IDNoteTitlesOnly: boolean): TStrings;
242{ returns a pointer to a list of clinical procedures titles (for use in a long list box) -
243 The return value is a pointer to RPCBrokerV.Results, so the data must be used BEFORE
244 the next broker call! }
245begin
246(* if IDNoteTitlesOnly then // This RPC not changed for initial ID Notes release
247 CallV('TIU LONG LIST CLINPROC TITLES', [StartFrom, Direction, IDNoteTitlesOnly])
248 else*)
249 CallV('TIU LONG LIST CLINPROC TITLES', [StartFrom, Direction]);
250 //MixedCaseList(RPCBrokerV.Results);
251 Result := RPCBrokerV.Results;
252end;
253
254{--------------- data retrieval ------------------------------------------}
255
256procedure GetConsultsList(Dest: TStrings; Early, Late: double;
257 Service, Status: string; SortAscending: Boolean);
258{ returns a list of consults for a patient, based on selected dates, service, status, or ALL}
259var
260 i: Integer;
261 x, date1, date2: string;
262begin
263 if Early <= 0 then date1 := '' else date1 := FloatToStr(Early) ;
264 if Late <= 0 then date2 := '' else date2 := FloatToStr(Late) ;
265 CallV('ORQQCN LIST', [Patient.DFN, date1, date2, Service, Status]);
266 with RPCBrokerV do
267 begin
268 if Copy(Results[0],1,1) <> '<' then
269 begin
270 SortByPiece(TStringList(Results), U, 2);
271 if not SortAscending then InvertStringList(TStringList(Results));
272 //SetListFMDateTime('mmm dd,yy', TStringList(Results), U, 2);
273 for i := 0 to Results.Count - 1 do
274 begin
275 x := MakeConsultListItem(Results[i]);
276 Results[i] := x;
277 end;
278 Dest.Assign(Results);
279 end
280 else
281 begin
282 Dest.Clear ;
283 Dest.Add('-1^No Matches') ;
284 end ;
285 end;
286end;
287
288procedure LoadConsultDetail(Dest: TStrings; IEN: integer) ;
289{ returns the detail of a consult }
290begin
291 CallV('ORQQCN DETAIL', [IEN]);
292 Dest.Assign(RPCBrokerV.Results);
293end;
294
295procedure DisplayResults(Dest: TStrings; IEN: integer) ;
296{ returns the results for a consult }
297begin
298 CallV('ORQQCN MED RESULTS', [IEN]);
299 Dest.Assign(RPCBrokerV.Results);
300end;
301
302procedure GetConsultRec(IEN: integer);
303{returns zero node from file 123, plus a list of all related TIU documents, if any}
304const
305 SHOW_ADDENDA = True;
306var
307 alist: TStrings;
308 x: string ;
309 i: integer;
310{ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
311{ Pieces: EntDt^Pat^OrIFN^PtLoc^ToSvc^From^ReqDt^Typ^Urg^Place^Attn^Sts^LstAct^SndPrv^Rslt^
312 16 17 18 19 20 21 22
313 ^EntMode^ReqTyp^InOut^SigFnd^TIUPtr^OrdFac^FrgnCslt}
314begin
315 FillChar(ConsultRec, SizeOf(ConsultRec), 0);
316 CallV('ORQQCN GET CONSULT', [IEN, SHOW_ADDENDA]);
317 ConsultRec.IEN := IEN ;
318 alist := TStringList.Create ;
319 try
320 alist.Assign(RPCBrokerV.Results) ;
321 x := alist[0] ;
322 if Piece(x,u,1) <> '-1' then
323 with ConsultRec do
324 begin
325 EntryDate := MakeFMDateTime(Piece(x, U, 1));
326 ORFileNumber := StrToIntDef(Piece(x, U, 3),0);
327 PatientLocation := StrToIntDef(Piece(x, U, 4),0);
328 OrderingFacility := StrToIntDef(Piece(x, U, 21),0);
329 ForeignConsultFileNum := StrToIntDef(Piece(x, U, 22),0);
330 ToService := StrToIntDef(Piece(x, U, 5),0);
331 From := StrToIntDef(Piece(x, U, 6),0);
332 RequestDate := MakeFMDateTime(Piece(x, U, 7));
333 ConsultProcedure := Piece(x, U, 8) ;
334 Urgency := StrToIntDef(Piece(x, U, 9),0);
335 PlaceOfConsult := StrToIntDef(Piece(x, U, 10),0);
336 Attention := StrToInt64Def(Piece(x, U, 11),0);
337 ORStatus := StrToIntDef(Piece(x, U, 12),0);
338 LastAction := StrToIntDef(Piece(x, U, 13),0);
339 SendingProvider := StrToInt64Def(Piece(Piece(x, U, 14),';',1),0);
340 SendingProviderName := Piece(Piece(x, U, 14),';',2) ;
341 Result := Piece(x, U, 15) ;
342 ModeOfEntry := Piece(x, U, 16) ;
343 RequestType := StrToIntDef(Piece(x, U, 17),0);
344 InOut := Piece(x, U, 18) ;
345 Findings := Piece(x, U, 19) ;
346 TIUResultNarrative := StrToIntDef(Piece(x, U, 20),0);
347 //ProvDiagnosis := Piece(x, U, 23); NO!!!!! Up to 180 Characters!!!!
348 alist.delete(0) ;
349 TIUDocuments := TStringList.Create ;
350 MedResults := TStringList.Create;
351 if alist.count > 0 then
352 begin
353 SortByPiece(TStringList(alist), U, 3);
354 for i := 0 to alist.Count - 1 do
355 if Copy(Piece(Piece(alist[i], U, 1), ';', 2), 1, 4) = 'MCAR' then
356 MedResults.Add(alist[i])
357 else
358 TIUDocuments.Add(alist[i]);
359 end;
360 end {ConsultRec}
361 else
362 ConsultRec.EntryDate := -1 ;
363 finally
364 alist.free ;
365 end ;
366end ;
367
368{---------------- list box fillers -----------------------------------}
369
370function SubSetOfStatus: TStrings;
371{ returns a pointer to a list of stati (for use in a list box) }
372begin
373 CallV('ORQQCN STATUS', [nil]);
374 MixedCaseList(RPCBrokerV.Results);
375 Result := RPCBrokerV.Results;
376end;
377
378function SubSetOfUrgencies(ConsultIEN: integer): TStrings;
379{ returns a pointer to a list of urgencies }
380begin
381 CallV('ORQQCN URGENCIES',[ConsultIEN]) ;
382 MixedCaseList(RPCBrokerV.Results);
383 Result := RPCBrokerV.Results;
384end;
385
386function FindConsult(ConsultIEN: integer): string ;
387var
388 x: string;
389begin
390 x := sCallV('ORQQCN FIND CONSULT',[ConsultIEN]);
391 Result := MakeConsultListItem(x);
392end;
393
394{-----------------consult result functions-----------------------------------}
395function GetAssignableMedResults(ConsultIEN: integer): TStrings;
396begin
397 CallV('ORQQCN ASSIGNABLE MED RESULTS', [ConsultIEN]);
398 Result := RPCBrokerV.Results;
399end;
400
401function GetRemovableMedResults(ConsultIEN: integer): TStrings;
402begin
403 CallV('ORQQCN REMOVABLE MED RESULTS', [ConsultIEN]);
404 Result := RPCBrokerV.Results;
405end;
406
407function GetDetailedMedicineResults(ResultID: string): TStrings;
408begin
409 CallV('ORQQCN GET MED RESULT DETAILS', [ResultID]);
410 Result := RPCBrokerV.Results;
411end;
412
413procedure AttachMedicineResult(ConsultIEN: integer; ResultID: string; DateTime: TFMDateTime; ResponsiblePerson: int64; AlertTo: string);
414begin
415 CallV('ORQQCN ATTACH MED RESULTS', [ConsultIEN, ResultID, DateTime, ResponsiblePerson, AlertTo]);
416end;
417
418procedure RemoveMedicineResult(ConsultIEN: integer; ResultID: string; DateTime: TFMDateTime; ResponsiblePerson: int64);
419begin
420 CallV('ORQQCN REMOVE MED RESULTS', [ConsultIEN, ResultID, DateTime, ResponsiblePerson]);
421end;
422{-------------- user access level functions ---------------------------------}
423
424function ConsultServiceUser(ServiceIEN: integer; DUZ: int64): boolean ;
425var
426 i: integer ;
427begin
428 Result := False ;
429 CallV('ORWU GENERIC', ['',1,'^GMR(123.5,'+IntToStr(ServiceIEN)+',123.3,"B")']) ;
430 for i:=0 to RPCBrokerV.Results.Count-1 do
431 if StrToInt64(Piece(RPCBrokerV.Results[i],u,2))=DUZ then result := True ;
432end ;
433
434function GetActionMenuLevel(ConsultIEN: integer): TMenuAccessRec ;
435var
436 x: string;
437begin
438 x := sCallV('ORQQCN SET ACT MENUS', [ConsultIEN]) ;
439 Result.UserLevel := StrToIntDef(Piece(x, U, 1), 1);
440 Result.AllowMedResulting := (Piece(x, U, 4) = '1');
441 Result.AllowMedDissociate := (Piece(x, U, 5) = '1');
442 Result.AllowResubmit := (Piece(x, U, 6) = '1') and (Piece(ConsultCanBeResubmitted(ConsultIEN), U, 1) <> '0');
443 Result.ClinProcFlag := StrToIntDef(Piece(x, U, 7), CP_NOT_CLINPROC);
444 Result.IsClinicalProcedure := (Result.ClinProcFlag > CP_NOT_CLINPROC);
445end ;
446
447{------------------- Consult request actions -------------------------------}
448
449procedure ReceiveConsult(Dest: TStrings; IEN: integer; ReceivedBy: int64; RcptDate: TFMDateTime; Comments: TStrings);
450begin
451 CallV('ORQQCN RECEIVE', [IEN, ReceivedBy, RcptDate, Comments]);
452 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
453end;
454
455procedure ScheduleConsult(Dest: TStrings; IEN: integer; ScheduledBy: Int64; SchdDate: TFMDateTime; Alert: integer;
456 AlertTo: string; Comments: TStrings);
457begin
458 CallV('ORQQCN2 SCHEDULE CONSULT', [IEN, ScheduledBy, SchdDate, Alert, AlertTo, Comments]);
459 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
460end;
461
462procedure DenyConsult(Dest: TStrings; IEN: integer; DeniedBy: int64;
463 DenialDate: TFMDateTime; Comments: TStrings);
464begin
465 CallV('ORQQCN DISCONTINUE', [IEN, DeniedBy, DenialDate,'DY',Comments]);
466 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
467end;
468
469procedure DiscontinueConsult(Dest: TStrings; IEN: integer; DiscontinuedBy: int64;
470 DiscontinueDate: TFMDateTime; Comments: TStrings);
471begin
472 CallV('ORQQCN DISCONTINUE', [IEN, DiscontinuedBy, DiscontinueDate,'DC',Comments]);
473 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
474end;
475
476procedure ForwardConsult(Dest: TStrings; IEN, ToService: integer; Forwarder, AttentionOf: int64; Urgency: integer;
477 ActionDate: TFMDateTime; Comments: TStrings);
478begin
479 CallV('ORQQCN FORWARD', [IEN, ToService, Forwarder, AttentionOf, Urgency, ActionDate, Comments]);
480 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
481end ;
482
483procedure AddComment(Dest: TStrings; IEN: integer; Comments: TStrings; ActionDate: TFMDateTime; Alert: integer;
484AlertTo: string) ;
485begin
486 CallV('ORQQCN ADDCMT', [IEN, Comments, Alert, AlertTo, ActionDate]);
487 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
488end ;
489
490procedure AdminComplete(Dest: TStrings; IEN: integer; SigFindingsFlag: string; Comments: TStrings;
491 RespProv: Int64; ActionDate: TFMDateTime; Alert: integer; AlertTo: string) ;
492begin
493 CallV('ORQQCN ADMIN COMPLETE', [IEN, SigFindingsFlag, Comments, RespProv, Alert, AlertTo, ActionDate]);
494 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
495end ;
496
497procedure SigFindings(Dest: TStrings; IEN: integer; SigFindingsFlag: string; Comments: TStrings; ActionDate: TFMDateTime; Alert: integer;
498AlertTo: string) ;
499begin
500 CallV('ORQQCN SIGFIND', [IEN, SigFindingsFlag, Comments, Alert, AlertTo, ActionDate]);
501 Dest.Assign(RPCBrokerV.Results); {1^Error message' or '0'}
502end ;
503
504//================== Ordering functions ===================================
505function ODForConsults: TStrings;
506{ Returns init values for consults dialog. The results must be used immediately. }
507begin
508 CallV('ORWDCN32 DEF', ['C']);
509 Result := RPCBrokerV.Results;
510end;
511
512function ODForProcedures: TStrings;
513{ Returns init values for procedures dialog. The results must be used immediately. }
514begin
515 CallV('ORWDCN32 DEF', ['P']);
516 Result := RPCBrokerV.Results;
517end;
518
519function SubSetOfProcedures(const StartFrom: string; Direction: Integer): TStrings;
520begin
521begin
522 CallV('ORWDCN32 PROCEDURES', [StartFrom, Direction]);
523 Result := RPCBrokerV.Results;
524end;
525end;
526
527function LoadServiceList(Purpose: integer): TStrings ;
528// Purpose: 0=display all services, 1=forward or order from possible services
529begin
530 Callv('ORQQCN SVCTREE',[Purpose]) ;
531 MixedCaseList(RPCBrokerV.Results) ;
532 Result := RPCBrokerV.Results;
533end ;
534
535function LoadServiceListWithSynonyms(Purpose: integer): TStrings ;
536// Param 1 = Starting service (1=All Services)
537// Param 2 = Purpose: 0=display all services, 1=forward or order from possible services
538// Param 3 = Show synonyms
539begin
540 Callv('ORQQCN SVC W/SYNONYMS',[1, Purpose, True]) ;
541 MixedCaseList(RPCBrokerV.Results) ;
542 Result := RPCBrokerV.Results;
543end ;
544
545function LoadServiceListWithSynonyms(Purpose, ConsultIEN: integer): TStrings ;
546// Param 1 = Starting service (1=All Services)
547// Param 2 = Purpose: 0=display all services, 1=forward or order from possible services
548// Param 3 = Show synonyms
549// Param 4 = Consult IEN
550begin
551 Callv('ORQQCN SVC W/SYNONYMS',[1, Purpose, True, ConsultIEN]) ;
552 MixedCaseList(RPCBrokerV.Results) ;
553 Result := RPCBrokerV.Results;
554end ;
555
556function SubSetOfServices(const StartFrom: string; Direction: Integer): TStrings;
557// used only on consults order dialog for service long combo box, which needs to include quick orders
558begin
559 CallV('ORQQCN SVCLIST', [StartFrom, Direction]);
560 Result := RPCBrokerV.Results;
561end;
562
563function LoadConsultsQuickList: TStrings ;
564begin
565 Callv('ORWDXQ GETQLST',['CSLT', 'Q']) ;
566 Result := RPCBrokerV.Results;
567end ;
568
569function ShowSF513(ConsultIEN: integer): TStrings ;
570var
571 x: string;
572 i: integer;
573begin
574 CallV('ORQQCN SHOW SF513',[ConsultIEN]) ;
575 if RPCBrokerV.Results.Count > 0 then
576 begin
577 x := RPCBrokerV.Results[0];
578 i := Pos('-', x);
579 x := Copy(x, i, 999);
580 RPCBrokerV.Results[0] := x;
581 end;
582 Result := RPCBrokerV.Results;
583end ;
584
585procedure PrintSF513ToDevice(AConsult: Integer; const ADevice: string; ChartCopy: string;
586 var ErrMsg: string);
587{ prints a SF 513 on the selected device }
588begin
589 ErrMsg := sCallV('ORQQCN PRINT SF513', [AConsult, ChartCopy, ADevice]);
590// if Piece(ErrMsg, U, 1) = '0' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
591end;
592
593function GetFormattedSF513(AConsult: Integer; ChartCopy: string): TStrings;
594begin
595 CallV('ORQQCN SF513 WINDOWS PRINT',[AConsult, ChartCopy]);
596 Result := RPCBrokerV.Results;
597end;
598
599function UnresolvedConsultsExist: boolean;
600begin
601 Result := (sCallV('ORQQCN UNRESOLVED', [Patient.DFN]) = '1');
602end;
603
604function ConsultMessage(AnIEN: Integer): string;
605begin
606 if AnIEN = uLastOrderedIEN then Result := uLastOrderMsg else
607 begin
608 Result := sCallV('ORWDCN32 ORDRMSG', [AnIEN]);
609 uLastOrderedIEN := AnIEN;
610 uLastOrderMsg := Result;
611 end;
612end;
613
614function GetProcedureIEN(ORIEN: string): string;
615begin
616 Result := sCallV('ORQQCN GET PROC IEN', [ORIEN]);
617end;
618
619function GetProcedureServices(ProcIEN: integer): TStrings;
620begin
621 CallV('ORQQCN GET PROC SVCS',[ProcIEN]) ;
622 Result := RPCBrokerV.Results;
623end;
624
625function ConsultCanBeResubmitted(ConsultIEN: integer): string;
626begin
627 Result := sCallV('ORQQCN CANEDIT', [ConsultIEN]);
628end;
629
630function LoadConsultForEdit(ConsultIEN: integer): TEditResubmitRec;
631var
632 Dest: TStringList;
633 EditRec: TEditResubmitRec;
634begin
635 Dest := TStringList.Create;
636 try
637 tCallV(Dest, 'ORQQCN LOAD FOR EDIT',[ConsultIEN]) ;
638 with EditRec do
639 begin
640 Changed := False;
641 IEN := ConsultIEN;
642 ToService := StrToIntDef(Piece(ExtractDefault(Dest, 'SERVICE'), U, 2), 0);
643 RequestType := Piece(ExtractDefault(Dest, 'TYPE'), U, 3);
644 OrderableItem := StrToIntDef(Piece(ExtractDefault(Dest, 'PROCEDURE'), U, 1), 0);
645 ConsultProc := Piece(ExtractDefault(Dest, 'PROCEDURE'), U, 3);
646 ConsultProcName := Piece(ExtractDefault(Dest, 'PROCEDURE'), U, 2);
647 Urgency := StrToIntDef(Piece(ExtractDefault(Dest, 'URGENCY'), U, 3), 0);
648 UrgencyName := Piece(ExtractDefault(Dest, 'URGENCY'), U, 2);
649 Place := Piece(ExtractDefault(Dest, 'PLACE'), U, 1);
650 PlaceName := Piece(ExtractDefault(Dest, 'PLACE'), U, 2);
651 Attention := StrToInt64Def(Piece(ExtractDefault(Dest, 'ATTENTION'), U, 1), 0);
652 AttnName := Piece(ExtractDefault(Dest, 'ATTENTION'), U, 2);
653 InpOutp := Piece(ExtractDefault(Dest, 'CATEGORY'), U, 1);
654 ProvDiagnosis := Piece(ExtractDefault(Dest, 'DIAGNOSIS'), U, 1);
655 ProvDxCode := Piece(ExtractDefault(Dest, 'DIAGNOSIS'), U, 2);
656 ProvDxCodeInactive := (Piece(ExtractDefault(Dest, 'DIAGNOSIS'), U, 3) = '1');
657 RequestReason := TStringList.Create;
658 ExtractText(RequestReason, Dest, 'REASON');
659 LimitStringLength(RequestReason, 74);
660 DenyComments := TStringList.Create;
661 ExtractText(DenyComments, Dest, 'DENY COMMENT');
662 OtherComments := TStringList.Create;
663 ExtractText(OtherComments, Dest, 'ADDED COMMENT');
664 NewComments := TStringList.Create;
665 end;
666 Result := EditRec;
667 finally
668 Dest.Free;
669 end;
670end;
671
672function ResubmitConsult(EditResubmitRec: TEditResubmitRec): string;
673var
674 i: integer;
675begin
676 with RPCBrokerV, EditResubmitRec do
677 begin
678 ClearParameters := True;
679 RemoteProcedure := 'ORQQCN RESUBMIT';
680 Param[0].PType := literal;
681 Param[0].Value := IntToStr(IEN);
682 Param[1].PType := list;
683 with Param[1] do
684 begin
685 if ToService > 0 then
686 Mult['1'] := 'GMRCSS^' + IntToStr(ToService);
687 if ConsultProc <> '' then
688 Mult['2'] := 'GMRCPROC^' + ConsultProc ;
689 if Urgency > 0 then
690 Mult['3'] := 'GMRCURG^' + IntToStr(Urgency);
691 if Length(Place) > 0 then
692 Mult['4'] := 'GMRCPL^' + Place;
693 if Attention > 0 then
694 Mult['5'] := 'GMRCATN^' + IntToStr(Attention)
695 else if Attention = -1 then
696 Mult['5'] := 'GMRCATN^' + '@';
697 if RequestType <> '' then
698 Mult['6'] := 'GMRCRQT^' + RequestType;
699 if Length(InpOutP) > 0 then
700 Mult['7'] := 'GMRCION^' + InpOutp;
701 if Length(ProvDiagnosis) > 0 then
702 Mult['8'] := 'GMRCDIAG^' + ProvDiagnosis + U + ProvDxCode;
703 if RequestReason.Count > 0 then
704 begin
705 Mult['9'] := 'GMRCRFQ^20';
706 for i := 0 to RequestReason.Count - 1 do
707 Mult['9,' + IntToStr(i+1)] := RequestReason.Strings[i];
708 end;
709 if NewComments.Count > 0 then
710 begin
711 Mult['10'] := 'COMMENT^';
712 for i := 0 to NewComments.Count - 1 do
713 Mult['10,' + IntToStr(i+1)] := NewComments.Strings[i];
714 end;
715 end;
716 CallBroker;
717 Result := '0';
718 //Result := Results[0];
719 end;
720end;
721
722function GetCurrentContext: TSelectContext;
723var
724 x: string;
725 AContext: TSelectContext;
726begin
727 x := sCallV('ORQQCN2 GET CONTEXT', [User.DUZ]) ;
728 with AContext do
729 begin
730 Changed := True;
731 BeginDate := Piece(x, ';', 1);
732 EndDate := Piece(x, ';', 2);
733 Status := Piece(x, ';', 3);
734 Service := Piece(x, ';', 4);
735 GroupBy := Piece(x, ';', 5);
736 Ascending := (Piece(x, ';', 6) = '1');
737 end;
738 Result := AContext;
739end;
740
741procedure SaveCurrentContext(AContext: TSelectContext) ;
742var
743 x: string;
744begin
745 with AContext do
746 begin
747 SetPiece(x, ';', 1, BeginDate);
748 SetPiece(x, ';', 2, EndDate);
749 SetPiece(x, ';', 3, Status);
750 SetPiece(x, ';', 4, Service);
751 SetPiece(x, ';', 5, GroupBy);
752 SetPiece(x, ';', 6, BOOLCHAR[Ascending]);
753 end;
754 CallV('ORQQCN2 SAVE CONTEXT', [x]);
755end;
756
757function GetDefaultReasonForRequest(Service: string; Resolve: Boolean): TStrings;
758begin
759 CallV('ORQQCN DEFAULT REQUEST REASON',[Service, Patient.DFN, Resolve]) ;
760 Result := RPCBrokerV.Results;
761end;
762
763function ReasonForRequestEditable(Service: string): string;
764begin
765 Result := sCallV('ORQQCN EDIT DEFAULT REASON', [Service]);
766end;
767
768function GetServicePrerequisites(Service: string): TStrings;
769begin
770 CallV('ORQQCN2 GET PREREQUISITE',[Service, Patient.DFN]) ;
771 Result := RPCBrokerV.Results;
772end;
773
774function GetNewDialog(OrderType: string): string;
775{ get dialog for new consults}
776begin
777 Result := sCallV('ORWDCN32 NEWDLG', [OrderType, Encounter.Location]);
778end;
779
780function GetServiceIEN(ORIEN: string): string;
781begin
782 Result := sCallV('ORQQCN GET SERVICE IEN', [ORIEN]);
783end;
784
785procedure GetProvDxMode(var ProvDx: TProvisionalDiagnosis; SvcIEN: string);
786var
787 x: string;
788begin
789 x := sCallV('ORQQCN PROVDX', [SvcIEN]);
790 ProvDx.Reqd := Piece(x, U, 1);
791 ProvDx.PromptMode := Piece(x, U, 2);
792end;
793
794function GetConsultOrderIEN(ConsultIEN: integer): string;
795begin
796 Result := sCallV('ORQQCN GET ORDER NUMBER', [ConsultIEN]);
797end;
798
799function GetSavedCPFields(NoteIEN: integer): TEditNoteRec;
800var
801 x: string;
802 AnEditRec: TEditNoteRec;
803begin
804 x := sCallV('ORWTIU GET SAVED CP FIELDS', [NoteIEN]);
805 with AnEditRec do
806 begin
807 Author := StrToInt64Def(Piece(x, U, 1), 0);
808 Cosigner := StrToInt64Def(Piece(x, U, 2), 0);
809 ClinProcSummCode := StrToIntDef(Piece(x, U, 3), 0);
810 ClinProcDateTime := StrToFMDateTime(Piece(x, U, 4));
811 Title := StrToIntDef(Piece(x, U, 5), 0);
812 end;
813 Result := AnEditRec;
814end;
815
816initialization
817 uLastOrderedIEN := 0;
818 uLastOrderMsg := '';
819 uConsultsClass := 0;
820 uClinProcClass := 0;
821
822finalization
823 if uConsultTitles <> nil then uConsultTitles.Free;
824 if uClinProcTitles <> nil then uClinProcTitles.Free;
825
826end.
Note: See TracBrowser for help on using the repository browser.