Make Module admin page publically accessible

0 views
Skip to first unread message

magus...@iiitd.ac.in

unread,
Jun 17, 2014, 1:45:32 PM6/17/14
to d...@openmrs.org
I have defined a custom module with an admin page that fetches patients and shows them.

I am trying to make that page accessible to public (no openmrs login required)

but I get following error on opening the page when I am not logged in openmrs
Privileges required: [View Patients]

I wrote several print statements to identify which line the code had problems on and I found following line in my controller which triggers this
Patient patient = (Patient) Context.getPatientService().getPatient(patientId);

if I login in openmrs and then open same page it works fine

is there a workaround that I could use to make that page public and still use getPatientService 

any help would be appreciated 

thanks

Darius Jazayeri

unread,
Jun 17, 2014, 1:50:30 PM6/17/14
to dev
Hi Magus,

First off, it's generally problematic to make patient data accessible globally to anonymous users. Assuming you know what you're doing, and you have some sort of particular use case, the pattern is to do something like this (copied from UserServiceImpl--you'd want to use a different privilege):

try {
Context.addProxyPrivilege(PrivilegeConstants.EDIT_USERS);
saveUser(user, null);
}
finally {
Context.removeProxyPrivilege(PrivilegeConstants.EDIT_USERS);
}

-Darius


--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org | Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/

magus...@iiitd.ac.in

unread,
Jun 17, 2014, 1:55:21 PM6/17/14
to d...@openmrs.org
thanks a lot Darius . I guess this should solve my problem .. i am trying that .

Your advice also seems valid about data sensitivity , will also explore alternatives that I could use for my use case.

thanks again  

magus...@iiitd.ac.in

unread,
Jun 17, 2014, 4:58:42 PM6/17/14
to d...@openmrs.org
I am trying to create a new encounter on same page ( which works publically/without authentication)

On opening the page , server log shows following error
ERROR - JDBCExceptionReporter.logExceptions(234) |2014-06-18 02:13:33,502| Column 'creator' cannot be null
ERROR - LoggingAdvice.invoke(135) |2014-06-18 02:13:33,505| An error occurred while executing this method.
Current user: Guest (Not logged in)
Error message: could not insert: [org.openmrs.EncounterProvider]

I have set creator for encounter but couldn't make out what how should set creator for EncounterProvider
this is the code I wrote,
Encounter enc = new Encounter();
enc.setEncounterDatetime(d);
enc.setPatient(patient);
enc.setEncounterType((EncounterType)Context.getEncounterService().getEncounterType(1));
List<User> a = Context.getUserService().getAllUsers();
User u = a.get(0);
enc.setCreator(u);
enc.setProvider((EncounterRole)Context.getEncounterService().getEncounterRole(1),(Provider) Context.getProviderService().getProvider(1));
Encounter enc_formed = (Encounter)Context.getEncounterService().saveEncounter(enc);

I verified user and it getting set as Super User , also I tried to do a toString of Encounter before saveEncounter which shows following
Encounter: [(no ID) Wed Jun 18 02:13:33 IST 2014 ADULTINITIAL (no Location) 2 (no Form) num Obs: [] num Orders: 0 ]

I have following privileges on top of my controller 
Context.addProxyPrivilege(PrivilegeConstants.VIEW_ENCOUNTERS);
Context.addProxyPrivilege(PrivilegeConstants.VIEW_ENCOUNTER_TYPES);
Context.addProxyPrivilege(PrivilegeConstants.VIEW_ENCOUNTER_ROLES);
Context.addProxyPrivilege(PrivilegeConstants.VIEW_PROVIDERS);
Context.addProxyPrivilege(PrivilegeConstants.VIEW_USERS);
Context.addProxyPrivilege(PrivilegeConstants.ADD_OBS);
Context.addProxyPrivilege(PrivilegeConstants.ADD_ENCOUNTERS);

can you please suggest something I could do to fix this

thanks

On Tuesday, June 17, 2014 11:20:30 PM UTC+5:30, Darius Jazayeri wrote:

Darius Jazayeri

unread,
Jun 17, 2014, 5:23:13 PM6/17/14
to dev
Hi Magus,

There is a lot of functionality in OpenMRS that assumes there is some user authenticated. You're going to be fighting an uphill battle trying to save data in this scenario.

I suggest that instead you create a user called "Guest User" (or something like that), and transparently log the user in, instead of mucking around with proxy privileges.

-Darius
Reply all
Reply to author
Forward
0 new messages