2324
« เมื่อ: ตุลาคม 21, 2006, 01:36:41 AM »
เนื่องจากมีหลายโรงพยาบาลต้องการให้ในบรรทัดสุด้ายของรายงานตัวนี้มียอดสรุปค่าใช้จ่ายทั้งหมด(ยอดรวมเบิกได้กับเบิกไม่ได้) แสดงครับ ผมได้ซึ่งผมได้ลองแก้ไขคำสั่ง pascal script ของอ.mn แต่ก็ยังไม่ได้ครับ ฝาก อ ช่วยตรวจสอบให้ด้วยครับ
ขอบคุณครับ
หมายเหตุ ส่วนที่เป็นอักษรสีแดงเป็นส่วนที่ผมได้แก้ไข ครับ
unit MyIPDReport;
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 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;
fan:string;
st1:string;
st2:string;
lo:integer;
begin
//showmessage('à¡ÕèÂǡѺÃÒ§ҹ'+#13+'Custom IN-Patient Summary');
// test with an 461402487
fan := '490000097';
if preset_value(1)='' then
begin
if not inputquery('Please enter Admit Number','AN',fan) then exit;
end else
begin
fan:=preset_value(1);
end;
zquery.sql.text:='delete from tempreport where id = "CUSTOM-IPT1" ';
zquery.execsql;
if getsqldata('select count(*) as cc from ipt where an="'+fan+'"')=0 then
raise exception.create('Invalid AN');
if getsqldata('select count(*) as cc from income_report2')=0 then
begin
zquery.close;
zquery.sql.text:='INSERT INTO income_report2 (group_id, group_name) VALUES '+
' (1,''¤èÒËéͧ/¤èÒÍÒËÒÃ''), '+
' (2,''ÍÇÑÂÇÐà·ÕÂÁ/ÍØ»¡Ã³ì㹡ÒúӺѴÃÑ¡ÉÒ''), '+
' (3,''ÂÒáÅÐÊÒÃÍÒËÒ÷ҧàÊé¹àÅ×Í´·Õèãªé㹠þ.''), '+
' (4,''ÂÒ·Õè¹Óä»ãªéµèÍ·ÕèºéÒ¹''), '+
' (5,''àǪÀѳ±ì·ÕèäÁèãªèÂÒ''), '+
' (6,''ºÃÔ¡ÒÃâÅËÔµáÅÐÊèǹ»ÃСͺ¢Í§âÅËÔµ''), '+
' (7,''µÃǨÇÔ¹Ô¨©Ñ·ҧ෤¹Ô¤¡ÒÃá¾·ÂìáÅоÂÒ¸ÔÇÔ·ÂÒ''), '+
' (8,''µÃǨÇÔ¹Ô¨©ÑÂáÅÐÃÑ¡ÉÒ·Ò§ÃѧÊÕÇÔ·ÂÒ''), '+
' (9,''µÃǨÇÔ¹Ô¨©ÑÂâ´ÂÇÔ¸Õ¾ÔàÈÉÍ×è¹æ''), '+
' (10,''ÍØ»¡Ã³ì¢Í§ãªéáÅÐà¤Ã×èͧÁ×Í·Ò§¡ÒÃá¾·Âì''), '+
' (11,''·ÓËѵ¶¡ÒÃáÅкÃÔ¡ÒÃÇÔÊÑ­­Õ''), '+
' (12,''¤èÒºÃÔ¡Ò÷ҧ¡ÒþÂÒºÒÅ''), '+
' (13,''ºÃÔ¡Ò÷ҧ·Ñ¹µ¡ÃÃÁ''), '+
' (14,''ºÃÔ¡Ò÷ҧ¡ÒÂÀÒ¾ºÓºÑ´áÅÐàǪ¡ÃÃÁ¿×鹿Ù''), '+
' (15,''ºÃÔ¡Òýѧà¢çÁ/¡ÒúӺѴ¢Í§¼Ùé»ÃСͺâäÈÔÅ»ÐÍ×è¹æ''), '+
' (16,''ºÃÔ¡ÒÃÍ×è¹·ÕèäÁèà¡ÕèÂÇ¢éͧ¡Ñº¡ÒÃÃÑ¡ÉÒ'') ';
zquery.execsql;
end;
zquery.sql.text:='delete from tempreport where id = "CUSTOM-IPT1" ';
zquery.execsql;
fcds.close;
fcds.datarequest('select * from tempreport where id = "CUSTOM-IPT1" ');
fcds.open;
fcds2.close;
fcds2.datarequest('select * from an_stat where an= "'+fan+'" ');
fcds2.open;
setstatuslabel('Open result : '+inttostr(fcds2.recordcount)+' Records');
if fcds2.recordcount=0 then
begin
showmessage('Invalid AN');
exit;
end;
fcds3.close;
fcds3.datarequest('select r.group_id,r.group_name,sum(h1.rcptamt) as total1,sum(h2.rcptamt) as total2 ,sum((h1.rcptamt)+(h2.rcptamt)) as total3'+
' from income_report2 r '+
' left outer join income i on i.income_group=r.group_id '+
' left outer join incith h1 on h1.income=i.income and h1.an="'+fan+'" and h1.paidst in ("01","00","02") '+
' left outer join incith h2 on h2.income=i.income and h2.an="'+fan+'" and h2.paidst in ("03") '+
' group by r.group_id, r.group_name '+
' order by r.group_id ');
fcds3.open;
fcds3.first;
while not fcds3.eof do
begin
fcds.insert;
fcds['id']:='CUSTOM-IPT1';
fcds['reportname']:='CUSTOM-IPT1';
fcds['name1']:=getsqldata('select concat(pname,fname," ",lname) as name from patient where hn="'+
fcds2['hn']+'"');
fcds['name2']:=fan;
fcds['name3']:=fcds2['hn'];
// address
st2:='';
st1:=vartostr(getsqldata('select addrpart from patient where hn="'+fcds2['hn']+'"'));
st2:=st1; // assign address part
st1:=vartostr(getsqldata('select moopart from patient where hn="'+fcds2['hn']+'"'));
if st1<>'' then
st2:=st2+' ËÁÙè '+st1;
st1:=vartostr(getsqldata('select road from patient where hn="'+fcds2['hn']+'"'));
if st1<>'' then
st2:=st2+' ¶. '+st1;
st1:=vartostr(getsqldata('select name from thaiaddress where concat(chwpart,amppart,tmbpart)="'+
fcds2['aid']+'"'));
st2:=st2+' µ.'+st1;
st1:=vartostr(getsqldata('select name from thaiaddress where concat(chwpart,amppart,tmbpart)="'+
copy(fcds2['aid'],1,4)+'00"'));
st2:=st2+' Í.'+st1;
st1:=vartostr(getsqldata('select name from thaiaddress where concat(chwpart,amppart,tmbpart)="'+
copy(fcds2['aid'],1,2)+'0000"'));
st2:=st2+' ¨.'+st1;
fcds['name5']:= st2;
st1:=vartostr(getsqldata('select name from icd101 where code="'+copy(vartostr(fcds2['pdx']),1,3)+'" '));
fcds['name4']:=vartostr(fcds2['pdx'])+' '+st1;
st1:=vartostr(getsqldata('select name from icd101 where code="'+copy(vartostr(fcds2['dx0']),1,3)+'"'));
fcds['name8']:= vartostr(fcds2['dx0'])+' '+st1;
fcds['name6']:=vartostr(getsqldata('select cid from vn_stat where vn="'+fcds2['vn']+'"'));
st1:=vartostr(getsqldata('select dch_doctor from ipt where an="'+fan+'"'));
st1:=vartostr(getsqldata('select name from doctor where code="'+st1+'"'));
fcds['name7']:=st1;
st1:=vartostr(getsqldata('select pttype from ipt where an="'+fan+'"'));
st1:=vartostr(getsqldata('select name from pttype where pttype="'+st1+'"'));
fcds['name7']:=vartostr(fcds['name7'])+' ÊÔ·¸Ô¡ÒÃÃÑ¡ÉÒ '+st1;
fcds['num1']:=fcds2['age_y'];
fcds['num2']:=fcds2['age_m'];
fcds['num3']:=fcds2['age_d'];
fcds['num4']:=1;
fcds['date1']:=fcds2['regdate'];
fcds['date2']:=fcds2['dchdate'];
// fcds['date4']:=fcds2['vstdate'];
try fcds['name9']:=fcds3['group_name']; except end;
try fcds['mon1']:=fcds3['total1']; except fcds['mon1']:=0; end;
try fcds['mon2']:=fcds3['total2']; except fcds['mon2']:=0; end;
try fcds['mon10']:=fcds3['total3']; except fcds['mon10']:=0; end;
try fcds['mon3']:=fcds3['group_id']; except end;
try fcds['mon4']:=fcds2['admdate']; except end;
fcds.post;
fcds3.next;
end;
fcds3.close;
fcds.datarequest('select * from tempreport where id = "CUSTOM-IPT1" ');
applyupdate_fcds();
end;
end.