1. Create a new form object from your xml
Option 1: Utilizing public void HtmlFormEntry.HtmlForm.setXmlData(String xmlData)
import org.openmrs.module.htmlformentry.HtmlForm;
...
HtmlForm form = new HtmlForm();
form.setXmlData(xml);
Option 2: if your XML is not loaded yet, utilizing public static HtmlForm HtmlFormEntryUI.HtmlFormUtil.getHtmlFormFromUiResource(<arguments>)
, reference
- Note:
relativeWebResourcePath
is the relative path from the directory /omod/src/main/webapp/resources
of your module.
- Arguments are
ResourceFactory resourceFactory, FormService formService, HtmlFormEntryService htmlFormEntryService, String providerAndPath
import org.openmrs.api.FormService;
import org.openmrs.module.htmlformentry.HtmlFormEntryService;
import org.openmrs.module.htmlformentry.HtmlForm;
import org.openmrs.module.htmlformentryui.HtmlFormUtil;
...
String htmlFormPath = thisModuleName+":"+relativeWebResourcePath;
ResourceFactory resourceFactory = ResourceFactory.getInstance();
FormService formService = Context.getFormService();
HtmlFormEntryService htmlFormEntryService = Context.getService(HtmlFormEntryService.class);
HtmlForm form = HtmlFormUtil.getHtmlFormFromUiResource(resourceFactory, formService, htmlFormEntryService, htmlFormPath);
2. Use FormEntrySession to generate HTML and handle form entry, submission, etc
import org.openmrs.module.htmlformentry.FormEntrySession;
...
FormEntrySession fes = new FormEntrySession(patient, form, request.session)
String html = fes.getHtmlToDisplay()
3. Use the html generated
The html that the FormEntrySession
object generated should contain all the logic required to submit the form.