| 1 | unit fOrdersDC;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, fBase508Form,
|
---|
| 7 | fAutoSz, StdCtrls, ORFn, ORCtrls, ExtCtrls, ORNet, VA508AccessibilityManager;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 10 | TfrmDCOrders = class(TfrmBase508Form)
|
---|
| 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);
|
---|
| 26 | procedure FormDestroy(Sender: TObject);
|
---|
| 27 | procedure unMarkedOrignalOrderDC(OrderArr: TStringList);
|
---|
| 28 | private
|
---|
| 29 | OKPressed: Boolean;
|
---|
| 30 | DCReason: Integer;
|
---|
| 31 | function MeasureColumnHeight(TheOrderText: string; Index: Integer):integer;
|
---|
| 32 | public
|
---|
| 33 | OrderIDArr: TStringList;
|
---|
| 34 | end;
|
---|
| 35 |
|
---|
| 36 | function ExecuteDCOrders(SelectedList: TList; var DelEvt: boolean): Boolean;
|
---|
| 37 |
|
---|
| 38 | implementation
|
---|
| 39 |
|
---|
| 40 | {$R *.DFM}
|
---|
| 41 |
|
---|
| 42 | uses rOrders, uCore, uConst, fOrders;
|
---|
| 43 |
|
---|
| 44 | function ExecuteDCOrders(SelectedList: TList; var DelEvt: boolean): Boolean;
|
---|
| 45 | const
|
---|
| 46 | DCT_NEWORDER = 1;
|
---|
| 47 | DCT_DELETION = 2;
|
---|
| 48 | DCT_NEWSTATUS = 3;
|
---|
| 49 | var
|
---|
| 50 | frmDCOrders: TfrmDCOrders;
|
---|
| 51 | AnOrder: TOrder;
|
---|
| 52 | i, j, CanSign, DCType: Integer;
|
---|
| 53 | NeedReason,NeedRefresh,OnCurrent, DCNewOrder: Boolean;
|
---|
| 54 | OriginalID,APtEvtID,APtEvtName,AnEvtInfo,tmpPtEvt: string;
|
---|
| 55 | PtEvtList: TStringList;
|
---|
| 56 | DCChangeItem: TChangeItem;
|
---|
| 57 | begin
|
---|
| 58 | Result := False;
|
---|
| 59 | DelEvt := False;
|
---|
| 60 | OnCurrent := False;
|
---|
| 61 | NeedRefresh := False;
|
---|
| 62 | DCNewOrder := false;
|
---|
| 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);
|
---|
| 73 | frmDCOrders.OrderIDArr.Add(AnOrder.ID);
|
---|
| 74 | if not ((AnOrder.Status = 11) and (AnOrder.Signature = 2)) then NeedReason := True;
|
---|
| 75 | if (NeedReason = True) and (AnOrder.Status = 10) and (AnOrder.Signature = 2) then NeedReason := False;
|
---|
| 76 |
|
---|
| 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);
|
---|
| 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);
|
---|
| 113 | case DCType of
|
---|
| 114 | DCT_NEWORDER: begin
|
---|
| 115 | Changes.Add(CH_ORD, AnOrder.ID, AnOrder.Text, '', CanSign, AnOrder.ParentID, user.DUZ, AnOrder.DGroupName, True);
|
---|
| 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;
|
---|
| 167 | end;
|
---|
| 168 |
|
---|
| 169 | procedure TfrmDCOrders.FormCreate(Sender: TObject);
|
---|
| 170 | var
|
---|
| 171 | DefaultIEN: Integer;
|
---|
| 172 | begin
|
---|
| 173 | inherited;
|
---|
| 174 | OKPressed := False;
|
---|
| 175 | OrderIDArr := TStringList.Create;
|
---|
| 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;
|
---|
| 184 | end;
|
---|
| 185 |
|
---|
| 186 | procedure TfrmDCOrders.cmdOKClick(Sender: TObject);
|
---|
| 187 | const
|
---|
| 188 | TX_REASON_REQ = 'A reason for discontinue must be selected.';
|
---|
| 189 | TC_REASON_REQ = 'Missing Discontinue Reason';
|
---|
| 190 | begin
|
---|
| 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;
|
---|
| 200 | end;
|
---|
| 201 |
|
---|
| 202 | procedure TfrmDCOrders.cmdCancelClick(Sender: TObject);
|
---|
| 203 | begin
|
---|
| 204 | inherited;
|
---|
| 205 | unMarkedOrignalOrderDC(Self.OrderIDArr);
|
---|
| 206 | Close;
|
---|
| 207 | end;
|
---|
| 208 |
|
---|
| 209 | procedure TfrmDCOrders.lstOrdersDrawItem(Control: TWinControl;
|
---|
| 210 | Index: Integer; Rect: TRect; State: TOwnerDrawState);
|
---|
| 211 | var
|
---|
| 212 | x: string;
|
---|
| 213 | ARect: TRect;
|
---|
| 214 | begin
|
---|
| 215 | inherited;
|
---|
| 216 | x := '';
|
---|
| 217 | ARect := Rect;
|
---|
| 218 | with lstOrders do
|
---|
| 219 | begin
|
---|
| 220 | Canvas.FillRect(ARect);
|
---|
| 221 | Canvas.Pen.Color := Get508CompliantColor(clSilver);
|
---|
| 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;
|
---|
| 230 | end;
|
---|
| 231 |
|
---|
| 232 | procedure TfrmDCOrders.lstOrdersMeasureItem(Control: TWinControl;
|
---|
| 233 | Index: Integer; var AHeight: Integer);
|
---|
| 234 | var
|
---|
| 235 | x:string;
|
---|
| 236 | begin
|
---|
| 237 | inherited;
|
---|
| 238 | with lstOrders do if Index < Items.Count then
|
---|
| 239 | begin
|
---|
| 240 | x := Items[index];
|
---|
| 241 | AHeight := MeasureColumnHeight(x, Index);
|
---|
| 242 | end;
|
---|
| 243 | end;
|
---|
| 244 |
|
---|
| 245 | function TfrmDCOrders.MeasureColumnHeight(TheOrderText: string;
|
---|
| 246 | Index: Integer): integer;
|
---|
| 247 | var
|
---|
| 248 | ARect: TRect;
|
---|
| 249 | begin
|
---|
| 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);
|
---|
| 255 | end;
|
---|
| 256 |
|
---|
| 257 | procedure TfrmDCOrders.FormDestroy(Sender: TObject);
|
---|
| 258 | begin
|
---|
| 259 | inherited;
|
---|
| 260 | if self.OrderIDArr <> nil then self.OrderIDArr.Free;
|
---|
| 261 | end;
|
---|
| 262 |
|
---|
| 263 | procedure TfrmDCOrders.unMarkedOrignalOrderDC(OrderArr: TStringList);
|
---|
| 264 | begin
|
---|
| 265 | CallV('ORWDX1 UNDCORIG', [OrderArr]);
|
---|
| 266 | end;
|
---|
| 267 |
|
---|
| 268 | end.
|
---|