source: cprs/branches/tmg-cprs/CPRS-Chart/rReports.pas@ 745

Last change on this file since 745 was 671, checked in by Kevin Toppenberg, 15 years ago

Fixed HTML Note Printing Error

File size: 28.2 KB
Line 
1//kt -- Modified with SourceScanner on 8/20/2007
2unit rReports;
3
4interface
5
6uses
7 Windows, SysUtils, Classes, ORNet, ORFn,
8 Forms, //kt 8/09
9 ComCtrls, Chart, graphics;
10
11{ Consults }
12procedure ListConsults(Dest: TStrings);
13procedure LoadConsultText(Dest: TStrings; IEN: Integer);
14
15{ Reports }
16procedure ListReports(Dest: TStrings);
17procedure ListLabReports(Dest: TStrings);
18procedure ListReportDateRanges(Dest: TStrings);
19procedure ListHealthSummaryTypes(Dest: TStrings);
20procedure ListImagingExams(Dest: TStrings);
21procedure ListProcedures(Dest: TStrings);
22procedure ListNutrAssessments(Dest: TStrings);
23procedure ListSurgeryReports(Dest: TStrings);
24procedure ColumnHeaders(Dest: TStrings; AReportType: String);
25procedure SaveColumnSizes(aColumn: String);
26procedure LoadReportText(Dest: TStrings; ReportType: string; const Qualifier: string; ARpc, AHSTag: string);
27procedure RemoteQueryAbortAll;
28procedure RemoteQuery(Dest: TStrings; AReportType: string; AHSType, ADaysback,
29 AExamID: string; Alpha, AOmega: Double; ASite, ARemoteRPC, AHSTag: String);
30procedure DirectQuery(Dest: TStrings; AReportType: string; AHSType, ADaysback,
31 AExamID: string; Alpha, AOmega: Double; ASite, ARemoteRPC, AHSTag: String);
32function ReportQualifierType(ReportType: Integer): Integer;
33function ImagingParams: String;
34function AutoRDV: String;
35function HDRActive: String;
36procedure PrintReportsToDevice(AReport: string; const Qualifier, Patient,
37 ADevice: string; var ErrMsg: string; aComponents: TStringlist;
38 ARemoteSiteID, ARemoteQuery, AHSTag: string);
39function HSFileLookup(aFile: String; const StartFrom: string;
40 Direction: Integer): TStrings;
41procedure HSComponentFiles(Dest: TStrings; aComponent: String);
42procedure HSSubItems(Dest: TStrings; aItem: String);
43procedure HSReportText(Dest: TStrings; aComponents: TStringlist);
44procedure HSComponents(Dest: TStrings);
45procedure HSABVComponents(Dest: TStrings);
46procedure HSDispComponents(Dest: TStrings);
47procedure HSComponentSubs(Dest: TStrings; aItem: String);
48procedure HealthSummaryCheck(Dest: TStrings; aQualifier: string);
49function GetFormattedReport(AReport: string; const Qualifier, Patient: string;
50 aComponents: TStringlist; ARemoteSiteID, ARemoteQuery, AHSTag: string): TStrings;
51procedure PrintWindowsReport(ARichEdit: TRichEdit; APageBreak, ATitle: string;
52 var ErrMsg: string; Application : TApplication); //kt 8/09 added Application
53function DefaultToWindowsPrinter: Boolean;
54procedure PrintGraph(GraphImage: TChart; PageTitle: string);
55procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
56procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle: string);
57procedure SaveDefaultPrinter(DefPrinter: string) ;
58function GetRemoteStatus(aHandle: string): String;
59function GetAdhocLookup: integer;
60procedure SetAdhocLookup(aLookup: integer);
61procedure GetRemoteData(Dest: TStrings; aHandle: string; aItem: PChar);
62procedure ModifyHDRData(Dest: string; aHandle: string; aID: string);
63procedure PrintVReports(Dest, ADevice, AHeader: string; AReport: TStringList);
64
65implementation
66
67uses uCore, rCore, Printers, clipbrd, uReports, fReports,
68 rHTMLTools, //kt 8/09
69 DKLang //kt
70 ;
71
72var
73 uTree: TStringList;
74 uReportsList: TStringList;
75 uLabReports: TStringList;
76 uDateRanges: TStringList;
77 uHSTypes: TStringList;
78
79{ Consults }
80
81procedure ListConsults(Dest: TStrings);
82var
83 i: Integer;
84 x: string;
85begin
86 CallV('ORWCS LIST OF CONSULT REPORTS', [Patient.DFN]);
87 with RPCBrokerV do
88 begin
89 SortByPiece(TStringList(Results), U, 2);
90 InvertStringList(TStringList(Results));
91 SetListFMDateTime('mmm dd,yy', TStringList(Results), U, 2);
92 for i := 0 to Results.Count - 1 do
93 begin
94 x := Results[i];
95 x := Pieces(x, U, 1, 2) + U + Piece(x, U, 3) + ' (' + Piece(x, U, 4) + ')';
96 Results[i] := x;
97 end;
98 Dest.Assign(Results);
99 end;
100end;
101
102procedure LoadConsultText(Dest: TStrings; IEN: Integer);
103begin
104 CallV('ORWCS REPORT TEXT', [Patient.DFN, IEN]);
105 QuickCopy(RPCBrokerV.Results,Dest);
106end;
107
108{ Reports }
109
110procedure ExtractSection(Dest: TStrings; const Section: string; Mixed: Boolean);
111var
112 i: Integer;
113begin
114 with RPCBrokerV do
115 begin
116 i := -1;
117 repeat Inc(i) until (i = Results.Count) or (Results[i] = Section);
118 Inc(i);
119 while (i < Results.Count) and (Results[i] <> '$$END') do
120 begin
121 {if (Pos('OR_ECS',UpperCase(Results[i]))>0) and (not uECSReport.ECSPermit) then
122 begin
123 Inc(i);
124 Continue;
125 end;}
126 if Mixed = true then
127 Dest.Add(MixedCase(Results[i]))
128 else
129 Dest.Add(Results[i]);
130 Inc(i);
131 end;
132 end;
133end;
134
135procedure LoadReportLists;
136begin
137 CallV('ORWRP REPORT LISTS', [nil]);
138 uDateRanges := TStringList.Create;
139 uHSTypes := TStringList.Create;
140 uReportsList := TStringList.Create;
141 ExtractSection(uDateRanges, '[DATE RANGES]', true);
142 ExtractSection(uHSTypes, '[HEALTH SUMMARY TYPES]', true);
143 ExtractSection(uReportsList, '[REPORT LIST]', true);
144end;
145
146procedure LoadLabReportLists;
147begin
148 CallV('ORWRP LAB REPORT LISTS', [nil]);
149 uLabReports := TStringList.Create;
150 ExtractSection(uLabReports, '[LAB REPORT LIST]', true);
151end;
152
153procedure LoadTree;
154begin
155 CallV('ORWRP3 EXPAND COLUMNS', [nil]);
156 uTree := TStringList.Create;
157 ExtractSection(uTree, '[REPORT LIST]', false);
158end;
159
160procedure ListReports(Dest: TStrings);
161var
162 i: Integer;
163begin
164 if uTree = nil
165 then LoadTree
166 else
167 begin
168 uTree.Clear;
169 LoadTree;
170 end;
171 for i := 0 to uTree.Count - 1 do Dest.Add(Pieces(uTree[i], '^', 1, 15));
172end;
173
174procedure ListLabReports(Dest: TStrings);
175var
176 i: integer;
177begin
178 if uLabreports = nil then LoadLabReportLists;
179 for i := 0 to uLabReports.Count - 1 do Dest.Add(Pieces(uLabReports[i], U, 1, 10));
180end;
181
182procedure ListReportDateRanges(Dest: TStrings);
183begin
184 if uDateRanges = nil then LoadReportLists;
185 Dest.Assign(uDateRanges);
186end;
187
188procedure ListHealthSummaryTypes(Dest: TStrings);
189begin
190 if uHSTypes = nil then LoadReportLists;
191 MixedCaseList(uHSTypes);
192 Dest.Assign(uHSTypes);
193end;
194
195procedure HealthSummaryCheck(Dest: TStrings; aQualifier: string);
196
197begin
198 if aQualifier = '1' then
199 begin
200 ListHealthSummaryTypes(Dest);
201 end;
202end;
203
204procedure ColumnHeaders(Dest: TStrings; AReportType: String);
205begin
206 CallV('ORWRP COLUMN HEADERS',[AReportType]);
207 Dest.Assign(RPCBrokerV.Results);
208end;
209
210procedure SaveColumnSizes(aColumn: String);
211begin
212 CallV('ORWCH SAVECOL', [aColumn]);
213end;
214
215procedure ListImagingExams(Dest: TStrings);
216var
217 x: string;
218 i: Integer;
219begin
220 CallV('ORWRA IMAGING EXAMS1', [Patient.DFN]);
221 with RPCBrokerV do
222 begin
223 SetListFMDateTime('mm/dd/yyyy hh:nn', TStringList(Results), U, 3);
224 for i := 0 to Results.Count - 1 do
225 begin
226 x := Results[i];
227// if Piece(x,U,7) = 'Y' then SetPiece(x,U,7, ' - Abnormal'); <-- original line. //kt 8/20/2007
228 if Piece(x,U,7) = 'Y' then SetPiece(x,U,7, DKLangConstW('rReports_x_Abnormal')); //kt added 8/20/2007
229 x := Piece(x,U,1) + U + 'i' + Pieces(x,U,2,3)+ U + Piece(x,U,4)
230 + U + Piece(x,U,6) + Piece(x,U,7) + U
231 + MixedCase(Piece(Piece(x,U,9),'~',2)) + U + Piece(x,U,5) + U + '[+]'
232 + U + Pieces(x, U, 15,17);
233(* x := Piece(x,U,1) + U + 'i' + Pieces(x,U,2,3)+ U + Piece(x,U,4)
234 + U + Piece(x,U,6) + Piece(x,U,7) + U + Piece(x,U,5) + U + '[+]' + U + Piece(x, U, 15);*)
235 Results[i] := x;
236 end;
237 Dest.Assign(Results);
238 end;
239end;
240
241procedure ListProcedures(Dest: TStrings);
242var
243 x,sdate: string;
244 i: Integer;
245begin
246 CallV('ORWMC PATIENT PROCEDURES1', [Patient.DFN]);
247 with RPCBrokerV do
248 begin
249 for i := 0 to Results.Count - 1 do
250 begin
251 x := Results[i];
252 if length(piece(x, U, 8)) > 0 then
253 begin
254 sdate := ShortDateStrToDate(piece(piece(x, U, 8),'@',1)) + ' ' + piece(piece(x, U, 8),'@',2);
255 end;
256 x := Piece(x, U, 1) + U + 'i' + Piece(x, U, 2) + U + sdate + U + Piece(x, U, 3) + U + Piece(x, U, 9) + '^[+]';
257 Results[i] := x;
258 end;
259 Dest.Assign(Results);
260 end;
261end;
262
263procedure ListNutrAssessments(Dest: TStrings);
264var
265 x: string;
266 i: Integer;
267begin
268 CallV('ORWRP1 LISTNUTR', [Patient.DFN]);
269 with RPCBrokerV do
270 begin
271 for i := 0 to Results.Count - 1 do
272 begin
273 x := Results[i];
274 x := Piece(x, U, 1) + U + 'i' + Piece(x, U, 3) + U + Piece(x, U, 3);
275 Results[i] := x;
276 end;
277 Dest.Assign(Results);
278 end;
279end;
280
281procedure ListSurgeryReports(Dest: TStrings);
282{ returns a list of surgery cases for a patient, without documents}
283//Facility^Case #^Date/Time of Operation^Operative Procedure^Surgeon name)
284var
285 i: integer;
286 x, AFormat: string;
287begin
288 CallV('ORWSR RPTLIST', [Patient.DFN]);
289 with RPCBrokerV do
290 begin
291 for i := 0 to Results.Count - 1 do
292 begin
293 x := Results[i];
294 if Piece(Piece(x, U, 3), '.', 2) = '' then AFormat := 'mm/dd/yyyy' else AFormat := 'mm/dd/yyyy hh:nn';
295 x := Piece(x, U, 1) + U + 'i' + Piece(x, U, 2) + U + FormatFMDateTimeStr(AFormat, Piece(x, U, 3))+ U +
296 Piece(x, U, 4)+ U + Piece(x, U, 5);
297 if Piece(Results[i], U, 6) = '+' then x := x + '^[+]';
298 Results[i] := x;
299 end;
300 Dest.Assign(Results);
301 end;
302end;
303
304procedure LoadReportText(Dest: TStrings; ReportType: string; const Qualifier: string; ARpc, AHSTag: string);
305var
306 HSType, DaysBack, ExamID, MaxOcc, AReport, x: string;
307 Alpha, Omega, Trans: double;
308begin
309 HSType := '';
310 DaysBack := '';
311 ExamID := '';
312 Alpha := 0;
313 Omega := 0;
314 if CharAt(Qualifier, 1) = 'T' then
315 begin
316 Alpha := StrToFMDateTime(Piece(Qualifier,';',1));
317 Omega := StrToFMDateTime(Piece(Qualifier,';',2));
318 if Alpha > Omega then
319 begin
320 Trans := Omega;
321 Omega := Alpha;
322 Alpha := Trans;
323 end;
324 MaxOcc := Piece(Qualifier,';',3);
325 SetPiece(AHSTag,';',4,MaxOcc);
326 end;
327 if CharAt(Qualifier, 1) = 'd' then
328 begin
329 MaxOcc := Piece(Qualifier,';',2);
330 SetPiece(AHSTag,';',4,MaxOcc);
331 x := Piece(Qualifier,';',1);
332 DaysBack := Copy(x, 2, Length(x));
333 end;
334 if CharAt(Qualifier, 1) = 'h' then HSType := Copy(Qualifier, 2, Length(Qualifier));
335 if CharAt(Qualifier, 1) = 'i' then ExamID := Copy(Qualifier, 2, Length(Qualifier));
336 AReport := ReportType + '~' + AHSTag;
337 if Length(ARpc) > 0 then
338 begin
339 CallV(ARpc, [Patient.DFN, AReport, HSType, DaysBack, ExamID, Alpha, Omega]);
340 QuickCopy(RPCBrokerV.Results,Dest);
341 end
342 else
343 begin
344// Dest.Add('RPC is missing from report definition (file 101.24).'); <-- original line. //kt 8/20/2007
345 Dest.Add(DKLangConstW('rReports_RPC_is_missing_from_report_definition_xfile_101x24xx')); //kt added 8/20/2007
346// Dest.Add('Please contact Technical Support.'); <-- original line. //kt 8/20/2007
347 Dest.Add(DKLangConstW('rReports_Please_contact_Technical_Supportx')); //kt added 8/20/2007
348 end;
349end;
350
351procedure RemoteQueryAbortAll;
352begin
353 CallV('XWB DEFERRED CLEARALL',[nil]);
354end;
355
356procedure RemoteQuery(Dest: TStrings; AReportType: string; AHSType, ADaysback,
357 AExamID: string; Alpha, AOmega: Double; ASite, ARemoteRPC, AHSTag: String);
358var
359 AReport: string;
360begin
361 AReport := AReportType + ';1' + '~' + AHSTag;
362 if length(AHSType) > 0 then
363 AHSType := piece(AHSType,':',1) + ';' + piece(AHSType,':',2); //format for backward compatibility
364 CallV('XWB REMOTE RPC', [ASite, ARemoteRPC, 0, Patient.DFN + ';' + Patient.ICN,
365 AReport, AHSType, ADaysBack, AExamID, Alpha, AOmega]);
366 QuickCopy(RPCBrokerV.Results,Dest);
367end;
368
369procedure DirectQuery(Dest: TStrings; AReportType: string; AHSType, ADaysback,
370 AExamID: string; Alpha, AOmega: Double; ASite, ARemoteRPC, AHSTag: String);
371var
372 AReport: string;
373begin
374 AReport := AReportType + ';1' + '~' + AHSTag;
375 if length(AHSType) > 0 then
376 AHSType := piece(AHSType,':',1) + ';' + piece(AHSType,':',2); //format for backward compatibility
377 CallV('XWB DIRECT RPC', [ASite, ARemoteRPC, 0, Patient.DFN + ';' + Patient.ICN,
378 AReport, AHSType, ADaysBack, AExamID, Alpha, AOmega]);
379 QuickCopy(RPCBrokerV.Results,Dest);
380end;
381
382function ReportQualifierType(ReportType: Integer): Integer;
383var
384 i: Integer;
385begin
386 Result := 0;
387 for i := 0 to uReportsList.Count - 1 do
388 if StrToIntDef(Piece(uReportsList[i], U, 1), 0) = ReportType
389 then Result := StrToIntDef(Piece(uReportsList[i], U, 3), 0);
390end;
391
392function ImagingParams: String;
393begin
394 Result := sCallV('ORWTPD GETIMG',[nil]);
395end;
396
397function AutoRDV: String;
398begin
399 Result := sCallV('ORWCIRN AUTORDV', [nil]);
400end;
401
402function HDRActive: String;
403begin
404 Result := sCallV('ORWCIRN HDRON', [nil]);
405end;
406
407procedure PrintVReports(Dest, ADevice, AHeader: string; AReport: TStringList);
408begin
409 CallV('ORWRP PRINT V REPORT', [ADevice, Patient.DFN, AHeader, AReport]);
410end;
411
412procedure PrintReportsToDevice(AReport: string; const Qualifier, Patient, ADevice: string;
413 var ErrMsg: string; aComponents: TStringlist; ARemoteSiteID, ARemoteQuery, AHSTag: string);
414{ prints a report on the selected device }
415var
416 HSType, DaysBack, ExamID, MaxOcc, ARpt, x: string;
417 Alpha, Omega: double;
418 j: integer;
419 RemoteHandle,Report: string;
420 aHandles: TStringlist;
421begin
422 HSType := '';
423 DaysBack := '';
424 ExamID := '';
425 Alpha := 0;
426 Omega := 0;
427 aHandles := TStringList.Create;
428 if CharAt(Qualifier, 1) = 'T' then
429 begin
430 Alpha := StrToFMDateTime(Piece(Qualifier,';',1));
431 Omega := StrToFMDateTime(Piece(Qualifier,';',2));
432 MaxOcc := Piece(Qualifier,';',3);
433 SetPiece(AHSTag,';',4,MaxOcc);
434 end;
435 if CharAt(Qualifier, 1) = 'd' then
436 begin
437 MaxOcc := Piece(Qualifier,';',2);
438 SetPiece(AHSTag,';',4,MaxOcc);
439 x := Piece(Qualifier,';',1);
440 DaysBack := Copy(x, 2, Length(x));
441 end;
442 if CharAt(Qualifier, 1) = 'h' then HSType := Copy(Qualifier, 2, Length(Qualifier));
443 if CharAt(Qualifier, 1) = 'i' then ExamID := Copy(Qualifier, 2, Length(Qualifier));
444 if Length(ARemoteSiteID) > 0 then
445 begin
446 RemoteHandle := '';
447 for j := 0 to RemoteReports.Count - 1 do
448 begin
449 Report := TRemoteReport(RemoteReports.ReportList.Items[j]).Report;
450 if Report = ARemoteQuery then
451 begin
452 RemoteHandle := TRemoteReport(RemoteReports.ReportList.Items[j]).Handle
453 + '^' + Pieces(Report,'^',9,10);
454 break;
455 end;
456 end;
457 if Length(RemoteHandle) > 1 then
458 with RemoteSites.SiteList do
459 aHandles.Add(ARemoteSiteID + '^' + RemoteHandle);
460 end;
461 ARpt := AReport + '~' + AHSTag;
462 if aHandles.Count > 0 then
463 begin
464 ErrMsg := sCallV('ORWRP PRINT REMOTE REPORT',[ADevice, Patient, ARpt, aHandles]);
465 if Piece(ErrMsg, U, 1) = '0' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
466 end
467 else
468 begin
469 ErrMsg := sCallV('ORWRP PRINT REPORT',[ADevice, Patient, ARpt, HSType,
470 DaysBack, ExamID, aComponents, Alpha, Omega]);
471 if Piece(ErrMsg, U, 1) = '0' then ErrMsg := '' else ErrMsg := Piece(ErrMsg, U, 2);
472 end;
473 aHandles.Clear;
474 aHandles.Free;
475end;
476
477function GetFormattedReport(AReport: string; const Qualifier, Patient: string;
478 aComponents: TStringlist; ARemoteSiteID, ARemoteQuery, AHSTag: string): TStrings;
479{ prints a report on the selected device }
480var
481 HSType, DaysBack, ExamID, MaxOcc, ARpt, x: string;
482 Alpha, Omega: double;
483 j: integer;
484 RemoteHandle,Report: string;
485 aHandles: TStringlist;
486begin
487 HSType := '';
488 DaysBack := '';
489 ExamID := '';
490 Alpha := 0;
491 Omega := 0;
492 aHandles := TStringList.Create;
493 if CharAt(Qualifier, 1) = 'T' then
494 begin
495 Alpha := StrToFMDateTime(Piece(Qualifier,';',1));
496 Omega := StrToFMDateTime(Piece(Qualifier,';',2));
497 MaxOcc := Piece(Qualifier,';',3);
498 SetPiece(AHSTag,';',4,MaxOcc);
499 end;
500 if CharAt(Qualifier, 1) = 'd' then
501 begin
502 MaxOcc := Piece(Qualifier,';',2);
503 SetPiece(AHSTag,';',4,MaxOcc);
504 x := Piece(Qualifier,';',1);
505 DaysBack := Copy(x, 2, Length(x));
506 end;
507 if CharAt(Qualifier, 1) = 'h' then HSType := Copy(Qualifier, 2, Length(Qualifier));
508 if CharAt(Qualifier, 1) = 'i' then ExamID := Copy(Qualifier, 2, Length(Qualifier));
509 if Length(ARemoteSiteID) > 0 then
510 begin
511 RemoteHandle := '';
512 for j := 0 to RemoteReports.Count - 1 do
513 begin
514 Report := TRemoteReport(RemoteReports.ReportList.Items[j]).Report;
515 if Report = ARemoteQuery then
516 begin
517 RemoteHandle := TRemoteReport(RemoteReports.ReportList.Items[j]).Handle
518 + '^' + Pieces(Report,'^',9,10);
519 break;
520 end;
521 end;
522 if Length(RemoteHandle) > 1 then
523 with RemoteSites.SiteList do
524 aHandles.Add(ARemoteSiteID + '^' + RemoteHandle);
525 end;
526 ARpt := AReport + '~' + AHSTag;
527 if aHandles.Count > 0 then
528 begin
529 CallV('ORWRP PRINT WINDOWS REMOTE',[Patient, ARpt, aHandles]);
530 Result := RPCBrokerV.Results;
531 end
532 else
533 begin
534 CallV('ORWRP PRINT WINDOWS REPORT',[Patient, ARpt, HSType,
535 DaysBack, ExamID, aComponents, Alpha, Omega]);
536 Result := RPCBrokerV.Results;
537 end;
538 aHandles.Clear;
539 aHandles.Free;
540end;
541
542function DefaultToWindowsPrinter: Boolean;
543begin
544 Result := (StrToIntDef(sCallV('ORWRP WINPRINT DEFAULT',[]), 0) > 0);
545end;
546
547procedure PrintWindowsReport(ARichEdit: TRichEdit; APageBreak, Atitle: string;
548 var ErrMsg: string;
549 Application : TApplication //kt added 8/09
550 );
551var
552 i, j, x, y, LineHeight: integer;
553 aGoHead: string;
554 aHeader: TStringList;
555 Header,Footer,TempLines: TStringList; //kt added 8/09
556 IsHTML : Boolean; //kt added 8/09
557
558const
559//TX_ERR_CAP = 'Print Error'; <-- original line. //kt 8/20/2007
560 TX_FONT_SIZE = 10;
561//TX_FONT_NAME = 'Courier New'; <-- original line. //kt 8/20/2007
562var
563 TX_ERR_CAP : string; //kt
564 TX_FONT_NAME : string ;//kt
565
566begin
567 TX_ERR_CAP := DKLangConstW('rReports_Print_Error'); //kt added 8/20/2007
568 TX_FONT_NAME := DKLangConstW('rReports_Courier_New'); //kt added 8/20/2007
569
570 aHeader := TStringList.Create;
571 aGoHead := '';
572 if piece(Atitle,';',2) = '1' then
573 begin
574 Atitle := piece(Atitle,';',1);
575 aGoHead := '1';
576 end;
577 CreatePatientHeader(aHeader ,ATitle);
578 IsHTML := rHTMLTools.IsHTML(ARichEdit.Lines); //kt 8/09
579 if not IsHTML then begin //kt 8/09
580 with ARichEdit do begin
581 (* if Lines[Lines.Count - 1] = APageBreak then // remove trailing form feed
582 Lines.Delete(Lines.Count - 1);
583 while (Lines[0] = '') or (Lines[0] = APageBreak) do
584 Lines.Delete(0); // remove leading blank lines and form feeds*)
585
586 {v20.4 - SFC-0602-62899 - RV}
587 while (Lines.Count > 0) and ((Lines[Lines.Count - 1] = '') or (Lines[Lines.Count - 1] = APageBreak)) do
588 Lines.Delete(Lines.Count - 1); // remove trailing blank lines and form feeds
589 while (Lines.Count > 0) and ((Lines[0] = '') or (Lines[0] = APageBreak)) do
590 Lines.Delete(0); // remove leading blank lines and form feeds
591
592 if Lines.Count > 1 then begin
593 (* i := Lines.IndexOf(APageBreak);
594 if ((i >= 0 ) and (i < Lines.Count - 1)) then // removed in v15.9 (RV)
595 begin*)
596 Printer.Canvas.Font.Size := TX_FONT_SIZE;
597 Printer.Canvas.Font.Name := TX_FONT_NAME;
598 Printer.Title := ATitle;
599 x := Trunc(Printer.Canvas.TextWidth(StringOfChar('=', TX_FONT_SIZE)) * 0.75);
600 LineHeight := Printer.Canvas.TextHeight(TX_FONT_NAME);
601 y := LineHeight * 5; // 5 lines = .83" top margin v15.9 (RV)
602 Printer.BeginDoc;
603 for i := 0 to Lines.Count - 1 do begin
604 if Lines[i] = APageBreak then begin
605 Printer.NewPage;
606 y := LineHeight * 5; // 5 lines = .83" top margin v15.9 (RV)
607 if aGoHead = '1' then begin
608 for j := 0 to aHeader.Count - 1 do begin
609 Printer.Canvas.TextOut(x, y, aHeader[j]);
610 y := y + LineHeight;
611 end;
612 end;
613 end else begin
614 Printer.Canvas.TextOut(x, y, Lines[i]);
615 y := y + LineHeight;
616 end;
617 end;
618 Printer.EndDoc;
619(* end
620 else // removed in v15.9 (RV) TRichEdit.Print no longer used.
621 try
622 Font.Size := TX_FONT_SIZE;
623 Font.Name := TX_FONT_NAME;
624 Print(ATitle);
625 except
626 ErrMsg := TX_ERR_CAP;
627 end;*)
628 end else if ARichEdit.Lines.Count = 1 then
629 if Piece(ARichEdit.Lines[0], U, 1) <> '0' then
630 ErrMsg := Piece(ARichEdit.Lines[0], U, 2);
631 end;
632 end else begin //kt added this entire block. 8/09
633 TempLines := TStringList.Create;
634 Header := TStringList.Create;
635 Footer := TStringList.Create;
636 TempLines.Assign(ARichEdit.Lines);
637 StripBeforeAfterHTML(TempLines,Header,Footer);
638 //LoadDocumentText(TempLines, FNote); //Get document without headers/footers
639 PrintHTMLReport(TempLines,ErrMsg,
640 Patient.Name,
641 FormatFMDateTime('mm/dd/yyyy', Patient.DOB),' ',
642 Encounter.LocationName,Application);
643 TempLines.Free;
644 Header.Free;
645 Footer.Free;
646 end; //kt end of added block 8/09
647 aHeader.Free;
648end;
649
650procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle: string);
651// standard patient header, from HEAD^ORWRPP
652var
653 tmpStr, tmpItem: string;
654begin
655 with HeaderList do
656 begin
657 Add(' ');
658 Add(StringOfChar(' ', (74 - Length(PageTitle)) div 2) + PageTitle);
659 Add(' ');
660 tmpStr := Patient.Name + ' ' + Patient.SSN;
661 tmpItem := tmpStr + StringOfChar(' ', 39 - Length(tmpStr)) + Encounter.LocationName;
662 tmpStr := FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + IntToStr(Patient.Age) + ')';
663 tmpItem := tmpItem + StringOfChar(' ', 74 - (Length(tmpItem) + Length(tmpStr))) + tmpStr;
664 Add(tmpItem);
665 Add(StringOfChar('=', 74));
666 Add('*** WORK COPY ONLY ***' + StringOfChar(' ', 24) + 'Printed: ' + FormatFMDateTime('mmm dd, yyyy hh:nn', FMNow));
667 Add(' ');
668 Add(' ');
669 end;
670end;
671
672procedure PrintGraph(GraphImage: TChart; PageTitle: string);
673var
674 AHeader: TStringList;
675 i, y, LineHeight: integer;
676 GraphPic: TBitMap;
677 Magnif: integer;
678const
679 TX_FONT_SIZE = 12;
680//TX_FONT_NAME = 'Courier New'; <-- original line. //kt 8/20/2007
681 CF_BITMAP = 2; // from Windows.pas
682var
683 TX_FONT_NAME : string; //kt
684
685begin
686 TX_FONT_NAME := DKLangConstW('rReports_Courier_New'); //kt added 8/20/2007
687 ClipBoard;
688 AHeader := TStringList.Create;
689 CreatePatientHeader(AHeader, PageTitle);
690 GraphPic := TBitMap.Create;
691 try
692 GraphImage.CopyToClipboardBitMap;
693 GraphPic.LoadFromClipBoardFormat(CF_BITMAP, ClipBoard.GetAsHandle(CF_BITMAP), 0);
694 with Printer do
695 begin
696 Canvas.Font.Size := TX_FONT_SIZE;
697 Canvas.Font.Name := TX_FONT_NAME;
698 Title := PageTitle;
699 Magnif := (Canvas.TextWidth(StringOfChar('=', 74)) div GraphImage.Width);
700 LineHeight := Printer.Canvas.TextHeight(TX_FONT_NAME);
701 y := LineHeight;
702 BeginDoc;
703 try
704 for i := 0 to AHeader.Count - 1 do
705 begin
706 Canvas.TextOut(0, y, AHeader[i]);
707 y := y + LineHeight;
708 end;
709 y := y + (4 * LineHeight);
710 //GraphImage.PrintPartial(Rect(0, y, Canvas.TextWidth(StringOfChar('=', 74)), y + (Magnif * GraphImage.Height)));
711 PrintBitmap(Canvas, Rect(0, y, Canvas.TextWidth(StringOfChar('=', 74)), y + (Magnif * GraphImage.Height)), GraphPic);
712 finally
713 EndDoc;
714 end;
715 end;
716 finally
717 ClipBoard.Clear;
718 GraphPic.Free;
719 AHeader.Free;
720 end;
721end;
722
723procedure SaveDefaultPrinter(DefPrinter: string) ;
724begin
725 CallV('ORWRP SAVE DEFAULT PRINTER', [DefPrinter]);
726end;
727
728function HSFileLookup(aFile: String; const StartFrom: string;
729 Direction:Integer): TStrings;
730begin
731 CallV('ORWRP2 HS FILE LOOKUP', [aFile, StartFrom, Direction]);
732 MixedCaseList(RPCBrokerV.Results);
733 Result := RPCBrokerV.Results;
734end;
735
736procedure HSComponentFiles(Dest: TStrings; aComponent: String);
737begin
738 CallV('ORWRP2 HS COMP FILES', [aComponent]);
739 QuickCopy(RPCBrokerV.Results,Dest);
740end;
741
742procedure HSSubItems(Dest: TStrings; aItem: String);
743begin
744 CallV('ORWRP2 HS SUBITEMS', [aItem]);
745 MixedCaseList(RPCBrokerV.Results);
746 QuickCopy(RPCBrokerV.Results,Dest);
747end;
748
749procedure HSReportText(Dest: TStrings; aComponents: TStringlist);
750begin
751 CallV('ORWRP2 HS REPORT TEXT', [aComponents, Patient.DFN]);
752 QuickCopy(RPCBrokerV.Results,Dest);
753end;
754
755procedure HSComponents(Dest: TStrings);
756begin
757 CallV('ORWRP2 HS COMPONENTS', [nil]);
758 QuickCopy(RPCBrokerV.Results,Dest);
759end;
760
761procedure HSABVComponents(Dest: TStrings);
762begin
763 CallV('ORWRP2 COMPABV', [nil]);
764 QuickCopy(RPCBrokerV.Results,Dest);
765end;
766
767procedure HSDispComponents(Dest: TStrings);
768begin
769 CallV('ORWRP2 COMPDISP', [nil]);
770 QuickCopy(RPCBrokerV.Results,Dest);
771end;
772
773procedure HSComponentSubs(Dest: TStrings; aItem: String);
774begin
775 CallV('ORWRP2 HS COMPONENT SUBS',[aItem]);
776 MixedCaseList(RPCBrokerV.Results);
777 QuickCopy(RPCBrokerV.Results,Dest);
778end;
779
780function GetRemoteStatus(aHandle: string): String;
781begin
782 CallV('XWB REMOTE STATUS CHECK', [aHandle]);
783 Result := RPCBrokerV.Results[0];
784end;
785
786function GetAdhocLookup: integer;
787begin
788 CallV('ORWRP2 GETLKUP', [nil]);
789 if RPCBrokerV.Results.Count > 0 then
790 Result := StrToInt(RPCBrokerV.Results[0])
791 else
792 Result := 0;
793end;
794
795procedure SetAdhocLookup(aLookup: integer);
796
797begin
798 CallV('ORWRP2 SAVLKUP', [IntToStr(aLookup)]);
799end;
800
801procedure GetRemoteData(Dest: TStrings; aHandle: string; aItem: PChar);
802begin
803 CallV('XWB REMOTE GETDATA', [aHandle]);
804 if RPCBrokerV.Results.Count < 1 then
805// RPCBrokerV.Results[0] := 'No data found.'; <-- original line. //kt 8/20/2007
806 RPCBrokerV.Results[0] := DKLangConstW('rReports_No_data_foundx'); //kt added 8/20/2007
807 if (RPCBrokerV.Results.Count < 2) and (RPCBrokerV.Results[0] = '') then
808// RPCBrokerV.Results[0] := 'No data found.'; <-- original line. //kt 8/20/2007
809 RPCBrokerV.Results[0] := DKLangConstW('rReports_No_data_foundx'); //kt added 8/20/2007
810 QuickCopy(RPCBrokerV.Results,Dest);
811end;
812
813procedure ModifyHDRData(Dest: string; aHandle: string; aID: string);
814begin
815 CallV('ORWRP4 HDR MODIFY', [aHandle, aID]);
816end;
817
818procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
819var
820 BitmapHeader: pBitmapInfo;
821 BitmapImage : POINTER;
822 HeaderSize : DWORD; // Use DWORD for D3-D5 compatibility
823 ImageSize : DWORD;
824begin
825 GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
826 GetMem(BitmapHeader, HeaderSize);
827 GetMem(BitmapImage, ImageSize);
828 try
829 GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
830 StretchDIBits(Canvas.Handle,
831 DestRect.Left, DestRect.Top, // Destination Origin
832 DestRect.Right - DestRect.Left, // Destination Width
833 DestRect.Bottom - DestRect.Top, // Destination Height
834 0, 0, // Source Origin
835 Bitmap.Width, Bitmap.Height, // Source Width & Height
836 BitmapImage,
837 TBitmapInfo(BitmapHeader^),
838 DIB_RGB_COLORS,
839 SRCCOPY)
840 finally
841 FreeMem(BitmapHeader);
842 FreeMem(BitmapImage)
843 end
844end {PrintBitmap};
845
846initialization
847 { nothing to initialize }
848
849finalization
850 uTree.Free;
851 uReportsList.Free;
852 uLabReports.Free;
853 uDateRanges.Free;
854 uHSTypes.Free;
855
856end.
Note: See TracBrowser for help on using the repository browser.