Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

We can have custom validations written in javascript for Registration Fields. 

For achieving this, need to do the following

  • Add a file called fieldValidation.js and put it under "/var/www/bahmni_config/openmrs/apps/registration/" directory.
  • Add the functions required to validate the field.
  • Include fieldValidation.js in bahmniapps/registration/index.html.

The format of the validator should be like below

Code Block
languagejs
titleConfig
linenumberstrue
  "<field id>" : {
           method: function (name, value, attributeDetails) {
          if (.......) {
            return true;
          }
          return false;
       },
       errorMessage: "Error Message"
     }
};

The fieldName details can be obtained from the openmrs administration module (Patient Attributes). The validators will work for non-attributes as well. For non attributes, you will need to get the field names using some html debuggers.

Patient Name Related Custom Field Validation Configurations

If the format of the patient names need to be changed, the global property patient.nameValidationRegex needs to be updated. This field is used in server side validations by openmrs.

Note
titleNote

 Error message is displayed only when return is false.  The specified field should be of non coded value type. If the field is not a patient attribute, the attributeDetails will not be given.

 The attribute details contain the below fields,

PropertyDescription
descriptionIts a description
formatjava class of the attribute
namename of the attribute
uuiduuid of the attribute

Example Fields:

Code Block
description: "मरीज़ का उपनाम"
format: "java.lang.String"
name: "familyNameLocal"
required: false
uuid: "b4f44ade-c79a-11e2-b284-107d46e7b2c5"


Code Block
languagejs
titleCode Snippet
linenumberstrue
collapsetrue
Bahmni.Registration.customValidator = {
    "age.days": {
        method: function (name, value) {
            return value >= 0;
        },
        errorMessage: "REGISTRATION_AGE_ERROR_KEY"
    },
    "Telephone Number": {
        method: function (name, value, personAttributeDetails) {
            return value && value.length> 6;
        },
        errorMessage: "REGISTRATION_TELEPHONE_NUMBER_ERROR_KEY"
    },
    "caste": {
        method: function (name, value, personAttributeDetails) {
            return value.match(/^\w+$/);
        },
        errorMessage: "REGISTRATION_CASTE_TEXT_ERROR_KEY"
    }
};