source: cprs/branches/foia-cprs/CPRS-Chart/rTIU.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: 37.3 KB
Line 
1unit rTIU;
2
3interface
4
5uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, uConst, TRPCB, uTIU;
6
7{ Progress Note Titles }
8function DfltNoteTitle: Integer;
9function DfltNoteTitleName: string;
10procedure ResetNoteTitles;
11function IsConsultTitle(TitleIEN: Integer): Boolean;
12function IsClinProcTitle(TitleIEN: Integer): Boolean;
13procedure ListNoteTitlesShort(Dest: TStrings);
14procedure LoadBoilerPlate(Dest: TStrings; Title: Integer);
15function PrintNameForTitle(TitleIEN: Integer): string;
16function SubSetOfNoteTitles(const StartFrom: string; Direction: Integer; IDNotesOnly: boolean): TStrings;
17
18{ TIU Preferences }
19procedure ResetTIUPreferences;
20function AskCosignerForNotes: Boolean;
21function AskCosignerForDocument(ADocument: Integer; AnAuthor: Int64): Boolean;
22function AskCosignerForTitle(ATitle: integer; AnAuthor: Int64): Boolean;
23function AskSubjectForNotes: Boolean;
24function CanCosign(ATitle, ADocType: integer; AUser: Int64): Boolean;
25function CanChangeCosigner(IEN: integer): boolean;
26procedure DefaultCosigner(var IEN: Int64; var Name: string);
27function ReturnMaxNotes: Integer;
28function SortNotesAscending: Boolean;
29function GetCurrentTIUContext: TTIUContext;
30procedure SaveCurrentTIUContext(AContext: TTIUContext) ;
31function TIUSiteParams: string;
32function DfltTIULocation: Integer;
33function DfltTIULocationName: string;
34
35{ Data Retrieval }
36procedure ActOnDocument(var AuthSts: TActionRec; IEN: Integer; const ActionName: string);
37function AuthorSignedDocument(IEN: Integer): boolean;
38function CosignDocument(IEN: Integer): Boolean;
39//function CPTRequiredForNote(IEN: Integer): Boolean;
40procedure ListNotes(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
41 Person: int64; OccLim: Integer; SortAscending: Boolean);
42procedure ListNotesForTree(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
43 Person: int64; OccLim: Integer; SortAscending: Boolean);
44procedure ListConsultRequests(Dest: TStrings);
45procedure ListDCSumm(Dest: TStrings);
46procedure LoadDetailText(Dest: TStrings; IEN: Integer); //**KCM**
47procedure LoadDocumentText(Dest: TStrings; IEN: Integer);
48procedure GetNoteForEdit(var EditRec: TEditNoteRec; IEN: Integer);
49function VisitStrForNote(IEN: Integer): string;
50function GetCurrentSigners(IEN: integer): TStrings;
51function TitleForNote(IEN: Int64): Integer;
52function GetConsultIENforNote(NoteIEN: integer): Integer;
53function GetPackageRefForNote(NoteIEN: integer): string;
54procedure LockDocument(IEN: Int64; var AnErrMsg: string);
55procedure UnlockDocument(IEN: Int64);
56function LastSaveClean(IEN: Int64): Boolean;
57function NoteHasText(NoteIEN: integer): boolean;
58function GetTIUListItem(IEN: Int64): string;
59
60{ Data Storage }
61//procedure ClearCPTRequired(IEN: Integer);
62procedure DeleteDocument(var DeleteSts: TActionRec; IEN: Integer; const Reason: string);
63function JustifyDocumentDelete(IEN: Integer): Boolean;
64procedure SignDocument(var SignSts: TActionRec; IEN: Integer; const ESCode: string);
65procedure PutNewNote(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec);
66procedure PutAddendum(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec; AddendumTo: Integer);
67procedure PutEditedNote(var UpdatedDoc: TCreatedDoc; const NoteRec: TNoteRec; NoteIEN: Integer);
68procedure PutTextOnly(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64);
69procedure SetText(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64; Suppress: Integer);
70procedure InitParams(NoteIEN: Int64; Suppress: Integer);
71procedure UpdateAdditionalSigners(IEN: integer; Signers: TStrings);
72procedure ChangeCosigner(IEN: integer; Cosigner: int64);
73
74{ Printing }
75function AllowChartPrintForNote(ANote: Integer): Boolean;
76procedure PrintNoteToDevice(ANote: Integer; const ADevice: string; ChartCopy: Boolean;
77 var ErrMsg: string);
78function GetFormattedNote(ANote: Integer; ChartCopy: Boolean): TStrings;
79
80// Interdisciplinary Notes
81function IDNotesInstalled: boolean;
82function CanTitleBeIDChild(Title: integer; var WhyNot: string): boolean;
83function CanReceiveAttachment(DocID: string; var WhyNot: string): boolean;
84function CanBeAttached(DocID: string; var WhyNot: string): boolean;
85function DetachEntryFromParent(DocID: string; var WhyNot: string): boolean;
86function AttachEntryToParent(DocID, ParentDocID: string; var WhyNot: string): boolean;
87function OneNotePerVisit(NoteEIN: Integer; DFN: String;VisitStr: String): boolean;
88
89
90//User Classes
91function SubSetOfUserClasses(const StartFrom: string; Direction: Integer): TStrings;
92function UserDivClassInfo(User: Int64): TStrings;
93function UserInactive(EIN: String): boolean;
94
95const
96 CLS_PROGRESS_NOTES = 3;
97
98implementation
99
100var
101 uTIUSiteParams: string;
102 uTIUSiteParamsLoaded: boolean = FALSE;
103 uNoteTitles: TNoteTitles;
104 uTIUPrefs: TTIUPrefs;
105
106
107{ Progress Note Titles -------------------------------------------------------------------- }
108
109procedure LoadNoteTitles;
110{ private - called one time to set up the uNoteTitles object }
111const
112 CLASS_PROGRESS_NOTES = 3;
113var
114 x: string;
115begin
116 if uNoteTitles <> nil then Exit;
117 CallV('TIU PERSONAL TITLE LIST', [User.DUZ, CLS_PROGRESS_NOTES]);
118 RPCBrokerV.Results.Insert(0, '~SHORT LIST'); // insert so can call ExtractItems
119 uNoteTitles := TNoteTitles.Create;
120 ExtractItems(uNoteTitles.ShortList, RPCBrokerV.Results, 'SHORT LIST');
121 x := ExtractDefault(RPCBrokerV.Results, 'SHORT LIST');
122 uNoteTitles.DfltTitle := StrToIntDef(Piece(x, U, 1), 0);
123 uNoteTitles.DfltTitleName := Piece(x, U, 2);
124end;
125
126procedure ResetNoteTitles;
127begin
128 if uNoteTitles <> nil then
129 begin
130 uNoteTitles.Free;
131 uNoteTitles := nil;
132 LoadNoteTitles;
133 end;
134end;
135
136function DfltNoteTitle: Integer;
137{ returns the IEN of the user defined default progress note title (if any) }
138begin
139 if uNoteTitles = nil then LoadNoteTitles;
140 Result := uNoteTitles.DfltTitle;
141end;
142
143function DfltNoteTitleName: string;
144{ returns the name of the user defined default progress note title (if any) }
145begin
146 if uNoteTitles = nil then LoadNoteTitles;
147 Result := uNoteTitles.DfltTitleName;
148end;
149
150function IsConsultTitle(TitleIEN: Integer): Boolean;
151begin
152 Result := False;
153 if TitleIEN <= 0 then Exit;
154 Result := sCallV('TIU IS THIS A CONSULT?', [TitleIEN]) = '1';
155end;
156
157function IsClinProcTitle(TitleIEN: Integer): Boolean;
158begin
159 Result := False;
160 if TitleIEN <= 0 then Exit;
161 Result := sCallV('TIU IS THIS A CLINPROC?', [TitleIEN]) = '1';
162end;
163
164procedure ListNoteTitlesShort(Dest: TStrings);
165{ returns the user defined list (short list) of progress note titles }
166begin
167 if uNoteTitles = nil then LoadNoteTitles;
168 Dest.AddStrings(uNoteTitles.ShortList);
169 if uNoteTitles.ShortList.Count > 0 then
170 begin
171 Dest.Add('0^________________________________________________________________________');
172 Dest.Add('0^ ');
173 end;
174end;
175
176procedure LoadBoilerPlate(Dest: TStrings; Title: Integer);
177{ returns the boilerplate text (if any) for a given progress note title }
178begin
179 CallV('TIU LOAD BOILERPLATE TEXT', [Title, Patient.DFN, Encounter.VisitStr]);
180 Dest.Assign(RPCBrokerV.Results);
181end;
182
183function PrintNameForTitle(TitleIEN: Integer): string;
184begin
185 Result := sCallV('TIU GET PRINT NAME', [TitleIEN]);
186end;
187
188function SubSetOfNoteTitles(const StartFrom: string; Direction: Integer; IDNotesOnly: boolean): TStrings;
189{ returns a pointer to a list of progress note titles (for use in a long list box) -
190 The return value is a pointer to RPCBrokerV.Results, so the data must be used BEFORE
191 the next broker call! }
192begin
193 if IDNotesOnly then
194 CallV('TIU LONG LIST OF TITLES', [CLS_PROGRESS_NOTES, StartFrom, Direction, IDNotesOnly])
195 else
196 CallV('TIU LONG LIST OF TITLES', [CLS_PROGRESS_NOTES, StartFrom, Direction]);
197 //MixedCaseList(RPCBrokerV.Results);
198 Result := RPCBrokerV.Results;
199end;
200
201{ TIU Preferences ------------------------------------------------------------------------- }
202
203procedure LoadTIUPrefs;
204{ private - creates TIUPrefs object for reference throughout the session }
205var
206 x: string;
207begin
208 uTIUPrefs := TTIUPrefs.Create;
209 with uTIUPrefs do
210 begin
211 x := sCallV('TIU GET PERSONAL PREFERENCES', [User.DUZ]);
212 DfltLoc := StrToIntDef(Piece(x, U, 2), 0);
213 DfltLocName := ExternalName(DfltLoc, FN_HOSPITAL_LOCATION);
214 SortAscending := Piece(x, U, 4) = 'A';
215 SortBy := Piece(x, U, 3);
216 AskNoteSubject := Piece(x, U, 8) = '1';
217 DfltCosigner := StrToInt64Def(Piece(x, U, 9), 0);
218 DfltCosignerName := ExternalName(DfltCosigner, FN_NEW_PERSON);
219 MaxNotes := StrToIntDef(Piece(x, U, 10), 0);
220 x := sCallV('TIU REQUIRES COSIGNATURE', [TYP_PROGRESS_NOTE, 0, User.DUZ]);
221 AskCosigner := Piece(x, U, 1) = '1';
222 end;
223end;
224
225procedure ResetTIUPreferences;
226begin
227 if uTIUPrefs <> nil then
228 begin
229 uTIUPrefs.Free;
230 uTIUPrefs := nil;
231 LoadTIUPrefs;
232 end;
233end;
234
235function AskCosignerForDocument(ADocument: Integer; AnAuthor: Int64): Boolean;
236begin
237 Result := Piece(sCallV('TIU REQUIRES COSIGNATURE', [0, ADocument, AnAuthor]), U, 1) = '1';
238end;
239
240function AskCosignerForTitle(ATitle: integer; AnAuthor: Int64): Boolean;
241{ returns TRUE if a cosignature is required for a document title and author }
242begin
243 Result := Piece(sCallV('TIU REQUIRES COSIGNATURE', [ATitle, 0, AnAuthor]), U, 1) = '1';
244end;
245
246function AskCosignerForNotes: Boolean;
247{ returns true if cosigner should be asked when creating a new progress note }
248begin
249 if uTIUPrefs = nil then LoadTIUPrefs;
250 Result := uTIUPrefs.AskCosigner;
251end;
252
253function AskSubjectForNotes: Boolean;
254{ returns true if subject should be asked when creating a new progress note }
255begin
256 if uTIUPrefs = nil then LoadTIUPrefs;
257 Result := uTIUPrefs.AskNoteSubject;
258end;
259
260function CanCosign(ATitle, ADocType: integer; AUser: Int64): Boolean;
261begin
262 if ATitle > 0 then ADocType := 0;
263 Result := Piece(sCallV('TIU REQUIRES COSIGNATURE', [ATitle, ADocType, AUser]), U, 1) <> '1';
264end;
265
266procedure DefaultCosigner(var IEN: Int64; var Name: string);
267{ returns the IEN (from the New Person file) and Name of this user's default cosigner }
268begin
269 if uTIUPrefs = nil then LoadTIUPrefs;
270 IEN := uTIUPrefs.DfltCosigner;
271 Name := uTIUPrefs.DfltCosignerName;
272end;
273
274function ReturnMaxNotes: Integer;
275begin
276 if uTIUPrefs = nil then LoadTIUPrefs;
277 Result := uTIUPrefs.MaxNotes;
278 if Result = 0 then Result := 100;
279end;
280
281function SortNotesAscending: Boolean;
282{ returns true if progress notes should be sorted from oldest to newest (chronological) }
283begin
284 if uTIUPrefs = nil then LoadTIUPrefs;
285 Result := uTIUPrefs.SortAscending;
286end;
287
288function DfltTIULocation: Integer;
289{ returns the IEN of the user defined default progress note title (if any) }
290begin
291 if uTIUPrefs = nil then LoadTIUPrefs;
292 Result := uTIUPrefs.DfltLoc;
293end;
294
295function DfltTIULocationName: string;
296{ returns the name of the user defined default progress note title (if any) }
297begin
298 if uTIUPrefs = nil then LoadTIUPrefs;
299 Result := uTIUPrefs.DfltLocName;
300end;
301
302{ Data Retrieval --------------------------------------------------------------------------- }
303
304procedure ActOnDocument(var AuthSts: TActionRec; IEN: Integer; const ActionName: string);
305var
306 x: string;
307begin
308 if not (IEN > 0) then
309 begin
310 AuthSts.Success := True;
311 AuthSts.Reason := '';
312 Exit;
313 end;
314 x := sCallV('TIU AUTHORIZATION', [IEN, ActionName]);
315 AuthSts.Success := Piece(x, U, 1) = '1';
316 AuthSts.Reason := Piece(x, U, 2);
317end;
318
319function AuthorSignedDocument(IEN: Integer): boolean;
320begin
321 Result := SCallV('TIU HAS AUTHOR SIGNED?', [IEN, User.DUZ]) = '1';
322end;
323
324function CosignDocument(IEN: Integer): Boolean;
325var
326 x: string;
327begin
328 x := sCallV('TIU WHICH SIGNATURE ACTION', [IEN]);
329 Result := x = 'COSIGNATURE';
330end;
331
332(*function CPTRequiredForNote(IEN: Integer): Boolean;
333begin
334 If IEN > 0 then
335 Result := sCallV('ORWPCE CPTREQD', [IEN]) = '1'
336 else
337 Result := False;
338end;*)
339
340procedure ListConsultRequests(Dest: TStrings);
341{ lists outstanding consult requests for a patient: IEN^Request D/T^Service^Procedure }
342begin
343 CallV('GMRC LIST CONSULT REQUESTS', [Patient.DFN]);
344 //MixedCaseList(RPCBrokerV.Results);
345 { remove first returned string, it is just a count }
346 if RPCBrokerV.Results.Count > 0 then RPCBrokerV.Results.Delete(0);
347 SetListFMDateTime('mmm dd,yy hh:nn', TStringList(RPCBrokerV.Results), U, 2);
348 Dest.Assign(RPCBrokerV.Results);
349end;
350
351procedure ListNotes(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
352 Person: int64; OccLim: Integer; SortAscending: Boolean);
353{ retrieves existing progress notes for a patient according to the parameters passed in
354 Pieces: IEN^Title^FMDateOfNote^Patient^Author^Location^Status^Visit
355 Return: IEN^ExDateOfNote^Title, Location, Author^ImageCount^Visit }
356var
357 i: Integer;
358 x: string;
359 SortSeq: Char;
360begin
361 if SortAscending then SortSeq := 'A' else SortSeq := 'D';
362 //if OccLim = 0 then OccLim := MaxNotesReturned;
363 CallV('TIU DOCUMENTS BY CONTEXT',
364 [3, Context, Patient.DFN, Early, Late, Person, OccLim, SortSeq]);
365 with RPCBrokerV do
366 begin
367 for i := 0 to Results.Count - 1 do
368 begin
369 x := Results[i];
370 x := Piece(x, U, 1) + U + FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(x, U, 3))) +
371 U + Piece(x, U, 2) + ', ' + Piece(x, U, 6) + ', ' + Piece(Piece(x, U, 5), ';', 2) +
372 U + Piece(x, U, 11) + U + Piece(x, U, 8) + U + Piece(x, U, 3);
373 Results[i] := x;
374 end; {for}
375 Dest.Assign(Results);
376 end; {with}
377end;
378
379procedure ListNotesForTree(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime;
380 Person: int64; OccLim: Integer; SortAscending: Boolean);
381{ retrieves existing progress notes for a patient according to the parameters passed in
382 Pieces: IEN^Title^FMDateOfNote^Patient^Author^Location^Status^Visit
383 Return: IEN^ExDateOfNote^Title, Location, Author^ImageCount^Visit }
384var
385 SortSeq: Char;
386const
387 SHOW_ADDENDA = True;
388begin
389 if SortAscending then SortSeq := 'A' else SortSeq := 'D';
390 if Context > 0 then
391 begin
392 CallV('TIU DOCUMENTS BY CONTEXT', [3, Context, Patient.DFN, Early, Late, Person, OccLim, SortSeq, SHOW_ADDENDA]);
393 Dest.Assign(RPCBrokerV.Results);
394 end;
395end;
396
397
398procedure ListDCSumm(Dest: TStrings);
399{ returns the list of discharge summaries for a patient - see ListNotes for pieces }
400var
401 i: Integer;
402 x: string;
403begin
404 CallV('TIU SUMMARIES', [Patient.DFN]);
405 with RPCBrokerV do
406 begin
407 SortByPiece(TStringList(Results), U, 3); // sort on date/time of summary
408 for i := 0 to Results.Count - 1 do
409 begin
410 x := Results[i];
411 x := Piece(x, U, 1) + U + FormatFMDateTime('mmm dd,yy', MakeFMDateTime(Piece(x, U, 3)))
412 + U + Piece(x, U, 2) + ', ' + Piece(x, U, 6) + ', ' + Piece(Piece(x, U, 5), ';', 2);
413 Results[i] := x;
414 end; {for}
415 Dest.Assign(Results);
416 end; {with}
417end;
418
419procedure LoadDocumentText(Dest: TStrings; IEN: Integer);
420{ returns the text of a document (progress note, discharge summary, etc.) }
421begin
422 CallV('TIU GET RECORD TEXT', [IEN]);
423 Dest.Assign(RPCBrokerV.Results);
424end;
425
426procedure LoadDetailText(Dest: TStrings; IEN: Integer); //**KCM**
427begin
428 CallV('TIU DETAILED DISPLAY', [IEN]);
429 Dest.Assign(RPCBrokerV.Results);
430end;
431
432procedure GetNoteForEdit(var EditRec: TEditNoteRec; IEN: Integer);
433{ retrieves internal/external values for progress note fields & loads them into EditRec
434 Fields: Title:.01, RefDate:1301, Author:1204, Cosigner:1208, Subject:1701, Location:1205 }
435var
436 i, j: Integer;
437 //x: string;
438
439 function FindDT(const FieldID: string): TFMDateTime;
440 var
441 i: Integer;
442 begin
443 Result := 0;
444 with RPCBrokerV do for i := 0 to Results.Count - 1 do
445 if Piece(Results[i], U, 1) = FieldID then
446 begin
447 Result := MakeFMDateTime(Piece(Results[i], U, 2));
448 Break;
449 end;
450 end;
451
452 function FindExt(const FieldID: string): string;
453 var
454 i: Integer;
455 begin
456 Result := '';
457 with RPCBrokerV do for i := 0 to Results.Count - 1 do
458 if Piece(Results[i], U, 1) = FieldID then
459 begin
460 Result := Piece(Results[i], U, 3);
461 Break;
462 end;
463 end;
464
465 function FindInt(const FieldID: string): Integer;
466 var
467 i: Integer;
468 begin
469 Result := 0;
470 with RPCBrokerV do for i := 0 to Results.Count - 1 do
471 if Piece(Results[i], U, 1) = FieldID then
472 begin
473 Result := StrToIntDef(Piece(Results[i], U, 2), 0);
474 Break;
475 end;
476 end;
477
478 function FindInt64(const FieldID: string): Int64;
479 var
480 i: Integer;
481 begin
482 Result := 0;
483 with RPCBrokerV do for i := 0 to Results.Count - 1 do
484 if Piece(Results[i], U, 1) = FieldID then
485 begin
486 Result := StrToInt64Def(Piece(Results[i], U, 2), 0);
487 Break;
488 end;
489 end;
490
491 function FindVal(const FieldID: string): string;
492 var
493 i: Integer;
494 begin
495 Result := '';
496 with RPCBrokerV do for i := 0 to Results.Count - 1 do
497 if Piece(Results[i], U, 1) = FieldID then
498 begin
499 Result := Piece(Results[i], U, 2);
500 Break;
501 end;
502 end;
503
504begin
505 CallV('TIU LOAD RECORD FOR EDIT', [IEN, '.01;.06;.07;1301;1204;1208;1701;1205;1405;2101;70201;70202']);
506 FillChar(EditRec, SizeOf(EditRec), 0);
507 with EditRec do
508 begin
509 Title := FindInt('.01');
510 TitleName := FindExt('.01');
511 DateTime := FindDT('1301');
512 Author := FindInt64('1204');
513 AuthorName := FindExt('1204');
514 Cosigner := FindInt64('1208');
515 CosignerName := FindExt('1208');
516 Subject := FindExt('1701');
517 Location := FindInt('1205');
518 LocationName := FindExt('1205');
519 IDParent := FindInt('2101');
520 ClinProcSummCode := FindInt('70201');
521 ClinProcDateTime := FindDT('70202');
522 VisitDate := FindDT('.07');
523 PkgRef := FindVal('1405');
524 PkgIEN := StrToIntDef(Piece(PkgRef, ';', 1), 0);
525 PkgPtr := Piece(PkgRef, ';', 2);
526 if Title = TYP_ADDENDUM then Addend := FindInt('.06');
527 with RPCBrokerV do
528 begin
529 for i := 0 to Results.Count - 1 do if Results[i] = '$TXT' then break;
530 for j := i downto 0 do Results.Delete(j);
531 // -------------------- v19.1 (RV) LOST NOTES?----------------------------
532 //Lines := Results; 'Lines' is being overwritten by subsequent Broker calls
533 if not Assigned(Lines) then Lines := TStringList.Create;
534 Lines.Assign(Results);
535 // -----------------------------------------------------------------------
536 end;
537 end;
538end;
539
540function VisitStrForNote(IEN: Integer): string;
541begin
542 Result := sCallV('ORWPCE NOTEVSTR', [IEN]);
543end;
544
545function TitleForNote(IEN: Int64): Integer;
546begin
547 Result := StrToIntDef(sCallV('TIU GET DOCUMENT TITLE', [IEN]), 3);
548// with RPCBrokerV do
549// begin
550// ClearParameters := True;
551// RemoteProcedure := 'XWB GET VARIABLE VALUE';
552// Param[0].PType := reference;
553// Param[0].Value := '$G(^TIU(8925,' + IntToStr(IEN) + ',0))';
554// CallBroker;
555// Result := StrToIntDef(Piece(Results[0], U, 1), 3);
556// end;
557end;
558
559function GetPackageRefForNote(NoteIEN: integer): string;
560begin
561 Result := sCallV('TIU GET REQUEST', [NoteIEN]);
562end;
563
564function GetConsultIENforNote(NoteIEN: integer): Integer;
565var
566 x: string;
567begin
568 x := sCallV('TIU GET REQUEST', [NoteIEN]);
569 if Piece(x, ';', 2) <> PKG_CONSULTS then
570 Result := -1
571 else
572 Result := StrTOIntDef(Piece(x, ';', 1), -1);
573end;
574
575procedure LockDocument(IEN: Int64; var AnErrMsg: string);
576var
577 x: string;
578begin
579 x := sCallV('TIU LOCK RECORD', [IEN]);
580 if CharAt(x, 1) = '0' then AnErrMsg := '' else AnErrMsg := Piece(x, U, 2);
581end;
582
583procedure UnlockDocument(IEN: Int64);
584begin
585 CallV('TIU UNLOCK RECORD', [IEN]);
586end;
587
588function LastSaveClean(IEN: Int64): Boolean;
589begin
590 Result := sCallV('TIU WAS THIS SAVED?', [IEN]) = '1';
591end;
592
593function GetTIUListItem(IEN: Int64): string;
594begin
595 Result := sCallV('ORWTIU GET LISTBOX ITEM', [IEN]);
596end;
597
598{ Data Updates ----------------------------------------------------------------------------- }
599
600(*procedure ClearCPTRequired(IEN: Integer);
601{ sets CREDIT STOP CODE ON COMPLETION to NO when no more need to get encounter information }
602begin
603 with RPCBrokerV do
604 begin
605 ClearParameters := True;
606 RemoteProcedure := 'TIU UPDATE RECORD';
607 Param[0].PType := literal;
608 Param[0].Value := IntToStr(IEN);
609 Param[1].PType := list;
610 with Param[1] do Mult['.11'] := '0'; // **** block removed in v19.1 {RV} ****
611 CallBroker;
612 end;
613end;*)
614
615procedure DeleteDocument(var DeleteSts: TActionRec; IEN: Integer; const Reason: string);
616{ delete a TIU document given the internal entry number, return reason if unable to delete }
617var
618 x: string;
619begin
620 x := sCallV('TIU DELETE RECORD', [IEN, Reason]);
621 DeleteSts.Success := Piece(x, U, 1) = '0';
622 DeleteSts.Reason := Piece(x, U, 2);
623end;
624
625function JustifyDocumentDelete(IEN: Integer): Boolean;
626begin
627 Result := sCallV('TIU JUSTIFY DELETE?', [IEN]) = '1';
628end;
629
630procedure SignDocument(var SignSts: TActionRec; IEN: Integer; const ESCode: string);
631{ update signed status of a TIU document, return reason if signature is not accepted }
632var
633 x: string;
634begin
635(* with RPCBrokerV do // temp - to insure sign doesn't go interactive
636 begin
637 ClearParameters := True;
638 RemoteProcedure := 'TIU UPDATE RECORD';
639 Param[0].PType := literal;
640 Param[0].Value := IntToStr(IEN);
641 Param[1].PType := list;
642 with Param[1] do Mult['.11'] := '0'; // **** block removed in v19.1 {RV} ****
643 CallBroker;
644 end; // temp - end*)
645 x := sCallV('TIU SIGN RECORD', [IEN, ESCode]);
646 SignSts.Success := Piece(x, U, 1) = '0';
647 SignSts.Reason := Piece(x, U, 2);
648end;
649
650procedure PutNewNote(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec);
651{ create a new progress note with the data in NoteRec and return its internal entry number
652 load broker directly since there isn't a good way to set up mutilple subscript arrays }
653(*var
654 i: Integer;*)
655var
656 ErrMsg: string;
657begin
658 with RPCBrokerV do
659 begin
660 ClearParameters := True;
661 RemoteProcedure := 'TIU CREATE RECORD';
662 Param[0].PType := literal;
663 Param[0].Value := Patient.DFN; //*DFN*
664 Param[1].PType := literal;
665 Param[1].Value := IntToStr(NoteRec.Title);
666 Param[2].PType := literal;
667 Param[2].Value := ''; //FloatToStr(Encounter.DateTime);
668 Param[3].PType := literal;
669 Param[3].Value := ''; //IntToStr(Encounter.Location);
670 Param[4].PType := literal;
671 Param[4].Value := '';
672 Param[5].PType := list;
673 with Param[5] do
674 begin
675 //Mult['.11'] := BOOLCHAR[NoteRec.NeedCPT]; // **** removed in v19.1 {RV} ****
676 Mult['1202'] := IntToStr(NoteRec.Author);
677 Mult['1301'] := FloatToStr(NoteRec.DateTime);
678 Mult['1205'] := IntToStr(Encounter.Location);
679 if NoteRec.Cosigner > 0 then Mult['1208'] := IntToStr(NoteRec.Cosigner);
680 if NoteRec.PkgRef <> '' then Mult['1405'] := NoteRec.PkgRef;
681 Mult['1701'] := FilteredString(Copy(NoteRec.Subject, 1, 80));
682 if NoteRec.IDParent > 0 then Mult['2101'] := IntToStr(NoteRec.IDParent);
683(* if NoteRec.Lines <> nil then
684 for i := 0 to NoteRec.Lines.Count - 1 do
685 Mult['"TEXT",' + IntToStr(i+1) + ',0'] := FilteredString(NoteRec.Lines[i]);*)
686 end;
687 Param[6].PType := literal;
688 Param[6].Value := Encounter.VisitStr;
689 Param[7].PType := literal;
690 Param[7].Value := '1'; // suppress commit logic
691 CallBroker;
692 CreatedDoc.IEN := StrToIntDef(Piece(Results[0], U, 1), 0);
693 CreatedDoc.ErrorText := Piece(Results[0], U, 2);
694 end;
695 if ( NoteRec.Lines <> nil ) and ( CreatedDoc.IEN <> 0 ) then
696 begin
697 SetText(ErrMsg, NoteRec.Lines, CreatedDoc.IEN, 1);
698 if ErrMsg <> '' then
699 begin
700 CreatedDoc.IEN := 0;
701 CreatedDoc.ErrorText := ErrMsg;
702 end;
703 end;
704end;
705
706procedure PutAddendum(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec; AddendumTo: Integer);
707{ create a new addendum for note identified in AddendumTo, returns IEN of new document
708 load broker directly since there isn't a good way to set up mutilple subscript arrays }
709(*var
710 i: Integer;*)
711var
712 ErrMsg: string;
713begin
714 with RPCBrokerV do
715 begin
716 ClearParameters := True;
717 RemoteProcedure := 'TIU CREATE ADDENDUM RECORD';
718 Param[0].PType := literal;
719 Param[0].Value := IntToStr(AddendumTo);
720 Param[1].PType := list;
721 with Param[1] do
722 begin
723 Mult['1202'] := IntToStr(NoteRec.Author);
724 Mult['1301'] := FloatToStr(NoteRec.DateTime);
725 if NoteRec.Cosigner > 0 then Mult['1208'] := IntToStr(NoteRec.Cosigner);
726(* if NoteRec.Lines <> nil then
727 for i := 0 to NoteRec.Lines.Count - 1 do
728 Mult['"TEXT",' + IntToStr(i+1) + ',0'] := FilteredString(NoteRec.Lines[i]);*)
729 end;
730 Param[2].PType := literal;
731 Param[2].Value := '1'; // suppress commit logic
732 CallBroker;
733 CreatedDoc.IEN := StrToIntDef(Piece(Results[0], U, 1), 0);
734 CreatedDoc.ErrorText := Piece(Results[0], U, 2);
735 end;
736 if ( NoteRec.Lines <> nil ) and ( CreatedDoc.IEN <> 0 ) then
737 begin
738 SetText(ErrMsg, NoteRec.Lines, CreatedDoc.IEN, 1);
739 if ErrMsg <> '' then
740 begin
741 CreatedDoc.IEN := 0;
742 CreatedDoc.ErrorText := ErrMsg;
743 end;
744 end;
745end;
746
747procedure PutEditedNote(var UpdatedDoc: TCreatedDoc; const NoteRec: TNoteRec; NoteIEN: Integer);
748{ update the fields and content of the note identified in NoteIEN, returns 1 if successful
749 load broker directly since there isn't a good way to set up mutilple subscript arrays }
750(*var
751 i: Integer;*)
752var
753 ErrMsg: string;
754begin
755 // First, file field data
756 with RPCBrokerV do
757 begin
758 ClearParameters := True;
759 RemoteProcedure := 'TIU UPDATE RECORD';
760 Param[0].PType := literal;
761 Param[0].Value := IntToStr(NoteIEN);
762 Param[1].PType := list;
763 with Param[1] do
764 begin
765 if NoteRec.Addend = 0 then
766 begin
767 Mult['.01'] := IntToStr(NoteRec.Title);
768 //Mult['.11'] := BOOLCHAR[NoteRec.NeedCPT]; // **** removed in v19.1 {RV} ****
769 end;
770 Mult['1202'] := IntToStr(NoteRec.Author);
771 if NoteRec.Cosigner > 0 then Mult['1208'] := IntToStr(NoteRec.Cosigner);
772 if NoteRec.PkgRef <> '' then Mult['1405'] := NoteRec.PkgRef;
773 Mult['1301'] := FloatToStr(NoteRec.DateTime);
774 Mult['1701'] := FilteredString(Copy(NoteRec.Subject, 1, 80));
775 if NoteRec.ClinProcSummCode > 0 then Mult['70201'] := IntToStr(NoteRec.ClinProcSummCode);
776 if NoteRec.ClinProcDateTime > 0 then Mult['70202'] := FloatToStr(NoteRec.ClinProcDateTime);
777(* for i := 0 to NoteRec.Lines.Count - 1 do
778 Mult['"TEXT",' + IntToStr(i+1) + ',0'] := FilteredString(NoteRec.Lines[i]);*)
779 end;
780 CallBroker;
781 UpdatedDoc.IEN := StrToIntDef(Piece(Results[0], U, 1), 0);
782 UpdatedDoc.ErrorText := Piece(Results[0], U, 2);
783 end;
784
785 if UpdatedDoc.IEN <= 0 then //v22.12 - RV
786 //if UpdatedDoc.ErrorText <> '' then //v22.5 - RV
787 begin
788 UpdatedDoc.ErrorText := UpdatedDoc.ErrorText + #13#10 + #13#10 + 'Document #: ' + IntToStr(NoteIEN);
789 exit;
790 end;
791
792 // next, if no error, file document body
793 SetText(ErrMsg, NoteRec.Lines, NoteIEN, 0);
794 if ErrMsg <> '' then
795 begin
796 UpdatedDoc.IEN := 0;
797 UpdatedDoc.ErrorText := ErrMsg;
798 end;
799end;
800
801procedure PutTextOnly(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64);
802var
803 i: Integer;
804begin
805 with RPCBrokerV do
806 begin
807 ClearParameters := True;
808 RemoteProcedure := 'TIU UPDATE RECORD';
809 Param[0].PType := literal;
810 Param[0].Value := IntToStr(NoteIEN);
811 Param[1].PType := list;
812 for i := 0 to Pred(NoteText.Count) do
813 Param[1].Mult['"TEXT",' + IntToStr(Succ(i)) + ',0'] := FilteredString(NoteText[i]);
814 Param[2].PType := literal;
815 Param[2].Value :='1'; // suppress commit code
816 CallBroker;
817 if Piece(Results[0], U, 1) = '0' then ErrMsg := Piece(Results[0], U, 2) else ErrMsg := '';
818 end;
819end;
820
821procedure SetText(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64; Suppress: Integer);
822const
823 DOCUMENT_PAGE_SIZE = 300;
824 TX_SERVER_ERROR = 'An error occurred on the server.' ;
825var
826 i, j, page, pages: Integer;
827begin
828 // Compute pages, initialize Params
829 pages := ( NoteText.Count div DOCUMENT_PAGE_SIZE );
830 if (NoteText.Count mod DOCUMENT_PAGE_SIZE) > 0 then pages := pages + 1;
831 page := 1;
832 InitParams( NoteIEN, Suppress );
833 // Loop through NoteRec.Lines
834 for i := 0 to NoteText.Count - 1 do
835 begin
836 j := i + 1;
837 //Add each successive line to Param[1].Mult...
838 RPCBrokerV.Param[1].Mult['"TEXT",' + IntToStr(j) + ',0'] := FilteredString(NoteText[i]);
839 // When current page is filled, call broker, increment page, itialize params,
840 // and continue...
841 if ( j mod DOCUMENT_PAGE_SIZE ) = 0 then
842 begin
843 RPCBrokerV.Param[1].Mult['"HDR"'] := IntToStr(page) + U + IntToStr(pages);
844 CallBroker;
845 if RPCBrokerV.Results.Count > 0 then
846 ErrMsg := Piece(RPCBrokerV.Results[0], U, 4)
847 else
848 ErrMsg := TX_SERVER_ERROR;
849 if ErrMsg <> '' then Exit;
850 page := page + 1;
851 InitParams( NoteIEN, Suppress );
852 end; // if
853 end; // for
854 // finally, file any remaining partial page
855 if ( NoteText.Count mod DOCUMENT_PAGE_SIZE ) <> 0 then
856 begin
857 RPCBrokerV.Param[1].Mult['"HDR"'] := IntToStr(page) + U + IntToStr(pages);
858 CallBroker;
859 if RPCBrokerV.Results.Count > 0 then
860 ErrMsg := Piece(RPCBrokerV.Results[0], U, 4)
861 else
862 ErrMsg := TX_SERVER_ERROR;
863 end;
864end;
865
866procedure InitParams( NoteIEN: Int64; Suppress: Integer );
867begin
868 with RPCBrokerV do
869 begin
870 ClearParameters := True;
871 RemoteProcedure := 'TIU SET DOCUMENT TEXT';
872 Param[0].PType := literal;
873 Param[0].Value := IntToStr(NoteIEN);
874 Param[1].PType := list;
875 Param[2].PType := literal;
876 Param[2].Value := IntToStr(Suppress);
877 end;
878end;
879
880{ Printing --------------------------------------------------------------------------------- }
881
882function AllowChartPrintForNote(ANote: Integer): Boolean;
883{ returns true if a progress note may be printed outside of MAS }
884begin
885 Result := (Piece(sCallV('TIU GET DOCUMENT PARAMETERS', [ANote]), U, 9) = '1');
886 // or (sCallV('TIU USER IS MEMBER OF CLASS', [User.DUZ, 'MEDICAL INFORMATION SECTION']) = '1');
887 // (V16? - RV) New TIU RPC required, per discussion on NOIS MAR-0900-21265
888end;
889
890procedure PrintNoteToDevice(ANote: Integer; const ADevice: string; ChartCopy: Boolean;
891 var ErrMsg: string);
892{ prints a progress note on the selected device }
893begin
894 ErrMsg := sCallV('TIU PRINT RECORD', [ANote, ADevice, ChartCopy]);
895 if Piece(ErrMsg, U, 1) = '0' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
896end;
897
898function GetFormattedNote(ANote: Integer; ChartCopy: Boolean): TStrings;
899begin
900 CallV('ORWTIU WINPRINT NOTE',[ANote, ChartCopy]);
901 Result := RPCBrokerV.Results;
902end;
903
904function GetCurrentSigners(IEN: integer): TStrings;
905begin
906 CallV('TIU GET ADDITIONAL SIGNERS', [IEN]);
907 MixedCaseList(RPCBrokerV.Results);
908 Result := RPCBrokerV.Results ;
909end;
910
911procedure UpdateAdditionalSigners(IEN: integer; Signers: TStrings);
912begin
913 CallV('TIU UPDATE ADDITIONAL SIGNERS', [IEN, Signers]);
914end;
915
916function CanChangeCosigner(IEN: integer): boolean;
917begin
918 Result := Piece(sCallV('TIU CAN CHANGE COSIGNER?', [IEN]), U, 1) = '1';
919end;
920
921procedure ChangeCosigner(IEN: integer; Cosigner: int64);
922begin
923 with RPCBrokerV do
924 begin
925 ClearParameters := True;
926 RemoteProcedure := 'TIU UPDATE RECORD';
927 Param[0].PType := literal;
928 Param[0].Value := IntToStr(IEN);
929 Param[1].PType := list;
930 with Param[1] do
931 if Cosigner > 0 then
932 Mult['1208'] := IntToStr(Cosigner)
933 else
934 Mult['1208'] := '@';
935 CallBroker;
936 end;
937end;
938
939// Determine if given note title is allowed more than once per visit. 12/2002-GRE
940function OneNotePerVisit(NoteEIN: Integer; DFN: String; VisitStr: String):boolean;
941var x: string;
942begin
943 x := sCallV('TIU ONE VISIT NOTE?', [IntToStr(NoteEIN),DFN,VisitStr]);
944 if StrToInt(x) > 0 then
945 Result := True //Only one per visit
946 else
947 Result := False;
948end;
949
950function GetCurrentTIUContext: TTIUContext;
951var
952 x: string;
953 AContext: TTIUContext;
954begin
955 x := sCallV('ORWTIU GET TIU CONTEXT', [User.DUZ]) ;
956 with AContext do
957 begin
958 Changed := True;
959 BeginDate := Piece(x, ';', 1);
960 FMBeginDate := StrToFMDateTime(BeginDate);
961 EndDate := Piece(x, ';', 2);
962 FMEndDate := StrToFMDateTime(EndDate);
963 Status := Piece(x, ';', 3);
964 if (StrToIntDef(Status, 0) < 1) or (StrToIntDef(Status, 0) > 5) then Status := '1';
965 Author := StrToInt64Def(Piece(x, ';', 4), 0);
966 MaxDocs := StrToIntDef(Piece(x, ';', 5), 0);
967 ShowSubject := StrToIntDef(Piece(x, ';', 6), 0) > 0; //TIU PREFERENCE??
968 SortBy := Piece(x, ';', 7); //TIU PREFERENCE??
969 ListAscending := StrToIntDef(Piece(x, ';', 8), 0) > 0;
970 TreeAscending := StrToIntDef(Piece(x, ';', 9), 0) > 0; //TIU PREFERENCE??
971 GroupBy := Piece(x, ';', 10);
972 SearchField := Piece(x, ';', 11);
973 KeyWord := Piece(x, ';', 12);
974 Filtered := (Keyword <> '');
975 end;
976 Result := AContext;
977end;
978
979procedure SaveCurrentTIUContext(AContext: TTIUContext) ;
980var
981 x: string;
982begin
983 with AContext do
984 begin
985 SetPiece(x, ';', 1, BeginDate);
986 SetPiece(x, ';', 2, EndDate);
987 SetPiece(x, ';', 3, Status);
988 if Author > 0 then
989 SetPiece(x, ';', 4, IntToStr(Author))
990 else
991 SetPiece(x, ';', 4, '');
992 SetPiece(x, ';', 5, IntToStr(MaxDocs));
993 SetPiece(x, ';', 6, BOOLCHAR[ShowSubject]); //TIU PREFERENCE??
994 SetPiece(x, ';', 7, SortBy); //TIU PREFERENCE??
995 SetPiece(x, ';', 8, BOOLCHAR[ListAscending]);
996 SetPiece(x, ';', 9, BOOLCHAR[TreeAscending]); //TIU PREFERENCE??
997 SetPiece(x, ';', 10, GroupBy);
998 SetPiece(x, ';', 11, SearchField);
999 SetPiece(x, ';', 12, KeyWord);
1000 end;
1001 CallV('ORWTIU SAVE TIU CONTEXT', [x]);
1002end;
1003
1004function TIUSiteParams: string;
1005begin
1006 if(not uTIUSiteParamsLoaded) then
1007 begin
1008 uTIUSiteParams := sCallV('TIU GET SITE PARAMETERS', []) ;
1009 uTIUSiteParamsLoaded := TRUE;
1010 end;
1011 Result := uTIUSiteParams;
1012end;
1013
1014// ===================Interdisciplinary Notes RPCs =====================
1015
1016function IDNotesInstalled: boolean;
1017begin
1018 Result := True;
1019end;
1020
1021function CanTitleBeIDChild(Title: integer; var WhyNot: string): boolean;
1022var
1023 x: string;
1024begin
1025 Result := False;
1026 x := sCallV('ORWTIU CANLINK', [Title]);
1027 if Piece(x, U, 1) = '1' then
1028 Result := True
1029 else if Piece(x, U, 1) = '0' then
1030 begin
1031 Result := False;
1032 WhyNot := Piece(x, U, 2);
1033 end;
1034end;
1035
1036function CanBeAttached(DocID: string; var WhyNot: string): boolean;
1037var
1038 x: string;
1039const
1040 TX_NO_ATTACH = 'This note appears to be an interdisciplinary parent. Please drag the child note you wish to ' + CRLF +
1041 'attach instead of attempting to drag the parent, or check with IRM or your' + CRLF +
1042 'clinical coordinator.';
1043begin
1044 Result := False;
1045 if StrToIntDef(DocID, 0) = 0 then exit;
1046 x := sCallV('TIU ID CAN ATTACH', [DocID]);
1047 if Piece(x, U, 1) = '1' then
1048 Result := True
1049 else if Piece(x, U, 1) = '0' then
1050 begin
1051 Result := False;
1052 WhyNot := Piece(x, U, 2);
1053 end
1054 else if Piece(x, U, 1) = '-1' then
1055 begin
1056 Result := False;
1057 WhyNot := TX_NO_ATTACH;
1058 end;
1059end;
1060
1061function CanReceiveAttachment(DocID: string; var WhyNot: string): boolean;
1062var
1063 x: string;
1064begin
1065 x := sCallV('TIU ID CAN RECEIVE', [DocID]);
1066 if Piece(x, U, 1) = '1' then
1067 Result := True
1068 else
1069 begin
1070 Result := False;
1071 WhyNot := Piece(x, U, 2);
1072 end;
1073end;
1074
1075function AttachEntryToParent(DocID, ParentDocID: string; var WhyNot: string): boolean;
1076var
1077 x: string;
1078begin
1079 x := sCallV('TIU ID ATTACH ENTRY', [DocID, ParentDocID]);
1080 if StrToIntDef(Piece(x, U, 1), 0) > 0 then
1081 Result := True
1082 else
1083 begin
1084 Result := False;
1085 WhyNot := Piece(x, U, 2);
1086 end;
1087end;
1088
1089function DetachEntryFromParent(DocID: string; var WhyNot: string): boolean;
1090var
1091 x: string;
1092begin
1093 x := sCallV('TIU ID DETACH ENTRY', [DocID]);
1094 if StrToIntDef(Piece(x, U, 1), 0) > 0 then
1095 Result := True
1096 else
1097 begin
1098 Result := False;
1099 WhyNot := Piece(x, U, 2);
1100 end;
1101end;
1102
1103function SubSetOfUserClasses(const StartFrom: string; Direction: Integer): TStrings;
1104begin
1105 CallV('TIU USER CLASS LONG LIST', [StartFrom, Direction]);
1106 Result := RPCBrokerV.Results;
1107end;
1108
1109function UserDivClassInfo(User: Int64): TStrings;
1110begin
1111 CallV('TIU DIV AND CLASS INFO', [User]);
1112 Result := RPCBrokerV.Results;
1113end;
1114
1115function UserInactive(EIN: String): boolean;
1116var x: string;
1117begin
1118 x:= sCallv('TIU USER INACTIVE?', [EIN]) ;
1119 if (StrToInt(x) > 0) then
1120 Result := True
1121 else
1122 Result := False;
1123end;
1124
1125function NoteHasText(NoteIEN: integer): boolean;
1126begin
1127 Result := (StrToIntDef(sCallV('ORWTIU CHKTXT', [NoteIEN]), 0) > 0);
1128end;
1129
1130initialization
1131 // nothing for now
1132
1133finalization
1134 if uNoteTitles <> nil then uNoteTitles.Free;
1135 if uTIUPrefs <> nil then uTIUPrefs.Free;
1136
1137end.
Note: See TracBrowser for help on using the repository browser.