ผู้เขียน หัวข้อ: ขอความช่วยเหลือเกี่ยวกับ Code รายงานหน่อยครับ  (อ่าน 4953 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ neopalm

  • Full Member
  • ***
  • กระทู้: 102
  • Respect: +1
    • ดูรายละเอียด
ผมทำรายงานเด็กเกิดใหม่ครับ เป็น Custom Report
โดยให้สามารถเลือกช่วงวันที่ที่ต้องการดึงข้อมูลได้
แต่พบปัญหาว่า หากมีวันไหนที่ไม่มีข้อมูล เพียงแค่วันเดียว มันก็จะไม่แสดงข้อมูลที่เหลือเลย
ไม่ทราบว่าจะทำอย่างไรดีครับ

ผมแนบไฟล์รายงานมาด้วยครับ

unit MyIPDReport;

function getsqlsubquerydata(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;
ds1,ds2,tambon,ampur,chw:string;
begin
   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-PCU-INFANT" ';
   zquery.execsql;
   fcds.close;
   fcds.datarequest('select * from tempreport where id = "CUSTOM-PCU-INFANT" ');
   fcds.open;
   fcds2.close;
   fcds2.datarequest('select * from ipt_labour_infant i left outer join ipt_labour l on l.ipt_labour_id=i.ipt_labour_id where i.birth_date between "'+ds1+'" and "'+ds2+'" order by i.ipt_labour_infant_id asc');
   fcds2.open;

     
   while not fcds2.eof do
   begin
   fcds.insert;
   fcds['id']:='CUSTOM-PCU-INFANT';
   fcds['reportname']:='CUSTOM-PCU-INFANT';
   fcds['num']:=fcds2['ipt_labour_infant_id'];
   fcds['num1']:=fcds2['birth_weight'];
   fcds['name']:=fcds2['an'];
   fcds['name1']:=getsqldata('select hn from ipt where an=(select an from ipt_newborn where mother_an='+fcds2['an']+')');
   fcds['name2']:=getsqldata('select concat(pname,fname," ",lname) as paname from patient where hn='+fcds['name1']);
   fcds['name3']:=getsqldata('select concat(fathername," ",fatherlname) as fathername from patient where hn='+fcds['name1']);
   fcds['name4']:=getsqldata('select concat(mathername," ",motherlname) as mothername from patient where hn='+fcds['name1']);
   
   tambon       :=getsqldata('select tmbpart from patient where hn='+fcds['name1']);
   ampur        :=getsqldata('select amppart from patient where hn='+fcds['name1']);
   chw          :=getsqldata('select chwpart from patient where hn='+fcds['name1']);
   fcds['name5']:=getsqldata('select concat(addrpart," ËÁÙè ",moopart'+
   '," µ.",(select name from thaiaddress where codetype=3 and chwpart='+chw+' and amppart='+ampur+' and tmbpart='+tambon+')'+
   '," Í.",(select name from thaiaddress where codetype=2 and chwpart='+chw+' and amppart='+ampur+')'+
   '," ¨.",(select name from thaiaddress where codetype=1 and chwpart='+chw+'))'+
   ' as address from patient where hn='+fcds['name1']);
   
   fcds['name6']:=fcds2['infant_check_vitk'];
   fcds['name7']:=fcds2['infant_check_eyepaste'];
   fcds['name8']:=formatdatetime('HH:mm',fcds2['birth_time']);
   fcds['date1']:=d1;
   fcds['date2']:=d2;
   fcds['date3']:=fcds2['birth_date'];
   
   
   fcds.post;
   fcds2.next;
   
   
   end;

   fcds.datarequest('select * from tempreport where id = "CUSTOM-PCU-INFANT" ');
   applyupdate_fcds();

end;

end.
เอกภาพ  ศรีเจริญ (อั้ง)
นักวิชาการคอมพิวเตอร์ (ลูกจ้างชั่วคราว) โรงพยาบาลชุมชน ท่าอุเทน จ.นครพนม

ขึ้นระบบเอง เริ่มใช้ HOSxP 1 มกราคม 2552 ปัจจุบันใช้ HOSxP V.3.52.6.4
Module
OPD  :   ห้องบัตร ซักประวัติ ห้องตรวจ ห้องยา LAB ห้องฟัน ห้องฉุกเฉิน PCU X-Ray นวดแผนไทย
 IPD  :   Ward ห้องคลอด
Main   :  Server OS Linux CentOS 5.2  MySQL 5.1.30  IBM System x3650 Server
            Intel Xeon Quadcore 2.0 Ghz  SAS Drive 3x146Gb 15000rpm Ram 2x1Gb  667Mhz

ออฟไลน์ armds

  • Hero Member
  • *****
  • กระทู้: 1,084
  • armds
  • Respect: +10
    • ดูรายละเอียด
Re: ขอความช่วยเหลือเกี่ยวกับ Code รายงานหน่อยครับ
« ตอบกลับ #1 เมื่อ: เมษายน 05, 2009, 23:25:00 PM »
0
แนะนำละกันนะครับ (ไม่เก่งหรอกนะ)
ผมว่าเขียน  คำสั่งเพิ่มจาก 
fcds2.datarequest('select * from ipt_labour_infant i left outer join ipt_labour l on l.ipt_labour_id=i.ipt_labour_id where i.birth_date between "'+ds1+'" and "'+ds2+'" order by i.ipt_labour_infant_id asc');

ให้ไปเชื่อมกับ  ipt_newborn   หรือ  patient  หรือ  thaiaddress   หรืออื่นๆ ที่ต้องการ  left outer join  เข้าไปอีก

จะได้เลี่ยงการใช้  ฟังชัน  getsqldata()   จะได้ดึงข้อมูลเร็วกว่านะครับ  เพราะดูแล้ว  เห็นดึง  patient  มาเยอะเหมือนกัน  เช่น  hn  ชื่อ พ่อ  แม่  ที่อยู่    เป็นต้น
ส่วน
 fcds['name8']:=formatdatetime('HH:mm',fcds2['birth_time']);
 ก็ไปกำหนดตอนแสดงผลก็ได้นะครับ  ใช้แสดงแค่  HH:mm  ก็ได้ครับ

สรุปคือเขียนให้สั้นลง  จะได้เร็วขึ้นและสะดวกขึ้นครับ 
 
โรงพยาบาลสมเด็จพระยุพราชด่านซ้าย จ.เลย
ขนาด 60 เตียง นวก. คอมพิวเตอร์ ขึ้นระบบ ปี 2548
ขอบคุณ อ.ชัยพร อ.สุชัย อ.เดชา อ.doreamon อ.naj อ.ขวด และอ.ในเว็บ hosxp.net ทุกท่าน

ออฟไลน์ armds

  • Hero Member
  • *****
  • กระทู้: 1,084
  • armds
  • Respect: +10
    • ดูรายละเอียด
Re: ขอความช่วยเหลือเกี่ยวกับ Code รายงานหน่อยครับ
« ตอบกลับ #2 เมื่อ: เมษายน 06, 2009, 11:14:39 AM »
0
ลองเอาไปใช้ดูนะครับ  แต่ผมดึงจาก  ตาราง  ipt_newborn  นะครับ 

fcds2.datarequest('select inew.*,i.*,concat(p.pname," ",p.fname," ",p.lname) as fullname from ipt_newborn   inew  '+
    ' left join ipt  i on i.an=inew.an                        '+
    ' left join patient p on p.hn=i.hn                        '+
    ' where inew.born_date between"'+ds1+'" and "'+ds2+'"  ');
โรงพยาบาลสมเด็จพระยุพราชด่านซ้าย จ.เลย
ขนาด 60 เตียง นวก. คอมพิวเตอร์ ขึ้นระบบ ปี 2548
ขอบคุณ อ.ชัยพร อ.สุชัย อ.เดชา อ.doreamon อ.naj อ.ขวด และอ.ในเว็บ hosxp.net ทุกท่าน

ออฟไลน์ neopalm

  • Full Member
  • ***
  • กระทู้: 102
  • Respect: +1
    • ดูรายละเอียด
Re: ขอความช่วยเหลือเกี่ยวกับ Code รายงานหน่อยครับ
« ตอบกลับ #3 เมื่อ: เมษายน 07, 2009, 09:37:32 AM »
0
ขอบคุณครับ
ขอบคุณสังคมแห่งความมีน้ำใจ ครับ
เอกภาพ  ศรีเจริญ (อั้ง)
นักวิชาการคอมพิวเตอร์ (ลูกจ้างชั่วคราว) โรงพยาบาลชุมชน ท่าอุเทน จ.นครพนม

ขึ้นระบบเอง เริ่มใช้ HOSxP 1 มกราคม 2552 ปัจจุบันใช้ HOSxP V.3.52.6.4
Module
OPD  :   ห้องบัตร ซักประวัติ ห้องตรวจ ห้องยา LAB ห้องฟัน ห้องฉุกเฉิน PCU X-Ray นวดแผนไทย
 IPD  :   Ward ห้องคลอด
Main   :  Server OS Linux CentOS 5.2  MySQL 5.1.30  IBM System x3650 Server
            Intel Xeon Quadcore 2.0 Ghz  SAS Drive 3x146Gb 15000rpm Ram 2x1Gb  667Mhz