unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBClient, Grids, DBGrids, cxControls, cxContainer,
cxEdit, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxCalendar, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox3: TGroupBox;
PttypeCombobox1: TComboBox;
PttypeCombobox2: TComboBox;
PttypeCombobox3: TComboBox;
PttypeButton: TButton;
PttypeListBox: TListBox;
Label4: TLabel;
Label5: TLabel;
HospcodeEdit1: TEdit;
HospcodeEdit2: TEdit;
Button2: TButton;
DBGrid1: TDBGrid;
cds: TClientDataSet;
ds: TDataSource;
Button3: TButton;
Button4: TButton;
GroupBox4: TGroupBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
Label6: TLabel;
cxDateEdit1: TcxDateEdit;
Label7: TLabel;
cxDateEdit2: TcxDateEdit;
Button1: TButton;
RadioGroup2: TRadioGroup;
PG: TProgressBar;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Bevel1: TBevel;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PttypeButtonClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
procedure ProcessIncome(field_name, income_group: string);
public
{ Public declarations }
end;
var
Form1: TForm1;
pttype_cri: string;
i: integer; s: string;
paidst_cri: string;
region_cri : string;
hospcode_cri : string;
implementation
{$R *.dfm}
procedure TForm1.ProcessIncome(field_name, income_group: string);
begin
cds.fieldbyname(field_name).asfloat := 0;
try
cds.fieldbyname(field_name).asfloat := getsqldata('select sum(rcptamt) as cc from incoth where vn = "' +
cds.fieldbyname('vn').asstring + '" and paidst in (' + paidst_cri + ') and income in (select income from income where income_group in (' + income_group + ')) ');
except end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
pttypelistbox.items.clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
pttype_cri := '';
if radiobutton1.checked then
begin
pttype_cri := ' and v.pttype = "' +
vartostr(getsqldata('select pttype from pttype where name = "' + pttypecombobox1.text + '"')) + '" ';
end else
if radiobutton2.checked then
begin
pttype_cri := ' and v.pcode = "' +
vartostr(getsqldata('select code from pcode where name = "' + pttypecombobox2.text + '"')) + '" ';
end else
if radiobutton3.checked then
begin
s := '';
for i := 0 to pttypelistbox.items.count - 1 do
begin
if s = '' then s := '"' + vartostr(getsqldata('select pttype from pttype where name = "' + pttypelistbox.items[i] + '"')) + '"' else
s := s + ',"' + vartostr(getsqldata('select pttype from pttype where name = "' + pttypelistbox.items[i] + '"')) + '"';
end;
pttype_cri := ' and v.pttype in (' + s + ') ';
end;
region_cri := '';
if checkbox2.checked then
begin
if radiogroup2.itemindex=1 then
region_cri := ' and v.pttype_in_region = "Y"' else
if radiogroup2.itemindex=2 then
region_cri := ' and v.pttype_in_region = "N" ';
end;
hospcode_cri := '';
if checkbox3.checked then
begin
if hospcodeedit1.text<>'' then
hospcode_cri :=' and v.hospmain = "'+hospcodeedit1.text+'" ';
if hospcodeedit2.text<>'' then
begin
hospcode_cri := hospcode_cri + ' and v.hospsub = "'+hospcodeedit2.text+'" ';
end;
end;
button2.enabled := false;
cds.data := HOSxP_GetDataset('select space(3) as no_card,v.cid ,concat(p.pname,p.fname) as name,p.birthday,s.name as sex_name,p.nationality as nation,p.hn,p.hid,p.addrpart as house,p.moopart as village,p.tmbpart as tambon,p.amppart as ampur,p.chwpart as province,v.vstdate,v.rcpno_list as receipt1,space(5) as receipt2,space(5) as rcode,space(5) as diag,space(5) as fu,concat(p.informname,"/",p.informaddr) as employer' +
' from vn_stat v ' +
' left outer join patient p on p.hn = v.hn ' +
' left outer join sex s on s.code = p.sex ' +
' where v.vstdate between "' + formatdatetime('yyyy-mm-dd', cxdateedit1.date) + '" and "' + formatdatetime('yyyy-mm-dd', cxdateedit2.date) + '" ' +
pttype_cri+' '+region_cri+' '+hospcode_cri);
paidst_cri := '"02"';
pg.position := 0;
pg.max := cds.recordcount;
cds.first;
dbgrid1.enabled := false;
while not cds.eof do
begin
pg.position := pg.position + 1;
cds.edit;
// cds.fieldbyname('count_in_day').asinteger := cds.recno;
// cds.fieldbyname('inc01').asfloat := 0;
// cds.fieldbyname('inc02').asfloat := 0;
// cds.fieldbyname('inc03').asfloat := 0;
// cds.fieldbyname('inc04').asfloat := 0;
// cds.fieldbyname('inc05').asfloat := 0;
// cds.fieldbyname('inc06').asfloat := 0;
// cds.fieldbyname('inc07').asfloat := 0;
// cds.fieldbyname('inc08').asfloat := 0;
// cds.fieldbyname('inc09').asfloat := 0;
// cds.fieldbyname('inc10').asfloat := 0;
// cds.fieldbyname('inc11').asfloat := 0;
// cds.fieldbyname('inc12').asfloat := 0;
// ProcessIncome('inc01', '"01"');
// ProcessIncome('inc02', '"04"');
// ProcessIncome('inc04', '"06"');
// ProcessIncome('inc05', '"07"');
// ProcessIncome('inc06', '"09"');
// ProcessIncome('inc07', '"10"');
// ProcessIncome('inc09', '"12"');
// ProcessIncome('inc10', '"13"');
// ProcessIncome('inc11', '"14"');
// ProcessIncome('inc03', '"02","03","05","08","11","15","16","17"');
// cds.fieldbyname('inc12').asfloat :=
// cds.fieldbyname('inc01').asfloat +
// cds.fieldbyname('inc02').asfloat +
// cds.fieldbyname('inc03').asfloat +
// cds.fieldbyname('inc04').asfloat +
// cds.fieldbyname('inc05').asfloat +
// cds.fieldbyname('inc06').asfloat +
// cds.fieldbyname('inc07').asfloat +
// cds.fieldbyname('inc08').asfloat +
// cds.fieldbyname('inc09').asfloat +
// cds.fieldbyname('inc10').asfloat +
// cds.fieldbyname('inc11').asfloat;
cds.post;
cds.next;
end;
cds.first;
dbgrid1.enabled := true;
button2.enabled := true;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
fcds.data := cds.data;
ExportDatasetToExcel('nhso.xls');
end;
procedure TForm1.FormCreate(Sender: TObject);
var tc: tclientdataset;
begin
tc := tclientdataset.create(nil);
tc.data := HOSxP_Getdataset('select name from pttype order by name');
while not tc.eof do
begin
pttypecombobox1.items.add(tc.fieldbyname('name').asstring);
pttypecombobox3.items.add(tc.fieldbyname('name').asstring);
tc.next;
end;
tc.data := HOSxP_GetDataset('select name from pcode order by name');
while not tc.eof do
begin
pttypecombobox2.items.add(tc.fieldbyname('name').asstring);
tc.next;
end;
tc.free;
cxdateedit1.date := date;
cxdateedit2.date := date;
end;
procedure TForm1.PttypeButtonClick(Sender: TObject);
begin
if pttypecombobox3.text <> '' then
if pttypelistbox.items.indexof(pttypecombobox3.text) = -1 then
pttypelistbox.items.add(pttypecombobox3.text);
end;
end.