source: cprs/trunk/CPRS-Chart/rReports.pas@ 929

Last change on this file since 929 was 830, checked in by Kevin Toppenberg, 14 years ago

Upgrading to version 27

File size: 26.8 KB
Line 
1unit rReports;
2
3interface
4
5uses Windows, SysUtils, Classes, ORNet, ORFn, ComCtrls, Chart, graphics;
6
7{ Consults }
8procedure ListConsults(Dest: TStrings);
9procedure LoadConsultText(Dest: TStrings; IEN: Integer);
10
11{ Reports }
12procedure ListReports(Dest: TStrings);
13procedure ListLabReports(Dest: TStrings);
14procedure ListReportDateRanges(Dest: TStrings);
15procedure ListHealthSummaryTypes(Dest: TStrings);
16procedure ListImagingExams(Dest: TStrings);
17procedure ListProcedures(Dest: TStrings);
18procedure ListNutrAssessments(Dest: TStrings);
19procedure ListSurgeryReports(Dest: TStrings);
20procedure ColumnHeaders(Dest: TStrings; AReportType: String);
21procedure SaveColumnSizes(aColumn: String);
22procedure LoadReportText(Dest: TStrings; ReportType: string; const Qualifier: string; ARpc, AHSTag: string);
23procedure RemoteQueryAbortAll;
24procedure RemoteQuery(Dest: TStrings; AReportType: string; AHSType, ADaysback,
25 AExamID: string; Alpha, AOmega: Double; ASite, ARemoteRPC, AHSTag: String);
26procedure DirectQuery(Dest: TStrings; AReportType: string; AHSType, ADaysback,
27 AExamID: string; Alpha, AOmega: Double; ASite, ARemoteRPC, AHSTag: String);
28function ReportQualifierType(ReportType: Integer): Integer;
29function ImagingParams: String;
30function AutoRDV: String;
31function HDRActive: String;
32procedure PrintReportsToDevice(AReport: string; const Qualifier, Patient,
33 ADevice: string; var ErrMsg: string; aComponents: TStringlist;
34 ARemoteSiteID, ARemoteQuery, AHSTag: string);
35function HSFileLookup(aFile: String; const StartFrom: string;
36 Direction: Integer): TStrings;
37procedure HSComponentFiles(Dest: TStrings; aComponent: String);
38procedure HSSubItems(Dest: TStrings; aItem: String);
39procedure HSReportText(Dest: TStrings; aComponents: TStringlist);
40procedure HSComponents(Dest: TStrings);
41procedure HSABVComponents(Dest: TStrings);
42procedure HSDispComponents(Dest: TStrings);
43procedure HSComponentSubs(Dest: TStrings; aItem: String);
44procedure HealthSummaryCheck(Dest: TStrings; aQualifier: string);
45function GetFormattedReport(AReport: string; const Qualifier, Patient: string;
46 aComponents: TStringlist; ARemoteSiteID, ARemoteQuery, AHSTag: string): TStrings;
47procedure PrintWindowsReport(ARichEdit: TRichEdit; APageBreak, ATitle: string;
48 var ErrMsg: string);
49function DefaultToWindowsPrinter: Boolean;
50procedure PrintGraph(GraphImage: TChart; PageTitle: string);
51procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
52procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle: string);
53procedure SaveDefaultPrinter(DefPrinter: string) ;
54function GetRemoteStatus(aHandle: string): String;
55function GetAdhocLookup: integer;
56procedure SetAdhocLookup(aLookup: integer);
57procedure GetRemoteData(Dest: TStrings; aHandle: string; aItem: PChar);
58procedure ModifyHDRData(Dest: string; aHandle: string; aID: string);
59procedure PrintVReports(Dest, ADevice, AHeader: string; AReport: TStringList);
60
61implementation
62
63uses uCore, rCore, Printers, clipbrd, uReports, fReports
64{ TODO -oRV -cWVEHR Long Age : Changed to use long age }
65, rWVEHR;
66
67var
68 uTree: TStringList;
69 uReportsList: TStringList;
70 uLabReports: TStringList;
71 uDateRanges: TStringList;
72 uHSTypes: TStringList;
73
74{ Consults }
75
76procedure ListConsults(Dest: TStrings);
77var
78 i: Integer;
79 x: string;
80begin
81 CallV('ORWCS LIST OF CONSULT REPORTS', [Patient.DFN]);
82 with RPCBrokerV do
83 begin
84 SortByPiece(TStringList(Results), U, 2);
85 InvertStringList(TStringList(Results));
86 SetListFMDateTime('mmm dd,yy', TStringList(Results), U, 2);
87 for i := 0 to Results.Count - 1 do
88 begin
89 x := Results[i];
90 x := Pieces(x, U, 1, 2) + U + Piece(x, U, 3) + ' (' + Piece(x, U, 4) + ')';
91 Results[i] := x;
92 end;
93 FastAssign(Results, Dest);
94 end;
95end;
96
97procedure LoadConsultText(Dest: TStrings; IEN: Integer);
98begin
99 CallV('ORWCS REPORT TEXT', [Patient.DFN, IEN]);
100 QuickCopy(RPCBrokerV.Results,Dest);
101end;
102
103{ Reports }
104
105procedure ExtractSection(Dest: TStrings; const Section: string; Mixed: Boolean);
106var
107 i: Integer;
108begin
109 with RPCBrokerV do
110 begin
111 i := -1;
112 repeat Inc(i) until (i = Results.Count) or (Results[i] = Section);
113 Inc(i);
114 while (i < Results.Count) and (Results[i] <> '$$END') do
115 begin
116 {if (Pos('OR_ECS',UpperCase(Results[i]))>0) and (not uECSReport.ECSPermit) then
117 begin
118 Inc(i);
119 Continue;
120 end;}
121 if Mixed = true then
122 Dest.Add(MixedCase(Results[i]))
123 else
124 Dest.Add(Results[i]);
125 Inc(i);
126 end;
127 end;
128end;
129
130procedure LoadReportLists;
131begin
132 CallV('ORWRP REPORT LISTS', [nil]);
133 uDateRanges := TStringList.Create;
134 uHSTypes := TStringList.Create;
135 uReportsList := TStringList.Create;
136 ExtractSection(uDateRanges, '[DATE RANGES]', true);
137 ExtractSection(uHSTypes, '[HEALTH SUMMARY TYPES]', true);
138 ExtractSection(uReportsList, '[REPORT LIST]', true);
139end;
140
141procedure LoadLabReportLists;
142begin
143 CallV('ORWRP LAB REPORT LISTS', [nil]);
144 uLabReports := TStringList.Create;
145 ExtractSection(uLabReports, '[LAB REPORT LIST]', true);
146end;
147
148procedure LoadTree(Tab: String);
149begin
150 CallV('ORWRP3 EXPAND COLUMNS', [Tab]);
151 uTree := TStringList.Create;
152 ExtractSection(uTree, '[REPORT LIST]', false);
153end;
154
155procedure ListReports(Dest: TStrings);
156var
157 i: Integer;
158begin
159 if uTree = nil
160 then LoadTree('REPORTS')
161 else
162 begin
163 uTree.Clear;
164 LoadTree('REPORTS');
165 end;
166 for i := 0 to uTree.Count - 1 do Dest.Add(Pieces(uTree[i], '^', 1, 20));
167end;
168
169procedure ListLabReports(Dest: TStrings);
170var
171 i: integer;
172begin
173 {if uLabreports = nil then LoadLabReportLists;
174 for i := 0 to uLabReports.Count - 1 do Dest.Add(Pieces(uLabReports[i], U, 1, 10)); }
175 if uTree = nil
176 then LoadTree('LABS')
177 else
178 begin
179 uTree.Clear;
180 LoadTree('LABS');
181 end;
182 for i := 0 to uTree.Count - 1 do Dest.Add(Pieces(uTree[i], '^', 1, 20));
183end;
184
185procedure ListReportDateRanges(Dest: TStrings);
186begin
187 if uDateRanges = nil then LoadReportLists;
188 FastAssign(uDateRanges, Dest);
189end;
190
191procedure ListHealthSummaryTypes(Dest: TStrings);
192begin
193 if uHSTypes = nil then LoadReportLists;
194 MixedCaseList(uHSTypes);
195 FastAssign(uHSTypes, Dest);
196end;
197
198procedure HealthSummaryCheck(Dest: TStrings; aQualifier: string);
199
200begin
201 if aQualifier = '1' then
202 begin
203 ListHealthSummaryTypes(Dest);
204 end;
205end;
206
207procedure ColumnHeaders(Dest: TStrings; AReportType: String);
208begin
209 CallV('ORWRP COLUMN HEADERS',[AReportType]);
210 FastAssign(RPCBrokerV.Results, Dest);
211end;
212
213procedure SaveColumnSizes(aColumn: String);
214begin
215 CallV('ORWCH SAVECOL', [aColumn]);
216end;
217
218procedure ListImagingExams(Dest: TStrings);
219var
220 x: string;
221 i: Integer;
222begin
223 CallV('ORWRA IMAGING EXAMS1', [Patient.DFN]);
224 with RPCBrokerV do
225 begin
226 SetListFMDateTime('mm/dd/yyyy hh:nn', TStringList(Results), U, 3);
227 for i := 0 to Results.Count - 1 do
228 begin
229 x := Results[i];
230 if Piece(x,U,7) = 'Y' then SetPiece(x,U,7, ' - Abnormal');
231 x := Piece(x,U,1) + U + 'i' + Pieces(x,U,2,3)+ U + Piece(x,U,4)
232 + U + Piece(x,U,6) + Piece(x,U,7) + U
233 + MixedCase(Piece(Piece(x,U,9),'~',2)) + U + Piece(x,U,5) + U + '[+]'
234 + U + Pieces(x, U, 15,17);
235(* x := Piece(x,U,1) + U + 'i' + Pieces(x,U,2,3)+ U + Piece(x,U,4)
236 + U + Piece(x,U,6) + Piece(x,U,7) + U + Piece(x,U,5) + U + '[+]' + U + Piece(x, U, 15);*)
237 Results[i] := x;
238 end;
239 FastAssign(Results, Dest);
240 end;
241end;
242
243procedure ListProcedures(Dest: TStrings);
244var
245 x,sdate: string;
246 i: Integer;
247begin
248 CallV('ORWMC PATIENT PROCEDURES1', [Patient.DFN]);
249 with RPCBrokerV do
250 begin
251 for i := 0 to Results.Count - 1 do
252 begin
253 x := Results[i];
254 if length(piece(x, U, 8)) > 0 then
255 begin
256 sdate := ShortDateStrToDate(piece(piece(x, U, 8),'@',1)) + ' ' + piece(piece(x, U, 8),'@',2);
257 end;
258 x := Piece(x, U, 1) + U + 'i' + Piece(x, U, 2) + U + sdate + U + Piece(x, U, 3) + U + Piece(x, U, 9) + '^[+]';
259 Results[i] := x;
260 end;
261 FastAssign(Results, Dest);
262 end;
263end;
264
265procedure ListNutrAssessments(Dest: TStrings);
266var
267 x: string;
268 i: Integer;
269begin
270 CallV('ORWRP1 LISTNUTR', [Patient.DFN]);
271 with RPCBrokerV do
272 begin
273 for i := 0 to Results.Count - 1 do
274 begin
275 x := Results[i];
276 x := Piece(x, U, 1) + U + 'i' + Piece(x, U, 3) + U + Piece(x, U, 3);
277 Results[i] := x;
278 end;
279 FastAssign(Results, Dest);
280 end;
281end;
282
283procedure ListSurgeryReports(Dest: TStrings);
284{ returns a list of surgery cases for a patient, without documents}
285//Facility^Case #^Date/Time of Operation^Operative Procedure^Surgeon name)
286var
287 i: integer;
288 x, AFormat: string;
289begin
290 CallV('ORWSR RPTLIST', [Patient.DFN]);
291 with RPCBrokerV do
292 begin
293 for i := 0 to Results.Count - 1 do
294 begin
295 x := Results[i];
296 if Piece(Piece(x, U, 3), '.', 2) = '' then AFormat := 'mm/dd/yyyy' else AFormat := 'mm/dd/yyyy hh:nn';
297 x := Piece(x, U, 1) + U + 'i' + Piece(x, U, 2) + U + FormatFMDateTimeStr(AFormat, Piece(x, U, 3))+ U +
298 Piece(x, U, 4)+ U + Piece(x, U, 5);
299 if Piece(Results[i], U, 6) = '+' then x := x + '^[+]';
300 Results[i] := x;
301 end;
302 FastAssign(Results, Dest);
303 end;
304end;
305
306procedure LoadReportText(Dest: TStrings; ReportType: string; const Qualifier: string; ARpc, AHSTag: string);
307var
308 HSType, DaysBack, ExamID, MaxOcc, AReport, x: string;
309 Alpha, Omega, Trans: double;
310begin
311 HSType := '';
312 DaysBack := '';
313 ExamID := '';
314 Alpha := 0;
315 Omega := 0;
316 if CharAt(Qualifier, 1) = 'T' then
317 begin
318 Alpha := StrToFMDateTime(Piece(Qualifier,';',1));
319 Omega := StrToFMDateTime(Piece(Qualifier,';',2));
320 if Alpha > Omega then
321 begin
322 Trans := Omega;
323 Omega := Alpha;
324 Alpha := Trans;
325 end;
326 MaxOcc := Piece(Qualifier,';',3);
327 SetPiece(AHSTag,';',4,MaxOcc);
328 end;
329 if CharAt(Qualifier, 1) = 'd' then
330 begin
331 MaxOcc := Piece(Qualifier,';',2);
332 SetPiece(AHSTag,';',4,MaxOcc);
333 x := Piece(Qualifier,';',1);
334 DaysBack := Copy(x, 2, Length(x));
335 end;
336 if CharAt(Qualifier, 1) = 'h' then HSType := Copy(Qualifier, 2, Length(Qualifier));
337 if CharAt(Qualifier, 1) = 'i' then ExamID := Copy(Qualifier, 2, Length(Qualifier));
338 AReport := ReportType + '~' + AHSTag;
339 if Length(ARpc) > 0 then
340 begin
341 CallV(ARpc, [Patient.DFN, AReport, HSType, DaysBack, ExamID, Alpha, Omega]);
342 QuickCopy(RPCBrokerV.Results,Dest);
343 end
344 else
345 begin
346 Dest.Add('RPC is missing from report definition (file 101.24).');
347 Dest.Add('Please contact Technical Support.');
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; var ErrMsg: string);
548var
549 i, j, x, y, LineHeight: integer;
550 aGoHead: string;
551 aHeader: TStringList;
552const
553 TX_ERR_CAP = 'Print Error';
554 TX_FONT_SIZE = 10;
555 TX_FONT_NAME = 'Courier New';
556begin
557 aHeader := TStringList.Create;
558 aGoHead := '';
559 if piece(Atitle,';',2) = '1' then
560 begin
561 Atitle := piece(Atitle,';',1);
562 aGoHead := '1';
563 end;
564 CreatePatientHeader(aHeader ,ATitle);
565 with ARichEdit do
566 begin
567(* if Lines[Lines.Count - 1] = APageBreak then // remove trailing form feed
568 Lines.Delete(Lines.Count - 1);
569 while (Lines[0] = '') or (Lines[0] = APageBreak) do
570 Lines.Delete(0); // remove leading blank lines and form feeds*)
571
572 {v20.4 - SFC-0602-62899 - RV}
573 while (Lines.Count > 0) and ((Lines[Lines.Count - 1] = '') or (Lines[Lines.Count - 1] = APageBreak)) do
574 Lines.Delete(Lines.Count - 1); // remove trailing blank lines and form feeds
575 while (Lines.Count > 0) and ((Lines[0] = '') or (Lines[0] = APageBreak)) do
576 Lines.Delete(0); // remove leading blank lines and form feeds
577
578 if Lines.Count > 1 then
579 begin
580(* i := Lines.IndexOf(APageBreak);
581 if ((i >= 0 ) and (i < Lines.Count - 1)) then // removed in v15.9 (RV)
582 begin*)
583 Printer.Canvas.Font.Size := TX_FONT_SIZE;
584 Printer.Canvas.Font.Name := TX_FONT_NAME;
585 Printer.Title := ATitle;
586 x := Trunc(Printer.Canvas.TextWidth(StringOfChar('=', TX_FONT_SIZE)) * 0.75);
587 LineHeight := Printer.Canvas.TextHeight(TX_FONT_NAME);
588 y := LineHeight * 5; // 5 lines = .83" top margin v15.9 (RV)
589 Printer.BeginDoc;
590 for i := 0 to Lines.Count - 1 do
591 begin
592 if Lines[i] = APageBreak then
593 begin
594 Printer.NewPage;
595 y := LineHeight * 5; // 5 lines = .83" top margin v15.9 (RV)
596 if aGoHead = '1' then
597 begin
598 for j := 0 to aHeader.Count - 1 do
599 begin
600 Printer.Canvas.TextOut(x, y, aHeader[j]);
601 y := y + LineHeight;
602 end;
603 end;
604 end
605 else
606 begin
607 Printer.Canvas.TextOut(x, y, Lines[i]);
608 y := y + LineHeight;
609 end;
610 end;
611 Printer.EndDoc;
612(* end
613 else // removed in v15.9 (RV) TRichEdit.Print no longer used.
614 try
615 Font.Size := TX_FONT_SIZE;
616 Font.Name := TX_FONT_NAME;
617 Print(ATitle);
618 except
619 ErrMsg := TX_ERR_CAP;
620 end;*)
621 end
622 else if ARichEdit.Lines.Count = 1 then
623 if Piece(ARichEdit.Lines[0], U, 1) <> '0' then
624 ErrMsg := Piece(ARichEdit.Lines[0], U, 2);
625 end;
626 aHeader.Free;
627end;
628
629procedure CreatePatientHeader(var HeaderList: TStringList; PageTitle: string);
630// standard patient header, from HEAD^ORWRPP
631var
632 tmpStr, tmpItem: string;
633begin
634 with HeaderList do
635 begin
636 Add(' ');
637 Add(StringOfChar(' ', (74 - Length(PageTitle)) div 2) + PageTitle);
638 Add(' ');
639 tmpStr := Patient.Name + ' ' + Patient.SSN;
640 tmpItem := tmpStr + StringOfChar(' ', 39 - Length(tmpStr)) + Encounter.LocationName;
641{ TODO -oRV -cWVEHR Long Age : Changed to use long age }
642 //tmpStr := FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + IntToStr(Patient.Age) + ')';
643 tmpStr := FormatFMDateTime('mmm dd, yyyy', Patient.DOB) + ' (' + GetPatientBriefAge(Patient.DFN) + ')';
644{}
645 tmpItem := tmpItem + StringOfChar(' ', 74 - (Length(tmpItem) + Length(tmpStr))) + tmpStr;
646 Add(tmpItem);
647 Add(StringOfChar('=', 74));
648 Add('*** WORK COPY ONLY ***' + StringOfChar(' ', 24) + 'Printed: ' + FormatFMDateTime('mmm dd, yyyy hh:nn', FMNow));
649 Add(' ');
650 Add(' ');
651 end;
652end;
653
654procedure PrintGraph(GraphImage: TChart; PageTitle: string);
655var
656 AHeader: TStringList;
657 i, y, LineHeight: integer;
658 GraphPic: TBitMap;
659 Magnif: integer;
660const
661 TX_FONT_SIZE = 12;
662 TX_FONT_NAME = 'Courier New';
663 CF_BITMAP = 2; // from Windows.pas
664begin
665 ClipBoard;
666 AHeader := TStringList.Create;
667 CreatePatientHeader(AHeader, PageTitle);
668 GraphPic := TBitMap.Create;
669 try
670 GraphImage.CopyToClipboardBitMap;
671 GraphPic.LoadFromClipBoardFormat(CF_BITMAP, ClipBoard.GetAsHandle(CF_BITMAP), 0);
672 with Printer do
673 begin
674 Canvas.Font.Size := TX_FONT_SIZE;
675 Canvas.Font.Name := TX_FONT_NAME;
676 Title := PageTitle;
677 Magnif := (Canvas.TextWidth(StringOfChar('=', 74)) div GraphImage.Width);
678 LineHeight := Printer.Canvas.TextHeight(TX_FONT_NAME);
679 y := LineHeight;
680 BeginDoc;
681 try
682 for i := 0 to AHeader.Count - 1 do
683 begin
684 Canvas.TextOut(0, y, AHeader[i]);
685 y := y + LineHeight;
686 end;
687 y := y + (4 * LineHeight);
688 //GraphImage.PrintPartial(Rect(0, y, Canvas.TextWidth(StringOfChar('=', 74)), y + (Magnif * GraphImage.Height)));
689 PrintBitmap(Canvas, Rect(0, y, Canvas.TextWidth(StringOfChar('=', 74)), y + (Magnif * GraphImage.Height)), GraphPic);
690 finally
691 EndDoc;
692 end;
693 end;
694 finally
695 ClipBoard.Clear;
696 GraphPic.Free;
697 AHeader.Free;
698 end;
699end;
700
701procedure SaveDefaultPrinter(DefPrinter: string) ;
702begin
703 CallV('ORWRP SAVE DEFAULT PRINTER', [DefPrinter]);
704end;
705
706function HSFileLookup(aFile: String; const StartFrom: string;
707 Direction:Integer): TStrings;
708begin
709 CallV('ORWRP2 HS FILE LOOKUP', [aFile, StartFrom, Direction]);
710 MixedCaseList(RPCBrokerV.Results);
711 Result := RPCBrokerV.Results;
712end;
713
714procedure HSComponentFiles(Dest: TStrings; aComponent: String);
715begin
716 CallV('ORWRP2 HS COMP FILES', [aComponent]);
717 QuickCopy(RPCBrokerV.Results,Dest);
718end;
719
720procedure HSSubItems(Dest: TStrings; aItem: String);
721begin
722 CallV('ORWRP2 HS SUBITEMS', [aItem]);
723 MixedCaseList(RPCBrokerV.Results);
724 QuickCopy(RPCBrokerV.Results,Dest);
725end;
726
727procedure HSReportText(Dest: TStrings; aComponents: TStringlist);
728begin
729 CallV('ORWRP2 HS REPORT TEXT', [aComponents, Patient.DFN]);
730 QuickCopy(RPCBrokerV.Results,Dest);
731end;
732
733procedure HSComponents(Dest: TStrings);
734begin
735 CallV('ORWRP2 HS COMPONENTS', [nil]);
736 QuickCopy(RPCBrokerV.Results,Dest);
737end;
738
739procedure HSABVComponents(Dest: TStrings);
740begin
741 CallV('ORWRP2 COMPABV', [nil]);
742 QuickCopy(RPCBrokerV.Results,Dest);
743end;
744
745procedure HSDispComponents(Dest: TStrings);
746begin
747 CallV('ORWRP2 COMPDISP', [nil]);
748 QuickCopy(RPCBrokerV.Results,Dest);
749end;
750
751procedure HSComponentSubs(Dest: TStrings; aItem: String);
752begin
753 CallV('ORWRP2 HS COMPONENT SUBS',[aItem]);
754 MixedCaseList(RPCBrokerV.Results);
755 QuickCopy(RPCBrokerV.Results,Dest);
756end;
757
758function GetRemoteStatus(aHandle: string): String;
759begin
760 CallV('XWB REMOTE STATUS CHECK', [aHandle]);
761 Result := RPCBrokerV.Results[0];
762end;
763
764function GetAdhocLookup: integer;
765begin
766 CallV('ORWRP2 GETLKUP', [nil]);
767 if RPCBrokerV.Results.Count > 0 then
768 Result := StrToInt(RPCBrokerV.Results[0])
769 else
770 Result := 0;
771end;
772
773procedure SetAdhocLookup(aLookup: integer);
774
775begin
776 CallV('ORWRP2 SAVLKUP', [IntToStr(aLookup)]);
777end;
778
779procedure GetRemoteData(Dest: TStrings; aHandle: string; aItem: PChar);
780begin
781 CallV('XWB REMOTE GETDATA', [aHandle]);
782 if RPCBrokerV.Results.Count < 1 then
783 RPCBrokerV.Results[0] := 'No data found.';
784 if (RPCBrokerV.Results.Count < 2) and (RPCBrokerV.Results[0] = '') then
785 RPCBrokerV.Results[0] := 'No data found.';
786 QuickCopy(RPCBrokerV.Results,Dest);
787end;
788
789procedure ModifyHDRData(Dest: string; aHandle: string; aID: string);
790begin
791 CallV('ORWRP4 HDR MODIFY', [aHandle, aID]);
792end;
793
794procedure PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
795var
796 BitmapHeader: pBitmapInfo;
797 BitmapImage : POINTER;
798 HeaderSize : DWORD; // Use DWORD for D3-D5 compatibility
799 ImageSize : DWORD;
800begin
801 GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
802 GetMem(BitmapHeader, HeaderSize);
803 GetMem(BitmapImage, ImageSize);
804 try
805 GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
806 StretchDIBits(Canvas.Handle,
807 DestRect.Left, DestRect.Top, // Destination Origin
808 DestRect.Right - DestRect.Left, // Destination Width
809 DestRect.Bottom - DestRect.Top, // Destination Height
810 0, 0, // Source Origin
811 Bitmap.Width, Bitmap.Height, // Source Width & Height
812 BitmapImage,
813 TBitmapInfo(BitmapHeader^),
814 DIB_RGB_COLORS,
815 SRCCOPY)
816 finally
817 FreeMem(BitmapHeader);
818 FreeMem(BitmapImage)
819 end
820end {PrintBitmap};
821
822initialization
823 { nothing to initialize }
824
825finalization
826 uTree.Free;
827 uReportsList.Free;
828 uLabReports.Free;
829 uDateRanges.Free;
830 uHSTypes.Free;
831
832end.
Note: See TracBrowser for help on using the repository browser.