source: cprs/branches/tmg-cprs/CPRS-Chart/fNotePrt.pas@ 1509

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

Fixed HTML Note Printing Error

File size: 12.3 KB
RevLine 
[541]1//kt -- Modified with SourceScanner on 8/25/2007, also 8/09
[453]2unit fNotePrt;
3
4interface
5
6uses
7 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
8 fAutoSz, ORCtrls, StdCtrls, Mask, ORNet, ORFn, ComCtrls, DKLang;
9
10type
11 TfrmNotePrint = class(TfrmAutoSz)
12 grpChooseCopy: TGroupBox;
13 radChartCopy: TRadioButton;
14 radWorkCopy: TRadioButton;
15 grpDevice: TGroupBox;
16 lblMargin: TLabel;
17 lblLength: TLabel;
18 txtRightMargin: TMaskEdit;
19 txtPageLength: TMaskEdit;
20 cmdOK: TButton;
21 cmdCancel: TButton;
22 lblNoteTitle: TMemo;
23 cboDevice: TORComboBox;
24 lblPrintTo: TLabel;
25 dlgWinPrinter: TPrintDialog;
26 chkDefault: TCheckBox;
27 procedure cboDeviceNeedData(Sender: TObject; const StartFrom: String;
28 Direction, InsertAt: Integer);
29 procedure FormCreate(Sender: TObject);
30 procedure cboDeviceChange(Sender: TObject);
31 procedure radChartCopyClick(Sender: TObject);
32 procedure radWorkCopyClick(Sender: TObject);
33 procedure cmdOKClick(Sender: TObject);
34 procedure cmdCancelClick(Sender: TObject);
35 private
36 //kt Begin Mod (change Consts to Vars) 8/25/2007
37 TX_NODEVICE : string; //kt
38 TX_NODEVICE_CAP : string; //kt
39 TX_ERR_CAP : string; //kt
40 //kt End Mod -------------------
41 { Private declarations }
42 FNote: Integer;
43 FReportText: TRichEdit;
44 procedure DisplaySelectDevice;
45 procedure SetupVars; //kt
46 public
47 { Public declarations }
48 end;
49
50procedure PrintNote(ANote: Longint; const ANoteTitle: string; MultiNotes: boolean = False);
51
52implementation
53
54{$R *.DFM}
55
[541]56uses rCore, rTIU, rReports, uCore, Printers,
57 rHTMLTools; //kt 8/09
[453]58
[541]59
[453]60const
61//TX_NODEVICE = 'A device must be selected to print, or press ''Cancel'' to not print.'; <-- original line. //kt 8/25/2007
62//TX_NODEVICE_CAP = 'Device Not Selected'; <-- original line. //kt 8/25/2007
63//TX_ERR_CAP = 'Print Error'; <-- original line. //kt 8/25/2007
64 PAGE_BREAK = '**PAGE BREAK**';
65
66
67
68procedure TfrmNotePrint.SetupVars;
69//kt Added entire function to replace constant declarations 8/25/2007
70begin
71 TX_NODEVICE := DKLangConstW('fNotePrt_A_device_must_be_selected_to_printx_or_press_xxCancelxx_to_not_printx');
72 TX_NODEVICE_CAP := DKLangConstW('fNotePrt_Device_Not_Selected');
73 TX_ERR_CAP := DKLangConstW('fNotePrt_Print_Error');
74end;
75
76procedure PrintNote(ANote: Longint; const ANoteTitle: string; MultiNotes: boolean = False);
77{ displays a form that prompts for a device and then prints the progress note }
78var
79 frmNotePrint: TfrmNotePrint;
80 DefPrt: string;
81begin
82 frmNotePrint := TfrmNotePrint.Create(Application);
83 try
84 ResizeFormToFont(TForm(frmNotePrint));
85 with frmNotePrint do
86 begin
87 { check to see of Chart Print allowed outside of MAS }
88 if AllowChartPrintForNote(ANote) then
89 begin
90 {This next code begs the question: Why are we even bothering to check
91 radWorkCopy if we immediately check the other button?
92 Short answer: it seems to wokr better
93 Long answer: The checkboxes have to in some way register with the group
94 they are in. If this doesn't happen, both will be initially included
95 the tab order. This means that the first time tabbing through the
96 controls, the work copy button would be tabbed to and selected after the
97 chart copy. Tabbing through controls should not change the group
98 selection.
99 }
100 radWorkCopy.Checked := True;
101 radChartCopy.Checked := True;
102 end
103 else
104 begin
105 radChartCopy.Enabled := False;
106 radWorkCopy.Checked := True;
107 end;
108
109 lblNoteTitle.Text := ANoteTitle;
110// frmNotePrint.Caption := 'Print ' + Piece(Piece(ANoteTitle, #9, 2), ',', 1); <-- original line. //kt 8/25/2007
111 frmNotePrint.Caption := DKLangConstW('fNotePrt_Print') + Piece(Piece(ANoteTitle, #9, 2), ',', 1); //kt added 8/25/2007
112 FNote := ANote;
113 DefPrt := GetDefaultPrinter(User.Duz, Encounter.Location);
114
115 if User.CurrentPrinter = '' then User.CurrentPrinter := DefPrt;
116
117 with cboDevice do
118 begin
119 if Printer.Printers.Count > 0 then
120 begin
121// Items.Add('WIN;Windows Printer^Windows Printer'); <-- original line. //kt 8/25/2007
122 Items.Add('WIN;'+DKLangConstW('fNotePrt_Windows_Printer')+'^'+DKLangConstW('fNotePrt_Windows_Printer')); //kt added 8/25/2007
123// Items.Add('^--------------------VistA Printers----------------------'); <-- original line. //kt 8/25/2007
124 Items.Add('^'+DKLangConstW('fNotePrt_xxxxxxxxxxxxxxxxxxxxxVistA_Printersxxxxxxxxxxxxxxxxxxxxxx')); //kt added 8/25/2007
125 end;
126 if User.CurrentPrinter <> '' then
127 begin
128 InitLongList(Piece(User.CurrentPrinter, ';', 2));
129 SelectByID(User.CurrentPrinter);
130 end
131 else
132 InitLongList('');
133 end;
134
135 if ((DefPrt = 'WIN;Windows Printer') and (User.CurrentPrinter = DefPrt)) then
136 cmdOKClick(frmNotePrint) //CQ6660
137 //Commented out for CQ6660
138 //or
139 //((User.CurrentPrinter <> '') and
140 //(MultiNotes = True)) then
141 //frmNotePrint.cmdOKClick(frmNotePrint)
142 //end CQ6660
143 else
144 frmNotePrint.ShowModal;
145 end;
146 finally
147 frmNotePrint.Release;
148 end;
149end;
150
151procedure TfrmNotePrint.FormCreate(Sender: TObject);
152begin
153 inherited;
154 FReportText := TRichEdit.Create(Self);
155 with FReportText do
156 begin
157 Parent := Self;
158 Visible := False;
159 Width := 600;
160 end;
161end;
162
163procedure TfrmNotePrint.DisplaySelectDevice;
164begin
165 with cboDevice, lblPrintTo do
166 begin
167// if radChartCopy.Checked then Caption := 'Print Chart Copy on: ' + Piece(ItemID, ';', 2); <-- original line. //kt 8/25/2007
168 if radChartCopy.Checked then Caption := DKLangConstW('fNotePrt_Print_Chart_Copy_onx') + Piece(ItemID, ';', 2); //kt added 8/25/2007
169// if radWorkCopy.Checked then Caption := 'Print Work Copy on: ' + Piece(ItemID, ';', 2); <-- original line. //kt 8/25/2007
170 if radWorkCopy.Checked then Caption := DKLangConstW('fNotePrt_Print_Work_Copy_onx') + Piece(ItemID, ';', 2); //kt added 8/25/2007
171 end;
172end;
173
174procedure TfrmNotePrint.cboDeviceNeedData(Sender: TObject; const StartFrom: string;
175 Direction, InsertAt: Integer);
176begin
177 inherited;
178 cboDevice.ForDataUse(SubsetOfDevices(StartFrom, Direction));
179end;
180
181procedure TfrmNotePrint.cboDeviceChange(Sender: TObject);
182begin
183 inherited;
184 with cboDevice do if ItemIndex > -1 then
185 begin
186 txtRightMargin.Text := Piece(Items[ItemIndex], '^', 4);
187 txtPageLength.Text := Piece(Items[ItemIndex], '^', 5);
188 DisplaySelectDevice;
189 end;
190end;
191
192procedure TfrmNotePrint.radChartCopyClick(Sender: TObject);
193begin
194 inherited;
195 DisplaySelectDevice;
196end;
197
198procedure TfrmNotePrint.radWorkCopyClick(Sender: TObject);
199begin
200 inherited;
201 DisplaySelectDevice;
202end;
203
204procedure TfrmNotePrint.cmdOKClick(Sender: TObject);
205var
206 ADevice, ErrMsg: string;
207 ChartCopy: Boolean;
208 RemoteSiteID: string; //for Remote site printing
209 RemoteQuery: string; //for Remote site printing
[541]210 TempLines: TStringList; //kt added 5-31-05
[453]211begin
212 SetupVars; //kt added 8/25/2007 to replace constants with vars.
213 inherited;
214 RemoteSiteID := '';
215 RemoteQuery := '';
216
217 if cboDevice.ItemID = '' then
[671]218 begin
219 InfoBox(TX_NODEVICE, TX_NODEVICE_CAP, MB_OK);
220 Exit;
221 end;
222 if radChartCopy.Checked then ChartCopy := True else ChartCopy := False;
223 if Piece(cboDevice.ItemID, ';', 1) = 'WIN' then
224(*
225 //begin original block of code from before 5-24-05
226 //----------------------------------------------
227 begin
228 if dlgWinPrinter.Execute then with FReportText do
229 begin
230 Lines.Assign(GetFormattedNote(FNote, ChartCopy));
231 PrintWindowsReport(FReportText, PAGE_BREAK, Self.Caption, ErrMsg);
232 if Length(ErrMsg) > 0 then InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
233 end;
234 end
235 //end original unmodified block of code //kt 5-24-05
236 //--------------------------------------------------
237*)
238 //begin modified block of code //kt 5-31-05
239 //----------------------------------------------
240 begin
241 TempLines := TStringList.Create;
242 TempLines.Assign(GetFormattedNote(FNote, ChartCopy));
243 if rHTMLTools.IsHTML(TempLines) = false then begin
244 //NOTE: If HTML, then bypass this printer dialog, because it will be
245 // replaced by a printer dialog that internet explorer uses.
246 if dlgWinPrinter.Execute then begin
247 FReportText.Lines.Assign(TempLines);
248 PrintWindowsReport(FReportText, PAGE_BREAK, Self.Caption, ErrMsg,Application);
249 end;
250 end else begin
251 LoadDocumentText(TempLines, FNote); //Get document without headers/footers
252 PrintHTMLReport(TempLines, ErrMsg, Patient.Name,
253 FormatFMDateTime('mm/dd/yyyy', Patient.DOB),
254 rHTMLtools.ExtractDateOfNote(TempLines), // date for report.
255 Patient.WardService, Application);
256 end;
257 TempLines.Free;
258 if Length(ErrMsg) > 0 then InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
259 end
260 //end modified block of code //kt 5-31-05
261 //----------------------------------------------
262 else
263 begin
264 ADevice := Piece(cboDevice.ItemID, ';', 2);
265 PrintNoteToDevice(FNote, ADevice, ChartCopy, ErrMsg);
266 if Length(ErrMsg) > 0 then InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
267
268{* Original Block of Code //elh 1/19/10
[453]269 begin
270 InfoBox(TX_NODEVICE, TX_NODEVICE_CAP, MB_OK);
271 Exit;
272 end;
273
274 if radChartCopy.Checked then
275 ChartCopy := True
276 else ChartCopy := False;
277
278
[541]279 if Piece(cboDevice.ItemID, ';', 1) = 'WIN' then begin
280 if dlgWinPrinter.Execute then begin
281 //kt ----- Begin original code ------------- 8/09
282 //kt FReportText.Lines.Assign(GetFormattedNote(FNote, ChartCopy));
283 //kt PrintWindowsReport(FReportText, PAGE_BREAK, Self.Caption, ErrMsg);
284 //kt if Length(ErrMsg) > 0 then InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
285 //kt ----- End original code -------------
286 TempLines := TStringList.Create; //kt 8/09
287 TempLines.Assign(GetFormattedNote(FNote, ChartCopy)); //kt 8/09
288 if not rHTMLTools.IsHTML(TempLines) then begin //kt 8/09
289 //NOTE: If HTML, then bypass this printer dialog, because it will be //kt 8/09
290 // replaced by a printer dialog that internet explorer uses. //kt 8/09
291 if dlgWinPrinter.Execute then begin //kt 8/09
292 FReportText.Lines.Assign(TempLines); //kt 8/09
293 PrintWindowsReport(FReportText, PAGE_BREAK, Self.Caption, ErrMsg,Application); //kt 8/09
294 end; //kt 8/09
295 end else begin //kt 8/09
296 LoadDocumentText(TempLines, FNote); //Get document without headers/footers //kt 8/09
297 PrintHTMLReport(TempLines, ErrMsg, Patient.Name, //kt 8/09
[671]298 FormatFMDateTime('mm/dd/yyyy', Patient.DOB),' ', //kt 8/09
[541]299 Patient.WardService, Application); //kt 8/09
300 end; //kt 8/09
301 TempLines.Free; //kt 8/09
302 if Length(ErrMsg) > 0 then InfoBox(ErrMsg, TX_ERR_CAP, MB_OK); //kt 8/09
303 end; //kt 8/09
304 end else begin
[453]305 ADevice := Piece(cboDevice.ItemID, ';', 2);
306 PrintNoteToDevice(FNote, ADevice, ChartCopy, ErrMsg);
307
308 if Length(ErrMsg) > 0 then
309 InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
[671]310*} // End of original block of code //elh 1/19/10
[453]311 end;
312
313 if chkDefault.Checked then
314 SaveDefaultPrinter(Piece(cboDevice.ItemID, ';', 1));
[541]315
[453]316 User.CurrentPrinter := cboDevice.ItemID;
317 Close;
318end;
319
320procedure TfrmNotePrint.cmdCancelClick(Sender: TObject);
321begin
322 inherited;
323 Close;
324end;
325
326end.
Note: See TracBrowser for help on using the repository browser.