source: cprs/branches/foia-cprs/CPRS-Chart/fNotePrt.pas@ 1531

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

Uploading from OR_30_258

File size: 6.7 KB
Line 
1unit fNotePrt;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 fAutoSz, ORCtrls, StdCtrls, Mask, ORNet, ORFn, ComCtrls;
8
9type
10 TfrmNotePrint = class(TfrmAutoSz)
11 grpChooseCopy: TGroupBox;
12 radChartCopy: TRadioButton;
13 radWorkCopy: TRadioButton;
14 grpDevice: TGroupBox;
15 lblMargin: TLabel;
16 lblLength: TLabel;
17 txtRightMargin: TMaskEdit;
18 txtPageLength: TMaskEdit;
19 cmdOK: TButton;
20 cmdCancel: TButton;
21 lblNoteTitle: TMemo;
22 cboDevice: TORComboBox;
23 lblPrintTo: TLabel;
24 dlgWinPrinter: TPrintDialog;
25 chkDefault: TCheckBox;
26 procedure cboDeviceNeedData(Sender: TObject; const StartFrom: String;
27 Direction, InsertAt: Integer);
28 procedure FormCreate(Sender: TObject);
29 procedure cboDeviceChange(Sender: TObject);
30 procedure radChartCopyClick(Sender: TObject);
31 procedure radWorkCopyClick(Sender: TObject);
32 procedure cmdOKClick(Sender: TObject);
33 procedure cmdCancelClick(Sender: TObject);
34 private
35 { Private declarations }
36 FNote: Integer;
37 FReportText: TRichEdit;
38 procedure DisplaySelectDevice;
39 public
40 { Public declarations }
41 end;
42
43procedure PrintNote(ANote: Longint; const ANoteTitle: string; MultiNotes: boolean = False);
44
45implementation
46
47{$R *.DFM}
48
49uses rCore, rTIU, rReports, uCore, Printers;
50
51const
52 TX_NODEVICE = 'A device must be selected to print, or press ''Cancel'' to not print.';
53 TX_NODEVICE_CAP = 'Device Not Selected';
54 TX_ERR_CAP = 'Print Error';
55 PAGE_BREAK = '**PAGE BREAK**';
56
57procedure PrintNote(ANote: Longint; const ANoteTitle: string; MultiNotes: boolean = False);
58{ displays a form that prompts for a device and then prints the progress note }
59var
60 frmNotePrint: TfrmNotePrint;
61 DefPrt: string;
62begin
63 frmNotePrint := TfrmNotePrint.Create(Application);
64 try
65 ResizeFormToFont(TForm(frmNotePrint));
66 with frmNotePrint do
67 begin
68 { check to see of Chart Print allowed outside of MAS }
69 if AllowChartPrintForNote(ANote) then
70 begin
71 {This next code begs the question: Why are we even bothering to check
72 radWorkCopy if we immediately check the other button?
73 Short answer: it seems to wokr better
74 Long answer: The checkboxes have to in some way register with the group
75 they are in. If this doesn't happen, both will be initially included
76 the tab order. This means that the first time tabbing through the
77 controls, the work copy button would be tabbed to and selected after the
78 chart copy. Tabbing through controls should not change the group
79 selection.
80 }
81 radWorkCopy.Checked := True;
82 radChartCopy.Checked := True;
83 end
84 else
85 begin
86 radChartCopy.Enabled := False;
87 radWorkCopy.Checked := True;
88 end;
89
90 lblNoteTitle.Text := ANoteTitle;
91 frmNotePrint.Caption := 'Print ' + Piece(Piece(ANoteTitle, #9, 2), ',', 1);
92 FNote := ANote;
93 DefPrt := GetDefaultPrinter(User.Duz, Encounter.Location);
94
95 if User.CurrentPrinter = '' then User.CurrentPrinter := DefPrt;
96
97 with cboDevice do
98 begin
99 if Printer.Printers.Count > 0 then
100 begin
101 Items.Add('WIN;Windows Printer^Windows Printer');
102 Items.Add('^--------------------VistA Printers----------------------');
103 end;
104 if User.CurrentPrinter <> '' then
105 begin
106 InitLongList(Piece(User.CurrentPrinter, ';', 2));
107 SelectByID(User.CurrentPrinter);
108 end
109 else
110 InitLongList('');
111 end;
112
113 if ((DefPrt = 'WIN;Windows Printer') and (User.CurrentPrinter = DefPrt)) then
114 cmdOKClick(frmNotePrint) //CQ6660
115 //Commented out for CQ6660
116 //or
117 //((User.CurrentPrinter <> '') and
118 //(MultiNotes = True)) then
119 //frmNotePrint.cmdOKClick(frmNotePrint)
120 //end CQ6660
121 else
122 frmNotePrint.ShowModal;
123 end;
124 finally
125 frmNotePrint.Release;
126 end;
127end;
128
129procedure TfrmNotePrint.FormCreate(Sender: TObject);
130begin
131 inherited;
132 FReportText := TRichEdit.Create(Self);
133 with FReportText do
134 begin
135 Parent := Self;
136 Visible := False;
137 Width := 600;
138 end;
139end;
140
141procedure TfrmNotePrint.DisplaySelectDevice;
142begin
143 with cboDevice, lblPrintTo do
144 begin
145 if radChartCopy.Checked then Caption := 'Print Chart Copy on: ' + Piece(ItemID, ';', 2);
146 if radWorkCopy.Checked then Caption := 'Print Work Copy on: ' + Piece(ItemID, ';', 2);
147 end;
148end;
149
150procedure TfrmNotePrint.cboDeviceNeedData(Sender: TObject; const StartFrom: string;
151 Direction, InsertAt: Integer);
152begin
153 inherited;
154 cboDevice.ForDataUse(SubsetOfDevices(StartFrom, Direction));
155end;
156
157procedure TfrmNotePrint.cboDeviceChange(Sender: TObject);
158begin
159 inherited;
160 with cboDevice do if ItemIndex > -1 then
161 begin
162 txtRightMargin.Text := Piece(Items[ItemIndex], '^', 4);
163 txtPageLength.Text := Piece(Items[ItemIndex], '^', 5);
164 DisplaySelectDevice;
165 end;
166end;
167
168procedure TfrmNotePrint.radChartCopyClick(Sender: TObject);
169begin
170 inherited;
171 DisplaySelectDevice;
172end;
173
174procedure TfrmNotePrint.radWorkCopyClick(Sender: TObject);
175begin
176 inherited;
177 DisplaySelectDevice;
178end;
179
180procedure TfrmNotePrint.cmdOKClick(Sender: TObject);
181var
182 ADevice, ErrMsg: string;
183 ChartCopy: Boolean;
184 RemoteSiteID: string; //for Remote site printing
185 RemoteQuery: string; //for Remote site printing
186begin
187 inherited;
188 RemoteSiteID := '';
189 RemoteQuery := '';
190
191 if cboDevice.ItemID = '' then
192 begin
193 InfoBox(TX_NODEVICE, TX_NODEVICE_CAP, MB_OK);
194 Exit;
195 end;
196
197 if radChartCopy.Checked then
198 ChartCopy := True
199 else ChartCopy := False;
200
201
202 if Piece(cboDevice.ItemID, ';', 1) = 'WIN' then
203 begin
204 if dlgWinPrinter.Execute then
205 begin
206 FReportText.Lines.Assign(GetFormattedNote(FNote, ChartCopy));
207 PrintWindowsReport(FReportText, PAGE_BREAK, Self.Caption, ErrMsg);
208 if Length(ErrMsg) > 0 then InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
209 end
210 end
211 else
212 begin
213 ADevice := Piece(cboDevice.ItemID, ';', 2);
214 PrintNoteToDevice(FNote, ADevice, ChartCopy, ErrMsg);
215
216 if Length(ErrMsg) > 0 then
217 InfoBox(ErrMsg, TX_ERR_CAP, MB_OK);
218 end;
219
220 if chkDefault.Checked then
221 SaveDefaultPrinter(Piece(cboDevice.ItemID, ';', 1));
222
223 User.CurrentPrinter := cboDevice.ItemID;
224 Close;
225end;
226
227procedure TfrmNotePrint.cmdCancelClick(Sender: TObject);
228begin
229 inherited;
230 Close;
231end;
232
233end.
Note: See TracBrowser for help on using the repository browser.