...
Technically, RFE Forms is a React component that requires the following properties(props):
Mapping Controls
Fields are mapped to their controls via a registry system. This is highly extensible and easy to override the default controls.
...
The field above has the rendering of type checkbox, the engine will simply check the registry for this kind of control and instantiates an instance of this control.
Submission Handlers
These handle submission at the field level. The engine doesn’t know how fields aggregate or compose primitive values into objects that the backend expects ie. an Observation. The form engine by default defines a set of base handlers eg. ObsSubmissionHandler
, EncounterLocationSubmissionHandler
etc.
These are also mapped using the registry system based on the type
property of a form field. On form submission, the engine simply collects all field submissions and aggregates them into some object that OpenMRS understands.
Extending the Registry
The engine exposes an API to work with the registry.
addHandler(handler: HandlerRegistryItem)
Adds submission handler to the handlers registryCode Block language json import { SomeCustomHandler } from "./handlers"; import { addHandler } from "openmrs-ohri-form-engine-lib"; // Add to registry addHandler({ id: "customHandler", component: SomeCustomHandler, type: "someCustomType", });
addvalidator(validator: ValidatorRegistryItem)
Adds validator to the validators registry
Code Block language json import { SomeCustomValidator } from "./validators"; import { addvalidator } from "openmrs-ohri-form-engine-lib"; // Add to registry addvalidator({ id: "customValidator", component: SomeCustomValidator, type: "customValidatorType", });
addFieldComponent(control: ControlRegistryItem)
Adds custom control to the field controls registry
Code Block language json import { BootstrapDropdown } from "./controls"; import { addFieldComponent } from "openmrs-ohri-form-engine-lib"; // Add to registry addFieldComponent({ id: "bootstrapDropdown", component: BootstrapDropdown, type: "bootstrapDropdownType", });
Post Submission Actions
The form-engine supports post-submission actions. A post action is a JS class or function that implements this interface. This functional interface requires implementing the applyAction(formSession, config)
function which has the form session context plus an adhoc config. The config makes the actions more generic and configurable hence the ability of reusing the same action for different use-cases.
How do we register an action?
The engine utilises the registerPostSubmissionAction
function to register a post submission action.
...
Code Block | ||
---|---|---|
| ||
"availableIntents": [ { "intent": "*", "display": "Labour & Delivery Form" } ], "processor": "EncounterFormProcessor", "uuid": "1e5614d6-5306-11e6-beb8-9e71128cae77", "referencedForms": [], "encounterType": "6dc5308d-27c9-4d49-b16f-2c5e3c759757", "postSubmissionActions": [ "MotherToChildLinkageSubmissionAction", "ArtSubmissionAction" ], "allowUnspecifiedAll": true, "formOptions": { "usePreviousValueDisabled": "true" } |
Program Enrolment
The ProgramEnrollmentSubmissionAction
is a generic post submission action that automatically enrols a patient to a specified program upon successful submission of an enncounter. This is passed through the form JSON and the action can either be enabled or disabled based on the expression passed as the enabled
flag. Below is an example of TB Program enrolment in the TB Case enrolment Form.
...