Changeset 542 for cprs/branches/GUI-config/BatchAddU.pas
- Timestamp:
- Aug 12, 2009, 7:34:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cprs/branches/GUI-config/BatchAddU.pas
r493 r542 29 29 uses 30 30 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 31 Dialogs, StdCtrls, Buttons, Grids, ExtCtrls, ComCtrls ;31 Dialogs, StdCtrls, Buttons, Grids, ExtCtrls, ComCtrls, DateUtils; 32 32 33 33 type … … 46 46 btnAbortRegistration: TBitBtn; 47 47 SaveDialog: TSaveDialog; 48 EstTimeLabel: TLabel; 48 49 procedure btnCreateTemplateClick(Sender: TObject); 49 50 procedure btnClearGridClick(Sender: TObject); … … 66 67 procedure ClearGrid; 67 68 procedure LoadData(fileName : string); 68 procedure AddHeaderCol(oneEntry : string); 69 procedure AddHeaderCol(oneEntry : string); 69 70 procedure GetColFieldNums(List : TStringList); 70 71 function GetOneRow(row : integer; ColFields : TStringList) : string; 72 function RowToStr(row : integer) : string; 73 procedure AddRowFromStr(Str : string); 71 74 function RegisterOne(oneRow : string; Log : TStringList) : string; 72 procedure DelGridRow(BatchGrid : TStringGrid; row : integer);75 //procedure DelGridRow(BatchGrid : TStringGrid; row : integer); 73 76 public 74 77 { Public declarations } … … 80 83 implementation 81 84 82 uses CreateTemplateU, StrUtils, ORNet, ORFn, Trpcb, FMErrorU; 85 uses CreateTemplateU, StrUtils, ORNet, ORFn, 86 Trpcb, //needed for .ptype types 87 FMErrorU; 83 88 84 89 const NOT_ADDED='(Not Added)'; … … 260 265 end; 261 266 262 267 263 268 procedure TBatchAddForm.btnDoRegistrationClick(Sender: TObject); 264 var row : integer; 269 var i,row : integer; 270 FailedPatients : TStringList; 265 271 ColFields : TStringList; 266 272 onePostEntry : string; 267 newIEN: string;273 RPCResult : string; 268 274 Log : TStringList; 269 Success,Failure,PreExisting : integer; 275 Success,Failure,PreExisting,Errors : integer; 276 StartTime : TDateTime; 277 278 procedure ShowEstTime(Pct : single); 279 var Delta : single; 280 EstTotalMin : Integer; 281 s : string; 282 begin 283 Delta := MinuteSpan(Now,StartTime); 284 if Pct=0 then begin 285 EstTimeLabel.caption := ''; 286 exit; 287 end; 288 EstTotalMin := Round(Delta / Pct); 289 s := ''; 290 if EstTotalMin > 1440 then begin //extract number of days 291 s := s + IntToStr(EstTotalMin div 1440) + 'd:'; 292 EstTotalMIn := EstTotalMin mod 1440; 293 end; 294 if EstTotalMin > 60 then begin //extract number of hours 295 if s <> '' then s := s + IntToStr(EstTotalMin div 60) + 'h:' 296 else s := IntToStr(EstTotalMin div 60) + ':'; 297 EstTotalMIn := EstTotalMin mod 60; 298 end; 299 s := s + IntToStr(EstTotalMin) + ':'; 300 EstTimeLabel.Caption := s; 301 end; 302 270 303 begin 271 304 btnOpenDataFile.Enabled := false; … … 274 307 btnClearGrid.Enabled := False; 275 308 btnSaveGrid.Enabled := False; 276 309 277 310 Log := TStringList.Create; 278 311 Success := 0; 279 312 Failure := 0; 280 313 PreExisting := 0; 314 Errors := 0; 281 315 FMErrorForm.Memo.Lines.clear; 282 316 ColFields := TStringList.Create; 317 FailedPatients := TStringList.Create; 283 318 GetColFieldNums(ColFields); 284 319 ProgressBar.Max := BatchGrid.RowCount-1; 285 320 FAbortRegistration := false; //abort button can change this. 321 StartTime := Now; 322 EstTimeLabel.Caption := ''; 286 323 for row := 2 to BatchGrid.RowCount-1 do begin 287 324 if FAbortRegistration = true then break; 288 325 ProgressBar.Position := row; 326 if (row mod 100) = 0 then ShowEstTime(row/(BatchGrid.RowCount-1)); 289 327 onePostEntry := GetOneRow(row,ColFields); 290 newIEN := RegisterOne(onePostEntry,Log); 291 BatchGrid.Cells[0,row] := newIEN; 292 if newIEN = NOT_ADDED then inc(Failure) 293 else if newIEN = ALREADY_ADDED then inc(PreExisting) 294 else inc(Success); 328 RPCResult := RegisterOne(onePostEntry,Log); //Returns: NewIEN^PrevReg^Reg'dNow^ErrorOccured 329 BatchGrid.Cells[0,row] := Piece(RPCResult,'^',1); 330 if Piece(RPCResult,'^',1)=NOT_ADDED then inc(Failure); 331 if Piece(RPCResult,'^',2)='1' then inc(PreExisting); 332 if Piece(RPCResult,'^',3)='1' then inc(Success); 333 if Piece(RPCResult,'^',4)='1' then inc(Errors); 295 334 Application.ProcessMessages; 296 335 end; 297 336 ProgressBar.Position := 0; 298 337 ColFields.free; 299 MessageDlg(IntToStr(Success)+' successful registrations, '+#10+#13+ 300 IntToStr(PreExisting)+' Patients were already registered,'+#10+#13+ 301 IntToStr(Failure)+' failures.', 338 MessageDlg(IntToStr(Success)+' successful registrations or data refresh, '+#10+#13+ 339 IntToStr(PreExisting)+' patients were already registered,'+#10+#13+ 340 IntToStr(Errors)+' filing errors encountered (including minor errors),'+#10+#13+ 341 IntToStr(Failure)+' patients NOT registered.', 302 342 mtInformation,[mbOK],0); 343 EstTimeLabel.Caption := ''; 344 StartTime := Now; 345 if BatchGrid.RowCount > 1000 then ShowMessage('Will now clear out patients that have been registered.'); 346 for row := 2 to BatchGrid.RowCount-1 do begin 347 if (BatchGrid.Cells[0,row] = NOT_ADDED) or (BatchGrid.Cells[0,row] = ADD_ROW) then begin 348 FailedPatients.Add(RowToStr(row)); 349 end; 350 ProgressBar.Position := row; 351 if (row mod 100) = 0 then ShowEstTime(row/(BatchGrid.RowCount-1)); 352 Application.ProcessMessages; 353 end; 354 BatchGrid.RowCount := 2; 355 ProgressBar.Max := FailedPatients.Count; 356 StartTime := Now; 357 for i := 0 to FailedPatients.Count-1 do begin 358 AddRowFromStr(FailedPatients.Strings[i]); 359 ProgressBar.Position := i; 360 if (i mod 100) = 0 then ShowEstTime(i/(FailedPatients.Count-1)); 361 Application.ProcessMessages; 362 end; 363 { 303 364 for row := BatchGrid.RowCount-1 downto 2 do begin 304 365 if (BatchGrid.Cells[0,row] <> NOT_ADDED) 305 366 and (BatchGrid.Cells[0,row] <> ADD_ROW) then begin 306 DelGridRow(BatchGrid,row); 307 end; 308 end; 367 DelGridRow(BatchGrid,row); // <------- this is VERY SLOW!!@#@! 368 end; 369 ProgressBar.Position := row; 370 if (row mod 100) = 0 then ShowEstTime((BatchGrid.RowCount-1-row)/(BatchGrid.RowCount-1)); 371 Application.ProcessMessages; 372 end; 373 } 374 EstTimeLabel.Caption := ''; 309 375 if Log.Count>0 then begin 310 376 FMErrorForm.Memo.Lines.Assign(Log); 311 377 FMErrorForm.PrepMessage; 312 378 FMErrorForm.ShowModal; 313 end; 379 end; 314 380 Log.Free; 315 381 if (BatchGrid.RowCount=3)and(BatchGrid.Cells[0,2]='') then begin … … 322 388 end else begin 323 389 btnClearGrid.Enabled := true; 324 btnSaveGrid.Enabled := true; 390 btnSaveGrid.Enabled := true; 325 391 btnAbortRegistration.Enabled := false; 326 392 end; 393 FailedPatients.Free; 394 327 395 end; 328 396 329 397 function TBatchAddForm.RegisterOne(oneRow : string; Log : TStringList) : string; 330 var RPCResult : string; 398 //Returns: NewIEN^Bool1^Bool2^Bool3 399 // NewIEN can be a #, or NOT_ADDED 400 // For each Bool, 0=false, 1=true 401 // Bool1 : Patient previously registered 402 // Bool2 : Patient registered this time (using identifier fields) 403 // Bool3 : Some Problem occurred during filing 404 var tempResult,RPCResult : string; 331 405 Msg : string; 332 406 i : integer; … … 336 410 RPCBrokerV.Param[0].Mult['"REQUEST"'] := 'REGISTER PATIENT^'+oneRow; 337 411 RPCBrokerV.Call; 338 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1 339 Msg := piece(RPCResult,'^',2); 340 result := piece(RPCResult,'^',3); 341 if result = '' then result := NOT_ADDED; 342 if piece(RPCResult,'^',1)='-1' then begin 343 if Msg='Patient already registered' then begin 344 result := ALREADY_ADDED; 345 exit; 346 end; 412 RPCResult := RPCBrokerV.Results[0]; 413 //returns: error: -1^Message; success=1^Success^IEN; or Equivical=0^Message^IEN 414 //If 0 then Message is in this format 415 // [Bool1;Bool2;Bool3;Bool4;Bool5*MessageText] 416 // For each Bool, 0=false, 1=true 417 // Bool1 : Patient previously registered 418 // Bool2 : Patient registered this time (using identifier fields) 419 // Bool3 : Problem filing non-identifier fields 420 // Bool4 : Problem filing data info sub-file fields 421 // Bool5 : Problem filing HRN 422 tempResult := piece(RPCResult,'^',1); 423 if tempResult='1' then begin //1=Success 424 result := piece(RPCResult,'^',3)+'^0^1^0'; 425 end else if tempResult='0' then begin //0=Mixed results 426 Msg := piece(RPCResult,'^',2); 427 result := piece(RPCResult,'^',3); 428 if result = '' then result := NOT_ADDED; 429 result := result + '^' + Piece(Msg,';',1) + '^' + Piece(Msg,';',2); 430 if Pos('1',Pieces(Msg,';',3,5))>0 then begin 431 result := result + '^1'; 432 if RPCBrokerV.Results.Count > 1 then begin 433 Log.Add('-----------------------------------------------'); 434 Log.Add('There was a problem with registering a patient.'); 435 for i := 1 to RPCBrokerV.Results.Count-1 do begin 436 Log.Add(RPCBrokerV.Results.Strings[i]); 437 end; 438 end; 439 end else begin 440 result := result + '^0'; 441 end; 442 end else begin //should be tempResult='-1' //-1=Error 347 443 FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results); 348 444 FMErrorForm.PrepMessage; //Does some clean up of the message format … … 350 446 Log.Add('-----------------------------------------------'); 351 447 Log.Add('There was a problem with registering a patient.'); 352 //Log.Add('This was the data sent to the server: ');353 //Log.Add(' '+oneRow);354 448 for i:= 0 to FMErrorForm.Memo.Lines.Count-1 do begin 355 449 Log.Add(FMErrorForm.Memo.Lines.Strings[i]); 356 end; 357 Log.Add(' '); 358 FMErrorForm.Memo.Lines.Clear; 359 if Msg='Success (but see message)' then exit;360 result := NOT_ADDED;361 end;362 end; 363 450 end; 451 Log.Add(' '); 452 FMErrorForm.Memo.Lines.Clear; 453 result := NOT_ADDED+'^0^0^1'; //Not-prev-reg^Not-reg-this-time^Problem-occured 454 end; 455 end; 456 457 { 364 458 procedure TBatchAddForm.DelGridRow(BatchGrid : TStringGrid; row : integer); 365 459 var col : integer; … … 374 468 end else begin 375 469 BatchGrid.RowCount := BatchGrid.RowCount-1; 376 end; 470 end; 377 471 exit; 378 472 end; … … 381 475 end; 382 476 inc(row); 383 until (1=0); 384 end; 477 until (1=0); 478 end; 479 } 385 480 386 481 procedure TBatchAddForm.FormDestroy(Sender: TObject); … … 395 490 List.Add(''); //fill 0'th column will null 396 491 for i := 1 to BatchGrid.ColCount-1 do begin 397 List.Add(BatchGrid.Cells[i,1]); 492 List.Add(BatchGrid.Cells[i,1]); 398 493 end; 399 494 end; … … 402 497 //Output format: FldNum1^Value1^fldNum2^Value2^FldNum3^Value3... 403 498 var i : integer; 404 oneValue : string; 405 begin 499 begin 406 500 result := ''; 407 501 if row >= BatchGrid.RowCount then exit; … … 410 504 end; 411 505 end; 506 507 function TBatchAddForm.RowToStr(row : integer) : string; 508 //Output format: Cell0^Cell1^Cell2^Cell3^Cell4.... 509 var i : integer; 510 begin 511 result := ''; 512 if row >= BatchGrid.RowCount then exit; 513 for i := 0 to BatchGrid.ColCount-1 do begin 514 result := result + BatchGrid.Cells[i,row]+'^'; 515 end; 516 end; 517 518 procedure TBatchAddForm.AddRowFromStr(Str : string); 519 var row : integer; 520 i : integer; 521 begin 522 BatchGrid.RowCount := BatchGrid.RowCount + 1; 523 row := BatchGrid.RowCount-1; 524 for i := 0 to BatchGrid.ColCount-1 do begin 525 BatchGrid.Cells[i,row] := Piece(Str,'^',i+1); 526 end; 527 end; 528 412 529 413 530 procedure TBatchAddForm.btnAbortRegistrationClick(Sender: TObject);
Note:
See TracChangeset
for help on using the changeset viewer.