I have a use case where I need to generate patient identifier following certain sequence(need to take a location attribute and concatenation with a random string) during registration(am using xform for capturing registration details). What is needed is to add a button after the identifier input filed, which when clicked, the input field is populated. My questions follows
-Can a button be added on a form to effect that in xform?
-Is it possible to call a service method that would fetch location attribute value?
-Can I use Idgen module for that purpose?(I know doing that from a java code, but how can that be called on an xform?)
If there is an already existing solution to this please point me to it, or if you can advice a way of accomplishing that. I would easily do that on a fragment and an HTML form, the challenge comes in when dealing with xform.
Thanks @dkayiwa. I have read about that and tried even setting up those global properties as explained. What I did NOT get is how I can add a button to trigger generation(on click) following a certain perttern(Facility_Code+5 digits which are random).
Can a service method(will be used to fetch the location attribute) be called on xform registration page and be fired by a click on the button?
Yes, that would work, this will give them an opportunity to edit it before saving to the database. If that Identifier could be generated based on an algorithim(which can be written as a java method in a class and just be called there) would be great.
In htmlform I usually create a method in a FragmentController class and call that via ajax in the form. In the class I would pass any parameters and call them in the form section via ajax. For example this method is called here for action, hope that helps
Use the form designer’s JavaScript tab to create a method which does an AJAX call. Then attach this method to the button click event to populate the text field with the fetched value.