Procedure

TfrmODDiet.nbkDietChange

Module

fODDiet

Last Modified

7/15/2014 3:26:42 PM

Comments

Procedure TfrmODDiet.CheckForAutoDCOrders(EvtID: integer; CurrentText: string; var CancelText: string; Sender: TObject);
const
  TX_CX_CUR = 'A new diet order will CANCEL and REPLACE this current diet now unless' + CRLF +
              'you specify a start date for when the new diet should replace the current' + CRLF +
              'diet:' + CRLF + CRLF;
  TX_CX_FUT = 'A new diet order with no expiration date will CANCEL and REPLACE these diets:' + CRLF + CRLF;
  TX_CX_DELAYED1 =  'There are other delayed diet orders for this release event:';
  TX_CX_DELAYED2 =  'This new diet order may cancel and replace those other diets' + CRLF +
                    'IMMEDIATELY ON RELEASE, unless you either:' + CRLF + CRLF +

                    '1. Specify an expiration date/time for this order that will' + CRLF +
                    '   be prior to the start date/time of those other orders; or' + CRLF + CRLF +

                    '2. Specify a later start date/time for this order for when you' + CRLF +
                    '   would like it to cancel and replace those other orders.';

var
  i: integer;
  AStringList: TStringList;
  AList: TList;
  x, PtEvtIFN, PtEvtName: string;
  //AResponse: TResponse;
begin
  if Self.EvtID = 0 then   // check current and future released diets
  begin
    x := CurrentText;
    if Piece(x, #13, 1) <> 'Current Diet:  ' then
    begin
      AStringList := TStringList.Create;
      try
        AStringList.Text := x;
        CancelText := TX_CX_CUR + #9 + Piece(AStringList[0], ':', 1) + ':' + CRLF + CRLF
                 + #9 + Copy(AStringList[0], 16, 99) + CRLF;
        if AStringList.Count > 1 then
        begin
          CancelText := CancelText + CRLF + CRLF +
                   TX_CX_FUT + #9 + Piece(AStringList[1], ':', 1) + ':' + CRLF + CRLF
                   + #9 + Copy(AStringList[1], 22, 99) + CRLF;
          if AStringList.Count > 2 then
          for i := 2 to AStringList.Count - 1 do
            CancelText := CancelText + #9 + TrimLeft(AStringList[i]) + CRLF;
        end;
      finally
        AStringList.Free;
      end;
    end;
  end 
  else if Sender is TButton then     // delayed orders code here - on accept only
  begin
    //AResponse := Responses.FindResponseByName('STOP', 1);
    //if (AResponse <> nil) and (AResponse.EValue <> '') then exit;
    AList := TList.Create;
    try
      PtEvtIFN := IntToStr(frmOrders.TheCurrentView.EventDelay.PtEventIFN);
      PtEvtName := frmOrders.TheCurrentView.EventDelay.EventName;
      LoadOrdersAbbr(AList, frmOrders.TheCurrentView, PtEvtIFN);
      for i := AList.Count - 1 downto 0 do
      begin
        if TOrder(Alist.Items[i]).DGroup <> Self.DisplayGroup then
        begin
          TOrder(AList.Items[i]).Free;
          AList.Delete(i);
        end;
      end;
      if AList.Count > 0 then
      begin
        x := '';
        RetrieveOrderFields(AList, 0, 0);
        CancelText := TX_CX_DELAYED1 + CRLF + CRLF + 'Release event: ' + PtEvtName; 
        for i := 0 to AList.Count - 1 do
          with TOrder(AList.Items[i]) do
          begin
            x := x + #9 + Text + CRLF;
(*            if StartTime <> '' then
              x := #9 + x + 'Start:   ' + StartTime + CRLF
            else
              x := #9 + x + 'Ordered: ' + FormatFMDateTime('mmm dd,yyyy@hh:nn', OrderTime) + CRLF;
          end;
        CancelText := CancelText + CRLF + CRLF + x;
        CancelText := CancelText + CRLF + CRLF + TX_CX_DELAYED2;
      end;
    finally
      with AList do for i := 0 to Count - 1 do TOrder(Items[i]).Free;
      AList.Free;
    end;
  end;
end;

Visibility

Public/Published

Owner

TfrmODDiet

Declaration

procedure nbkDietChange(Sender: TObject);

Calls Hierarchy


TfrmODDiet.nbkDietChange
 ├TfrmODBase.cmdQuitClick
 ├TResponses.Clear
 ├CurrentDietText
 ├CheckForAutoDCDietOrders
 │ ├LoadOrdersAbbr
 │ │ ├ClearOrders
 │ │ ├LoadDGroupMap
 │ │ ├ExpiredOrdersStartDT
 │ │ ├FMNow
 │ │ └SeqOfDGroup
 │ │   └LoadDGroupMap
 │ └RetrieveOrderFields
 │   └SetOrderFields
 │     ├TOrder.Clear
 │     ├SeqOfDGroup...
 │     └TopNameOfDGroup
 │       └LoadDGroupMap
 ├TfrmODBase.OrderMessage
 │ └TfrmODBase.ShowOrderMessage
 ├TResponses.SetDialog
 │ ├LoadDialogDefinition
 │ └SortPromptsBySequence
 ├TfrmODBase.SetDisplayGroup
 ├DisplayGroupForDialog
 ├LoadDietQuickList
 ├TfrmODDiet.ResetControlsDO
 ├TfrmODBase.OrderForInpatient
 │ ├OrderEventTypeOnCreate
 │ └IsPassEvt1
 ├TfrmODDiet.PatientHasRecurringMeals
 │ └GetCurrentRecurringOPMeals
 ├..(rec)..
 ├TextForOrder
 ├AppendTFProducts
 ├TfrmODDiet.ResetControlsTF
 │ └TfrmODDiet.TFClearGrid
 ├TfrmODDiet.ResetControlsEL
 ├LoadIsolations
 ├CurrentIsolation
 ├IsolationID
 ├TfrmODDiet.ResetControlsIP
 ├TfrmODDiet.ResetControlsAO
 ├TfrmODDiet.ResetControlsOP
 ├SubSetOfOPDiets
 ├TfrmODDiet.cboOPDietAvailMouseClick
 │ ├TResponses.SetQuickOrder
 │ │ ├TResponses.Clear
 │ │ └LoadResponses
 │ │   └ExtractToResponses
 │ │     └ExpandOrderObjects
 │ │       ├TdmodShared.BoilerplateOK
 │ │       │ ├ErrCount
 │ │       │ ├AddErr
 │ │       │ └TdmodShared.LoadTIUObjects
 │ │       │   └GetObjectList
 │ │       └GetTemplateText
 │ │         └TEncounter.GetVisitStr
 │ │           └TEncounter.GetVisitCategory
 │ ├TfrmODDiet.SetValuesFromResponsesOP
 │ │ ├TfrmODDiet.ResetControlsOP
 │ │ ├TResponses.FindResponseByName
 │ │ ├DietAttributes
 │ │ ├TResponses.SetControl
 │ │ │ ├TResponses.FindResponseByName
 │ │ │ └AssignBPText
 │ │ │   ├DisplayGroupToLinkType
 │ │ │   │ └DisplayGroupByName
 │ │ │   ├TResponses.EValueFor
 │ │ │   ├GetServiceIEN
 │ │ │   ├TResponses.IValueFor
 │ │ │   ├GetProcedureIEN
 │ │ │   ├ExpandOrderObjects...
 │ │ │   ├SetTemplateDialogCanceled
 │ │ │   ├CheckBoilerplate4Fields
 │ │ │   ├ExecuteTemplateOrBoilerPlate
 │ │ │   └WasTemplateDialogCanceled
 │ │ ├TfrmODDiet.calOPStopChange
 │ │ │ ├TfrmODDiet.SetEnableOPDOW
 │ │ │ ├TfrmODDiet.FMDOW
 │ │ │ ├TfrmODDiet.FMDays
 │ │ │ └TfrmODDiet.OPChange
 │ │ │   ├TResponses.Clear
 │ │ │   ├TResponses.Update
 │ │ │   │ ├TResponses.FindResponseByName
 │ │ │   │ └TResponses.IENForPrompt
 │ │ │   ├TfrmODDiet.GetOPDaysOfWeek
 │ │ │   └TResponses.GetOrderText
 │ │ │     ├TResponses.NextInstance
 │ │ │     ├TResponses.FindResponseByName
 │ │ │     ├TResponses.FormatResponse
 │ │ │     │ └TResponses.FindResponseByIEN
 │ │ │     └TResponses.AppendChildren
 │ │ │       ├TResponses.FindPromptByIEN
 │ │ │       ├TResponses.FindResponseByIEN
 │ │ │       └TResponses.FormatResponse...
 │ │ ├TfrmODDiet.OPDietCheckForNPO
 │ │ ├TfrmODDiet.OPDietCheckForTF
 │ │ │ └TextForOrder
 │ │ └TfrmODDiet.OPChange...
 │ ├DietAttributes
 │ ├TfrmODDiet.OPDietCheckForNPO
 │ ├TfrmODDiet.OPDietCheckForTF...
 │ ├TfrmODBase.OrderMessage...
 │ ├OIMessage
 │ └TfrmODDiet.OPChange...
 └TfrmODDiet.SetEnableOPDOW

Called-By Hierarchy


           TfrmODDiet.nbkDietChange
            TfrmODDiet.InitDialog┤ 
           TfrmODDiet.SetupDialog┤ 
                        ..(rec)..┘ 

Calls

Name Declaration Comments
AppendTFProducts procedure AppendTFProducts(Dest: TStrings); -
TfrmODDiet.cboOPDietAvailMouseClick procedure cboOPDietAvailMouseClick(Sender: TObject); -
CheckForAutoDCDietOrders procedure CheckForAutoDCDietOrders(EvtID: integer; DispGrp: integer; CurrentText: string; var CancelText: string; Sender: TObject); -
TResponses.Clear procedure Clear; overload; -
TfrmODBase.cmdQuitClick procedure cmdQuitClick(Sender: TObject); -
CurrentDietText function CurrentDietText: string; -
CurrentIsolation function CurrentIsolation: string; -
DisplayGroupForDialog function DisplayGroupForDialog(const DialogName: string): Integer; -
IsolationID function IsolationID: string; -
LoadDietQuickList procedure LoadDietQuickList(Dest: TStrings; const GroupID: string); -
LoadIsolations procedure LoadIsolations(Dest: TStrings); -
TfrmODDiet.nbkDietChange procedure nbkDietChange(Sender: TObject); -
TfrmODBase.OrderForInpatient function OrderForInpatient: Boolean; -
TfrmODBase.OrderMessage procedure OrderMessage(const AMessage: string); -
TfrmODDiet.PatientHasRecurringMeals function PatientHasRecurringMeals(var MealList: TStringList; MealType: string = ''): boolean; -
TfrmODDiet.ResetControlsAO procedure ResetControlsAO; -
TfrmODDiet.ResetControlsDO procedure ResetControlsDO; -
TfrmODDiet.ResetControlsEL procedure ResetControlsEL; -
TfrmODDiet.ResetControlsIP procedure ResetControlsIP; -
TfrmODDiet.ResetControlsOP procedure ResetControlsOP; -
TfrmODDiet.ResetControlsTF procedure ResetControlsTF; -
TResponses.SetDialog procedure SetDialog(Value: string); -
TfrmODBase.SetDisplayGroup procedure SetDisplayGroup(Value: Integer); -
TfrmODDiet.SetEnableOPDOW procedure SetEnableOPDOW(AllowUse: Boolean; OneTimeDay: integer; DaysToCheck: string = ''); -
SubSetOfOPDiets function SubSetOfOPDiets: TStrings; -
TextForOrder function TextForOrder(const ID: string): string; -

Called-By

Name Declaration Comments
TfrmODDiet.InitDialog procedure InitDialog; override; -
TfrmODDiet.nbkDietChange procedure nbkDietChange(Sender: TObject); -
TfrmODDiet.SetupDialog procedure SetupDialog(OrderAction: Integer; const ID: string); override; -


Source

769   procedure TfrmODDiet.nbkDietChange(Sender: TObject);
770   var
771     x: string ;
772     CxMsg: string;
773   begin
774     inherited;
775     // much of the logic here can be eliminated if ClearDialogControls starts clearing containers
776     if AbortOrder then
777     begin
778       cmdQuitClick(Self);
779       exit;
780     end;
781     StatusText('Loading Dialog Definition');
782     if Sender <> Self then Responses.Clear;
783     Changing := True;                                        // Changing set!
784     if nbkDiet.ActivePage = pgeDiet then
785     begin
786       AllowQuickOrder := True;
787       x := CurrentDietText;
788       CheckForAutoDCDietOrders(Self.EvtID, Self.DisplayGroup, x, CxMsg, nbkDiet);
789       if CxMsg <> '' then
790       begin
791         if InfoBox(CxMsg + CRLF +
792                   'Are you sure?', 'Confirm', MB_ICONWARNING or MB_YESNO) = ID_NO then
793         begin
794           AbortOrder := True;
795           cmdQuitClick(Self);
796           exit;
797         end;
798       end;
799       OrderMessage(x);
800       Responses.Dialog := 'FHW1';                            // Diet Order
801       DisplayGroup := DisplayGroupForDialog('FHW1');
802       LoadDietQuickList(cboDietAvail.Items, 'DO');
803       cboDietAvail.InsertSeparator;
804       cboDietAvail.InitLongList('');
805       chkCancelTubefeeding.State := cbGrayed;
806       chkCancelTubefeeding.Visible := False;
807       ResetControlsDO;
808     end;
809     if nbkDiet.ActivePage = pgeTubefeeding then
810     begin
811       if not OrderForInpatient then
812       begin
813         if not PatientHasRecurringMeals(uRecurringMealList) then
814           begin
815             Changing := False;
816             nbkDiet.ActivePage := pgeOutPt;
817             nbkDietChange(nbkDiet);
818             Exit;
819             end
820           else
821             FastAssign(uRecurringMealList, cboOPTFRecurringMeals.Items);
822       end;
823       cboOPTFRecurringMeals.Visible := not OrderForInpatient;
824       calOPTFStart.Visible := False;
825       lblOPTFStart.Visible := not OrderForInpatient;
826       AllowQuickOrder := True;
827       if Length(uDietParams.CurTF) > 0
828         then OrderMessage(TextForOrder(uDietParams.CurTF))
829         else OrderMessage('');
830       Responses.Dialog := 'FHW8';                            // Tubefeeding
831       DisplayGroup := DisplayGroupForDialog('FHW8');
832       with cboProduct do if Items.Count = 0 then
833       begin
834         LoadDietQuickList(Items, 'TF');
835         if Items.Count > 0 then
836         begin
837           Items.Add(LLS_LINE);
838           Items.Add(LLS_SPACE);
839         end;
840         AppendTFProducts(Items);
841       end;
842       cboProduct.Text := '';
843       ResetControlsTF;
844     end;
845     if nbkDiet.ActivePage = pgeEarlyLate then
846     begin
847       if not OrderForInpatient then
848         begin
849           if not PatientHasRecurringMeals(uRecurringMealList) then
850             begin
851               Changing := False;
852               nbkDiet.ActivePage := pgeOutPt;
853               nbkDietChange(nbkDiet);
854               Exit;
855             end
856           else
857             FastAssign(uRecurringMealList, cboOPELRecurringMeals.Items);
858         end
859       else if (StrToIntDef(uDietParams.EarlyIEN, 0) = 0) or (StrToIntDef(uDietParams.LateIEN, 0) = 0) then
860         begin
861           InfoBox(TX_NO_PARAMS, TC_NO_PARAMS, MB_ICONERROR or MB_OK);
862           if pgeEarlyLate <> nil then
863             nbkDiet.SelectNextPage(False);
864           Changing := False;
865           Exit;
866         end;
867       cboOPELRecurringMeals.Visible := not OrderForInpatient;
868       cboOPELRecurringMeals.TabStop := not OrderForInpatient;
869       calELStart.Visible := OrderForInpatient;
870       calELStart.TabStop := OrderForInpatient;
871       calELStop.Visible := OrderForInpatient;
872       lblELStop.Visible := OrderForInpatient;
873       grpDOW.Visible := OrderForInpatient;
874       grpDOW.Enabled := OrderForInpatient;
875       AllowQuickOrder := False;
876       OrderMessage('');
877       Responses.Dialog := 'FHW2';                            // Early/Late Tray
878       DisplayGroup := DisplayGroupForDialog('FHW2');
879       ResetControlsEL;
880     end;
881     if nbkDiet.ActivePage = pgeIsolations then
882     begin
883       AllowQuickOrder := False;
884       OrderMessage('');
885       Responses.Dialog := 'FHW3';                            // Isolations
886       DisplayGroup := DisplayGroupForDialog('FHW3');
887       if lstIsolation.Items.Count = 0 then LoadIsolations(lstIsolation.Items);
888       txtIPCurrent.Text := CurrentIsolation;
889       FIsolationID := IsolationID;
890       ResetControlsIP;
891     end;
892     if nbkDiet.ActivePage = pgeAdditional then
893     begin
894     if not OrderForInpatient then
895       begin
896         if not PatientHasRecurringMeals(uRecurringMealList) then
897           begin
898             Changing := False;
899             nbkDiet.ActivePage := pgeOutPt;
900             nbkDietChange(nbkDiet);
901             Exit;
902           end
903         else
904           FastAssign(uRecurringMealList, cboOPAORecurringMeals.Items);
905       end;
906       cboOPAORecurringMeals.Visible := not OrderForInpatient;
907       calOPAOStart.Visible := False;  //not OrderForInpatient;
908       lblOPAOStart.Visible := not OrderForInpatient;
909       AllowQuickOrder := False;
910       OrderMessage('');
911       Responses.Dialog := 'FHW7';                            // Additional Order
912       DisplayGroup := DisplayGroupForDialog('FHW7');
913       ResetControlsAO;
914     end;
915     if nbkDiet.ActivePage = pgeOutPt then
916     begin
917       x := CurrentDietText;
918       if Length(Piece(x, #$D, 1)) > Length('Current Diet:  ') then
919         OrderMessage(x)
920       else
921         OrderMessage('');
922       if (uDialogName <> 'FHW SPECIAL MEAL') and (uDialogName <> 'FHW OP MEAL') then
923         uDialogName := 'FHW OP MEAL';
924       Responses.Dialog := uDialogName;
925       DisplayGroup := DisplayGroupForDialog(uDialogName);
926       if uDialogName = 'FHW SPECIAL MEAL' then                 // Special meal
927         begin
928          AllowQuickOrder := False;
929          ResetControlsOP;
930          FastAddStrings(SubSetOfOPDiets, cboOPDietAvail.Items);
931          { TODO -oRich V. -cOutpatient Meals : Need to DC Tubefeeding order for OP meals? }
932          chkOPCancelTubefeeding.State := cbGrayed;
933          chkOPCancelTubefeeding.Visible := False;
934          grpOPMeal.Caption := 'Special Meal';
935          pgeTubefeeding.TabVisible := False;
936          pgeIsolations.TabVisible := False;
937          pgeAdditional.TabVisible := False;
938          pgeEarlyLate.TabVisible := False;
939          cboOPDietAvail.SelectByIEN(uDietParams.OPDefaultDiet);
940          cboOPDietAvailMouseClick(Self);
941          Changing := False;
942         end
943       else if uDialogName = 'FHW OP MEAL' then                          // Recurring meal
944         begin
945          AllowQuickOrder := True;
946          ResetControlsOP;
947          LoadDietQuickList(cboOPDietAvail.Items, 'MEAL');              // use D.G. short name here
948          cboOPDietAvail.InsertSeparator;
949          FastAddStrings(SubSetOfOPDiets, cboOPDietAvail.Items);
950          cboOPDietAvail.SelectByIEN(uDietParams.OPDefaultDiet);
951          { TODO -oRich V. -cOutpatient Meals : Need to DC Tubefeeding order for OP meals? }
952          chkOPCancelTubefeeding.State := cbGrayed;
953          chkOPCancelTubefeeding.Visible := False;
954          grpOPMeal.Caption := 'Recurring Meal';
955          SetEnableOPDOW(False, -1);
956          cboOPDietAvailMouseClick(Self);
957          Changing := False;
958         end;
959     end;
960     Changing := False;                                       // Changing reset
961     StatusText('');
962     if FGiveMultiTabMessage then  // CQ#15483
963     begin
964       FGiveMultiTabMessage := FALSE;
965       GetScreenReader.Speak('Multi Tab Form');
966     end;
967   end;