Index: cprs/trunk/CPRS-Chart/uCore.pas
===================================================================
--- cprs/trunk/CPRS-Chart/uCore.pas	(revision 456)
+++ cprs/trunk/CPRS-Chart/uCore.pas	(revision 830)
@@ -159,10 +159,11 @@
     destructor Destroy; override;
     procedure Clear;
+    procedure EncounterSwitch(Loc: integer; LocName, LocText: string; DT: TFMDateTime; vCat: Char);
     function NeedVisit: Boolean;
     property DateTime:      TFMDateTime read FDateTime  write SetDateTime;
     property Inpatient:     Boolean     read FInpatient write SetInpatient;
     property Location:      Integer     read FLocation  write SetLocation;
-    property LocationName:  string      read GetLocationName;
-    property LocationText:  string      read GetLocationText;
+    property LocationName:  string      read GetLocationName write FLocationName;
+    property LocationText:  string      read GetLocationText write FLocationText;
     property Provider:      Int64       read FProvider  write SetProvider;
     property ProviderName:  string      read GetProviderName;
@@ -181,6 +182,10 @@
     FSignState: Integer;
     FParentID : string;
+    FUser     : Int64;
+    FOrderDG  : String;
+    FDCOrder  : boolean;
+    FDelay    : boolean;
     constructor Create(AnItemType: Integer; const AnID, AText, AGroupName: string;
-      ASignState: Integer; AParentID: string = '');
+      ASignState: Integer; AParentID: string = ''; User: int64 = 0; OrderDG: string = ''; DCOrder: boolean = False; Delay: boolean = False);
   public
     property ItemType:  Integer read FItemType;
@@ -190,4 +195,8 @@
     property SignState: Integer read FSignState write FSignState;
     property ParentID : string  read FParentID;
+    property User: Int64 read FUser write FUser;
+    property OrderDG: string read FOrderDG write FOrderDG;
+    property DCOrder: boolean read FDCOrder write FDCOrder;
+    property Delay: boolean read FDelay write FDelay;
   end;
 
@@ -208,5 +217,6 @@
     constructor Create;
     destructor Destroy; override;
-    procedure Add(ItemType: Integer; const AnID, ItemText, GroupName: string; SignState: Integer; AParentID: string = '');
+    procedure Add(ItemType: Integer; const AnID, ItemText, GroupName: string; SignState: Integer; AParentID: string = '';
+                  User: int64 = 0; OrderDG: String = ''; DCOrder: boolean = FALSE; Delay: boolean = FALSE);
     procedure Clear;
     function CanSign: Boolean;
@@ -367,4 +377,9 @@
   TempEncounterLoc: Integer; // used to Save Encounter Location when user selected "Review Sign Changes" from "File"
   TempEncounterLocName: string; // since in the path PatientRefresh is done prior to checking if patient has been admitted while entering OPT orders.
+  TempEncounterText: string;
+  TempEncounterDateTime: TFMDateTime;
+  TempEncounterVistCat: Char;
+  //TempOutEncounterLoc: Integer;
+  //TempOutEncounterLocName: string;
 
 procedure NotifyOtherApps(const AppEvent, AppData: string);
@@ -372,4 +387,6 @@
 procedure TerminateOtherAppNotification;
 procedure GotoWebPage(const URL: WideString);
+function AllowAccessToSensitivePatient(NewDFN: string; var AccessStatus: integer): boolean;
+
 
 implementation
@@ -410,4 +427,46 @@
   SHORT_BROADCAST_TIMEOUT = 2000; // 2 seconds
   MSG_TYPE: array[TMsgType] of String = ('V','D');
+
+function AllowAccessToSensitivePatient(NewDFN: string; var AccessStatus: integer): boolean;
+const
+  TX_DGSR_ERR    = 'Unable to perform sensitive record checks';
+  TC_DGSR_ERR    = 'Error';
+  TC_DGSR_SHOW   = 'Restricted Record';
+  TC_DGSR_DENY   = 'Access Denied';
+  TX_DGSR_YESNO  = CRLF + 'Do you want to continue processing this patient record?';
+  TC_NEXT_NOTIF  = 'NEXT NOTIFICATION:  ';
+var
+  //AccessStatus: integer;
+  AMsg, PrefixC, PrefixT: string;
+begin
+  Result := TRUE;
+  if Notifications.Active then
+  begin
+    PrefixT := Piece(Notifications.RecordID, U, 1) + CRLF + CRLF;
+    PrefixC := TC_NEXT_NOTIF;
+  end
+  else
+  begin
+    PrefixT := '';
+    PrefixC := '';
+  end;
+  CheckSensitiveRecordAccess(NewDFN, AccessStatus, AMsg);
+  case AccessStatus of
+  DGSR_FAIL: begin
+               InfoBox(PrefixT + TX_DGSR_ERR, PrefixC + TC_DGSR_ERR, MB_OK);
+               Result := FALSE;
+             end;
+  DGSR_NONE: { Nothing - allow access to the patient. };
+  DGSR_SHOW: InfoBox(PrefixT + AMsg, PrefixC + TC_DGSR_SHOW, MB_OK);
+  DGSR_ASK:  if InfoBox(PrefixT + AMsg + TX_DGSR_YESNO, PrefixC + TC_DGSR_SHOW, MB_YESNO or MB_ICONWARNING or
+               MB_DEFBUTTON2) = IDYES then LogSensitiveRecordAccess(NewDFN)
+             else Result := FALSE;
+  else       begin
+               InfoBox(PrefixT + AMsg, PrefixC + TC_DGSR_DENY, MB_OK);
+               if Notifications.Active then Notifications.DeleteForCurrentUser;
+               Result := FALSE;
+             end;
+  end;
+end;
 
 function QueuePending: boolean;
@@ -740,4 +799,13 @@
 end;
 
+procedure TEncounter.EncounterSwitch(Loc: integer; LocName, LocText: string; DT: TFMDateTime; vCat: Char);
+begin
+ Encounter.Location := Loc;
+ Encounter.LocationName := LocName;
+ Encounter.LocationText := LocText;
+ Encounter.VisitCategory := vCat;
+ Encounter.DateTime := DT;;
+end;
+
 procedure TEncounter.Clear;
 { clears all the fields of an Encounter (usually done upon patient selection }
@@ -887,5 +955,5 @@
 
 constructor TChangeItem.Create(AnItemType: Integer; const AnID, AText, AGroupName: string;
-  ASignState: Integer; AParentID: string);
+  ASignState: Integer; AParentID: string; user: int64; OrderDG: string; DCOrder, Delay: boolean);
 begin
   FItemType  := AnItemType;
@@ -895,4 +963,8 @@
   FSignState := ASignState;
   FParentID  := AParentID;
+  FUser      := User;
+  FOrderDG   := OrderDG;
+  FDCOrder   := DCOrder;
+  FDelay     := Delay;
 end;
 
@@ -921,5 +993,5 @@
 
 procedure TChanges.Add(ItemType: Integer; const AnID, ItemText, GroupName: string;
-  SignState: Integer; AParentID: string);
+  SignState: Integer; AParentID: string; User: int64; OrderDG: String; DCOrder, Delay: boolean);
 var
   i: Integer;
@@ -948,5 +1020,5 @@
   if not Found then
   begin
-    NewChangeItem := TChangeItem.Create(ItemType, AnID, ItemText, GroupName, SignState, AParentID);
+    NewChangeItem := TChangeItem.Create(ItemType, AnID, ItemText, GroupName, SignState, AParentID, User, OrderDG, DCOrder, Delay);
     case ItemType of
     CH_DOC: begin
@@ -1213,5 +1285,6 @@
 { retrieves unsigned orders outside this session based on OR UNSIGNED ORDERS ON EXIT }
 var
-  i, CanSign: Integer;
+  i, CanSign(*, OrderUser*): Integer;
+  OrderUser: int64;
   AnID: string;
   HaveOrders, OtherOrders: TStringList;
@@ -1235,6 +1308,8 @@
     for i := 0 to Pred(OtherOrders.Count) do
     begin
-      AnID := OtherOrders[i];
-      Add(CH_ORD, AnID, TextForOrder(AnID), 'Other Unsigned', CanSign);
+      AnID := Piece(OtherOrders[i],U,1);
+      if Piece(OtherOrders[i],U,2) = '' then OrderUser := 0
+      else OrderUser := StrtoInt64(Piece(OtherOrders[i],U,2));
+      Add(CH_ORD, AnID, TextForOrder(AnID), 'Other Unsigned', CanSign,'', OrderUser);
     end;
   finally
