Hi all,
Preamble:
I'm working on a project that displays a years worth of Doctor (General Practioners) (after planning with OptaPlanner) shifts. In NL a GP has his/her own practice during weekdays, and after hours (evening, nights, weekends and holidays) instead of being on duty 24/7 for their individual patients they now do shifts at on of the several doctors posts in a region that patients can use. Doctors posts have been migrating into hospitals during the last decade and now doctor's posts and the 'classic' ER are being integrated.
Once we have the yearly planning for the shifts (around 4100 for 100 doctors), doctors are free to swap shifts with other doctors, and they use it a lot. Our roster, which is in use since January 2, 2018 already has 850+ changes. All changes are managed through a central bureau, as GP's need certain certificates for certain shifts, so you can't swap shifts with just any other GP. That is checked by this bureau.
Question:
To undo a shift change I have created a dedicated view in which the user can select (using Modal) a Date, a shift, and more. Typically you'll select a date, which then lists all shifts on that day that have been changed. With a trash can for that change. As a shift can change doctors more than once, the listing is sorted per shift and per change. Users are only allowed to delete the last change made.
I keep track of the changes in two ways:
(1) in a change-record listing the shift, the previous doctor, the new doctor and the original doctor (The original doctor gets the financial compensation for that shift and clears it with the doctor that actually does the shift.). Also stuff like date/time of change and who has entered it into the system. AND the change number.
(2) the shift-item itself: the number of changes (just making it easy on myself, I could also count the number of linked change-records)
When undoing the last change I use the row_deleting event of the created view and first thing I do is test if it's the last change:
function Row_Deleting(&$rs) {
GLOBAL $sysbericht; //for any error messages
//Test if it's the last change
//get Roster-Item
$RI_key = $rs["DR_RI_ID"];
$RI_REC = ew_ExecuteRow("SELECT * FROM tbl3_ri_roosteritem WHERE RI_ID = " . $RI_key); //the Roster-Item in question
$aantal_muts = $RI_REC["RI_Aantal_Muts"]; //total number of changes to the RI
$wijz_nr = $rs["DR_AantalWijzigingen"]; //this is the change-number of the record to be deleted
if ($wijz_nr <> $aantal_muts) { //if the change-number == total number of changes, you have the last change-record
$sysbericht = "Only the LAST change may be revoked";
Return FALSE;
}
....
}
In 'Delete Page', Message_Showing event I have the following:
function Message_Showing(&$msg, $type) {
GLOBAL $sysbericht;
if ($type == 'success') {
//$msg = "your success message";
} elseif ($type == 'failure') {
$msg = $sysbericht.", processing is cancelled";
} elseif ($type == 'warning') {
//$msg = "your warning message";
} else {
//$msg = "your message";
}
}
The following happens:
When I click the trashcan in the list view, it displays the delete-page for that record AND an 'empty' pop-up with ", processing cancelled" which I have to click away with OK.
I then get a clear Delete page. The user then confirms the deletion.
If it's NOT the last change then I get the expected pop-up again, but now stating correctly "Only the LAST change may be revoked, processing is cancelled"
If it IS the last change I get the expected pop-up with "Deletion successful"
But I always get that first empty pop-up with ", processing cancelled".
If I comment out my tailor-made failure message in message_showing, I DON'T get the first empty pop-up. After confirmation, If it's not the last change I get a correct pop-up with "deletion cancelled", - of course without my tailor-made message.
And if it's the last record I get the "deletion successful" pop-up.
So the process and the code seems to work, except for that first empty pop-up when I'm using custom messages.
What am I doing wrong here?
Thanks for any feedback!