1 | unit fOMSet;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
7 | StdCtrls, CheckLst, rOrders, uConst, ORFn, rODMeds, fODBase,uCore,fOrders, fframe, fBase508Form,
|
---|
8 | VA508AccessibilityManager;
|
---|
9 |
|
---|
10 | type
|
---|
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 |
|
---|
48 | var
|
---|
49 | frmOMSet: TfrmOMSet;
|
---|
50 |
|
---|
51 | implementation
|
---|
52 |
|
---|
53 | {$R *.DFM}
|
---|
54 |
|
---|
55 | uses uOrders, fOMNavA, rMisc, uODBase;
|
---|
56 |
|
---|
57 | const
|
---|
58 | TX_STOP = 'Do you want to stop entering the current set of orders?';
|
---|
59 | TC_STOP = 'Interrupt Order Set';
|
---|
60 |
|
---|
61 | procedure TfrmOMSet.SetEventDelay(AnEvent: TOrderDelayEvent);
|
---|
62 | begin
|
---|
63 | FDelayEvent := AnEvent;
|
---|
64 | end;
|
---|
65 |
|
---|
66 | procedure 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 }
|
---|
69 | const
|
---|
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.';
|
---|
72 | var
|
---|
73 | i, InsertAt: Integer;
|
---|
74 | SetItem: TSetItem;
|
---|
75 | begin
|
---|
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;
|
---|
105 | end;
|
---|
106 |
|
---|
107 | procedure TfrmOMSet.DoNextItem;
|
---|
108 | var
|
---|
109 | SetItem: TSetItem;
|
---|
110 | theOwner: TComponent;
|
---|
111 |
|
---|
112 | procedure SkipToNext;
|
---|
113 | begin
|
---|
114 | lstSet.Checked[lstSet.ItemIndex] := True;
|
---|
115 | DoNextItem;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | begin
|
---|
119 | DoingNextItem := true;
|
---|
120 | //frmFrame.UpdatePtInfoOnRefresh;
|
---|
121 | if FClosing then Exit;
|
---|
122 | if frmOrders <> nil then
|
---|
123 | begin
|
---|
124 | if (frmOrders.TheCurrentView<>nil) and (frmOrders.TheCurrentView.EventDelay.PtEventIFN>0)
|
---|
125 | and IsCompletedPtEvt(frmOrders.TheCurrentView.EventDelay.PtEventIFN) then
|
---|
126 | begin
|
---|
127 | FDelayEvent.EventType := #0;
|
---|
128 | FDelayEvent.EventIFN := 0;
|
---|
129 | FDelayEvent.TheParent := TParentEvent.Create;
|
---|
130 | FDelayEvent.EventName := '';
|
---|
131 | FDelayEvent.PtEventIFN := 0;
|
---|
132 | end;
|
---|
133 | end;
|
---|
134 | with lstSet do
|
---|
135 | begin
|
---|
136 | if ItemIndex >= Items.Count - 1 then
|
---|
137 | begin
|
---|
138 | Close;
|
---|
139 | Exit;
|
---|
140 | end;
|
---|
141 | ItemIndex := ItemIndex + 1;
|
---|
142 | SetItem := TSetItem(Items.Objects[ItemIndex]);
|
---|
143 | case SetItem.DialogType of
|
---|
144 | 'A': if not ActivateAction(IntToStr(SetItem.DialogIEN), Self, ItemIndex) then
|
---|
145 | begin
|
---|
146 | if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
|
---|
147 | lstSet.Checked[lstSet.ItemIndex] := True
|
---|
148 | else SkipToNext;
|
---|
149 | end;
|
---|
150 | 'D', 'Q': if not ActivateOrderDialog(IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex) then
|
---|
151 | begin
|
---|
152 | if Not FClosing then
|
---|
153 | begin
|
---|
154 | if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
|
---|
155 | lstSet.Checked[lstSet.ItemIndex] := True
|
---|
156 | else SkipToNext;
|
---|
157 | end;
|
---|
158 | end;
|
---|
159 | 'M': if ActivateOrderMenu( IntToStr(SetItem.DialogIEN), FDelayEvent, Self, ItemIndex)
|
---|
160 | then Inc(FActiveMenus)
|
---|
161 | else
|
---|
162 | begin
|
---|
163 | if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
|
---|
164 | lstSet.Checked[lstSet.ItemIndex] := True
|
---|
165 | else
|
---|
166 | SkipToNext;
|
---|
167 | end;
|
---|
168 | 'O': begin
|
---|
169 | if (Self.Owner.Name = 'frmOMNavA') then theOwner := Self.Owner else theOwner := self;
|
---|
170 | if not ActivateOrderSet( IntToStr(SetItem.DialogIEN), FDelayEvent, theOwner, ItemIndex) then
|
---|
171 | begin
|
---|
172 | if IsCreatedByMenu(SetItem) and (lstSet.ItemIndex < lstSet.Items.Count - 1) then
|
---|
173 | lstSet.Checked[lstSet.ItemIndex] := True
|
---|
174 | else SkipToNext;
|
---|
175 | end;
|
---|
176 | end;
|
---|
177 | else begin
|
---|
178 | InfoBox('Unsupported dialog type: ' + SetItem.DialogType, 'Error', MB_OK);
|
---|
179 | SkipToNext;
|
---|
180 | end;
|
---|
181 | end; {case}
|
---|
182 | end; {with lstSet}
|
---|
183 | DoingNextItem := false;
|
---|
184 | end;
|
---|
185 |
|
---|
186 | procedure TfrmOMSet.UMDelayEvent(var Message: TMessage);
|
---|
187 | begin
|
---|
188 | // ignore if delay from other than current itemindex
|
---|
189 | // (prevents completion of an order set from calling DoNextItem)
|
---|
190 | if Message.WParam = lstSet.ItemIndex then
|
---|
191 | if lstSet.ItemIndex < lstSet.Items.Count - 1 then DoNextItem else Close;
|
---|
192 | if CloseRequested then
|
---|
193 | Close;
|
---|
194 | end;
|
---|
195 |
|
---|
196 | procedure TfrmOMSet.UMDestroy(var Message: TMessage);
|
---|
197 | { Received whenever activated item is finished. Posts to Owner if last item in the set. }
|
---|
198 | var
|
---|
199 | SetItem: TSetItem;
|
---|
200 | RefNum: Integer;
|
---|
201 | begin
|
---|
202 | RefNum := Message.WParam;
|
---|
203 | lstSet.Checked[RefNum] := True;
|
---|
204 | SetItem := TSetItem(lstSet.Items.Objects[RefNum]);
|
---|
205 | if SetItem.DialogType = 'M' then Dec(FActiveMenus);
|
---|
206 | if (SetItem.OwnedBy <> nil) and (SetItem.DialogType <> 'O') then
|
---|
207 | begin
|
---|
208 | PopKeyVars;
|
---|
209 | if ((lstSet.ItemIndex = lstSet.Count - 1) and (lstSet.Checked[lstSet.ItemIndex] = True)) then Close;
|
---|
210 | if {(SetItem.OwnedBy <> Self) and} (SetItem.OwnedBy is TWinControl) then
|
---|
211 | begin
|
---|
212 | SendMessage(TWinControl(SetItem.OwnedBy).Handle, UM_DESTROY, SetItem.RefNum, 0);
|
---|
213 | //Exit;
|
---|
214 | end;
|
---|
215 | end;
|
---|
216 | // let menu or dialog finish closing before going on to next item in the order set
|
---|
217 | While RefNum <= lstSet.Items.Count - 2 do
|
---|
218 | begin
|
---|
219 | if not (lstSet.Checked[RefNum+1]) then Break
|
---|
220 | else
|
---|
221 | begin
|
---|
222 | RefNum := RefNum + 1;
|
---|
223 | lstSet.ItemIndex := RefNum;
|
---|
224 | end;
|
---|
225 | end;
|
---|
226 | PostMessage(Handle, UM_DELAYEVENT, RefNum, 0);
|
---|
227 | end;
|
---|
228 |
|
---|
229 | procedure TfrmOMSet.FormCreate(Sender: TObject);
|
---|
230 | begin
|
---|
231 | FActiveMenus := 0;
|
---|
232 | FClosing := False;
|
---|
233 | FClosebyDeaCheck := False;
|
---|
234 | NoFresh := True;
|
---|
235 | CloseRequested := false;
|
---|
236 | DoingNextItem := false;
|
---|
237 | end;
|
---|
238 |
|
---|
239 | procedure TfrmOMSet.FormDestroy(Sender: TObject);
|
---|
240 | var
|
---|
241 | i: Integer;
|
---|
242 | begin
|
---|
243 | with lstSet do for i := 0 to Items.Count - 1 do TSetItem(Items.Objects[i]).Free;
|
---|
244 | DestroyingOrderSet;
|
---|
245 | end;
|
---|
246 |
|
---|
247 | procedure TfrmOMSet.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
248 | { if this is not the last item in the set, prompt whether to interrupt processing }
|
---|
249 | begin
|
---|
250 | if FClosebyDeaCheck then
|
---|
251 | CanClose := True
|
---|
252 | else if lstSet.ItemIndex < (lstSet.Items.Count - 1)
|
---|
253 | then CanClose := InfoBox(TX_STOP, TC_STOP, MB_YESNO) = IDYES;
|
---|
254 | end;
|
---|
255 |
|
---|
256 | procedure TfrmOMSet.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
257 | { Notify remaining owners that their item is done (or - really never completed) }
|
---|
258 | var
|
---|
259 | i: Integer;
|
---|
260 | SetItem: TSetItem;
|
---|
261 | begin
|
---|
262 | // do we need to iterate thru and send messages where OwnedBy <> nil?
|
---|
263 | FClosing := True;
|
---|
264 | for i := 1 to FActiveMenus do PopLastMenu;
|
---|
265 | if lstSet.Items.Count > 0 then
|
---|
266 | begin
|
---|
267 | if lstSet.ItemIndex < 0 then lstSet.ItemIndex := 0;
|
---|
268 | with lstSet do for i := ItemIndex to Items.Count - 1 do
|
---|
269 | begin
|
---|
270 | SetItem := TSetItem(lstSet.Items.Objects[i]);
|
---|
271 | if (SetItem.OwnedBy <> nil) and (SetItem.OwnedBy is TWinControl)
|
---|
272 | then SendMessage(TWinControl(SetItem.OwnedBy).Handle, UM_DESTROY, SetItem.RefNum, 0);
|
---|
273 | end;
|
---|
274 | end;
|
---|
275 | SaveUserBounds(Self);
|
---|
276 | NoFresh := False;
|
---|
277 | Action := caFree;
|
---|
278 | end;
|
---|
279 |
|
---|
280 | procedure TfrmOMSet.cmdInteruptClick(Sender: TObject);
|
---|
281 | begin
|
---|
282 | if DoingNextItem then
|
---|
283 | CloseRequested := true //Fix for CQ: 8297
|
---|
284 | else
|
---|
285 | Close;
|
---|
286 | end;
|
---|
287 |
|
---|
288 | function TfrmOMSet.DeaCheckPassed(OIIens: string; APkg: string; AnEventType: Char): boolean;
|
---|
289 | var
|
---|
290 | tmpIenList: TStringList;
|
---|
291 | i: integer;
|
---|
292 | isInpt: boolean;
|
---|
293 | begin
|
---|
294 | Result := True;
|
---|
295 | if Pos('PS',APkg) <> 1 then
|
---|
296 | Exit;
|
---|
297 | if Length(OIIens)=0 then Exit;
|
---|
298 | tmpIenList := TStringList.Create;
|
---|
299 | PiecesToList(OIIens,';',TStrings(tmpIenList));
|
---|
300 | case AnEventType of
|
---|
301 | 'A','T': isInpt := True;
|
---|
302 | 'D': isInpt := False;
|
---|
303 | else isInpt := Patient.Inpatient;
|
---|
304 | end;
|
---|
305 | for i := 0 to tmpIenList.Count - 1 do
|
---|
306 | if DEACheckFailed(StrToIntDef(tmpIenList[i],0), isInpt) then
|
---|
307 | begin
|
---|
308 | Result := False;
|
---|
309 | Break;
|
---|
310 | end;
|
---|
311 | end;
|
---|
312 |
|
---|
313 | function TfrmOMSet.IsCreatedByMenu(ASetItem: TSetItem): boolean;
|
---|
314 | begin
|
---|
315 | Result := False;
|
---|
316 | if (AsetItem.OwnedBy <> nil) and (ASetItem.OwnedBy.Name = 'frmOMNavA') then
|
---|
317 | Result := True;
|
---|
318 | end;
|
---|
319 |
|
---|
320 | end.
|
---|