When I view a patient through the patient dashboard, the EMRAPI module add that patient to the lastViewedPatients list which will be listed as
RECENT in the findPatients dashboard.
The EMRAPI modules call the getPatientByUuid() method to get that patient information before adding that to lastViewedPatientsList. See here 
LocationBasedAccessControl Module: I’m working on this module to restrict the patients by the locations.
- At very first Location based access control module will check the UserContext Location to get the logged in user location. See here
- If the UserContext Location is null, it will replace the actual patient object by a
null object to restrict the patient from the user view - See here
Actual Error Point:
I clicked a patient from the findPatient dashboard to view the patient information to the dashboard. When I started to view the patient information, the EMRAPI module tried to add that patient into the lastViewedPatient list. At this point, I’m getting this error.
Here is the log : https://pastebin.com/GLmbi9YE
Actually the page called the
getPatientByUuid() method for multiple times before showing all the information about the patients in the patient dashboard (for multiple reasons). At one point, It got an exception to validate the user context in the line - 37 (see the log).
You can see all the
getPatientByUuid() method is validated with the UserContext(you can see Location, administrative user, and roles). But for a call in Line-37, System Could not find the Usercontext information (still user context is not null, but the location and the administrative user is null, and role is Anonymous). Actually, this
getPatientByUuid() method was called from that EMRAPI module.
When the location in the UserContext is null, Our module skips the checking (Since couldn’t find the user logged in session information) and return the
null object instead of an actual patient object. So that the request method(In EMRAPI) could not find the patient since it is null. So It couldn’t add this patient to the last viewed patient list and throws the exception.
ERROR - PatientViewedEventListener$1.run(66) |2018-07-11 18:48:51,641| Failed to update the user's last viewed patients property
org.openmrs.api.APIException: failed to find a patient with uuid:5342904c-104c-4463-98e3-d60027792113 or the patient is not yet saved
Could someone help me to find out the actual error on this part?
CC : @dkayiwa @wyclif @darius