[SOLVED] How to get the provider for an Encounter using Velocity in HTML Form Entry

I would like to get the provider details for an encounter in HTML Form entry.

On the encounter model there was a getProvider() method which was deprecated in favor of getProvidersByRole method which would take a parameter with a value 1.

So how do I call this method in velocity?

@k_joseph @mogoodrich @ball any ideas?

@arbaughj have you had any experience doing this?

@ssmusoke I don’t believe I’ve ever tried doing this before.

Hi @ssmusoke, I assume you have tried the getValue(‘encounterProvider.value’) function? https://wiki.openmrs.org/display/docs/HTML+Form+Entry+JavaScript+Reference

 jQuery(function() {
         getField('encounterProvider.value').change(function() {
         window.alert('Provider is ' + getValue('encounterProvider.value'))
         });
});

@arbaughj Yes I have used that for the current encounter, but what I am looking for is how to get the encounter provider for the last encounter which has to be from a lookup complexExpression

Thanks @ssmusoke, thanks for the clarification. I think I understand what you’re trying to do now.

I think one of the velocity functions returned all of the encounter details. It was rather cryptic what it returned, if I remember correctly.

Try… Past Encounters: <lookup complexExpression="#foreach($encounter in $fn.allEncounters(null)) $encounter #end"/> or… Past Encounter Providers: <lookup complexExpression="#foreach($encounter in $fn.allEncounters(null)) $encounter.encounterProvider #end"/>

If that doesn’t work, it may never have been “fixed” to support the multiple providers.

This is just a shot-in-the-dark. If you can get it to work, please document it on the OpenMRS Wiki.

@arbaughj I will try that and give feedback

1 Like

@arbaughj Thanks for the lead, what I ended up using for the last encounter was #foreach($encounterProvider in $fn.latestEncounter('encounterTypeUuid').encounterProviders) $encounterProvider.provider.person.personName #end

which gave me the name of the provider of the last encounter

1 Like