1 | //kt -- Modified with SourceScanner on 8/8/2007
|
---|
2 | unit rTemplates;
|
---|
3 |
|
---|
4 | interface
|
---|
5 |
|
---|
6 | uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, uConst, TRPCB, uTIU;
|
---|
7 |
|
---|
8 | { Templates }
|
---|
9 | procedure GetTemplateRoots;
|
---|
10 | function IsUserTemplateEditor(TemplateID: string; UserID :Int64): boolean;
|
---|
11 | procedure GetTemplateChildren(ID: string);
|
---|
12 | procedure GetTemplateBoilerplate(ID: string);
|
---|
13 | procedure GetTemplateText(BoilerPlate: TStrings);
|
---|
14 | function IsTemplateEditor(ID: string): boolean;
|
---|
15 | //function SubSetOfTemplateOwners(const StartFrom: string; Direction: Integer): TStrings;
|
---|
16 | function UpdateTemplate(ID: string; Fields: TStrings): string;
|
---|
17 | procedure UpdateChildren(ID: string; Children: TStrings);
|
---|
18 | procedure DeleteTemplates(DelList: TStrings);
|
---|
19 | procedure GetObjectList;
|
---|
20 | procedure GetAllowedPersonalObjects;
|
---|
21 | procedure TestBoilerplate(BoilerPlate: TStrings);
|
---|
22 | function GetTemplateAccess(ID: string): integer;
|
---|
23 | function SubSetOfBoilerplatedTitles(const StartFrom: string; Direction: Integer): TStrings;
|
---|
24 | function GetTitleBoilerplate(TitleIEN: string): string;
|
---|
25 | function GetUserTemplateDefaults(LoadFromServer: boolean = FALSE): string;
|
---|
26 | procedure SetUserTemplateDefaults(Value: string; PieceNum: integer);
|
---|
27 | procedure SaveUserTemplateDefaults;
|
---|
28 | procedure LoadTemplateDescription(TemplateIEN: string);
|
---|
29 | function GetTemplateAllowedReminderDialogs: TStrings;
|
---|
30 | function IsRemDlgAllowed(RemDlgIEN: string): integer;
|
---|
31 | function LockTemplate(const ID: string): boolean; // returns true if successful
|
---|
32 | procedure UnlockTemplate(const ID: string);
|
---|
33 | function GetLinkedTemplateData(const Link: string): string;
|
---|
34 | function SubSetOfAllTitles(const StartFrom: string; Direction: Integer): TStrings;
|
---|
35 |
|
---|
36 | { Template Fields }
|
---|
37 | function SubSetOfTemplateFields(const StartFrom: string; Direction: Integer): TStrings;
|
---|
38 | function LoadTemplateField(const DlgFld: string): TStrings;
|
---|
39 | function LoadTemplateFieldByIEN(const DlgFld: string): TStrings;
|
---|
40 | function CanEditTemplateFields: boolean;
|
---|
41 | function UpdateTemplateField(const ID: string; Fields: TStrings): string;
|
---|
42 | function LockTemplateField(const ID: string): boolean;
|
---|
43 | procedure UnlockTemplateField(const ID: string);
|
---|
44 | procedure DeleteTemplateField(const ID: string);
|
---|
45 | function ExportTemplateFields(FldList: TStrings): TStrings;
|
---|
46 | function ImportTemplateFields(FldList: TStrings): TStrings;
|
---|
47 | function IsTemplateFieldNameUnique(const FldName, IEN: string): boolean;
|
---|
48 | procedure Convert2LMText(Text: TStringList);
|
---|
49 | procedure CheckTemplateFields(ResultString: TStrings);
|
---|
50 | function BuildTemplateFields(XMLString: TStrings): boolean;
|
---|
51 | function ImportLoadedFields(ResultSet: TStrings): boolean;
|
---|
52 |
|
---|
53 | implementation
|
---|
54 | var
|
---|
55 | uUserTemplateDefaults: string = '';
|
---|
56 | uCanEditDlgFldChecked: boolean = FALSE;
|
---|
57 | uCanEditDlgFlds: boolean;
|
---|
58 |
|
---|
59 | { Template RPCs -------------------------------------------------------------- }
|
---|
60 |
|
---|
61 | procedure GetTemplateRoots;
|
---|
62 | begin
|
---|
63 | CallV('TIU TEMPLATE GETROOTS', [User.DUZ]);
|
---|
64 | end;
|
---|
65 |
|
---|
66 | function IsUserTemplateEditor(TemplateID: string; UserID :Int64): boolean;
|
---|
67 | begin
|
---|
68 | if StrToIntDef(TemplateID,0) > 0 then
|
---|
69 | Result := (Piece(sCallV('TIU TEMPLATE ISEDITOR', [TemplateID, UserID]),U,1) = '1')
|
---|
70 | else
|
---|
71 | Result := FALSE;
|
---|
72 | end;
|
---|
73 |
|
---|
74 | procedure GetTemplateChildren(ID: string);
|
---|
75 | begin
|
---|
76 | if(ID = '') or (ID = '0') then
|
---|
77 | RPCBrokerV.Results.Clear
|
---|
78 | else
|
---|
79 | CallV('TIU TEMPLATE GETITEMS', [ID]);
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure GetTemplateBoilerplate(ID: string);
|
---|
83 | begin
|
---|
84 | if(ID = '') or (ID = '0') then
|
---|
85 | RPCBrokerV.Results.Clear
|
---|
86 | else
|
---|
87 | CallV('TIU TEMPLATE GETBOIL', [ID]);
|
---|
88 | end;
|
---|
89 |
|
---|
90 | procedure GetTemplateText(BoilerPlate: TStrings);
|
---|
91 | var
|
---|
92 | i: integer;
|
---|
93 |
|
---|
94 | begin
|
---|
95 | with RPCBrokerV do
|
---|
96 | begin
|
---|
97 | ClearParameters := True;
|
---|
98 | RemoteProcedure := 'TIU TEMPLATE GETTEXT';
|
---|
99 | Param[0].PType := literal;
|
---|
100 | Param[0].Value := Patient.DFN;
|
---|
101 | Param[1].PType := literal;
|
---|
102 | Param[1].Value := Encounter.VisitStr;
|
---|
103 | Param[2].PType := list;
|
---|
104 | for i := 0 to BoilerPlate.Count-1 do
|
---|
105 | Param[2].Mult[IntToStr(i+1)+',0'] := BoilerPlate[i];
|
---|
106 | CallBroker;
|
---|
107 | RPCBrokerV.Results.Delete(0);
|
---|
108 | BoilerPlate.Assign(RPCBrokerV.Results);
|
---|
109 | RPCBrokerV.Results.Clear;
|
---|
110 | end;
|
---|
111 | end;
|
---|
112 |
|
---|
113 | function IsTemplateEditor(ID: string): boolean;
|
---|
114 | begin
|
---|
115 | Result := (sCallV('TIU TEMPLATE ISEDITOR', [ID, User.DUZ]) = '1');
|
---|
116 | end;
|
---|
117 |
|
---|
118 | //function SubSetOfTemplateOwners(const StartFrom: string; Direction: Integer): TStrings;
|
---|
119 | //begin
|
---|
120 | // CallV('TIU TEMPLATE LISTOWNR', [StartFrom, Direction]);
|
---|
121 | // MixedCaseList(RPCBrokerV.Results);
|
---|
122 | // Result := RPCBrokerV.Results;
|
---|
123 | //end;
|
---|
124 |
|
---|
125 | function UpdateTIURec(RPC, ID: string; Fields: TStrings): string;
|
---|
126 | var
|
---|
127 | i, j: integer;
|
---|
128 |
|
---|
129 | begin
|
---|
130 | with RPCBrokerV do
|
---|
131 | begin
|
---|
132 | ClearParameters := True;
|
---|
133 | RemoteProcedure := RPC;
|
---|
134 | Param[0].PType := literal;
|
---|
135 | Param[0].Value := ID;
|
---|
136 | Param[1].PType := list;
|
---|
137 | for i := 0 to Fields.Count-1 do
|
---|
138 | begin
|
---|
139 | j := pos('=',Fields[i]);
|
---|
140 | if(j > 0) then
|
---|
141 | Param[1].Mult[Fields.Names[i]] := copy(Fields[i],j+1,MaxInt);
|
---|
142 | end;
|
---|
143 | CallBroker;
|
---|
144 | Result := RPCBrokerV.Results[0];
|
---|
145 | end;
|
---|
146 | end;
|
---|
147 |
|
---|
148 | function UpdateTemplate(ID: string; Fields: TStrings): string;
|
---|
149 | begin
|
---|
150 | Result := UpdateTIURec('TIU TEMPLATE CREATE/MODIFY', ID, Fields);
|
---|
151 | end;
|
---|
152 |
|
---|
153 | procedure UpdateChildren(ID: string; Children: TStrings);
|
---|
154 | var
|
---|
155 | i: integer;
|
---|
156 |
|
---|
157 | begin
|
---|
158 | with RPCBrokerV do
|
---|
159 | begin
|
---|
160 | ClearParameters := True;
|
---|
161 | RemoteProcedure := 'TIU TEMPLATE SET ITEMS';
|
---|
162 | Param[0].PType := literal;
|
---|
163 | Param[0].Value := ID;
|
---|
164 | Param[1].PType := list;
|
---|
165 | for i := 0 to Children.Count-1 do
|
---|
166 | Param[1].Mult[IntToStr(i+1)] := Children[i];
|
---|
167 | CallBroker;
|
---|
168 | end;
|
---|
169 | end;
|
---|
170 |
|
---|
171 | procedure DeleteTemplates(DelList: TStrings);
|
---|
172 | var
|
---|
173 | i: integer;
|
---|
174 |
|
---|
175 | begin
|
---|
176 | if(DelList.Count > 0) then
|
---|
177 | begin
|
---|
178 | with RPCBrokerV do
|
---|
179 | begin
|
---|
180 | ClearParameters := True;
|
---|
181 | RemoteProcedure := 'TIU TEMPLATE DELETE';
|
---|
182 | Param[0].PType := list;
|
---|
183 | for i := 0 to DelList.Count-1 do
|
---|
184 | Param[0].Mult[IntToStr(i+1)] := DelList[i];
|
---|
185 | CallBroker;
|
---|
186 | end;
|
---|
187 | end;
|
---|
188 | end;
|
---|
189 |
|
---|
190 | procedure GetObjectList;
|
---|
191 | begin
|
---|
192 | CallV('TIU GET LIST OF OBJECTS', []);
|
---|
193 | end;
|
---|
194 |
|
---|
195 | procedure GetAllowedPersonalObjects;
|
---|
196 | begin
|
---|
197 | CallV('TIU TEMPLATE PERSONAL OBJECTS', []);
|
---|
198 | end;
|
---|
199 |
|
---|
200 | procedure TestBoilerplate(BoilerPlate: TStrings);
|
---|
201 | var
|
---|
202 | i: integer;
|
---|
203 |
|
---|
204 | begin
|
---|
205 | with RPCBrokerV do
|
---|
206 | begin
|
---|
207 | ClearParameters := True;
|
---|
208 | RemoteProcedure := 'TIU TEMPLATE CHECK BOILERPLATE';
|
---|
209 | Param[0].PType := list;
|
---|
210 | for i := 0 to BoilerPlate.Count-1 do
|
---|
211 | Param[0].Mult['2,'+IntToStr(i+1)+',0'] := BoilerPlate[i];
|
---|
212 | CallBroker;
|
---|
213 | end;
|
---|
214 | end;
|
---|
215 |
|
---|
216 | function GetTemplateAccess(ID: string): integer;
|
---|
217 | begin
|
---|
218 | Result := StrToIntDef(sCallV('TIU TEMPLATE ACCESS LEVEL', [ID, User.DUZ, Encounter.Location]), 0);
|
---|
219 | end;
|
---|
220 |
|
---|
221 | function SubSetOfBoilerplatedTitles(const StartFrom: string; Direction: Integer): TStrings;
|
---|
222 | begin
|
---|
223 | CallV('TIU LONG LIST BOILERPLATED', [StartFrom, Direction]);
|
---|
224 | Result := RPCBrokerV.Results;
|
---|
225 | end;
|
---|
226 |
|
---|
227 | function GetTitleBoilerplate(TitleIEN: string): string;
|
---|
228 | begin
|
---|
229 | CallV('TIU GET BOILERPLATE', [TitleIEN]);
|
---|
230 | Result := RPCBrokerV.Results.Text;
|
---|
231 | end;
|
---|
232 |
|
---|
233 | function GetUserTemplateDefaults(LoadFromServer: boolean = FALSE): string;
|
---|
234 | begin
|
---|
235 | if(LoadFromServer) then
|
---|
236 | uUserTemplateDefaults := sCallV('TIU TEMPLATE GET DEFAULTS', []);
|
---|
237 | Result := uUserTemplateDefaults;
|
---|
238 | end;
|
---|
239 |
|
---|
240 | procedure SetUserTemplateDefaults(Value: string; PieceNum: integer);
|
---|
241 | begin
|
---|
242 | SetPiece(uUserTemplateDefaults, '/', PieceNum, Value);
|
---|
243 | end;
|
---|
244 |
|
---|
245 | procedure SaveUserTemplateDefaults;
|
---|
246 | begin
|
---|
247 | CallV('TIU TEMPLATE SET DEFAULTS', [uUserTemplateDefaults]);
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure LoadTemplateDescription(TemplateIEN: string);
|
---|
251 | begin
|
---|
252 | CallV('TIU TEMPLATE GET DESCRIPTION', [TemplateIEN]);
|
---|
253 | end;
|
---|
254 |
|
---|
255 | function GetTemplateAllowedReminderDialogs: TStrings;
|
---|
256 | var
|
---|
257 | TmpList: TStringList;
|
---|
258 |
|
---|
259 | begin
|
---|
260 | CallV('TIU REMINDER DIALOGS', []);
|
---|
261 | TmpList := TStringList.Create;
|
---|
262 | try
|
---|
263 | TmpList.Assign(RPCBrokerV.Results);
|
---|
264 | SortByPiece(TmpList, U, 2);
|
---|
265 | MixedCaseList(TmpList);
|
---|
266 | RPCBrokerV.Results.Assign(TmpList);
|
---|
267 | finally
|
---|
268 | TmpList.Free;
|
---|
269 | end;
|
---|
270 | Result := RPCBrokerV.Results;
|
---|
271 | end;
|
---|
272 |
|
---|
273 | function IsRemDlgAllowed(RemDlgIEN: string): integer;
|
---|
274 | // -1 = inactive or deleted, 0 = not in Param, 1 = allowed
|
---|
275 | begin
|
---|
276 | Result := StrToIntDef(sCallV('TIU REM DLG OK AS TEMPLATE', [RemDlgIEN]),-1);
|
---|
277 | end;
|
---|
278 |
|
---|
279 | function LockTemplate(const ID: string): boolean; // returns true if successful
|
---|
280 | begin
|
---|
281 | Result := (sCallV('TIU TEMPLATE LOCK', [ID]) = '1')
|
---|
282 | end;
|
---|
283 |
|
---|
284 | procedure UnlockTemplate(const ID: string);
|
---|
285 | begin
|
---|
286 | CallV('TIU TEMPLATE UNLOCK', [ID]);
|
---|
287 | end;
|
---|
288 |
|
---|
289 | function GetLinkedTemplateData(const Link: string): string;
|
---|
290 | begin
|
---|
291 | Result := sCallV('TIU TEMPLATE GETLINK', [Link]);
|
---|
292 | end;
|
---|
293 |
|
---|
294 | function SubSetOfAllTitles(const StartFrom: string; Direction: Integer): TStrings;
|
---|
295 | begin
|
---|
296 | CallV('TIU TEMPLATE ALL TITLES', [StartFrom, Direction]);
|
---|
297 | Result := RPCBrokerV.Results;
|
---|
298 | end;
|
---|
299 |
|
---|
300 | { Template Fields }
|
---|
301 |
|
---|
302 | function SubSetOfTemplateFields(const StartFrom: string; Direction: Integer): TStrings;
|
---|
303 | begin
|
---|
304 | CallV('TIU FIELD LIST', [StartFrom, Direction]);
|
---|
305 | Result := RPCBrokerV.Results;
|
---|
306 | end;
|
---|
307 |
|
---|
308 | function LoadTemplateField(const DlgFld: string): TStrings;
|
---|
309 | begin
|
---|
310 | CallV('TIU FIELD LOAD', [DlgFld]);
|
---|
311 | Result := RPCBrokerV.Results;
|
---|
312 | end;
|
---|
313 |
|
---|
314 | function LoadTemplateFieldByIEN(const DlgFld: string): TStrings;
|
---|
315 | begin
|
---|
316 | CallV('TIU FIELD LOAD BY IEN', [DlgFld]);
|
---|
317 | Result := RPCBrokerV.Results;
|
---|
318 | end;
|
---|
319 |
|
---|
320 | function CanEditTemplateFields: boolean;
|
---|
321 | begin
|
---|
322 | if(not uCanEditDlgFldChecked) then
|
---|
323 | begin
|
---|
324 | uCanEditDlgFldChecked := TRUE;
|
---|
325 | uCanEditDlgFlds := sCallV('TIU FIELD CAN EDIT', []) = '1';
|
---|
326 | end;
|
---|
327 | Result := uCanEditDlgFlds;
|
---|
328 | end;
|
---|
329 |
|
---|
330 | function UpdateTemplateField(const ID: string; Fields: TStrings): string;
|
---|
331 | begin
|
---|
332 | Result := UpdateTIURec('TIU FIELD SAVE', ID, Fields);
|
---|
333 | end;
|
---|
334 |
|
---|
335 | function LockTemplateField(const ID: string): boolean; // returns true if successful
|
---|
336 | begin
|
---|
337 | Result := (sCallV('TIU FIELD LOCK', [ID]) = '1')
|
---|
338 | end;
|
---|
339 |
|
---|
340 | procedure UnlockTemplateField(const ID: string);
|
---|
341 | begin
|
---|
342 | CallV('TIU FIELD UNLOCK', [ID]);
|
---|
343 | end;
|
---|
344 |
|
---|
345 | procedure DeleteTemplateField(const ID: string);
|
---|
346 | begin
|
---|
347 | CallV('TIU FIELD DELETE', [ID]);
|
---|
348 | end;
|
---|
349 |
|
---|
350 | function CallImportExportTemplateFields(FldList: TStrings; RPCName: string): TStrings;
|
---|
351 | var
|
---|
352 | i: integer;
|
---|
353 |
|
---|
354 | begin
|
---|
355 | with RPCBrokerV do
|
---|
356 | begin
|
---|
357 | ClearParameters := True;
|
---|
358 | RemoteProcedure := RPCName;
|
---|
359 | Param[0].PType := list;
|
---|
360 | for i := 0 to FldList.Count-1 do
|
---|
361 | Param[0].Mult[IntToStr(i+1)] := FldList[i];
|
---|
362 | CallBroker;
|
---|
363 | end;
|
---|
364 | Result := RPCBrokerV.Results;
|
---|
365 | end;
|
---|
366 |
|
---|
367 | function ExportTemplateFields(FldList: TStrings): TStrings;
|
---|
368 | begin
|
---|
369 | Result := CallImportExportTemplateFields(FldList, 'TIU FIELD EXPORT');
|
---|
370 | end;
|
---|
371 |
|
---|
372 | function ImportTemplateFields(FldList: TStrings): TStrings;
|
---|
373 | begin
|
---|
374 | Result := CallImportExportTemplateFields(FldList, 'TIU FIELD IMPORT');
|
---|
375 | end;
|
---|
376 |
|
---|
377 | procedure CheckTemplateFields(ResultString: TStrings);
|
---|
378 | begin
|
---|
379 | CallV('TIU FIELD CHECK',[nil]);
|
---|
380 | ResultString.Assign(RPCBrokerV.Results);
|
---|
381 | end;
|
---|
382 |
|
---|
383 | function IsTemplateFieldNameUnique(const FldName, IEN: string): boolean;
|
---|
384 | begin
|
---|
385 | Result := sCallV('TIU FIELD NAME IS UNIQUE', [FldName, IEN]) = '1';
|
---|
386 | end;
|
---|
387 |
|
---|
388 | procedure Convert2LMText(Text: TStringList);
|
---|
389 | var
|
---|
390 | i: integer;
|
---|
391 | begin
|
---|
392 | with RPCBrokerV do
|
---|
393 | begin
|
---|
394 | ClearParameters := True;
|
---|
395 | RemoteProcedure := 'TIU FIELD DOLMTEXT';
|
---|
396 | Param[0].PType := list;
|
---|
397 | for i := 0 to Text.Count-1 do
|
---|
398 | Param[0].Mult[IntToStr(i+1)+',0'] := Text[i];
|
---|
399 | CallBroker;
|
---|
400 | end;
|
---|
401 | Text.Assign(RPCBrokerV.Results);
|
---|
402 | end;
|
---|
403 |
|
---|
404 | function BuildTemplateFields(XMLString: TStrings): boolean; //Simply builds XML fields on the server
|
---|
405 | var //in chunks.
|
---|
406 | i,j,p1: integer;
|
---|
407 | ok: boolean;
|
---|
408 |
|
---|
409 | procedure reset_broker;
|
---|
410 | begin
|
---|
411 | with RPCBrokerV do begin
|
---|
412 | ClearParameters := True;
|
---|
413 | RemoteProcedure := 'TIU FIELD LIST ADD';
|
---|
414 | Param[0].PType := list;
|
---|
415 | end;
|
---|
416 | end;
|
---|
417 |
|
---|
418 | begin
|
---|
419 | ok := TRUE;
|
---|
420 | with RPCBrokerV do
|
---|
421 | begin
|
---|
422 | reset_broker;
|
---|
423 | j := 1;
|
---|
424 | for i := 0 to XMLString.Count-1 do begin
|
---|
425 | p1 := pos('<FIELD NAME="',XMLString[i]);
|
---|
426 | if (p1 > 0) and (pos('">',copy(XMLString[i],p1+13,maxint)) > 0) then begin
|
---|
427 | j := j + 1;
|
---|
428 | if (j > 50) then begin
|
---|
429 | j := 1;
|
---|
430 | CallBroker;
|
---|
431 | if pos('1',Results[0]) = 0 then begin
|
---|
432 | ok := FALSE;
|
---|
433 | break;
|
---|
434 | end;//if
|
---|
435 | reset_broker;
|
---|
436 | end;//if
|
---|
437 | end;//if
|
---|
438 | Param[0].Mult[IntToStr(i+1)] := XMLString[i];
|
---|
439 | end;//for
|
---|
440 | if ok then begin
|
---|
441 | CallBroker;
|
---|
442 | if pos('1',Results[0]) = 0 then ok := FALSE;
|
---|
443 | end;//if
|
---|
444 | end;
|
---|
445 | Result := ok;
|
---|
446 | end;
|
---|
447 |
|
---|
448 | function ImportLoadedFields(ResultSet: TStrings): boolean;
|
---|
449 | begin
|
---|
450 | Result := TRUE;
|
---|
451 | CallV('TIU FIELD LIST IMPORT',[nil]);
|
---|
452 | ResultSet.Assign(RPCBrokerV.Results);
|
---|
453 | if ResultSet.Count < 1 then
|
---|
454 | Result := FALSE;
|
---|
455 | end;
|
---|
456 |
|
---|
457 | end.
|
---|