Ignore:
Timestamp:
Jul 7, 2010, 4:31:10 PM (14 years ago)
Author:
Kevin Toppenberg
Message:

Upgrade to version 27

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/trunk/CPRS-Chart/Orders/fODMedNVA.pas

    r456 r829  
    66  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    77  fODBase, StdCtrls, ComCtrls, ExtCtrls, ORCtrls, Grids, Buttons, uConst, ORDtTm,
    8   Menus, XUDIGSIGSC_TLB, rMisc, uOrders, StrUtils, oRFn;
     8  Menus, XUDIGSIGSC_TLB, rMisc, uOrders, StrUtils, oRFn, contnrs,
     9  VA508AccessibilityManager;
    910
    1011const
     
    9495  private
    9596    {selection}
    96     FAllItems:   TStringList;
    97     FAllFirst:   Integer;
    98     FAllLast:    Integer;
    99     FAllList:    Integer;
     97    FNVAMedCache:   TObjectList;
     98    FCacheIEN:   integer;
    10099    FQuickList:  Integer;
    101100    FQuickItems: TStringList;
     
    135134    FQOInitial: boolean;
    136135    FRemoveText : Boolean;
     136    FMedName: string;
    137137    {selection}
    138138    procedure ChangeDelayed;
     
    140140    function FindQuickOrder(const x: string): Integer;
    141141    function isUniqueQuickOrder(iText: string): Boolean;
     142    function GetCacheChunkIndex(idx: integer): integer;
    142143    procedure ScrollToVisible(AListView: TListView);
    143144    procedure StartKeyTimer;
     
    180181    procedure SetupDialog(OrderAction: Integer; const ID: string); override;
    181182    procedure CheckDecimal(var AStr: string);
     183    property MedName: string read FMedName write FMedName;
    182184  end;
    183185
     
    194196
    195197uses rCore, uCore, rODMeds, rODBase, rOrders, fRptBox, fODMedOIFA,
    196   uAccessibleStringGrid, fFrame, ORNet;
     198  fFrame, ORNet, VAUtils;
    197199
    198200const
     
    259261  TIMER_FROM_DAYS = 1;
    260262  TIMER_FROM_QTY  = 2;
     263
     264  MED_CACHE_CHUNK_SIZE = 100; 
    261265  {text constants}
    262266  TX_ADMIN      = 'Requested Start: ';
     
    346350  FRowHeight := MainFontHeight + 1;
    347351  x := 'NV RX';  // CLA 6/3/03
    348   ListForOrderable(FAllList, ListCount, x);
     352  ListForOrderable(FCacheIEN, ListCount, x);
    349353  lstAll.Items.Count := ListCount;
    350   FAllItems := TStringList.Create;
    351   FAllFirst := -1;
    352   FAllLast  := -1;
     354  FNVAMedCache := TObjectList.Create;
    353355  FQuickItems := TStringList.Create;
    354356  ListForQuickOrders(FQuickList, ListCount, x);
     
    370372    then Height := (((Height - 6) div VisibleRowCount) * ListCount) + 6;
    371373  pnlFields.Height := cmdAccept.Top - 4 - pnlFields.Top;
     374  cmdAccept.Left := cmdQuit.Left;
     375  cmdaccept.Anchors := cmdQuit.anchors;
    372376  FNoZero := False;
    373377  FShrinked := False;
     
    382386  {selection}
    383387  FQuickItems.Free;
    384   FAllItems.Free;
     388  FNVAMedCache.Free;
    385389  {edit}
    386390  FGuideline.Free;
     
    553557   end;
    554558  end;
     559  if Pos(U, self.memComment.Text) > 0 then SetError('Comments cannot contain a "^".');
    555560end;
    556561
     
    659664  UserText := Copy(txtMed.Text, 1, txtMed.SelStart);
    660665  QuickIndex := FindQuickOrder(UserText);
    661   AllIndex := IndexOfOrderable(FAllList, UserText);  // but always synch the full list
     666  AllIndex := IndexOfOrderable(FCacheIEN, UserText);  // but always synch the full list
    662667  if UserText <> Copy(txtMed.Text, 1, txtMed.SelStart) then Exit;  // if typing during lookup
    663668  if AllIndex > -1 then
     
    772777{ lstAll Methods (lstAll is TListView) }
    773778
     779// Cache is a list of 100 string lists, starting at idx 0
    774780procedure TfrmODMedNVA.LoadNonVAMedCache(First, Last: Integer);
    775 const
    776   MAX_CACHE_ITEMS = 1000;
    777 begin
    778   // if range is within cache range we don't need to update anything
    779   if (First >= FAllFirst) and (Last <= FAllLast) then Exit;
    780   // if range is outside of cache or a superset of cache, start over
    781   if (Last < Pred(FAllFirst)) or (First > Succ(FAllLast)) or
    782      ((First < FAllFirst) and (Last > FAllLast)) or
    783      (FAllItems.Count > MAX_CACHE_ITEMS) then
    784   begin
    785     FAllItems.Clear;
    786     FAllFirst := -1;
    787     FAllLast  := -1;
    788   end;
    789   // if getting items immediately before cache range
    790   if (First < FAllFirst) and (Last  >= FAllFirst) then Last  := Pred(FAllFirst);
    791   // if getting items immediately after cache range
    792   if (Last  > FAllLast)  and (First <= FAllLast)  then First := Succ(FAllLast);
    793   // retrieve the items and append (First>FAllLast) or prepend them to FAllItems
    794   SubsetOfOrderable(FAllItems, First>FAllLast, FAllList, First, Last);
    795   // reset FAllFirst & FAllLast indexes to reflect current FAllItems
    796   if FAllFirst < 0     then FAllFirst := First;
    797   if FAllLast  < 0     then FAllLast  := Last;
    798   if First < FAllFirst then FAllFirst := First;
    799   if Last > FAllLast   then FAllLast := Last;
     781var
     782  firstChunk, lastchunk, i: integer;
     783  list: TStringList;
     784  firstMed, LastMed: integer;
     785
     786begin
     787  firstChunk := GetCacheChunkIndex(First);
     788  lastChunk := GetCacheChunkIndex(Last);
     789  for i := firstChunk to lastChunk do
     790  begin
     791    if (FNVAMedCache.Count <= i) or (not assigned(FNVAMedCache[i])) then
     792    begin
     793      while FNVAMedCache.Count <= i do
     794        FNVAMedCache.add(nil);
     795      list := TStringList.Create;
     796      FNVAMedCache[i] := list;
     797      firstMed := i * MED_CACHE_CHUNK_SIZE;
     798      LastMed := firstMed + MED_CACHE_CHUNK_SIZE - 1;
     799      if LastMed >= lstAll.Items.Count then
     800        LastMed := lstAll.Items.Count - 1;
     801      SubsetOfOrderable(list, false, FCacheIEN, firstMed, lastMed);
     802    end;
     803  end;
    800804end;
    801805
     
    803807var
    804808  x: string;
    805 begin
    806   if (FAllFirst = -1) or (Item.Index < FAllFirst) or (Item.Index > FAllLast)
    807     then LoadNonVAMedCache(Item.Index, Item.Index);
    808   x := FAllItems[Item.Index - FAllFirst];
     809  chunk: integer;
     810  list: TStringList;
     811begin
     812  LoadNonVAMedCache(Item.Index, Item.Index);
     813  chunk := GetCacheChunkIndex(Item.Index);
     814  list := TStringList(FNVAMedCache[chunk]);
     815  x := list[Item.Index mod MED_CACHE_CHUNK_SIZE];
    809816  Item.Caption := Piece(x, U, 2);
    810817  Item.Data := Pointer(StrToIntDef(Piece(x, U, 1), 0));
     
    822829var
    823830  MedIEN: Integer;
    824   MedName: string;
     831  //MedName: string;
    825832  QOQuantityStr: string;
    826   ErrMsg: string;
     833  ErrMsg, temp: string;
    827834begin
    828835  inherited;
    829836  QOQuantityStr := '';
    830   btnSelect.SetFocus;                             // let the exit events finish
     837  btnSelect.SetFocus;
     838  self.MedName := '';                             // let the exit events finish
    831839  if pnlMeds.Visible then                         // display the medication fields
    832840  begin
     
    845853        //btnSelect.Visible := False;
    846854        btnSelect.Enabled := False;
    847         ShowMessage(ErrMsg);
     855        ShowMsg(ErrMsg);
    848856        Exit;
    849857      end;
     
    862870    begin
    863871      MedIEN := Integer(lstAll.Selected.Data);
    864       MedName := lstAll.Selected.Caption;
     872      self.MedName := lstAll.Selected.Caption;
    865873      txtMed.Tag := MedIEN;
    866874      ErrMsg := '';
     
    869877      begin
    870878        btnSelect.Enabled := False;
    871         ShowMessage(ErrMsg);
     879        ShowMsg(ErrMsg);
    872880        Exit;
    873881      end;
     
    882890      begin
    883891        txtMed.Tag := MedIEN;
    884         txtMed.Text := MedName;
     892        temp := self.MedName;
     893        self.MedName := txtMed.Text;
     894        txtMed.Text := Temp;
    885895      end;
    886896      SetOnMedSelect;
     
    918928var
    919929  i,j: Integer;
    920   x: string;
     930  temp,x: string;
    921931  QOPiUnChk: boolean;
    922932  PKIEnviron: boolean;
     
    933943    // set up lists & initial values based on orderable item
    934944    SetControl(txtMed,       'Medication');
     945    if (self.MedName <> '') then
     946       begin
     947         if (txtMed.Text <> self.MedName) then
     948           begin
     949             temp := self.MedName;
     950             self.MedName := txtMed.Text;
     951             txtMed.Text := temp;
     952           end
     953         else MedName := '';
     954       end;
    935955    SetControl(cboDosage,    'Dosage');
    936956    SetControl(cboRoute,     'Route');
     
    10441064      else
    10451065        SetDosage(IValueFor('INSTR', 1));
    1046         SetControl(cboDosage, 'DOSAGE', 1); // CQ: HDS00007776
    1047         SetSchedule(IValueFor('SCHEDULE',  1));
     1066      SetControl(cboDosage, 'DOSAGE', 1); // CQ: HDS00007776
     1067      SetControl(cboRoute,  'ROUTE',     1);  //AGP ADDED ROUTE FOR CQ 11252
     1068      SetSchedule(IValueFor('SCHEDULE',  1));
    10481069      if (cboSchedule.Text = '') and FIsQuickOrder then
    10491070      begin
     
    16131634  FUpdated := FALSE;
    16141635  Responses.Clear;
    1615   Responses.Update('ORDERABLE',  1, IntToStr(txtMed.Tag), txtMed.Text);
     1636  if self.MedName = '' then Responses.Update('ORDERABLE',  1, IntToStr(txtMed.Tag), txtMed.Text)
     1637  else Responses.Update('ORDERABLE',  1, IntToStr(txtMed.Tag), self.MedName);
    16161638  DoseList := TStringList.Create;
    16171639  case tabDose.TabIndex of
     
    17291751    Schedule  <TAB> (nothing)
    17301752    Duration  <TAB> Duration^Units }
     1753
     1754  // the following functions were created to get rid of a compile warning saying the
     1755  // return value may be undefined - too much branching logic in the case statements
     1756  // for the compiler to handle
     1757
     1758  function GetSchedule: string;
     1759  begin
     1760    Result := UpperCase(cboSchedule.Text);
     1761    if chkPRN.Checked then Result := Result + ' PRN';
     1762    if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN'
     1763      then Result := Copy(Result, 1, Length(Result) - 4);
     1764  end;
     1765
     1766  function GetScheduleEX: string;
     1767  begin
     1768    Result := '';
     1769    with cboSchedule do
     1770      if ItemIndex > -1 then Result := Piece(Items[ItemIndex], U, 2);
     1771    if (Length(Result) > 0) and chkPRN.Checked then Result := Result + ' AS NEEDED';
     1772    if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
     1773      then Result := Copy(Result, 1, Length(Result) - 10);
     1774  end;
     1775
    17311776begin
    17321777  Result := '';
     
    17631808                     if ItemIndex > -1  then Result := Piece(Items[ItemIndex], U, 4);
    17641809    FLD_SCHEDULE  : begin
    1765                       Result := UpperCase(cboSchedule.Text);
    1766                       if chkPRN.Checked then Result := Result + ' PRN';
    1767                       if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN'
    1768                         then Result := Copy(Result, 1, Length(Result) - 4);
     1810                      Result := GetSchedule;
    17691811                    end;
    17701812    FLD_SCHED_EX  : begin
    1771                       with cboSchedule do
    1772                         if ItemIndex > -1 then Result := Piece(Items[ItemIndex], U, 2);
    1773                       if (Length(Result) > 0) and chkPRN.Checked then Result := Result + ' AS NEEDED';
    1774                       if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
    1775                         then Result := Copy(Result, 1, Length(Result) - 10);
     1813                      Result := GetScheduleEX;
    17761814                    end;
    17771815    FLD_SCHED_TYP : with cboSchedule do
     
    21842222end;
    21852223
     2224function TfrmODMedNVA.GetCacheChunkIndex(idx: integer): integer;
     2225begin
     2226  Result := idx div MED_CACHE_CHUNK_SIZE;
     2227end;
     2228
    21862229procedure TfrmODMedNVA.lstQuickData(Sender: TObject; Item: TListItem);
    21872230var
     
    22092252            tmplst.Strings[i] := Piece(s,U,2);
    22102253        end;
    2211         Dest.Assign(tmplst);
     2254        FastAssign(tmplst, Dest);
    22122255    end;
    22132256 end;
Note: See TracChangeset for help on using the changeset viewer.