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