Module

rTIU

Path

C:\CPRS\CPRS30\rTIU.pas

Last Modified

7/15/2014 3:26:44 PM

Initialization Code

initialization
  // nothing for now

Finalization Code

finalization
  if uNoteTitles <> nil then uNoteTitles.Free;
  if uTIUPrefs <> nil then uTIUPrefs.Free;

end.

Units Used in Interface

Name Comments
rCore -
uConst -
uCore -
uTIU -

Units Used in Implementation

Name Comments
rMisc -

Procedures

Name Owner Declaration Scope Comments
ActOnDocument - procedure ActOnDocument(var AuthSts: TActionRec; IEN: Integer; const ActionName: string); Interfaced
Data Retrieval
Data Retrieval ---------------------------------------------------------------------------
ChangeCosigner - procedure ChangeCosigner(IEN: integer; Cosigner: int64); Interfaced -
DefaultCosigner - procedure DefaultCosigner(var IEN: Int64; var Name: string); Interfaced Returns the IEN (from the New Person file) and Name of this user's default cosigner
DeleteDocument - procedure DeleteDocument(var DeleteSts: TActionRec; IEN: Integer; const Reason: string); Interfaced
Data Storage 
procedure ClearCPTRequired(IEN: Integer);
procedure ClearCPTRequired(IEN: Integer);
{sets CREDIT STOP CODE ON COMPLETION to NO when no more need to get encounter information }
begin
  with RPCBrokerV do
  begin
    ClearParameters := True;
    RemoteProcedure := 'TIU UPDATE RECORD';
    Param[0].PType := literal;                     
    Param[0].Value := IntToStr(IEN);
    Param[1].PType := list;
    with Param[1] do Mult['.11']  := '0';          //  **** block removed in v19.1  {RV} ****
    CallBroker;
  end;
end;

 delete a TIU document given the internal entry number, return reason if unable to delete
GetNoteForEdit - procedure GetNoteForEdit(var EditRec: TEditNoteRec; IEN: Integer); Interfaced
Retrieves internal/external values for progress note fields & loads them into EditRec
  Fields: Title:.01, RefDate:1301, Author:1204, Cosigner:1208, Subject:1701, Location:1205 

x: string;
InitParams - procedure InitParams(NoteIEN: Int64; Suppress: Integer); Interfaced -
ListConsultRequests - procedure ListConsultRequests(Dest: TStrings); Interfaced
Function CPTRequiredForNote(IEN: Integer): Boolean;
begin
  If IEN > 0 then
    Result := sCallV('ORWPCE CPTREQD', [IEN]) = '1'
  else
    Result := False;
end;

 lists outstanding consult requests for a patient: IEN^Request D/T^Service^Procedure
ListDCSumm - procedure ListDCSumm(Dest: TStrings); Interfaced Returns the list of discharge summaries for a patient - see ListNotes for pieces
ListNotes - procedure ListNotes(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime; Person: int64; OccLim: Integer; SortAscending: Boolean); Interfaced
Function CPTRequiredForNote(IEN: Integer): Boolean;
retrieves existing progress notes for a patient according to the parameters passed in
  Pieces: IEN^Title^FMDateOfNote^Patient^Author^Location^Status^Visit
  Return: IEN^ExDateOfNote^Title, Location, Author^ImageCount^Visit
ListNotesForTree - procedure ListNotesForTree(Dest: TStrings; Context: Integer; Early, Late: TFMDateTime; Person: int64; OccLim: Integer; SortAscending: Boolean); Interfaced
Retrieves existing progress notes for a patient according to the parameters passed in
  Pieces: IEN^Title^FMDateOfNote^Patient^Author^Location^Status^Visit
  Return: IEN^ExDateOfNote^Title, Location, Author^ImageCount^Visit
ListNoteTitlesShort - procedure ListNoteTitlesShort(Dest: TStrings); Interfaced Returns the user defined list (short list) of progress note titles
LoadBoilerPlate - procedure LoadBoilerPlate(Dest: TStrings; Title: Integer); Interfaced Returns the boilerplate text (if any) for a given progress note title
LoadDetailText - procedure LoadDetailText(Dest: TStrings; IEN: Integer); Interfaced
KCM**
KCM**
LoadDocumentText - procedure LoadDocumentText(Dest: TStrings; IEN: Integer); Interfaced Returns the text of a document (progress note, discharge summary, etc.)
LoadNoteTitles - procedure LoadNoteTitles; Global Progress Note Titles --------------------------------------------------------------------
LoadTIUPrefs - procedure LoadTIUPrefs; Global TIU Preferences -------------------------------------------------------------------------
LockDocument - procedure LockDocument(IEN: Int64; var AnErrMsg: string); Interfaced -
PrintNoteToDevice - procedure PrintNoteToDevice(ANote: Integer; const ADevice: string; ChartCopy: Boolean; var ErrMsg: string); Interfaced Prints a progress note on the selected device
PutAddendum - procedure PutAddendum(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec; AddendumTo: Integer); Interfaced
Create a new addendum for note identified in AddendumTo, returns IEN of new document
  load broker directly since there isn't a good way to set up mutilple subscript arrays 

var
  i: Integer;
PutEditedNote - procedure PutEditedNote(var UpdatedDoc: TCreatedDoc; const NoteRec: TNoteRec; NoteIEN: Integer); Interfaced
Update the fields and content of the note identified in NoteIEN, returns 1 if successful
  load broker directly since there isn't a good way to set up mutilple subscript arrays 

var
  i: Integer;
PutNewNote - procedure PutNewNote(var CreatedDoc: TCreatedDoc; const NoteRec: TNoteRec); Interfaced
Create a new progress note with the data in NoteRec and return its internal entry number
  load broker directly since there isn't a good way to set up mutilple subscript arrays 

var
  i: Integer;
PutTextOnly - procedure PutTextOnly(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64); Interfaced -
ResetNoteTitles - procedure ResetNoteTitles; Interfaced -
ResetTIUPreferences - procedure ResetTIUPreferences; Interfaced TIU Preferences
SaveCurrentTIUContext - procedure SaveCurrentTIUContext(AContext: TTIUContext) ; Interfaced -
SetText - procedure SetText(var ErrMsg: string; NoteText: TStrings; NoteIEN: Int64; Suppress: Integer); Interfaced -
SignDocument - procedure SignDocument(var SignSts: TActionRec; IEN: Integer; const ESCode: string); Interfaced Update signed status of a TIU document, return reason if signature is not accepted
UnlockDocument - procedure UnlockDocument(IEN: Int64); Interfaced -
UpdateAdditionalSigners - procedure UpdateAdditionalSigners(IEN: integer; Signers: TStrings); Interfaced -

Functions

Name Owner Declaration Scope Comments
AllowChartPrintForNote - function AllowChartPrintForNote(ANote: Integer): Boolean; Interfaced
Printing
Printing --------------------------------------------------------------------------------- 

 returns true if a progress note may be printed outside of MAS
AskCosignerForDocument - function AskCosignerForDocument(ADocument: Integer; AnAuthor: Int64; ADate: TFMDateTime): Boolean; Interfaced -
AskCosignerForNotes - function AskCosignerForNotes: Boolean; Interfaced Returns true if cosigner should be asked when creating a new progress note
AskCosignerForTitle - function AskCosignerForTitle(ATitle: integer; AnAuthor: Int64; ADate: TFMDateTime): Boolean; Interfaced Returns TRUE if a cosignature is required for a document title and author
AskSubjectForNotes - function AskSubjectForNotes: Boolean; Interfaced Returns true if subject should be asked when creating a new progress note
AttachEntryToParent - function AttachEntryToParent(DocID, ParentDocID: string; var WhyNot: string): boolean; Interfaced -
AuthorSignedDocument - function AuthorSignedDocument(IEN: Integer): boolean; Interfaced -
CanBeAttached - function CanBeAttached(DocID: string; var WhyNot: string): boolean; Interfaced -
CanChangeCosigner - function CanChangeCosigner(IEN: integer): boolean; Interfaced -
CanCosign - function CanCosign(ATitle, ADocType: integer; AUser: Int64; ADate: TFMDateTime): Boolean; Interfaced -
CanReceiveAttachment - function CanReceiveAttachment(DocID: string; var WhyNot: string): boolean; Interfaced -
CanTitleBeIDChild - function CanTitleBeIDChild(Title: integer; var WhyNot: string): boolean; Interfaced -
CosignDocument - function CosignDocument(IEN: Integer): Boolean; Interfaced -
DetachEntryFromParent - function DetachEntryFromParent(DocID: string; var WhyNot: string): boolean; Interfaced -
DfltNoteTitle - function DfltNoteTitle: Integer; Interfaced
Progress Note Titles
returns the IEN of the user defined default progress note title (if any)
DfltNoteTitleName - function DfltNoteTitleName: string; Interfaced Returns the name of the user defined default progress note title (if any)
DfltTIULocation - function DfltTIULocation: Integer; Interfaced Returns the IEN of the user defined default progress note title (if any)
DfltTIULocationName - function DfltTIULocationName: string; Interfaced Returns the name of the user defined default progress note title (if any)
FindDT - function FindDT(const FieldID: string): TFMDateTime; Local X: string;
FindExt - function FindExt(const FieldID: string): string; Local -
FindInt - function FindInt(const FieldID: string): Integer; Local -
FindInt64 - function FindInt64(const FieldID: string): Int64; Local -
FindVal - function FindVal(const FieldID: string): string; Local -
GetConsultIENforNote - function GetConsultIENforNote(NoteIEN: integer): Integer; Interfaced -
GetCurrentSigners - function GetCurrentSigners(IEN: integer): TStrings; Interfaced -
GetCurrentTIUContext - function GetCurrentTIUContext: TTIUContext; Interfaced -
GetFormattedNote - function GetFormattedNote(ANote: Integer; ChartCopy: Boolean): TStrings; Interfaced -
GetPackageRefForNote - function GetPackageRefForNote(NoteIEN: integer): string; Interfaced -
GetTIUListItem - function GetTIUListItem(IEN: Int64): string; Interfaced -
IDNotesInstalled - function IDNotesInstalled: boolean; Interfaced
Interdisciplinary Notes
===================Interdisciplinary Notes RPCs =====================
IsClinProcTitle - function IsClinProcTitle(TitleIEN: Integer): Boolean; Interfaced -
IsConsultTitle - function IsConsultTitle(TitleIEN: Integer): Boolean; Interfaced -
IsPRFTitle - function IsPRFTitle(TitleIEN: Integer): Boolean; Interfaced -
JustifyDocumentDelete - function JustifyDocumentDelete(IEN: Integer): Boolean; Interfaced -
LastSaveClean - function LastSaveClean(IEN: Int64): Boolean; Interfaced -
NoteHasText - function NoteHasText(NoteIEN: integer): boolean; Interfaced -
OneNotePerVisit - function OneNotePerVisit(NoteEIN: Integer; DFN: String;VisitStr: String): boolean; Interfaced Determine if given note title is allowed more than once per visit. 12/2002-GRE
PrintNameForTitle - function PrintNameForTitle(TitleIEN: Integer): string; Interfaced -
ReturnMaxNotes - function ReturnMaxNotes: Integer; Interfaced -
SortNotesAscending - function SortNotesAscending: Boolean; Interfaced Returns true if progress notes should be sorted from oldest to newest (chronological)
SubSetOfNoteTitles - function SubSetOfNoteTitles(const StartFrom: string; Direction: Integer; IDNotesOnly: boolean): TStrings; Interfaced
Returns a pointer to a list of progress note titles (for use in a long list box) -
  The return value is a pointer to RPCBrokerV.Results, so the data must be used BEFORE
  the next broker call!
SubSetOfUserClasses - function SubSetOfUserClasses(const StartFrom: string; Direction: Integer): TStrings; Interfaced User Classes
TitleForNote - function TitleForNote(IEN: Int64): Integer; Interfaced -
TIUPatch175Installed - function TIUPatch175Installed: boolean; Interfaced Miscellaneous
TIUSiteParams - function TIUSiteParams: string; Interfaced -
UserDivClassInfo - function UserDivClassInfo(User: Int64): TStrings; Interfaced -
UserInactive - function UserInactive(EIN: String): boolean; Interfaced -
VisitStrForNote - function VisitStrForNote(IEN: Integer): string; Interfaced -

Global Variables

Name Type Declaration Comments
uNoteTitles TNoteTitles uNoteTitles: TNoteTitles; -
uPatch175Installed uPatch175Installed: TPatchInstalled; -
uTIUPrefs TTIUPrefs uTIUPrefs: TTIUPrefs; -
uTIUSiteParams UnicodeString uTIUSiteParams: string; -
uTIUSiteParamsLoaded Boolean uTIUSiteParamsLoaded: boolean = FALSE; -

Constants

Name Declaration Scope Comments
CLS_PROGRESS_NOTES 3 Interfaced -


Module Source

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

Module Calls (2 levels)


rTIU
 ├rCore
 │ └uCore
 ├uCore...
 ├uConst
 ├uTIU
 └rMisc
   └fOrders

Module Called-By (2 levels)


                       rTIU
                    uCore┤ 
                rOrders┤ │ 
                  rCore┤ │ 
                rTIU...┤ │ 
              rConsults┤ │ 
                uOrders┤ │ 
                fODBase┤ │ 
                rODBase┤ │ 
             UBAGlobals┤ │ 
                UBACore┤ │ 
                 fFrame┤ │ 
               fTimeout┤ │ 
                rODMeds┤ │ 
                fOrders┤ │ 
                dShared┤ │ 
             uTemplates┤ │ 
             rTemplates┤ │ 
        uTemplateFields┤ │ 
         uDlgComponents┤ │ 
             uReminders┤ │ 
                   uPCE┤ │ 
      fBALocalDiagnoses┤ │ 
                fPCELex┤ │ 
                   rPCE┤ │ 
        fEncounterFrame┤ │ 
             fVisitType┤ │ 
             fDiagnoses┤ │ 
             fEncVitals┤ │ 
                uVitals┤ │ 
                 uProbs┤ │ 
                 rProbs┤ │ 
                fVitals┤ │ 
                 fCover┤ │ 
                 rCover┤ │ 
              fPtSelMsg┤ │ 
                 fPtSel┤ │ 
            fOrdersSign┤ │ 
         fPrintLocation┤ │ 
                  fMeds┤ │ 
                  rMeds┤ │ 
              fARTAllgy┤ │ 
             rODAllergy┤ │ 
                 fNotes┤ │ 
               uDocTree┤ │ 
         fConsult513Prt┤ │ 
               rReports┤ │ 
               fReports┤ │ 
                   rECS┤ │ 
                 fVisit┤ │ 
                 fEncnt┤ │ 
                 fProbs┤ │ 
               fProbEdt┤ │ 
               fProbLex┤ │ 
          fReportsPrint┤ │ 
                fGraphs┤ │ 
             fGraphData┤ │ 
         fGraphProfiles┤ │ 
           fGraphOthers┤ │ 
                  rLabs┤ │ 
              fConsults┤ │ 
           fPCEProvider┤ │ 
          fDeviceSelect┤ │ 
                fDCSumm┤ │ 
                rDCSumm┤ │ 
        fTemplateEditor┤ │ 
            uEventHooks┤ │ 
        fReminderDialog┤ │ 
                fMHTest┤ │ 
                  fLabs┤ │ 
         fLabTestGroups┤ │ 
              fLabPrint┤ │ 
                fPtDemo┤ │ 
                fPtCWAD┤ │ 
                fReview┤ │ 
        fClinicWardMeds┤ │ 
           fCSRemaining┤ │ 
             rReminders┤ │ 
               fOptions┤ │ 
    fBAOptionsDiagnoses┤ │ 
             uSignItems┤ │ 
              fODDietLT┤ │ 
                rODDiet┤ │ 
           fOrdersPrint┤ │ 
               fSurgery┤ │ 
               rSurgery┤ │ 
uVA508CPRSCompatibility┤ │ 
          fDefaultEvent┤ │ 
      fPatientFlagMulti┤ │ 
           fOrdersRenew┤ │ 
                fODDiet┤ │ 
              fOrdersDC┤ │ 
              fOrdersCV┤ │ 
              fODMedOut┤ │ 
             fODConsult┤ │ 
             fConsultBS┤ │ 
          fConsultsView┤ │ 
            fConsultAct┤ │ 
                fODProc┤ │ 
              fCsltNote┤ │ 
             fNoteProps┤ │ 
                fNoteBA┤ │ 
               fNotePrt┤ │ 
               fTIUView┤ │ 
           fDCSummProps┤ │ 
              fEditProc┤ │ 
           fEditConsult┤ │ 
           fConsMedRslt┤ │ 
          fNoteCPFields┤ │ 
             fCombatVet┤ │ 
                 fODRad┤ │ 
                 fODLab┤ │ 
                 rODLab┤ │ 
          fLabCollTimes┤ │ 
               fODBBank┤ │ 
                fODMeds┤ │ 
               fODMedIV┤ │ 
                fODAuto┤ │ 
         fOrdersRelease┤ │ 
                fOMHTML┤ │ 
              fODMedNVA┤ │ 
         fOrdersOnChart┤ │ 
     fOrdersEvntRelease┤ │ 
        fODReleaseEvent┤ │ 
             fOCSession┤ │ 
              fOrdersTS┤ │ 
             mEvntDelay┤ │ 
              fODActive┤ │ 
            fOrdersCopy┤ │ 
               fMedCopy┤ │ 
                   fGAF┤ │ 
         fRemCoverSheet┤ │ 
               fPCEEdit┤ │ 
  fOptionsReportsCustom┤ │ 
 fOptionsReportsDefault┤ │ 
                   fvit┤ │ 
               fODAllgy┘ │ 
                  uPCE...┤ 
                fNotes...┤ 
             fConsults...┤ 
               fDCSumm...┤ 
               rDCSumm...┤ 
              fSurgery...┤ 
             fAddlSigners┤ 
              fNotes...┤ │ 
           fConsults...┤ │ 
             fDCSumm...┤ │ 
            fSurgery...┘ │ 
            fNoteProps...┤ 
              fNotePrt...┤ 
                  fNoteDR┤ 
              fNotes...┤ │ 
           fConsults...┤ │ 
             fDCSumm...┤ │ 
            fSurgery...┘ │ 
          fDCSummProps...┤ 
           fNoteIDParents┤ 
              fNotes...┤ │ 
           fConsults...┤ │ 
             fDCSumm...┘ │ 
                fNoteCslt┤ 
        fRemCoverSheet...┤ 
            fOptionsNotes┤ 
            fOptions...┘ │ 
           fOptionsTitles┘ 
            fOptions...┘