สวัสดีครับ วันนี้ลองแก้ดู ก็ยังไม่ได้ ยากจิง ๆๆครับ มันเป็ย Code pascal อยากได้เป็นชื่อ สิทธิ ที่เป็น ชื่อไทยครับ
ของเดิมมันเป้นตัวเลครับ เช่น 89 ถ้าเป็นชื่อไทยก็ UC-12-59 ในตาราง Pttype แต่เขียนให้มันจับกันไม่ได้ครับ ถ้าเป้น sql พอไหว
ใครพอมีเวลา ว่าง ๆ กรุณา ช่วยเขียนเพิ่มให้นิดหนึงครับ ยังไม่ค่อยเข้าใน Code ครับ ตัวอย่าง Code มนัครับ
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 := '461402487';
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');
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;
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'];
fcds['name4']:=fcds2['pttype'];
// 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 informname from patient where hn="'+fcds2['hn']+'"'));
fcds['name8']:= st1;
st1:=vartostr(getsqldata('select informaddr from patient where hn="'+fcds2['hn']+'"'));
fcds['name9']:= st1;
fcds['name6']:=vartostr(getsqldata('select cid from vn_stat where vn="'+fcds2['vn']+'"'));
if fcds2['sex']='1' then
fcds['name7']:='MALE' else
fcds['name7']:='FEMALE';
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'];
fcds.post;
fcds.insert;
fcds['id']:='CUSTOM-IPT1';
fcds['reportname']:='CUSTOM-IPT1';
fcds['num4']:=2;
st1:=vartostr(getsqldata('select religion from patient where hn="'+fcds2['hn']+'"'));
st1:=vartostr(getsqldata('select name from religion where religion="'+st1+'"'));
fcds['name1']:= st1;
st1:=vartostr(getsqldata('select marrystatus from patient where hn="'+fcds2['hn']+'"'));
st1:=vartostr(getsqldata('select name from marrystatus where code="'+st1+'"'));
fcds['name2']:= st1;
st1:=vartostr(getsqldata('select occupation from patient where hn="'+fcds2['hn']+'"'));
st1:=vartostr(getsqldata('select name from occupation where occupation="'+st1+'"'));
fcds['name3']:= st1;
st1:=formatdatetime('d mmm eeee',getsqldata('select birthday from patient where hn="'+fcds2['hn']+'"'));
fcds['name4']:= st1;
st1:=vartostr(getsqldata('select gravidity from ipt where an="'+fan+'"'));
fcds['name5']:= st1;
st1:=vartostr(getsqldata('select parity from ipt where an="'+fan+'"'));
fcds['name6']:= st1;
st1:=vartostr(getsqldata('select living_children from ipt where an="'+fan+'"'));
fcds['name7']:= st1;
st1:=vartostr(getsqldata('select birthcondition1 from ipt_newborn where an="'+fan+'"'));
if st1='0' then
fcds['name8']:= 'LIVEBORN' else
if st1='1' then
fcds['name8']:= 'STILLBORN';
st1:=vartostr(getsqldata('select birthcondition2 from ipt_newborn where an="'+fan+'"'));
if st1='0' then
fcds['name9']:= 'CLINICALLY MATURE' else
if st1='1' then
fcds['name9']:= 'CLINICALLY PREMATURE';
try
i:=getsqldata('select birth_weight from ipt_newborn where an="'+fan+'"');
except
i:=0;
end;
if i>0 then
fcds['mon1']:=i;
fcds.post;
fcds.insert;
fcds['id']:='CUSTOM-IPT1';
fcds['reportname']:='CUSTOM-IPT1';
fcds['num4']:=3;
st1:=vartostr(getsqldata('select ward from ipt where an="'+fan+'"'));
fcds['name1']:= st1;
st1:=vartostr(getsqldata('select name from ward where ward="'+st1+'"'));
fcds['name2']:= st1;
try
fcds['name3']:=formatdatetime('d mmmm eeee',
getsqldata('select regdate from ipt where an="'+fan+'"') );
except
end;
try
fcds['name4']:=formatdatetime('d mmmm eeee',
getsqldata('select dchdate from ipt where an="'+fan+'"') );
except
end;
try
fcds['name5']:=vartostr(getsqldata('select admdate from an_stat where an="'+fan+'"')) ;
except
end;
st1:=vartostr(getsqldata('select pdx from an_stat where an="'+fan+'"'));
fcds['name6']:= st1+' '+
vartostr(getsqldata('select name from icd101 where code="'+st1+'"'));
st1:=getsqlsubquerydata('select icd10 from iptdiag where an="'+fan+'" and diagtype="2"');
fcds['name7']:= st1+' '+
getsqlsubquerydata('select name from icd101 where code in ('+st1+')');
st1:=getsqlsubquerydata('select icd10 from iptdiag where an="'+fan+'" and diagtype="3"');
fcds['name8']:= st1+' '+
getsqlsubquerydata('select name from icd101 where code in ('+st1+')');
st1:=getsqlsubquerydata('select icd10 from iptdiag where an="'+fan+'" and diagtype="4"');
fcds['name9']:= st1+' '+
getsqlsubquerydata('select name from icd101 where code in ('+st1+')');
fcds.post;
fcds.insert;
fcds['id']:='CUSTOM-IPT1';
fcds['reportname']:='CUSTOM-IPT1';
fcds['num4']:=4;
fcds3.close;
fcds3.datarequest('select * from iptoprt where an="'+fan+'" order by priority, opdate,optime ');
fcds3.open;
fcds3.first;
lo:=0;
while not fcds3.eof do
begin
lo:=lo+1;
case lo of
1 :
begin
st1:=fcds3.fieldbyname('icd9').asstring;
fcds['name1']:=st1+' '+vartostr(getsqldata('select name from icd9cm1 where code="'+st1+'"'));
fcds['name2']:=formatdatetime('dd-mm-eeee',fcds3.fieldbyname('opdate').asdatetime );
fcds['name3']:=formatdatetime('hh:nn',fcds3.fieldbyname('optime').asdatetime );
fcds['name4']:=formatdatetime('hh:nn',fcds3.fieldbyname('endtime').asdatetime );
end;
2 :
begin
st1:=fcds3.fieldbyname('icd9').asstring;
fcds['name5']:=st1+' '+vartostr(getsqldata('select name from icd9cm1 where code="'+st1+'"'));
fcds['name6']:=formatdatetime('dd-mm-eeee',fcds3.fieldbyname('opdate').asdatetime );
fcds['name7']:=formatdatetime('hh:nn',fcds3.fieldbyname('optime').asdatetime );
fcds['name8']:=formatdatetime('hh:nn',fcds3.fieldbyname('endtime').asdatetime );
end;
end;
fcds3.next;
end;
st1:=vartostr(getsqldata('select dchstts from ipt where an="'+fan+'" '));
fcds['name9']:= vartostr(getsqldata('select name from dchstts where dchstts = "'+st1+'"'));
fcds.post;
fcds.insert;
fcds['id']:='CUSTOM-IPT1';
fcds['reportname']:='CUSTOM-IPT1';
fcds['num4']:=5;
fcds3.close;
fcds3.datarequest('select * from iptoprt where an="'+fan+'" order by priority, opdate,optime ');
fcds3.open;
fcds3.first;
lo:=0;
while not fcds3.eof do
begin
lo:=lo+1;
case lo of
3 :
begin
st1:=fcds3.fieldbyname('icd9').asstring;
fcds['name1']:=st1+' '+vartostr(getsqldata('select name from icd9cm1 where code="'+st1+'"'));
fcds['name2']:=formatdatetime('dd-mm-eeee',fcds3.fieldbyname('opdate').asdatetime );
fcds['name3']:=formatdatetime('hh:nn',fcds3.fieldbyname('optime').asdatetime );
fcds['name4']:=formatdatetime('hh:nn',fcds3.fieldbyname('endtime').asdatetime );
end;
4 :
begin
st1:=fcds3.fieldbyname('icd9').asstring;
fcds['name5']:=st1+' '+vartostr(getsqldata('select name from icd9cm1 where code="'+st1+'"'));
fcds['name6']:=formatdatetime('dd-mm-eeee',fcds3.fieldbyname('opdate').asdatetime );
fcds['name7']:=formatdatetime('hh:nn',fcds3.fieldbyname('optime').asdatetime );
fcds['name8']:=formatdatetime('hh:nn',fcds3.fieldbyname('endtime').asdatetime );
end;
end;
fcds3.next;
end;
st1:=vartostr(getsqldata('select dchtype from ipt where an="'+fan+'" '));
fcds['name9']:= vartostr(getsqldata('select name from dchtype where dchtype = "'+st1+'"'));
if st1='04' then
begin
st1:=vartostr(getsqldata('select rfrolct from ipt where an="'+fan+'"')) ;
st1:=vartostr(getsqldata('select concat(hosptype," ",name) as name from hospcode where hospcode="'+st1+'"'));
fcds['name9']:=fcds['name9']+' '+st1;
end;
fcds.post;
fcds.datarequest('select * from tempreport where id = "CUSTOM-IPT1" ');
applyupdate_fcds();
end;
end.