Can I automatically schedule an appointment based on observation forms?

Hello, we have visit information captured from one observations forms(visit site, next followup date), could it be possible to push that information automatically to the appointment model?Other than re-entering the same information into the appointment scheduler.

Well, You have to write some code to post process the form submission. What you are capturing is observation. Easiest way would be: write an advice (in a different omod) on, check whether the desired form (or ob with the followup date concept) is being saved, and then create the appointment in code.

Btw, This should be a different topic

I moved this to a new topic.

@ejustine, as Angshuman says, this isn’t supported out of the box, but you could write a small amount of server-side code to do it. You could either write AOP advice on saving an encounter, or else you could write a scheduled task.

(Do ask if you need more guidance on how to do this.)

@darius definitely I will need a lot of guidance on how to schedule task or writing AOP advice.

Okay, what is the level/background you’re coming from (either you or your team), particularly in Java and in creating/modifying OpenMRS modules?

Am a beginner in java and haven’t created/modified any OpenMRS modules yet.

Okay, in that case it’s going to require a longer explanation of some things, which I won’t have time to do this week. Do you have a particular timeline on needing this, based on the implementation?

The steps are going to be:

  1. create an empty OpenMRS module (using OpenMRS SDK)
  2. add maven dependencies on (at least) the appointment module (I need to look up the details)
  3. use AOP to add “advice” after (hopefully this is documented in the OpenMRS wiki)
  4. write a Java method that will inspect the encounter that is being saved, look for your relevant observations, and then call the API of appointment scheduling to create a new appointment (this will be specific to your use case)

One question that you will need to answer for yourself is what happens in the case of edits? E.g. it’s straightforward if the first time they fill out that section of the form, you create a scheduled appointment. It’s trickier if you want to figure out what to do if they edit that section of the form later.

This can either be done asynchronously outside of the transaction or synchronously part of the same transaction. My inclination is towards aysnchronous option. For that, you can have a openmrs scheduled task that regularly reads such observations and creates corresponding appointments.

I had recently created a ‘Bahmni appointments scheduling extension’ omod to have a task to auto-checkin appointments discussed in this thread. The omod has been running fine in production for a week now. The source code can be found here. The omod still requires fine tuning in terms of removing unwanted dependencies, etc. Hopefully i will be able to do it in next week. But feel free to use it as reference if it helps. In creating appointments asynchronously a mechanism will have to be figured out to know which observations have been processed and so not to create duplicate appointments. (may be the combination of patient id, appointment date and service type can be used for that).

If there is really a need to do it synchronously as part of the same transaction then you can either create another omod like darius suggested or it can probably be done via the already existing groovy script support in Bahmni like the BahmniObsValueCalculator which gets called before transaction update by bahmni-core.

True, think It will need explicit explanation just as you have said, and I will be glad when you fix some time for me. About the time frame , really need it as soon I can.

Thanks in advance

Please note, async based appointment creation using a scheduled job has few other things to be thought

  1. if the job fails, then you don’t know! - you will need to think of retry mechanism, views for admins etc.
  2. When and how do you the scheduled job? what data do you scan?
  3. What happens if there are 10 appointments to be created and it failed after 2? Do you restart from the 3rd? How do you track?

not saying that this is not the right way to do so, but to do this right, you need to have other things to be take care.

1 Like

Okay, I’ll try to get back to this next week.

In the meantime, please do think about how exactly you’ll expect this code to behave when you edit the form data, and/or if you expect the appointment to be scheduled instantly, at the end of the day, at the end of the visit, or what.

FWIW this could be more convincing to people if you could say something like “for x implementation that we’re doing in country y and is already live”, or whatever. :slight_smile:

Thank you @darius currently we are implementing bahmni 0.9 in one of the hospitals in Uganda where we have someone in place helping in updating the patients visits where we have the followup date and site in one of the forms.And we saw auto marking the appointments as an optimal way of tracking followups.