Procedure

TfrmODMeds.UpdateSupplyQuantity

Module

fODMeds

Last Modified

7/15/2014 3:26:42 PM

Comments

Add CURInstrcut to this procedure. This address a problem with an user starting with a free-text dosage and changing
to another free-text dose and the quantity value not updating.

Visibility

Private

Owner

TfrmODMeds

Declaration

procedure UpdateSupplyQuantity(const CurUnits, CurSchedule, CurDuration, CurDispDrug, CurInstruct: string;
  var CurSupply: Integer; var CurQuantity: double);

Calls Hierarchy


TfrmODMeds.UpdateSupplyQuantity
 ├TfrmODMeds.DurationToDays
 │ └TfrmODMeds.ValFor
 ├DaysToQty
 └QtyToDays

Called-By Hierarchy


    TfrmODMeds.UpdateSupplyQuantity
  TfrmODMeds.timCheckChangesTimer┘ 
       TfrmODMeds.UpdateRelated┘   
       TfrmODMeds.SetupDialog┤     
    TfrmODMeds.btnSelectClick┤     
    TfrmODMeds.UMDelayClick┘ │     
    TfrmODMeds.cboDosageClick┤     
  TfrmODMeds.cboDosageKeyUp┘ │     
   TfrmODMeds.cboDosageChange┤     
     TfrmODMeds.cboDosageExit┤     
  TfrmODMeds.cboScheduleClick┤     
  TfrmODMeds.cmdAcceptClick┤ │     
     TfrmODMeds.chkPRNClick┤ │     
     TfrmODMeds.txtNSSClick┤ │     
TfrmODMeds.cboScheduleEnter┤ │     
TfrmODMeds.UMShowNSSBuilder┘ │     
 TfrmODMeds.cboScheduleChange┤     
   TfrmODMeds.txtSupplyChange┤     
 TfrmODMeds.txtQuantityChange┤     
      TfrmODMeds.grdDosesExit┤     
  TfrmODMeds.cboXDosageChange┤     
   TfrmODMeds.cboXDosageClick┤     
  TfrmODMeds.cboXDosageExit┤ │     
 TfrmODMeds.cboXDosageKeyUp┘ │     
    TfrmODMeds.cboXDosageExit┤     
TfrmODMeds.cboXScheduleChange┤     
     TfrmODMeds.txtNSSClick┘ │     
 TfrmODMeds.cboXScheduleClick┤     
    TfrmODMeds.chkXPRNClick┤ │     
TfrmODMeds.pnlXScheduleExit┘ │     
  TfrmODMeds.pnlXScheduleExit┤     
TfrmODMeds.txtXDurationChange┤     
TfrmODMeds.popDurationClick┘ │     
  TfrmODMeds.pnlXDurationExit┤     
       TfrmODMeds.chkPRNClick┤     
   TfrmODMeds.cboScheduleExit┤     
    TfrmODMeds.cboDosageKeyUp┤     
   TfrmODMeds.cboXDosageKeyUp┘     

Calls

Name Declaration Comments
DaysToQty function DaysToQty(DaysSupply: Integer; const UnitsPerDose, Schedule, Duration, Drug: string): Integer; -
TfrmODMeds.DurationToDays function DurationToDays: Integer; -
QtyToDays function QtyToDays(Quantity: Double; const UnitsPerDose, Schedule, Duration, Drug: string): Integer; -

Called-By

Name Declaration Comments
TfrmODMeds.timCheckChangesTimer procedure timCheckChangesTimer(Sender: TObject); -


Source

4387  procedure TfrmODMeds.UpdateSupplyQuantity(const CurUnits, CurSchedule, CurDuration, CurDispDrug, CurInstruct: string;
4388    var CurSupply: Integer; var CurQuantity: double);
4389  const
4390    UPD_NONE     = 0;
4391    UPD_QUANTITY = 1;
4392    UPD_SUPPLY   = 2;
4393    UPD_COMPLEX  = 3;
4394    UPD_BOTH     = 4;
4395  var
4396    UpdateControl, NewSupply: Integer;
4397    ADrug: string;
4398    SaveChanging: Boolean;
4399    tmpQuantity: double;
4400  begin
4401    if (tabDose.TabIndex = TI_COMPLEX) and (txtSupply.Tag = 0) and (txtQuantity.Tag = 0) then
4402    begin
4403      // set days supply based on durations
4404      NewSupply := DurationToDays;
4405      if NewSupply > 0 then
4406      begin
4407        SaveChanging := Changing;
4408        Changing := TRUE;
4409        txtSupply.Text := IntToStr(NewSupply);
4410        CurSupply := NewSupply;
4411        Changing := SaveChanging;
4412      end;
4413    end;
4414    // exit if not enough fields to calculation supply or quantity
4415    if (CurQuantity = 0) and (CurSupply = 0) then Exit;
4416    // exit if nothing has changed
4417    if (CurUnits    = FLastUnits)    and
4418       (CurSchedule = FLastSchedule) and
4419       (CurDuration = FLastDuration) and
4420       (CurQuantity = FLastQuantity) and
4421       (CurSupply   = FLastSupply)   and
4422       (CurInstruct = FLastInstruct) then Exit;
4423    // exit if supply & quantity have both been directly edited
4424    if (txtSupply.Tag > 0) and (txtQuantity.Tag > 0) then Exit;
4425    // figure out which control to update
4426    UpdateControl := UPD_NONE;
4427  
4428    if (CurSupply <> FLastSupply) and (txtQuantity.Tag = 0) and (CurQuantity <> FLastQuantity) and (txtSupply.Tag = 0) and Changing then UpdateControl := UPD_BOTH
4429    else if (CurSupply <> FLastSupply) and (txtQuantity.Tag = 0) then UpdateControl := UPD_QUANTITY
4430    else if (CurQuantity <> FLastQuantity) and (txtSupply.Tag = 0) then UpdateControl := UPD_SUPPLY;
4431    if (UpdateControl = UPD_NONE) and (((CurUnits <> FLastUnits) or (CurInstruct <> FLastInstruct)) or (CurSchedule <> FLastSchedule)) then
4432    begin
4433      if txtQuantity.Tag = 0    then UpdateControl := UPD_QUANTITY
4434      else if txtSupply.Tag = 0 then UpdateControl := UPD_SUPPLY;
4435    end;
4436    ADrug := Piece(CurDispDrug, U, 1);  // just use the first dispense drug (for clozapine chk)
4437    case UpdateControl of
4438    UPD_QUANTITY : begin
4439                     if FIsQuickOrder and (CurQuantity > 0) and FQOInitial then
4440                     begin
4441                       txtQuantity.Text := FloatToStr(CurQuantity);
4442                       Exit;
4443                     end;
4444                     CurQuantity := DaysToQty(CurSupply,   CurUnits, CurSchedule, CurDuration, ADrug);
4445                     if (CurQuantity >= 0) then
4446                       txtQuantity.Text := FloatToStr(CurQuantity);
4447                   end;
4448    UPD_SUPPLY   : begin
4449                     CurSupply   := QtyToDays(CurQuantity, CurUnits, CurSchedule, CurDuration, ADrug);
4450                     if CurSupply > 0   then txtSupply.Text     := IntToStr(CurSupply);
4451                   end;
4452    UPD_BOTH     : begin
4453                     txtSupply.Text     := IntToStr(CurSupply);
4454                     spnSupply.Position := StrToIntDef(txtSupply.Text, 0);
4455                     tmpQuantity := DaysToQty(CurSupply,   CurUnits, CurSchedule, CurDuration, ADrug);
4456                     if FIsQuickOrder and (CurQuantity > 0) and FQOInitial then
4457                        begin
4458                          txtQuantity.Text := FloatToStr(CurQuantity);
4459                          Exit;
4460                        end;
4461                    (* if FIsQuickOrder and (CurQuantity > 0) and (tmpQuantity = 0) and FQOInitial then
4462                     begin
4463                       txtQuantity.Text := FloatToStr(CurQuantity);
4464                       Exit;
4465                     end;  *)
4466                     //CurQuantity := DaysToQty(CurSupply,   CurUnits, CurSchedule, CurDuration, ADrug);
4467                     CurQuantity := tmpQuantity;
4468                     if CurQuantity >= 0 then
4469                       txtQuantity.Text := FloatToStr(CurQuantity);
4470                   end;
4471    end;
4472    if UpdateControl > UPD_NONE then FUpdated := True;
4473  end;