source: cprs/trunk/CPRS-Chart/Orders/fOrdersDC.pas@ 1142

Last change on this file since 1142 was 829, checked in by Kevin Toppenberg, 14 years ago

Upgrade to version 27

File size: 8.4 KB
RevLine 
[456]1unit fOrdersDC;
2
3interface
4
5uses
[829]6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, fBase508Form,
7 fAutoSz, StdCtrls, ORFn, ORCtrls, ExtCtrls, ORNet, VA508AccessibilityManager;
[456]8
9type
[829]10 TfrmDCOrders = class(TfrmBase508Form)
[456]11 Label1: TLabel;
12 Panel1: TPanel;
13 lstOrders: TCaptionListBox;
14 Panel2: TPanel;
15 lblReason: TLabel;
16 lstReason: TORListBox;
17 cmdOK: TButton;
18 cmdCancel: TButton;
19 procedure FormCreate(Sender: TObject);
20 procedure cmdOKClick(Sender: TObject);
21 procedure cmdCancelClick(Sender: TObject);
22 procedure lstOrdersDrawItem(Control: TWinControl; Index: Integer;
23 Rect: TRect; State: TOwnerDrawState);
24 procedure lstOrdersMeasureItem(Control: TWinControl; Index: Integer;
25 var AHeight: Integer);
[829]26 procedure FormDestroy(Sender: TObject);
27 procedure unMarkedOrignalOrderDC(OrderArr: TStringList);
[456]28 private
29 OKPressed: Boolean;
30 DCReason: Integer;
[829]31 function MeasureColumnHeight(TheOrderText: string; Index: Integer):integer;
32 public
33 OrderIDArr: TStringList;
[456]34 end;
35
36function ExecuteDCOrders(SelectedList: TList; var DelEvt: boolean): Boolean;
37
38implementation
39
40{$R *.DFM}
41
42uses rOrders, uCore, uConst, fOrders;
43
44function ExecuteDCOrders(SelectedList: TList; var DelEvt: boolean): Boolean;
45const
46 DCT_NEWORDER = 1;
47 DCT_DELETION = 2;
48 DCT_NEWSTATUS = 3;
49var
50 frmDCOrders: TfrmDCOrders;
51 AnOrder: TOrder;
[829]52 i, j, CanSign, DCType: Integer;
53 NeedReason,NeedRefresh,OnCurrent, DCNewOrder: Boolean;
[456]54 OriginalID,APtEvtID,APtEvtName,AnEvtInfo,tmpPtEvt: string;
55 PtEvtList: TStringList;
[829]56 DCChangeItem: TChangeItem;
[456]57begin
58 Result := False;
59 DelEvt := False;
60 OnCurrent := False;
61 NeedRefresh := False;
[829]62 DCNewOrder := false;
[456]63 PtEvtList := TStringList.Create;
64 if SelectedList.Count = 0 then Exit;
65 frmDCOrders := TfrmDCOrders.Create(Application);
66 try
67 ResizeFormToFont(TForm(frmDCOrders));
68 NeedReason := False;
69 with SelectedList do for i := 0 to Count - 1 do
70 begin
71 AnOrder := TOrder(Items[i]);
72 frmDCOrders.lstOrders.Items.Add(AnOrder.Text);
[829]73 frmDCOrders.OrderIDArr.Add(AnOrder.ID);
[456]74 if not ((AnOrder.Status = 11) and (AnOrder.Signature = 2)) then NeedReason := True;
[829]75 if (NeedReason = True) and (AnOrder.Status = 10) and (AnOrder.Signature = 2) then NeedReason := False;
76
[456]77 end;
78 if NeedReason then
79 begin
80 frmDCOrders.lblReason.Visible := True;
81 frmDCOrders.lstReason.Visible := True;
82 end else
83 begin
84 frmDCOrders.lblReason.Visible := False;
85 frmDCOrders.lstReason.Visible := False;
86 end;
87 frmDCOrders.ShowModal;
88 if frmDCOrders.OKPressed then
89 begin
90 if (Encounter.Provider = User.DUZ) and User.CanSignOrders
91 then CanSign := CH_SIGN_YES
92 else CanSign := CH_SIGN_NA;
93 with SelectedList do for i := 0 to Count - 1 do
94 begin
95 AnOrder := TOrder(Items[i]);
96 OriginalID := AnOrder.ID;
97 PtEvtList.Add(AnOrder.EventPtr + '^' + AnOrder.EventName);
[829]98 if Changes.Orders.Count = 0 then DCNewOrder := false
99 else
100 begin
101 for j := 0 to Changes.Orders.Count - 1 do
102 begin
103 DCChangeItem := TChangeItem(Changes.Orders.Items[j]);
104 if DCChangeItem.ID = AnOrder.ID then
105 begin
106 if (Pos('DC', AnOrder.ActionOn) = 0) then
107 DCNewOrder := True
108 else DCNewOrder := False;
109 end;
110 end;
111 end;
112 DCOrder(AnOrder, frmDCOrders.DCReason, DCNewOrder, DCType);
[456]113 case DCType of
114 DCT_NEWORDER: begin
[829]115 Changes.Add(CH_ORD, AnOrder.ID, AnOrder.Text, '', CanSign, AnOrder.ParentID, user.DUZ, AnOrder.DGroupName, True);
[456]116 AnOrder.ActionOn := OriginalID + '=DC';
117 end;
118 DCT_DELETION: begin
119 Changes.Remove(CH_ORD, OriginalID);
120 if (AnOrder.ID = '0') or (AnOrder.ID = '')
121 then AnOrder.ActionOn := OriginalID + '=DL' // delete order
122 else AnOrder.ActionOn := OriginalID + '=CA'; // cancel action
123 {else AnOrder.ActionOn := AnOrder.ID + '=CA'; - caused cancel from meds to not update orders}
124 UnlockOrder(OriginalID); // for deletion of unsigned DC
125 end;
126 DCT_NEWSTATUS: begin
127 AnOrder.ActionOn := OriginalID + '=DC';
128 UnlockOrder(OriginalID);
129 end;
130 else UnlockOrder(OriginalID);
131 end;
132 SendMessage(Application.MainForm.Handle, UM_NEWORDER, ORDER_ACT, Integer(AnOrder));
133 end;
134 if frmOrders.lstSheets.ItemIndex > -1 then
135 if CharAt(frmOrders.lstSheets.Items[frmOrders.lstSheets.ItemIndex],1)='C' then
136 OnCurrent := True;
137 if not OnCurrent then
138 begin
139 for i := 0 to PtEvtList.Count - 1 do
140 begin
141 if Length(PtEvtList[i])>1 then
142 begin
143 APtEvtID := Piece(PtEvtList[i],'^',1);
144 APtEvtName := Piece(PtEvtList[i],'^',2);
145 AnEvtInfo := EventInfo(APtEvtID);
146 if isExistedEvent(Patient.DFN,Piece(AnEvtInfo,'^',2),tmpPtEvt) and (DeleteEmptyEvt(APtEvtID,APtEvtName,False)) then
147 begin
148 NeedRefresh := True;
149 frmOrders.ChangesUpdate(APtEvtID);
150 end;
151 end;
152 end;
153 if NeedRefresh then
154 begin
155 frmOrders.InitOrderSheetsForEvtDelay;
156 frmOrders.lstSheets.ItemIndex := 0;
157 frmOrders.lstSheetsClick(nil);
158 DelEvt := True;
159 end;
160 end;
161 Result := True;
162 end
163 else with SelectedList do for i := 0 to Count - 1 do UnlockOrder(TOrder(Items[i]).ID);
164 finally
165 frmDCOrders.Release;
166 end;
167end;
168
169procedure TfrmDCOrders.FormCreate(Sender: TObject);
170var
171 DefaultIEN: Integer;
172begin
173 inherited;
174 OKPressed := False;
[829]175 OrderIDArr := TStringList.Create;
[456]176 ListDCReasons(lstReason.Items, DefaultIEN);
177 lstReason.SelectByIEN(DefaultIEN);
178 { the following commented out so that providers can enter DC reasons }
179// if Encounter.Provider = User.DUZ then
180// begin
181// lblReason.Visible := False;
182// lstReason.Visible := False;
183// end;
184end;
185
186procedure TfrmDCOrders.cmdOKClick(Sender: TObject);
187const
188 TX_REASON_REQ = 'A reason for discontinue must be selected.';
189 TC_REASON_REQ = 'Missing Discontinue Reason';
190begin
191 inherited;
192 if (lstReason.Visible) and (not (lstReason.ItemIEN > 0)) then
193 begin
194 InfoBox(TX_REASON_REQ, TC_REASON_REQ, MB_OK);
195 Exit;
196 end;
197 OKPressed := True;
198 DCReason := lstReason.ItemIEN;
199 Close;
200end;
201
202procedure TfrmDCOrders.cmdCancelClick(Sender: TObject);
203begin
204 inherited;
[829]205 unMarkedOrignalOrderDC(Self.OrderIDArr);
[456]206 Close;
207end;
208
209procedure TfrmDCOrders.lstOrdersDrawItem(Control: TWinControl;
210 Index: Integer; Rect: TRect; State: TOwnerDrawState);
211var
212 x: string;
213 ARect: TRect;
214begin
215 inherited;
216 x := '';
217 ARect := Rect;
218 with lstOrders do
219 begin
220 Canvas.FillRect(ARect);
[829]221 Canvas.Pen.Color := Get508CompliantColor(clSilver);
[456]222 Canvas.MoveTo(0, ARect.Bottom - 1);
223 Canvas.LineTo(ARect.Right, ARect.Bottom - 1);
224 if Index < Items.Count then
225 begin
226 x := Items[Index];
227 DrawText(Canvas.handle, PChar(x), Length(x), ARect, DT_LEFT or DT_NOPREFIX or DT_WORDBREAK);
228 end;
229 end;
230end;
231
232procedure TfrmDCOrders.lstOrdersMeasureItem(Control: TWinControl;
233 Index: Integer; var AHeight: Integer);
234var
235 x:string;
236begin
237 inherited;
238 with lstOrders do if Index < Items.Count then
239 begin
240 x := Items[index];
241 AHeight := MeasureColumnHeight(x, Index);
242 end;
243end;
244
245function TfrmDCOrders.MeasureColumnHeight(TheOrderText: string;
246 Index: Integer): integer;
247var
248 ARect: TRect;
249begin
250 ARect.Left := 0;
251 ARect.Top := 0;
252 ARect.Bottom := 0;
253 ARect.Right := lstOrders.Width - 6;
254 Result := WrappedTextHeightByFont(lstOrders.Canvas,lstOrders.Font,TheOrderText,ARect);
255end;
256
[829]257procedure TfrmDCOrders.FormDestroy(Sender: TObject);
258begin
259 inherited;
260 if self.OrderIDArr <> nil then self.OrderIDArr.Free;
261end;
262
263procedure TfrmDCOrders.unMarkedOrignalOrderDC(OrderArr: TStringList);
264begin
265 CallV('ORWDX1 UNDCORIG', [OrderArr]);
266end;
267
[456]268end.
Note: See TracBrowser for help on using the repository browser.