ผู้เขียน หัวข้อ: ตัวอย่าง DBF -> patient import script  (อ่าน 3643 ครั้ง)

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

ออฟไลน์ manoi

  • Hero Member
  • *****
  • กระทู้: 8,669
  • Respect: +170
    • ดูรายละเอียด
    • HOSxP Community Center
ตัวอย่าง DBF -> patient import script
« เมื่อ: กันยายน 30, 2006, 01:58:25 AM »
0
โค๊ด: Delphi
  1.  
  2.  
  3. Unit Script;
  4.  
  5. const
  6.  
  7.  
  8.  
  9.   dbf_path = 'd:\statwin\';
  10.  
  11.   HoursPerDay   = 24;
  12.   MinsPerHour   = 60;
  13.   SecsPerMin    = 60;
  14.   MSecsPerSec   = 1000;
  15.   MinsPerDay    = HoursPerDay * MinsPerHour;
  16.   SecsPerDay    = MinsPerDay * SecsPerMin;
  17.   MSecsPerDay   = SecsPerDay * MSecsPerSec;
  18.  
  19. function IncTime(ATime: TDateTime; Hours, Minutes, Seconds,
  20.   MSecs: Integer): TDateTime;
  21. begin
  22.   Result := ATime + (Hours div 24) + (((Hours mod 24) * 3600000 +
  23.     Minutes * 60000 + Seconds * 1000 + MSecs) / MSecsPerDay);
  24.   if Result < 0 then
  25.     Result := Result + 1;
  26. end;
  27.  
  28. function IncHour(ATime: TDateTime; Delta: Integer): TDateTime;
  29. begin
  30.   Result := IncTime(ATime, Delta, 0, 0, 0);
  31. end;
  32.  
  33. function IncMinute(ATime: TDateTime; Delta: Integer): TDateTime;
  34. begin
  35.   Result := IncTime(ATime, 0, Delta, 0, 0);
  36. end;
  37.  
  38. function IncSecond(ATime: TDateTime; Delta: Integer): TDateTime;
  39. begin
  40.   Result := IncTime(ATime, 0, 0, Delta, 0);
  41. end;
  42.  
  43.  
  44. function addzero(s:string;i:integer):string;
  45. begin
  46.   //result:=s;
  47.   while length(s)<i do
  48.   begin
  49.     s:='0'+s;
  50.   end;
  51.   result:=s;
  52. end;
  53.  
  54. function CheckPID(pid: string): boolean;
  55. var
  56.   i: integer;
  57.   nMod, nValue, cv: integer;
  58.   snmod: string;
  59. begin
  60.   pid := replacestr(pid, '-', '');
  61.   result := false;
  62.   if length(replacestr(pid, ' ', '')) <> 13 then
  63.     exit;
  64.  
  65.   try
  66.  
  67.     cv := strtoint(copy(pid, 1, 1));
  68.     nValue := cv * 13;
  69.  
  70.     for i := 2 to 12 do
  71.     begin
  72.       cv := strtoint(copy(pid, i, 1));
  73.       nValue := nValue + (cv * (14 - i));
  74.  
  75.     end;
  76.  
  77.     nMod := 11 - (nValue mod 11);
  78.     snmod := inttostr(nmod);
  79.     snmod := copy(snmod, length(snmod), 1);
  80.     result := copy(pid, 13, 1) = snmod;
  81.  
  82.   except
  83.     result := false;
  84.  
  85.   end;
  86.  
  87. end;
  88.  
  89. function MakeFullCID(cid: string): string;
  90. begin
  91.   result := cid;
  92.   if length(cid) = 17 then
  93.     exit;
  94.   result := '';
  95.   if length(cid) <> 13 then
  96.     exit;
  97.   result := copy(cid, 1, 1) + '-' +
  98.     copy(cid, 2, 4) + '-' +
  99.     copy(cid, 6, 5) + '-' +
  100.     copy(cid, 11, 2) + '-' +
  101.     copy(cid, 13, 1);
  102. end;
  103.  
  104.  
  105.  
  106.  
  107.  
  108. Procedure DoImportPatient;
  109. var
  110.   i:integer;
  111.   card_tablename:string;
  112.   ic,ip:integer;
  113.  
  114.   fhn:string;
  115.   cid:string;
  116. begin
  117.  
  118.  
  119.  
  120.   dbf1.close;
  121.   dbf1.tablename:=dbf_path+'data\opd\mainrec.dbf';
  122.   dbf1.open;
  123.  
  124.  
  125.  
  126.   setstatuslabel('Importing... opd patient data');
  127.  
  128.   setcursorbusy(true);
  129.  
  130.   dbf1.first;
  131.   i:=0;
  132.   while not dbf1.eof do
  133.   begin
  134.     i:=i+1;
  135.     dbf1.next;
  136.   end;
  137.  
  138.   setprogressbar(0,i);
  139.  
  140.  
  141.   fcds.close;
  142.   fcds.datarequest('select * from patient');
  143.   fcds.open;
  144.  
  145.   fcds3.close;
  146.   fcds3.datarequest('select * from ptcardno');
  147.   fcds3.open;
  148.  
  149.   dbf1.first;
  150.   ic:=0;
  151.   ip:=0;
  152.  
  153.   DisableReconcileDialog;
  154.  
  155.   while not dbf1.eof do
  156.   begin
  157.     ip:=ip+1;
  158.     setprogressbar(ip,i);
  159.  
  160.     //fhn:=addzero(dbf1.fieldbyname('hn').asstring,7);
  161.     fhn:=dbf1.fieldbyname('hn').asstring;
  162.     ic:=ic+1;
  163.     if (ic mod 25)=0 then
  164.     setstatuslabel('Processing ... '+inttostr(ic)+'/'+inttostr(i));
  165.  
  166.     fcds.insert;
  167.     fcds.fieldbyname('hos_guid').asstring:=get_new_guid;
  168.     fcds.fieldbyname('hn').asstring:=fhn;
  169.     fcds.fieldbyname('pname').asstring:=dbf1.fieldbyname('status').asstrin g;
  170.     fcds.fieldbyname('fname').asstring:=dbf1.fieldbyname('fname').asstring  ;
  171.     fcds.fieldbyname('lname').asstring:=dbf1.fieldbyname('lname').asstring  ;
  172.     try fcds.fieldbyname('birthday').asdatetime:=dbf1.fieldbyname('dob').asdat etime; except end;
  173.     fcds.fieldbyname('sex').asstring:=dbf1.fieldbyname('sex').asstring;
  174.     fcds.fieldbyname('marrystatus').asstring:=dbf1.fieldbyname('marriage') .asstring;
  175.     fcds.fieldbyname('addrpart').asstring:=dbf1.fieldbyname('address').ass tring;
  176.     fcds.fieldbyname('node_id').asstring:='';
  177.     fcds.fieldbyname('road').asstring:=dbf1.fieldbyname('road').asstring;
  178.     fcds.fieldbyname('moopart').asstring:=dbf1.fieldbyname('village').asst ring;
  179.     fcds.fieldbyname('chwpart').asstring:=dbf1.fieldbyname('changwat').ass tring;
  180.     fcds.fieldbyname('amppart').asstring:=dbf1.fieldbyname('amphur').asstr ing;
  181.     fcds.fieldbyname('tmbpart').asstring:=dbf1.fieldbyname('tambon').asstr ing;
  182.     fcds.fieldbyname('po_code').asstring:=dbf1.fieldbyname('zipcode').asst ring;
  183.     fcds.fieldbyname('hometel').asstring:=dbf1.fieldbyname('phone').asstri ng;
  184.     fcds.fieldbyname('religion').asstring:='01';
  185.     fcds.fieldbyname('occupation').asstring:=dbf1.fieldbyname('occupa').as string;
  186.     fcds.fieldbyname('nationality').asstring:=dbf1.fieldbyname('nation').a sstring;
  187.     fcds.fieldbyname('citizenship').asstring:=dbf1.fieldbyname('nation').a sstring;
  188.     //fcds.fieldbyname('bloodgrp').asstring:=dbf1.fieldbyname('bl_gr').ass tring;
  189.     //fcds.fieldbyname('drugallergy').asstring:=dbf1.fieldbyname('dallergy ').asstring;
  190.  
  191.     cid:='';
  192.  
  193.     if checkpid(dbf1.fieldbyname('person_id').asstring) then
  194.        cid:=dbf1.fieldbyname('person_id').asstring;
  195.  
  196.     if cid<>'' then
  197.     begin
  198.  
  199.       fcds.fieldbyname('cid').asstring:=cid;
  200.  
  201.       fcds3.insert;
  202.       fcds3.fieldbyname('hn').asstring:=fhn;
  203.       fcds3.fieldbyname('cardtype').asstring:='01';
  204.       fcds3.fieldbyname('cardno').asstring:=MakeFullCID(cid);
  205.       fcds3.post;
  206.     end;
  207.  
  208.  
  209.  
  210.     fcds.post;
  211.  
  212.  
  213.    if (ip mod 50)=0 then
  214.    begin
  215.      fcds.datarequest('select * from patient limit 0');
  216.      applyupdate_fcds;
  217.  
  218.      fcds3.datarequest('select * from ptcardno limit 0');
  219.      applyupdate_fcds3;
  220.  
  221.    end;
  222.  
  223.    dbf1.next;
  224.   end;
  225.  
  226.   fcds.datarequest('select * from patient limit 0');
  227.   applyupdate_fcds;
  228.  
  229.   fcds3.datarequest('select * from ptcardno limit 0');
  230.   applyupdate_fcds3;
  231.   fcds3.close;
  232.   fcds.close;
  233.   dbf1.close;
  234.  
  235.   setcursorbusy(false);
  236.  
  237. end;
  238.  
  239.  
  240. Procedure Main;
  241. begin
  242.  
  243.  
  244.  
  245.  if messagedlg('Please confirm import'+#13+'patient and ptcardno data will be delete '+#13+
  246.  'Current statwin data path = '+dbf_path,mtconfirmation,[mbyes,mbno],0)=mryes then
  247.  begin
  248.  
  249.    DoImportPatient;
  250.  
  251. end;
  252.  
  253. end;
  254.  
  255. end.
  256.  
  257.  
HOSxP Project Manager / Cheif Developer / BMS MD