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