Procedure

CheckLateTray

Module

fODDietLT

Last Modified

7/15/2014 3:26:42 PM

Scope

Interfaced

Declaration

procedure CheckLateTray(const StartTime: string; var LateTrayFields: TLateTrayFields; IsOutpatient: boolean; AMeal: char = #0);

Calls Hierarchy


CheckLateTray
 ├StrToFMDateTime
 ├FMToday
 │ └FMNow
 ├FMNow
 ├LoadDietParams
 ├SetAvailTimes
 │ └AMPMToFMTime
 └TfrmBase508Form.Create
   ├TfrmBase508Form.UpdateAccessibilityActions
   ├UnfocusableControlEnter
   └AdjustControls
     ├TfrmBase508Form.ModifyUnfocusableControl
     └..(rec)..

Called-By Hierarchy


                                               CheckLateTray
                                             LateTrayCheck┘ 
                               TfrmODBase.cmdAcceptClick┤   
                                   ActivateOrderDialog┘ │   
                           TfrmRemDlg.btnFinishClick┤   │   
           TfrmConsults.mnuActNewConsultRequestClick┤   │   
                   TfrmConsults.cmdNewConsultClick┘ │   │   
                TfrmConsults.mnuActNewProcedureClick┤   │   
                      TfrmConsults.cmdNewProcClick┘ │   │   
                                        ChangeOrders┤   │   
                      TfrmOrders.mnuActChangeClick┤ │   │   
                        TfrmMeds.mnuActChangeClick┘ │   │   
                                     ChangeOrdersEvt┤   │   
                                          CopyOrders┤   │   
                        TfrmOrders.mnuActCopyClick┤ │   │   
                          TfrmMeds.mnuActCopyClick┤ │   │   
                           TfrmODActive.btnOKClick┘ │   │   
                                      TransferOrders┤   │   
                        TfrmOrders.mnuActCopyClick┤ │   │   
                          TfrmMeds.mnuActCopyClick┤ │   │   
                           TfrmODActive.btnOKClick┘ │   │   
                            TfrmOrders.lstWriteClick┤   │   
               TfrmOrders.PlaceOrderForDefaultDialog┤   │   
                  TfrmOrders.DisplayDefaultDlgList┤ │   │   
                       TfrmOrders.ResetOrderPage┘ │ │   │   
               TfrmOrders.btnDelayedOrderClick┘   │ │   │   
                                 DisplayEvntDialog┤ │   │   
                             SetDelayEventForMed┘ │ │   │   
                      TfrmMeds.mnuActCopyClick┘   │ │   │   
                                 DisplayEvntDialog┤ │   │   
                                  SetViewForCopy┘ │ │   │   
                    TfrmOrders.mnuActCopyClick┘   │ │   │   
                                 DisplayEvntDialog┘ │   │   
                                ExecuteChangeEvt┘   │   │   
                 TfrmOrders.mnuActChgEvntClick┘     │   │   
                             TfrmMeds.mnuActNewClick┤   │   
                           TfrmOMNavA.ActivateDialog┤   │   
                         TfrmOMNavA.grdMenuKeyDown┤ │   │   
                         TfrmOMNavA.grdMenuMouseUp┘ │   │   
                                TfrmOMSet.DoNextItem┘   │   
                              TfrmOMSet.InsertList┤     │   
                               ActivateOrderList┘ │     │   
                     TfrmRemDlg.btnFinishClick┤   │     │   
                             ActivateOrderHTML┤   │     │   
                    TfrmOrders.lstWriteClick┤ │   │     │   
    TfrmOrders.PlaceOrderForDefaultDialog...┘ │   │     │   
                              ActivateOrderSet┤   │     │   
                   TfrmRemDlg.btnFinishClick┤ │   │     │   
TfrmConsults.mnuActNewConsultRequestClick...┤ │   │     │   
     TfrmConsults.mnuActNewProcedureClick...┤ │   │     │   
                    TfrmOrders.lstWriteClick┤ │   │     │   
    TfrmOrders.PlaceOrderForDefaultDialog...┤ │   │     │   
                     TfrmMeds.mnuActNewClick┤ │   │     │   
                TfrmOMNavA.ActivateDialog...┤ │   │     │   
                     TfrmOMSet.DoNextItem...┘ │   │     │   
                       TfrmOMNavA.DoSelectList┘   │     │   
                     TfrmOMNavA.grdMenuKeyUp┤     │     │   
                   TfrmOMNavA.grdMenuMouseUp┘     │     │   
                                        SkipToNext┤     │   
                         TfrmOMSet.DoNextItem...┘ │     │   
                            TfrmOMSet.UMDelayEvent┘     │   
                               TfrmODDiet.cmdAcceptClick┘   
                            TfrmODDiet.nbkDietChanging┘     

Calls

Name Declaration Comments
TfrmBase508Form.Create constructor Create(AOwner: TComponent); override; -
FMNow function FMNow: TFMDateTime; -
FMToday function FMToday: TFMDateTime; -
LoadDietParams procedure LoadDietParams(var DietParams: TDietParams; ALocation: string); -
SetAvailTimes procedure SetAvailTimes(ATime: Extended; var ACount: Integer; var TimeList: string); -
StrToFMDateTime function StrToFMDateTime(const AString: string): TFMDateTime; -

Called-By

Name Declaration Comments
LateTrayCheck procedure LateTrayCheck(SomeResponses: TResponses; EventId: integer; IsOutpatient: boolean; var LateTrayFields: TLateTrayFields); -


Source

51    procedure CheckLateTray(const StartTime: string; var LateTrayFields: TLateTrayFields; IsOutpatient: boolean; AMeal: char = #0);
52    var
53      frmODDietLT: TfrmODDietLT;
54      DietParams: TDietParams;
55      FMTime: TFMDateTime;
56      TimePart: Extended;
57      Meal: Char;
58      AvailTimes,ALocation: string;
59      TimeCount: Integer;
60    
61      function AMPMToFMTime(const x: string): Extended;
62      var
63        IntTime: Integer;
64      begin
65        Result := 0;
66        if Pos(':', x) = 0 then Exit;
67        IntTime := StrToIntDef(Piece(x, ':', 1) + Copy(Piece(x, ':', 2), 1, 2), 0);
68        if (Pos('P', x) > 0) and (IntTime < 1200) then IntTime := IntTime + 1200;
69        if (Pos('A', x) > 0) and (IntTime > 1200) then IntTime := IntTime - 1200;
70        Result := IntTime / 10000;
71      end;
72    
73      function FMTimeToAMPM(x: Extended): string;
74      var
75        TimePart: extended;
76        AMPMTime, Suffix: string;
77      begin
78        TimePart := Frac(x);
79        if TimePart > 0.1159 then
80        begin
81          if TimePart > 0.1259 then x := x - 0.12;
82          Suffix := 'P'
83        end
84        else Suffix := 'A';
85        AMPMTime := FormatFMDateTime('hh:nn', x);
86        Result := AMPMTime + Suffix;
87      end;
88    
89      procedure SetAvailTimes(ATime: Extended; var ACount: Integer; var TimeList: string);
90      var
91        i: Integer;
92        ReturnList: string;
93      begin
94        ACount := 0;
95        ReturnList := '';
96        for i := 1 to 3 do
97          if AMPMToFMTime(Piece(TimeList, U, i)) > ATime then
98          begin
99            if Length(ReturnList) > 0 then ReturnList := ReturnList + U;
100           ReturnList := ReturnList + Piece(TimeList, U, i);
101           Inc(ACount);
102         end;
103       TimeList := ReturnList;
104     end;
105   
106   begin
107     // initialize LateTrayFields
108     LateTrayFields.LateMeal := #0;
109     LateTrayFields.LateTime := '';
110     LateTrayFields.IsBagged := False;
111     // make sure the start time is today and not in the future
112     FMTime := StrToFMDateTime(StartTime);
113     if FMTime < 0 then Exit;
114     if Int(FMTime) <> FMToday then Exit;
115     TimePart := Frac(FMTime);
116     if TimePart = 0 then TimePart := Frac(FMNow);
117     if TimePart > Frac(FMNow) then Exit;
118     Meal := #0;
119     ALocation := IntToStr(Encounter.Location);
120     LoadDietParams(DietParams,ALocation);
121     // check to see if falling within the alarm range of a meal
122     if not IsOutpatient then
123     begin
124       if (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 1), 0) / 10000)) and
125          (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 2), 0) / 10000)) then Meal := 'B';
126       if (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 3), 0) / 10000)) and
127          (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 4), 0) / 10000)) then Meal := 'N';
128       if (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 5), 0) / 10000)) and
129          (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 6), 0) / 10000)) then Meal := 'E';
130       if Meal = #0 then Exit;
131     end
132     else  // for outpatients
133     begin
134   (*  From Rich Knoepfle, NFS developer
135   If they order a breakfast and it is after the LATE BREAKFAST ALARM END, I don't allow them to do it.  (For special meals I don't allow them to order something for the following day).
136   If it's before the LATE BREAKFAST ALARM BEGIN than I accept the order.
137   If it's between the LATE BREAKFAST ALARM BEGIN and ALARM END then I ask if they want to order a Late breakfast tray.
138   *)
139       Meal := AMeal;
140       case AMeal of
141         'B':  if (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 1), 0) / 10000)) or
142                  (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 2), 0) / 10000)) then Meal := #0;
143         'N':  if (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 3), 0) / 10000)) or
144                  (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 4), 0) / 10000)) then Meal := #0;
145         'E':  if (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 5), 0) / 10000)) or
146                  (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 6), 0) / 10000)) then Meal := #0;
147       end;
148       if Meal = #0 then exit;
149     end;
150   
151     // get the available late times for this meal
152     case Meal of
153     'B': AvailTimes := Pieces(DietParams.BTimes, U, 4, 6);
154     'E': AvailTimes := Pieces(DietParams.ETimes, U, 4, 6);
155     'N': AvailTimes := Pieces(DietParams.NTimes, U, 4, 6);
156     end;
157     SetAvailTimes(TimePart, TimeCount, AvailTimes);
158     if TimeCount = 0 then Exit;
159   
160     // setup form to get the selected late tray
161     frmODDietLT := TfrmODDietLT.Create(Application);
162     try
163       ResizeFormToFont(TForm(frmODDietLT));
164       with frmODDietLT do
165       begin
166         FOutpatient := IsOutpatient;
167         if Length(Piece(AvailTimes, U, 1)) > 0 then radLT1.Caption := Piece(AvailTimes, U, 1);
168         if Length(Piece(AvailTimes, U, 2)) > 0 then radLT2.Caption := Piece(AvailTimes, U, 2);
169         if Length(Piece(AvailTimes, U, 3)) > 0 then radLT3.Caption := Piece(AvailTimes, U, 3);
170         radLT1.Visible := Length(radLT1.Caption) > 0;
171         radLT2.Visible := Length(radLT2.Caption) > 0;
172         radLT3.Visible := Length(radLT3.Caption) > 0;
173         radLT1.Checked := TimeCount = 1;
174         chkBagged.Visible := DietParams.Bagged;
175         with lblMealCutOff do case Meal of
176         'B': Caption := 'You have missed the breakfast cut-off.';
177         'E': Caption := 'You have missed the evening cut-off.';
178         'N': Caption := 'You have missed the noon cut-off.';
179         end;
180         // display the form
181         ShowModal;
182         if YesPressed then
183         begin
184           with radLT1 do if Checked then LateTrayFields.LateTime := Caption;
185           with radLT2 do if Checked then LateTrayFields.LateTime := Caption;
186           with radLT3 do if Checked then LateTrayFields.LateTime := Caption;
187           LateTrayFields.LateMeal := Meal;
188           LateTrayFields.IsBagged := chkBagged.Checked;
189         end;
190       end; {with frmODDietLT}
191     finally
192       frmODDietLT.Release;
193     end;
194   end;