Changeset 671 for cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas
- Timestamp:
- Jan 19, 2010, 1:26:10 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cprs/branches/tmg-cprs/CPRS-Chart/rHTMLTools.pas
r541 r671 16 16 DesiredHTMLFontSize : byte; 17 17 18 procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string; PtName:string;19 DOB:string;Location:string; Application : TApplication); //kt added 5-2-0518 procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string; 19 PtName, DOB, VisitDate, Location:string; Application : TApplication); //kt added 5-2-05 20 20 function IsHTML(Lines : TStrings): boolean; overload; 21 21 function IsHTML(Line : String): boolean; overload; … … 34 34 procedure SetRegHTMLFontSize(Size: byte); 35 35 procedure RestoreRegHTMLFontSize; 36 procedure SetupHTMLPrinting(Name,DOB, Location,Institution : string);36 procedure SetupHTMLPrinting(Name,DOB,VisitDate,Location,Institution : string); 37 37 procedure RestoreIEPrinting; 38 38 function ExtractDateOfNote(Lines : TStringList) : string; 39 39 40 implementation 40 41 … … 44 45 Graphics, //For color constants 45 46 fTMGPrintingAnimation, 47 ExtCtrls, 46 48 StrUtils; 49 50 type 51 TPrinterEvents = class 52 public 53 SavedDefaultPrinter : string; 54 LastChosenPrinterName : string; 55 RestorePrinterTimer : TTimer; 56 PrintingNow : boolean; 57 procedure HandleRestorePrinting (Sender: TObject); 58 Constructor Create; 59 Destructor Destroy; override; 60 end; 61 62 var 63 PrinterEvents : TPrinterEvents; 47 64 48 65 const CRLF = #$0D#$0A; … … 100 117 until (GetTime-StartTime) > (OneSec*Sec); 101 118 end; 102 119 120 121 procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string; 122 PtName, DOB, VisitDate, Location:string; 123 Application : TApplication); 124 // Web browser printing options: 125 // OLECMDEXECOPT_DODEFAULT Use the default behavior, whether prompting the user for input or not. 126 // OLECMDEXECOPT_PROMPTUSER Execute the command after obtaining user input. 127 // OLECMDEXECOPT_DONTPROMPTUSER Execute the command without prompting the user. 128 129 {Notice: When IE is asked to print, it immediately returns from the function, 130 but the printing has not yet occured. If UI is requested, then the 131 printing will not start until after the user selects a printer and 132 presses [OK]. I could not find any reliable way to determine when the 133 print job had been created. I had to know this event because I need to 134 restore some IE settings AFTER the printing has finished. I even tried to 135 get the active windows and see if it was a print dialog. But IE print dlg 136 apparently is owned by another thread than CPRS, because GetActiveWindow would 137 not bring back a handle to the printer dialog window. I therefore told IE 138 to print WITHOUT asking which printer via UI. In that case it prints to the 139 system wide default printer. So I have to set the default printer to the 140 user's choice, and then change it back again. This is bit of a kludge, 141 but I couldn't figure out any other way after hours of trial and error. 142 NOTE: I tried to query IE to see if it was able to print, thinking that it 143 would return NO if in the process of currently printing. It didn't work, 144 and would return OK immediately. 145 146 ADDENDUM: I was getting errors and inconsistent behavior with this, so I 147 have decided to try to let the user click a button when the printer has 148 been selected. } 149 150 var 151 UseUI : OleVariant; 152 //NewPrinterName : string; 153 //dlgWinPrinter : TPrintDialog; 154 begin 155 //if PrinterEvents.RestorePrinterTimer.Enabled = false then begin 156 // PrinterEvents.SavedDefaultPrinter := GetCurrentPrinterName; 157 //end; 158 if PrinterEvents.PrintingNow then exit; // prevent double printing (it has happened) 159 160 try 161 frmNotes.SetDisplayToHTMLvsText([vmView,vmHTML],Lines); //ActivateHtmlViewer(Lines); 162 if frmNotes.HtmlViewer.WaitForDocComplete = false then begin 163 ErrMsg := 'The web browser timed out trying to set up document.'; 164 exit; 165 end; 166 PrinterEvents.PrintingNow := true; 167 SetupHTMLPrinting(PtName,DOB,VisitDate,Location,' '); {elh 6/19/09} //kt 168 frmNotes.HtmlViewer.PrintFinished := false; 169 UseUI := true; 170 frmNotes.HtmlViewer.PrintDocument(UseUI); //Returns immediately, not after printing done. 171 frmTMGPrinting.ShowModal; // Let user show when print job has been launched. 172 PrinterEvents.RestorePrinterTimer.Enabled := true; //launch a restore event in 30 seconds 173 //RestoreIEPrinting; //elh - This was omitted from below. Not sure why. 11/10/09 174 finally 175 PrinterEvents.PrintingNow := false; 176 end; 177 end; 178 179 (* 180 Safe copy of above. Delete later... 181 103 182 procedure PrintHTMLReport(Lines: TStringList; var ErrMsg: string; 104 183 PtName, DOB, Location:string; … … 126 205 and would return OK immediately. } 127 206 207 208 128 209 var 129 UseUI : OleVariant; 130 NewPrinterName,DefaultPrinter: string; 131 dlgWinPrinter: TPrintDialog; 132 begin 133 DefaultPrinter := GetCurrentPrinterName; 210 UseUI : OleVariant; 211 NewPrinterName : string; 212 dlgWinPrinter : TPrintDialog; 213 begin 214 if PrinterEvents.RestorePrinterTimer.Enabled = false then begin 215 PrinterEvents.SavedDefaultPrinter := GetCurrentPrinterName; 216 end; 134 217 dlgWinPrinter := TPrintDialog.Create(nil); 135 218 frmTMGPrinting.Show; 219 //FIX: get printer name for the one used last time somehow... 136 220 if dlgWinPrinter.Execute then begin //only sets a local printer 137 221 NewPrinterName := GetCurrentPrinterName; 138 222 SetDefaultPrinter(NewPrinterName); //Set global setting that IE will use. 223 PrinterEvents.LastChosenPrinterName := NewPrinterName; 139 224 try 140 //frmNotes.SetHTMLorTextViewer(True,Lines); //ActivateHtmlViewer(Lines);141 225 frmNotes.SetDisplayToHTMLvsText([vmView,vmHTML],Lines); //ActivateHtmlViewer(Lines); 142 226 if frmNotes.HtmlViewer.WaitForDocComplete = false then begin … … 148 232 UseUI := false; //UseUI := true; 149 233 frmNotes.HtmlViewer.PrintDocument(UseUI); //Returns immediately, not after printing done. 150 Wait(4,Application); //give IE x sec to complete print document. Is this always enough? 234 PrinterEvents.RestorePrinterTimer.Enabled := true; //launch a restore event in 30 seconds 235 Wait(4,Application); 151 236 //WaitForBrowserOK(10, Application); //wait up to 10 seconds //Note: this doesn't do what I want. Status is immediately OK. 152 RestoreIEPrinting; {elh 6/19/09} //kt237 //RestoreIEPrinting; {elh 6/19/09} //kt 153 238 finally //any needed final code goes here. 154 SetDefaultPrinter(DefaultPrinter);239 //SetDefaultPrinter(DefaultPrinter); 155 240 //beep; 156 241 end; … … 159 244 frmTMGPrinting.Hide; 160 245 end; 161 246 *) 162 247 (* 163 248 function WaitForBrowserOK(MaxSecDelay: integer; Application : TApplication) : boolean; … … 738 823 Reg : TRegistry; 739 824 740 procedure SetupHTMLPrinting(Name,DOB, Location,Institution : string);825 procedure SetupHTMLPrinting(Name,DOB,VisitDate,Location,Institution : string); 741 826 //Purpose: To open the IE header and footer registry keys, save the 742 827 //current value and then replace with passed patient data. elh 6/19/09 … … 748 833 end; 749 834 NewHeader := Location + ' &b ' + Institution + ' &b Printed: &d &t'; 750 NewFooter := Name + ' &b DOB: ' + DOB+ ' &b &p of &P';835 NewFooter := Name + ' (' + DOB + ') &b Note: ' + VisitDate + ' &b &p of &P'; 751 836 Reg := TRegistry.Create; //to be freed in RestoreIEPrinting 752 837 try … … 764 849 procedure RestoreIEPrinting; 765 850 //Purpose: To restore the IE header and footer registry with the initial value 851 //NOTE: The below function was used to restore the previous value to the registry 852 // but got commented above, so the registry retained the patient's data 853 // to resolve this, we are now setting this to a default value. 766 854 //elh 6/19/09 767 855 begin 768 856 if not assigned(Reg) then Reg := TRegistry.Create; 769 857 try 858 StoredIEFooters := '&u&b&d'; //Comment this line to restore previous value 859 StoredIEHeader := '&d&b&t&bPage &p of &P'; //Comment this line to restore previous value 770 860 Reg.WriteString('footer',StoredIEFooters); 771 861 Reg.WriteString('header',StoredIEHeader); … … 776 866 end; 777 867 778 begin 868 function ExtractDateOfNote(Lines : TStringList) : string; 869 //Scan note and return date found after 'DATE OF NOTE:', if present. 870 var i,p : integer; 871 s : string; 872 begin 873 Result := ''; 874 if Lines = nil then exit; 875 for i := 0 to Lines.Count-1 do begin 876 p := Pos('DATE OF NOTE:',Lines.Strings[i]); 877 if p<1 then continue; 878 s := Piece(Lines.Strings[i],'DATE OF NOTE:',2); 879 s := Piece(s,'@',1); 880 Result := Trim(s); 881 end; 882 end; 883 884 //=============================================================== 885 886 Constructor TPrinterEvents.Create; 887 begin 888 RestorePrinterTimer := TTimer.Create(frmNotes); 889 RestorePrinterTimer.Enabled := false; 890 RestorePrinterTimer.Interval := 30000; //30 seconds to complete print job. 891 RestorePrinterTimer.OnTimer := HandleRestorePrinting; 892 PrintingNow := false; 893 end; 894 895 Destructor TPrinterEvents.Destroy; 896 begin 897 RestorePrinterTimer.Free; 898 inherited Destroy; 899 end; 900 901 902 procedure TPrinterEvents.HandleRestorePrinting (Sender: TObject); 903 begin 904 if PrinterEvents.PrintingNow then begin 905 RestorePrinterTimer.Enabled := true; // reset timer for later. 906 exit; 907 end; 908 RestorePrinterTimer.Enabled := false; 909 RestoreIEPrinting; {elh 6/19/09} //kt 910 //kt SetDefaultPrinter(SavedDefaultPrinter); 911 //beep; 912 end; 913 914 //=============================================================== 915 916 917 initialization 779 918 DesiredHTMLFontSize := 2; //probably overwritten in fNotes initialization 919 PrinterEvents := TPrinterEvents.Create; 920 921 finalization 922 PrinterEvents.Free; 780 923 end.
Note:
See TracChangeset
for help on using the changeset viewer.