Triggering calls from referenceapplication.registrationapp.registerPatient

Hi all,

Building on my prior question re. triggering ADT generation from an HTML form[0], we are also asked to trigger other custom code via the patient registration app in the refapp (referenceapplication.registrationapp.registerPatient). I understand that we can edit these JSON scripts, but has anyone any expertise in triggering an action from these apps? Any prior examples would be very useful!

[0] OpenMRS ADT generation for COVID response

How about doing AOP for the PatientService.savePatient() method?

3 Likes

You could also use the event module to catch saves to the database at the Hibernate level. It’s built off of JMS and can work via:

At some point in the application:

Event.subscribe(Patient.class, Event.Action.CREATED.toString(), patientListener);

Where patientListener looks something like this:

class PatientListener implements EventListener {

    @Override
    public void onMessage(Message message) {
        String uuid = ((MapMessage) message).getString("uuid");
        Patient patient = patientService.getPatientByUuid(uuid);
        
        // Nifty ADT generating stuff goes here
    }
}
2 Likes

… or just a plain Hibernate interceptor. We did that in one of our impls to associate patients to locations ahead of location filtering with Data Filter.

1 Like