ผู้เขียน หัวข้อ: HI 271 Exchange hosxp ส่งข้อมูลรายวันกลับด้วย  (อ่าน 6960 ครั้ง)

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

doramon

  • บุคคลทั่วไป
HI 271 Exchange hosxp ส่งข้อมูลรายวันกลับด้วย
« เมื่อ: มกราคม 06, 2007, 11:21:37 AM »
0
โค๊ด: Delphi
  1.  
  2. unit StatExchange;
  3. // version 0.1.1
  4. // 2006-09-05
  5. // Chaiyaporn Suratemekul
  6. //  2006-10-28
  7. // Tawee  Supklang  
  8.  
  9. var StatPath: string;
  10.  
  11.   MainForm: TForm;
  12.   StartButton: TButton;
  13.   AbortButton: TButton;
  14.   StatusMemo: TMemo;
  15.   FAbort: Boolean;
  16.   StatusLabel : TLabel;
  17.   ErrMemo:TMemo;
  18.  
  19.   LastErr: string;
  20.  
  21. implementation
  22.  
  23. Procedure AddLog(s:string);
  24. begin
  25.   StatusMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+'>'+s);
  26.  
  27. end;
  28.  
  29. Procedure CheckErr;
  30. begin
  31.  
  32.   if LastErr<>'' then
  33.   if Pos('CommandText', LastErr) = 0 then ErrMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+' '+LastErr);
  34.  
  35. end;
  36.  
  37.  
  38. procedure StartExport;
  39. var
  40.   sconnection: string; // variable for hold connection string
  41.   st: string; // variable for hold any string
  42.   tc,stoday, StatCDS: Tclientdataset;
  43.   QueueCDS: TClientDataset;
  44.  
  45. begin
  46.  
  47.   if StatPath = '' then
  48.   begin
  49.     StatPath := VarToStr(GetSQLData('select statroot from opdconfig'));
  50.     StatusMemo.Lines.Add('Stat Path = ' + statPath);
  51.   end;
  52.  
  53.   if StatPath = '' then
  54.   begin
  55.     AddLog('Error : no information in opdconfig.statroot');
  56.     exit;
  57.   end;
  58.  
  59.  
  60.  
  61.  
  62.   sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  63.  
  64.   ado_connection.connected := false;
  65.  
  66.   ado_connection.connectionstring := sconnection;
  67.  
  68.   ado_connection.connected := true;
  69.  
  70.   tc := tclientdataset.create(nil);
  71.   statcds := tclientdataset.create(nil);
  72.  // tc.data:=HOSxP_GetADODataset('select count(*) as cc from patient1');
  73.  // StatusMemo.lines.add('Start Import Patient');
  74.  
  75.   QueueCDS := TClientDataset.create(nil);
  76.  
  77.  
  78.   repeat
  79.  
  80.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
  81.  
  82.     while not QueueCDS.eof do
  83.     begin
  84.       LastErr := '';
  85. //      AddLog('Edit patient1 ' +  vartostr(strtoint(queuecds.fieldbyname('id').asstring)));
  86.       tc.data := HOSxP_GetDataset('select * from patient where hn = "' + queuecds.fieldbyname('id').asstring+'"');
  87.  
  88. //      '+ tc.fieldbyname('hn').asinteger+'"'
  89.       statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn ='+vartostr(strtoint(tc.fieldbyname('hn').asstring)));
  90.       if statcds.fieldbyname('cc').asinteger = 0 then
  91.       begin
  92.         LastErr := '';
  93.         StatusMemo.Lines.Add('======= New PT ====== [' + tc.fieldbyname('hn').asstring+']');
  94.         AddLog('Insert patient 1 '+tc.fieldbyname('hn').asstring);
  95.         try
  96.           HOSxP_GetADODataset('insert into pt (hn,pop_id,pname,fname,lname,brthdate,truebrth,dthdate,MALE,CTZSHP,NTNLTY,RLGN ,OCCPTN, BLOODGRP,ALLERGY, ADDRPART,MOOPART,TMBPART,AMPPART,CHWPART, HOMETEL, PTTYPE,MRTLST,SPSNAME, MTHNAME,FTHNAME,OFFADDR,OFFTEL
  97.          ,INFMNAME, PRSNRLT,INFMADDR,INFMTEL,OPDLCT,fdate,ldate,cid_m,cid_f,hmain,hsub,card,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10 )
  98.           values ('+tc['hn']+',"'+vartostr(tc['cid'])+'","'+tc['pname']+'","'+tc['fname']+'","'+tc['lname']+'",'+
  99.  
  100.             ' Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
  101.             formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
  102.             formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , '+
  103.  
  104.  
  105.            '1,{2006/01/01},"'+vartostr(tc['sex'])+'","",
  106.           "","","403","O","not","'+vartostr(tc['addrpart'])
  107.            +'","'+vartostr(tc['moopart'])
  108.            +'","'+vartostr(tc['tmbpart'])
  109.            +'","'+vartostr(tc['amppart'])
  110.            +'","'+vartostr(tc['chwpart'])+'"
  111.             ,"","10","1","","","","","","","","","","",{},{},"","","","","000","","","","","","","","","","")');
  112.  //          +vartostr(tc['addrpart'])+'","+
  113.  //          +vartostr(tc['moopart'])+'","+
  114.  //          +vartostr(tc['tmbpart'])+'","+
  115.  //          +vartostr(tc['amppart'])+'","+
  116.  //          +vartostr(tc['chwpart'])+'"'+
  117.  
  118.  
  119.  
  120.           except
  121.           on e: exception do
  122.           begin
  123.             LastErr := E.message;
  124.           end;
  125.         end;
  126.  
  127.         CheckErr;
  128.  
  129.  
  130.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn =' +vartostr(strtoint(tc.fieldbyname('hn').asstring)));
  131. //        if statcds.fieldbyname('cc').asinteger = 0 then StatusMemo.lines.add('Stat Insert Fail !!!');
  132.  
  133.       end else
  134.       begin
  135.         LastErr := '';
  136.         AddLog('Edit PT ' + tc.fieldbyname('hn').asstring);
  137.         try
  138.           HOSxP_GetADODataset('update pt set MALE = "' + vartostr(tc['sex']) + '" , ' +
  139. //           'fname = "' + vartostr(tc['fname']) + ' ' + vartostr(tc['lname']) + ',' + vartostr(tc['pname']) + '" ,' +
  140.             'pname = "'+vartostr(tc['pname'])+'" , ' +
  141.             'fname = "'+vartostr(tc['fname'])+'" , ' +
  142.             'lname = "'+vartostr(tc['lname'])+'" , ' +
  143.            'brthdate = Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
  144.           formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
  145.           formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , ' +
  146.           'mthname = "' + vartostr(tc['mathername']) + '" , ' +
  147.           'fthname = "' + vartostr(tc['fathername']) + '" , ' +
  148.           'addrpart = "' + vartostr(tc['addrpart']) + '" , ' +
  149.           'moopart = "' + vartostr(tc['moopart']) + '" , ' +
  150.           'tmbpart = "' + vartostr(tc['tmbpart']) + '" , ' +
  151.           'amppart = "' + vartostr(tc['amppart']) + '" , ' +
  152.           'chwpart = "' + vartostr(tc['chwpart']) + '" , ' +
  153.           'pttype = "' + vartostr(tc['pttype']) + '"  ' +
  154.             ' where hn = ' + vartostr(tc['hn']) + '');
  155.         except
  156.           on e: exception do
  157.           begin
  158.             LastErr := E.message;
  159.           end;
  160.         end;
  161.  
  162.       end;
  163.  
  164.  
  165.       CheckErr;
  166.  
  167.       QueueCDS.edit;
  168.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  169.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  170.       QueueCDs.post;
  171.  
  172.       QueueCDS.next;
  173.     end;
  174.  
  175.     if QueueCDs.ChangeCount > 0 then
  176.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
  177.  
  178.   until ((QueueCDS.RecordCount = 0) or FAbort);
  179.  
  180.  
  181.   repeat
  182.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
  183.  
  184.     while not QueueCDS.Eof do
  185.     begin
  186.       LastErr := '';
  187.       sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  188.  
  189.       ado_connection.connected := false;
  190.  
  191.       ado_connection.connectionstring := sconnection;
  192.  
  193.       ado_connection.connected := true;
  194.  
  195.       tc.data := HOSxP_GetDataset('select * from vn_stat where vn = "' + QueueCDS.fieldbyname('id').asstring + '"');
  196.       if tc.recordcount > 0 then
  197.       begin
  198.         LastErr := '';
  199.         StatusMemo.Lines.add('===== New Visit =====');
  200.         AddLog('Edit insure pttype ' + tc.fieldbyname('hn').asstring);
  201.         try
  202.           HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '",  ' +
  203.            'card_id = "' + vartostr(tc['pttypeno']) + '",  ' +
  204.            'pttype = "' + vartostr(tc['pttype']) + '",  ' +
  205.            'hospmain = "' + vartostr(tc['hospmain']) + '",  ' +
  206.            'hospsub = "' + vartostr(tc['hospsub']) + '"  ' +
  207.             ' where hn = ' + vartostr(tc['hn']) + '');
  208.         except
  209.           on e: exception do
  210.           begin
  211.             LastErr := E.message;
  212.           end;
  213.         end;
  214.  
  215.         CheckErr;
  216.  
  217.  
  218.         //check insurelog
  219.         sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  220.  
  221.  
  222.  
  223.         ado_connection.connected := false;
  224.  
  225.         ado_connection.connectionstring := sconnection;
  226.  
  227.         ado_connection.connected := true;
  228.  
  229.  
  230.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + '');
  231.  
  232.  
  233.         if statcds.fieldbyname('cc').asinteger = 0 then
  234.       begin
  235.         LastErr := '';
  236.         AddLog('Insert insure ' + tc.fieldbyname('hn').asstring);
  237.  
  238.         try
  239.           HOSxP_GetADODataset('insert into insure (hn,pop_id,card_id,pttype,hospmain,hospsub,datein,dateexp,notedate,note) values ("' +
  240.             tc['hn'] + '","' +
  241.             vartostr(tc['cid']) + '", "' +
  242.             tc.fieldbyname('pttypeno').asstring + '" ,"' +
  243.             tc.fieldbyname('pttype').asstring + '" ,"' +
  244.             tc.fieldbyname('hospmain').asstring + '" ,"' +
  245.             tc.fieldbyname('hospsub').asstring + '" ,"' +
  246.         //    vartostr(getsqldata('select concat(fname," ",lname,",",pname) as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '", ' +
  247.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  248.             formatdatetime('m', date) + ',' +
  249.             formatdatetime('d', date) + ') , '+
  250.  
  251.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  252.             formatdatetime('m', date) + ',' +
  253.             formatdatetime('d', date) + ') , '+
  254.  
  255.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  256.             formatdatetime('m', date) + ',' +
  257.             formatdatetime('d', date) + ')  ,'+
  258.  
  259.             ' "HOSxP" '+ // verifyby
  260.  
  261.             ' )');
  262.         except
  263.           on e: exception do
  264.           begin
  265.             LastErr := E.message;
  266.           end;
  267.         end;
  268.  
  269.         CheckErr;
  270.  
  271.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + '');
  272.         if statcds.fieldbyname('cc').asinteger = 0 then ErrMemo.lines.add('Stat insurlog Insert Fail !!!');
  273.  
  274.       end else
  275.       begin
  276.         LastErr := '';
  277.         AddLog('Edit insurlog ' + tc.fieldbyname('hn').asstring);
  278.         try
  279.           HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '" ,' +
  280.  
  281.             'pop_id = "' + vartostr(tc['cid']) + '" , ' +
  282.             'card_id = "' + vartostr(tc['pttypeno']) + '",  ' +
  283.             'hospmain = "' + vartostr(tc['hospmain']) + '",  ' +
  284.             'hospsub = "' + vartostr(tc['hospsub']) + '"  ,' +
  285.  
  286.      //       'datein = "' + vartostr(tc['pttype_begin']) + '"  ,' +
  287.      //       'dateexp = "' + vartostr(tc['pttype_expire']) + '"  ,' +
  288.  
  289.             'datein =  Date(' + formatdatetime('yyyy', tc['pttype_begin']) + ',' +
  290.             formatdatetime('m', tc['pttype_begin']) + ',' +
  291.             formatdatetime('d', tc['pttype_begin']) + ') , '+
  292.  
  293.             'dateexp =  Date(' + formatdatetime('yyyy', tc['pttype_expire']) + ',' +
  294.             formatdatetime('m', tc['pttype_expire']) + ',' +
  295.             formatdatetime('d', tc['pttype_expire']) + ') , '+
  296.  
  297.  
  298.  
  299.             'note = "' + vartostr(getsqldata('select concat(pname,fname," ",lname,",HOSXP") as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '" ' +
  300.  
  301.             ' where hn = ' + vartostr(tc['hn']) + ' ');
  302.         except
  303.           on e: exception do
  304.           begin
  305.             LastErr := E.message;
  306.           end;
  307.         end;
  308.  
  309.         CheckErr;
  310.  
  311.       end;
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.       end;
  319.  
  320.  
  321.      // if Pos('CommandText', LastErr) > 0 then
  322.      // begin
  323.  
  324.      /////////////////////////////////////////////////////////////////////////////////////////////////
  325.      ////////////////////  OYYMMDD
  326.           StatusMemo.Lines.add('===== New HI  TODAY =====');
  327.         sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\OPD\50\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  328.  
  329.         ado_connection.connected := false;
  330.  
  331.         ado_connection.connectionstring := sconnection;
  332.  
  333.         ado_connection.connected := true;
  334.  
  335.  
  336.         LastErr := '';
  337.         ErrMemo.Lines.add('===== New HI  O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+' =====');
  338.         AddLog('Insert hosxp  TODAY DDMMYY ' + tc.fieldbyname('hn').asstring);
  339.         try
  340.  
  341.           HOSxP_GetADODataset('insert into O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+'(hn,fname,lname,male,age,allergy,pttype,vsttime,dct,bw,tt,pr,rr,sbp,dbp,nrs,dtr,dtt,lab,xry,er,or,rec,phm,hpt,fudate,fus1,fus2,fus3,fus4,fus5,ldrug,DRXTIME)'+
  342.           'values (' + vartostr(tc['hn'])
  343. //          + ',"hosxp","hosxp","'
  344.          +',"' + vartostr(getsqldata('select fname  from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'"'
  345.          +',"' + vartostr(getsqldata('select lname  from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'","'
  346.           + vartostr(tc['sex']) + '","' + vartostr(tc['age_y']) + '","not","' + vartostr(tc['pttype']) + '",' + copy(vartostr(tc['vn']),7,4) + ',"01",1,2,3,4,5,6,1,0,0,0,0,0,0,0,0,0,{},"F1","F2","F3","F4","F5",.F.,10)');
  347.  
  348.  
  349.         except
  350.           on e: exception do
  351.           begin
  352.             LastErr := E.message;
  353.           end;
  354.         end;
  355.  
  356.         CheckErr;
  357.  
  358.  
  359.      /////////////////////////////////////////////////////////////////////////////////////////////////
  360.       QueueCDS.edit;
  361.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  362.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  363.  
  364.       QueueCDs.post;
  365.       QueueCDS.next;
  366.  
  367.       //end;
  368.     end;
  369.  
  370.  
  371.     if QueueCDs.ChangeCount > 0 then
  372.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
  373.  
  374.  
  375.  
  376.   until ((QueueCDS.RecordCount = 0) or FAbort);
  377.  
  378.   ado_connection.connected := false;
  379.  
  380.   tc.free;
  381.   queuecds.free;
  382.   statcds.free;
  383.  // StatusMemo.lines.add('Patient Export Done.');
  384.  
  385.   if StatusMemo.lines.count > 1000 then Statusmemo.lines.clear;
  386.  
  387. end;
  388.  
  389. procedure StartButtonClick(Sender: TObject);
  390. var Tk: LongInt;
  391. begin
  392.   StartButton.enabled := false;
  393.   AbortButton.enabled:=true;
  394.   FAbort := false;
  395.   while not FAbort do
  396.   begin
  397.     StatusLabel.caption:=formatdatetime('dd/mm/ee hh:nn:ss',now);
  398.     StartExport;
  399.     tk := GetTickCount;
  400.  
  401.     repeat
  402.       application.processmessages;
  403.     until ((GetTickCount - Tk) > 3000);
  404.   end;
  405.   startButton.enabled := true;
  406.  
  407. end;
  408.  
  409. procedure AbortButtonClick(Sender: TObject);
  410. begin
  411.  
  412.   FAbort := true;
  413.   AbortButton.enabled:=false;
  414.  
  415. end;
  416.  
  417.  
  418. procedure Main;
  419.  
  420.  
  421. begin
  422.  
  423.   MainForm := TForm.Create(nil);
  424.   MainForm.top := 200;
  425.   MainForm.left := 200;
  426.   MainForm.Width := 750;
  427.   MainForm.Height := 400;
  428.  
  429.   StartButton := TButton.Create(MainForm);
  430.   StartButton.parent := mainForm;
  431.   startButton.left := 30;
  432.   StartButton.top := 20;
  433.   StartButton.Width := 100;
  434.   StartButton.caption := 'Start';
  435.   StartButton.OnClick := StartButtonClick;
  436.  
  437.   AbortButton := TButton.Create(MainForm);
  438.   AbortButton.parent := mainForm;
  439.   AbortButton.left := 140;
  440.   AbortButton.top := 20;
  441.   AbortButton.Width := 100;
  442.   AbortButton.caption := 'Abort';
  443.   AbortButton.OnClick := AbortButtonClick;
  444.   AbortButton.enabled:=false;
  445.  
  446.   StatusMemo := TMemo.create(MainForm);
  447.   StatusMemo.parent := MainForm;
  448.   StatusMemo.left := 30;
  449.   Statusmemo.top := 50;
  450.   Statusmemo.width := 300;
  451.   StatusMemo.height := 300;
  452.  
  453.   ErrMemo := TMemo.create(MainForm);
  454.   ErrMemo.parent := MainForm;
  455.   ErrMemo.left:=350;
  456.   ErrMemo.top:=50;
  457.   ErrMemo.width := 300;
  458.   ErrMemo.Height := 300;
  459.  
  460.   StatusLabel := TLabel.create(Mainform);
  461.   STatusLabel.parent:=Mainform;
  462.   StatusLabel.left:=280;
  463.   StatusLabel.top := 20;
  464.   StatusLabel.caption:='Status';
  465.  
  466.   MainForm.Caption := 'HI 271 Exchange version 0.4 beta  hosxp  DEV---> &middot;&Ccedil;&Otilde; &middot;&Atilde;&Ntilde;&frac34;&Acirc;&igrave;&curren;&Aring;&Ntilde;&sect;  0868011680';
  467.  
  468.   MainForm.Showmodal;
  469.   MainForm.free;
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476. end;
  477.  
  478.  
  479. end.
  480.  
  481.  
  482.  
  483.  
  484. end.
  485.  
  486.  
  487.  

doramon

  • บุคคลทั่วไป
Re: HI 271 Exchange hosxp ส่งข้อมูลรายวันกลับด้วย
« ตอบกลับ #1 เมื่อ: มกราคม 07, 2007, 06:24:48 AM »
0
โค๊ด: Delphi
  1.  
  2. unit StatExchange;
  3. // version 0.1.1
  4. // 2006-09-05
  5. // Chaiyaporn Suratemekul
  6. //  2006-10-28
  7. // Tawee  Supklang  
  8.  
  9. var StatPath: string;
  10.  
  11.   MainForm: TForm;
  12.   StartButton: TButton;
  13.   AbortButton: TButton;
  14.   StatusMemo: TMemo;
  15.   FAbort: Boolean;
  16.   StatusLabel : TLabel;
  17.   ErrMemo:TMemo;
  18.  
  19.   LastErr: string;
  20.  
  21. implementation
  22.  
  23. Procedure AddLog(s:string);
  24. begin
  25.   StatusMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+'>'+s);
  26.  
  27. end;
  28.  
  29. Procedure CheckErr;
  30. begin
  31.  
  32.   if LastErr<>'' then
  33.   if Pos('CommandText', LastErr) = 0 then ErrMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+' '+LastErr);
  34.  
  35. end;
  36.  
  37.  
  38. procedure StartExport;
  39. var
  40.   sconnection: string; // variable for hold connection string
  41.   st: string; // variable for hold any string
  42.   tc,stoday, StatCDS: Tclientdataset;
  43.   QueueCDS: TClientDataset;
  44.  
  45. begin
  46.  
  47.   if StatPath = '' then
  48.   begin
  49.     StatPath := VarToStr(GetSQLData('select statroot from opdconfig'));
  50.     StatusMemo.Lines.Add('HI Path = ' + statPath);
  51.   end;
  52.  
  53.   if StatPath = '' then
  54.   begin
  55.     AddLog('Error : no information in opdconfig.statroot');
  56.     exit;
  57.   end;
  58.  
  59.  
  60.  
  61.  
  62.   sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  63.  
  64.   ado_connection.connected := false;
  65.  
  66.   ado_connection.connectionstring := sconnection;
  67.  
  68.   ado_connection.connected := true;
  69.  
  70.   tc := tclientdataset.create(nil);
  71.   statcds := tclientdataset.create(nil);
  72.  // tc.data:=HOSxP_GetADODataset('select count(*) as cc from patient1');
  73.  // StatusMemo.lines.add('Start Import Patient');
  74.  
  75.   QueueCDS := TClientDataset.create(nil);
  76.  
  77.  
  78.   repeat
  79.  
  80.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
  81.  
  82.     while not QueueCDS.eof do
  83.     begin
  84.       LastErr := '';
  85. //      AddLog('Edit patient1 ' +  vartostr(strtoint(queuecds.fieldbyname('id').asstring)));
  86.       tc.data := HOSxP_GetDataset('select * from patient where hn = "' + queuecds.fieldbyname('id').asstring+'"');
  87.  
  88. //      '+ tc.fieldbyname('hn').asinteger+'"'
  89.       statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn ='+vartostr(strtoint(tc.fieldbyname('hn').asstring)));
  90.       if statcds.fieldbyname('cc').asinteger = 0 then
  91.       begin
  92.         LastErr := '';
  93.         StatusMemo.Lines.Add('======= New PT ====== [' + tc.fieldbyname('hn').asstring+']');
  94.         AddLog('Insert patient 1 '+tc.fieldbyname('hn').asstring);
  95.         try
  96.           HOSxP_GetADODataset('insert into pt (hn,pop_id,pname,fname,lname,brthdate,truebrth,dthdate,MALE,CTZSHP,NTNLTY,RLGN ,OCCPTN, BLOODGRP,ALLERGY, ADDRPART,MOOPART,TMBPART,AMPPART,CHWPART, HOMETEL, PTTYPE,MRTLST,SPSNAME, MTHNAME,FTHNAME,OFFADDR,OFFTEL
  97.          ,INFMNAME, PRSNRLT,INFMADDR,INFMTEL,OPDLCT,fdate,ldate,cid_m,cid_f,hmain,hsub,card,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10 )
  98.           values ('+tc['hn']+',"'+vartostr(tc['cid'])+'","'+tc['pname']+'","'+tc['fname']+'","'+tc['lname']+'",'+
  99.  
  100.             ' Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
  101.             formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
  102.             formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , '+
  103.  
  104.  
  105.            '1,{2006/01/01},"'+vartostr(tc['sex'])+'","",
  106.           "","","403","O","not","'+vartostr(tc['addrpart'])
  107.            +'","'+vartostr(tc['moopart'])
  108.            +'","'+vartostr(tc['tmbpart'])
  109.            +'","'+vartostr(tc['amppart'])
  110.            +'","'+vartostr(tc['chwpart'])+'"
  111.             ,"","10","1","","","","","","","","","","",{},{},"","","","","000","","","","","","","","","","")');
  112.  //          +vartostr(tc['addrpart'])+'","+
  113.  //          +vartostr(tc['moopart'])+'","+
  114.  //          +vartostr(tc['tmbpart'])+'","+
  115.  //          +vartostr(tc['amppart'])+'","+
  116.  //          +vartostr(tc['chwpart'])+'"'+
  117.  
  118.  
  119.  
  120.           except
  121.           on e: exception do
  122.           begin
  123.             LastErr := E.message;
  124.           end;
  125.         end;
  126.  
  127.         CheckErr;
  128.  
  129.  
  130.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn =' +vartostr(strtoint(tc.fieldbyname('hn').asstring)));
  131. //        if statcds.fieldbyname('cc').asinteger = 0 then StatusMemo.lines.add('Stat Insert Fail !!!');
  132.  
  133.       end else
  134.       begin
  135.         LastErr := '';
  136.         AddLog('Edit PT ' + tc.fieldbyname('hn').asstring);
  137.         try
  138.           HOSxP_GetADODataset('update pt set MALE = "' + vartostr(tc['sex']) + '" , ' +
  139. //           'fname = "' + vartostr(tc['fname']) + ' ' + vartostr(tc['lname']) + ',' + vartostr(tc['pname']) + '" ,' +
  140.             'pname = "'+vartostr(tc['pname'])+'" , ' +
  141.             'fname = "'+vartostr(tc['fname'])+'" , ' +
  142.             'lname = "'+vartostr(tc['lname'])+'" , ' +
  143.            'brthdate = Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
  144.           formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
  145.           formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , ' +
  146.           'mthname = "' + vartostr(tc['mathername']) + '" , ' +
  147.           'fthname = "' + vartostr(tc['fathername']) + '" , ' +
  148.           'addrpart = "' + vartostr(tc['addrpart']) + '" , ' +
  149.           'moopart = "' + vartostr(tc['moopart']) + '" , ' +
  150.           'tmbpart = "' + vartostr(tc['tmbpart']) + '" , ' +
  151.           'amppart = "' + vartostr(tc['amppart']) + '" , ' +
  152.           'chwpart = "' + vartostr(tc['chwpart']) + '" , ' +
  153.           'pttype = "' + vartostr(tc['pttype']) + '"  ' +
  154.             ' where hn = ' + vartostr(tc['hn']) + '');
  155.         except
  156.           on e: exception do
  157.           begin
  158.             LastErr := E.message;
  159.           end;
  160.         end;
  161.  
  162.       end;
  163.  
  164.  
  165.       CheckErr;
  166.  
  167.       QueueCDS.edit;
  168.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  169.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  170.       QueueCDs.post;
  171.  
  172.       QueueCDS.next;
  173.     end;
  174.  
  175.     if QueueCDs.ChangeCount > 0 then
  176.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
  177.  
  178.   until ((QueueCDS.RecordCount = 0) or FAbort);
  179.  
  180.  
  181.   repeat
  182.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
  183.  
  184.     while not QueueCDS.Eof do
  185.     begin
  186.       LastErr := '';
  187.       sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  188.  
  189.       ado_connection.connected := false;
  190.  
  191.       ado_connection.connectionstring := sconnection;
  192.  
  193.       ado_connection.connected := true;
  194.  
  195.       tc.data := HOSxP_GetDataset('select * from vn_stat where vn = "' + QueueCDS.fieldbyname('id').asstring + '"');
  196.       if tc.recordcount > 0 then
  197.       begin
  198.         LastErr := '';
  199.         StatusMemo.Lines.add('===== New Visit =====');
  200.         AddLog('Edit insure pttype ' + tc.fieldbyname('hn').asstring);
  201.         try
  202.           HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '",  ' +
  203.            'card_id = "' + vartostr(tc['pttypeno']) + '",  ' +
  204.            'pttype = "' + vartostr(tc['pttype']) + '",  ' +
  205.            'hospmain = "' + vartostr(tc['hospmain']) + '",  ' +
  206.            'hospsub = "' + vartostr(tc['hospsub']) + '"  ' +
  207.             ' where hn = ' + vartostr(tc['hn']) + '');
  208.         except
  209.           on e: exception do
  210.           begin
  211.             LastErr := E.message;
  212.           end;
  213.         end;
  214.  
  215.         CheckErr;
  216.  
  217.  
  218.         //check insurelog
  219.         sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  220.  
  221.  
  222.  
  223.         ado_connection.connected := false;
  224.  
  225.         ado_connection.connectionstring := sconnection;
  226.  
  227.         ado_connection.connected := true;
  228.  
  229.  
  230.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + '');
  231.  
  232.  
  233.         if statcds.fieldbyname('cc').asinteger = 0 then
  234.       begin
  235.         LastErr := '';
  236.         AddLog('Insert insure 1' + tc.fieldbyname('hn').asstring);
  237.  
  238.         try
  239.           HOSxP_GetADODataset('insert into insure (hn,pop_id,card_id,pttype,hospmain,hospsub,datein,dateexp,notedate,note) values (' +
  240.             tc['hn'] + ',"' +
  241.             vartostr(tc['cid']) + '", "' +
  242.             tc.fieldbyname('pttypeno').asstring + '" ,"' +
  243.             tc.fieldbyname('pttype').asstring + '" ,"' +
  244.             tc.fieldbyname('hospmain').asstring + '" ,"' +
  245.             tc.fieldbyname('hospsub').asstring + '" ,' +
  246.         //    vartostr(getsqldata('select concat(fname," ",lname,",",pname) as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '", ' +
  247.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  248.             formatdatetime('m', date) + ',' +
  249.             formatdatetime('d', date) + ') , '+
  250.  
  251.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  252.             formatdatetime('m', date) + ',' +
  253.             formatdatetime('d', date) + ') , '+
  254.  
  255.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  256.             formatdatetime('m', date) + ',' +
  257.             formatdatetime('d', date) + ')  ,'+
  258.  
  259.             ' "HOSxP" '+ // verifyby
  260.  
  261.             ' )');
  262.         except
  263.           on e: exception do
  264.           begin
  265.             LastErr := E.message;
  266.           end;
  267.         end;
  268.  
  269.         CheckErr;
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + '');
  277.         if statcds.fieldbyname('cc').asinteger = 0 then ErrMemo.lines.add('Stat insurlog Insert Fail !!!');
  278.  
  279.       end else
  280.       begin
  281.         LastErr := '';
  282.         AddLog('Edit insurlog 1 ' + tc.fieldbyname('hn').asstring);
  283.         try
  284.           HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '" ,' +
  285.  
  286.             'pop_id = "' + vartostr(tc['cid']) + '" , ' +
  287.             'card_id = "' + vartostr(tc['pttypeno']) + '",  ' +
  288.             'hospmain = "' + vartostr(tc['hospmain']) + '",  ' +
  289.             'hospsub = "' + vartostr(tc['hospsub']) + '"  ,' +
  290.  
  291.      //       'datein = "' + vartostr(tc['pttype_begin']) + '"  ,' +
  292.      //       'dateexp = "' + vartostr(tc['pttype_expire']) + '"  ,' +
  293.  
  294.             'datein =  Date(' + formatdatetime('yyyy', tc['pttype_begin']) + ',' +
  295.             formatdatetime('m', tc['pttype_begin']) + ',' +
  296.             formatdatetime('d', tc['pttype_begin']) + ') , '+
  297.  
  298.             'dateexp =  Date(' + formatdatetime('yyyy', tc['pttype_expire']) + ',' +
  299.             formatdatetime('m', tc['pttype_expire']) + ',' +
  300.             formatdatetime('d', tc['pttype_expire']) + ') , '+
  301.  
  302.  
  303.  
  304.             'note = "' + vartostr(getsqldata('select concat(pname,fname," ",lname,",HOSXP") as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '" ' +
  305.  
  306.             ' where hn = ' + vartostr(tc['hn']) + ' ');
  307.         except
  308.           on e: exception do
  309.           begin
  310.             LastErr := E.message;
  311.           end;
  312.         end;
  313.  
  314.         CheckErr;
  315.  
  316.       end;
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.       end;
  324.  
  325.  
  326.      // if Pos('CommandText', LastErr) > 0 then
  327.      // begin
  328.  
  329.      /////////////////////////////////////////////////////////////////////////////////////////////////
  330.      ////////////////////  OYYMMDD
  331.  
  332.         StatusMemo.Lines.add('===== New HI  TODAY =====');
  333.  
  334.         sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\OPD\50\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  335.  
  336.         ado_connection.connected := false;
  337.  
  338.         ado_connection.connectionstring := sconnection;
  339.  
  340.         ado_connection.connected := true;
  341.  
  342.  
  343.         LastErr := '';
  344.         ErrMemo.Lines.add('===== New HI  &Ccedil;&Ntilde;&sup1;&middot;&Otilde;&egrave;  O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+' =====');
  345.         AddLog('Insert hosxp  TODAY HN: ' + tc.fieldbyname('hn').asstring);
  346.         try
  347.  
  348.           HOSxP_GetADODataset('insert into O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+'(hn,fname,lname,male,age,allergy,pttype,vsttime,dct,bw,tt,pr,rr,sbp,dbp,nrs,dtr,dtt,lab,xry,er,or,rec,phm,hpt,fudate,fus1,fus2,fus3,fus4,fus5,ldrug,DRXTIME)'+
  349.           'values (' + vartostr(tc['hn'])
  350. //          + ',"hosxp","hosxp","'
  351.          +',"' + vartostr(getsqldata('select fname  from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'"'
  352.          +',"' + vartostr(getsqldata('select concat(lname,"(H)")  from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'","'
  353.           + vartostr(tc['sex']) + '","' + vartostr(tc['age_y']) + '","","' + vartostr(tc['pttype']) + '",'
  354.            + copy(vartostr(tc['vn']),7,4) + ',"01",1,2,3,4,5,6,1,0,0,0,0,0,0,0,0,0,{},"F1","F2","F3","F4","F5",.F.,10)');
  355.  
  356.  
  357.         except
  358.           on e: exception do
  359.           begin
  360.             LastErr := E.message;
  361.           end;
  362.         end;
  363.  
  364.         CheckErr;
  365.  
  366.  
  367.      /////////////////////////////////////////////////////////////////////////////////////////////////
  368.       QueueCDS.edit;
  369.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  370.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  371.  
  372.       QueueCDs.post;
  373.       QueueCDS.next;
  374.  
  375.       //end;
  376.     end;
  377.  
  378.  
  379.     if QueueCDs.ChangeCount > 0 then
  380.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
  381.  
  382.  
  383.  
  384.   until ((QueueCDS.RecordCount = 0) or FAbort);
  385.  
  386.   ado_connection.connected := false;
  387.  
  388.   tc.free;
  389.   queuecds.free;
  390.   statcds.free;
  391.  // StatusMemo.lines.add('Patient Export Done.');
  392.  
  393.   if StatusMemo.lines.count > 1000 then Statusmemo.lines.clear;
  394.  
  395. end;
  396.  
  397. procedure StartButtonClick(Sender: TObject);
  398. var Tk: LongInt;
  399. begin
  400.   StartButton.enabled := false;
  401.   AbortButton.enabled:=true;
  402.   FAbort := false;
  403.   while not FAbort do
  404.   begin
  405.     StatusLabel.caption:=formatdatetime('dd/mm/ee hh:nn:ss',now);
  406.     StartExport;
  407.     tk := GetTickCount;
  408.  
  409.     repeat
  410.       application.processmessages;
  411.     until ((GetTickCount - Tk) > 3000);
  412.   end;
  413.   startButton.enabled := true;
  414.  
  415. end;
  416.  
  417. procedure AbortButtonClick(Sender: TObject);
  418. begin
  419.  
  420.   FAbort := true;
  421.   AbortButton.enabled:=false;
  422.  
  423. end;
  424.  
  425.  
  426. procedure Main;
  427.  
  428.  
  429. begin
  430.  
  431.   MainForm := TForm.Create(nil);
  432.   MainForm.top := 200;
  433.   MainForm.left := 200;
  434.   MainForm.Width := 750;
  435.   MainForm.Height := 400;
  436.  
  437.   StartButton := TButton.Create(MainForm);
  438.   StartButton.parent := mainForm;
  439.   startButton.left := 30;
  440.   StartButton.top := 20;
  441.   StartButton.Width := 100;
  442.   StartButton.caption := 'Start';
  443.   StartButton.OnClick := StartButtonClick;
  444.  
  445.   AbortButton := TButton.Create(MainForm);
  446.   AbortButton.parent := mainForm;
  447.   AbortButton.left := 140;
  448.   AbortButton.top := 20;
  449.   AbortButton.Width := 100;
  450.   AbortButton.caption := 'Abort';
  451.   AbortButton.OnClick := AbortButtonClick;
  452.   AbortButton.enabled:=false;
  453.  
  454.   StatusMemo := TMemo.create(MainForm);
  455.   StatusMemo.parent := MainForm;
  456.   StatusMemo.left := 30;
  457.   Statusmemo.top := 50;
  458.   Statusmemo.width := 300;
  459.   StatusMemo.height := 300;
  460.  
  461.   ErrMemo := TMemo.create(MainForm);
  462.   ErrMemo.parent := MainForm;
  463.   ErrMemo.left:=350;
  464.   ErrMemo.top:=50;
  465.   ErrMemo.width := 300;
  466.   ErrMemo.Height := 300;
  467.  
  468.   StatusLabel := TLabel.create(Mainform);
  469.   STatusLabel.parent:=Mainform;
  470.   StatusLabel.left:=280;
  471.   StatusLabel.top := 20;
  472.   StatusLabel.caption:='Status';
  473.  
  474.   MainForm.Caption := 'HI 271 Exchange version 0.4 beta  hosxp  DEV---> &middot;&Ccedil;&Otilde; &middot;&Atilde;&Ntilde;&frac34;&Acirc;&igrave;&curren;&Aring;&Ntilde;&sect;  0868011680';
  475.  
  476.   MainForm.Showmodal;
  477.   MainForm.free;
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484. end;
  485.  
  486.  
  487. end.
  488.  
  489.  
  490.  
  491.  
  492. end.
  493.  
  494.  
  495.  
  496.  

doramon

  • บุคคลทั่วไป
Re: HI 271 Exchange hosxp ส่งข้อมูลรายวันกลับด้วย
« ตอบกลับ #2 เมื่อ: มกราคม 09, 2007, 04:50:53 AM »
0
อันนี้เพิ่มการส่ง  admit  กลับไป HI ด้วย
เนื่องจากว่าผมมีโปรแกรม  dos ที่เขี่ยนเพิ่มผูกอยู่กับ HI อีกหลายตัว
ต้องใช้ไปจนกว่าจะมีโปรแกรมที่เขียนเชื่อมกับ HOSXP เสร็จ

 ;D ;D ;D

โค๊ด: Delphi
  1.  
  2. unit StatExchange;
  3. // version 0.1.1
  4. // 2006-09-05
  5. // Chaiyaporn Suratemekul
  6. //  2007-01-07
  7. // Tawee  Supklang  
  8.  
  9. var StatPath: string;
  10.  
  11.   MainForm: TForm;
  12.   StartButton: TButton;
  13.   AbortButton: TButton;
  14.   StatusMemo: TMemo;
  15.   FAbort: Boolean;
  16.   StatusLabel : TLabel;
  17.   ErrMemo:TMemo;
  18.  
  19.   LastErr: string;
  20.  
  21. implementation
  22.  
  23. Procedure AddLog(s:string);
  24. begin
  25.   StatusMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+'>'+s);
  26.  
  27. end;
  28.  
  29. Procedure CheckErr;
  30. begin
  31.  
  32.   if LastErr<>'' then
  33.   if Pos('CommandText', LastErr) = 0 then ErrMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+' '+LastErr);
  34.  
  35. end;
  36.  
  37.  
  38. procedure StartExport;
  39. var
  40.   sconnection: string; // variable for hold connection string
  41.   st: string; // variable for hold any string
  42.   tc,stoday, StatCDS: Tclientdataset;
  43.   QueueCDS: TClientDataset;
  44.  
  45. begin
  46.  
  47.   if StatPath = '' then
  48.   begin
  49.     StatPath := VarToStr(GetSQLData('select statroot from opdconfig'));
  50.     StatusMemo.Lines.Add('HI Path = ' + statPath);
  51.   end;
  52.  
  53.   if StatPath = '' then
  54.   begin
  55.     AddLog('Error : no information in opdconfig.statroot');
  56.     exit;
  57.   end;
  58.  
  59.  
  60.  
  61.  
  62.   sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  63.  
  64.   ado_connection.connected := false;
  65.  
  66.   ado_connection.connectionstring := sconnection;
  67.  
  68.   ado_connection.connected := true;
  69.  
  70.   tc := tclientdataset.create(nil);
  71.   statcds := tclientdataset.create(nil);
  72.  // tc.data:=HOSxP_GetADODataset('select count(*) as cc from patient1');
  73.  // StatusMemo.lines.add('Start Import Patient');
  74.  
  75.   QueueCDS := TClientDataset.create(nil);
  76.  
  77.   /////////////   PATIENT  ////////////////
  78.   repeat
  79.  
  80.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
  81.  
  82.     while not QueueCDS.eof do
  83.     begin
  84.       LastErr := '';
  85. //      AddLog('Edit patient1 ' +  vartostr(strtoint(queuecds.fieldbyname('id').asstring)));
  86.       tc.data := HOSxP_GetDataset('select * from patient where hn = "' + queuecds.fieldbyname('id').asstring+'"');
  87.  
  88. //      '+ tc.fieldbyname('hn').asinteger+'"'
  89.       statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn ='+vartostr(strtoint(tc.fieldbyname('hn').asstring)));
  90.       if statcds.fieldbyname('cc').asinteger = 0 then
  91.       begin
  92.         LastErr := '';
  93.         StatusMemo.Lines.Add('======= New PT ====== [' + tc.fieldbyname('hn').asstring+']');
  94.         AddLog('Insert patient 1 '+tc.fieldbyname('hn').asstring);
  95.         try
  96.           HOSxP_GetADODataset('insert into pt (hn,pop_id,pname,fname,lname,brthdate,truebrth,dthdate,MALE,CTZSHP,NTNLTY,RLGN ,OCCPTN, BLOODGRP,ALLERGY, ADDRPART,MOOPART,TMBPART,AMPPART,CHWPART, HOMETEL, PTTYPE,MRTLST,SPSNAME, MTHNAME,FTHNAME,OFFADDR,OFFTEL
  97.          ,INFMNAME, PRSNRLT,INFMADDR,INFMTEL,OPDLCT,fdate,ldate,cid_m,cid_f,hmain,hsub,card,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10 )
  98.           values ('+tc['hn']+',"'+vartostr(tc['cid'])+'","'+tc['pname']+'","'+tc['fname']+'","'+tc['lname']+'",'+
  99.  
  100.             ' Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
  101.             formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
  102.             formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , '+
  103.  
  104.  
  105.            '1,{2006/01/01},"'+vartostr(tc['sex'])+'","",
  106.           "","","403","O","not","'+vartostr(tc['addrpart'])
  107.            +'","'+vartostr(tc['moopart'])
  108.            +'","'+vartostr(tc['tmbpart'])
  109.            +'","'+vartostr(tc['amppart'])
  110.            +'","'+vartostr(tc['chwpart'])+'"
  111.             ,"","10","1","","","","","","","","","","",{},{},"","","","","000","","","","","","","","","","")');
  112.  //          +vartostr(tc['addrpart'])+'","+
  113.  //          +vartostr(tc['moopart'])+'","+
  114.  //          +vartostr(tc['tmbpart'])+'","+
  115.  //          +vartostr(tc['amppart'])+'","+
  116.  //          +vartostr(tc['chwpart'])+'"'+
  117.  
  118.  
  119.  
  120.           except
  121.           on e: exception do
  122.           begin
  123.             LastErr := E.message;
  124.           end;
  125.         end;
  126.  
  127.         CheckErr;
  128.  
  129.  
  130.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn =' +vartostr(strtoint(tc.fieldbyname('hn').asstring)));
  131. //        if statcds.fieldbyname('cc').asinteger = 0 then StatusMemo.lines.add('Stat Insert Fail !!!');
  132.  
  133.       end else
  134.       begin
  135.         LastErr := '';
  136.         AddLog('Edit PT ' + tc.fieldbyname('hn').asstring);
  137.         try
  138.           HOSxP_GetADODataset('update pt set MALE = "' + vartostr(tc['sex']) + '" , ' +
  139. //           'fname = "' + vartostr(tc['fname']) + ' ' + vartostr(tc['lname']) + ',' + vartostr(tc['pname']) + '" ,' +
  140.             'pname = "'+vartostr(tc['pname'])+'" , ' +
  141.             'fname = "'+vartostr(tc['fname'])+'" , ' +
  142.             'lname = "'+vartostr(tc['lname'])+'" , ' +
  143.            'brthdate = Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
  144.           formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
  145.           formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , ' +
  146.           'mthname = "' + vartostr(tc['mathername']) + '" , ' +
  147.           'fthname = "' + vartostr(tc['fathername']) + '" , ' +
  148.           'addrpart = "' + vartostr(tc['addrpart']) + '" , ' +
  149.           'moopart = "' + vartostr(tc['moopart']) + '" , ' +
  150.           'tmbpart = "' + vartostr(tc['tmbpart']) + '" , ' +
  151.           'amppart = "' + vartostr(tc['amppart']) + '" , ' +
  152.           'chwpart = "' + vartostr(tc['chwpart']) + '" , ' +
  153.           'pttype = "' + vartostr(tc['pttype']) + '", ' +
  154.           'pop_id = "' + vartostr(tc['cid']) + '"  ' +
  155.             ' where hn = ' + vartostr(tc['hn']) + '');
  156.         except
  157.           on e: exception do
  158.           begin
  159.             LastErr := E.message;
  160.           end;
  161.         end;
  162.  
  163.       end;
  164.  
  165.  
  166.       CheckErr;
  167.  
  168.       QueueCDS.edit;
  169.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  170.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  171.       QueueCDs.post;
  172.  
  173.       QueueCDS.next;
  174.     end;
  175.  
  176.     if QueueCDs.ChangeCount > 0 then
  177.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
  178.  
  179.   until ((QueueCDS.RecordCount = 0) or FAbort);
  180.  /////////////  END  PATIENT  ////////////////
  181.  
  182.   /////////////  ovst  ////////////////
  183.   repeat
  184.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
  185.  
  186.     while not QueueCDS.Eof do
  187.     begin
  188.       LastErr := '';
  189.       sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  190.  
  191.       ado_connection.connected := false;
  192.  
  193.       ado_connection.connectionstring := sconnection;
  194.  
  195.       ado_connection.connected := true;
  196.  
  197.       tc.data := HOSxP_GetDataset('select * from vn_stat where vn = "' + QueueCDS.fieldbyname('id').asstring + '"');
  198.       if tc.recordcount > 0 then
  199.       begin
  200.         LastErr := '';
  201.         StatusMemo.Lines.add('===== New Visit =====');
  202.         AddLog('Edit insure pttype ' + tc.fieldbyname('hn').asstring);
  203.         try
  204.           HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '",  ' +
  205.            'card_id = "' + vartostr(tc['pttypeno']) + '",  ' +
  206.            'pttype = "' + vartostr(tc['pttype']) + '",  ' +
  207.            'hospmain = "' + vartostr(tc['hospmain']) + '",  ' +
  208.            'hospsub = "' + vartostr(tc['hospsub']) + '"  ' +
  209.             ' where hn = ' + vartostr(tc['hn']) + '');
  210.         except
  211.           on e: exception do
  212.           begin
  213.             LastErr := E.message;
  214.           end;
  215.         end;
  216.  
  217.         CheckErr;
  218.  
  219.  
  220.         //check insurelog
  221.         sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\TBL\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  222.  
  223.  
  224.  
  225.         ado_connection.connected := false;
  226.  
  227.         ado_connection.connectionstring := sconnection;
  228.  
  229.         ado_connection.connected := true;
  230.  
  231.  
  232.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + 'and pttype="'+tc.fieldbyname('pttype').asstring+'"');
  233.  
  234.  
  235.         if statcds.fieldbyname('cc').asinteger = 0 then
  236.       begin
  237.         LastErr := '';
  238.         AddLog('Insert insure 1  &agrave;&frac34;&Ocirc;&egrave;&Aacute;&Ecirc;&Ocirc;&middot;&ETH;&Uacute;&igrave;' + tc.fieldbyname('hn').asstring);
  239.  
  240.         try
  241.           HOSxP_GetADODataset('insert into insure (hn,pop_id,card_id,pttype,hospmain,hospsub,datein,dateexp,notedate,note) values (' +
  242.             tc['hn'] + ',"' +
  243.             vartostr(tc['cid']) + '", "' +
  244.             tc.fieldbyname('pttypeno').asstring + '" ,"' +
  245.             tc.fieldbyname('pttype').asstring + '" ,"' +
  246.             tc.fieldbyname('hospmain').asstring + '" ,"' +
  247.             tc.fieldbyname('hospsub').asstring + '" ,' +
  248.         //    vartostr(getsqldata('select concat(fname," ",lname,",",pname) as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '", ' +
  249.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  250.             formatdatetime('m', date) + ',' +
  251.             formatdatetime('d', date) + ') , '+
  252.  
  253.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  254.             formatdatetime('m', date) + ',' +
  255.             formatdatetime('d', date) + ') , '+
  256.  
  257.             ' Date(' + formatdatetime('yyyy', date) + ',' +
  258.             formatdatetime('m', date) + ',' +
  259.             formatdatetime('d', date) + ')  ,'+
  260.  
  261.             ' "HOSxP add New" '+ // verifyby
  262.  
  263.             ' )');
  264.         except
  265.           on e: exception do
  266.           begin
  267.             LastErr := E.message;
  268.           end;
  269.         end;
  270.  
  271.         CheckErr;
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.         statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + '');
  279.         if statcds.fieldbyname('cc').asinteger = 0 then ErrMemo.lines.add('Stat insurlog Insert Fail !!!');
  280.  
  281.       end else
  282.       begin
  283.         LastErr := '';
  284.         AddLog('Edit insurlog 1 ' + tc.fieldbyname('hn').asstring);
  285.         try
  286.           HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '" ,' +
  287.  
  288.             'pop_id = "' + vartostr(tc['cid']) + '" , ' +
  289.             'card_id = "' + vartostr(tc['pttypeno']) + '",  ' +
  290.             'hospmain = "' + vartostr(tc['hospmain']) + '",  ' +
  291.             'hospsub = "' + vartostr(tc['hospsub']) + '"  ,' +
  292.  
  293.      //       'datein = "' + vartostr(tc['pttype_begin']) + '"  ,' +
  294.      //       'dateexp = "' + vartostr(tc['pttype_expire']) + '"  ,' +
  295.  
  296.             'datein =  Date(' + formatdatetime('yyyy', tc['pttype_begin']) + ',' +
  297.             formatdatetime('m', tc['pttype_begin']) + ',' +
  298.             formatdatetime('d', tc['pttype_begin']) + ') , '+
  299.  
  300.             'dateexp =  Date(' + formatdatetime('yyyy', tc['pttype_expire']) + ',' +
  301.             formatdatetime('m', tc['pttype_expire']) + ',' +
  302.             formatdatetime('d', tc['pttype_expire']) + ') , '+
  303.  
  304.  
  305.  
  306.             'note = "' + vartostr(getsqldata('select concat(pname,fname," ",lname,",HOSXP edit") as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '" ' +
  307.  
  308.             ' where hn = ' + vartostr(tc['hn']) + ' ');
  309.         except
  310.           on e: exception do
  311.           begin
  312.             LastErr := E.message;
  313.           end;
  314.         end;
  315.  
  316.         CheckErr;
  317.  
  318.       end;
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.       end;
  326.  
  327.  
  328.      // if Pos('CommandText', LastErr) > 0 then
  329.      // begin
  330.  
  331.      /////////////////////////////////////////////////////////////////////////////////////////////////
  332.      ////////////////////  OYYMMDD
  333.  
  334.         StatusMemo.Lines.add('===== New HI &aacute;&iexcl;&eacute;&auml;&cent;&eacute;&Ecirc;&Ocirc;&middot;&cedil;&igrave; TODAY =====');
  335.  
  336.         sconnection := 'Provider=VFPOLEDB.1;Data Source=' + StatPath + '\HI\OPD\50\;Mode=Share Deny None;Extended Properties="";User ID="";Password="";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=THAI;DSN=""';
  337.  
  338.         ado_connection.connected := false;
  339.  
  340.         ado_connection.connectionstring := sconnection;
  341.  
  342.         ado_connection.connected := true;
  343.  
  344.  
  345.         LastErr := '';
  346.       ErrMemo.Lines.add('===== New HI  &Ccedil;&Ntilde;&sup1;&middot;&Otilde;&egrave;  O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+' =====');
  347.         AddLog('Insert hosxp  TODAY HN: ' + tc.fieldbyname('hn').asstring);
  348.         try
  349.  
  350.           HOSxP_GetADODataset('insert into O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+'(hn,fname,lname,male,age,allergy,pttype,vsttime,dct,bw,tt,pr,rr,sbp,dbp,nrs,dtr,dtt,lab,xry,er,or,rec,phm,hpt,fudate,fus1,fus2,fus3,fus4,fus5,ldrug,DRXTIME)'+
  351.           'values (' + vartostr(tc['hn'])
  352. //          + ',"hosxp","hosxp","'
  353.          +',"' + vartostr(getsqldata('select fname  from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'"'
  354.          +',"' + vartostr(getsqldata('select concat(lname,"(H)")  from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'","'
  355.           + vartostr(tc['sex']) + '","' + vartostr(tc['age_y']) + '","","' + vartostr(tc['pttype']) + '",'
  356.            + copy(vartostr(tc['vn']),7,4) + ',"01",1,2,3,4,5,6,1,0,0,0,0,1,0,0,0,0,{},"F1","F2","F3","F4","F5",.F.,10)');
  357.  
  358.  
  359.         except
  360.           on e: exception do
  361.           begin
  362.             LastErr := E.message;
  363.           end;
  364.         end;
  365.  
  366.         CheckErr;
  367.  
  368.  
  369.      /////////////////////////////////////////////////////////////////////////////////////////////////
  370.       QueueCDS.edit;
  371.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  372.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  373.  
  374.       QueueCDs.post;
  375.       QueueCDS.next;
  376.  
  377.       //end;
  378.     end;
  379.  
  380.  
  381.     if QueueCDs.ChangeCount > 0 then
  382.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
  383.  
  384.  
  385.  
  386.   until ((QueueCDS.RecordCount = 0) or FAbort);
  387.  
  388.  
  389.   ///////////// END  ovst  ////////////////
  390.  
  391.   /////////////   ADMIN  ipd  ////////////////
  392.   repeat
  393.     QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "ADMIT" order by queue_date_time');
  394.  
  395.     while not QueueCDS.Eof do
  396.     begin
  397.     ErrMemo.Lines.add('IPD');
  398.  
  399.       QueueCDS.edit;
  400.       QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
  401.       if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
  402.  
  403.       QueueCDs.post;
  404.       QueueCDS.next;
  405.  
  406.  
  407.  
  408.       end;
  409.  
  410.       if QueueCDs.ChangeCount > 0 then
  411.       HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "ADMIT" order by queue_date_time');
  412.  
  413.  
  414.  
  415.  
  416.   until ((QueueCDS.RecordCount = 0) or FAbort);
  417.   ///////////// END  ADMIN ipd  ////////////////
  418.  
  419.   ado_connection.connected := false;
  420.  
  421.   tc.free;
  422.   queuecds.free;
  423.   statcds.free;
  424.  // StatusMemo.lines.add('HI Export Done.');
  425.  
  426.   if StatusMemo.lines.count > 1000 then Statusmemo.lines.clear;
  427.  
  428. end;
  429.  
  430. procedure StartButtonClick(Sender: TObject);
  431. var Tk: LongInt;
  432. begin
  433.   StartButton.enabled := false;
  434.   AbortButton.enabled:=true;
  435.   FAbort := false;
  436.   while not FAbort do
  437.   begin
  438.     StatusLabel.caption:=formatdatetime('dd/mm/ee hh:nn:ss',now);
  439.     StartExport;
  440.     tk := GetTickCount;
  441.  
  442.     repeat
  443.       application.processmessages;
  444.     until ((GetTickCount - Tk) > 3000);
  445.   end;
  446.   startButton.enabled := true;
  447.  
  448. end;
  449.  
  450. procedure AbortButtonClick(Sender: TObject);
  451. begin
  452.  
  453.   FAbort := true;
  454.   AbortButton.enabled:=false;
  455.  
  456. end;
  457.  
  458.  
  459. procedure Main;
  460.  
  461.  
  462. begin
  463.  
  464.   MainForm := TForm.Create(nil);
  465.   MainForm.top := 200;
  466.   MainForm.left := 200;
  467.   MainForm.Width := 750;
  468.   MainForm.Height := 600;
  469.  
  470.   StartButton := TButton.Create(MainForm);
  471.   StartButton.parent := mainForm;
  472.   startButton.left := 30;
  473.   StartButton.top := 20;
  474.   StartButton.Width := 100;
  475.   StartButton.caption := 'Start';
  476.   StartButton.OnClick := StartButtonClick;
  477.  
  478.   AbortButton := TButton.Create(MainForm);
  479.   AbortButton.parent := mainForm;
  480.   AbortButton.left := 140;
  481.   AbortButton.top := 20;
  482.   AbortButton.Width := 100;
  483.   AbortButton.caption := 'Abort';
  484.   AbortButton.OnClick := AbortButtonClick;
  485.   AbortButton.enabled:=false;
  486.  
  487.   StatusMemo := TMemo.create(MainForm);
  488.   StatusMemo.parent := MainForm;
  489.   StatusMemo.left := 30;
  490.   Statusmemo.top := 50;
  491.   Statusmemo.width := 300;
  492.   StatusMemo.height := 500;
  493.  
  494.   ErrMemo := TMemo.create(MainForm);
  495.   ErrMemo.parent := MainForm;
  496.   ErrMemo.left:=350;
  497.   ErrMemo.top:=50;
  498.   ErrMemo.width := 300;
  499.   ErrMemo.Height := 500;
  500.  
  501.   StatusLabel := TLabel.create(Mainform);
  502.   STatusLabel.parent:=Mainform;
  503.   StatusLabel.left:=280;
  504.   StatusLabel.top := 20;
  505.   StatusLabel.caption:='Status';
  506.  
  507.   MainForm.Caption := 'HI 271 Exchange version 0.4 beta  hosxp  DEV---> &middot;&Ccedil;&Otilde; &middot;&Atilde;&Ntilde;&frac34;&Acirc;&igrave;&curren;&Aring;&Ntilde;&sect;  0868011680';
  508.  
  509.   MainForm.Showmodal;
  510.   MainForm.free;
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517. end;
  518.  
  519.  
  520. end.
  521.  
  522.  
  523.  
  524.  
  525. end.
  526.  
  527.  
  528.