source: cprs/branches/foia-cprs/CPRS-Chart/rReports.pas@ 459

Last change on this file since 459 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

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