source: cprs/branches/foia-cprs/CPRS-Chart/Orders/fODDietLT.pas@ 459

Last change on this file since 459 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

File size: 6.9 KB
Line 
1unit fODDietLT;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 fAutoSz, ExtCtrls, StdCtrls, ORFn;
8
9type
10 TfrmODDietLT = class(TfrmAutoSz)
11 lblMealCutoff: TStaticText;
12 Label2: TStaticText;
13 GroupBox1: TGroupBox;
14 cmdYes: TButton;
15 cmdNo: TButton;
16 radLT1: TRadioButton;
17 radLT2: TRadioButton;
18 radLT3: TRadioButton;
19 chkBagged: TCheckBox;
20 Bevel1: TBevel;
21 procedure cmdYesClick(Sender: TObject);
22 procedure cmdNoClick(Sender: TObject);
23 procedure FormCreate(Sender: TObject);
24 private
25 FOutpatient: boolean;
26 YesPressed: Boolean;
27 public
28 { Public declarations }
29 end;
30
31 TLateTrayFields = record
32 LateMeal: Char;
33 LateTime: string;
34 IsBagged: Boolean;
35 end;
36
37procedure CheckLateTray(const StartTime: string; var LateTrayFields: TLateTrayFields; IsOutpatient: boolean; AMeal: char = #0);
38
39implementation
40
41{$R *.DFM}
42
43uses rCore, uCore, rODDiet, uConst, rOrders;
44
45const
46 TX_MEAL_REQ = 'A meal time must be selected.';
47 TC_MEAL_REQ = 'No Meal Time Selected';
48
49procedure CheckLateTray(const StartTime: string; var LateTrayFields: TLateTrayFields; IsOutpatient: boolean; AMeal: char = #0);
50var
51 frmODDietLT: TfrmODDietLT;
52 DietParams: TDietParams;
53 FMTime: TFMDateTime;
54 TimePart: Extended;
55 Meal: Char;
56 AvailTimes,ALocation: string;
57 TimeCount: Integer;
58
59 function AMPMToFMTime(const x: string): Extended;
60 var
61 IntTime: Integer;
62 begin
63 Result := 0;
64 if Pos(':', x) = 0 then Exit;
65 IntTime := StrToIntDef(Piece(x, ':', 1) + Copy(Piece(x, ':', 2), 1, 2), 0);
66 if (Pos('P', x) > 0) and (IntTime < 1200) then IntTime := IntTime + 1200;
67 if (Pos('A', x) > 0) and (IntTime > 1200) then IntTime := IntTime - 1200;
68 Result := IntTime / 10000;
69 end;
70
71 function FMTimeToAMPM(x: Extended): string;
72 var
73 TimePart: extended;
74 AMPMTime, Suffix: string;
75 begin
76 TimePart := Frac(x);
77 if TimePart > 0.12 then
78 begin
79 x := x - 0.12;
80 Suffix := 'P'
81 end
82 else Suffix := 'A';
83 AMPMTime := FormatFMDateTime('hh:nn', x);
84 Result := AMPMTime + Suffix;
85 end;
86
87 procedure SetAvailTimes(ATime: Extended; var ACount: Integer; var TimeList: string);
88 var
89 i: Integer;
90 ReturnList: string;
91 begin
92 ACount := 0;
93 ReturnList := '';
94 for i := 1 to 3 do
95 if AMPMToFMTime(Piece(TimeList, U, i)) > ATime then
96 begin
97 if Length(ReturnList) > 0 then ReturnList := ReturnList + U;
98 ReturnList := ReturnList + Piece(TimeList, U, i);
99 Inc(ACount);
100 end;
101 TimeList := ReturnList;
102 end;
103
104begin
105 // initialize LateTrayFields
106 LateTrayFields.LateMeal := #0;
107 LateTrayFields.LateTime := '';
108 LateTrayFields.IsBagged := False;
109 // make sure the start time is today and not in the future
110 FMTime := StrToFMDateTime(StartTime);
111 if FMTime < 0 then Exit;
112 if Int(FMTime) <> FMToday then Exit;
113 TimePart := Frac(FMTime);
114 if TimePart = 0 then TimePart := Frac(FMNow);
115 if TimePart > Frac(FMNow) then Exit;
116 Meal := #0;
117 ALocation := IntToStr(Encounter.Location);
118 LoadDietParams(DietParams,ALocation);
119 // check to see if falling within the alarm range of a meal
120 if not IsOutpatient then
121 begin
122 if (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 1), 0) / 10000)) and
123 (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 2), 0) / 10000)) then Meal := 'B';
124 if (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 3), 0) / 10000)) and
125 (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 4), 0) / 10000)) then Meal := 'N';
126 if (TimePart > (StrToIntDef(Piece(DietParams.Alarms, U, 5), 0) / 10000)) and
127 (TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 6), 0) / 10000)) then Meal := 'E';
128 if Meal = #0 then Exit;
129 // get the available late times for this meal
130 case Meal of
131 'B': AvailTimes := Pieces(DietParams.BTimes, U, 4, 6);
132 'E': AvailTimes := Pieces(DietParams.ETimes, U, 4, 6);
133 'N': AvailTimes := Pieces(DietParams.NTimes, U, 4, 6);
134 end;
135 SetAvailTimes(TimePart, TimeCount, AvailTimes);
136 if TimeCount = 0 then Exit;
137 end
138 else // for outpatients
139 begin
140 Meal := AMeal;
141 case AMeal of
142 'B': if TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 1), 0) / 10000) then Meal := #0;
143 'N': if TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 3), 0) / 10000) then Meal := #0;
144 'E': if TimePart < (StrToIntDef(Piece(DietParams.Alarms, U, 5), 0) / 10000) then Meal := #0;
145 end;
146 if Meal = #0 then exit;
147 end;
148 // setup form to get the selected late tray
149 frmODDietLT := TfrmODDietLT.Create(Application);
150 try
151 ResizeFormToFont(TForm(frmODDietLT));
152 with frmODDietLT do
153 begin
154 FOutpatient := IsOutpatient;
155 if not IsOutpatient then
156 begin
157 if Length(Piece(AvailTimes, U, 1)) > 0 then radLT1.Caption := Piece(AvailTimes, U, 1);
158 if Length(Piece(AvailTimes, U, 2)) > 0 then radLT2.Caption := Piece(AvailTimes, U, 2);
159 if Length(Piece(AvailTimes, U, 3)) > 0 then radLT3.Caption := Piece(AvailTimes, U, 3);
160 radLT1.Visible := Length(radLT1.Caption) > 0;
161 radLT2.Visible := Length(radLT2.Caption) > 0;
162 radLT3.Visible := Length(radLT3.Caption) > 0;
163 radLT1.Checked := TimeCount = 1;
164 end
165 else GroupBox1.Visible := False;
166 chkBagged.Visible := DietParams.Bagged;
167 with lblMealCutOff do case Meal of
168 'B': Caption := 'You have missed the breakfast cut-off.';
169 'E': Caption := 'You have missed the evening cut-off.';
170 'N': Caption := 'You have missed the noon cut-off.';
171 end;
172 // display the form
173 ShowModal;
174 if YesPressed then
175 begin
176 if not IsOutpatient then
177 begin
178 with radLT1 do if Checked then LateTrayFields.LateTime := Caption;
179 with radLT2 do if Checked then LateTrayFields.LateTime := Caption;
180 with radLT3 do if Checked then LateTrayFields.LateTime := Caption;
181 end
182 else
183 LateTrayFields.LateTime := FMTimeToAMPM(FMToday + TimePart);
184 LateTrayFields.LateMeal := Meal;
185 LateTrayFields.IsBagged := chkBagged.Checked;
186 end; {if YesPressed}
187 end; {with frmODDietLT}
188 finally
189 frmODDietLT.Release;
190 end;
191end;
192
193// ---------- frmODDietLT procedures ---------------
194procedure TfrmODDietLT.FormCreate(Sender: TObject);
195begin
196 inherited;
197 YesPressed := False;
198end;
199
200procedure TfrmODDietLT.cmdYesClick(Sender: TObject);
201begin
202 inherited;
203 if not FOutpatient then
204 if (radLT1.Checked = False) and (radLT2.Checked = False) and (radLT3.Checked = False) then
205 begin
206 InfoBox(TX_MEAL_REQ, TC_MEAL_REQ, MB_OK);
207 Exit;
208 end;
209 YesPressed := True;
210 Close;
211end;
212
213procedure TfrmODDietLT.cmdNoClick(Sender: TObject);
214begin
215 inherited;
216 Close;
217end;
218
219end.
Note: See TracBrowser for help on using the repository browser.