OpenSRP Document Configurability
Contents
Purpose
High level goal - The goal of OpenSRP document configurability is to move OpenSRP towards the product direction whereby we would have one APK for different deployments, countries and use-cases. However, these implementations would have different configurations eg. forms, views & models.
Other goal - The goal of OpenSRP document configurability is to come up with a structure for moving implementation-specific features to configuration files & then moving these files to the server so that any update of the implementation-specific features can be done remotely from the server.
Implementation-specific features are:
Add, update or remove form questions
Edit label on form questions
Add or update constraints, validations on current form questions
Model changes that enable processing of data from new form questions
This would enable you to show new questions from the form
View changes
Button font, color, size, position & label changes
Client profile changes
Register view changes
menu changes
eg. 2 OpenSRP apps might fundamentally function the same but have different themes based on client preferences. These two apps might also have different questions or use different languages due to the nature of implementation requirements.
Currently, to provide an update of implementation-specific features you need to make the changes in the code ,generate an APK & upload this to PlayStore where the update will be reviewed. The client needs to be notified of the application update and perform a complete download of the APK before the update is performed.
With document configurability, there would be one codebase that can serve multiple implementations by the change of the configurations to fit the expectation.
Setup
Server-setup
Document configurability is enabled by default on the opensrp-web-server repository. The server can store and provide any of the configurations documents by default.
Deploy OpenSRP server version >= v2.1.12
Deploy OpenSRP web version >= v0.1.4
Client-setup:
Make sure you are using opensrp-client-core version >= v1.12.0-SNASPHOT
Make sure you are using opensrp-client-native-form version >= v.1.13.1-SNAPSHOT
Add the following code to the last line in your
Application.onCreate
methodNativeFormLibrary .getInstance() .setClientFormDao(CoreLibrary.getInstance().context().getClientFormRepository());
Change any references, extensions and manifest declarations of
com.vijay.jsonwizard.activities.JsonFormActivity
tocom.vijay.jsonwizard.activities.FormConfigurationJsonFormActivity
Change the
AndroidManifest.xml
declaration of theJsonFormActivity
toFormConfigurationJsonFormActivity
Change any
startActivity
andstartActivityForResult
methods to useFormConfigurationJsonFormActivity
instead ofJsonFormActivity
as the target activityReplace parent activities from
JsonFormActivity
toFormConfigurationJsonFormActivity
in the activities which extendJsonFormActivity
Add the following lines to your
AppJobCreator#onCreate
method to make theDocumentConfigurationServiceJob
availablecase DocumentConfigurationServiceJob.TAG: return new DocumentConfigurationServiceJob(DocumentConfigurationIntentService.class);
Schedule the
DocumentConfigurationServiceJob
to run every 15 minutes by adding the following line toLoginInteractor#scheduleJobsPeriodically
DocumentConfigurationServiceJob .scheduleJob(DocumentConfigurationServiceJob.TAG , TimeUnit.MINUTES.toMillis(BuildConfig.CLIENT_SETTINGS_SYNC_MINUTES) , getFlexValue(BuildConfig.CLIENT_SETTINGS_SYNC_MINUTES));
Create the
ClientFormRepository
andManifestRepository
by adding the create statements in theApplicationRepository
eg.ANCRepository
or add the create statements as migrations. To create the tables, add the following statementsAdd the forms sync to the immediate sync call. This function enables forms sync to happen when the user clicks on the Sync button
When opening forms, use
com.vijay.jsonwizard.utils.FormUtils#getFormJsonFromRepositoryOrAssets
method to fetch the JSON form. The rules & other assets required when loading the form are handled by the FormConfigurationJsonFormActivityMake an initial upload of the form files:
Clone this repo github.com/OpenSRP/opensrp-server-web
Change client project assets folder path in the configuration file named doc_config_script_configs.properties
Change the server url & authentication credentials in the configuration file named doc_config_script_configs.properties
Change the appId and appVersion values in the configuration file named doc_config_script_configs.properties
Run the main method in InitialFormConfigUploadUtil.java file
Check the output for any failures. Increment the formVersion and repeat in case of any failures
How it works
Changes to the form eg. child_enrollment.json, disease_effects.json are made and tested
Create a Manifest in json form with the package name, app version & forms version as below
The identifier should be the version of the Manifest and uniquely identify this Manifest
3. Upload the manifest to the rest/manifest
endpoint as described here
4. Upload the form(s) that has changed
Technical Details & How to use it
These are the technical details
Server side APIs
1. Manifest Endpoint
rest/manifest
GET request - Returns all the manifests available on the server
POST request with the following
application/json
body - Publish a new manifest to the serverReturns 201 when successful
GET request at endpoint
rest/manifest/search
with paramsapp_id
- (Required) The app package name eg. org.smartregister.chwapp_version
- (Required) The application version name eg. 0.0.1
Returns a 200 with the latest manifest of the app or 404 if no manifest is found
2. Client Form endpoint
rest/clientForm
POST with the following
multi-part
paramsform_version
(Required) The semantic version of the formform_identifier
(Required) The unique identifier of the form eg.en/json.form/maternity/enrollment.json
form_name
(Required) The title or label of the form eg. Child Registrationform
(File, Required) The actual json form filemodule
(Optional) The parent module of the form eg. Child, Immunization
Returns a 201 when successful
GET request with params
form_version
(Required) The semantic version of the formform_identifier
(Required) The unique identifier of the form eg.en/json.form/maternity/enrollment.json
current_form_version
(Optional) The current form version on the client app
Client side APIs
Coming soon. This work is under development
Assumptions
Coming soon.
Questions
Are the uploaded forms stored as files on the server? No, they are currently stored on the database server as JSON
How to customise for your project
Coming soon
This site is no longer maintained. Please visit docs.opensrp.io for current documentation.