You’re reloading left_nav? That doesn’t look right… it’s destructive to other state information in there, and you also need to clear pid and encounter from the session data. Suggest you look at the code involved in selecting a new patient, and work from that. And definitely post up for review as this seems non-trivial.
Thanks for the feedback, that’s why I didn’t do anything else, it seemed too simple…
edit_globals.php seems to do something different and equally simple the clears the active patient/encounter. Is that model OK or is ti doing bad things too?
Not sure what you mean about edit_globals.php. Suggest you look at interface/patient_file/summary/demographics.php. Search for all occurrences of the string “set_pid” and look at the surrounding code. There is some PHP code as well as some javaScript that must be run. But instead of the JS setPatient() function I think you’ll want to call clearPatient(). This will need to be done with some understanding of what is going on.
Thanks,
Is there documentation on this whole interaction somewhere. As I have said I’m not a javascript guy. and adding the complex interaction of the titlebar, left_nav and main frames just makes it virtually impossible for me to figure out. I know you and yehster get it.
Please share your knowledge on the architecture, in the form of some formal documentation on the wiki.
Re: edit_globals.php - Just this, when you make changes to the globals settings and click save. The active patient appears to be cleared. Yet there are no obvious way (to me) that that happens, there is not a call to clearPatient() or anything like that. So I’m worried now that using that menu item without some kind of logoff/on may cause some issues such as you describe in reloading left_nav.
My functionality is temporarily reduced due to Sandy, but there is also a server side component you need to deal with. Since there is at least patID saved as a session variable, if you don’t clear that, some weirdness could ensue.
What it looks like you are doing so far is only just trying to clear the client side info via JavaScript.
If you dont’t clear the sever side state too, it’s possible that future entries could go to the wrong patient.
You also need to clear the active encounter session variable.
On the client side, resetting to “no patient” needs to deactivate more menus than switching patients. For example, new encounter is still enabled when switching patients, but needs to be disabled if you are clearing. I think you can probably set the patient ID tracked in JavaScript to zero, but I’d need to take a closer look at the code.
My first thought is it’s easier to review code on github than in the forum.
That said, calling document reload right before your Ajax call is likely to result in a race condition. It’s probably better to do the reloads in the Ajax callback after the session stuff gets cleared server side rather than before.
I don’t see where clearPatient is defined. Does that already exist in left_nav.php?
Yes, agreed, but I didn’t have to pull it over into a formal branch this morning and it’s a really short set of code.
clearPatient() is a function in left_nav
-Tony
I suggest NOT reloading left_nav. In theory clearPatient() (yes that does exist) should do what’s necessary on the client side, and if it doesn’t then that is the place to fix it. You could move the ajax call into there too, that makes it easier for other places that want to do this.
Alternatively, skip the ajax call and add the PHP code to one of the reloaded scripts. Either way, suggest you include pid.inc and call set_pid(0) to clear the session pid and encounter… it does logging, and it’s always better to use a common function when it applies.
You probably don’t need to reload any frames at all. I think clearPatient() resets what matters (or used to, anyway) in the title frame. If it doesn’t, it should. Note also it calls reloadPatient() which attempts to reload the top and bottom frames only when necessary; not sure how perfectly that works, but in theory it should. I’d like to see that approach preserved because other things depend on it, and reloading the same frame twice is pretty silly.
Definitely agree that you should use setPid(0) instead of directly unsetting the session variables, that’s a much cleaner abstraction.
Picking nits here, but if the implemented function is truly meant to be “Go HOME” then it should explicitly reset the Top and Bottom frames, to their initial states at login. However, if it is meant to be just “clear patient” then it should leave any non patient specific frames alone per Rod’s description of the functionality:
attempts to reload the top and bottom frames only when necessary;
e.g. If you “clear patient” while the “Billing” screen is up, it should leave billing alone.
All good feed back. I’m going to get out of the middle and let the Visolve developer get this sorted out.
However: In light of the Go Home vs Clear Patient, I felt that “Home” was the right place to do that, clear the patient and return to the main base screen config, seems natural. I can see an argument for a separate Clear Patient button that does not “go Home” however and would be OK with that or some global that options either.
Should it, in fact, in either case, give an alert about “Unsaved Data” before clearing and/or going home?
It’s these seemingly little things that always have complications
The Go Home idea will be much easier (since then don’t need to ensure the currently loaded screens are “safe” after resetting the patient/encounter ids). And Rod, not sure how the code in globals is working, but it is basically reloading everything, which on testing appears to reset the patient/encounter ids.