Procedure

TfrmMeds.NotifyOrder

Directives

Override

Module

fMeds

Last Modified

7/15/2014 3:26:38 PM

Visibility

Public

Overrides

TfrmPage.NotifyOrder

Owner

TfrmMeds

Declaration

procedure NotifyOrder(OrderAction: Integer; AnOrder: TOrder); override;

Calls Hierarchy


TfrmMeds.NotifyOrder
 ├TfrmMeds.GetPlainText
 │ ├TfrmMeds.GetMedList
 │ ├TfrmMeds.GetHeader
 │ └TfrmMeds.GetListText
 │   ├TfrmMeds.GetActionText
 │   └TfrmMeds.GetInstructText
 ├IndexForCurrentID
 ├GetChildrenOfComplexOrder
 ├IsFirstDoseNowOrder
 └TfrmMeds.RefreshMedLists
   ├TfrmFrame.GetTimedOut
   │ └TimedOut
   ├LoadActiveMedLists
   │ ├ClearMedList
   │ └SetMedFields
   ├TfrmMeds.SetViewCaption
   └TfrmMeds.GetPlainText...

Called-By Hierarchy


  TfrmMeds.NotifyOrder
TfrmFrame.UMNewOrder┘ 

Calls

Name Declaration Comments
GetChildrenOfComplexOrder procedure GetChildrenOfComplexOrder(AnParentID,CurrAct: string; var ChildList: TStringList); -
TfrmMeds.GetPlainText function GetPlainText(Control: TWinControl; Index: integer): string; -
IndexForCurrentID function IndexForCurrentID(const AnID: string): Integer; -
IsFirstDoseNowOrder function IsFirstDoseNowOrder(OrderID: string): boolean; -
TfrmMeds.RefreshMedLists procedure RefreshMedLists; -

Called-By

Name Declaration Comments
TfrmFrame.UMNewOrder procedure UMNewOrder(var Message: TMessage); message UM_NEWORDER; -


Source

379   procedure TfrmMeds.NotifyOrder(OrderAction: Integer; AnOrder: TOrder);
380   var
381     AMedList: TList;
382     AStringList: TStringList;
383     NewMedRec: TMedListRec;
384     i, idx, Match: Integer;
385     j: integer;
386     AChildList: TStringlist;
387     CplxOrderID: string;
388   
389     procedure SetCurrentOrderID;
390     var
391       i: Integer;
392       AMedRec: TMedListRec;
393     begin
394       with AMedList do for i := 0 to Count - 1 do
395       begin
396         AMedRec := TMedListRec(AMedList[i]);
397         if Piece(AMedRec.OrderID, ';', 1) = Piece(AnOrder.ActionOn, ';', 1) then
398         begin
399         end;
400       end;
401     end;
402   
403     function IndexForCurrentID(const AnID: string): Integer;
404     var
405       i: Integer;
406     begin
407       Result := -1;
408       for i := 0 to uPendingChanges.Count - 1 do
409         if Piece(uPendingChanges[i], U, 2) = AnID then Result := i;
410       if Result < 0 then
411         for i := 0 to uPendingChanges.Count - 1 do
412           if Piece(uPendingChanges[i], '=', 1) = Piece(AnID, ';', 1) then Result := i;
413     end;
414   
415   begin
416     AMedList := nil;
417     if AnOrder <> nil then
418     begin
419       //AGP Change 26.24 CQ 7150 fixes the problem with non-va meds initially showing up in the inpatient section
420       if uDGrp[DG_OUT] = AnOrder.DGroup then AMedList := uMedListOut;
421       If uDGrp[DG_NVA] = AnOrder.DGroup then AMedList := uMedListNonVA;
422       if (AMedList <> uMedListOut) and (AMedList <> uMedListNonVA) then
423         for i := 1 to 6 do if uDGrp[i] = AnOrder.DGroup then AMedList := uMedListIn;
424     end;
425     case OrderAction of
426     ORDER_NEW:  { sent by accept order on new order }
427       if AMedList <> nil then
428       begin
429         // check this out carefully!!
430         NewMedRec := TMedListRec.Create;
431         NewMedRec.OrderID := AnOrder.ID;
432         NewMedRec.Instruct := AnOrder.Text;
433         NewMedRec.Inpatient := AMedList = uMedListIn;
434         AMedList.Insert(0, NewMedRec);
435         if AMedList = uMedListIn then
436         begin
437           lstMedsIn.Items.Insert(0, GetPlainText(lstMedsIn,0));
438           uPharmacyOrdersIn.Insert(0, U + AnOrder.ID);
439         end
440         else
441         begin
442           if AMedList = uMedListOut then
443           begin
444              lstMedsOut.Items.Insert(0, GetPlainText(lstMedsOut,0));
445              uPharmacyOrdersOut.Insert(0, U + AnOrder.ID);
446           end
447         else
448         begin
449             if AMedList = uMedListNonVA then
450             begin
451                lstMedsNonVA.Items.Insert(0, GetPlainText(lstMedsNonVA,0));
452                uNonVAOrdersOut.Insert(0, U + AnOrder.ID);
453             end;
454         end;
455         end;
456         uPendingChanges.Add(Piece(AnOrder.ID, ';', 1) + '=NW^' + AnOrder.ID);
457       end;
458     ORDER_DC:   { sent by a diet to cancel a tubefeeding - do nothing };
459     ORDER_EDIT: { sent by accept on edit order }
460       if AMedList <> nil then
461       begin
462         Match := IndexForCurrentID(AnOrder.EditOf);
463         if Match < 0
464           { add a new pending change if there is no existing change that matches EditOf }
465           then uPendingChanges.Add(Piece(AnOrder.EditOf, ';', 1) + '=XX' + U + AnOrder.ID + U + AnOrder.Text + U + AnOrder.OrderLocName)
466           { leave 1st piece (original ID) intact, while changing text & current ID }
467           else uPendingChanges[Match] := Piece(uPendingChanges[Match], '=', 1) + '=XX' + U + AnOrder.ID + U + AnOrder.Text + U + AnOrder.OrderLocName;
468       end;
469     ORDER_ACT:  { sent by DC, Hold, & Renew actions }
470       if AMedList <> nil then
471       begin
472         if Piece(AnOrder.ActionOn, '=', 2) = 'CA' then
473         begin
474           // cancel action, remove from PendingChanges
475           for idx := uPendingChanges.Count-1 downto 0 do
476           begin
477             Match := IndexForCurrentID(Piece(AnOrder.ActionOn, '=', 1));
478             if Match > -1 then uPendingChanges.Delete(Match);
479           end;
480         end
481         else if Piece(AnOrder.ActionOn, '=', 2) = 'DL' then
482         begin
483           // delete action, show as deleted (set OrderID's to 0 so not confused with next order)
484           Match := IndexForCurrentID(Piece(AnOrder.ActionOn, '=', 1));
485           if Match > -1 then uPendingChanges[Match] := '0=DL';
486           if AMedList = uMedListIn
487           then AStringList := uPharmacyOrdersIn
488           else if AMedList = uMedListOut
489           then AStringList := uPharmacyOrdersOut
490           else AStringList := uNonVAOrdersOut;
491           with AStringList do for i := 0 to Count - 1 do
492             if (U + Piece(AnOrder.ActionOn, '=', 1)) = Strings[i] then Strings[i] := '^0';
493           Match := -1;
494           with AMedList do for i := 0 to Count - 1 do
495             if TMedListRec(Items[i]).OrderID = Piece(AnOrder.ActionOn, '=', 1) then Match := i;
496           if Match > -1 then TMedListRec(AMedList.Items[Match]).OrderID := '0';
497         end
498         else uPendingChanges.Add(Piece(AnOrder.ActionOn, ';', 1) + '=' +
499                 Piece(AnOrder.ActionOn, '=', 2) + U + AnOrder.ID + '^^' + AnOrder.OrderLocName);
500   
501       end; {if AMedList}
502     ORDER_CPLXRN:
503       begin
504         AChildList := TStringList.Create;
505         CplxOrderID := Piece(AnOrder.ActionOn,'=',1);
506         GetChildrenOfComplexOrder(CplxOrderID, Piece(CplxOrderID,';',2), AChildList);
507         if AMedList = uMedListIn then with AMedList do
508         begin
509           for i := Count-1 downto 0 do
510           begin
511             for j := 0 to AChildList.Count - 1 do
512             begin
513               if (TMedListRec(Items[i]).OrderID = AChildList[j]) then
514               begin
515               {  Delete(i);
516                 Break;}
517                 if not IsFirstDoseNowOrder(TMedListRec(Items[i]).OrderID) then
518                 begin
519                   uPendingChanges.Add(Piece(TMedListRec(Items[i]).OrderID, ';', 1) + '=' + Piece(AnOrder.ActionOn, '=', 2) + U + AnOrder.ID);
520                   Break;
521                 end;
522               end;
523             end;
524           end;
525         end;
526         AChildList.Clear;
527         AChildList.Free;
528       end;
529     ORDER_SIGN: { sent by fReview, fOrderSign when orders signed, AnOrder=nil}
530       begin
531         // ** only if tab has been visited?
532         uPendingChanges.Clear;
533         RefreshMedLists;
534       end;
535     end; {case}
536   end;