| [459] | 1 | unit fNotePrt;
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | interface
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | uses
 | 
|---|
 | 6 |   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 | 
|---|
 | 7 |   fAutoSz, ORCtrls, StdCtrls, Mask, ORNet, ORFn, ComCtrls;
 | 
|---|
 | 8 | 
 | 
|---|
 | 9 | type
 | 
|---|
 | 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 | 
 | 
|---|
 | 43 | procedure PrintNote(ANote: Longint; const ANoteTitle: string; MultiNotes: boolean = False);
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | implementation
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | {$R *.DFM}
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | uses rCore, rTIU, rReports, uCore, Printers;
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | const
 | 
|---|
 | 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 | 
 | 
|---|
 | 57 | procedure PrintNote(ANote: Longint; const ANoteTitle: string; MultiNotes: boolean = False);
 | 
|---|
 | 58 | { displays a form that prompts for a device and then prints the progress note }
 | 
|---|
 | 59 | var
 | 
|---|
 | 60 |   frmNotePrint: TfrmNotePrint;
 | 
|---|
 | 61 |   DefPrt: string;
 | 
|---|
 | 62 | begin
 | 
|---|
 | 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;
 | 
|---|
 | 127 | end;
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | procedure TfrmNotePrint.FormCreate(Sender: TObject);
 | 
|---|
 | 130 | begin
 | 
|---|
 | 131 |   inherited;
 | 
|---|
 | 132 |   FReportText := TRichEdit.Create(Self);
 | 
|---|
 | 133 |   with FReportText do
 | 
|---|
 | 134 |     begin
 | 
|---|
 | 135 |       Parent := Self;
 | 
|---|
 | 136 |       Visible := False;
 | 
|---|
 | 137 |       Width := 600;
 | 
|---|
 | 138 |     end;
 | 
|---|
 | 139 | end;
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 | procedure TfrmNotePrint.DisplaySelectDevice;
 | 
|---|
 | 142 | begin
 | 
|---|
 | 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;
 | 
|---|
 | 148 | end;
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | procedure TfrmNotePrint.cboDeviceNeedData(Sender: TObject; const StartFrom: string;
 | 
|---|
 | 151 |   Direction, InsertAt: Integer);
 | 
|---|
 | 152 | begin
 | 
|---|
 | 153 |   inherited;
 | 
|---|
 | 154 |   cboDevice.ForDataUse(SubsetOfDevices(StartFrom, Direction));
 | 
|---|
 | 155 | end;
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 | procedure TfrmNotePrint.cboDeviceChange(Sender: TObject);
 | 
|---|
 | 158 | begin
 | 
|---|
 | 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;
 | 
|---|
 | 166 | end;
 | 
|---|
 | 167 | 
 | 
|---|
 | 168 | procedure TfrmNotePrint.radChartCopyClick(Sender: TObject);
 | 
|---|
 | 169 | begin
 | 
|---|
 | 170 |   inherited;
 | 
|---|
 | 171 |   DisplaySelectDevice;
 | 
|---|
 | 172 | end;
 | 
|---|
 | 173 | 
 | 
|---|
 | 174 | procedure TfrmNotePrint.radWorkCopyClick(Sender: TObject);
 | 
|---|
 | 175 | begin
 | 
|---|
 | 176 |   inherited;
 | 
|---|
 | 177 |   DisplaySelectDevice;
 | 
|---|
 | 178 | end;
 | 
|---|
 | 179 | 
 | 
|---|
 | 180 | procedure TfrmNotePrint.cmdOKClick(Sender: TObject);
 | 
|---|
 | 181 | var
 | 
|---|
 | 182 |   ADevice, ErrMsg: string;
 | 
|---|
 | 183 |   ChartCopy: Boolean;
 | 
|---|
 | 184 |   RemoteSiteID: string;    //for Remote site printing
 | 
|---|
 | 185 |   RemoteQuery: string;    //for Remote site printing
 | 
|---|
 | 186 | begin
 | 
|---|
 | 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
 | 
|---|
| [460] | 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
 | 
|---|
| [459] | 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;
 | 
|---|
 | 225 | end;
 | 
|---|
 | 226 | 
 | 
|---|
 | 227 | procedure TfrmNotePrint.cmdCancelClick(Sender: TObject);
 | 
|---|
 | 228 | begin
 | 
|---|
 | 229 |   inherited;
 | 
|---|
 | 230 |   Close;
 | 
|---|
 | 231 | end;
 | 
|---|
 | 232 | 
 | 
|---|
 | 233 | end.
 | 
|---|