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/fODMeds.pas

    r456 r829  
    88  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    99  fODBase, StdCtrls, ComCtrls, ExtCtrls, ORCtrls, Grids, Buttons, uConst, ORDtTm,
    10   Menus, XUDIGSIGSC_TLB;
     10  Menus, XUDIGSIGSC_TLB, VA508AccessibilityManager, VAUtils, Contnrs;
    1111
    1212const
     
    2626    cboXRoute: TORComboBox;
    2727    pnlXDuration: TPanel;
    28     pnlXSequence: TKeyClickPanel;
    29     btnXSequence: TSpeedButton;
    3028    timCheckChanges: TTimer;
    3129    popDuration: TPopupMenu;
     
    3432    hours1: TMenuItem;
    3533    minutes1: TMenuItem;
    36     popXSequence: TPopupMenu;
    37     and1: TMenuItem;
    38     then1: TMenuItem;
    3934    months1: TMenuItem;
    4035    weeks1: TMenuItem;
     
    7873    radPickClinic: TRadioButton;
    7974    cboPriority: TORComboBox;
    80     chkSC: TCheckBox;
    81     lblAdminTime: TStaticText;
    8275    stcPI: TStaticText;
    8376    chkPtInstruct: TCheckBox;
     
    8679    memDrugMsg: TMemo;
    8780    txtNSS: TLabel;
    88     SpeedButton1: TSpeedButton;
     81    pnlXAdminTime: TPanel;
     82    cboXSequence: TORComboBox;
     83    lblAdminSch: TMemo;
     84    lblAdminTime: TVA508StaticText;
    8985    procedure FormCreate(Sender: TObject);
    9086    procedure btnSelectClick(Sender: TObject);
     
    138134    procedure cboXRouteChange(Sender: TObject);
    139135    procedure cboXScheduleChange(Sender: TObject);
    140     procedure pnlXSequenceExit(Sender: TObject);
    141     procedure btnXSequenceClick(Sender: TObject);
    142136    procedure grdDosesExit(Sender: TObject);
    143137    procedure ListViewEnter(Sender: TObject);
    144138    procedure timCheckChangesTimer(Sender: TObject);
    145139    procedure popDurationClick(Sender: TObject);
    146     procedure popXSequenceClick(Sender: TObject);
    147     procedure chkSCEnter(Sender: TObject);
    148     procedure chkSCClick(Sender: TObject);
    149140    procedure cmdAcceptClick(Sender: TObject);
    150141    procedure btnXInsertClick(Sender: TObject);
     
    167158      Shift: TShiftState);
    168159    procedure cboXRouteEnter(Sender: TObject);
    169     procedure pnlXSequenceEnter(Sender: TObject);
    170160    procedure pnlMessageEnter(Sender: TObject);
    171161    procedure pnlMessageExit(Sender: TObject);
     
    174164    procedure memPIClick(Sender: TObject);
    175165    procedure FormResize(Sender: TObject);
    176     procedure spnQuantityChangingEx(Sender: TObject;
    177       var AllowChange: Boolean; NewValue: Smallint;
    178       Direction: TUpDownDirection);
    179166    procedure memPIKeyDown(Sender: TObject; var Key: Word;
    180167      Shift: TShiftState);
     
    196183    procedure WMClose(var Msg : TWMClose); message WM_CLOSE;
    197184    procedure cboXScheduleEnter(Sender: TObject);
     185    procedure pnlXAdminTimeClick(Sender: TObject);
     186    procedure cboXSequenceChange(Sender: TObject);
     187    procedure cboXSequence1Exit(Sender: TObject);
     188    procedure cboXSequenceExit(Sender: TObject);
     189    procedure cboXSequenceEnter(Sender: TObject);
     190    procedure txtRefillsChange(Sender: TObject);
    198191    //procedure btnNSSClick(Sender: TObject);
    199192  private
     193    FCloseCalled : Boolean;
    200194    FScheduleChanged : Boolean;
    201195    {selection}
    202     FAllItems:   TStringList;
    203     FAllFirst:   Integer;
    204     FAllLast:    Integer;
    205     FAllList:    Integer;
     196    FMedCache:   TObjectList;
     197    FCacheIEN:   Integer;
    206198    FQuickList:  Integer;
    207199    FQuickItems: TStringList;
     
    237229    FNoZERO: boolean;
    238230    FIsQuickOrder: boolean;
    239     FAdminTimeLbl: string;
    240231    FDisabledDefaultButton: TButton;
    241232    FDisabledCancelButton: TButton;
     
    250241    FRemoveText : Boolean;
    251242    FSmplPRNChkd: Boolean;
     243    {Admin Time}
     244    FAdminTimeLbl: string;
     245    FMedName: String;
     246    FNSSAdminTime: string;
     247    FNSSScheduleType: string;
     248    FAdminTimeText: string;
     249    //FOriginalAdminTime: string;
     250    //FOriginalScheduleIndex: integer;
     251    FOrderAction: integer;
     252    JAWSON: boolean;
    252253    procedure ChangeDelayed;
    253254    function FindQuickOrder(const x: string): Integer;
    254255    function isUniqueQuickOrder(iText: string): Boolean;
     256    function GetCacheChunkIndex(idx: integer): integer;
    255257    procedure LoadMedCache(First, Last: Integer);
    256258    procedure ScrollToVisible(AListView: TListView);
     
    284286    procedure UpdateRelated(DelayUpdate: Boolean = TRUE);
    285287    procedure UpdateRefills(const CurDispDrug: string; CurSupply: Integer);
    286     procedure UpdateSC(const CurDispDrug: string);
    287288    procedure UpdateStartExpires(const CurSchedule: string);
    288289    procedure UpdateDefaultSupply(const CurUnits, CurSchedule, CurDuration, CurDispDrug: string;
     
    313314    function IsSupplyAndOutPatient : boolean;
    314315    function GetSchedListIndex(SchedCombo: TORComboBox; pSchedule: String):integer;
     316    procedure DisplayDoseNow(Status: boolean);
     317    function lblAdminSchGetText: string;
     318    procedure lblAdminSchSetText(str: string);
    315319  protected
     320    procedure Loaded; override;
    316321    procedure InitDialog; override;
    317322    procedure Validate(var AnErrMsg: string); override;
     323    procedure updateSig; override;
    318324  public
    319325    ARow1: integer;
    320326    procedure SetupDialog(OrderAction: Integer; const ID: string); override;
    321327    procedure CheckDecimal(var AStr: string);
     328    property MedName: string read FMedName write FMedName;
     329    property NSSAdminTime: string read FNSSAdminTime write FNSSAdminTime;
     330    property NSSScheduleType: string read FNSSScheduleType write FNSSScheduleType;
    322331  end;
    323332
     
    331340
    332341uses rCore, uCore, ORFn, rODMeds, rODBase, rOrders, fRptBox, fODMedOIFA,
    333   uAccessibleStringGrid, uOrders, fOtherSchedule, StrUtils, fFrame;
     342  uOrders, fOtherSchedule, StrUtils, fFrame, VA508AccessibilityRouter;
    334343
    335344const
    336345  {grid columns for complex dosing}
    337   COL_SELECT   =  0;
    338   COL_DOSAGE   =  1;
    339   COL_ROUTE    =  2;
    340   COL_SCHEDULE =  3;
    341   COL_DURATION =  4;
    342   COL_SEQUENCE =  5;
    343   COL_CHKXPRN  =  6;
    344   VAL_DOSAGE   = 10;
    345   VAL_ROUTE    = 20;
    346   VAL_SCHEDULE = 30;
    347   VAL_DURATION = 40;
    348   VAL_SEQUENCE = 50;
    349   VAL_CHKXPRN  = 60;
    350   TAB          = #9;
     346  COL_SELECT    =  0;
     347  COL_DOSAGE    =  1;
     348  COL_ROUTE     =  2;
     349  COL_SCHEDULE  =  3;
     350  COL_DURATION  =  4;
     351  COL_ADMINTIME =  5;
     352  COL_SEQUENCE  =  6;
     353  COL_CHKXPRN   =  7;
     354  VAL_DOSAGE    = 10;
     355  VAL_ROUTE     = 20;
     356  VAL_SCHEDULE  = 30;
     357  VAL_DURATION  = 40;
     358  VAL_ADMINTIME = 50;
     359  VAL_SEQUENCE  = 60;
     360  VAL_CHKXPRN   = 70;
     361  TAB           = #9;
    351362  {field identifiers}
    352363  FLD_LOCALDOSE =  1;
     
    395406  TIMER_FROM_DAYS = 1;
    396407  TIMER_FROM_QTY  = 2;
     408
     409  MED_CACHE_CHUNK_SIZE = 100;
    397410  {text constants}
    398411  TX_ADMIN      = 'Requested Start: ';
     
    440453  AutoSizeDisabled := True;
    441454  inherited;
     455  FAdminTimeText := '';
    442456  btnXDuration.Align := alClient;
    443457  AllowQuickOrder := True;
     
    475489  //if (Self.EvtID > 0) then LoadSchedules(cboSchedule.Items)
    476490  //else LoadSchedules(cboSchedule.Items, FInptDlg);
    477   LoadSchedules(cboSchedule.Items, FInptDlg); 
     491  LoadSchedules(cboSchedule.Items, FInptDlg);
    478492  StatusText('');
    479493  if FInptDlg then SetControlsInpatient else SetControlsOutpatient;
     
    482496  FOrigiMsgDisp := FSuppressMsg;
    483497  InitDialog;
     498  isIMO := IfisIMODialog;
     499  if (isIMO) or ((FInptDlg) and (encounter.Location <> patient.Location)) then
     500      FAdminTimeText := 'Not defined for Clinic Locations';
    484501  if FInptDlg then
    485502  begin
     
    489506  end;
    490507  with grdDoses do
    491   begin
     508  begin                                         
    492509    ColWidths[0] := 8;  // select
    493510    ColWidths[1] := 160; // dosage
     
    495512    ColWidths[3] := 102;  // schedule
    496513    ColWidths[4] := 70;  // duration
    497     ColWidths[5] := 58;  // and/then
     514    if (FInptDlg) and (FAdminTimeText <> 'Not defined for Clinic Locations') then
     515      begin
     516        ColWidths[5] := 102;  // administration times
     517        ColWidths[6] := 58;  // and/then
     518      end
     519    else
     520        ColWidths[5] := 0;
     521        ColWidths[6] := 58;
    498522    Cells[1, 0]  := 'Dosage';
    499523    Cells[2, 0]  := 'Route';
    500524    Cells[3, 0]  := 'Schedule';
    501525    Cells[4, 0]  := 'Duration (optional)';
    502     Cells[5, 0]  := 'then/and';
    503   end;
    504   TAccessibleStringGrid.WrapControl(grdDoses);
     526    Cells[5, 0]  := 'Admin. Times';
     527    Cells[6, 0]  := 'then/and';
     528  end;
    505529
    506530  // medication selection
    507531  FRowHeight := MainFontHeight + 1;
    508532
    509   IsIMO := IfIsIMODialog; //IMO
     533  //IsIMO := IfIsIMODialog; //IMO
    510534  if (Self.EvtID > 0) then IsIMO := False; // event order can not be IMO order.
    511535  if FInptDlg then x := 'UD RX'
     
    517541    x := 'IVM RX';
    518542  end;
    519   ListForOrderable(FAllList, ListCount, x);
     543  if self.EvtID > 0  then FAdminTimeText := 'To Be Determined';
     544  ListForOrderable(FCacheIEN, ListCount, x);
    520545  lstAll.Items.Count := ListCount;
    521   FAllItems := TStringList.Create;
    522   FAllFirst := -1;
    523   FAllLast  := -1;
     546  FMedCache := TObjectList.Create;
    524547  FQuickItems := TStringList.Create;
    525548  ListForQuickOrders(FQuickList, ListCount, x);
     
    546569  FShowPnlXScheduleOk := True;
    547570  FRemoveText := True;
     571  JAWSON := True;
     572  if ScreenReaderActive = false then
     573    begin
     574      lblAdminTime.TabStop := false;
     575      lblAdminSch.TabStop := false;
     576      memOrder.TabStop := false;
     577      JAWSON := false;
     578    end;
    548579end;
    549580
     
    552583  {selection}
    553584  FQuickItems.Free;
    554   FAllItems.Free;
     585  FMedCache.Free;
    555586  {edit}
    556587  FGuideline.Free;
    557588  FAllDoses.Free;
    558589  FAllDrugs.Free;
    559   TAccessibleStringGrid.UnwrapControl(grdDoses);
    560590  frmFrame.pnlVisit.Enabled := true;
    561591  inherited;
     
    584614procedure TfrmODMeds.SetupDialog(OrderAction: Integer; const ID: string);
    585615var
    586   AnInstr, OrderID, nsSch, Text: string;
     616  AnInstr, OrderID, nsSch, Text, tempOrder, tempSchString, tempSchType, AdminTime: string;
    587617  ix: integer;
    588 begin
    589   inherited;
     618  LocChange: boolean;
     619  AResponse: TResponse;
     620
     621begin
     622  inherited;
     623  FOrderAction := OrderAction;
     624  if self.EvtID > 0 then DisplayDoseNow(false);
    590625  if XfInToOutNow then DisplayGroup := DisplayGroupByName('O RX');
    591   if CharAt(ID,1)='X' then
     626  if (CharAt(ID,1)='X') or (CharAt(ID,1)='C') then
    592627  begin
    593628    OrderID := Copy(Piece(ID, ';', 1), 2, Length(ID));
    594629    CheckExistingPI(OrderID, FPtInstruct);
    595630  end;
    596   if OrderAction = ORDER_QUICK then
     631  //AGP 27.72 Order Action behave similar to QO this is why Edit and Copy are setting FIsQuickOrder to true
     632  //this is not the best approach but this should fix the problem with order edit losing the quantity value.
     633  if (OrderAction = ORDER_QUICK) or (OrderAction = ORDER_EDIT) or (OrderAction = ORDER_COPY) then
    597634  begin
    598635    FIsQuickOrder := True;
     
    610647    Changing := True;
    611648    txtMed.Tag  := StrToIntDef(Responses.IValueFor('ORDERABLE', 1), 0);
     649    if (OrderAction = ORDER_QUICK) and (uOrders.PassDrugTstCall = False) and
     650     (uOrders.OutptDisp = OutptDisp) and (PassDrugTest(txtMed.Tag, 'Q', false) = False) then Exit;
     651    if (OrderAction = ORDER_QUICK) and (uOrders.PassDrugTstCall = False) and
     652     ((uOrders.ClinDisp = ClinDisp) or (uOrders.InptDisp = InptDisp)) and (PassDrugTest(txtMed.Tag, 'Q', true) = False) then Exit;
     653  (*  if (OrderAction = ORDER_QUICK) then
     654      begin
     655        tempAltIEN := GetQOAltOI;
     656        if tempAltIEN > 0 then txtMed.Tag := tempAltIEN;
     657      end; *)
    612658    SetOnMedSelect;                               // set up for this medication
    613659    SetOnQuickOrder;                              // insert quick order responses
     
    638684       end;
    639685    end;  //nss
     686    //if (FInptDlg) and (self.tabDose.TabIndex = TI_DOSE) and (OrderAction in [ORDER_COPY, ORDER_EDIT])  then
     687    if (FInptDlg) and (OrderAction in [ORDER_COPY, ORDER_EDIT])  then
     688      begin
     689        TempOrder := Piece(id,';',1);
     690        TempOrder := Copy(tempOrder, 2, Length(tempOrder));
     691        LocChange := DifferentOrderLocations(tempOrder, Patient.Location);
     692          if LocChange = false then
     693            begin
     694              AResponse := Responses.FindResponseByName('ADMIN', 1);
     695              if AResponse <> nil then AdminTime := AResponse.EValue;
     696              if self.cboSchedule.ItemIndex > -1 then
     697                begin
     698                  tempSchString := self.cboSchedule.Items.Strings[cboSchedule.itemindex];
     699                  SetPiece(tempSchString,U,4,AdminTime);
     700                  self.cboSchedule.Items.strings[cboSchedule.ItemIndex] := tempSchString;
     701                end;
     702              if self.tabDose.TabIndex = TI_COMPLEX then
     703                begin
     704                  if self.cboXSchedule.ItemIndex > -1 then
     705                    begin
     706                      tempSchString := self.cboXSchedule.Items.Strings[cboXSchedule.itemindex];
     707                      SetPiece(tempSchString,U,4,AdminTime);
     708                      self.cboXSchedule.Items.strings[cboXSchedule.ItemIndex] := tempSchString;
     709                    end;
     710                end;
     711              AResponse := Responses.FindResponseByName('SCHTYPE', 1);
     712              if AResponse <> nil then tempSchType := AResponse.EValue;
     713              if self.cboSchedule.ItemIndex > -1 then
     714                begin
     715                  if (Piece(self.cboSchedule.Items.Strings[self.cboSchedule.itemIndex], U, 3) = 'C') and (tempSchType = 'P') then
     716                     self.chkPRN.Checked := True
     717                  else
     718                     begin
     719                       tempSchString := self.cboSchedule.Items.Strings[cboSchedule.itemindex];
     720                       SetPiece(tempSchString,U,3,tempSchType);
     721                       self.cboSchedule.Items.strings[cboSchedule.ItemIndex] := tempSchString;
     722                     end;
     723                  end;
     724               if self.tabDose.TabIndex = TI_COMPLEX then
     725                begin
     726                  if self.cboXSchedule.ItemIndex > -1 then
     727                    begin
     728                      if  (Piece(self.cboXSchedule.Items.Strings[self.cboXSchedule.itemIndex], U, 3) = 'C') and (tempSchType = 'P') then
     729                          self.chkXPRN.Checked := True
     730                      else
     731                        begin
     732                          tempSchString := self.cboXSchedule.Items.Strings[cboXSchedule.itemindex];
     733                          SetPiece(tempSchString,U,3,tempSchType);
     734                          self.cboXSchedule.Items.strings[cboXSchedule.ItemIndex] := tempSchString;
     735                        end;
     736                    end;
     737                end;
     738            end;
     739        if (FAdminTimeText <> 'Not defined for Clinic Locations') and (self.tabDose.TabIndex = TI_COMPLEX) then
     740            lblAdminSchSetText('');
     741        if (FAdminTimeText <> '') and (self.tabDose.TabIndex = TI_DOSE) then lblAdminSchSetText('Admin. Time: ' + FAdminTimeText);
     742      end;
    640743    if ((OrderAction <> Order_COPY) and (OrderAction <> Order_EDIT)) or
    641     (XfInToOutNow = true) then UpdateRelated(FALSE); //AGP Change
     744    (XfInToOutNow = true) or (FIsQuickOrder) then UpdateRelated(FALSE); //AGP Change
    642745    Changing := False;
     746    if ((OrderAction = Order_Copy) or (OrderAction = Order_Edit)) and
     747        (self.cboSchedule.ItemIndex > -1) then
     748          UpdateStartExpires(Piece(self.cboSchedule.items.strings[self.cboSchedule.itemindex], U, 1));
    643749  end;
    644750  { prevent the SIG from being part of the comments on pre-CPRS prescriptions }
     
    663769procedure TfrmODMeds.Validate(var AnErrMsg: string);
    664770var
    665   i,ie,code: Integer;
     771  i,ie,code, curSupply, tempRefills: Integer;
     772  curDispDrug, tmpError, temp, x: string;
    666773
    667774  procedure SetError(const x: string);
     
    736843  if txtMed.Tag = 0 then SetError(TX_NO_MED);
    737844  if Responses.InstanceCount('INSTR') < 1 then SetError(TX_NO_DOSE);
     845  if Pos(U, self.memComment.Text) > 0 then SetError('Comments cannot contain a "^".');
    738846  i := Responses.NextInstance('INSTR', 0);
    739847  while i > 0 do
     
    757865    i := Responses.NextInstance('INSTR', i);
    758866  end;
     867  if self.tabDose.TabIndex = TI_DOSE then
     868     begin
     869         if (LeftStr(cboDosage.Text,1)='.') then
     870       begin
     871         SetError('Dosage must have a leading numeric value');
     872         Exit;
     873       end;
     874     end;
    759875  //AGP Change 26.45 Fix for then/and conjucntion PSI-04-069
    760   if self.tabDose.TabIndex = 1 then
    761     begin
    762        for i := 2 to self.grdDoses.RowCount do
     876  if self.tabDose.TabIndex = TI_COMPLEX then
     877    begin
     878       for i := 1 to self.grdDoses.RowCount do
    763879         begin
    764            if ((ValFor(COL_DOSAGE, i-1) <> '') and (ValFor(COL_DOSAGE, i) <> '')) and (ValFor(COL_SEQUENCE,i-1) = '') then
     880           temp := ValFor(COL_DOSAGE, i);
     881           if (LeftStr(temp,1) = '.') then
    765882             begin
    766               SetError(TX_NO_SEQ);
    767               Exit;
     883                SetError('All dosage must have a leading numeric value');
     884                Exit;
    768885             end;
     886           if (i > 1) and ((ValFor(COL_DOSAGE, i-1) <> '') and (ValFor(COL_DOSAGE, i) <> '')) and (ValFor(COL_SEQUENCE,i-1) = '') then
     887              begin
     888                SetError(TX_NO_SEQ);
     889                Exit;
     890              end;
    769891         end;
    770892    end;
     
    772894  begin
    773895    if Responses.IValueFor('PICKUP', 1) = '' then SetError(TX_NO_PICK);
    774     if StrToIntDef(Responses.IValueFor('REFILLS', 1), 99) > spnRefills.Max
     896    temp := Responses.IValueFor('REFILLS', 1);
     897    for i := 1 to Length(temp) do if not (temp[i] in ['0'..'9']) then
     898      begin
     899        SetError('Refills can only be a number');
     900        Exit;
     901      end;
     902    tempRefills := StrToIntDef(temp, 0);
     903    if (spnRefills.Max > 0) and (tempRefills > 0) then
     904      begin
     905        i := Responses.NextInstance('DOSE', 0);
     906        while i > 0 do
     907        begin
     908          x := ValueOfResponse(FLD_DRUG_ID,   i);
     909          CurDispDrug := CurDispDrug + x + U;
     910          i := Responses.NextInstance('DOSE', i);
     911        end;
     912        CurSupply   := StrToIntDef(ValueOfResponse(FLD_SUPPLY)   ,0);
     913        UpdateRefills(CurDispDrug, CurSupply);
     914      end;
     915    if tempRefills > spnRefills.Max
    775916      then SetError(TX_RNG_REFILL + IntToStr(spnRefills.Max));
    776917    with txtQuantity do
    777       if not ValidQuantity(Responses.IValueFor('QTY', 1)) then SetError(TX_QTY_NV);
     918      begin
     919        if not ValidQuantity(Responses.IValueFor('QTY', 1)) then
     920          SetError(TX_QTY_NV);
     921      (*  else
     922          begin
     923            Quantity := ValidateQuantityErrorMsg(StrtoIntDef(Responses.IValueFor('QTY', 1), 0));
     924            if Quantity <> '' then SetError(Quantity);
     925          end; *)
     926      end;
    778927    with txtSupply do
    779928    begin
     
    787936      if (StrToIntDef(Responses.IValueFor('SUPPLY', 1), 0) > 90) then SetError(TX_SUPPLY_LIM);
    788937      if (StrToIntDef(Responses.IValueFor('SUPPLY', 1), 0) < 1)  then SetError(TX_SUPPLY_LIM1);
    789     end;
     938      //Supply := ValidateDaySupplyandQuantityErrorMsg(strtoInt(Responses.IValueFor('SUPPLY',1)));
     939      //if Supply <> '' then  SetError(Supply);
     940    end;
     941    tmpError :=  ValidateDaySupplyandQuantityErrorMsg(strtoInt(Responses.IValueFor('SUPPLY',1)),StrtoIntDef(Responses.IValueFor('QTY', 1), 0));
     942    if tmpError <> '' then SetError(tmpError)
     943    else ClearMaxData;
    790944  end;
    791945end;
     
    815969  lblPriority.Visible := True;
    816970  cboPriority.Visible := True;
    817   chkSC.Visible := False;
    818971  chkDoseNow.Visible := True;
    819972  lblAdminTime.Visible := True;
     973  lblAdminSch.Visible := True;
     974  lblAdminSch.Hint := AdminTimeHelpText;
     975  if cboXSequence.Items.IndexOf('except') > -1 then cboXSequence.Items.Delete(cboXSequence.Items.IndexOf('except'));
    820976end;
    821977
    822978procedure TfrmODMeds.SetControlsOutpatient;
    823 var
    824   ExceptItem: TMenuItem;
    825979begin
    826980  FillerID := 'PSO';
     
    833987  lblQuantity.Visible := True;
    834988  txtQuantity.Visible := True;
     989  //if IsClozapineOrder = True then txtQuantity.Enabled := false;
    835990  spnQuantity.Visible := True;
    836991  lblQtyMsg.Visible := True;
     
    841996  lblPriority.Visible := True;
    842997  cboPriority.Visible := True;
    843   chkSC.Visible := True;
    844998  chkDoseNow.Visible := False;
    845999  lblAdminTime.Visible := False;
    846   ExceptItem := TMenuItem.Create(Self);
    847   ExceptItem.Caption := 'except';
    848   ExceptItem.Tag := 3;
    849   ExceptItem.OnClick := popXSequenceClick;
    850   popXSequence.Items.Add(ExceptItem);
     1000  lblAdminSch.Visible := False;
     1001  if cboXSequence.Items.IndexOf('except') = -1 then cboXSequence.Items.Add('except');
     1002 
    8511003end;
    8521004
     
    9061058  x: string;
    9071059begin
    908   if Key in [VK_PRIOR, VK_NEXT, VK_UP, VK_DOWN] then             // navigation
     1060  if txtMed.ReadOnly then    // v27.50 - RV - CQ #15365
     1061  begin
     1062    if not (Key in [VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_HOME, VK_END]) then           // navigation
     1063    begin
     1064      Key := 0;
     1065      Exit;
     1066    end;
     1067  end
     1068  else if (Key in [VK_PRIOR, VK_NEXT, VK_UP, VK_DOWN]) then             // navigation
    9091069  begin
    9101070    FActiveMedList.Perform(WM_KEYDOWN, Key, 0);
     
    9311091  Shift: TShiftState);
    9321092begin
    933   if not (Key in [VK_PRIOR, VK_NEXT, VK_UP, VK_DOWN]) then StartKeyTimer;
    934 end;
     1093  if txtMed.ReadOnly then exit;    // v27.50 - RV - CQ #15365
     1094  if not (Key in [VK_PRIOR, VK_NEXT, VK_LEFT, VK_RIGHT, VK_UP, VK_DOWN, VK_HOME, VK_END]) then StartKeyTimer;
     1095end;
     1096
    9351097
    9361098procedure TfrmODMeds.txtMedChange(Sender: TObject);
     
    9681130  UserText := Copy(txtMed.Text, 1, txtMed.SelStart);
    9691131  QuickIndex := FindQuickOrder(UserText);            // look in quick list first
    970   AllIndex := IndexOfOrderable(FAllList, UserText);  // but always synch the full list
     1132  AllIndex := IndexOfOrderable(FCacheIEN, UserText);  // but always synch the full list
    9711133  if UserText <> Copy(txtMed.Text, 1, txtMed.SelStart) then Exit;  // if typing during lookup
    9721134  if AllIndex > -1 then
     
    10441206begin
    10451207  StopKeyTimer;
     1208  if txtMed.ReadOnly then exit;        // v27.50 - RV - CQ #15365
    10461209  if not ((ActiveControl = lstAll) or (ActiveControl = lstQuick)) then ChangeDelayed;
    10471210end;
     
    11121275{ lstAll Methods (lstAll is TListView) }
    11131276
     1277procedure TfrmODMeds.Loaded;
     1278begin
     1279  inherited;
     1280  if ScreenReaderSystemActive then
     1281    tabDose.TabStop := TRUE;
     1282end;
     1283
     1284// Cache is a list of 100 string lists, starting at idx 0
    11141285procedure TfrmODMeds.LoadMedCache(First, Last: Integer);
    1115 const
    1116   MAX_CACHE_ITEMS = 1000;
    1117 begin
    1118   // if range is within cache range we don't need to update anything
    1119   if (First >= FAllFirst) and (Last <= FAllLast) then Exit;
    1120   // if range is outside of cache or a superset of cache, start over
    1121   if (Last < Pred(FAllFirst)) or (First > Succ(FAllLast)) or
    1122      ((First < FAllFirst) and (Last > FAllLast)) or
    1123      (FAllItems.Count > MAX_CACHE_ITEMS) then
    1124   begin
    1125     FAllItems.Clear;
    1126     FAllFirst := -1;
    1127     FAllLast  := -1;
    1128   end;
    1129   // if getting items immediately before cache range
    1130   if (First < FAllFirst) and (Last  >= FAllFirst) then Last  := Pred(FAllFirst);
    1131   // if getting items immediately after cache range
    1132   if (Last  > FAllLast)  and (First <= FAllLast)  then First := Succ(FAllLast);
    1133   // retrieve the items and append (First>FAllLast) or prepend them to FAllItems
    1134   SubsetOfOrderable(FAllItems, First>FAllLast, FAllList, First, Last);
    1135   // reset FAllFirst & FAllLast indexes to reflect current FAllItems
    1136   if FAllFirst < 0     then FAllFirst := First;
    1137   if FAllLast  < 0     then FAllLast  := Last;
    1138   if First < FAllFirst then FAllFirst := First;
    1139   if Last > FAllLast   then FAllLast := Last;
     1286var
     1287  firstChunk, lastchunk, i: integer;
     1288  list: TStringList;
     1289  firstMed, LastMed: integer;
     1290
     1291begin
     1292  firstChunk := GetCacheChunkIndex(First);
     1293  lastChunk := GetCacheChunkIndex(Last);
     1294  for i := firstChunk to lastChunk do
     1295  begin
     1296    if (FMedCache.Count <= i) or (not assigned(FMedCache[i])) then
     1297    begin
     1298      while FMedCache.Count <= i do
     1299        FMedCache.add(nil);
     1300      list := TStringList.Create;
     1301      FMedCache[i] := list;
     1302      firstMed := i * MED_CACHE_CHUNK_SIZE;
     1303      LastMed := firstMed + MED_CACHE_CHUNK_SIZE - 1;
     1304      if LastMed >= lstAll.Items.Count then
     1305        LastMed := lstAll.Items.Count - 1;
     1306      SubsetOfOrderable(list, false, FCacheIEN, firstMed, lastMed);
     1307    end;
     1308  end;
    11401309end;
    11411310
     
    11431312var
    11441313  x: string;
    1145 begin
    1146   if (FAllFirst = -1) or (Item.Index < FAllFirst) or (Item.Index > FAllLast)
    1147     then LoadMedCache(Item.Index, Item.Index);
    1148   x := FAllItems[Item.Index - FAllFirst];
     1314  chunk: integer;
     1315  list: TStringList;
     1316begin
     1317  LoadMedCache(Item.Index, Item.Index);
     1318  chunk := GetCacheChunkIndex(Item.Index);
     1319  list := TStringList(FMedCache[chunk]);
     1320  x := list[Item.Index mod MED_CACHE_CHUNK_SIZE];
    11491321  Item.Caption := Piece(x, U, 2);
    11501322  Item.Data := Pointer(StrToIntDef(Piece(x, U, 1), 0));
     
    11851357var
    11861358  MedIEN: Integer;
    1187   MedName: string;
     1359  //MedName: string;
    11881360  QOQuantityStr: string;
    1189   ErrMsg: string;
     1361  ErrMsg, Temp: string;
    11901362begin
    11911363  inherited;
    11921364  QOQuantityStr := '';
    11931365  btnSelect.SetFocus;                             // let the exit events finish
    1194 
     1366  self.MedName := '';
    11951367  if pnlMeds.Visible then                         // display the medication fields
    11961368  begin
     
    12041376      Responses.QuickOrder := Integer(lstQuick.Selected.Data);
    12051377      txtMed.Tag  := StrToIntDef(Responses.IValueFor('ORDERABLE', 1), 0);
     1378      if (not FInptDLG) and (PassDrugTest(TXTmED.Tag, 'N', false) = false) then exit;
     1379      if (FInptDLG) and (PassDrugTest(TXTmED.Tag, 'N', true) = false) then exit;
    12061380      IsActivateOI(ErrMsg, txtMed.Tag);
    12071381      if Length(ErrMsg)>0 then
     
    12091383        //btnSelect.Visible := False;
    12101384        btnSelect.Enabled := False;
    1211         ShowMessage(ErrMsg);
     1385        ShowMsg(ErrMsg);
    12121386        Exit;
    12131387      end;
     
    12281402        Exit;
    12291403      end;
     1404   (*   temp := self.MedName;
     1405      tempIEN := txtMed.Tag;
     1406      QOIEN := GetQOOrderableItem(InttoStr(Responses.QuickOrder));
     1407      if QOIEN > 0 then
     1408        begin
     1409          CheckFormularyOI(tempIEN, temp, FInptDlg);
     1410          if tempIEN <> txtMed.Tag then
     1411            begin
     1412              txtMed.Tag := tempIEN;
     1413              txtMed.Text := temp;
     1414            end;
     1415        end; *)
     1416      FAltChecked := True;
     1417      ;
    12301418      SetOnMedSelect;   // set up for this medication
    12311419      SetOnQuickOrder;  // insert quick order responses
     
    12331421         QOQuantityStr := txtQuantity.Text;
    12341422      ShowMedFields;
     1423      if self.tabDose.TabIndex = TI_COMPLEX then self.lblAdminSch.Visible := false;
    12351424      if (txtQuantity.Text = '0') and (Length(QOQuantityStr)>0) then
    12361425        txtQuantity.Text := QOQuantityStr;
     
    12391428    begin
    12401429      MedIEN := Integer(lstAll.Selected.Data);
    1241       MedName := lstAll.Selected.Caption;
     1430      self.MedName := lstAll.Selected.Caption;
     1431      if (not FInptDLG) and (PassDrugTest(MedIEN, 'N', false) = false) then exit;
     1432      if (FInptDLG) and (PassDrugTest(MedIEN, 'N', true) = false) then exit;
    12421433      txtMed.Tag := MedIEN;
    12431434      ErrMsg := '';
     
    12471438        //btnSelect.Visible := False;
    12481439        btnSelect.Enabled := False;
    1249         ShowMessage(ErrMsg);
     1440        ShowMsg(ErrMsg);
    12501441        Exit;
    12511442      end;
     
    12591450        Exit;
    12601451      end;
    1261       if Pos(' NF', MedName) > 0 then
    1262       begin
    1263         CheckFormularyOI(MedIEN, MedName, FInptDlg);
     1452      if Pos(' NF', self.MedName) > 0 then
     1453      begin
     1454        temp := self.MedName;
     1455        CheckFormularyOI(MedIEN, temp, FInptDlg);
    12641456        FAltChecked := True;
    12651457      end;
     
    12671459      begin
    12681460        txtMed.Tag := MedIEN;
    1269         txtMed.Text := MedName;
     1461        temp := self.MedName;
     1462        self.MedName := txtMed.Text;
     1463        txtMed.Text := Temp;
    12701464      end;
    12711465      SetOnMedSelect;
     
    13521546  cboSchedule.ItemIndex := -1;
    13531547  cboSchedule.Text := '';  // leave items intact
     1548  if FAdminTimeText <> 'Not defined for Clinic Locations' then lblAdminSchSetText('');
    13541549  txtSupply.Text := '';
    13551550  txtSupply.Tag := 0;
     
    13711566var
    13721567  i,j: Integer;
    1373   x: string;
     1568  temp,x: string;
    13741569  QOPiUnChk: boolean;
    13751570  PKIEnviron: boolean;
     1571  AResponse: TResponse;
    13761572begin
    13771573  // clear controls?
     
    13801576  txtQuantity.Tag := 0;
    13811577  spnQuantity.Tag := 0;
    1382   chkSC.Tag := 0;
    1383   QOPiUnChk := False;
     1578   QOPiUnChk := False;
    13841579  PKIEnviron := False;
    13851580  if GetPKISite then PKIEnviron := True;
     
    13901585    // set up lists & initial values based on orderable item
    13911586    SetControl(txtMed,       'Medication');
     1587    if (self.MedName <> '') then
     1588       begin
     1589         if (txtMed.Text <> self.MedName) then
     1590           begin
     1591             temp := self.MedName;
     1592             self.MedName := txtMed.Text;
     1593             txtMed.Text := temp;
     1594           end
     1595         else MedName := '';
     1596       end;
    13921597    SetControl(cboDosage,    'Dosage');
    13931598    SetControl(cboRoute,     'Route');
     
    13951600    cboRouteChange(Self);
    13961601    x := DefaultText('Schedule');
    1397     if x <> '' then
     1602    //AGP Change 27.72 trying to centralized the schedule setting code
     1603    AResponse := Responses.FindResponseByName('SCHEDULE',1);
     1604    if (AResponse <> nil) and (AResponse.EValue <> '') then  x := AResponse.EValue;
     1605    SetSchedule(x);
     1606   (* if x <> '' then
    13981607    begin
    13991608      cboSchedule.SelectByID(x);
     1609      if cboSchedule.ItemIndex > -1 then
     1610        AdminTime := Piece(cboSchedule.Items.Strings[cboSchedule.itemindex],U,4);
     1611      if (cboSchedule.ItemIndex < 0) and (RightStr(x,3) = 'PRN')  then
     1612        begin
     1613          self.chkPRN.Checked := true;
     1614          x := Copy(x,1,(Length(x)-3));
     1615          if RightStr(X,1) = ' ' then x := Copy(x,1,(Length(x)-1))
     1616        end;
    14001617      cboSchedule.Text := x;
    1401     end;
     1618    end; *)
    14021619    if Length(ValueOf(FLD_QTYDISP))>10 then
    14031620    begin
     
    14311648      lblPriority.Top := memcomment.Top + memComment.Height + 1;
    14321649      cboPriority.Top := lblPriority.Top + lblPriority.Height;
    1433       lblAdminTime.Left := chkDoseNow.Left;
    1434       lblAdminTime.Top := chkDoseNow.Top + chkDoseNow.Height - 1;
     1650      lblAdminSch.Left := chkDoseNow.Left;
     1651      lblAdminSch.Top := chkDoseNow.Top + chkDoseNow.Height - 1;
     1652      lblAdminSch.Height := (MainFontHeight * 3) + 3;
     1653      lblAdminSch.Width := cboPriority.Left - lblAdminSch.Left - 5;
     1654      lblAdminTime.Left := lblAdminSch.Left;
     1655      lblAdminTime.top := lblAdminSch.Top + lblAdminSch.Height -1;
     1656      if self.tabDose.TabIndex = TI_Dose then lblAdminSchSetText('')
     1657      else
     1658        begin
     1659          if FAdminTimeText = 'Not defined for Clinic Locations' then lblAdminSchSetText('Admin. Time: ' + FAdminTimeText)
     1660          else self.lblAdminSch.Visible := False;
     1661        end;
    14351662    end else
    14361663    begin
     
    14481675      end;
    14491676      //if Length(FPtInstruct) = 0 then
    1450       FPtInstruct := TextOf('PtInstr');
     1677      if FPtInstruct = '' then FPtInstruct := TextOf('PtInstr');
    14511678      for i := 1 to Length(FPtInstruct) do if Ord(FPtInstruct[i]) < 32 then FPtInstruct[i] := ' ';
    14521679      FPtInstruct := TrimRight(FPtInstruct);
     
    15121739        if FIsQuickOrder then TempSch := cboSchedule.Text;
    15131740        SetSchedule(IValueFor('SCHEDULE', i));
    1514         if (cboSchedule.Text = '') and FIsQuickOrder then
     1741        if (cboSchedule.Text = '') and (FIsQuickOrder) and (NSSchedule = False) then
    15151742        begin
    15161743          cboSchedule.SelectByID(TempSch);
    15171744          cboSchedule.Text := TempSch;
    15181745        end;
     1746        if (cboSchedule.Text = '') and (FIsQuickOrder) and (NSSchedule = True) then cboSchedule.ItemIndex := -1;
    15191747        x := cboSchedule.Text;
    15201748        if chkPRN.Checked then x := x + ' PRN';
     
    15241752        if chkPRN.Checked = True then grdDoses.Cells[COL_CHKXPRN,i] := '1';
    15251753        grdDoses.Cells[COL_DURATION, i] := IValueFor('DAYS', i);
     1754        if FInptDlg then
     1755          begin
     1756            if IValueFor('ADMIN', i) <> '' then grdDoses.Cells[COL_ADMINTIME, i] := IValueFor('ADMIN', i)
     1757            else if cboSchedule.ItemIndex > -1 then
     1758               grdDoses.Cells[COL_ADMINTIME, i] := Piece(cboSchedule.Items.Strings[cboSchedule.itemIndex],U,4)
     1759            else grdDoses.Cells[COL_ADMINTIME, i] := '';
     1760            if grdDoses.Cells[COL_ADMINTIME, i] = '' then grdDoses.Cells[COL_ADMINTIME, i] := 'Not Defined';
     1761            if FAdminTimeText <> '' then grdDoses.Cells[COL_ADMINTIME, i] := FAdminTimeText;
     1762          end;
    15261763        if      IValueFor('CONJ', i) = 'A' then x := 'AND'
    15271764        else if IValueFor('CONJ', i) = 'T' then x := 'THEN'
     
    15431780      SetControl(cboRoute,  'ROUTE',     1);
    15441781      SetSchedule(IValueFor('SCHEDULE',  1));
    1545       if (cboSchedule.Text = '') and FIsQuickOrder then
     1782      if (cboSchedule.Text = '') and (FIsQuickOrder) and (NSSchedule = False) then
    15461783      begin
    15471784        cboSchedule.SelectByID(TempSch);
    15481785        cboSchedule.Text := TempSch;
    15491786      end;
     1787      if (cboSchedule.Text = '') and (FIsQuickOrder) and (NSSchedule = True) then cboSchedule.ItemIndex := -1;
    15501788      if ((cboSchedule.Text = 'OTHER') and FIsQuickOrder)  then
    15511789         FNSSOther := True;
     
    15881826      AResponse := Responses.FindResponseByName('PICKUP', 1);
    15891827      if AResponse <> nil then SetPickup(AResponse.IValue);
    1590       if FIsQuickOrder then
     1828      if (FIsQuickOrder) and (FOrderAction = ORDER_QUICK) then
    15911829      begin
    15921830        if not QOHasRouteDefined(Responses.QuickOrder) then
     
    16031841      end;
    16041842      if ValueOf(FLD_PICKUP) = '' then SetPickup(FLastPickup);
    1605       AResponse := Responses.FindResponseByName('SC',     1);
    1606       if AResponse <> nil then chkSC.Checked := AResponse.IValue = '1';
     1843//      AResponse := Responses.FindResponseByName('SC',     1);
     1844      Responses.FindResponseByName('SC',     1);
    16071845    end; {if FInptDlg..else}
    16081846  end; {with}
    1609   if FInptDlg then
     1847 if FInptDlg then
    16101848  begin
    16111849    x := ValueOfResponse(FLD_SCHEDULE, 1);
     
    17041942  lblSchedule.Visible := True;
    17051943  cboSchedule.Visible := True;
     1944  if FInptDlg = True then lblAdminSch.Visible := True
     1945  else lblAdminSch.Visible := false;
    17061946  chkPRN.Visible := True;
    17071947  ActiveControl := cboDosage;
     
    17181958    begin
    17191959      DestCombo.Items.Clear;
    1720       DestCombo.Items.Assign(SrcCombo.Items);
     1960      FastAssign(SrcCombo.Items, DestCombo.Items);
    17211961      DestCombo.ItemIndex := SrcCombo.ItemIndex;
    17221962      DestCombo.Text := Piece(SrcCombo.Text, TAB, 1);
     
    17391979        else cnt := cnt+1;
    17401980      end;
     1981    if (index = -1) and (Text <> '') then
     1982       begin
     1983         for I := 0 to DestCombo.Items.Count - 1 do
     1984         if Piece(DestCombo.Items.Strings[i],U,1) = Text then
     1985            begin
     1986               DestCombo.ItemIndex := i;
     1987               DestCombo.Text := Text;
     1988               Exit;
     1989            end;
     1990       end;
    17411991    end;
    17421992  end;
     
    18152065procedure TfrmODMeds.SetSchedule(const x: string);
    18162066var
    1817 NonPRNPart: string;
    1818 begin
    1819   cboSchedule.ItemIndex := -1;
    1820   //AGP change CQ 10593, remove code to match the new expected first dose code
    1821   //PSI-05-026
    1822  (* if Pos('PRN', x) > 0 then
    1823   begin
    1824     NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
    1825     cboSchedule.SelectByID(NonPRNPart);
    1826     if cboSchedule.ItemIndex < 0 then
    1827     begin
    1828       if NSSchedule then
    1829       begin
    1830         chkPRN.Checked := False;
    1831         cboSchedule.Text := '';
    1832       end else
    1833       begin
    1834         chkPRN.Checked := True;
    1835         cboSchedule.Items.Add(NonPRNPart);
    1836         cboSchedule.Text := NonPRNPart;
     2067NonPRNPart,tempSch, tempText: string;
     2068begin
     2069    //AGP Change 27.72 if schedule matches why goes through and reprocess the same info?
     2070    if cboSchedule.ItemIndex > -1 then
     2071      begin
     2072        tempText := Piece(cboSchedule.Items.Strings[cboSchedule.itemindex], U, 1);
     2073        if tempText = x then exit;
     2074        if (Pos('PRN',x)>0) and (chkPRN.Checked = true) then
     2075          begin
     2076             NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
     2077             if nonPRNPart = tempText then exit;
     2078          end;
    18372079      end;
    1838     end else
    1839       chkPRN.Checked := True;
    1840   end else
    1841   begin  *)
    1842     chkPRN.Checked := False;
     2080    cboSchedule.ItemIndex := -1;
     2081    if chkPRN.Checked = True then chkPRN.Checked := False;
    18432082    cboSchedule.SelectByID(x);
    1844     if cboSchedule.ItemIndex < 0 then
    1845     begin
    1846       if NSSchedule then
    1847       begin
    1848         cboSchedule.Text := '';
     2083    if cboSchedule.ItemIndex > -1 then exit;
     2084   // if cboSchedule.ItemIndex < 0 then
     2085    //begin
     2086      //if NSSchedule then
     2087      //begin
     2088      //  cboSchedule.Text := '';
     2089      //end
     2090      if FInptDlg then
     2091        begin
     2092          if (Pos('@', x) > 0) then
     2093            begin
     2094            tempSch := Piece(x, '@', 2);
     2095            cboSchedule.SelectByID(tempSch);
     2096            if cboSchedule.ItemIndex > -1 then
     2097              begin
     2098                tempSch := Piece(x, '@', 1) + '@' + cboSchedule.Items.Strings[cboSchedule.itemindex];
     2099                cboSchedule.Items.Add(tempSch);
     2100                cboSchedule.Text := (Piece(tempSch,U,1));
     2101                cboSchedule.SelectByID(Piece(tempSch,u,1));
     2102                EXIT;
     2103              end;
     2104            if Pos('PRN', tempSch) > 0 then
     2105              begin
     2106                NonPRNPart := Trim(Copy(tempSch, 1, Pos('PRN', tempSch) - 1));
     2107                cboSchedule.SelectByID(NonPRNPart);
     2108                if cboSchedule.ItemIndex > -1 then
     2109                  begin
     2110                    tempSch := Piece(x, '@', 1) + '@' + cboSchedule.Items.Strings[cboSchedule.itemindex];
     2111                    cboSchedule.Items.Add(tempSch);
     2112                    cboSchedule.Text := (Piece(tempSch,U,1));
     2113                    cboSchedule.SelectByID(Piece(tempSch,u,1));
     2114                    chkPRN.Checked := True;
     2115                    EXIT;
     2116                  end
     2117                else
     2118                  begin
     2119                    NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
     2120                    chkPRN.Checked := true;
     2121                    tempSch := NonPRNPart + U + U + U + Piece(NonPRNPart, '@', 2);
     2122                    cboSchedule.Items.Add(tempSch);
     2123                    cboSchedule.SelectByID(Piece(tempSch, U, 1));
     2124                    EXIT;
     2125                  end;
     2126              end;
     2127              cboSchedule.Items.Add(X + U + U + U + Piece(x, '@', 2));
     2128              cboSchedule.Text := x;
     2129              cboSchedule.SelectByID(x);
     2130              EXIT;
     2131            end
     2132        else if Pos('PRN', x) > 0 then
     2133          begin
     2134            NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
     2135            chkPRN.Checked := True;
     2136            cboSchedule.SelectByID(NonPRNPart);
     2137            if cboSchedule.ItemIndex > -1 then  EXIT;
     2138          end;
    18492139      end
    1850       else
    1851       begin
    1852       if Pos('PRN', x) > 0 then
     2140      else if Pos('PRN', x) > 0 then
    18532141        begin
    18542142         NonPRNPart := Trim(Copy(x, 1, Pos('PRN', x) - 1));
     
    18612149         EXIT;
    18622150        end;
    1863          cboSchedule.Items.Add(x);
    1864          cboSchedule.Text := x;
    1865          cboSchedule.SelectByID(x);
    1866       end;
    1867   end;
     2151      cboSchedule.Items.Add(x);
     2152      cboSchedule.Text := x;
     2153      cboSchedule.SelectByID(x);
    18682154end;
    18692155
     
    18722158var
    18732159  //text,x, tmpsch: string;
    1874   text, x: string;
     2160  text, tmpAdmin, x: string;
    18752161  reset: integer;
    18762162begin
     
    18962182  TI_DOSE:    begin
    18972183                cboXSchedule.Clear;                       // Added to Fix CQ: 9603
     2184                cboXDosage.Clear;
    18982185                // clean up responses?
    18992186                FSuppressMsg := FOrigiMsgDisp;
     
    19122199                FSuppressMsg := FOrigiMsgDisp;
    19132200                if reset = 1 then exit;
     2201               (*  AGP Change admin wrap 27.73
     2202                tmpAdmin := Piece(self.lblAdminSch.text, ':', 2);
     2203                tmpAdmin := Copy(tmpAdmin,2,Length(tmpAdmin)); *)
     2204                tmpAdmin := lblAdminSchGetText;
     2205                if FAdminTimeText <> '' then
     2206                  begin
     2207                    tmpAdmin := FAdminTimeText;
     2208                    if FAdminTimeText <> 'Not defined for Clinic Locations' then self.lblAdminSch.Visible := False;
     2209                  end;               
    19142210                ShowControlsComplex;
    19152211                ResetOnTabChange;
     
    19172213                txtNss.Visible := False;
    19182214                x := cboXDosage.Text + TAB;
     2215                if LeftStr(x,1) = '.' then x := '';
    19192216                with cboXDosage   do if ItemIndex > -1 then x := x + Items[ItemIndex];
    19202217                grdDoses.Cells[COL_DOSAGE,   1] := x;
     
    19252222                with cboXSchedule do if ItemIndex > -1 then x := x + Items[ItemIndex];
    19262223                grdDoses.Cells[COL_SCHEDULE, 1] := x;
    1927                 UpdateStartExpires(ValFor(VAL_SCHEDULE,1));
     2224                //AGP Change 27.1 handle PRN not showing in schedule panel if a dose is not selected.
     2225                if FSmplPRNChkd then
     2226                  begin
     2227                    pnlXSchedule.Tag := 1;
     2228                    self.chkXPRN.Checked := True;
     2229                  end;
     2230                if FInptDLG then UpdateStartExpires(ValFor(VAL_SCHEDULE,1));
    19282231                ControlChange(Self);
    19292232             end; {TI_COMPLEX}
    19302233  end; {case}
    1931 end;
    1932 
     2234  if ScreenReaderSystemActive then
     2235    GetScreenReader.Speak(tabDose.Tabs[tabDose.TabIndex] + ' tab');
     2236end;
     2237
     2238
     2239function TfrmODMeds.lblAdminSchGetText: string;
     2240var
     2241tempstr: string;
     2242i: integer;
     2243begin
     2244  result := '';
     2245  if self.lblAdminSch.Text = '' then exit;
     2246  tempstr := '';
     2247  if self.lblAdminSch.Lines.Count > 1 then
     2248    begin
     2249      for i := 0 to self.lblAdminSch.Lines.Count - 1 do
     2250        tempstr := tempStr + self.lblAdminSch.Lines.Strings[i];
     2251    end
     2252  else if self.lblAdminSch.Lines.Count = 1 then
     2253       begin
     2254         tempstr := self.lblAdminSch.Text;
     2255       end;
     2256  Result := Piece(tempStr,':',2);
     2257  Result := Copy(Result,2,Length(Result));
     2258end;
     2259
     2260procedure TfrmODMeds.lblAdminSchSetText(str: string);
     2261var
     2262cutoff: integer;
     2263begin
     2264  cutoff := lblAdminSch.width div MainFontWidth;
     2265  if Length(str) > cutoff then self.lblAdminSch.Text := Copy(str, 1, cutoff) + CRLF +
     2266                                              Copy(str, cutoff + 1, Length(str))
     2267  else self.lblAdminSch.Text := str;
     2268end;
    19332269
    19342270procedure TfrmODMeds.lblGuidelineClick(Sender: TObject);
     
    20102346
    20112347procedure TfrmODMeds.cboDosageChange(Sender: TObject);
    2012 begin
    2013   inherited;
     2348var
     2349temp1,temp2: string;
     2350Count: integer;
     2351begin
     2352  inherited;
     2353  Count := Pos(U,cboDosage.Text);
     2354  if Count > 0 then
     2355    begin
     2356      temp1 := copy(cboDosage.Text,0,count-1);
     2357      temp2 := copy(cboDosage.Text,count+1,Length(cboDosage.text));
     2358      infoBox('An ^ is not allowed in the dosage value', 'Dosage Warning', MB_OK);
     2359      cboDosage.Text := temp1 + temp2;
     2360    end;
    20142361  UpdateRelated;
    20152362end;
    20162363
    20172364procedure TfrmODMeds.cboDosageExit(Sender: TObject);
    2018 begin
    2019   inherited;
     2365var
     2366str: string;
     2367begin
     2368  inherited;
     2369  str := cboDosage.Text;
    20202370  if (length(cboDosage.Text)<1) then
    2021     cboDosage.ItemIndex := -1;
     2371      cboDosage.ItemIndex := -1;
     2372 (* Probably not needed here since this on validation check on accept
     2373  if (LeftStr(cboDosage.Text,1)='.') then
     2374       begin
     2375         infoBox('Dosage must have a leading numeric value','Invalid Dosage',MB_OK);
     2376         if self.tabDose.TabIndex = TI_DOSE then cboDosage.SetFocus;
     2377         Exit;
     2378       end; *)
     2379  if (length(cbodosage.Text)>0) and (cboDosage.ItemIndex > -1) and
     2380    (Piece(cboDosage.Items.Strings[cboDosage.ItemIndex],U,5) <> Piece(cboDosage.Text,tab,1)) then
     2381    begin
     2382      cboDosage.ItemIndex := -1;
     2383      cboDosage.Text := Piece(str, tab, 1);
     2384      UpdateRelated(false);
     2385    end;
    20222386  if ActiveControl = memMessage then
    20232387  begin
     
    20822446    if length(trim(othSch)) > 1 then
    20832447    begin
     2448      othSch := othSch + U + U + NSSScheduleType + U + NSSAdminTime;
     2449      cboSchedule.Items.Add(othSch);
     2450      idx := cboSchedule.Items.IndexOf(Piece(OthSch, U, 1));
     2451      cboSchedule.ItemIndex := idx;
     2452    end;
     2453  end
     2454  else
     2455    begin
     2456      NSSAdminTime := '';
     2457      FNSSScheduleType := '';
     2458    end;
     2459  UpdateRelated(False);
     2460end;
     2461
     2462
     2463procedure TfrmODMeds.cboScheduleChange(Sender: TObject);
     2464var
     2465  othSch: string;
     2466  idx : integer;
     2467begin
     2468  inherited;
     2469  if  (FInptDlg) and (cboSchedule.Text = 'OTHER') then
     2470  begin
     2471    othSch := CreateOtherScheduel;
     2472    if length(trim(othSch)) > 1 then
     2473    begin
    20842474      cboSchedule.Items.Add(othSch);
    20852475      idx := cboSchedule.Items.IndexOf(OthSch);
     
    20872477    end;
    20882478  end;
    2089   UpdateRelated(False);
    2090 end;
    2091 
    2092 procedure TfrmODMeds.cboScheduleChange(Sender: TObject);
    2093 var
    2094   othSch: string;
    2095   idx : integer;
    2096 begin
    2097   inherited;
    2098   if  (FInptDlg) and (cboSchedule.Text = 'OTHER') then
    2099   begin
    2100     othSch := CreateOtherScheduel;
    2101     if length(trim(othSch)) > 1 then
    2102     begin
    2103       cboSchedule.Items.Add(othSch);
    2104       idx := cboSchedule.Items.IndexOf(OthSch);
    2105       cboSchedule.ItemIndex := idx;
    2106     end;
    2107   end;
    2108 //Remove Deletion of Text, since we are changing the validation to be on exit of the control.
    2109 {  if (Length(cboSchedule.Text)>0) and (cboSchedule.ItemIndex < 0) and FInptDlg then
    2110     cboSchedule.Text := '';}
    21112479  FScheduleChanged := true;
    21122480  UpdateRelated;
     
    21782546  inherited;
    21792547  if Changing then Exit;
    2180   if not Showing then Exit;
     2548  if not Showing then
     2549    begin
     2550       if (FISQuickOrder = true) and (txtQuantity.Text = '0') and (FLastQuantity > 0) and (FLastQuantity <> StrtoInt64(txtQuantity.text)) then
     2551         begin
     2552           Changing := True;
     2553           txtQuantity.Text := FloattoStr(FLastQuantity);
     2554           Changing := False;
     2555         end;
     2556       Exit;
     2557    end;
    21812558  if FNoZERO = False then FNoZERO := True;
    21822559  // if value = 0, change probably caused by the spin button
    21832560  if txtQuantity.Text <> '0' then txtQuantity.Tag := 1;
    21842561  UpdateRelated;
    2185 end;
    2186 
    2187 procedure TfrmODMeds.chkSCEnter(Sender: TObject);
    2188 begin
    2189   inherited;
    2190   pnlMessage.TabOrder := chkSC.TabOrder+1;
    2191   DispOrderMessage(RatedDisabilities);
    2192 end;
    2193 
    2194 procedure TfrmODMeds.chkSCClick(Sender: TObject);
    2195 begin
    2196   inherited;
    2197   chkSC.Tag := 1;
    21982562end;
    21992563
     
    23152679end;
    23162680
     2681
    23172682function TfrmODMeds.ConstructedDoseFields(const ADose: string; PrependName: Boolean = FALSE): string;
    23182683var
     
    24412806begin
    24422807  Result := '';
    2443   if FInptDlg then                                // inpatient dialog
     2808 if FInptDlg then                                // inpatient dialog
    24442809  begin
    24452810    DrugOK := True;
     
    24912856            end
    24922857            else DoseUnits := Piece(DoseFields, '&', 2);
    2493             if not AnsiSameText(DoseUnits, DrugUnits) then DrugOK := False;
     2858            if (not AnsiSameText(DoseUnits, DrugUnits)) then DrugOK := False;
    24942859          end;
    24952860          if not DrugOK then
     
    25362901  FUpdated := FALSE;
    25372902  Responses.Clear;
    2538   Responses.Update('ORDERABLE',  1, IntToStr(txtMed.Tag), txtMed.Text);
     2903  if self.MedName = '' then Responses.Update('ORDERABLE',  1, IntToStr(txtMed.Tag), txtMed.Text)
     2904  else Responses.Update('ORDERABLE',  1, IntToStr(txtMed.Tag), self.MedName);
    25392905  DoseList := TStringList.Create;
    25402906  case tabDose.TabIndex of
     
    25792945                                else Responses.Update('ROUTE',    1, '', x);
    25802946      x := ValueOf(FLD_SCHEDULE);    Responses.Update('SCHEDULE', 1, x,  x);
     2947      if FInptDlg then
     2948        begin
     2949        (* AGP Change Admin Time Wrap 27.73
     2950          x := Piece(self.lblAdminSch.text,':',2);
     2951          x := Copy(x,2,Length(x));  *)
     2952          x := lblAdminSchGetText;
     2953          if FAdminTimeText <> '' then x := '';
     2954          if x = 'Not Defined' then x := '';
     2955          Responses.Update('ADMIN',1,x,x);
     2956          X := Valueof(FLD_SCHED_TYP);
     2957          if self.chkPRN.Checked = true then x := 'P';
     2958          Responses.Update('SCHTYPE',1,x,x);
     2959        end;
    25812960    end;
    25822961  TI_COMPLEX:
     
    26273006        end;
    26283007        x := ValueOf(FLD_DURATION, i);  Responses.Update('DAYS',     i, UpperCase(x), x);
     3008        if FInptDlg then
     3009          begin
     3010            x := ValFor(VAL_ADMINTIME,i);
     3011            if FAdminTimeText <> '' then x := '';
     3012            if x = 'Not Defined' then x := '';
     3013            Responses.Update('ADMIN',i,x,x);
     3014            x := Valueof(FLD_SCHED_TYP, i);
     3015            if ValFor(VAL_CHKXPRN, i) = '1' then x := 'P';
     3016            Responses.Update('SCHTYPE', i, x, x);
     3017          end;
    26293018        x := ValueOf(FLD_SEQUENCE, i);
    26303019        if      Uppercase(x) = 'THEN'   then x := 'T'
     
    26743063  with grdDoses do
    26753064    case FieldID of
    2676     COL_DOSAGE   : Result := Piece(Cells[COL_DOSAGE,   ARow], TAB, 1);
    2677     COL_ROUTE    : Result := Piece(Cells[COL_ROUTE,    ARow], TAB, 1);
    2678     COL_SCHEDULE : Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
    2679     COL_DURATION : Result := Piece(Cells[COL_DURATION, ARow], TAB, 1);
    2680     COL_SEQUENCE : Result := Piece(Cells[COL_SEQUENCE, ARow], TAB, 1);
    2681     VAL_DOSAGE   : Result := Piece(Cells[COL_DOSAGE,   ARow], TAB, 2);
    2682     VAL_ROUTE    : Result := Piece(Cells[COL_ROUTE,    ARow], TAB, 2);
    2683     VAL_SCHEDULE : Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
    2684     VAL_DURATION : Result := Piece(Cells[COL_DURATION, ARow], TAB, 1);
    2685     VAL_SEQUENCE : Result := Piece(Cells[COL_SEQUENCE, ARow], TAB, 1);
    2686     VAL_CHKXPRN  : Result := Cells[COL_CHKXPRN, ARow];
     3065    COL_DOSAGE    : Result := Piece(Cells[COL_DOSAGE,   ARow], TAB, 1);
     3066    COL_ROUTE     : Result := Piece(Cells[COL_ROUTE,    ARow], TAB, 1);
     3067    COL_SCHEDULE  : Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
     3068    COL_DURATION  : Result := Piece(Cells[COL_DURATION, ARow], TAB, 1);
     3069    COL_SEQUENCE  : Result := Piece(Cells[COL_SEQUENCE, ARow], TAB, 1);
     3070    VAL_DOSAGE    : Result := Piece(Cells[COL_DOSAGE,   ARow], TAB, 2);
     3071    VAL_ROUTE     : Result := Piece(Cells[COL_ROUTE,    ARow], TAB, 2);
     3072    VAL_SCHEDULE  : Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
     3073    VAL_DURATION  : Result := Piece(Cells[COL_DURATION, ARow], TAB, 1);
     3074    VAL_ADMINTIME : Result := Piece(Cells[COL_ADMINTIME, ARow], TAB, 1);
     3075    VAL_SEQUENCE  : Result := Piece(Cells[COL_SEQUENCE, ARow], TAB, 1);
     3076    VAL_CHKXPRN   : Result := Cells[COL_CHKXPRN, ARow];
    26873077    end;
    26883078end;
     
    27303120function TfrmODMeds.DurationToDays: Integer;
    27313121var
    2732   i, DoseMinutes, TotalMinutes: Integer;
     3122  i, DoseMinutes, AndMinutes, TotalMinutes: Integer;
    27333123  AllRows: Boolean;
    27343124  Days: Extended;
     
    27433133  if not AllRows then Exit;
    27443134
     3135  AndMinutes := 0;
    27453136  TotalMinutes := 0;
    27463137  with grdDoses do for i := 1 to Pred(RowCount) do
     
    27543145      if Piece(x, ' ', 2) = 'HOURS'   then DoseMinutes := ExtractInteger(x) * 60;
    27553146      if Piece(x, ' ', 2) = 'MINUTES' then DoseMinutes := ExtractInteger(x);
    2756       TotalMinutes := TotalMinutes + DoseMinutes;
    2757     end;
     3147      // Determine how TotalMinutes should be calculated based on conjunction
     3148      if ValFor(COL_SEQUENCE, i) <> 'AND' then  // 'THEN', 'EXCEPT', or ''
     3149      begin
     3150        if AndMinutes = 0 then TotalMinutes := TotalMinutes + DoseMinutes;
     3151        if AndMinutes > 0 then
     3152        begin
     3153          if AndMinutes < DoseMinutes then AndMinutes := DoseMinutes;
     3154          TotalMinutes := TotalMinutes + AndMinutes;
     3155          AndMinutes := 0;
     3156        end;
     3157        if ValFor(COL_SEQUENCE, i) = 'EXCEPT' then break;  //quit out of For Loop to stop counting TotalMinutes
     3158      end;
     3159      if (ValFor(COL_SEQUENCE, i) = 'AND') then
     3160        if AndMinutes < DoseMinutes then AndMinutes := DoseMinutes;
     3161    end;
     3162  if AndMinutes > 0 then TotalMinutes := TotalMinutes + AndMinutes;
     3163
    27583164  Days := TotalMinutes / 1440;
    27593165  if Days > Int(Days) then Days := Days + 1;
     
    27683174  REL_DURATION = 0.16;
    27693175  REL_ANDTHEN  = 0.10;
     3176  REL_ADMINTIME = 0.16;
    27703177var
    27713178  i, ht, RowCountShowing: Integer;
     
    27773184    i := grdDoses.Width - 12;                 // 12 = 4 pixel margin + 8 pixel column 0
    27783185    i := i - GetSystemMetrics(SM_CXVSCROLL);  // compensate for appearance of scroll bar
    2779     ColWidths[1] := Round(REL_DOSAGE   * i);  // dosage
    2780     ColWidths[2] := Round(REL_ROUTE    * i);  // route
    2781     ColWidths[3] := Round(REL_SCHEDULE * i);  // schedule
    2782     ColWidths[4] := Round(REL_DURATION * i);  // duration
    2783     ColWidths[5] := Round(REL_ANDTHEN  * i);  // and/then
     3186    if (not FinptDlg) or (FAdminTimeText = 'Not defined for Clinic Locations') then
     3187      begin
     3188        ColWidths[1] := Round(REL_DOSAGE   * i);  // dosage
     3189        ColWidths[2] := Round(REL_ROUTE    * i);  // route
     3190        ColWidths[3] := Round(REL_SCHEDULE * i);  // schedule
     3191        ColWidths[4] := Round(REL_DURATION * i);  // duration
     3192        ColWidths[5] := Round(0  * i);  // administration time
     3193        grdDoses.TabStops[5] := False;
     3194        ColWidths[6] := Round(REL_ANDTHEN  * i);  // and/then
     3195      end
     3196    else
     3197      begin
     3198        ColWidths[1] := Round(0.35    * i);  // dosage
     3199        ColWidths[2] := Round(0.10     * i);  // route
     3200        ColWidths[3] := Round(0.19  * i);  // schedule
     3201        ColWidths[4] := Round(0.12  * i);  // duration
     3202        ColWidths[5] := Round(0.16 * i);  // administration time
     3203        grdDoses.TabStops[5] := True;
     3204        ColWidths[6] := Round(0.08   * i);  // and/then
     3205      end;
    27843206    // adjust height of grid to not show partial rows
    27853207    ht := pnlBottom.Top - Top - 6;
     
    27963218      COL_SCHEDULE:ColControl := pnlXSchedule;
    27973219      COL_DURATION:ColControl := pnlXDuration;
    2798       COL_SEQUENCE:ColControl := pnlXSequence;
     3220      COL_ADMINTIME:ColControl := pnlXAdminTime;
     3221      COL_SEQUENCE:ColControl := cboXSequence;
    27993222    end; {case}
    28003223
     
    28443267  COL_ROUTE:    with cboXRoute    do if Items.Count > 0 then DroppedDown := True;
    28453268  COL_SCHEDULE: with cboXSchedule do if Items.Count > 0 then DroppedDown := True;
     3269  COL_SEQUENCE: with cboXSequence do if Items.Count > 0 then DroppedDown := True;
     3270                                     
    28463271  end;
    28473272  FDropColumn := -1;
     
    29773402                  end; *)
    29783403                  Changing := FALSE;
    2979                   pnlXSequence.Tag := ARow;
     3404                  cboXSequence.Tag := ARow;
    29803405                  PlaceControl(pnlXSchedule);
    2981                   //cboXSchedule.SetFocus;
    29823406                  FDropColumn := COL_SCHEDULE;
    29833407                  if AChar <> #0 then PostMessage(Handle, UM_DELAYEVENT, Ord(AChar), COL_SCHEDULE);
     
    30053429                end;
    30063430  COL_SEQUENCE: begin
    3007                   x := ValFor(COL_SEQUENCE, ARow);
    3008                   //if x = '' then x := 'and';  AGP Change 26.46 remove for CQ 9535
    3009                   btnXSequence.Caption := x;
    3010                   pnlXSequence.Caption := btnXSequence.Caption;
    3011                   pnlXSequence.Tag := ARow;
     3431                  SynchCombo(cboXSequence, ValFor(VAL_SEQUENCE, ARow), ValFor(COL_SEQUENCE, ARow));
     3432                  cboXSequence.Tag := ARow;
    30123433                  ARow1 := ARow;
    3013                   PlaceControl(pnlXSequence);
    3014                   btnXSequence.Width := pnlXSequence.Width;
     3434                  PlaceControl(cboXSequence);
     3435                  FDropColumn := COL_SEQUENCE;
     3436                  if AChar <> #0 then PostMessage(Handle, UM_DELAYEVENT, Ord(AChar), COL_SEQUENCE);
    30153437                end;
     3438  COL_ADMINTIME: BEGIN
     3439                 pnlXAdminTime.OnClick(pnlXAdminTime);
     3440                 end;
    30163441  end; {case ACol}
    30173442end;
     
    30283453                   txtXDuration.SelStart := 1;
    30293454                 end;
     3455  COL_SEQUENCE : FindInCombo(Chr(Message.WParam), cboXSequence);
    30303456  end;
    30313457end;
     
    30413467
    30423468procedure TfrmODMeds.cboXDosageChange(Sender: TObject);
     3469var
     3470temp1,temp2: string;
     3471count: integer;
    30433472begin
    30443473  inherited;
    30453474  if not Changing and (cboXDosage.ItemIndex < 0) then
    30463475  begin
     3476    Count := Pos(U,cboXDosage.Text);
     3477    if Count > 0 then
     3478      begin
     3479        temp1 := copy(cboXDosage.Text,0,count-1);
     3480        temp2 := copy(cboXDosage.Text,count+1,Length(cboXDosage.text));
     3481        infoBox('An ^ is not allowed in the dosage value', 'Dosage Warning', MB_OK);
     3482        cboXDosage.Text := temp1 + temp2;
     3483      end;
    30473484    grdDoses.Cells[COL_DOSAGE, cboXDosage.Tag] := cboXDosage.Text;
    30483485    UpdateRelated;
     
    30853522
    30863523procedure TfrmODMeds.cboXDosageExit(Sender: TObject);
    3087 begin
    3088   inherited;
    3089   cboXDosageClick(Self);
    3090   cboXDosage.Tag := -1;
    3091   cboXDosage.Hide;
    3092   UpdateRelated;
    3093   RestoreDefaultButton;
    3094   RestoreCancelButton;
    3095   if (pnlMessage.Visible) and (memMessage.TabStop)  then
    3096   begin
    3097     pnlMessage.Parent := grdDoses.Parent;
    3098     pnlMessage.TabOrder := grdDoses.TabOrder;
    3099     ActiveControl := memMessage;
    3100   end
    3101   else if grdDoses.Showing then
    3102     ActiveControl := grdDoses
    3103   else
    3104     ActiveControl := cboDosage;
    3105 end;
     3524var
     3525//tempTag: integer;
     3526str: string;
     3527begin
     3528  inherited;
     3529  if cboXDosage.Showing then
     3530  begin
     3531    cboXDosageClick(Self);
     3532    str := cboXDosage.Text;
     3533    //tempTag := cboXDosage.Tag;
     3534    //cboXDosage.Tag := -1;
     3535    cboXDosage.Hide;
     3536    UpdateRelated;
     3537    RestoreDefaultButton;
     3538    RestoreCancelButton;
     3539   (*Probably not needed here since on validation check on accept
     3540    if (LeftStr(cboXDosage.Text,1)='.') and (self.tabDose.TabIndex = TI_COMPLEX) then
     3541         begin
     3542           infoBox('Dosage must have a leading numeric value','Invalid Dosage',MB_OK);
     3543           //cboXDosage.Tag := tempTag;
     3544           cboXDosage.Show;
     3545           cboXDosage.SetFocus;
     3546           Exit;
     3547         end;  *)
     3548    if (length(cboxdosage.Text)>0) and (cboxDosage.ItemIndex > -1) and
     3549      (Piece(cboxDosage.Items.Strings[cboxDosage.ItemIndex],U,5) <> Piece(cboxDosage.Text,'#',1)) then
     3550      begin
     3551        cboXDosage.ItemIndex := -1;
     3552        cboXDosage.Text := Piece(str, '#', 1);
     3553        self.grdDoses.Cells[COL_DOSAGE,self.grdDoses.row] := cboXDosage.Text;
     3554        UpdateRelated(false);
     3555      end;
     3556    if (pnlMessage.Visible) and (memMessage.TabStop)  then
     3557    begin
     3558      pnlMessage.Parent := grdDoses.Parent;
     3559      pnlMessage.TabOrder := grdDoses.TabOrder;
     3560      ActiveControl := memMessage;
     3561    end
     3562    else if grdDoses.Showing then
     3563      ActiveControl := grdDoses
     3564    else
     3565      ActiveControl := cboDosage;
     3566    end
     3567    else
     3568       cmdQuit.Click;
     3569  end;
    31063570
    31073571procedure TfrmODMeds.cboXRouteChange(Sender: TObject);
     
    31753639    if (FInptDlg) and (cboXSchedule.Text = 'OTHER') then
    31763640    begin
     3641      cboXSchedule.SelectByID('OTHER');
    31773642      othSch := CreateOtherScheduelComplex;
    31783643      if length(trim(othSch)) > 1 then
    31793644      begin
     3645        othSch := othSch + U + U + NSSScheduleType + U + NSSAdminTime;
    31803646        cboXSchedule.Items.Add(othSch);
    3181         idx := cboXSchedule.Items.IndexOf(OthSch);
     3647        idx := cboXSchedule.Items.IndexOf(Piece(OthSch, U, 1));
    31823648        cboXSchedule.ItemIndex := idx;
    31833649      end;
    31843650    end;
    3185   (* if chkXPRN.Checked then PRN := ' PRN' else PRN := '';
    3186     with cboXSchedule do if ItemIndex > -1
    3187       then x := Text + PRN + TAB + Items[ItemIndex]
    3188       else x := Text + PRN; *)
     3651  if pnlXSchedule.Tag = -1 then pnlXSchedule.Tag := self.grdDoses.Row;
     3652    //if pnlXSchedule.Tag = -1 then pnlXSchedule.Tag := self.grdDoses.Row;
    31893653    with cboXSchedule do if ItemIndex > -1
    31903654      then x := Text + TAB + Items[ItemIndex]
     
    31923656    grdDoses.Cells[COL_SCHEDULE, pnlXSchedule.Tag] := x;
    31933657    self.cboSchedule.Text := x;
     3658     //AGP Start Expired uncommented out the line
     3659    if FInptDlg then UpdateStartExpires(Piece(x, tab, 1));
    31943660    UpdateRelated;
    31953661  end;
     
    31983664procedure TfrmODMeds.cboXScheduleClick(Sender: TObject);
    31993665var
    3200   x: string;
    3201 begin
    3202   inherited;
    3203   //if chkXPRN.Checked then PRN := ' PRN' else PRN := '';
     3666  PRN,x: string;
     3667begin
     3668  inherited;
     3669  //agp change CQ 11015
     3670  if (chkXPRN.Checked) then PRN := ' PRN' else PRN := '';
     3671  with cboXSchedule do
     3672    begin
     3673      if RightStr(Text,3) = 'PRN' then PRN := '';
     3674      if ItemIndex > -1 then x := Text + PRN + TAB + Items[ItemIndex]
     3675      else x := Text + PRN;
     3676    end;
    32043677 (* with cboXSchedule do if ItemIndex > -1
    3205     then x := Text + PRN + TAB + Items[ItemIndex]
    3206     else x := Text + PRN;  *)
    3207   with cboXSchedule do if ItemIndex > -1
    32083678    then x := Text + TAB + Items[ItemIndex]
    3209     else x := Text;
    3210    (* if (Pos('PRN',X)>0) and (pnlXSchedule.Tag = 1) then
    3211     if lblAdmintime.visible then
    3212       lblAdmintime.Caption := ''; *)
     3679    else x := Text;  *)
    32133680  grdDoses.Cells[COL_SCHEDULE, pnlXSchedule.Tag] := x;
    3214   UpdateStartExpires(x);
     3681  //AGP Start Expired uncommented out the line
     3682  UpdateStartExpires(Piece(x, tab, 1));
    32153683  UpdateRelated;
    32163684end;
     
    32483716  else
    32493717    ActiveControl := cboDosage;
     3718  //AGP Start Expired commented out the line
     3719  //updateStartExpires(valFor(COL_SCHEDULE,self.grdDoses.Row));
     3720end;
     3721
     3722procedure TfrmODMeds.pnlXAdminTimeClick(Sender: TObject);
     3723var
     3724Str: string;
     3725begin
     3726  inherited;
     3727  if not FInptDlg then Exit;
     3728 
     3729  str := 'The Administration Times for this dose are: ' + CRLF + CRLF + VALFOR(VAL_ADMINTIME,grddoses.Row);
     3730  str := str + CRLF + CRLF + AdminTimeHelpText;
     3731  infoBox(str,'Administration Time Information',MB_OK);
    32503732end;
    32513733
     
    32723754    if (Code <> 0) {and (I=0)} then
    32733755    begin
    3274       ShowMessage('Please use numeric characters only.');
     3756      ShowMsg('Please use numeric characters only.');
    32753757      with txtXDuration do
    32763758      begin
     
    33053787                    begin
    33063788                        grdDoses.Cells[COL_DURATION, pnlXDuration.Tag] := '';
    3307                         pnlXSequence.Tag := ARow1;
    3308                         pnlXSequence.Caption := '';
    3309                         grdDoses.Cells[COL_SEQUENCE, pnlXSequence.Tag] := '';
    3310                         btnXSequence.Click;
     3789                        cboXSequence.Tag := ARow1;
     3790                        grdDoses.Cells[COL_SEQUENCE, cboXSequence.Tag] := '';
     3791                        cboXSequence.Text := '';
     3792                        cboXSequence.ItemIndex := -1;
    33113793                    end
    33123794                    else
     
    33403822end;
    33413823
    3342 procedure TfrmODMeds.btnXSequenceClick(Sender: TObject);
    3343 var
    3344   APoint: TPoint;
    3345 begin
    3346   inherited;
    3347   inherited;
    3348   with TSpeedButton(Sender) do APoint := ClientToScreen(Point(0, Height));
    3349   popXSequence.Popup(APoint.X, APoint.Y);
    3350   pnlXSequence.Caption := btnXSequence.Caption;
    3351   {
    3352   with TSpeedButton(Sender) do APoint := ClientToScreen(Point(0, Height));
    3353   popXSequence.Popup(APoint.X, APoint.Y);
    3354   pnlXSequence.Caption := btnXSequence.Caption;
    3355   if (pnlXSequence.Caption = 'then') and
    3356       ((ValFor(COL_DURATION, ARow1) = '') or
    3357        (ValFor(COL_DURATION, ARow1) = '0')) then
    3358      begin
    3359        InfoBox('A duration is required when using "Then" as a conjunction','Duration Warning',MB_OK);
    3360        pnlXSequence.Caption := '';
    3361        btnXSequence.Caption := '';
    3362      end;
    3363      }
    3364 end;
    3365 
    3366 procedure TfrmODMeds.popXSequenceClick(Sender: TObject);
    3367 var
    3368   x: string;
    3369 begin
    3370   inherited;
    3371   with TMenuItem(Sender) do if Tag > 0 then x := Caption else x := '';
    3372  //AGP Changes 26.12 PSI-04-63
    3373  //if ((x = 'then') and (FInptDlg)) and ((ValFor(COL_DURATION, ARow1) = '') or (ValFor(COL_DURATION, ARow1) = '0')) then
    3374  //AGP change 26.32 Then/And conjunction requiring a duration to include outpatient orders
    3375  if (x = 'then') and ((ValFor(COL_DURATION, ARow1) = '') or (ValFor(COL_DURATION, ARow1) = '0')) then
    3376      begin
    3377        InfoBox('A duration is required when using "Then" as a conjunction' + CRLF + CRLF+
    3378            'The patient will be instructed to take these doses consecutively, not concurrently.','Duration Warning',MB_OK);
    3379        x := '';
    3380      end;
    3381   btnXSequence.Caption := x;
    3382   pnlXSequence.Caption := btnXSequence.Caption;
    3383   grdDoses.Cells[COL_SEQUENCE, pnlXSequence.Tag] := Uppercase(x);
    3384   ControlChange(Sender);
    3385 end;
    3386 
    3387 procedure TfrmODMeds.pnlXSequenceExit(Sender: TObject);
    3388 begin
    3389   inherited;
    3390   grdDoses.Cells[COL_SEQUENCE, pnlXSequence.Tag] := Uppercase(btnXSequence.Caption);
    3391   if ActiveControl = grdDoses then
    3392   begin
    3393     //This next condition seldom occurs, since entering the dosage on the last
    3394     // row adds another row
    3395     if grdDoses.Row = grdDoses.RowCount - 1 then
    3396       grdDoses.RowCount := grdDoses.RowCount + 1;
    3397   end;
    3398   pnlXSequence.Tag := -1;
    3399   pnlXSequence.Hide;
    3400   RestoreDefaultButton;
    3401   RestoreCancelButton;
    3402   if (pnlMessage.Visible) and (memMessage.TabStop) then
    3403   begin
    3404     pnlMessage.Parent := grdDoses.Parent;
    3405     pnlMessage.TabOrder := grdDoses.TabOrder;
    3406     ActiveControl := memMessage;
    3407   end
    3408   else if grdDoses.Showing then
    3409     ActiveControl := grdDoses
    3410   else
    3411     ActiveControl := cboDosage;
    3412 end;
    34133824
    34143825procedure TfrmODMeds.btnXInsertClick(Sender: TObject);
     
    34633874    Schedule  <TAB> (nothing)
    34643875    Duration  <TAB> Duration^Units }
     3876
     3877  // the following functions were created to get rid of a compile warning saying the
     3878  // return value may be undefined - too much branching logic in the case statements
     3879  // for the compiler to handle
     3880 
     3881  function GetSingleDoseSchedule: string;
     3882  begin
     3883    Result := UpperCase(Trim(cboSchedule.Text));
     3884    if chkPRN.Checked then Result := Result + ' PRN';
     3885    if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN'
     3886      then Result := Copy(Result, 1, Length(Result) - 4);
     3887  end;
     3888
     3889  function GetSingleDoseScheduleEX: string;
     3890  begin
     3891    Result := '';
     3892    with cboSchedule do
     3893    begin
     3894      if ItemIndex > -1 then Result := Piece(Items[ItemIndex], U, 2);
     3895(*     if (Length(Result)=0) and (ItemIndex > -1) then
     3896        begin
     3897          Result := Piece(Items[ItemIndex], U, 1);
     3898          if Piece(Items[ItemIndex], U, 3) = 'P' then
     3899          begin
     3900            if RightStr(Result,3) = 'PRN' then
     3901              begin
     3902                Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
     3903                if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
     3904                Result := Copy(Result,1,Length(Result)-1);
     3905              end;
     3906           Result := Result + ' AS NEEDED';
     3907          end;
     3908        end;
     3909    end; *)
     3910      if RightStr(Result,3) = 'PRN' then
     3911      begin
     3912        Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
     3913        if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
     3914          Result := Copy(Result,1,Length(Result)-1);
     3915        Result := Result + ' AS NEEDED'
     3916      end;
     3917      if (Length(Result) > 0) and chkPRN.Checked then
     3918        Result := Result + ' AS NEEDED';
     3919      if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED' then
     3920        Result := Copy(Result, 1, Length(Result) - 10);
     3921      if UpperCase(Copy(Result, Length(Result) - 12, Length(Result))) = 'PRN AS NEEDED' then
     3922      begin
     3923        Result := Copy(Result, 1, Length(Result) - 13);
     3924        if RightStr(Result,1)=' ' then
     3925          Result := Result + 'AS NEEDED'
     3926        else
     3927          Result := Result + ' AS NEEDED';
     3928      end;
     3929    end;
     3930  end;
     3931
     3932  function GetComplexDoseSchedule: string;
     3933  begin
     3934    with grdDoses do
     3935    begin
     3936      Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 1);
     3937      if Result = '' then Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
     3938      if valFor(VAL_CHKXPRN,ARow)='1' then Result := Result + ' PRN';
     3939      if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN' then
     3940      Result := Copy(Result, 1, Length(Result) - 4);
     3941    end;
     3942  end;
     3943
     3944  function GetComplexDoseScheduleEX: string;
     3945  begin
     3946    with grdDoses do
     3947    begin
     3948      (*Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 2);
     3949      if Result = '' then //Added for CQ: 7639
     3950      begin
     3951        Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
     3952        if RightStr(Result,4) = ' PRN' then
     3953          Result := Copy(Result,1,Length(Result)-4); //Remove the Trailing PRN
     3954      end;
     3955      if (Piece(Cells[COL_SCHEDULE, ARow], TAB, 1) <>
     3956         Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 1)) and
     3957         (Pos('PRN', Piece(Cells[COL_SCHEDULE, ARow], TAB, 1)) > 0)
     3958         then Result := Result + ' AS NEEDED';
     3959    end;*)
     3960      Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2),U,2);
     3961      if Result = '' then Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2),U,1); //Added for CQ: 7639
     3962      if Result = '' then Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
     3963      if RightStr(Result,3) = 'PRN' then
     3964      begin
     3965        Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
     3966        if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
     3967        Result := Copy(Result,1,Length(Result)-1);
     3968        Result := Result + ' AS NEEDED';
     3969      end;
     3970      if valFor(VAL_CHKXPRN,ARow)='1' then Result := Result + ' AS NEEDED';
     3971      if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
     3972      then Result := Copy(Result, 1, Length(Result) - 10);
     3973      if UpperCase(Copy(Result, Length(Result) - 12, Length(Result))) = 'PRN AS NEEDED' then
     3974      begin
     3975        Result := Copy(Result, 1, Length(Result) - 13);
     3976        if RightStr(Result,1)=' ' then Result := Result + 'AS NEEDED'
     3977        else Result := Result + ' AS NEEDED';
     3978      end;
     3979    end;
     3980  end;
     3981 
    34653982begin
    34663983  Result := '';
     
    34964013    FLD_ROUTE_EX  : with cboRoute do
    34974014                     if ItemIndex > -1  then Result := Piece(Items[ItemIndex], U, 4);
    3498     FLD_SCHEDULE  : begin        //gary)
    3499                       Result := UpperCase(Trim(cboSchedule.Text));
    3500                       if chkPRN.Checked then Result := Result + ' PRN';
    3501                       if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN'
    3502                         then Result := Copy(Result, 1, Length(Result) - 4);
     4015    FLD_SCHEDULE  : begin     
     4016                      Result := GetSingleDoseSchedule;
    35034017                    end;
    35044018    FLD_SCHED_EX  : begin
    3505                       with cboSchedule do
    3506                         begin
    3507                         if ItemIndex > -1 then Result := Piece(Items[ItemIndex], U, 2);
    3508                    (*     if (Length(Result)=0) and (ItemIndex > -1) then
    3509                             begin
    3510                               Result := Piece(Items[ItemIndex], U, 1);
    3511                               if Piece(Items[ItemIndex], U, 3) = 'P' then
    3512                               begin
    3513                                 if RightStr(Result,3) = 'PRN' then
    3514                                   begin
    3515                                     Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
    3516                                     if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
    3517                                     Result := Copy(Result,1,Length(Result)-1);
    3518                                   end;
    3519                                Result := Result + ' AS NEEDED';
    3520                               end;
    3521                             end;
    3522                         end; *)
    3523                       if RightStr(Result,3) = 'PRN' then
    3524                            begin
    3525                               Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
    3526                               if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
    3527                               Result := Copy(Result,1,Length(Result)-1);
    3528                               Result := Result + ' AS NEEDED'
    3529                            end;
    3530                       if (Length(Result) > 0) and chkPRN.Checked then Result := Result + ' AS NEEDED';
    3531                       if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
    3532                         then Result := Copy(Result, 1, Length(Result) - 10);
    3533                       if UpperCase(Copy(Result, Length(Result) - 12, Length(Result))) = 'PRN AS NEEDED' then
    3534                           begin
    3535                             Result := Copy(Result, 1, Length(Result) - 13);
    3536                             if RightStr(Result,1)=' ' then Result := Result + 'AS NEEDED'
    3537                             else Result := Result + ' AS NEEDED';
    3538                           end;
    3539                     end;
     4019                      Result := GetSingleDoseScheduleEX;
    35404020                    end;
    35414021    FLD_SCHED_TYP : with cboSchedule do
     
    35784058      FLD_ROUTE_EX  : Result := Piece(Piece(Cells[COL_ROUTE, ARow], TAB, 2), U, 4);
    35794059      FLD_SCHEDULE  : begin
    3580                          Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 1);
    3581                          if Result = '' then Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
    3582                          if valFor(VAL_CHKXPRN,ARow)='1' then Result := Result + ' PRN';
    3583                          if UpperCase(Copy(Result, Length(Result) - 6, Length(Result))) = 'PRN PRN' then
    3584                          Result := Copy(Result, 1, Length(Result) - 4);
     4060                        Result := GetComplexDoseSchedule;
    35854061                      end;
    35864062      FLD_SCHED_EX  : begin
    3587                         (*Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 2);
    3588                         if Result = '' then //Added for CQ: 7639
    3589                         begin
    3590                           Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
    3591                           if RightStr(Result,4) = ' PRN' then
    3592                             Result := Copy(Result,1,Length(Result)-4); //Remove the Trailing PRN
    3593                         end;
    3594                         if (Piece(Cells[COL_SCHEDULE, ARow], TAB, 1) <>
    3595                            Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 1)) and
    3596                            (Pos('PRN', Piece(Cells[COL_SCHEDULE, ARow], TAB, 1)) > 0)
    3597                            then Result := Result + ' AS NEEDED';
    3598                       end;*)
    3599                         Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2),U,2);
    3600                         if Result = '' then Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2),U,1); //Added for CQ: 7639
    3601                         if Result = '' then Result := Piece(Cells[COL_SCHEDULE, ARow], TAB, 1);
    3602                         if RightStr(Result,3) = 'PRN' then
    3603                            begin
    3604                               Result := Copy(Result,1,Length(Result)-3); //Remove the Trailing PRN
    3605                               if (RightStr(Result,1) = ' ') or (RightStr(Result,1) = '-') then
    3606                               Result := Copy(Result,1,Length(Result)-1);
    3607                               Result := Result + ' AS NEEDED';
    3608                            end;
    3609                         if valFor(VAL_CHKXPRN,ARow)='1' then Result := Result + ' AS NEEDED';
    3610                         if UpperCase(Copy(Result, Length(Result) - 18, Length(Result))) = 'AS NEEDED AS NEEDED'
    3611                         then Result := Copy(Result, 1, Length(Result) - 10);
    3612                         if UpperCase(Copy(Result, Length(Result) - 12, Length(Result))) = 'PRN AS NEEDED' then
    3613                           begin
    3614                             Result := Copy(Result, 1, Length(Result) - 13);
    3615                             if RightStr(Result,1)=' ' then Result := Result + 'AS NEEDED'
    3616                             else Result := Result + ' AS NEEDED';
    3617                           end;
     4063                        Result := GetComplexDoseScheduleEX;
    36184064                      end;
    36194065      FLD_SCHED_TYP : Result := Piece(Piece(Cells[COL_SCHEDULE, ARow], TAB, 2), U, 3);
     
    36414087    FLD_PRIOR_NM  : Result := cboPriority.Text;
    36424088    FLD_COMMENT   : Result := memComment.Text;
    3643     FLD_SC        : if chkSC.Visible then
    3644                     begin
    3645                       if chkSC.Checked then Result := '1' else Result := '0';
    3646                     end;
     4089
    36474090    FLD_NOW_ID    : if chkDoseNow.Visible and chkDoseNow.Checked then Result := '1'   else Result := '';
    36484091    FLD_NOW_NM    : if chkDoseNow.Visible and chkDoseNow.Checked then Result := 'NOW' else Result := '';
     
    36824125var
    36834126  ADrug: string;
    3684 begin
     4127  Checked: boolean;
     4128  tmpSupply: integer;
     4129begin
     4130  Checked := false;
    36854131  if ((StrToFloatDef(txtQuantity.Text, 0) = 0) and (StrToIntDef(txtSupply.Text, 0) = 0) and
    36864132     (txtQuantity.Tag = 0) and (txtSupply.Tag = 0) and (cboDosage.Text <> ''))
    3687      or ((cboDosage.ItemIndex < 0) and not FIsQuickOrder ) then
    3688   begin
     4133     or ((cboDosage.ItemIndex < 0) and (not FIsQuickOrder)) or
     4134     ((IsClozapineOrder = true) and (FISQuickOrder) and (FQOInitial))  then
     4135  begin
     4136    Checked := True;
    36894137    ADrug := Piece(CurDispDrug, U, 1);
    36904138    CurSupply := DefaultDays(ADrug, CurUnits, CurSchedule);
     
    36944142      if (txtSupply.Text = '') or (StrToInt(txtSupply.Text)<>CurSupply)  then
    36954143        txtSupply.Text := IntToStr(CurSupply);
    3696       if (FIsQuickOrder and FQOInitial) then
     4144      if (FIsQuickOrder) and (FQOInitial) and (IsClozapineOrder = false) then
    36974145      begin
    36984146        if StrToFloatDef(txtSupply.Text,0) > 0 then
     
    37124160      SkipQtyCheck := TRUE;
    37134161    end;
    3714   end;
     4162    if FQOInitial = true then FQOInitial := False;   
     4163  end;
     4164  if (IsClozapineOrder = true) and (CurDispDrug <> '') and (CurDispDrug <> U)and (Checked = false) then
     4165    begin
     4166      ADrug := Piece(CurDispDrug, U, 1);
     4167      tmpSupply := DefaultDays(ADrug, CurUnits, CurSchedule);
     4168      if (tmpSupply > 0) and (CurSupply > tmpSupply) then
     4169        begin
     4170          CurSupply := tmpSupply;
     4171          spnSupply.Position := CurSupply;
     4172          if (txtSupply.Text = '') or (StrToInt(txtSupply.Text)<>CurSupply)  then
     4173          txtSupply.Text := IntToStr(CurSupply);
     4174        end;
     4175      CurQuantity := DaysToQty(CurSupply, CurUnits, CurSchedule, CurDuration, ADrug);
     4176      if CurQuantity >= 0 then
     4177      begin
     4178       //spnQuantity.Position := CurQuantity;
     4179       if (txtQuantity.Text <> '') and (CurQuantity > 0) then
     4180        txtQuantity.Text := FloatToStr(CurQuantity);
     4181       if (txtQuantity.Text = '') or (StrToInt(txtQuantity.Text) <> CurQuantity) and (CurQuantity > 0)  then
     4182         txtQuantity.Text := FloatToStr(CurQuantity);
     4183      end;
     4184    end;
    37154185end;
    37164186
     
    38084278end;
    38094279
    3810 procedure TfrmODMeds.UpdateSC(const CurDispDrug: string);
    3811 var
    3812   Dispense: Integer;
    3813 begin
    3814   Dispense := StrToIntDef(Piece(CurDispDrug, U, 1), 0);  // just use first dispense drug for now
    3815   if Patient.ServiceConnected and RequiresCopay(Dispense) then
    3816   begin
    3817     chkSC.Visible := True;
    3818     if chkSC.Tag = 0 then chkSC.Checked := Patient.SCPercent > 50;
    3819     if chkSC.Hint = '' then chkSC.Hint := RatedDisabilities;
    3820   end
    3821   else chkSC.Visible := False;
    3822   FUpdated := True;
     4280procedure TfrmODMeds.updateSig;
     4281begin
     4282  inherited;
     4283  if self.tabDose.TabIndex = TI_DOSE then self.cboDosage.OnExit(cboDosage);
     4284  if self.tabDose.TabIndex = TI_COMPLEX then self.cboxDosage.OnExit(cboxDosage);
    38234285end;
    38244286
    38254287procedure TfrmODMeds.UpdateStartExpires(const CurSchedule: string);
    38264288var
    3827   CompSch, ShowText, Duration, ASchedule: string;
     4289  CompSch, CompDose, LastSch, ShowText, Duration, ASchedule, TempSch, schType, Admin, tempAdmin: string;
    38284290  AdminTime:    TFMDateTime;
    3829   i, j, Interval, PrnPos: Integer;
    3830 begin
     4291  j, r, Interval, PrnPos, SchID: Integer;
     4292  EndCheck, rowCheck, DoseNow: boolean;
     4293begin
     4294  if not FInptDlg then Exit;
    38314295  if Length(CurSchedule)=0 then Exit;
    38324296  ASchedule := Trim(CurSchedule);
     4297  DoseNow := True;
     4298  if self.EvtID > 0 then DoseNow := false;
    38334299  if (Pos('^',ASchedule)>0) then
    38344300  begin
     
    38374303      Delete(ASchedule, PrnPos-1, 4);
    38384304  end;
     4305  if (FAdminTimeText = '') and (self.EvtID > 0) then FAdminTimeText := 'To Be Determined';
     4306  AdminTime := 0;
    38394307  ASchedule := Trim(ASchedule);
     4308  //AGP Change for CQ 9906
     4309  EndCheck := False;
     4310  lastSch := '';
    38404311  if self.tabDose.TabIndex = TI_COMPLEX then
    38414312    begin
    3842       CompSch := valFor(VAL_SCHEDULE,1);
    3843       if CompSch = '' then
    3844         begin
    3845           ASchedule := '';
    3846           AdminTime := -1;
    3847         end;
    3848       if CompSch <> '' then
    3849         begin
    3850           for i := 0 to self.cboXSchedule.Items.Count-1 do
    3851             begin
    3852               if (Piece(self.cboXSchedule.Items.Strings[i],U,1) = CompSch) and (Piece(self.cboXSchedule.Items.Strings[i],U,3)='P') then
     4313    tempSch := ASchedule;
     4314    ASchedule := '';
     4315    for r := 1 to self.grdDoses.RowCount-1 do
     4316      begin
     4317        CompSch := valFor(VAL_SCHEDULE,r);
     4318        CompDose := valFor(VAL_DOSAGE,r);
     4319        RowCheck := valFor(VAL_CHKXPRN,r)='1';
     4320        if (RowCheck = True) then
     4321          begin
     4322            if EndCheck = false then AdminTime := -1;
     4323            if FAdminTimeText = '' then self.grdDoses.cells[COL_ADMINTIME, r] := ''
     4324            else Self.grdDoses.Cells[COL_ADMINTIME, r] := FAdminTimeText;
     4325          end
     4326        else
     4327          begin
     4328            if CompSch <> '' then
     4329               begin
     4330                 //cboXSchedule.Items.IndexOfName(CompSch);
     4331                 //cboXSchedule.SelectByID(CompSch);
     4332                 SchID := -1;
     4333                 for j := 0 to cboXSchedule.Items.Count - 1 do
     4334                    begin
     4335                      if Piece(cboXSchedule.Items.Strings[j], U, 1) = CompSch then
     4336                        begin
     4337                          schID := j;
     4338                          break;
     4339                        end;
     4340                    end;
     4341                 //if cboXSchedule.ItemIndex > -1 then
     4342                 if SchID > -1 then
     4343                   begin
     4344                     //SchID := cboXSchedule.ItemIndex;
     4345                     if (Piece(self.cboXSchedule.Items.Strings[SchID],U,1) = CompSch) then
     4346                       begin
     4347                         SchType := Piece(self.cboXSchedule.Items.Strings[SchID],U,3);
     4348                         if (SchType = 'P') or (SchType = 'O') or (SchType = 'OC') then
     4349                             self.grdDoses.Cells[COL_ADMINTIME, r] := ''
     4350                         else if FAdminTimeText <> '' then self.grdDoses.Cells[COL_ADMINTIME, r] := FAdminTimeText
     4351                         else
     4352                           begin
     4353                             self.grdDoses.Cells[COL_ADMINTIME, r] := Piece(self.cboXSchedule.Items.Strings[SchID],U,4);
     4354                             if self.grdDoses.Cells[COL_ADMINTIME, r] = '' then self.grdDoses.Cells[COL_ADMINTIME, r] := 'Not Defined';
     4355
     4356                           end;
     4357                         if CompDose <> '' then
     4358                           begin
     4359                             lastSch := CompSch;
     4360                             if (EndCheck = False) and ((SchType = 'P') or (SchType = 'O')) then AdminTime := -1
     4361                             //else Aschedule := ';' + CompSch;
     4362                           end;
     4363                       end;
     4364                     
     4365                   end;
     4366               end;
     4367          end;
     4368        if ((valFor(VAL_SEQUENCE,r) = 'AND') or (valFor(VAL_SEQUENCE,r) = '')) and (AdminTime > -1) and (EndCheck = false) then
     4369          begin
     4370            //if (CompSch = '') and (LastSch <> '') and (Aschedule <> '') then CompSch := LastSch;
     4371            if (ASchedule <> '') and (CompSch <> '') and (RowCheck = False) then ASchedule := ASchedule + ';' + CompSch;
     4372            if (ASchedule = '') and (CompSch <> '') and (RowCheck = False) then ASchedule := ';' + CompSch;
     4373          end
     4374        else if ValFor(VAL_SEQUENCE, r) = 'THEN' then
     4375          begin
     4376           // if (CompSch = '') and (LastSch <> '') and (Aschedule <> '') then CompSch := LastSch;
     4377            if (ASchedule <> '') and (CompSch <> '') and (RowCheck = False) then ASchedule := ASchedule + ';' + CompSch;
     4378            if (ASchedule = '') and (CompSch <> '') and (RowCheck = False) then ASchedule := ';' + CompSch;
     4379            EndCheck := True;
     4380          end
     4381      end;
     4382    end;
     4383  if self.tabDose.TabIndex = TI_DOSE then
     4384    begin
     4385     if LeftStr(ASchedule, 1) = ';' then tempSch := Piece(ASchedule, ';', 2)
     4386     else tempSch := ASchedule;
     4387     if self.chkPRN.Checked = True then
     4388       begin
     4389         AdminTime := -1;
     4390         lblAdminSchSetText('');
     4391         if (cboSchedule.ItemIndex > -1) and (Piece(self.cboSchedule.Items.Strings[cboSchedule.itemIndex], U, 3) = 'O') then
     4392           DoseNow := false;
     4393       end
     4394     else begin
     4395         //cboSchedule.SelectByID(tempSch);
     4396         SchID := -1;
     4397         for j := 0 to cboSchedule.Items.Count - 1 do
     4398           begin
     4399             if Piece(cboSchedule.Items.Strings[j], U, 1) = tempSch then
    38534400                begin
    3854                   AdminTime := -1;
    3855                   Aschedule := '';
     4401                  schID := j;
     4402                  break;
    38564403                end;
    3857             end;
    3858         end;
    3859         if valFor(VAL_CHKXPRN,1)='1' then
    3860           begin
    3861             AdminTime := -1;
    3862             Aschedule := '';
    3863           end;
    3864       if (ASchedule <> '') and (CompSch <> '') then ASchedule := ';' + CompSch;
    3865     end;
    3866   if Length(ASchedule)>0 then
    3867       LoadAdminInfo(ASchedule, txtMed.Tag, ShowText, AdminTime, Duration);
    3868   //else Exit;
    3869   if (AdminTime > 0) and (self.tabDose.TabIndex = TI_DOSE) then
    3870     begin
    3871      if self.cboSchedule.ItemIndex = -1 then
    3872        begin
    3873          for j := 0 to self.cboSchedule.items.Count -1 do
     4404           end;
     4405         if schID > -1 then
    38744406           begin
    3875              if (Piece(self.cboSchedule.Items.Strings[j],U,1) = Piece(Aschedule,';',2)) and (Piece(self.cboSchedule.Items.Strings[j],U,3)='P') then
     4407             SchType := Piece(self.cboSchedule.Items.Strings[schID], U, 3);
     4408             if (SchType = 'P') or (SchType = 'OC') or (SchType = 'O') then
    38764409               begin
    3877                  AdminTime := -1;
    3878                  break;
     4410                 lblAdminSchSetText('');
     4411                 if (SchType = 'P') or (SchType = 'OC') or (SchType = 'O') then AdminTime := -1;
     4412                 if SchType = 'O' then DoseNow := false;
     4413               end
     4414             else
     4415               begin
     4416                 if FAdminTimeText <> '' then tempAdmin := 'Admin. Time: ' + FAdminTimeText
     4417                 else
     4418                   begin
     4419                      if Piece(self.cboSchedule.Items.Strings[schID], U, 4) <> '' then
     4420                          tempAdmin := 'Admin. Time: ' + Piece(self.cboSchedule.Items.Strings[schID], U, 4)
     4421                      else tempAdmin := 'Admin. Time: Not Defined';
     4422                   end;
     4423                  lblAdminSchSetText(tempAdmin);
     4424             (*    if FAdminTimeText <> '' then self.lblAdminSch.text := 'Admin. Time: ' + FAdminTimeText
     4425                 else
     4426                   begin
     4427                      if Piece(self.cboSchedule.Items.Strings[schID], U, 4) <> '' then
     4428                          self.lblAdminSch.text := 'Admin. Time: ' + Piece(self.cboSchedule.Items.Strings[schID], U, 4)
     4429                      else self.lblAdminSch.text := 'Admin. Time: Not Defined';
     4430                   end;   *)
     4431
    38794432               end;
    38804433           end;
    38814434       end;
    3882      if (self.cboSchedule.ItemIndex > -1) and (Piece(self.cboSchedule.Items.Strings[self.cboSchedule.ItemIndex],U,3)='P') then
    3883        AdminTime := -1;
    3884      if self.chkPRN.Checked = true then AdminTime := -1
    3885     end;
     4435    end;
     4436  if (Length(ASchedule)>0) and (AdminTime > -1) then
     4437     begin
     4438      if LeftStr(Aschedule, 1) <> ';' then ASchedule := ';'+ASchedule;
     4439      Admin := '';
     4440      if (self.lblAdminSch.visible = True) and (self.lblAdminSch.text <> '') and (self.tabDose.TabIndex = TI_DOSE) then
     4441        begin
     4442          //AGP Change Admin Time Wrap 27.73
     4443          //Admin := Copy(self.lblAdminSch.text,  14, (Length(self.lblAdminSch.text)-1));
     4444          Admin := lblAdminSchGetText;
     4445          if (Admin <> '') and (not (Admin[1] in ['0'..'9'])) then Admin := '';
     4446        end
     4447      else if self.tabDose.TabIndex = TI_COMPLEX then
     4448        begin
     4449          Admin := Self.grdDoses.Cells[COL_ADMINTIME, 1];
     4450          if (Admin <> '') and (not (Admin[1] in ['0'..'9'])) then Admin := '';
     4451        end;           
     4452      LoadAdminInfo(ASchedule, txtMed.Tag, ShowText, AdminTime, Duration, Admin);
     4453     end;
    38864454  if AdminTime > 0 then
    38874455  begin
     
    39064474  end
    39074475  else lblAdminTime.Caption := '';
     4476  if (lblAdminTime.Caption <> '') and (lblAdminTime.Visible = True) and (JAWSON = true) then lblAdminTime.TabStop := true
     4477  else lblAdminTime.TabStop := false;
     4478  if (lblAdminSch.text <> '') and (lblAdminSch.Visible = True) and (JAWSON = true) then lblAdminSch.TabStop := true
     4479  else lblAdminSch.TabStop := false;
     4480  DisplayDoseNow(DoseNow);
    39084481end;
    39094482
     
    39144487  else
    39154488    spnRefills.Max := CalcMaxRefills(CurDispDrug, CurSupply, txtMed.Tag, Responses.EventType = 'D');
    3916   if StrToIntDef(txtRefills.Text, 0) > spnRefills.Max then
     4489  if (StrToIntDef(txtRefills.Text, 0) > spnRefills.Max) then
    39174490  begin
    39184491    txtRefills.Text := IntToStr(spnRefills.Max);
     
    39404513  CurSupply, i, pNum, j: Integer;
    39414514  CurQuantity: double;
    3942   LackQtyInfo, SaveChanging, DispFirstDose: Boolean;
     4515  LackQtyInfo, SaveChanging: Boolean;
    39434516begin
    39444517  inherited;
     
    39474520  SaveChanging := Changing;
    39484521  Changing := TRUE;
    3949   DispFirstDose := FALSE;
    39504522  // don't allow Exit procedure so Changing gets reset appropriately
    39514523  CurUnits    := '';
     
    39974569  CurQuantity := StrToFloatDef(ValueOfResponse(FLD_QUANTITY), 0);
    39984570  CurSupply   := StrToIntDef(ValueOfResponse(FLD_SUPPLY)   ,0);
     4571  //CurRefill  := StrToIntDef(ValueOfResponse(FLD_REFILLS) , 0);
    39994572  if FInptDlg then
    40004573  begin
     
    40064579          lblAdminTime.Caption := '';
    40074580    end;
    4008     if CurSchedule <> FLastSchedule then UpdateStartExpires(CurSchedule);
    4009     if (ValueOf(FLD_SCHED_TYP) = 'O')
     4581   if (self.tabDose.TabIndex = TI_DOSE) and (CurSchedule <> FLastSchedule) then UpdateStartExpires(CurSchedule);
     4582   //AGP remove this code for CQ 11772
     4583  (*if (ValueOf(FLD_SCHED_TYP) = 'O')
    40104584      or (Responses.EventType in ['A','D','T','M','O'])
    40114585      or ((Length(cboSchedule.Text)>0) and (cboSchedule.ItemIndex < 0)) then
     
    40164590        chkDoseNow.Checked := False;
    40174591      end;
    4018       for i := 0 to cboSchedule.Items.Count-1 do
    4019         begin
    4020                   if Piece(cboSchedule.Items.Strings[i],U,1) = Uppercase(cboSchedule.Text) then
    4021             begin
    4022               DispFirstDose := True;
    4023               break;
    4024             end;
    4025         end;
    4026       if not DispFirstDose then
    4027         begin
    40284592          chkDoseNow.Visible := False;
    40294593          lblAdminTime.Visible := False;
    4030         end;
    40314594    end
    40324595    else
     
    40344597        chkDoseNow.Visible := TRUE;
    40354598        lblAdminTime.Visible := not chkDoseNow.Checked;
    4036       end;
     4599      end;  *)
    40374600    if Responses.EventType in ['A','D','T','M','O'] then lblAdminTime.Visible := False;
    40384601  end;
     
    40404603  begin
    40414604    CurSchedule := CurScheduleOut;
    4042     if (CurInstruct <> FLastInstruct) and (CurUnits <> U) //AGP Change 26.48 Do not update quantity and day supply if no matching dose on the server
     4605    if ((CurInstruct <> FLastInstruct) and (CurUnits <> U)) or ((IsClozapineOrder = true) and (CurDispDrug <> '') and (CurDispDrug <> U)) //AGP Change 26.48 Do not update quantity and day supply if no matching dose on the server
    40434606      then UpdateDefaultSupply(CurUnits, CurSchedule, CurDuration, CurDispDrug, CurSupply, CurQuantity,
    40444607                               LackQtyInfo);
     
    40494612    else
    40504613      UpdateSupplyQuantity(CurUnits, CurSchedule, CurDuration, CurDispDrug, CurSupply, CurQuantity);
    4051     if (CurDispDrug <> FLastDispDrug) then UpdateSC(CurDispDrug);
    4052     if (CurDispDrug <> FLastDispDrug) or (CurSupply <> FLastSupply) then
     4614   // if (CurDispDrug <> FLastDispDrug) then UpdateSC(CurDispDrug);
     4615    if ((CurDispDrug <> FLastDispDrug) or (CurSupply <> FLastSupply)) and ((CurDispDrug <> '') and (CurSupply > 0)) then
    40534616      UpdateRefills(CurDispDrug, CurSupply);
    40544617  end;
     
    40984661    then DisplayGroup := DisplayGroupByName('UD RX')
    40994662  else DisplayGroup := DisplayGroupByName('O RX');
     4663 (* if (Not FInptDlg) then
     4664    begin
     4665      if (ValidateDaySupplyandQuantity(strtoInt(txtSupply.Text), strtoInt(txtQuantity.text)) = false) then Exit
     4666      else ClearMaxData;
     4667    end;   *)
     4668  //if (Not FInptDlg) and (ValidateMaxQuantity(strtoInt(txtQuantity.Text)) = false) then Exit;
     4669 
     4670
    41004671  //timCheckChangesTimer(Self);
    41014672  DropLastSequence;
     
    41354706    if length(theSch)>0 then
    41364707    begin
    4137       if ( (ValueOf(FLD_SCHED_TYP) <> 'O') and (InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) )then
     4708      //if ( (ValueOf(FLD_SCHED_TYP) <> 'O') and (InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) )then
     4709      if InfoBox(T1+medNm+T+T2+theSch+T+T3+'NOW"'+T4, 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL then
    41384710      begin
    41394711        chkDoseNow.Checked := False;
     
    41524724  if (tabDose.TabIndex = TI_COMPLEX) and chkDoseNow.Checked  then
    41534725  begin
    4154     if ( (ValueOf(FLD_SCHED_TYP) <> 'O') and (InfoBox('Give Additional Dose Now is in addition to those listed in the table.' + CRLF +
     4726    if (InfoBox('Give Additional Dose Now is in addition to those listed in the table.' + CRLF +
    41554727                 'Please adjust the duration of the first row, if necessary.',
    4156                  'Give Additional Dose Now for Complex Order', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) ) then
     4728                 'Give Additional Dose Now for Complex Order', MB_OKCANCEL or MB_ICONWARNING) = IDCANCEL) then
    41574729    begin
    41584730      chkDoseNow.Checked := False;
     
    42834855  case Key of
    42844856//  VK_RETURN:   //moved to form key press
     4857  VK_RIGHT:
     4858    begin
     4859      if (not FInptDlg) and (self.grdDoses.Col = COL_DURATION) then
     4860        begin
     4861          self.grdDoses.Col := COL_SEQUENCE;
     4862          Key := 0;
     4863        end;
     4864    end;
     4865  VK_LEFT:
     4866    begin
     4867      if (not FInptDlg) and (self.grdDoses.Col = COL_SEQUENCE) then
     4868        begin
     4869          self.grdDoses.Col := COL_DURATION;
     4870          Key := 0;
     4871        end;
     4872    end;
    42854873  VK_ESCAPE:
    42864874    begin
     
    43774965procedure TfrmODMeds.FormKeyPress(Sender: TObject; var Key: Char);
    43784966begin
    4379   if (Key = #13) and (ActiveControl = grdDoses{pnlXSequence}) then
     4967 (* if (Key = #13) and (ActiveControl = grdDoses{pnlXSequence}) then
    43804968  begin
    43814969    ShowEditor(grdDoses.Col, grdDoses.Row, #0);
    43824970    Key := #0;  //Don't let the base class turn it into a forward tab!
    4383   end
    4384   else if (Key = #13) and (ActiveControl = txtMed) then
     4971  end *)
     4972  //else
     4973  if (Key = #13) and (ActiveControl = txtMed) then
    43854974    Key := #0;   //Don't let the base class turn it into a forward tab!
    43864975end;
     
    44064995end;
    44074996
    4408 procedure TfrmODMeds.pnlXSequenceEnter(Sender: TObject);
     4997procedure TfrmODMeds.pnlMessageEnter(Sender: TObject);
    44094998begin
    44104999  inherited;
     
    44135002end;
    44145003
    4415 procedure TfrmODMeds.pnlMessageEnter(Sender: TObject);
    4416 begin
    4417   inherited;
    4418   DisableDefaultButton(self);
    4419   DisableCancelButton(self);
    4420 end;
    4421 
    44225004procedure TfrmODMeds.pnlMessageExit(Sender: TObject);
    44235005begin
     
    44415023begin
    44425024  inherited;
    4443   ShowMessage('The patient instruction field may not be edited.');
     5025  ShowMsg('The patient instruction field may not be edited.');
    44445026  chkPtInstruct.SetFocus;
    44455027end;
     
    44485030var
    44495031  aftHeight: integer;
     5032  tempAdmin: string;
    44505033begin
    44515034  inherited;
     
    44565039  if pnlMessage.Visible then
    44575040    pnlMessage.Top := pnlFields.Top + pnlTop.Height + 8;
    4458 end;
    4459 
    4460 procedure TfrmODMeds.spnQuantityChangingEx(Sender: TObject;
    4461   var AllowChange: Boolean; NewValue: Smallint;
    4462   Direction: TUpDownDirection);
    4463 var
    4464   tempQuant: double;
    4465 begin
    4466   inherited;
    4467   if Direction = updUp then
    4468   begin
    4469     tempQuant := StrToFloatDef(txtQuantity.Text,0) + 1;
    4470     txtQuantity.Text := FloatToStr(tempQuant);
    4471   end else if Direction = updDown then
    4472   begin
    4473     tempQuant := StrToFloatDef(txtQuantity.Text,0) - 1 ;
    4474     if tempQuant < 0 then tempQuant := 0;
    4475     txtQuantity.Text := FloatToStr(tempQuant);
    4476   end;
    4477   spnQuantity.Tag := 1;
    4478   txtQuantity.Tag := 1;
     5041  tempAdmin := lblAdminSchGetText;
     5042  if tempAdmin <> '' then lblAdminSchSetText('Admin Time: ' + tempAdmin);
    44795043end;
    44805044
     
    44835047begin
    44845048  inherited;
    4485   ShowMessage('The patient instruction field may not be edited.');
     5049  ShowMsg('The patient instruction field may not be edited.');
    44865050  chkPtInstruct.SetFocus;
    44875051end;
     
    45535117    cboSchedule.ItemIndex := -1;
    45545118    cboSchedule.Text      := '';
    4555   end;
    4556   Result := aSchedule;
     5119  end
     5120  else
     5121    begin
     5122        Result := Piece(aSchedule,U,1);
     5123        NSSAdminTime := Piece(aschedule,u,2);
     5124        NSSScheduleType := Piece(aSchedule, U, 3);
     5125        if FAdminTimeText <> '' then NSSAdminTime := FAdminTimeText;
     5126    end;
    45575127end;
    45585128
     
    45795149                       (Assigned(lstQuick.Items[lstQuick.ItemIndex].Data)) and
    45805150                       (Integer(lstQuick.Selected.Data) > 0)) ;
     5151  if (btnSelect.Enabled) and (FOrderAction = ORDER_EDIT) then btnSelect.Enabled := false; 
    45815152  if (btnSelect.Enabled) and (FRemoveText) then
    45825153    txtMed.Text := '';
    45835154end;
    45845155
     5156
     5157procedure TfrmODMeds.DisplayDoseNow(Status: boolean);
     5158begin
     5159  if not FinptDlg then Status := False;
     5160  if Status = false then
     5161    begin
     5162      if (self.chkDoseNow.Visible = true) and (self.chkDoseNow.Checked = true) then self.chkDoseNow.Checked := false;
     5163      self.chkDoseNow.Visible := false;
     5164    end;
     5165  if status = true then self.chkDoseNow.Visible := true; 
     5166end;
    45855167
    45865168procedure TfrmODMeds.DispOrderMessage(const AMessage: string);
     
    46135195procedure TfrmODMeds.FormClose(Sender: TObject; var Action: TCloseAction);
    46145196begin
     5197  if FCloseCalled then Exit; //Temporary Hack: Close is called 2x for some reason & errors out
     5198  FCloseCalled := true;
    46155199  FResizedAlready := False;
    46165200  inherited;
     
    46265210    cboXSchedule.ItemIndex := -1;
    46275211    cboXSchedule.Text      := '';
    4628   end;
    4629   Result := aSchedule;
     5212  end
     5213  else
     5214    begin
     5215        Result := Piece(aSchedule,U,1);
     5216        NSSAdminTime := Piece(aschedule,u,2);
     5217        NSSScheduleType := Piece(ASchedule, U, 3);
     5218        if FAdminTimeText <> '' then NSSAdminTime := FAdminTimeText;
     5219    end;
    46305220end;
    46315221
     
    46605250procedure TfrmODMeds.FormShow(Sender: TObject);
    46615251begin
     5252  FCloseCalled := false;
    46625253  inherited;
    46635254  if ( (cboSchedule.Text = 'OTHER') and FNSSOther and FInptDlg )then
    46645255    PostMessage(Handle, UM_NSSOTHER, 0, 0);
     5256
     5257  //I was using btnSelect.Top for the following, but it gets moved around
     5258  Constraints.MinHeight := Constraints.MinHeight + ((Self.Height - cmdQuit.Top) * 2);
    46655259end;
    46665260
     
    46975291      ScheduleCombo.ItemIndex := tmpIndex;
    46985292  end;
    4699   if (Length(ScheduleCombo.Text) > 0) and (ScheduleCombo.ItemIndex < 0) and FInptDlg then
    4700   begin
    4701     FShowPnlXScheduleOk := False; //Added for CQ: 7370
    4702     Application.MessageBox('Please select a valid schedule from the list.'+#13+#13+
     5293    if (Length(ScheduleCombo.Text) > 0) and (ScheduleCombo.ItemIndex < 0) and FInptDlg then
     5294        begin
     5295          FShowPnlXScheduleOk := False; //Added for CQ: 7370
     5296          Application.MessageBox('Please select a valid schedule from the list.'+#13+#13+
    47035297                           'If you would like to create a Day-of-Week schedule please'+
    47045298                           ' select ''OTHER'' from the list.',
     
    47495343
    47505344// CQ: 7397 - Inpatient med orders with PRN cancel due to invalid schedule.
     5345function TfrmODMeds.GetCacheChunkIndex(idx: integer): integer;
     5346begin
     5347  Result := idx div MED_CACHE_CHUNK_SIZE;
     5348end;
     5349
    47515350function TfrmODMeds.GetSchedListIndex(SchedCombo: TORComboBox; pSchedule: String):integer;
    47525351var i: integer;
     
    47725371end;
    47735372
     5373procedure TfrmODMeds.cboXSequenceChange(Sender: TObject);
     5374var
     5375x: string;
     5376begin
     5377  inherited;
     5378 x := cboXSequence.Text;
     5379 if (x = 'then') and ((ValFor(COL_DURATION, ARow1) = '') or (ValFor(COL_DURATION, ARow1) = '0')) then
     5380     begin
     5381       InfoBox('A duration is required when using "Then" as a conjunction' + CRLF + CRLF+
     5382           'The patient will be instructed to take these doses consecutively, not concurrently.','Duration Warning',MB_OK);
     5383       x := '';
     5384     end;
     5385  cboXSequence.text := x;
     5386  cboXSequence.ItemIndex := cboXSequence.Items.IndexOf(x);
     5387  grdDoses.Cells[COL_SEQUENCE, cboXSequence.Tag] := Uppercase(x);
     5388  //AGP Start Expire add line
     5389  UpdateStartExpires(valFor(COL_SCHEDULE,self.grdDoses.Row));
     5390  ControlChange(Sender);
     5391end;
     5392
     5393procedure TfrmODMeds.cboXSequenceEnter(Sender: TObject);
     5394begin
     5395  inherited;
     5396  DisableDefaultButton(self);
     5397  DisableCancelButton(self);
     5398end;
     5399
     5400procedure TfrmODMeds.cboXSequenceExit(Sender: TObject);
     5401begin
     5402  inherited;
     5403  grdDoses.Cells[COL_SEQUENCE, cboXSequence.Tag] := Uppercase(cboXSequence.Text);
     5404  if ActiveControl = grdDoses then
     5405  begin
     5406    //This next condition seldom occurs, since entering the dosage on the last
     5407    // row adds another row
     5408    if grdDoses.Row = grdDoses.RowCount - 1 then
     5409      grdDoses.RowCount := grdDoses.RowCount + 1;
     5410  end;
     5411  cboXSequence.Tag := -1;
     5412  cboXSequence.Hide;
     5413  RestoreDefaultButton;
     5414  RestoreCancelButton;
     5415  if (pnlMessage.Visible) and (memMessage.TabStop) then
     5416  begin
     5417    pnlMessage.Parent := grdDoses.Parent;
     5418    pnlMessage.TabOrder := grdDoses.TabOrder;
     5419    ActiveControl := memMessage;
     5420  end
     5421  else if grdDoses.Showing then
     5422    ActiveControl := grdDoses
     5423  else
     5424    ActiveControl := cboDosage;
     5425  //AGP Start Expire commented out line
     5426  //UpdateStartExpires(valFor(COL_SCHEDULE,self.grdDoses.Row));
     5427end;
     5428
     5429procedure TfrmODMeds.cboXSequence1Exit(Sender: TObject);
     5430begin
     5431  inherited;
     5432  cboxSequence.Hide;
     5433end;
     5434
    47745435procedure TfrmODMeds.cboDosageKeyUp(Sender: TObject; var Key: Word;
    47755436  Shift: TShiftState);
     
    47785439  //Fix for CQ: 7545
    47795440  if cboDosage.ItemIndex > -1 then
    4780     cboDosageClick(Sender);
     5441    cboDosageClick(Sender)
     5442  else
     5443    UpdateRelated;
    47815444end;
    47825445
     
    47875450  //Fix for CQ: 7545
    47885451  if cboXDosage.ItemIndex > -1 then
    4789     cboXDosageClick(Sender);
     5452    cboXDosageClick(Sender)
     5453  else
     5454    begin
     5455      grdDoses.Cells[COL_DOSAGE, cboXDosage.Tag] := cboXDosage.Text;
     5456      UpdateRelated;
     5457    end;
    47905458end;
    47915459
     
    48005468  inherited;
    48015469   self.txtQuantity.SelectAll;
     5470end;
     5471
     5472procedure TfrmODMeds.txtRefillsChange(Sender: TObject);
     5473begin
     5474  inherited;
     5475  ControlChange(sender);
    48025476end;
    48035477
     
    48305504begin
    48315505  inherited;
    4832   //agp Change CQ 10719 
     5506  //agp Change CQ 10719
    48335507   self.chkXPRN.OnClick(self.chkXPRN);
    48345508end;
    48355509
     5510
    48365511end.
Note: See TracChangeset for help on using the changeset viewer.