unit MyIPDReport;
var uc30_pcode : string;
uc_pcode : string;
foreign_pcode : string;
other_pcode : string;
icdx1,icdx2,ix2:string;
fonlineid : string;
function getsqlsubquerydatax(sql:string):string;
begin
result:='';
zquery.close;
zquery.sql.text:=sql;
zquery.open;
zquery.first;
while not zquery.eof do
begin
if result='' then result:=''''+zquery.fields[0].asstring+'''' else
result:=result+','''+zquery.fields[0].asstring+'''';
zquery.next;
end;
zquery.close;
if result='' then result:='''''';
end;
function GetICDRangeCount_UC30_InRegion(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" and v.pcode in ('+
uc30_pcode+') and v.pttype_in_region="Y" ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_UC30_OutRegion(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" and v.pcode in ('+
uc30_pcode+') and v.pttype_in_region="N" ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_UC_InRegion(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" and v.pcode in ('+
uc_pcode+') and v.pttype_in_region="Y" ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_UC_OutRegion(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" and v.pcode in ('+
uc_pcode+') and v.pttype_in_region="N" ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_Other(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" and v.pcode in ('+
other_pcode+') ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_Foreign(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" and v.pcode in ('+
foreign_pcode+') ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_Distinct_HN(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(distinct v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
function GetICDRangeCount_HN(icd1,icd2:string;bd1,bd2:TDateTime):integer;
begin
result:=0;
try
result:=getsqldata('select count(v.hn) as cc from vn_stat v,ovstdiag o where v.vstdate between "'+formatdatetime('yyyy-mm-dd',bd1)+'" '+
' and "'+formatdatetime('yyyy-mm-dd',bd2)+'" and v.vn=o.vn and o.icd10 between "'+icd1+'" and "'+icd2+'" ');
except
on e:exception do
begin
showmessage(e.message);
end;
end;
end;
procedure ProcessReport(n1,n2:string;i,i1,i2:integer;td1,td2:tdatetime);
begin
setstatuslabel('Processing... '+n2);
fcds.insert;
fcds['id']:=fonlineid;
fcds['reportname']:='CUSTOM-RGx2';
fcds['name1']:=n1;
fcds['num1']:=i;
fcds['name2']:=n2;
fcds['mon1']:=i1;
fcds['mon2']:=i2;
fcds['date1']:=td1;
fcds['date2']:=td2;
fcds.post;
fcds.datarequest('select * from tempreport where id = '''+fonlineid+''' ');
applyupdate_fcds();
end;
procedure main;
var d1,d2:tdatetime;
people_distinct_count1 : integer;
people_count1 : integer;
ds1,ds2:string;
pttype_list1 : string;
pttype,pttype_name:string;
hospcode_list:string;
money1:currency;
i:integer;
begin
if not getdaterange() then exit;
d1:=date_result1();
d2:=date_result2();
fonlineid:=report_value(1);
icdx1:='J00';
icdx2:='J99';
// if not inputquery('ICD10 begin code ','code',icdx1) then exit;
// if not inputquery('ICD10 end code ','code',icdx2) then exit;
// ix2:=icdx2;
// icdx2:=icdx2+'99';
setstatuslabel('Processing...');
uc30_pcode :='"UC"';
uc_pcode := '"AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK"';
foreign_pcode := '"AL"';
other_pcode := getsqlsubquerydata('select pcode from pttype where pcode not in ('+uc30_pcode+','+uc_pcode+','+foreign_pcode+') ');
// showmessage(formatdatetime('yyyy-mm-dd',d1)+' - '+
// formatdatetime('yyyy-mm-dd',d2));
ds1:=formatdatetime('yyyy-mm-dd',d1);
ds2:=formatdatetime('yyyy-mm-dd',d2);
zquery.sql.text:='delete from tempreport where id = '''+fonlineid+''' ';
zquery.execsql;
fcds.close;
fcds.datarequest('select * from tempreport where id = '''+fonlineid+''' ');
fcds.open;
fcds2.close;
fcds2.datarequest('select a.pcode,c.name as pttype_name,count(a.an) as pt_count, '+
' sum(a.admdate) as admdate_count '+
' from an_stat a '+
' left outer join pcode c on c.code = a.pcode '+
' where a.dchdate between "'+ds1+'" and "'+ds2+'" '+
' group by a.pcode,c.name order by a.pcode ');
fcds2.open;
fcds2.first;
i:=0;
while not fcds2.eof do
begin
i:=i+1;
setprogressbar(i,fcds2.recordcount);
processreport(vartostr(fcds2['pcode']),vartostr(fcds2['pttype_name']),i,fcds2['pt_count'],fcds2['admdate_count'],d1,d2);
fcds2.next;
end;
setstatuslabel('Done.');
end;
end.
ขอความช่วยเหลือจากอาจารย์ด้วยนะครับ ว่าต้องเพิ่ม ให้เลือกตึกผู้ป่วยตรงไหนครับ รายงานนี้ออกทุกตึกผู้ป่วยเลย