unit MyIPDReport;
var d1,d2:tdatetime;
rc:integer;
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;
procedure InsertRecordx(name1:string;n1,n2:integer);
begin
setstatuslabel(name1);
rc:=rc+1;
fcds.close;
fcds.datarequest('select * from tempreport where id = "CUSTOM-CHRONIC1" limit 0 ');
fcds.open;
fcds.insert;
fcds['id']:='CUSTOM-CHRONIC1';
fcds['reportname']:='CUSTOM-CHRONIC1';
fcds['name1']:=name1;
fcds['num']:=rc;
fcds['num1']:=n1;
fcds['num2']:=n2;
fcds['date1']:=d1;
fcds['date2']:=d2;
fcds.post;
fcds.datarequest('select * from tempreport where id = "CUSTOM-CHRONIC1" limit 0 ');
applyupdate_fcds();
end;
procedure main;
var
people_distinct_count1 : integer;
people_count1 : integer;
ds1,ds2:string;
pttype_list1 : string;
pttype,pttype_name:string;
hospcode_list:string;
money1:currency;
i:integer;
clinic:string;
i1,i2:integer;
begin
//showmessage('à¡ÕèÂǡѺÃÒ§ҹ'+#13+'Custom OPD-NK2');
clinic:='';
clinic:= vartostr(getsqldata('select sys_value from sys_var where sys_name="dm_clinic_code"'));
if clinic='' then raise exception.create('Invalid dm clinic code');
rc:=0;
if not getdaterange() then exit;
d1:=date_result1();
d2:=date_result2();
// 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 = ''CUSTOM-CHRONIC1'' ';
zquery.execsql;
i1:=getsqldata('select count(*) as cc from clinicmember where regdate between "'+ds1+'" and "'+ds2+'" '+
' and new_case="Y" and clinic="'+clinic+'"');
InsertRecordx('2.1 ¼Ùé»èÇ·Õèä´éÃѺ¡ÒÃÇÔ¹Ô¨©ÑÂâ´Âá¾·Âì·Õè¢Öé¹·ÐàºÕ¹ãËÁè·Ñé§ËÁ´',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'"');
InsertRecordx('2.2 ¼Ùé»èÇ·Õè¢Öé¹·ÐàºÕ¹·Ñé§ËÁ´',i1,0);
// IDDM
i1:=getsqldata('select count(hn) as cc from clinicmember '+
' where clinic="'+clinic+'" and subtype=1 and hn not in (select hn from patient where deathday is not null)');
InsertRecordx('3.1 ¨Ó¹Ç¹¼Ùé»èÇ·Õè¾Öè§ÍÔ¹«ÙÅÔ¹',i1,0);
// NIDDM
i1:=getsqldata('select count(hn) as cc from clinicmember '+
' where clinic="'+clinic+'" and (subtype=2 or subtype is NULL or subtype=0 ) and hn not in (select hn from patient where deathday is not null) ');
InsertRecordx('3.2 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèäÁè¾Öè§ÍÔ¹«ÙÅÔ¹',i1,0);
// Visit
i1:=getsqldata('select count(distinct hn) as cc from ovst where hn in (select hn from clinicmember '+
' where clinic="'+clinic+'" ) and vstdate between "'+ds1+'" and "'+ds2+'" ');
i2:=getsqldata('select count(hn) as cc from ovst where hn in (select hn from clinicmember '+
' where clinic="'+clinic+'" ) and vstdate between "'+ds1+'" and "'+ds2+'" ');
InsertRecordx('4.0 ¼Ùé»èÇÂàºÒËÇÒ¹·ÕèÁÒÃѺºÃÔ¡ÒÃã¹Ê¶Ò¹ºÃÔ¡ÒÃÊÒ¸ÒóÊØ¢',i1,i2);
// Old pt has blood fbs check
i1:=getsqldata('select count(o.hn) as cc from opdscreen o,ovst v where o.vn=v.vn and v.hn in (select hn from clinicmember '+
' where clinic="'+clinic+'" ) and v.vstdate between "'+ds1+'" and "'+ds2+'" and o.fbs>0 and v.hn not in (select hn from clinicmember '+
' where clinic="'+clinic+'" and regdate between "'+ds1+'" and "'+ds2+'" and new_case="Y") ');
InsertRecordx('6.0 ¼Ùé»èÇÂàºÒËÇÒ¹·Õèä´éÃѺ¡ÒÃà¨ÒÐàÅ×Í´',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=1) ');
InsertRecordx('8.1 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§µÒ',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=2) ');
InsertRecordx('8.2 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§äµ',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=3) ');
InsertRecordx('8.3 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§Ãкº»ÃÐÊÒ·',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=4) ');
InsertRecordx('8.4 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§ËÅÍ´àÅ×Í´á´§',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=5) ');
InsertRecordx('8.5 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§µÑ´ÍÇÑÂÇÐ',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=6) ');
InsertRecordx('8.6 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§ÁÒ¡¡ÇèÒ˹Öè§ÍÂèÒ§',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn not in (select hn from patient where deathday is not null) and clinic="'+clinic+'" and '+
' hn in (select hn from clinic_cormobidity_list where clinic="'+clinic+'" and cormobidity=7) ');
InsertRecordx('8.7 ¨Ó¹Ç¹¼Ùé»èÇ·ÕèÁÕÀÒÇÐá·Ã¡«é͹·Ò§Í×è¹æ',i1,0);
i1:=getsqldata('select count(*) as cc from clinicmember where '+
' hn in (select hn from patient where deathday between "'+ds1+'" and "'+ds2+'" ) and clinic="'+clinic+'"');
InsertRecordx('9.0 ¼Ùé»èÇÂàºÒËÇÒ¹ã¹à¢µÃѺ¼Ô´ªÍº·ÕèàÊÕªÕÇÔµ',i1,0);
setstatuslabel('done.');
end;
end.