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 USER IS MEMBER OF CLASS', [User.DUZ, 'MEDICAL INFORMATION SECTION']) = '1');
|
---|
917 | // (V16? - RV) New TIU RPC required, per discussion on NOIS MAR-0900-21265
|
---|
918 | end;
|
---|
919 |
|
---|
920 | procedure PrintNoteToDevice(ANote: Integer; const ADevice: string; ChartCopy: Boolean;
|
---|
921 | var ErrMsg: string);
|
---|
922 | { prints a progress note on the selected device }
|
---|
923 | begin
|
---|
924 | ErrMsg := sCallV('TIU PRINT RECORD', [ANote, ADevice, ChartCopy]);
|
---|
925 | if Piece(ErrMsg, U, 1) = '0' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
|
---|
926 | end;
|
---|
927 |
|
---|
928 | function GetFormattedNote(ANote: Integer; ChartCopy: Boolean): TStrings;
|
---|
929 | begin
|
---|
930 | CallV('ORWTIU WINPRINT NOTE',[ANote, ChartCopy]);
|
---|
931 | Result := RPCBrokerV.Results;
|
---|
932 | end;
|
---|
933 |
|
---|
934 | function GetCurrentSigners(IEN: integer): TStrings;
|
---|
935 | begin
|
---|
936 | CallV('TIU GET ADDITIONAL SIGNERS', [IEN]);
|
---|
937 | MixedCaseList(RPCBrokerV.Results);
|
---|
938 | Result := RPCBrokerV.Results ;
|
---|
939 | end;
|
---|
940 |
|
---|
941 | procedure UpdateAdditionalSigners(IEN: integer; Signers: TStrings);
|
---|
942 | begin
|
---|
943 | CallV('TIU UPDATE ADDITIONAL SIGNERS', [IEN, Signers]);
|
---|
944 | end;
|
---|
945 |
|
---|
946 | function CanChangeCosigner(IEN: integer): boolean;
|
---|
947 | begin
|
---|
948 | Result := Piece(sCallV('TIU CAN CHANGE COSIGNER?', [IEN]), U, 1) = '1';
|
---|
949 | end;
|
---|
950 |
|
---|
951 | procedure ChangeCosigner(IEN: integer; Cosigner: int64);
|
---|
952 | begin
|
---|
953 | with RPCBrokerV do
|
---|
954 | begin
|
---|
955 | ClearParameters := True;
|
---|
956 | RemoteProcedure := 'TIU UPDATE RECORD';
|
---|
957 | Param[0].PType := literal;
|
---|
958 | Param[0].Value := IntToStr(IEN);
|
---|
959 | Param[1].PType := list;
|
---|
960 | with Param[1] do
|
---|
961 | if Cosigner > 0 then
|
---|
962 | Mult['1208'] := IntToStr(Cosigner)
|
---|
963 | else
|
---|
964 | Mult['1208'] := '@';
|
---|
965 | CallBroker;
|
---|
966 | end;
|
---|
967 | end;
|
---|
968 |
|
---|
969 | // Determine if given note title is allowed more than once per visit. 12/2002-GRE
|
---|
970 | function OneNotePerVisit(NoteEIN: Integer; DFN: String; VisitStr: String):boolean;
|
---|
971 | var x: string;
|
---|
972 | begin
|
---|
973 | x := sCallV('TIU ONE VISIT NOTE?', [IntToStr(NoteEIN),DFN,VisitStr]);
|
---|
974 | if StrToInt(x) > 0 then
|
---|
975 | Result := True //Only one per visit
|
---|
976 | else
|
---|
977 | Result := False;
|
---|
978 | end;
|
---|
979 |
|
---|
980 | function GetCurrentTIUContext: TTIUContext;
|
---|
981 | var
|
---|
982 | x: string;
|
---|
983 | AContext: TTIUContext;
|
---|
984 | begin
|
---|
985 | x := sCallV('ORWTIU GET TIU CONTEXT', [User.DUZ]) ;
|
---|
986 | with AContext do
|
---|
987 | begin
|
---|
988 | Changed := True;
|
---|
989 | BeginDate := Piece(x, ';', 1);
|
---|
990 | FMBeginDate := StrToFMDateTime(BeginDate);
|
---|
991 | EndDate := Piece(x, ';', 2);
|
---|
992 | FMEndDate := StrToFMDateTime(EndDate);
|
---|
993 | Status := Piece(x, ';', 3);
|
---|
994 | if (StrToIntDef(Status, 0) < 1) or (StrToIntDef(Status, 0) > 5) then Status := '1';
|
---|
995 | Author := StrToInt64Def(Piece(x, ';', 4), 0);
|
---|
996 | MaxDocs := StrToIntDef(Piece(x, ';', 5), 0);
|
---|
997 | ShowSubject := StrToIntDef(Piece(x, ';', 6), 0) > 0; //TIU PREFERENCE??
|
---|
998 | SortBy := Piece(x, ';', 7); //TIU PREFERENCE??
|
---|
999 | ListAscending := StrToIntDef(Piece(x, ';', 8), 0) > 0;
|
---|
1000 | TreeAscending := StrToIntDef(Piece(x, ';', 9), 0) > 0; //TIU PREFERENCE??
|
---|
1001 | GroupBy := Piece(x, ';', 10);
|
---|
1002 | SearchField := Piece(x, ';', 11);
|
---|
1003 | KeyWord := Piece(x, ';', 12);
|
---|
1004 | Filtered := (Keyword <> '');
|
---|
1005 | end;
|
---|
1006 | Result := AContext;
|
---|
1007 | end;
|
---|
1008 |
|
---|
1009 | procedure SaveCurrentTIUContext(AContext: TTIUContext) ;
|
---|
1010 | var
|
---|
1011 | x: string;
|
---|
1012 | begin
|
---|
1013 | with AContext do
|
---|
1014 | begin
|
---|
1015 | SetPiece(x, ';', 1, BeginDate);
|
---|
1016 | SetPiece(x, ';', 2, EndDate);
|
---|
1017 | SetPiece(x, ';', 3, Status);
|
---|
1018 | if Author > 0 then
|
---|
1019 | SetPiece(x, ';', 4, IntToStr(Author))
|
---|
1020 | else
|
---|
1021 | SetPiece(x, ';', 4, '');
|
---|
1022 | SetPiece(x, ';', 5, IntToStr(MaxDocs));
|
---|
1023 | SetPiece(x, ';', 6, BOOLCHAR[ShowSubject]); //TIU PREFERENCE??
|
---|
1024 | SetPiece(x, ';', 7, SortBy); //TIU PREFERENCE??
|
---|
1025 | SetPiece(x, ';', 8, BOOLCHAR[ListAscending]);
|
---|
1026 | SetPiece(x, ';', 9, BOOLCHAR[TreeAscending]); //TIU PREFERENCE??
|
---|
1027 | SetPiece(x, ';', 10, GroupBy);
|
---|
1028 | SetPiece(x, ';', 11, SearchField);
|
---|
1029 | SetPiece(x, ';', 12, KeyWord);
|
---|
1030 | end;
|
---|
1031 | CallV('ORWTIU SAVE TIU CONTEXT', [x]);
|
---|
1032 | end;
|
---|
1033 |
|
---|
1034 | function TIUSiteParams: string;
|
---|
1035 | begin
|
---|
1036 | if(not uTIUSiteParamsLoaded) then
|
---|
1037 | begin
|
---|
1038 | uTIUSiteParams := sCallV('TIU GET SITE PARAMETERS', []) ;
|
---|
1039 | uTIUSiteParamsLoaded := TRUE;
|
---|
1040 | end;
|
---|
1041 | Result := uTIUSiteParams;
|
---|
1042 | end;
|
---|
1043 |
|
---|
1044 | // ===================Interdisciplinary Notes RPCs =====================
|
---|
1045 |
|
---|
1046 | function IDNotesInstalled: boolean;
|
---|
1047 | begin
|
---|
1048 | Result := True; // old patch check no longer called
|
---|
1049 | end;
|
---|
1050 |
|
---|
1051 | function CanTitleBeIDChild(Title: integer; var WhyNot: string): boolean;
|
---|
1052 | var
|
---|
1053 | x: string;
|
---|
1054 | begin
|
---|
1055 | Result := False;
|
---|
1056 | x := sCallV('ORWTIU CANLINK', [Title]);
|
---|
1057 | if Piece(x, U, 1) = '1' then
|
---|
1058 | Result := True
|
---|
1059 | else if Piece(x, U, 1) = '0' then
|
---|
1060 | begin
|
---|
1061 | Result := False;
|
---|
1062 | WhyNot := Piece(x, U, 2);
|
---|
1063 | end;
|
---|
1064 | end;
|
---|
1065 |
|
---|
1066 | function CanBeAttached(DocID: string; var WhyNot: string): boolean;
|
---|
1067 | var
|
---|
1068 | x: string;
|
---|
1069 | const
|
---|
1070 | TX_NO_ATTACH = 'This note appears to be an interdisciplinary parent. Please drag the child note you wish to ' + CRLF +
|
---|
1071 | 'attach instead of attempting to drag the parent, or check with IRM or your' + CRLF +
|
---|
1072 | 'clinical coordinator.';
|
---|
1073 | begin
|
---|
1074 | Result := False;
|
---|
1075 | if StrToIntDef(DocID, 0) = 0 then exit;
|
---|
1076 | x := sCallV('TIU ID CAN ATTACH', [DocID]);
|
---|
1077 | if Piece(x, U, 1) = '1' then
|
---|
1078 | Result := True
|
---|
1079 | else if Piece(x, U, 1) = '0' then
|
---|
1080 | begin
|
---|
1081 | Result := False;
|
---|
1082 | WhyNot := Piece(x, U, 2);
|
---|
1083 | end
|
---|
1084 | else if Piece(x, U, 1) = '-1' then
|
---|
1085 | begin
|
---|
1086 | Result := False;
|
---|
1087 | WhyNot := TX_NO_ATTACH;
|
---|
1088 | end;
|
---|
1089 | end;
|
---|
1090 |
|
---|
1091 | function CanReceiveAttachment(DocID: string; var WhyNot: string): boolean;
|
---|
1092 | var
|
---|
1093 | x: string;
|
---|
1094 | begin
|
---|
1095 | x := sCallV('TIU ID CAN RECEIVE', [DocID]);
|
---|
1096 | if Piece(x, U, 1) = '1' then
|
---|
1097 | Result := True
|
---|
1098 | else
|
---|
1099 | begin
|
---|
1100 | Result := False;
|
---|
1101 | WhyNot := Piece(x, U, 2);
|
---|
1102 | end;
|
---|
1103 | end;
|
---|
1104 |
|
---|
1105 | function AttachEntryToParent(DocID, ParentDocID: string; var WhyNot: string): boolean;
|
---|
1106 | var
|
---|
1107 | x: string;
|
---|
1108 | begin
|
---|
1109 | x := sCallV('TIU ID ATTACH ENTRY', [DocID, ParentDocID]);
|
---|
1110 | if StrToIntDef(Piece(x, U, 1), 0) > 0 then
|
---|
1111 | Result := True
|
---|
1112 | else
|
---|
1113 | begin
|
---|
1114 | Result := False;
|
---|
1115 | WhyNot := Piece(x, U, 2);
|
---|
1116 | end;
|
---|
1117 | end;
|
---|
1118 |
|
---|
1119 | function DetachEntryFromParent(DocID: string; var WhyNot: string): boolean;
|
---|
1120 | var
|
---|
1121 | x: string;
|
---|
1122 | begin
|
---|
1123 | x := sCallV('TIU ID DETACH ENTRY', [DocID]);
|
---|
1124 | if StrToIntDef(Piece(x, U, 1), 0) > 0 then
|
---|
1125 | Result := True
|
---|
1126 | else
|
---|
1127 | begin
|
---|
1128 | Result := False;
|
---|
1129 | WhyNot := Piece(x, U, 2);
|
---|
1130 | end;
|
---|
1131 | end;
|
---|
1132 |
|
---|
1133 | function SubSetOfUserClasses(const StartFrom: string; Direction: Integer): TStrings;
|
---|
1134 | begin
|
---|
1135 | CallV('TIU USER CLASS LONG LIST', [StartFrom, Direction]);
|
---|
1136 | Result := RPCBrokerV.Results;
|
---|
1137 | end;
|
---|
1138 |
|
---|
1139 | function UserDivClassInfo(User: Int64): TStrings;
|
---|
1140 | begin
|
---|
1141 | CallV('TIU DIV AND CLASS INFO', [User]);
|
---|
1142 | Result := RPCBrokerV.Results;
|
---|
1143 | end;
|
---|
1144 |
|
---|
1145 | function UserInactive(EIN: String): boolean;
|
---|
1146 | var x: string;
|
---|
1147 | begin
|
---|
1148 | x:= sCallv('TIU USER INACTIVE?', [EIN]) ;
|
---|
1149 | if (StrToInt(x) > 0) then
|
---|
1150 | Result := True
|
---|
1151 | else
|
---|
1152 | Result := False;
|
---|
1153 | end;
|
---|
1154 |
|
---|
1155 | function TIUPatch175Installed: boolean;
|
---|
1156 | begin
|
---|
1157 | with uPatch175Installed do
|
---|
1158 | if not PatchChecked then
|
---|
1159 | begin
|
---|
1160 | PatchInstalled := ServerHasPatch('TIU*1.0*175');
|
---|
1161 | PatchChecked := True;
|
---|
1162 | end;
|
---|
1163 | Result := uPatch175Installed.PatchInstalled;
|
---|
1164 | end;
|
---|
1165 |
|
---|
1166 | function NoteHasText(NoteIEN: integer): boolean;
|
---|
1167 | begin
|
---|
1168 | Result := (StrToIntDef(sCallV('ORWTIU CHKTXT', [NoteIEN]), 0) > 0);
|
---|
1169 | end;
|
---|
1170 |
|
---|
1171 |
|
---|
1172 | initialization
|
---|
1173 | // nothing for now
|
---|
1174 |
|
---|
1175 | finalization
|
---|
1176 | if uNoteTitles <> nil then uNoteTitles.Free;
|
---|
1177 | if uTIUPrefs <> nil then uTIUPrefs.Free;
|
---|
1178 |
|
---|
1179 | end.
|
---|