unit StatExchange;
// version 0.1.1
// 2006-09-05
// Chaiyaporn Suratemekul
// 2007-01-07
// Tawee Supklang
var StatPath: string;
MainForm: TForm;
StartButton: TButton;
AbortButton: TButton;
StatusMemo: TMemo;
FAbort: Boolean;
StatusLabel : TLabel;
ErrMemo:TMemo;
LastErr: string;
implementation
Procedure AddLog(s:string);
begin
StatusMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+'>'+s);
end;
Procedure CheckErr;
begin
if LastErr<>'' then
if Pos('CommandText', LastErr) = 0 then ErrMemo.Lines.Add(formatdatetime('hh:nn:ss',now)+' '+LastErr);
end;
procedure StartExport;
var
sconnection: string; // variable for hold connection string
st: string; // variable for hold any string
tc,stoday, StatCDS: Tclientdataset;
QueueCDS: TClientDataset;
begin
if StatPath = '' then
begin
StatPath := VarToStr(GetSQLData('select statroot from opdconfig'));
StatusMemo.Lines.Add('HI Path = ' + statPath);
end;
if StatPath = '' then
begin
AddLog('Error : no information in opdconfig.statroot');
exit;
end;
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=""';
ado_connection.connected := false;
ado_connection.connectionstring := sconnection;
ado_connection.connected := true;
tc := tclientdataset.create(nil);
statcds := tclientdataset.create(nil);
// tc.data:=HOSxP_GetADODataset('select count(*) as cc from patient1');
// StatusMemo.lines.add('Start Import Patient');
QueueCDS := TClientDataset.create(nil);
///////////// PATIENT ////////////////
repeat
QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
while not QueueCDS.eof do
begin
LastErr := '';
// AddLog('Edit patient1 ' + vartostr(strtoint(queuecds.fieldbyname('id').asstring)));
tc.data := HOSxP_GetDataset('select * from patient where hn = "' + queuecds.fieldbyname('id').asstring+'"');
// '+ tc.fieldbyname('hn').asinteger+'"'
statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn ='+vartostr(strtoint(tc.fieldbyname('hn').asstring)));
if statcds.fieldbyname('cc').asinteger = 0 then
begin
LastErr := '';
StatusMemo.Lines.Add('======= New PT ====== [' + tc.fieldbyname('hn').asstring+']');
AddLog('Insert patient 1 '+tc.fieldbyname('hn').asstring);
try
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
,INFMNAME, PRSNRLT,INFMADDR,INFMTEL,OPDLCT,fdate,ldate,cid_m,cid_f,hmain,hsub,card,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10 )
values ('+tc['hn']+',"'+vartostr(tc['cid'])+'","'+tc['pname']+'","'+tc['fname']+'","'+tc['lname']+'",'+
' Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , '+
'1,{2006/01/01},"'+vartostr(tc['sex'])+'","",
"","","403","O","not","'+vartostr(tc['addrpart'])
+'","'+vartostr(tc['moopart'])
+'","'+vartostr(tc['tmbpart'])
+'","'+vartostr(tc['amppart'])
+'","'+vartostr(tc['chwpart'])+'"
,"","10","1","","","","","","","","","","",{},{},"","","","","000","","","","","","","","","","")');
// +vartostr(tc['addrpart'])+'","+
// +vartostr(tc['moopart'])+'","+
// +vartostr(tc['tmbpart'])+'","+
// +vartostr(tc['amppart'])+'","+
// +vartostr(tc['chwpart'])+'"'+
except
on e: exception do
begin
LastErr := E.message;
end;
end;
CheckErr;
statcds.data := HOSxP_GetADODataset('select count(*) as cc from pt where hn =' +vartostr(strtoint(tc.fieldbyname('hn').asstring)));
// if statcds.fieldbyname('cc').asinteger = 0 then StatusMemo.lines.add('Stat Insert Fail !!!');
end else
begin
LastErr := '';
AddLog('Edit PT ' + tc.fieldbyname('hn').asstring);
try
HOSxP_GetADODataset('update pt set MALE = "' + vartostr(tc['sex']) + '" , ' +
// 'fname = "' + vartostr(tc['fname']) + ' ' + vartostr(tc['lname']) + ',' + vartostr(tc['pname']) + '" ,' +
'pname = "'+vartostr(tc['pname'])+'" , ' +
'fname = "'+vartostr(tc['fname'])+'" , ' +
'lname = "'+vartostr(tc['lname'])+'" , ' +
'brthdate = Date(' + formatdatetime('yyyy', tc.fieldbyname('birthday').asdatetime) + ',' +
formatdatetime('m', tc.fieldbyname('birthday').asdatetime) + ',' +
formatdatetime('d', tc.fieldbyname('birthday').asdatetime) + ') , ' +
'mthname = "' + vartostr(tc['mathername']) + '" , ' +
'fthname = "' + vartostr(tc['fathername']) + '" , ' +
'addrpart = "' + vartostr(tc['addrpart']) + '" , ' +
'moopart = "' + vartostr(tc['moopart']) + '" , ' +
'tmbpart = "' + vartostr(tc['tmbpart']) + '" , ' +
'amppart = "' + vartostr(tc['amppart']) + '" , ' +
'chwpart = "' + vartostr(tc['chwpart']) + '" , ' +
'pttype = "' + vartostr(tc['pttype']) + '", ' +
'pop_id = "' + vartostr(tc['cid']) + '" ' +
' where hn = ' + vartostr(tc['hn']) + '');
except
on e: exception do
begin
LastErr := E.message;
end;
end;
end;
CheckErr;
QueueCDS.edit;
QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
QueueCDs.post;
QueueCDS.next;
end;
if QueueCDs.ChangeCount > 0 then
HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "OPDCARD" order by queue_date_time');
until ((QueueCDS.RecordCount = 0) or FAbort);
///////////// END PATIENT ////////////////
///////////// ovst ////////////////
repeat
QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
while not QueueCDS.Eof do
begin
LastErr := '';
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=""';
ado_connection.connected := false;
ado_connection.connectionstring := sconnection;
ado_connection.connected := true;
tc.data := HOSxP_GetDataset('select * from vn_stat where vn = "' + QueueCDS.fieldbyname('id').asstring + '"');
if tc.recordcount > 0 then
begin
LastErr := '';
StatusMemo.Lines.add('===== New Visit =====');
AddLog('Edit insure pttype ' + tc.fieldbyname('hn').asstring);
try
HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '", ' +
'card_id = "' + vartostr(tc['pttypeno']) + '", ' +
'pttype = "' + vartostr(tc['pttype']) + '", ' +
'hospmain = "' + vartostr(tc['hospmain']) + '", ' +
'hospsub = "' + vartostr(tc['hospsub']) + '" ' +
' where hn = ' + vartostr(tc['hn']) + '');
except
on e: exception do
begin
LastErr := E.message;
end;
end;
CheckErr;
//check insurelog
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=""';
ado_connection.connected := false;
ado_connection.connectionstring := sconnection;
ado_connection.connected := true;
statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + 'and pttype="'+tc.fieldbyname('pttype').asstring+'"');
if statcds.fieldbyname('cc').asinteger = 0 then
begin
LastErr := '';
AddLog('Insert insure 1 à¾ÔèÁÊÔ·ÐÚì' + tc.fieldbyname('hn').asstring);
try
HOSxP_GetADODataset('insert into insure (hn,pop_id,card_id,pttype,hospmain,hospsub,datein,dateexp,notedate,note) values (' +
tc['hn'] + ',"' +
vartostr(tc['cid']) + '", "' +
tc.fieldbyname('pttypeno').asstring + '" ,"' +
tc.fieldbyname('pttype').asstring + '" ,"' +
tc.fieldbyname('hospmain').asstring + '" ,"' +
tc.fieldbyname('hospsub').asstring + '" ,' +
// vartostr(getsqldata('select concat(fname," ",lname,",",pname) as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '", ' +
' Date(' + formatdatetime('yyyy', date) + ',' +
formatdatetime('m', date) + ',' +
formatdatetime('d', date) + ') , '+
' Date(' + formatdatetime('yyyy', date) + ',' +
formatdatetime('m', date) + ',' +
formatdatetime('d', date) + ') , '+
' Date(' + formatdatetime('yyyy', date) + ',' +
formatdatetime('m', date) + ',' +
formatdatetime('d', date) + ') ,'+
' "HOSxP add New" '+ // verifyby
' )');
except
on e: exception do
begin
LastErr := E.message;
end;
end;
CheckErr;
statcds.data := HOSxP_GetADODataset('select count(*) as cc from insure where hn = ' + tc.fieldbyname('hn').asstring + '');
if statcds.fieldbyname('cc').asinteger = 0 then ErrMemo.lines.add('Stat insurlog Insert Fail !!!');
end else
begin
LastErr := '';
AddLog('Edit insurlog 1 ' + tc.fieldbyname('hn').asstring);
try
HOSxP_GetADODataset('update insure set pttype = "' + vartostr(tc['pttype']) + '" ,' +
'pop_id = "' + vartostr(tc['cid']) + '" , ' +
'card_id = "' + vartostr(tc['pttypeno']) + '", ' +
'hospmain = "' + vartostr(tc['hospmain']) + '", ' +
'hospsub = "' + vartostr(tc['hospsub']) + '" ,' +
// 'datein = "' + vartostr(tc['pttype_begin']) + '" ,' +
// 'dateexp = "' + vartostr(tc['pttype_expire']) + '" ,' +
'datein = Date(' + formatdatetime('yyyy', tc['pttype_begin']) + ',' +
formatdatetime('m', tc['pttype_begin']) + ',' +
formatdatetime('d', tc['pttype_begin']) + ') , '+
'dateexp = Date(' + formatdatetime('yyyy', tc['pttype_expire']) + ',' +
formatdatetime('m', tc['pttype_expire']) + ',' +
formatdatetime('d', tc['pttype_expire']) + ') , '+
'note = "' + vartostr(getsqldata('select concat(pname,fname," ",lname,",HOSXP edit") as name from patient where hn="'+tc.fieldbyname('hn').asstring+'"')) + '" ' +
' where hn = ' + vartostr(tc['hn']) + ' ');
except
on e: exception do
begin
LastErr := E.message;
end;
end;
CheckErr;
end;
end;
// if Pos('CommandText', LastErr) > 0 then
// begin
/////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////// OYYMMDD
StatusMemo.Lines.add('===== New HI á¡éä¢éÊÔ·¸ì TODAY =====');
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=""';
ado_connection.connected := false;
ado_connection.connectionstring := sconnection;
ado_connection.connected := true;
LastErr := '';
ErrMemo.Lines.add('===== New HI Çѹ·Õè O'+formatdatetime('dd',now )+formatdatetime('mm',now)+formatdatetime('ee',now)+' =====');
AddLog('Insert hosxp TODAY HN: ' + tc.fieldbyname('hn').asstring);
try
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)'+
'values (' + vartostr(tc['hn'])
// + ',"hosxp","hosxp","'
+',"' + vartostr(getsqldata('select fname from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'"'
+',"' + vartostr(getsqldata('select concat(lname,"(H)") from patient where hn="'+tc.fieldbyname('hn').asstring+'"'))+'","'
+ vartostr(tc['sex']) + '","' + vartostr(tc['age_y']) + '","","' + vartostr(tc['pttype']) + '",'
+ 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)');
except
on e: exception do
begin
LastErr := E.message;
end;
end;
CheckErr;
/////////////////////////////////////////////////////////////////////////////////////////////////
QueueCDS.edit;
QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
QueueCDs.post;
QueueCDS.next;
//end;
end;
if QueueCDs.ChangeCount > 0 then
HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "VISIT" order by queue_date_time');
until ((QueueCDS.RecordCount = 0) or FAbort);
///////////// END ovst ////////////////
///////////// ADMIN ipd ////////////////
repeat
QueueCDS.data := HOSxP_GetDataset('select * from stat_queue where process_count = 0 and queue_type = "ADMIT" order by queue_date_time');
while not QueueCDS.Eof do
begin
ErrMemo.Lines.add('IPD');
QueueCDS.edit;
QueueCDS.fieldbyname('process_count').asinteger := QueueCDS.fieldbyname('process_count').asinteger + 1;
if Pos('CommandText', LastErr) > 0 then QueueCDS.fieldbyname('error').asinteger:= QueueCDS.fieldbyname('error').asinteger+1;
QueueCDs.post;
QueueCDS.next;
end;
if QueueCDs.ChangeCount > 0 then
HOSxP_updateDelta(Queuecds.Delta, 'select * from stat_queue where process_count = 0 and queue_type = "ADMIT" order by queue_date_time');
until ((QueueCDS.RecordCount = 0) or FAbort);
///////////// END ADMIN ipd ////////////////
ado_connection.connected := false;
tc.free;
queuecds.free;
statcds.free;
// StatusMemo.lines.add('HI Export Done.');
if StatusMemo.lines.count > 1000 then Statusmemo.lines.clear;
end;
procedure StartButtonClick(Sender: TObject);
var Tk: LongInt;
begin
StartButton.enabled := false;
AbortButton.enabled:=true;
FAbort := false;
while not FAbort do
begin
StatusLabel.caption:=formatdatetime('dd/mm/ee hh:nn:ss',now);
StartExport;
tk := GetTickCount;
repeat
application.processmessages;
until ((GetTickCount - Tk) > 3000);
end;
startButton.enabled := true;
end;
procedure AbortButtonClick(Sender: TObject);
begin
FAbort := true;
AbortButton.enabled:=false;
end;
procedure Main;
begin
MainForm := TForm.Create(nil);
MainForm.top := 200;
MainForm.left := 200;
MainForm.Width := 750;
MainForm.Height := 600;
StartButton := TButton.Create(MainForm);
StartButton.parent := mainForm;
startButton.left := 30;
StartButton.top := 20;
StartButton.Width := 100;
StartButton.caption := 'Start';
StartButton.OnClick := StartButtonClick;
AbortButton := TButton.Create(MainForm);
AbortButton.parent := mainForm;
AbortButton.left := 140;
AbortButton.top := 20;
AbortButton.Width := 100;
AbortButton.caption := 'Abort';
AbortButton.OnClick := AbortButtonClick;
AbortButton.enabled:=false;
StatusMemo := TMemo.create(MainForm);
StatusMemo.parent := MainForm;
StatusMemo.left := 30;
Statusmemo.top := 50;
Statusmemo.width := 300;
StatusMemo.height := 500;
ErrMemo := TMemo.create(MainForm);
ErrMemo.parent := MainForm;
ErrMemo.left:=350;
ErrMemo.top:=50;
ErrMemo.width := 300;
ErrMemo.Height := 500;
StatusLabel := TLabel.create(Mainform);
STatusLabel.parent:=Mainform;
StatusLabel.left:=280;
StatusLabel.top := 20;
StatusLabel.caption:='Status';
MainForm.Caption := 'HI 271 Exchange version 0.4 beta hosxp DEV---> ·ÇÕ ·ÃѾÂì¤Åѧ 0868011680';
MainForm.Showmodal;
MainForm.free;
end;
end.
end.