Index: cprs/branches/foia-cprs/CPRS-Chart/fPtSel.pas
===================================================================
--- cprs/branches/foia-cprs/CPRS-Chart/fPtSel.pas	(revision 459)
+++ cprs/branches/foia-cprs/CPRS-Chart/fPtSel.pas	(revision 460)
@@ -3,4 +3,6 @@
 
 {$OPTIMIZATION OFF}                              // REMOVE AFTER UNIT IS DEBUGGED
+
+{$define VAA}
 
 interface
@@ -77,4 +79,6 @@
     FsortAscending: boolean;
     FLastPt: string;
+    FsortDirection: string;
+    FUserCancelled: boolean;
     procedure AdjustFormSize(ShowNotif: Boolean; FontSize: Integer);
     procedure ClearIDInfo;
@@ -85,9 +89,10 @@
     procedure RPLDisplay;
     procedure AlertList;
+    procedure ReformatAlertDateTime;
   public
     procedure Loaded; override;
   end;
 
-procedure SelectPatient(ShowNotif: Boolean; FontSize: Integer);
+procedure SelectPatient(ShowNotif: Boolean; FontSize: Integer; var UserCancelled: boolean);
 
 var
@@ -114,5 +119,5 @@
   AliasString = ' -- ALIAS';
 
-procedure SelectPatient(ShowNotif: Boolean; FontSize: Integer);
+procedure SelectPatient(ShowNotif: Boolean; FontSize: Integer; var UserCancelled: boolean);
 { displays patient selection dialog (with optional notifications), updates Patient object }
 var
@@ -137,9 +142,12 @@
         end;
       Notifications.Clear;
+      FsortCol := -1;
       AlertList;
       ClearIDInfo;
       if (IsRPL = '1') then                          // Deal with restricted patient list users.
         RPLDisplay;                                  // Removes unnecessary components from view.
+      FUserCancelled := FALSE;
       ShowModal;
+      UserCancelled := FUserCancelled;
     end;
   finally
@@ -539,8 +547,9 @@
   if User.IsProvider then Encounter.Provider := User.DUZ;
 
-  GetBAStatus(Encounter.Provider,Encounter.Location);
+  GetBAStatus(Encounter.Provider,Patient.DFN);
   //HDS00005025
-   if BILLING_AWARE then
-     if Assigned(UBAGLOBALS.BAOrderList) then UBAGLOBALS.BAOrderList.Clear;
+  if BILLING_AWARE then
+    if Assigned(UBAGLOBALS.BAOrderList) then UBAGLOBALS.BAOrderList.Clear;
+  FUserCancelled := FALSE;
   Close;
 end;
@@ -549,4 +558,5 @@
 begin
   // Leave Patient object unchanged
+  FUserCancelled := TRUE;
   Close;
 end;
@@ -633,9 +643,12 @@
         lstvAlerts.Clear;
         AlertList;
+        //display alerts sorted according to parameter settings:
+        FsortCol := -1;     //CA - display alerts in correct sort
+        FormShow(Sender);
       end;
     if Items.Count = 0 then ShowButts(False);
     if SelCount <= 0 then ShowButts(False);
   end;
-  GetBAStatus(User.DUZ,Encounter.Location);
+  GetBAStatus(User.DUZ,Patient.DFN);
 end;
 
@@ -723,5 +736,5 @@
   lstvAlerts.Clear;
   AlertList;
-  FsortCol := 0;     //CA - display alerts in correct sort
+  FsortCol := -1;     //CA - display alerts in correct sort
   FormShow(Sender);  //CA - display alerts in correct sort
   if lstvAlerts.Items.Count = 0 then ShowButts(False);
@@ -805,5 +818,5 @@
 function ConvertDate(var thisList: TStringList; listIndex: integer) : string;
 {
- CQ1075: Convert date portion from yyyy/mm/dd to mm/dd/yyyy
+ Convert date portion from yyyy/mm/dd to mm/dd/yyyy
 }
 var
@@ -887,6 +900,5 @@
      for I := 0 to List.Count - 1 do
        begin
-       //CQ1075: Convert date portion from yyyy/mm/dd to mm/dd/yyyy
-       List[i] := ConvertDate(List, i);
+    //   List[i] := ConvertDate(List, i);  //cla commented out 8/9/04 CQ #4749
 
          if Piece(List[I], U, 1) <> 'Forwarded by: ' then
@@ -929,25 +941,30 @@
 
   if ((FsortCol = Column.Index) and (not SortViaKeyboard)) then
-        FsortAscending := not FsortAscending
+     FsortAscending := not FsortAscending;
+
+  if FsortAscending then
+     FsortDirection := 'F'
   else
-     if Column.Index = 4 then
-        FsortAscending := false
-     else
-        FsortAscending := true;
+     FsortDirection := 'R';
 
   FsortCol := Column.Index;
-  lstvAlerts.AlphaSort;
+
+  if FsortCol = 4 then
+    ReformatAlertDateTime //  hds7397- ge 2/6/6 sort and display date/time column correctly - as requested
+  else
+     lstvAlerts.AlphaSort;
   SortViaKeyboard := false;
+
 
   //Set the Notifications sort method to last-used sort-type
   //ie., user clicked on which column header last use of CPRS?
   case Column.Index of
-     0: rCore.SetSortMethod('I');
-     1: rCore.SetSortMethod('P');
-     2: rCore.SetSortMethod('L');
-     3: rCore.SetSortMethod('U');
-     4: rCore.SetSortMethod('D');
-     5: rCore.SetSortMethod('M');
-     6: rCore.SetSortMethod('F');
+     0: rCore.SetSortMethod('I', FsortDirection);
+     1: rCore.SetSortMethod('P', FsortDirection);
+     2: rCore.SetSortMethod('L', FsortDirection);
+     3: rCore.SetSortMethod('U', FsortDirection);
+     4: rCore.SetSortMethod('D', FsortDirection);
+     5: rCore.SetSortMethod('M', FsortDirection);
+     6: rCore.SetSortMethod('F', FsortDirection);
   end;
 end;
@@ -1022,5 +1039,5 @@
 //    pnlPrf.Visible := True;
   end
-//  else pnlPrf.Visible := False;
+  //else pnlPrf.Visible := False;
 end;
 
@@ -1043,5 +1060,5 @@
   if lstvAlerts.SelCount <= 0 then ShowButts(False)
   else ShowButts(True);
-  GetBAStatus(User.DUZ,Encounter.Location);
+  GetBAStatus(User.DUZ,Patient.DFN);
 end;
 
@@ -1100,7 +1117,14 @@
 }
 var
+  sortResult: string;
   sortMethod: string;
 begin
-  sortMethod := rCore.GetSortMethod;
+  sortResult := rCore.GetSortMethod;
+  sortMethod := Piece(sortResult, U, 1);
+  FsortDirection := Piece(sortResult, U, 2);
+  if FsortDirection = 'F' then
+     FsortAscending := true
+  else
+     FsortAscending := false;
 
   case sortMethod[1] of
@@ -1115,4 +1139,37 @@
 end;
 
+//hds7397- ge 2/6/6 sort and display date/time column correctly - as requested
+procedure  TfrmPtSel.ReformatAlertDateTime;
+var
+  I,J: Integer;
+  inDateStr, holdDayTime,srtDate: String;
+begin
+  // convert date to yyyy/mm/dd prior to sort.
+ for J := 0 to lstvAlerts.items.count -1 do
+  begin
+    inDateStr := '';
+    srtDate := '';
+    holdDayTime := '';
+    inDateStr := lstvAlerts.Items[j].SubItems[3];
+    srtDate := ( (Piece( Piece(inDateStr,'/',3), '@',1)) + '/' + Piece(inDateStr,'/',1) + '/' + Piece(inDateStr,'/',2) +'@'+ Piece(inDateStr, '@',2) );
+    lstvAlerts.Items[j].SubItems[3] := srtDate;
+  end;
+   //sort the listview records by date
+  lstvAlerts.AlphaSort;
+ // loop thru lstvAlerts change date to yyyy/mm/dd
+ // sort list
+ // change alert date/time back to mm/dd/yyyy@time for display
+  for I := 0 to lstvAlerts.items.Count -1 do
+   begin
+     inDateStr := '';
+     srtDate := '';
+     holdDayTime := '';
+     inDateStr :=   lstvAlerts.Items[i].SubItems[3];
+     holdDayTime := Piece(inDateStr,'/',3);  // dd@time
+     lstvAlerts.Items[i].SubItems[3] := (Piece(inDateStr, '/', 2) + '/' + Piece(holdDayTime, '@',1) +'/'
+                                            + Piece(inDateStr,'/',1) + '@' + Piece(holdDayTime,'@',2) );
+  end;
+end;
+
 Initialization
   SortViaKeyboard := false;
