Skip to content

Date picker Field

Benjamin Mwalimu edited this page Jan 15, 2021 · 4 revisions

Date Picker Field

This is a Material design date selection input field that is identified by type date_picker in the JSON.

Field attributes

Field Attribute Usage Required
key Unique of the field yes
type Type of the field yes
hint The hint/text displayed to the user no
expanded Determines whether the whole month calender is shown or just the date selection popup is displayed. If set to true then the whole calendar is displayed. If set to false then only the date selector popup is displayed yes
value Holds the user entry. It's a string literal. Only needed in case the field has a predefined entry otherwise it's always auto-generated/automatically added through code no
read_only Holds the read-only status of a specific field. true - means the user cannot enter/type anything on the field. They can only view what is presented no
default Holds the value of the default date if any no
duration Calculates the time period between the date selected and the date today e.g, if the date selected, is 2021-01-01 and the date today is 2021-01-04 then the duration will be 3days or 0 years depending on the field. no
duration.label Hold the texts that will be the postfix to the calculated period e.g age no
min_date Defines the minimum date the that can be selected on the date picker no
max_date Defines the maximum date that can be selected on the date picker no
v_required Status to indicate whether this field is required or not no
relevance Holds the rules to show/hide the specific field. This can use rules engine/ the line relevance no
calculations Holds the link to the rules files that has a calculation affects the field in question no
openmrs_entity_parent Holds the concept id of the parent concept in OpenMRS yes
openmrs_entity Holds the entity type on OpenMRS e.g Person, Address, Concept yes
openmrs_entity_id Holds the concept id from OpenMRS no

Example JSON

{
  "key": "user_date",
  "openmrs_entity_parent": "",
  "openmrs_entity": "",
  "openmrs_entity_id": "",
  "type": "date_picker",
  "hint": "User DOB",
  "expanded": false,
  "duration": {
    "label": "Age"
  },
  "default": "12-12-2015",
  "min_date": "today-5y",
  "max_date": "today",
  "v_required": {
    "value": "true",
    "err": "Please enter the date of birth"
  },
  "relevance": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-relevance-rules.yml"
      }
    }
  },
  "calculation": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-calculation-rules.yml"
      }
    }
  }
}

Field Validation

min_date, max_date are used to validate the field.

min_date --- Holds the minimum date that the date picker can display/allow. max_date --- Holds the maximum date the date picker can display/allow.

Required Status

To make a field required add v_required attribute with value true. The text on the err attribute will be displayed to the user in case the field is not filled.

Rules

Calculations

  "calculation": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-calculation-rules.yml"
      }
    }
  }

The block above shows the rules engine relevance block.

Relevance

"relevance": {
    "rules-engine": {
      "ex-rules": {
        "rules-file": "sample-relevance-rules.yml"
      }
    }
  }

The block above shows the rules engine relevance block.