Ignore:
Timestamp:
Aug 12, 2009, 7:34:51 PM (15 years ago)
Author:
Kevin Toppenberg
Message:

v1.1 Fixes Access/Verify code issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/GUI-config/BatchAddU.pas

    r493 r542  
    2929uses
    3030  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    31   Dialogs, StdCtrls, Buttons, Grids, ExtCtrls, ComCtrls;
     31  Dialogs, StdCtrls, Buttons, Grids, ExtCtrls, ComCtrls, DateUtils;
    3232
    3333type
     
    4646    btnAbortRegistration: TBitBtn;
    4747    SaveDialog: TSaveDialog;
     48    EstTimeLabel: TLabel;
    4849    procedure btnCreateTemplateClick(Sender: TObject);
    4950    procedure btnClearGridClick(Sender: TObject);
     
    6667    procedure ClearGrid;
    6768    procedure LoadData(fileName : string);
    68     procedure AddHeaderCol(oneEntry : string); 
     69    procedure AddHeaderCol(oneEntry : string);
    6970    procedure GetColFieldNums(List : TStringList);
    7071    function GetOneRow(row : integer; ColFields : TStringList) : string;
     72    function RowToStr(row : integer) : string;
     73    procedure AddRowFromStr(Str : string);
    7174    function RegisterOne(oneRow : string; Log : TStringList) : string;
    72     procedure DelGridRow(BatchGrid : TStringGrid; row : integer);
     75    //procedure DelGridRow(BatchGrid : TStringGrid; row : integer);
    7376  public
    7477    { Public declarations }
     
    8083implementation
    8184
    82 uses CreateTemplateU, StrUtils, ORNet, ORFn, Trpcb, FMErrorU;
     85uses CreateTemplateU, StrUtils, ORNet, ORFn,
     86     Trpcb,  //needed for .ptype types
     87     FMErrorU;
    8388
    8489const NOT_ADDED='(Not Added)';
     
    260265  end;
    261266
    262  
     267
    263268  procedure TBatchAddForm.btnDoRegistrationClick(Sender: TObject);
    264   var row : integer;
     269  var i,row : integer;
     270      FailedPatients : TStringList;
    265271      ColFields : TStringList;
    266272      onePostEntry : string;
    267       newIEN : string;
     273      RPCResult : string;
    268274      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
    270303  begin
    271304    btnOpenDataFile.Enabled := false;
     
    274307    btnClearGrid.Enabled := False;
    275308    btnSaveGrid.Enabled := False;
    276    
     309
    277310    Log := TStringList.Create;
    278311    Success := 0;
    279312    Failure := 0;
    280313    PreExisting := 0;
     314    Errors := 0;
    281315    FMErrorForm.Memo.Lines.clear;
    282316    ColFields := TStringList.Create;
     317    FailedPatients := TStringList.Create;
    283318    GetColFieldNums(ColFields);
    284319    ProgressBar.Max := BatchGrid.RowCount-1;
    285320    FAbortRegistration := false;  //abort button can change this.
     321    StartTime := Now;
     322    EstTimeLabel.Caption := '';
    286323    for row := 2 to BatchGrid.RowCount-1 do begin
    287324      if FAbortRegistration = true then break;
    288325      ProgressBar.Position := row;
     326      if (row mod 100) = 0 then ShowEstTime(row/(BatchGrid.RowCount-1));
    289327      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);
    295334      Application.ProcessMessages;
    296335    end;
    297336    ProgressBar.Position := 0;
    298337    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.',
    302342               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    {
    303364    for row := BatchGrid.RowCount-1 downto 2 do begin
    304365      if (BatchGrid.Cells[0,row] <> NOT_ADDED)
    305366      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 := '';
    309375    if Log.Count>0 then begin
    310376      FMErrorForm.Memo.Lines.Assign(Log);
    311377      FMErrorForm.PrepMessage;
    312378      FMErrorForm.ShowModal;
    313     end; 
     379    end;
    314380    Log.Free;
    315381    if (BatchGrid.RowCount=3)and(BatchGrid.Cells[0,2]='') then begin
     
    322388    end else begin
    323389      btnClearGrid.Enabled := true;
    324       btnSaveGrid.Enabled := true; 
     390      btnSaveGrid.Enabled := true;
    325391      btnAbortRegistration.Enabled := false;
    326392    end;
     393    FailedPatients.Free;
     394
    327395  end;
    328396
    329397  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;
    331405      Msg : string;
    332406      i : integer;
     
    336410    RPCBrokerV.Param[0].Mult['"REQUEST"'] := 'REGISTER PATIENT^'+oneRow;
    337411    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
    347443      FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
    348444      FMErrorForm.PrepMessage;  //Does some clean up of the message format
     
    350446      Log.Add('-----------------------------------------------');
    351447      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);
    354448      for i:= 0 to FMErrorForm.Memo.Lines.Count-1 do begin
    355449        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  {
    364458  procedure TBatchAddForm.DelGridRow(BatchGrid : TStringGrid; row : integer);
    365459  var col : integer;
     
    374468        end else begin
    375469          BatchGrid.RowCount := BatchGrid.RowCount-1;
    376         end; 
     470        end;
    377471        exit;
    378472      end;
     
    381475      end;
    382476      inc(row);
    383     until (1=0);     
    384   end; 
     477    until (1=0);
     478  end;
     479  }
    385480 
    386481  procedure TBatchAddForm.FormDestroy(Sender: TObject);
     
    395490    List.Add(''); //fill 0'th column will null
    396491    for i := 1 to BatchGrid.ColCount-1 do begin
    397       List.Add(BatchGrid.Cells[i,1]);     
     492      List.Add(BatchGrid.Cells[i,1]);
    398493    end;
    399494  end;
     
    402497  //Output format: FldNum1^Value1^fldNum2^Value2^FldNum3^Value3...
    403498  var i : integer;
    404       oneValue : string;
    405   begin   
     499  begin
    406500    result := '';
    407501    if row >= BatchGrid.RowCount then exit;
     
    410504    end;
    411505  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
    412529
    413530  procedure TBatchAddForm.btnAbortRegistrationClick(Sender: TObject);
Note: See TracChangeset for help on using the changeset viewer.