source: cprs/branches/HealthSevak-CPRS/CPRS-Chart/Orders/fOMSet.pas@ 1722

Last change on this file since 1722 was 1693, checked in by healthsevak, 9 years ago

Committing the files for first time to this new branch

File size: 10.8 KB
Line 
1unit fOMSet;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, CheckLst, rOrders, uConst, ORFn, rODMeds, fODBase,uCore,fOrders, fframe, fBase508Form,
8 VA508AccessibilityManager;
9
10type
11 TSetItem = class
12 DialogIEN: Integer;
13 DialogType: Char;
14 OIIEN: string;
15 InPkg: string;
16 OwnedBy: TComponent;
17 RefNum: Integer;
18 end;
19
20 TfrmOMSet = class(TfrmBase508Form)
21 lstSet: TCheckListBox;
22 cmdInterupt: TButton;
23 procedure cmdInteruptClick(Sender: TObject);
24 procedure FormDestroy(Sender: TObject);
25 procedure FormClose(Sender: TObject; var Action: TCloseAction);
26 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
27 procedure FormCreate(Sender: TObject);
28 private
29 DoingNextItem : Boolean;
30 CloseRequested : Boolean;
31 FDelayEvent: TOrderDelayEvent;
32 FClosing: Boolean;
33 FRefNum: Integer;
34 FActiveMenus: Integer;
35 FClosebyDeaCheck: Boolean;
36 function IsCreatedByMenu(ASetItem: TSetItem): boolean;
37 function DeaCheckPassed(OIIens: string; APkg: string; AnEventType: Char): boolean;
38 procedure DoNextItem;
39 procedure UMDestroy(var Message: TMessage); message UM_DESTROY;
40 procedure UMDelayEvent(var Message: TMessage); message UM_DELAYEVENT;
41 public
42 procedure InsertList(SetList: TStringList; AnOwner: TComponent; ARefNum: Integer;
43 const KeyVarStr: string; AnEventType:Char =#0);
44 procedure SetEventDelay(AnEvent: TOrderDelayEvent);
45 property RefNum: Integer read FRefNum write FRefNum;
46 end;
47
48var
49 frmOMSet: TfrmOMSet;
50
51implementation
52
53{$R *.DFM}
54
55uses uOrders, fOMNavA, rMisc, uODBase;
56
57const
58 TX_STOP = 'Do you want to stop entering the current set of orders?';
59 TC_STOP = 'Interrupt Order Set';
60
61procedure TfrmOMSet.SetEventDelay(AnEvent: TOrderDelayEvent);
62begin
63 FDelayEvent := AnEvent;
64end;
65
66procedure TfrmOMSet.InsertList(SetList: TStringList; AnOwner: TComponent; ARefNum: Integer;
67 const KeyVarStr: string; AnEventType: Char);
68{ expects SetList to be strings of DlgIEN^DlgType^DisplayName^OrderableItemIens }
69const
70 TXT_DEAFAIL = 'You need have #DEA key to place the order ';
71 TXT_INSTRUCT = #13 + 'Click OK to continue, Click Cancel to terminate the current order process.';
72var
73 i, InsertAt: Integer;
74 SetItem: TSetItem;
75begin
76 InsertAt := lstSet.ItemIndex + 1;
77 with SetList do for i := 0 to Count - 1 do
78 begin
79 SetItem := TSetItem.Create;
80 SetItem.DialogIEN := StrToIntDef(Piece(SetList[i], U, 1), 0);
81 SetItem.DialogType := CharAt(Piece(SetList[i], U, 2), 1);
82 SetItem.OIIEN := Piece(SetList[i], U, 4);
83 SetItem.InPkg := Piece(SetList[i], U, 5);
84 // put the Owner form and reference number in the last item
85 if i = Count - 1 then
86 begin
87 SetItem.OwnedBy := AnOwner;
88 SetItem.RefNum := ARefNum;
89 end;
90 if not DeaCheckPassed(SetItem.OIIEN, SetItem.InPkg, AnEventType) then
91 if InfoBox(TXT_DEAFAIL + Piece(SetList[i], U, 3) + TXT_INSTRUCT,
92 'Warning', MB_OKCANCEL or MB_ICONWARNING) = IDOK then
93 Continue
94 else
95 begin
96 FClosebyDeaCheck := True;
97 Close;
98 Exit;
99 end;
100 lstSet.Items.InsertObject(InsertAt, Piece(SetList[i], U, 3), SetItem);
101 Inc(InsertAt);
102 end;
103 PushKeyVars(KeyVarStr);
104 DoNextItem;
105end;
106
107procedure TfrmOMSet.DoNextItem;
108var
109 SetItem: TSetItem;
110 theOwner: TComponent;
111 ok: boolean;
112
113 procedure SkipToNext;
114 begin
115 if FClosing then Exit;
116 lstSet.Checked[lstSet.ItemIndex] := True;
117 DoNextItem;
118 end;
119
120begin
121 DoingNextItem := true;
122 //frmFrame.UpdatePtInfoOnRefresh;
123 if FClosing then Exit;
124 if frmOrders <> nil then
125 begin
126 if (frmOrders.TheCurrentView<>nil) and (frmOrders.TheCurrentView.EventDelay.PtEventIFN>0)
127 and IsCompletedPtEvt(frmOrders.TheCurrentView.EventDelay.PtEventIFN) then
128 begin
129 FDelayEvent.EventType := #0;
130 FDelayEvent.EventIFN := 0;
131 FDelayEvent.TheParent := TParentEvent.Create;
132 FDelayEvent.EventName := '';
133 FDelayEvent.PtEventIFN := 0;
134 end;
135 end;
136 with lstSet do
137 begin
138 if ItemIndex >= Items.Count - 1 then
139 begin
140 Close;
141 Exit;
142 end;
143 ItemIndex := ItemIndex + 1;
144 SetItem := TSetItem(Items.Objects[ItemIndex]);
145 case SetItem.DialogType of
146 'A': if not ActivateAction(IntToStr(SetItem.DialogIEN), Self, ItemIndex) then
147 begin
148 if Not FClosing then
149 begin
150 if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
151 lstSet.Checked[lstSet.ItemIndex] := True
152 else SkipToNext;
153 end;
154 end;
155 'D', 'Q': if not ActivateOrderDialog(IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex) then
156 begin
157 if Not FClosing then
158 begin
159 if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
160 lstSet.Checked[lstSet.ItemIndex] := True
161 else SkipToNext;
162 end;
163 end;
164 'M': begin
165 ok := ActivateOrderMenu(IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex);
166 if not FClosing then
167 begin
168 if ok then
169 Inc(FActiveMenus)
170 else
171 begin
172 if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
173 lstSet.Checked[lstSet.ItemIndex] := True
174 else
175 SkipToNext;
176 end;
177 end;
178 end;
179 'O': begin
180 if (Self.Owner.Name = 'frmOMNavA') then theOwner := Self.Owner else theOwner := self;
181 if not ActivateOrderSet( IntToStr(SetItem.DialogIEN), FDelayEvent, theOwner, ItemIndex) then
182 begin
183 if Not FClosing then
184 begin
185 if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
186 lstSet.Checked[lstSet.ItemIndex] := True
187 else SkipToNext;
188 end;
189 end;
190 end;
191 else begin
192 InfoBox('Unsupported dialog type: ' + SetItem.DialogType, 'Error', MB_OK);
193 SkipToNext;
194 end;
195 end; {case}
196 end; {with lstSet}
197 DoingNextItem := false;
198end;
199
200procedure TfrmOMSet.UMDelayEvent(var Message: TMessage);
201begin
202 if CloseRequested then
203 begin
204 Close;
205 if Not FClosing then
206 begin
207 CloseRequested := False;
208 FClosing := False;
209 DoNextItem;
210 end
211 else Exit;
212 end;
213 // ignore if delay from other than current itemindex
214 // (prevents completion of an order set from calling DoNextItem)
215 if Message.WParam = lstSet.ItemIndex then
216 if lstSet.ItemIndex < lstSet.Items.Count - 1 then DoNextItem else Close;
217end;
218
219procedure TfrmOMSet.UMDestroy(var Message: TMessage);
220{ Received whenever activated item is finished. Posts to Owner if last item in the set. }
221var
222 SetItem: TSetItem;
223 RefNum: Integer;
224begin
225 RefNum := Message.WParam;
226 lstSet.Checked[RefNum] := True;
227 SetItem := TSetItem(lstSet.Items.Objects[RefNum]);
228 if SetItem.DialogType = 'M' then Dec(FActiveMenus);
229 if (SetItem.OwnedBy <> nil) and (SetItem.DialogType <> 'O') then
230 begin
231 PopKeyVars;
232 if ((lstSet.ItemIndex = lstSet.Count - 1) and (lstSet.Checked[lstSet.ItemIndex] = True)) then Close;
233 if {(SetItem.OwnedBy <> Self) and} (SetItem.OwnedBy is TWinControl) then
234 begin
235 SendMessage(TWinControl(SetItem.OwnedBy).Handle, UM_DESTROY, SetItem.RefNum, 0);
236 //Exit;
237 end;
238 end;
239 // let menu or dialog finish closing before going on to next item in the order set
240 While RefNum <= lstSet.Items.Count - 2 do
241 begin
242 if not (lstSet.Checked[RefNum+1]) then Break
243 else
244 begin
245 RefNum := RefNum + 1;
246 lstSet.ItemIndex := RefNum;
247 end;
248 end;
249 PostMessage(Handle, UM_DELAYEVENT, RefNum, 0);
250end;
251
252procedure TfrmOMSet.FormCreate(Sender: TObject);
253begin
254 FActiveMenus := 0;
255 FClosing := False;
256 FClosebyDeaCheck := False;
257 NoFresh := True;
258 CloseRequested := false;
259 DoingNextItem := false;
260end;
261
262procedure TfrmOMSet.FormDestroy(Sender: TObject);
263var
264 i: Integer;
265begin
266 with lstSet do for i := 0 to Items.Count - 1 do TSetItem(Items.Objects[i]).Free;
267 DestroyingOrderSet;
268end;
269
270procedure TfrmOMSet.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
271{ if this is not the last item in the set, prompt whether to interrupt processing }
272begin
273 if FClosebyDeaCheck then
274 CanClose := True
275 else if lstSet.ItemIndex < (lstSet.Items.Count - 1)
276 then CanClose := InfoBox(TX_STOP, TC_STOP, MB_YESNO) = IDYES;
277 FClosing := CanClose;
278end;
279
280procedure TfrmOMSet.FormClose(Sender: TObject; var Action: TCloseAction);
281{ Notify remaining owners that their item is done (or - really never completed) }
282var
283 i: Integer;
284 SetItem: TSetItem;
285begin
286 // do we need to iterate thru and send messages where OwnedBy <> nil?
287 FClosing := True;
288 for i := 1 to FActiveMenus do PopLastMenu;
289 if lstSet.Items.Count > 0 then
290 begin
291 if lstSet.ItemIndex < 0 then lstSet.ItemIndex := 0;
292 with lstSet do for i := ItemIndex to Items.Count - 1 do
293 begin
294 SetItem := TSetItem(lstSet.Items.Objects[i]);
295 if (SetItem.OwnedBy <> nil) and (SetItem.OwnedBy is TWinControl)
296 then SendMessage(TWinControl(SetItem.OwnedBy).Handle, UM_DESTROY, SetItem.RefNum, 0);
297 end;
298 end;
299 SaveUserBounds(Self);
300 NoFresh := False;
301 Action := caFree;
302end;
303
304procedure TfrmOMSet.cmdInteruptClick(Sender: TObject);
305begin
306 if DoingNextItem then
307 begin
308 CloseRequested := true; //Fix for CQ: 8297
309 FClosing := true;
310 end
311 else
312 Close;
313end;
314
315function TfrmOMSet.DeaCheckPassed(OIIens: string; APkg: string; AnEventType: Char): boolean;
316var
317 tmpIenList: TStringList;
318 i: integer;
319 isInpt: boolean;
320begin
321 Result := True;
322 if Pos('PS',APkg) <> 1 then
323 Exit;
324 if Length(OIIens)=0 then Exit;
325 tmpIenList := TStringList.Create;
326 PiecesToList(OIIens,';',TStrings(tmpIenList));
327 case AnEventType of
328 'A','T': isInpt := True;
329 'D': isInpt := False;
330 else isInpt := Patient.Inpatient;
331 end;
332 for i := 0 to tmpIenList.Count - 1 do
333 if DEACheckFailed(StrToIntDef(tmpIenList[i],0), isInpt) then
334 begin
335 Result := False;
336 Break;
337 end;
338end;
339
340function TfrmOMSet.IsCreatedByMenu(ASetItem: TSetItem): boolean;
341begin
342 Result := False;
343 if (AsetItem.OwnedBy <> nil) and (ASetItem.OwnedBy.Name = 'frmOMNavA') then
344 Result := True;
345end;
346
347end.
Note: See TracBrowser for help on using the repository browser.