Index: cprs/branches/foia-cprs/CPRS-Chart/fMeds.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/fMeds.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/fMeds.pas	(revision 460)
@@ -72,4 +72,15 @@
     lstMedsOut: TCaptionListBox;
     hdrMedsOut: THeaderControl;
+    mnuViewInformation: TMenuItem;
+    mnuViewDemo: TMenuItem;
+    mnuViewVisits: TMenuItem;
+    mnuViewPrimaryCare: TMenuItem;
+    mnuViewMyHealtheVet: TMenuItem;
+    mnuInsurance: TMenuItem;
+    mnuViewFlags: TMenuItem;
+    mnuViewReminders: TMenuItem;
+    mnuViewRemoteData: TMenuItem;
+    mnuViewPostings: TMenuItem;
+    mnuOptimizeFields: TMenuItem;
     procedure mnuChartTabClick(Sender: TObject);
     procedure FormCreate(Sender: TObject);
@@ -96,5 +107,4 @@
     procedure mnuActRefillClick(Sender: TObject);
     procedure mnuActClick(Sender: TObject);
-    procedure pnlMedOut1Resize(Sender: TObject);
     procedure mnuViewHistoryClick(Sender: TObject);
     procedure popMedPopup(Sender: TObject);
@@ -114,4 +124,26 @@
     procedure splitBottomMoved(Sender: TObject);
     procedure splitTopMoved(Sender: TObject);
+    procedure hdrMedsOutMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure hdrMedsNonVAMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure hdrMedsInMouseDown(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure hdrMedsOutMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure hdrMedsNonVAMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    procedure hdrMedsInMouseUp(Sender: TObject; Button: TMouseButton;
+      Shift: TShiftState; X, Y: Integer);
+    //procedure ActivateDeactiveRenew(AListBox: TListBox);
+    procedure ViewInfo(Sender: TObject);
+    procedure mnuViewInformationClick(Sender: TObject);
+    procedure mnuOptimizeFieldsClick(Sender: TObject);
+    procedure hdrMedsOutSectionClick(HeaderControl: THeaderControl;
+      Section: THeaderSection);
+    procedure hdrMedsNonVASectionClick(HeaderControl: THeaderControl;
+      Section: THeaderSection);
+    procedure hdrMedsInSectionClick(HeaderControl: THeaderControl;
+      Section: THeaderSection);
   private
     FIterating: Boolean;
@@ -138,6 +170,7 @@
     function GetMedList(Control: TWinControl): TList;
     function GetPharmacyOrders(Control: TWinControl): TStringList;
+    function PatientStatusChanged: boolean;
+    procedure ClearChildODList;
   public
-    function PctOfTotalHeight(thisPanel: TPanel) : integer;
     procedure RefreshMedLists;
     procedure ClearPtData; override;
@@ -148,5 +181,13 @@
     property ParentComplexOrderID: string read FParentComplexOrderID  write FParentComplexOrderID;
     procedure InitfMedsSize;
-  end;
+    procedure SetSectionWidths(Sender: TObject);
+    function GetTotalSectionsWidth(Sender: TObject) : integer;
+    function CheckMedStatus(ActiveList: TListBox): boolean;
+  end;
+
+type
+  arOrigOutPtSecWidths = array[0..6] of integer; //CQ7586
+  arOrigInPtSecWidths = array[0..4] of integer; //CQ7586
+  arOrigNonVASecWidths = array[0..3] of integer; //CQ7586
 
 var
@@ -154,4 +195,9 @@
 //  LargePanelPortion: Integer;
 //  SmallPanelPortion: integer;
+
+  OrigOutPtSecWidths: arOrigOutPtSecWidths; //CQ7586
+  OrigInPtSecWidths : arOrigInPtSecWidths; //CQ7586
+  OrigNonVASecWidths: arOrigNonVASecWidths; //CQ7586
+
   MedOutSize:  double;
   s: string;
@@ -161,7 +207,4 @@
 
   totalHeight: integer;
-  MedOutPctOfTotalHeight: integer;
-  NonVAPctOfTotalHeight: integer;
-  MedInpctOfTotalHeight : integer;
 
   resizedTotalHeight: integer;
@@ -171,14 +214,20 @@
 
   splitterTop: TSplitter;
-  splitterBottom: TSplitter;  
+  splitterBottom: TSplitter;
+
+  oldFont: integer; //CQ9182
+
 
 implementation
 
-uses uCore, fFrame, fRptBox, uOrders, fODBase, fOrdersDC, fOrdersHold,
-     fOrdersRenew, fOMNavA, fOrdersRefill, fMedCopy, fOrders, fODChild, rODBase;
+uses uCore, rCore, fFrame, fRptBox, uOrders, fODBase, fOrdersDC, fOrdersHold,
+     fOrdersRenew, fOMNavA, fOrdersRefill, fMedCopy, fOrders, fODChild, rODBase, 
+     StrUtils, fActivateDeactivate;
 
 {$R *.DFM}
 
 const
+  SMALL_PANEL = 20;
+  LARGE_PANEL = 60;
   COL_MEDNAME = 1;
   DG_OUT = 0;
@@ -215,4 +264,5 @@
 begin
   inherited ClearPtData;
+  ClearChildODList;
   lstMedsIn.Clear;
   lstMedsOut.Clear;
@@ -225,4 +275,5 @@
   uPharmacyOrdersOut.Clear;
   uMedListNonVA.Clear;
+  totalHeight := 0;
 
 end;
@@ -231,4 +282,6 @@
 const
  RATIO_SMALL = 0.13; //0.1866;
+
+
 begin
   inherited DisplayPage;
@@ -251,36 +304,46 @@
 
   if Patient.Inpatient then
-     begin
+  begin
      splitBottom.Align := alNone;
-     hdrMedsIn.Align := alNone;
-
-     lstMedsIn.Parent := pnlTop;
-     lstMedsIn.Align := alClient;
+     hdrMedsIn.Align  := alNone;
+     lstMedsIn.Align   := alNone;
+
+     lstMedsIn.Parent  := pnlTop;
+     lstMedsIn.Align   := alClient;
      lstMedsOut.Parent := pnlMedIn;
 
-     hdrMedsIn.Parent := pnlTop;
-     hdrMedsIn.Align := alTop;
+     hdrMedsIn.Parent  := pnlTop;
+     hdrMedsIn.Align   := alTop;
 
      hdrMedsOut.Parent := pnlMedIn;
-     splitBottom.Align     := alBottom;
-     end
+     splitBottom.Align := alBottom;
+
+     lstMedsIn.Height  := lstMedsIn.Height - 1; // added to cause repaint if user makes area small
+     lstMedsIn.Height  := lstMedsIn.Height + 1; // added to cause repaint if user makes area small.
+     lstMedsOut.Height := lstMedsOut.Height + 1;  // added to cause repaint if user makes area small
+     lstMedsOut.Height := lstMedsOut.Height - 1; // added to cause repaint if user makes area small
+
+  end
   else
      begin
-     splitBottom.Align := alNone;
-     hdrMedsIn.Align := alNone;
-
-     lstMedsIn.Parent := pnlMedIn;
-     lstMedsOut.Parent := pnlTop;
-     lstMedsOut.Align := alClient;
-
-     hdrMedsIn.Parent := pnlMedIn;
-     hdrMedsIn.Align := alTop;
-
-     hdrMedsOut.Parent := pnlTop;
-     splitBottom.Align     := alBottom;
+        splitBottom.Align := alNone;
+        hdrMedsIn.Align   := alNone;
+
+        lstMedsIn.Parent  := pnlMedIn;
+        lstMedsOut.Parent := pnlTop;
+        lstMedsOut.Align  := alClient;
+
+        hdrMedsIn.Parent  := pnlMedIn;
+        hdrMedsIn.Align   := alTop;
+
+        hdrMedsOut.Parent := pnlTop;
+        splitBottom.Align := alBottom;
+
+        lstMedsIn.Height  := lstMedsIn.Height - 1; // added to cause repaint if user makes area small
+        lstMedsIn.Height  := lstMedsIn.Height + 1; // added to cause repaint if user makes area small.
+        lstMedsOut.Height := lstMedsOut.Height + 1;  // added to cause repaint if user makes area small
+        lstMedsOut.Height := lstMedsOut.Height - 1; // added to cause repaint if user makes area small
      end;
-
-
-  RefreshMedLists;
+   RefreshMedLists;
 
 end;
@@ -332,6 +395,9 @@
   if AnOrder <> nil then
   begin
+    //AGP Change 26.24 CQ 7150 fixes the problem with non-va meds initially showing up in the inpatient section
     if uDGrp[DG_OUT] = AnOrder.DGroup then AMedList := uMedListOut;
-    for i := 1 to 6 do if uDGrp[i] = AnOrder.DGroup then AMedList := uMedListIn;
+    If uDGrp[DG_NVA] = AnOrder.DGroup then AMedList := uMedListNonVA;
+    if (AMedList <> uMedListOut) and (AMedList <> uMedListNonVA) then
+      for i := 1 to 6 do if uDGrp[i] = AnOrder.DGroup then AMedList := uMedListIn;
   end;
   case OrderAction of
@@ -409,5 +475,6 @@
       end
       else uPendingChanges.Add(Piece(AnOrder.ActionOn, ';', 1) + '=' +
-                               Piece(AnOrder.ActionOn, '=', 2) + U + AnOrder.ID + '^^' + AnOrder.OrderLocName);
+              Piece(AnOrder.ActionOn, '=', 2) + U + AnOrder.ID + '^^' + AnOrder.OrderLocName);
+
     end; {if AMedList}
   ORDER_CPLXRN:
@@ -450,4 +517,5 @@
 begin
   inherited SetFontSize(FontSize);
+  mnuOptimizeFieldsClick(self);
   if Patient.DFN <> '' then
     RefreshMedLists;
@@ -459,5 +527,4 @@
 var
  medsSplitFnd : boolean;
-  panelBottom, panelMedIn : integer;
   retList : TStringList;
   i: integer;
@@ -486,5 +553,6 @@
   ChildODList := TStringList.Create;
 
-  
+
+
   //DETECT 1st TIME USER.
   //If first time user (medSplitFound=false), then manually set panel heights.
@@ -501,5 +569,5 @@
         if strPos(PChar(x),PChar(MEDS_SPLIT_FORM)) <> nil then
            begin
-           medsSplitFnd := TRUE;
+           medsSplitFnd := False;//TRUE;
            Break;
            end;
@@ -510,11 +578,24 @@
           pnlBottom.Height := frmMeds.Height div 2;
           pnlMedIn.Height := pnlBottom.Height div 2;
-          panelBottom := pnlBottom.Height;
-          panelMedIn  := pnlMedIn.Height;
         end;
      end;
 
-
-
+  //CQ9622
+  if hdrMedsIn.Sections[1].Width < 100 then
+     begin
+     hdrMedsIn.Sections[1].Width := 100;
+     hdrMedsIn.Refresh;
+     end;
+  if hdrMedsNonVA.Sections[1].Width < 100 then
+     begin
+     hdrMedsNonVA.Sections[1].Width := 100;
+     lstMedsNonVA.Refresh;
+     end;
+  if hdrMedsOut.Sections[1].Width < 100 then
+     begin
+     hdrMedsOut.Sections[1].Width := 100;
+     hdrMedsOut.Refresh;
+     end;
+  //end CQ9622
 end;
 
@@ -522,4 +603,5 @@
 begin
   inherited;
+  ClearChildODList;
   ClearMedList(uMedListIn);
   ClearMedList(uMedListOut);
@@ -706,9 +788,10 @@
   result := '';
   Detail := '';
+  if AMed.Status = 'Suspended' then AMed.Status := 'Active/Susp'; //HDS00007547	PSI-03-033 Interim Solution.
   case Column of
     0: result := GetActionText(AMed);
     1: result := GetInstructText(AMed, Detail);
     2: result := FormatFMDateTime('mm/dd/yy', AMed.StopDate);
-    3: result := AMed.Status;
+    3: result :=  AMed.Status;
     4:
      begin
@@ -748,5 +831,6 @@
     TAG_INPT:  result := hdrMedsIn;
 
-    else       result := nil;
+    else       
+    result := nil;
   end;
 end;
@@ -758,5 +842,6 @@
     TAG_NONVA: result := uMedListNonVA;
     TAG_INPT:  result := uMedListIn;
-    else       result := nil;
+    else
+    result := nil;
   end;
 end;
@@ -768,5 +853,5 @@
     TAG_NONVA: result := uNonVAOrdersOut;
     TAG_INPT:  result := uPharmacyOrdersIn;
-  else       
+  else
      result := nil;
   end;
@@ -813,6 +898,5 @@
 end;
 
-procedure TfrmMeds.lstMedsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect;
-  State: TOwnerDrawState);
+procedure TfrmMeds.lstMedsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
 var
   ReturnHt: Integer;
@@ -838,5 +922,13 @@
       begin
         Canvas.Font.Style := [fsBold];
-        if ColorToRGB(clWindowText) = ColorToRGB(clBlack) then
+        //AGP Change 26.29 CQ #8188 Fix for highlighted new meds displaying blue font with a blue background.
+        if odSelected in State  then
+            begin
+              Canvas.Brush.Color := clHighlight;
+              Canvas.Font.Color := clHighlightText;
+              //Canvas.FillRect(ARect);
+              Canvas.Font.Color := clWhite;
+           end;
+        if (ColorToRGB(clWindowText) = ColorToRGB(clBlack)) and (Canvas.Font.Color <> clWhite) then
           Canvas.Font.Color := clBlue;
         if (Length(Piece(AnAction,'^',4)) > 0) then
@@ -851,5 +943,9 @@
           ARect := ItemRect(Index);
           ARect.Left  := RectLeft + 2;
-          ARect.Right := ARect.Left + AHeader.Sections[i].Width - 6;
+          ARect.Right := (ARect.Left + AHeader.Sections[i].Width - 6);
+
+          //if ((ARect.Right - ARect.Left) < 100) then
+              //ARect.Right := ARect.Right + (100 - (ARect.Left + AHeader.Sections[i].Width - 6));
+
           ReturnHt  := DrawText(Canvas.Handle, PChar(x), Length(x), ARect, DT_LEFT or DT_NOPREFIX
                         or DT_WORDBREAK);
@@ -884,4 +980,6 @@
 begin
   inherited;
+  
+  if PatientStatusChanged then exit;
   with lstMedsOut do for i := 0 to Items.Count -1 do
     Selected[i] := false;
@@ -895,4 +993,6 @@
 begin
   inherited;
+ 
+  if PatientStatusChanged then exit;
   with lstMedsIn do for i := 0 to Items.Count -1 do
     Selected[i] := false;
@@ -901,6 +1001,5 @@
 end;
 
-procedure TfrmMeds.hdrMedsOutSectionResize(HeaderControl: THeaderControl;
-  Section: THeaderSection);
+procedure TfrmMeds.hdrMedsOutSectionResize(HeaderControl: THeaderControl; Section: THeaderSection);
 begin
   inherited;
@@ -916,6 +1015,5 @@
 end;
 
-procedure TfrmMeds.hdrMedsInSectionResize(HeaderControl: THeaderControl;
-  Section: THeaderSection);
+procedure TfrmMeds.hdrMedsInSectionResize(HeaderControl: THeaderControl; Section: THeaderSection);
 begin
   inherited;
@@ -926,4 +1024,5 @@
     IntegralHeight := not IntegralHeight;  // listbox window to be recreated
   end;
+
   RedrawActivate(Self.Handle);
   lstMedsIn.Invalidate;
@@ -936,5 +1035,5 @@
 begin
   inherited;
-  //frmFrame.UpdatePtInfoOnRefresh;
+  if PatientStatusChanged then exit;
   if lstMedsOut.SelCount > 0 then
   begin
@@ -972,4 +1071,5 @@
     begin
       ValidateSelected(ActiveList, OA_DC, TX_NO_DC, TC_NO_DC);
+      //ActivateDeactiveRenew(ActiveList); AGP 26.53 TURN OFF UNTIL FINAL DECISION CAN BE MADE
       MakeSelectedList(ActiveList, SelectedList);
       if ExecuteDCOrders(SelectedList,DelEvt) then
@@ -999,4 +1099,5 @@
   if ActiveList = nil then Exit;
   SelectedList := TList.Create;
+  if CheckMedStatus(ActiveList) = True then Exit;
   try
     FIterating := True;
@@ -1034,4 +1135,5 @@
   try
     FIterating := True;
+    if CheckMedStatus(ActiveList) = True then Exit;
     if AuthorizedUser and EncounterPresent and LockedForOrdering then
     begin
@@ -1084,4 +1186,7 @@
   ChangeIFNList := TStringList.Create;
   try
+    FIterating := true;
+    if CheckMedStatus(ActiveList) = True then Exit;
+    ValidateSelected(ActiveList, OA_CHANGE, TX_NO_CHANGE, TC_NO_CHANGE);
     MakeSelectedList(Activelist, SelectedList);
     with SelectedList do for i := 0 to Count - 1 do ChangeIFNList.Add(TOrder(Items[i]).ID);
@@ -1136,4 +1241,5 @@
   DoesDestEvtOccur := False;
   ActiveList := ListSelected(TX_NOSEL);
+  if CheckMedStatus(ActiveList) = True then Exit;
   if ActiveList = nil then Exit;
   NewOrderCreated := False;
@@ -1296,4 +1402,5 @@
   if ActiveList = nil then Exit;
   SelectedList := TList.Create;
+  if CheckMedStatus(ActiveList) = True then Exit;
   try
     FIterating := True;
@@ -1344,5 +1451,5 @@
        begin
          Selected[i] := False;
-         MessageDlg('You can not renew inpatient medication order on a clinic location for selected inpatient.', mtWarning, [mbOK], 0);
+         MessageDlg('You cannot renew inpatient medication orders from a clinic location for selected patient.', mtWarning, [mbOK], 0);
        end;
     CurID := uPendingChanges.Values[Piece(Piece(SomePharmacyOrders[i], U, 2), ';', 1)];
@@ -1412,5 +1519,4 @@
         end;
       end;
-      idx := -1;
       idx := ChildODList.IndexOf(AnOrder.ID);
       if idx > - 1 then
@@ -1426,38 +1532,12 @@
 
 procedure TfrmMeds.SynchListToOrders(AListBox: TListBox; AList: TList);
-{ shows selected med orders as selected }
-//var
-//  i, j: Integer;
-//  AMedListRec: TMedListRec;
-//  AnOrder: TOrder;
-begin
-//  with AListBox do for i := 0 to Items.Count - 1 do
-//  begin
-//    AMedListRec := TMedListRec(AListBox.Items.Objects[i]);
-//    with AList do for j := 0 to Count - 1 do
-//    begin
-//      AnOrder := TOrder(AList.Items[j]);
-//      if Piece(AMedListRec.OrderID, ';', 1) = Piece(AnOrder.ID, ';', 1) then
-//      begin
-//        //AMedListRec.Instruct := AMedListRec.Instruct + ' * EDITED *';
-//        //AMedListRec.Action := MED_NEW;  //*KCM*
-//        //AListBox.Selected[i] := True;   // resets valid selections to indicate changes  //*KCM*
-//      end;
-//    end;
-//  end;
+begin
   AListBox.Invalidate;
 end;
 
-procedure TfrmMeds.pnlMedOut1Resize(Sender: TObject);
-begin
-  inherited;
-  //if pnlMedOut.Height < 20 then pnlMedOut.Height := 20;
-end;
-
-
 procedure TfrmMeds.popMedPopup(Sender: TObject);
 begin
   inherited;
-  //frmFrame.UpdatePtInfoOnRefresh;
+  if PatientStatusChanged then exit;
 end;
 
@@ -1465,5 +1545,5 @@
 begin
   inherited;
-  //frmFrame.UpdatePtInfoOnRefresh;
+  if PatientStatusChanged then exit;  
 end;
 
@@ -1473,4 +1553,5 @@
 begin
   inherited;
+  if PatientStatusChanged then exit;  
   with lstMedsIn do for i := 0 to Items.Count -1 do
      Selected[i] := false;
@@ -1491,6 +1572,5 @@
 end;
 
-procedure TfrmMeds.hdrMedsNonVASectionResize(HeaderControl: THeaderControl;
-  Section: THeaderSection);
+procedure TfrmMeds.hdrMedsNonVASectionResize(HeaderControl: THeaderControl; Section: THeaderSection);
 begin
   inherited;
@@ -1506,21 +1586,38 @@
 end;
 
-function TfrmMeds.PctOfTotalHeight(thisPanel: TPanel) : integer;
-var
-  pctOfTotal: real;
-begin
-  pctOfTotal := ((thisPanel.Height / totalHeight) * 100);
-  Result := Round(pctOfTotal);
+function FontChanged : boolean;
+//CQ9182:  SEE ALSO procedure TfrmFrame.mnuFontSizeClick()
+begin
+  Result := false;
+  if Assigned(frmMeds) then
+  begin
+     if fMeds.oldFont = 0 then Result := False
+     else
+        if (fMeds.oldFont <> MainFontSize)  then
+           Result := true;
+  end;
 end;
 
 procedure TfrmMeds.FormResize(Sender: TObject);
+var
+ maxPanelHeight: integer;
+
 begin
   inherited;
   if Assigned(frmMeds) then
+  begin
+    //CQ9522 v26.51 Make sure all three panels are visible regardless of font size
+    if Assigned(self.Parent) then
      begin
-     //Adjust splitter positions to always be in view, regardless of window size
-     if (pnlBottom.Height > frmMeds.Height-50) then pnlBottom.Height := frmMeds.Height-50;
-     if (pnlMedIn.Height > pnlBottom.Height-50) then pnlMedIn.Height := pnlBottom.Height-50;
-     end;
+      if self.Height > parent.ClientHeight then
+         self.Height := parent.ClientHeight;
+      maxPanelHeight := round((parent.ClientHeight-20)/3);
+      if pnlTop.Height + pnlBottom.Height > parent.ClientHeight then
+        begin
+          pnlBottom.Height := maxPanelHeight*2;
+          pnlTop.Height := maxPanelHeight;
+        end;
+     end;    //assigned(self.parent)
+  end;
 end;
 
@@ -1537,9 +1634,8 @@
   inherited;
   with hdrMedsOut do
-     begin
-     if Height < 16 then Height := 16;
-     if Height > 16 then Height := 16;
+  begin
+     Height := TextHeightByFont(Font.Handle, Sections[0].Text);
      Invalidate;
-     end;
+  end;
 end;
 
@@ -1548,9 +1644,8 @@
   inherited;
   with hdrMedsNonVA do
-     begin
-     if Height < 16 then Height := 16;
-     if Height > 16 then Height := 16;
+  begin
+     Height := TextHeightByFont(Font.Handle, Sections[0].Text);
      Invalidate;
-     end;
+  end;
 end;
 
@@ -1559,9 +1654,8 @@
   inherited;
   with hdrMedsIn do
-     begin
-     if Height < 16 then Height := 16;
-     if Height > 16 then Height := 16;
+  begin
+     Height := TextHeightByFont(Font.Handle, Sections[0].Text);
      Invalidate;
-     end;
+  end;
 end;
 
@@ -1581,5 +1675,5 @@
 begin
   inherited;
-  if splitBottom.Height > 5 then splitBottom.Height := 5;
+  splitBottom.Height := 5;
 end;
 
@@ -1587,5 +1681,5 @@
 begin
   inherited;
-  if splitTop.Height > 5 then splitTop.Height := 5;
+   splitTop.Height := 5;
 end;
 
@@ -1612,5 +1706,5 @@
         x := retList.strings[i];
         if strPos(PChar(x),PChar(MEDS_SPLIT_FORM)) <> nil then
-           begin
+        begin
            medsSplitFnd := TRUE;
            Break;
@@ -1631,4 +1725,331 @@
 end;
 
+function TfrmMeds.PatientStatusChanged: boolean;
+const
+
+  msgTxt1 = 'Patient status was changed from ';
+  msgTxt2 = 'CPRS needs to refresh patient information to display patient latest record.';
+   //GE CQ9537  - Change message text
+  msgTxt3 = 'Patient has been admitted.';
+  msgTxt4 = CRLF +'You will be prompted to sign your orders.  Any new orders subsequently' +
+            CRLF + 'entered and signed will be directed to the inpatient staff.';
+
+var
+  PtSelect: TPtSelect;
+  IsInpatientNow: boolean;
+  ptSts: string;
+begin
+  result := False;
+  SelectPatient(Patient.DFN, PtSelect);
+  IsInpatientNow := Length(PtSelect.Location) > 0;
+   //GE CQ9537  - Change message text
+  if Patient.Inpatient <> IsInpatientNow then
+  begin
+    if (not Patient.Inpatient) then MessageDlg(msgTxt3 + msgTxt4, mtWarning, [mbOK], 0);
+    if Patient.Inpatient then ptSts := 'Inpatient to Outpatient.';
+    MessageDlg(msgTxt1 + ptSts + #13#10#13 + msgTxt2, mtWarning, [mbOK], 0);
+    frmFrame.mnuFileRefreshClick(Application);
+    Result := True;
+  end;
+end;
+
+function TfrmMeds.GetTotalSectionsWidth(Sender: TObject) : integer;
+//CQ7586
+//Return stored values of column widths
+var
+  i: integer;
+begin
+  Result := 0;
+
+  if (Sender as THeaderControl).Name = 'hdrMedsOut' then
+     for i := 0 to hdrMedsOut.Sections.Count - 1 do
+        Result := Result + hdrMedsOut.Sections[i].Width;
+
+  if (Sender as THeaderControl).Name = 'hdrMedsIn' then
+     for i := 0 to hdrMedsIn.Sections.Count - 1 do
+        Result := Result + hdrMedsIn.Sections[i].Width;
+
+  if (Sender as THeaderControl).Name = 'hdrMedsNonVA' then
+     for i := 0 to hdrMedsNonVA.Sections.Count - 1 do
+        Result := Result + hdrMedsNonVA.Sections[i].Width;
+end;
+
+procedure TfrmMeds.SetSectionWidths(Sender: TObject);
+//CQ7586
+//Copy values of column widths into array variables.
+var
+  i: integer;
+begin
+  if (Sender as THeaderControl).Name = 'hdrMedsOut' then
+     for i := 0 to hdrMedsOut.Sections.Count - 1 do
+        OrigOutPtSecWidths[i] := hdrMedsOut.Sections[i].Width;
+
+  if (Sender as THeaderControl).Name = 'hdrMedsIn' then
+     for i := 0 to hdrMedsIn.Sections.Count - 1 do
+        OrigInPtSecWidths[i] := hdrMedsIn.Sections[i].Width;
+
+  if (Sender as THeaderControl).Name = 'hdrMedsNonVA' then
+     for i := 0 to hdrMedsNonVA.Sections.Count - 1 do
+        OrigNonVASecWidths[i] := hdrMedsNonVA.Sections[i].Width;
+end;
+
+procedure TfrmMeds.hdrMedsOutMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  inherited;
+  Self.SetSectionWidths(Sender); //CQ7586
+end;
+
+procedure TfrmMeds.hdrMedsNonVAMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  inherited;
+  Self.SetSectionWidths(Sender); //CQ7586
+end;
+
+procedure TfrmMeds.hdrMedsInMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+begin
+  inherited;
+  Self.SetSectionWidths(Sender); //CQ7586
+end;
+
+procedure TfrmMeds.hdrMedsOutMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+//CQ7586
+var
+  i: integer;
+  totalSectionsWidth, originalwidth: integer;
+begin
+  inherited;
+  totalSectionsWidth := Self.GetTotalSectionsWidth(Sender);
+  if totalSectionsWidth > lstMedsOut.Width - 5 then  //could used any of the three list boxes here, since all are same width
+  begin
+    originalwidth := 0;
+    for i := 0 to hdrMedsOut.Sections.Count - 1 do
+      originalwidth := originalwidth + OrigOutPtSecWidths[i];
+    if originalwidth < totalSectionsWidth then
+    begin
+      for i := 0 to hdrMedsOut.Sections.Count - 1 do
+        hdrMedsOut.Sections[i].Width := OrigOutPtSecWidths[i];
+      lstMedsOut.Invalidate;
+    end;
+  end;
+  //CQ9622
+  if hdrMedsOut.Sections[1].Width < 100 then
+  begin
+    hdrMedsOut.Sections[1].Width := 100;
+    lstMedsOut.Refresh;
+  end;
+  //end CQ9622
+  pnlBottom.Height := pnlBottom.Height - 1;  // forces autopanel resize
+  pnlBottom.Height := pnlBottom.Height + 1;  // forces autopanel resize
+end;
+
+procedure TfrmMeds.hdrMedsNonVAMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+//CQ7586
+var
+  i: integer;
+  totalSectionsWidth, originalwidth: integer;
+begin
+  inherited;
+  totalSectionsWidth := Self.GetTotalSectionsWidth(Sender);
+  if totalSectionsWidth > lstMedsNonVA.Width - 5 then  //could used any of the three list boxes here, since all are same width
+  begin
+    originalwidth := 0;
+    for i := 0 to hdrMedsNonVA.Sections.Count - 1 do
+      originalwidth := originalwidth + OrigNonVASecWidths[i];
+    if originalwidth < totalSectionsWidth then
+    begin
+      for i := 0 to hdrMedsNonVA.Sections.Count - 1 do
+        hdrMedsNonVA.Sections[i].Width := OrigNonVASecWidths[i];
+      lstMedsNonVA.Invalidate;
+    end;
+  end;
+  //CQ9622
+  if hdrMedsNonVA.Sections[1].Width < 100 then
+  begin
+    hdrMedsNonVA.Sections[1].Width := 100;
+    lstMedsNonVA.Refresh;
+  end;
+  //end CQ9622
+  pnlNonVA.Height := pnlNonVA.Height - 1;  // forces autopanel resize
+  pnlNonVA.Height := pnlNonVA.Height + 1;  // forces autopanel resize
+end;
+
+procedure TfrmMeds.hdrMedsInMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
+//CQ7586
+var
+  i: integer;
+  totalSectionsWidth, originalwidth: integer;
+begin
+  inherited;
+  totalSectionsWidth := Self.GetTotalSectionsWidth(Sender);
+  if totalSectionsWidth > lstMedsIn.Width - 5 then  //could used any of the three list boxes here, since all are same width
+  begin
+    originalwidth := 0;
+    for i := 0 to hdrMedsIn.Sections.Count - 1 do
+      originalwidth := originalwidth + OrigInPtSecWidths[i];
+    if originalwidth < totalSectionsWidth then
+    begin
+      for i := 0 to hdrMedsIn.Sections.Count - 1 do
+        hdrMedsIn.Sections[i].Width := OrigInPtSecWidths[i];
+      lstMedsIn.Invalidate;
+    end;
+  end;
+  //CQ9622
+  if hdrMedsIn.Sections[1].Width < 100 then
+  begin
+    hdrMedsIn.Sections[1].Width := 100;
+    lstMedsIn.Refresh;
+  end;
+  //end CQ9622
+  pnlBottom.Height := pnlBottom.Height - 1;  // forces autopanel resize
+  pnlBottom.Height := pnlBottom.Height + 1;  // forces autopanel resize
+end;
+
+procedure TfrmMeds.ClearChildODList;
+var
+  i: integer;
+begin
+  for i := 0 to ChildODList.count-1 do
+    if(assigned(ChildODList.Objects[i])) then
+      ChildODList.Objects[i].Free;
+  ChildODList.Clear;
+end;
+
+function TfrmMeds.CheckMedStatus(ActiveList: TListBox): boolean;
+var
+i: integer;
+tmpList: TStringList;
+Str: string;
+AMed: TMedListRec;
+AMedList: TList;
+
+begin
+ result := False;
+ tmpList:= TStringList.Create;
+ if TMedListRec = nil then exit;
+ AMedList := GetMedList(ActiveList);
+ for i := 0 to ActiveList.Count - 1 do if ActiveList.Selected[i] then
+    begin
+       AMed := TMedListRec(AMedList[i]);
+       str := Amed.PharmID + U + AMed.Status;
+       tmpList.Add(Str);
+      end;
+ if tmpList <> nil then
+   begin
+     Result := GetMedStatus(tmpList);
+     tmpList.Free;
+   end;
+ if Result = True then
+     begin
+       MessageDlg('The Medication status has change.' + #13#10#13 + 'CPRS needs to refresh patient information to display the correct medication status', mtWarning, [mbOK], 0);
+       frmFrame.mnuFileRefreshClick(Application);
+     end;
+end;
+
+(*procedure TfrmMeds.ActivateDeactiveRenew(AListBox: TListBox);
+var
+  i: Integer;
+  CurID: string;
+  SomePharmacyOrders: TStringList;
+  tmpArr: TStringList;
+begin
+    tmpArr := TStringList.Create;
+    SomePharmacyOrders := GetPharmacyOrders(AListBox);
+    with AListBox do for i := 0 to Items.Count - 1 do if Selected[i] then
+      begin
+        CurID := uPendingChanges.Values[Piece(Piece(SomePharmacyOrders[i], U, 2), ';', 1)];
+        if Length(CurID) > 0 then CurID := Piece(CurID, U, 2)
+        else CurID := Piece(SomePharmacyOrders[i], U, 2);
+        tmpArr.Add(curID);
+      end;
+    if tmpArr <> nil then frmActivateDeactive.fActivateDeactive(tmpArr, AListBox);
+end; *)
+
+procedure TfrmMeds.ViewInfo(Sender: TObject);
+begin
+  inherited;
+  frmFrame.ViewInfo(Sender);
+end;
+
+procedure TfrmMeds.mnuViewInformationClick(Sender: TObject);
+begin
+  inherited;
+  mnuViewDemo.Enabled := frmFrame.pnlPatient.Enabled;
+  mnuViewVisits.Enabled := frmFrame.pnlVisit.Enabled;
+  mnuViewPrimaryCare.Enabled := frmFrame.pnlPrimaryCare.Enabled;
+  mnuViewMyHealtheVet.Enabled := not (Copy(frmFrame.laMHV.Hint, 1, 2) = 'No');
+  mnuInsurance.Enabled := not (Copy(frmFrame.laVAA2.Hint, 1, 2) = 'No');
+  mnuViewFlags.Enabled := frmFrame.lblFlag.Enabled;
+  mnuViewRemoteData.Enabled := frmFrame.lblCirn.Enabled;
+  mnuViewReminders.Enabled := frmFrame.pnlReminders.Enabled;
+  mnuViewPostings.Enabled := frmFrame.pnlPostings.Enabled;
+end;
+
+procedure TfrmMeds.mnuOptimizeFieldsClick(Sender: TObject);
+var
+  totalSectionsWidth, unit1, unit2, unit8: integer;
+begin
+  totalSectionsWidth := pnlTop.Width - 5;
+  if totalSectionsWidth < 16 then exit;
+  unit1 := (totalSectionsWidth div 16) - 1;
+  unit2 := unit1 * 2;
+  unit8 := unit1 * 8;
+
+  with hdrMedsNonVA do
+  begin
+    Sections[0].Width := unit1;
+    Sections[1].Width := unit8;
+    Sections[2].Width := unit2;
+    Sections[3].Width := unit2;
+  end;
+  hdrMedsNonVASectionResize(hdrMedsNonVA, hdrMedsNonVA.Sections[0]);
+  hdrMedsNonVA.Repaint;
+
+  with hdrMedsIn do
+  begin
+    Sections[0].Width := unit1;
+    Sections[1].Width := unit8;
+    Sections[2].Width := unit2;
+    Sections[3].Width := unit2;
+    Sections[4].Width := unit2;
+  end;
+  hdrMedsInSectionResize(hdrMedsIn, hdrMedsIn.Sections[0]);
+  hdrMedsIn.Repaint;
+  with hdrMedsOut do
+  begin
+    Sections[0].Width := unit1;
+    Sections[1].Width := unit8;
+    Sections[2].Width := unit2;
+    Sections[3].Width := unit2;
+    Sections[4].Width := unit2;
+    Sections[5].Width := unit1;
+  end;
+  hdrMedsOutSectionResize(hdrMedsOut, hdrMedsOut.Sections[0]);
+  hdrMedsOut.Repaint;
+end;
+
+procedure TfrmMeds.hdrMedsOutSectionClick(HeaderControl: THeaderControl;
+  Section: THeaderSection);
+begin
+  inherited;
+  //if Section = hdrMedsOut.Sections[1] then
+    mnuOptimizeFieldsClick(self);
+end;
+
+procedure TfrmMeds.hdrMedsNonVASectionClick(HeaderControl: THeaderControl;
+  Section: THeaderSection);
+begin
+  inherited;
+  //if Section = hdrMedsNonVA.Sections[1] then
+    mnuOptimizeFieldsClick(self);
+end;
+
+procedure TfrmMeds.hdrMedsInSectionClick(HeaderControl: THeaderControl;
+  Section: THeaderSection);
+begin
+  inherited;
+  //if Section = hdrMedsIn.Sections[1] then
+    mnuOptimizeFieldsClick(self);
+end;
+
 end.
 
