Function

TfrmODMeds.DurationToDays

Module

fODMeds

Last Modified

7/15/2014 3:26:42 PM

Comments

Procedure TfrmODMeds.DurationToDays;
var
  i, DoseHours, TotalHours: Integer;
  AllRows: Boolean;
  Days: Extended;
  x: string;
begin
  Exit;  // don't try to figure out days supply from duration for now
  if txtSupply.Tag = 1 then Exit;
  AllRows := True;
  with grdDoses do for i := 1 to Pred(RowCount) do
    if (Length(ValFor(COL_DOSAGE, i)) > 0) and (Length(ValFor(VAL_DURATION, i)) = 0)
      then AllRows := False;
  if not AllRows then Exit;
  Changing := True;
  TotalHours := 0;
  with grdDoses do for i := 1 to Pred(RowCount) do
    if Length(ValFor(COL_DOSAGE, i)) > 0 then
    begin
      x := ValFor(VAL_DURATION, i);
      if Piece(x, U, 2) = 'D'
        then DoseHours := ExtractInteger(x) * 24
        else DoseHours := ExtractInteger(x);
      TotalHours := TotalHours + DoseHours;
    end;
  Days := TotalHours / 24;
  if Days > Int(Days) then Days := Days + 1;
  txtSupply.Text := IntToStr(Trunc(Days));
  //timDayQty.Tag := TIMER_FROM_DAYS;
  //timDayQtyTimer(Self);
  Changing := False;
end;

Visibility

Private

Owner

TfrmODMeds

Declaration

function DurationToDays: Integer;

Calls Hierarchy


TfrmODMeds.DurationToDays
 └TfrmODMeds.ValFor

Called-By Hierarchy


            TfrmODMeds.DurationToDays
    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
TfrmODMeds.ValFor function ValFor(FieldID, ARow: Integer): string; -

Called-By

Name Declaration Comments
TfrmODMeds.UpdateSupplyQuantity procedure UpdateSupplyQuantity(const CurUnits, CurSchedule, CurDuration, CurDispDrug, CurInstruct: string; var CurSupply: Integer; var CurQuantity: double); -


Source

3303  function TfrmODMeds.DurationToDays: Integer;
3304  var
3305    i, DoseMinutes, AndMinutes, TotalMinutes: Integer;
3306    AllRows: Boolean;
3307    Days: Extended;
3308    x: string;
3309  begin
3310    Result := 0;
3311    // make sure a duration exists for all rows with a dose
3312    AllRows := True;
3313    with grdDoses do for i := 1 to Pred(RowCount) do
3314      if (Length(ValFor(COL_DOSAGE, i)) > 0) and (Length(ValFor(VAL_DURATION, i)) = 0)
3315        then AllRows := False;
3316    if not AllRows then Exit;
3317  
3318    AndMinutes := 0;
3319    TotalMinutes := 0;
3320    with grdDoses do for i := 1 to Pred(RowCount) do
3321      if Length(ValFor(COL_DOSAGE, i)) > 0 then
3322      begin
3323        x := ValFor(VAL_DURATION, i);
3324        DoseMinutes := 0;
3325        if Piece(x, ' ', 2) = 'MONTHS'  then DoseMinutes := ExtractInteger(x) * 43200;
3326        if Piece(x, ' ', 2) = 'WEEKS'   then DoseMinutes := ExtractInteger(x) * 10080;
3327        if Pos('DAY',Piece(x, ' ', 2))>0    then DoseMinutes := ExtractInteger(x) * 1440;
3328        if Piece(x, ' ', 2) = 'HOURS'   then DoseMinutes := ExtractInteger(x) * 60;
3329        if Piece(x, ' ', 2) = 'MINUTES' then DoseMinutes := ExtractInteger(x);
3330        // Determine how TotalMinutes should be calculated based on conjunction
3331        if ValFor(COL_SEQUENCE, i) <> 'AND' then  // 'THEN', 'EXCEPT', or ''
3332        begin
3333          if AndMinutes = 0 then TotalMinutes := TotalMinutes + DoseMinutes;
3334          if AndMinutes > 0 then
3335          begin
3336            if AndMinutes < DoseMinutes then AndMinutes := DoseMinutes;
3337            TotalMinutes := TotalMinutes + AndMinutes;
3338            AndMinutes := 0;
3339          end;
3340          if ValFor(COL_SEQUENCE, i) = 'EXCEPT' then break;  //quit out of For Loop to stop counting TotalMinutes
3341        end;
3342        if (ValFor(COL_SEQUENCE, i) = 'AND') then
3343          if AndMinutes < DoseMinutes then AndMinutes := DoseMinutes;
3344      end;
3345    if AndMinutes > 0 then TotalMinutes := TotalMinutes + AndMinutes;
3346  
3347    Days := TotalMinutes / 1440;
3348    if Days > Int(Days) then Days := Days + 1;
3349    Result := Trunc(Days);
3350  end;