Openmrs provider

How can I get a provider that is currently authenticated in openmrs 2.3.3 so as to append to an encounter i.e encounter.setProvider(Context.getProviderService().getProvidersByPerson(user.getPerson()));

What you are doing seems almost correct, just make sure the user is the authenticated user by calling Context.getAuthenticatedUser(), the problem would be if the person has multiple provider accounts and in that case you don’t proceed.

1 Like

Thank you @wyclif. Your Ideation worked for me. We created a custom method that takes a role and person object to get the provider account linked to the currently authenticated user. Gets a list of provider accounts linked to the user and we pick one at index [0]. For our case, one user is mapped to only one provider account.

Under what scenario would a single user/person have multiple provider accounts?

It’s possible, though likely uncommon for standard provider definitions, for an individual to be qualified for and interact as different providers (e.g., working as nurse and moonlighting as a pharmacy technician). It’s more common that a single individual would have different roles over time (e.g., student last year, clinical officer this year, and doctor a few years later).

@injiri as long a person has one user account, it’s purely fine to select the first, but to be safe you might want to add a check to ensure the returned provider list is always containing one record.

1 Like