Index: cprs/trunk/CPRS-Chart/fReminderDialog.pas
===================================================================
--- cprs/trunk/CPRS-Chart/fReminderDialog.pas	(revision 830)
+++ cprs/trunk/CPRS-Chart/fReminderDialog.pas	(revision 1679)
@@ -7,5 +7,5 @@
   ExtCtrls, ORFn, StdCtrls, ComCtrls, Buttons, ORCtrls, uReminders, uConst,
   ORClasses, fRptBox, Menus, rPCE, uTemplates,fBase508Form,
-  VA508AccessibilityManager, fMHTest;
+  VA508AccessibilityManager, fMHTest, fFrame;
 
 type
@@ -42,5 +42,7 @@
     procedure btnVisitClick(Sender: TObject);
     procedure KillDlg(ptr: Pointer; ID: string; KillObjects: boolean = FALSE);
-    procedure FormShow(Sender: TObject); //AGP Change 24.8
+    procedure FormShow(Sender: TObject);
+    procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
+      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); //AGP Change 24.8
   private
     FSCCond: TSCConditions;
@@ -82,4 +84,5 @@
     procedure ClinMaintDestroyed(Sender: TObject);
     procedure ProcessTemplate(Template: TTemplate);
+    procedure ClearMHTest(Rien: string);
   public
     procedure ProcessReminder(ARemData: string; NodeID: string);
@@ -199,5 +202,8 @@
         begin
           if(OwningForm = frmNotes) then
-            frmNotes.AssignRemForm
+            begin
+              frmNotes.AssignRemForm;
+              if FutureEncounter(RemForm.PCEObj) then Err := 'Can not process a reminder dialog for a future encounter date.';
+            end
           else
           if(OwningForm = frmConsults) then
@@ -209,4 +215,6 @@
       end;
     end;
+    if (Err = '') and (FutureEncounter(RemForm.PCEObj)) then
+       Err := 'Can not process a reminder dialog for a future encounter date.';
     if Err <> '' then
     begin
@@ -254,5 +262,5 @@
 var
   own: TComponent;
-
+  
 begin
   if assigned(RemNode) then
@@ -419,4 +427,17 @@
 end;
 
+procedure TfrmRemDlg.FormMouseWheel(Sender: TObject; Shift: TShiftState;
+  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
+var
+  box: TScrollBox;
+begin
+  box := GetBox(TRUE);
+  If RectContains(box.BoundsRect, box.ScreenToClient(MousePos)) then
+  begin
+    ScrollControl(box, (WheelDelta > 0));
+    Handled := True;
+  end;
+end;
+
 procedure TfrmRemDlg.ClearControls(All: boolean = FALSE);
 
@@ -445,4 +466,60 @@
   else
     WipeOutControls(GetBox);
+end;
+
+procedure TfrmRemDlg.ClearMHTest(Rien: string);
+var
+MHKillArray: TStringList;
+i,idx, j: integer;
+TestName: string;
+begin
+  MHKillArray := TStringList.Create;
+  idx := RemindersInProcess.IndexOf(RIEN);
+  //Find All MH Test in the current Reminders and stored them in a temp Array
+  if idx > -1 then
+    begin
+       if (TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray <> nil) and
+       (TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Count > 0) then
+         begin
+           for j := 0 to TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Count - 1 do
+             begin
+               TestName := Piece(TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Strings[j], U, 1);
+               //TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Delete(j);
+               MHKillArray.Add(TestName);
+             end;
+         end;
+       if Assigned(TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray) then
+          TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Free;
+      (* if (TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray <> nil) and
+       (TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Count = 0) then
+          TReminderDialog(TReminder(RemindersInProcess.Objects[idx])).MHTestArray.Free; *)
+    end;
+  //Check to see if other reminders contains any of the MH test in the temp Array if so set entry to null
+  if (MHKillArray.Count > 0) and (RemindersInProcess.Count > 1) then
+    begin
+      for I := 0 to RemindersInProcess.Count - 1 do
+        begin
+          if (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).IEN <> RIEN) and
+             (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray <> nil) and
+             (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Count > 0) then
+               begin
+                  for j := 0 to TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Count - 1 do
+                    begin
+                      TestName := Piece(TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Strings[j], U, 1);
+                      idx := MHKillArray.IndexOf(TestName);
+                      if idx > -1 then MHKillArray.Strings[idx] := '';
+                    end;
+               end;
+        end;
+    end;
+  //Delete the temp file stored in the MH dll for any MH tests names left in the temp array
+  if MHKillArray.Count > 0 then
+    begin
+      for I := 0 to MHKillArray.Count - 1 do
+        begin
+          if MHKillArray.Strings[i] <> '' then RemoveMHTest(MHKillArray.Strings[i]);
+        end;
+    end;
+  if Assigned(MHKillArray) then FreeandNil(MHKillArray);
 end;
 
@@ -748,6 +825,5 @@
       if(OK) then
       begin
-        FReminder.ClearMHTest(FReminder.IEN);
-        if (FReminder.MHTestArray <> nil) and (FReminder.MHTestArray.Count = 0) then FReminder.MHTestArray.Free;
+        ClearMHTest(Freminder.IEN);
         RemindersInProcess.Delete(i);
         Tmp := (FReminder as TReminder).RemData; // clear should never be active if template
@@ -782,5 +858,5 @@
   i, cnt: integer;
   msg, RemWipe: string;
-  ClearMH: boolean;
+  //ClearMH: boolean;
 
 begin
@@ -788,9 +864,22 @@
  //flag the patient specific dialog to be destroy if not in process.
  RemWipe := '';
- ClearMH := false;
+ //ClearMH := false;
+  if frmFrame.TimedOut = True then
+     begin
+       result := True;
+       Exit;
+     end;
   if FProcessingTemplate or FSilent then
     begin
       Result := TRUE;
       if FReminder.RemWipe = 1 then RemWipe := Piece(FReminder.DlgData,U,1);
+      if (FProcessingTemplate) and (FReminder.Processing) then
+          begin
+            msg := msg + '  ' + FReminder.PrintName + CRLF;
+            msg := 'The Following Reminders are being processed:' + CRLF + CRLF + msg;
+            msg := msg + CRLF + 'Canceling will cause all processing information to be lost.' + CRLF +
+                          'Do you still want to cancel out of reminder processing?';
+            Result := (InfoBox(msg, 'Cancel Reminder Processing', MB_YESNO or MB_DEFBUTTON2) = ID_YES);
+          end;
     end
   else
@@ -800,5 +889,4 @@
     for i := 0 to RemindersInProcess.Count-1 do
     begin
-      //if Piece(TReminder(RemindersInProcess.Objects[i]).RemData,U,11)='1' then
       if TReminderDialog(TReminder(RemindersInProcess.Objects[i])).RemWipe = 1 then
           begin
@@ -827,22 +915,34 @@
   if(Result) then
     begin
-      for i := 0 to RemindersInProcess.Count - 1 do
+      if FProcessingTemplate or FSilent then
         begin
-          if (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray <> nil) and
-             (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Count > 0) then
-             begin
-               if ClearMH = false then
-                 begin
-                   RemoveMHTest('');
-                   ClearMH := true;
-                 end;
-                TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Free;
-             end;
+          if (FReminder.MHTestArray <> nil) and (FReminder.MHTestArray.Count > 0) then
+            begin
+             (* if ClearMH = false then
+                begin
+                  RemoveMHTest('');
+                  ClearMH := true;
+                end; *)
+              RemoveMHTest('');
+              FReminder.MHTestArray.Free;
+            end;
+        end
+      else
+        begin
+          for i := 0 to RemindersInProcess.Count - 1 do
+            begin
+              if (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray <> nil) and
+                 (TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Count > 0) then
+                begin
+                  (*if ClearMH = false then
+                    begin
+                      RemoveMHTest('');
+                      ClearMH := true;
+                    end;  *)
+                  RemoveMHTest('');
+                  TReminderDialog(TReminder(RemindersInProcess.Objects[i])).MHTestArray.Free;
+                end;
+            end;
         end;
-      (* if (FReminder.MHTestArray <> nil) and (FReminder.MHTestArray.Count > 0) then
-         begin
-           RemoveMHTest('');
-           FReminder.MHTestArray.Free;
-         end; *)
     ResetProcessing(RemWipe);
   end;
@@ -1751,4 +1851,6 @@
   Width := RemDlgWidth;
   Height := RemDlgHeight;
+  pnlFrmBottom.Height := RemDlgSpltr1 + lblFootnotes.Height;
+  reData.Height := RemDlgSpltr2;
 end;
 
