How to get a user login location

Hey Everyone.

I am currently customizing the header and I want to display the current login location in the header. I thought I would find this information using the /session endpoint but this only has the logged in user details.

Kindly advise how I can get this information.

Thanks.

You can get this whole location information using location end point. /ws/rest/v1/location

To get the current user session and location information, let’s play with /ws/rest/v1/appui/session

1 Like

@suthagar23,

This works. :grinning: Thanks!

Hello @suthagar23,

I followed you advice on using the appui/session endpoint and now a change of location from the homepage reflects on the OWA module I’m working on.

However, the question of setting the sessionLocation in reverse that is, from the OWA app we are building came about during the Addon manager demo and I thought of making a post to edit the /appui/session sessionLocation property, but it does not work.

I have also looked for documentation of this endpoint but can’t seem to find it.

Kindly assist.

1 Like

Hi @suthagar23, I am also having the same blocker, what API can i use to set a new location. Thanks cc @dkayiwa

I am using that one in SysAdmin OWA. Can you take a look at here for setOpenMRSLocation function,

@suthagar23

This works for me.

Thanks a bunch!

Does this also work when I’m not running the appui module?

Help me understand: is everyone reimplementing their own UI widgets for the page header with behavior for changing locations?

That would be bad.

  1. We need to be building reusable components
  2. I would personally vote for not allowing the login location to be changed except for on specific screens (e.g. on the home screen)

-Darius (by phone)

1 Like

Noted @darius, I believe your first point can be solved by ensuring the generator-openmrs-owa scaffolds the UI widgets for the page header. I’ll create a ticket for this and possibly look into it. For your second point, should we disable the login location changing feature on other screens going forward?

For the first point, we should avoid duplicating the code in every every owa. In other words, we should define the widget in an npm project like “common-openmrs-react-widgets”, and the scaffolding can just include this.

For the second point, ignore this for now, and forget I said anything. (As long as we can have a reusable widget and aren’t duplicating the business logic in every OWA, it’s fine.)

Hi @suthagar23 is there an endpoint I can use to get authenticated user that doesn’t require me to have the appui module installed?

cc @dkayiwa

@ivange94 I worked on this before to get another endpoint. But most of the previous OWA used this endpoint and I couldn’t find any other endpoint for this purpose.

1 Like

@suthagar23 thanks. @dkayiwa any help here? We need to use this in radiology and declaring a dependency to appui which may also end up having other dependencies to use just one endpoint doesn’t sound like the right way for us. Do you think this can be moved to the webservices.rest module?

@ivange94 what you are saying makes perfect sense! Do you wanna create the ticket? It would be awesome if you can also do the pull request. :slight_smile:

Doesn’t /ws/rest/v1/session deliver the autthenticated user information?

1 Like

@willa thanks. I think this is what I was looking for.

Hi @suthagar23

I have tried using this endpoint /ws/rest/v1/appui/session but it turns out that the sessionLocation property is ever null!

I’m running this on platform: 2.2.1 and appui: 1.10.0

URL:

    curl -i -u admin:Admin123  GET "http://localhost:8080/openmrs/ws/rest/v1/appui/session" -H  "accept: 
    application/json"

I realized that when I used the webapplication UI to test out this endpoint it works fine yet it fails with the cURL tool!

Anyway that’s not a big issue at my end, but I wonder why though