orderentryui - provider is undefined in order-entry.js

Hi @darius,

I finally could start trying orderentryui around and it looks very promising, so I’m very keen to get it working fully. Right now I’m blocked with this one after clicking on ‘Sign and Save’:

TypeError: Cannot read property 'uuid' of undefined
    at http://localhost:8080/openmrs/ms/uiframework/resource/orderentryui/scripts/order-entry.js?cache=1446536698472:227:55

This happens because earlier on provider is undefined after this processing line of order-entry.js:

var provider = SessionInfo.get().currentProvider;

For sure the user I’m trying this with is defined as a provider, so that is not the issue. Note that SessionInfo and SessionInfo.get() seem to be set correctly too.


I’m not sure where to look, I had a look at http://localhost:8080/openmrs/ws/rest/v1/session and I can’t find any information about a ‘provider’. Could you point me to the next troubleshooting step?

Hi Dimitri,

I know you said this is not the issue, but just to confirm - make sure your current user is defined as a Provider using this page http://demo.openmrs.org/openmrs/admin/provider/index.htm, and not simply with a “Provider” role on this page http://demo.openmrs.org/openmrs/admin/users/user.form?userId=1.

Mike

Hi Mike,

The users I tried with were indeed added in Manage Providers, however one of them was not ticked as ‘Provider’ in Manage Users. Nevertheless, same undefined error in both instances.

Or perhaps could anyone help me understand what is behind SessionInfo.get(), so that I can get some clues as to why its .currentProvider returns undefined?

I’m sorry, I am not yet so familiar with AngularJS or the context here within OpenMRS where it is used.

Thanks again.

SessionInfo comes from the uicommons module here. Make sure you’re including this file.

(Sorry, I’m too swamped now to engage with this much, but once you all have started working with the orderentryui module code, I’m happy to have a voice call so I can try to convey whatever I remember about the state of the module and code.)

Hi @darius, thanks for coming back to me. And yes, assuming we move forward with orderentryui, it would be great if you could talk me through the code over a call! Thanks for suggesting this. I’m currently assessing it, and depending on my findings, we may kick start the development somewhere after November 23rd. Until then there is no urgency but it would be good that I could get it running beforehand, obviously.

Ok so the link you provided points to a REST resource that I already thought was in use behind the scenes:

Should I start debugging that REST resource or you are adamant that it has got to be a configuration issue? Meaning that if there is indeed a ‘current provider’ /ws/rest/v1/session would for sure report it.

Thanks again!

I’m not adamant about anything. I spent <5 minutes looking into this.

You can manually GET the session resource and see what it is returning, and whether there is a provider there.

Hi,

Sorry, I’m forgetting that this module is still under development (and not actively) and may not be fresh out of your mind.

Yes that is what I did by inspecting http://localhost:8080/openmrs/ws/rest/v1/session In there I can find the provider role information:

<roles>
  <role>
    <uuid>8d94f280-c2cc-11de-8d13-0010c6dffd0f</uuid>
    <display>Provider</display>
    ...
  </role>
...
</roles>

So

  1. SessionInfo is populated from /ws/rest/v1/session.
  2. Inspecting /ws/rest/v1/session confirms that the provider role is present.
  3. Q. Where is defined the function .currentProvider that is invoked in order-entry.js? As in:
var provider = SessionInfo.get().currentProvider;

That is the one that is undefined. Perhaps is it really not defined (yet)? Sorry if this is a basic JS question. I’m just not so familiar yet with it, and with AngularJS within OpenMRS in particular.

@mksd , I think the confusion may be what Mike mentioned in his first reply to you (but I will expand, because it’s not obvious).

Prior to OpenMRS 1.9, you indicated that a user was a provider by giving the “Provider” Role to that User. This is what you are showing in the REST result. However things changed in OpenMRS 1.9, and the code no longer looks for this.

Since OpenMRS 1.9 there is a Provider domain object, which is not directly linked to User. Rather a Person can have 0…n User accounts, and 0…n Provider accounts. The Reference Application does some simple logic that you can see here:


You need to make sure that the currently-logged in user has a Provider account, i.e. that the user’s person has a matching row in the provider table.

In the REST response you should be seeing a “currentProvider” property, as generated here:

Does this make sense?

*** = I notice one possible bug: the UiSessionContext constructor code uses the VIEW_PROVIDERS proxy privilege, which could be buggy if the appui module was compiled against OpenMRS < 1.11, but is run against 1.11+ (however looking further, this should be okay, since appui inherits its versions from the distro, so it should be building against the same openmrs-core version).

Hi @darius,

Thanks, that is a very clear and detailed explanation. In particular your hint that there may be some version compatibility issues. Thanks for pointing me to the exact bit I was wondering about:

SimpleObject ret = new SimpleObject()
  .add("authenticated", uiSessionContext.isAuthenticated())
  .add("locale", uiSessionContext.getLocale().toString())
  .add("currentProvider", ConversionUtil.convertToRepresentation(uiSessionContext.getCurrentProvider(), rep))
  .add("sessionLocation", ConversionUtil.convertToRepresentation(uiSessionContext.getSessionLocation(), rep))
  .add("user", ConversionUtil.convertToRepresentation(uiSessionContext.getCurrentUser(), rep));

And I can see that out of authenticated, locale, currentProvider, sessionLocation and user, only authenticated and user are brought back by the REST service:

<object>
  <sessionId>3zc6dtbay93s</sessionId>
  <authenticated>true</authenticated>
  <user>
  	...
  </user>
</object>

Looking at SimpleObject.add(...):

public SimpleObject add(String key, Object value) {
  put(key, value);
  return this;
}
```
I see that even if `value` is `null`, then at least the key should be there. Unless `null`-valued pairs are eventually kicked out when building the JavaScript object from the `SimpleObject` instance.

----

I guess that the bottom line is that I need to see what exactly happens with `ConversionUtil.convertToRepresentation(uiSessionContext.getCurrentProvider(), rep)`?

@mksd, I think using version 1.4 (or later) of appui solves this problem.

I have extended this module and included lab orders. when I login as an admin, I am able to create lab orders successfully but I am not able to achieve the same when I login as a provider. An error is thrown of provider undefined. I have followed through this talk but still I am not able to solve it. I am running appui 1.8.0 and webservices.rest-2.19.0 . @darius any further guidance on this?

@makombe have you considered using the new Order Entry OWA instead? It should be the way to go from now on.

Not yet. I can see you are the one who raised this issue. Were you able to solve it? and if so how did you go about it?