GDA-SMDS : Conditional Check Implementation in Ruleset Table - Solution LLD
Created by Srikant Sahoo, last modified on Feb 10, 2025
- What is the
conditional_checkcolumn in the ruleset table, and why is it necessary?
All rules are stored in thesmds_generic_country_rulestable. However, not all rules are straightforward in CMD, and some rules depend on others. To effectively manage these rule dependencies, it is essential to include theconditional_checkcolumn within the same table. - How to interpret the
conditional_checkvalues?
Currently, there are two types ofconditional_check, each with distinct meanings:- OR separator
|- This indicates that both rules are optional, but at least one must be provided. - AND separator
&- This signifies that the second rule is dependent on the first. In other words, the second rule applies only when the first rule is satisfied.
- OR separator
- Let's explore some examples of
conditional_checkimplementations below:- Street Number mandatory requirement
CMD1-5948 -Customer and facility street name mandatory In Progress
- Street Number mandatory requirement
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check |
|---|---|---|---|---|---|---|---|---|
| OM | STREET_NAME | X | For Oman, the street name is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ | ||||
| OM | PO_BOX | For country Oman, PO Box is optional and length must not be more than 10 characters. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ |
Explanation - Here for Oman the STREET_NAME is mandatory and PO_BOX is optional.
| STREET_NAME | PO_BOX | Is Valid? |
|---|---|---|
| ABC | YES | |
| ABC | NO | |
| ABC | ABC | YES |
| NO |
b. Any other country - CH, IN, PK etc
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check |
|---|---|---|---|---|---|---|---|---|
| LT | STREET_NAME | X | For Lithuania, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ | STREET_NAME | PO_BOX | |||
| LT | PO_BOX | For Lithuania, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ | STREET_NAME | PO_BOX |
Explanation - Here for Lithunia or any other countries, both the STREET_NAME and PO_BOX is optional. But the user needs to enter either one of them.
| STREET_NAME | PO_BOX | Is Valid? |
|---|---|---|
| ABC | YES | |
| ABC | YES | |
| ABC | ABC | YES |
| NO |
c. AE PO_BOX mandatory requirement - CMD1-4114 -Make UAE PO box and phone number mandatory Done
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check |
|---|---|---|---|---|---|---|---|---|
| AE | PO_BOX | X | 2 | 100 | For country U. A. E., PO Box is mandatory and length must be from 1 to 10 characters. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ | ||
| AE | STREET_NAME | X | For UAE, the street name is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ |
Explanation - Here for UAE both STREET_NAME and PO_BOX are mandatory. The user needs to enter both of them.
| STREET_NAME | PO_BOX | Is Valid? |
|---|---|---|
| ABC | NO | |
| ABC | NO | |
| ABC | ABC | YES |
| NO |
d. US requirement - CMD1-4492 -Make US street number mandatory Done
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check |
|---|---|---|---|---|---|---|---|---|
| US | STREET_NUMBER | X | Please enter the PO Box. If the PO Box is blank, the Street Number and the Street Name must be entered. | STREET_NUMBER | PO_BOX | ||||
| US | STREET_NAME | X | Please enter the PO Box. If the PO Box is blank, the Street Number and the Street Name must be entered. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ | STREET_NAME | PO_BOX | |||
| US | PO_BOX | Please enter the PO Box. If the PO Box is blank, the Street Number and the Street Name must be entered. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ | **STREET_NAME | PO_BOX | STREET_NUMBER** WIP |
| STREET_NUMBER | STREET_NAME | PO_BOX | Is Valid? |
|---|---|---|---|
| ABC | ABC | YES | |
| ABC | ABC | YES | |
| ABC | ABC | ABC | YES |
| ABC | NO | ||
| ABC | NO | ||
| ABC | YES | ||
| ABC | ABC | YES | |
| NO |
STREET_NUMBER and STREET_NAME are mandatory only if PO_BOX is not entered.
If pobox is entered no need to enter anything.
e. Brazil - CMD1-5441 -Brazil tax rule change Done
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check |
|---|---|---|---|---|---|---|---|---|
| BR | TAXNO2 | XWIP | A | 11 | For country Brazil, Tax Number 2 field (CPF) should be 11 numeric digits, format NNNNNNNNNNN. Also, either CNPJ (BR1) or CPF (BR2) is mandatory for Brazil customers. | ^[0-9]{11}$ | TAXNO1 | TAXNO2 | |
| BR | TAXNO1 | A | 14 | For Country Brazil, Tax Reference field (CNPJ) length must be 14 numeric digits, format NNNNNNNNNNNNNN. Also, either CNPJ (BR1) or CPF (BR2) is mandatory for Brazil customers. | ^[0-9]{14}$ | (TAXNO1 & TAXNO3 & TAXNO4 & TAXNO5) | TAXNO2 WIP | ||
| BR | TAXNO5 | 0 | 9 | For country Brazil, Tax Number 5 field (SUFRAMA ID) must not be more than 9 digits. Also Tax Number 5 field is optional when TAX Number 1 is entered. | ^[0-9]{0,9}$ | TAXNO1 & TAXNO5 | ||
| BR | TAXNO4 | C | 0 | 18 | For country Brazil, Tax Number 4 field (Municipal Tax) must not be more than 18 digits. Also, Tax Number 4 field is optional when TAX Number 1 is entered. | ^[0-9]{0,18}$ | TAXNO1 & TAXNO4 | |
| BR | TAXNO3 | X | C | 1 | 14 | For country Brazil, Tax Number 3 field (State Tax) must not be more than 14 digits or ‘ISENTO’. Also, Tax Number 3 field is mandatory when TAX Number 1 is entered. | ^ISENTO$|^[0-9]{1,14}$ | TAXNO1 & TAXNO3 |
| BR | STREET_NAME | X | For Brazil, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ | STREET_NAME | PO_BOX | |||
| BR | PO_BOX | For Brazil, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ | STREET_NAME | PO_BOX |
Here either of TAXNO1 or TAXNO2 needs to be entered.
TAXNO5, TAXNO4, TAXNO3 are dependent on TAXNO1 i.e only if TAXNO1 is entered then the TAXNO5, TAXNO4 and TAXNO3 are applicable.
And since there is a mandatory indicator in TAXNO3, it means it needs to be entered by the user whenever TAXNO1 is present, whereas TAXNO4 and TAXNO5 are optional even though both are dependent on TAXNO1.
If someone enters TAXNO2 then they can choose to not enter anything else since there are no other dependent rules related to it.
Future enhancements
- (TAXNO1 & TAXNO3 & TAXNO4 & TAXNO5) | TAXNO2 - Complex strings in conditional checks
- Merging the tables of facility and ruleset into a single table, can include rules for contact etc.
f. Thailand - CMD1-5224 -Enable branch ID for Thailand customers Done
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check |
|---|---|---|---|---|---|---|---|---|
| TH | TAXNO1 | A | 13 | For Country Thailand, Tax Reference field length must be 13 numeric digits,format NNNNNNNNNNNNN Ex: 1234567890987 | ^[0-9]{13}$|^ZZ$ | |||
| TH | BID | X | For Thailand, the Branch ID is mandatory if the Thailand tax ID is entered and the format is ‘NNNNN’. For example, “00000”, “00001”, … “99999” etc.” | ^\d{5}$ | TAXNO1 & BID | |||
| TH | STREET_NAME | X | For Thailand, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ | STREET_NAME | PO_BOX | |||
| TH | PO_BOX | For Thailand, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ | STREET_NAME | PO_BOX |
Here BID is applicable only when TAXNO1 is entered. And BID is mandatory only when it TAXNO1 is entered. If there is no TAXNO1 then BID cannot be added to the customer.
g. ROC for Malaysia ( WIP ) - CMD1-6090 -Malaysia ROC number / Company Registration Number mandatory To Do
Approach 1
| country_iso_code | field_type | mandatory_ind | check_type | check_exact_lo | check_max_hi | check_mask | check_mask_exp | conditional_check | isExternalCheckApplicable, excludeRule |
|---|---|---|---|---|---|---|---|---|---|
| MY | CRN | 1 | 40 | For country Malaysia CRN can be between 1 to 40 in length. | ^[a-zA-Z0-9.,:;$%&+\]\[\*\"\(\)\/'\^\-\s]{1,40}$|^ZZ | ||||
| MY | COR | X | 3 | 12 | For Country Malaysia, Customer reference field length can be from 3 digit to 12 digits, format N(1 to 10 times)-L (Where N denotes number and L denotes Letter) or LLNNNNNNN-L | ^[0-9]{1,10}[-]{1}[A-Z]{1}$|^[A-Z]{2}[0-9]{7}[-]{1}[A-Z]{1}$ | ^ZZ$ | ROC | COR | |
| MY | ROC | A | 12 | For Country Malaysia, Register Of Company length must be 12 digit. Format NNNNNNNNNNNN | ^[0-9]{12}$ | ROC | COR | |||
| MY | REGION | For country Malaysia, State field is mandatory. | ^[A-Z0-9\&\'\- ]{1,50}$ | REGION & (ROC | COR) | } | ||||
| MY | STREET_NAME | X | For Malaysia, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,36}$ | STREET_NAME | PO_BOX | ||||
| MY | PO_BOX | For Malaysia, either Street Name or P.O Box is mandatory. | ^[a-zA-Z0-9.,:;$%&+\]\[*\"( )'\/^\-]{0,10}$ | STREET_NAME | PO_BOX |
Approach 2 - (Preferred)
| MY | ROC | COR | X | For Malaysia, either of ROC(Registration of Company) or COR(Customer’s own Reference number) reference is mandatory. | ROC | COR |
|---|
API
/validate-rules -
Here the ROC | COR rule can be read by the API and UI and based on the conditional check the rules can be checked.
// Psuedo Code
if(Ruleset["ROC|COR"].isMandatory){ // logic here to return the formatCheckDescription of either ROC | COR is mandatory if the cases does not satisfy
if ( !CMDApplicationConfig.anyMatch(CustomerRegion == IgnoreCase(configRegion)){ // check here if either ROC or COR is entered/not empty // if it is empty then throw formatCheckDescription error of rule "ROC | COR" // if it is entered then pass the validation } else { // else pass the validation if Region is Sabah or Sarawak // No need to write any logic here } }
BBU scenario - Address template on region/city change should throw an error of ROC | COR.
Similar above logic can be placed to validate whether the references are present in the customer or not, otherwise, the user needs to first enter the reference then update the address.
| Matrix | ROC | COR | Result |
|---|---|---|---|
| Other regions | Y | VALID | |
| Other regions | Y | Y | VALID |
| Other regions | INVALID | ||
| Other regions | Y | VALID | |
| SABAH/SARAWAK | Y | VALID?(Doubt) | |
| SABAH/SARAWAK | Y | Y | VALID |
| SABAH/SARAWAK | INVALID | ||
| SABAH/SARAWAK | Y | VALID |
Requirement analysis of ROC & COR
- For MY it’s COR whose length is 12 and also there is an existing regex. Its not CRN as mentioned in Epic.
- As per the email thread
ROC – 12 digits NNNNNNNNNNNN
Customer’s Own Reference Number – NNNNNN-X format.
Below is a dynamic approach for calibrating the rules in CMD - This approach can be implemented when we work on the next ruleset requirement.
Due to current limited bandwidth we are going with the above mentioned ROC | COR implementation.
Expected JSON Structure
[
{
"fieldType": "PO_BOX",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["STREET_NAME"],
"message": "For Malaysia, either Street Name or P.O Box is mandatory."
}
],
"formatCheck": {
"pattern": "^[a-zA-Z0-9.,:;$%&+\\]\\[*\\\"( )'\\/^\\-]{0,10}$",
"description": "For Malaysia, P.O Box must be a maximum of 10 characters."
}
},
"properties": {
"isMandatory": false,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
{
"fieldType": "STREET_NAME",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["PO_BOX"],
"message": "For Malaysia, either Street Name or P.O Box is mandatory."
}
],
"formatCheck": {
"pattern": "^[a-zA-Z0-9.,:;$%&+\\]\\[*\\\"( )'\\/^\\-]{0,36}$",
"description": "For Malaysia, Street Name must be a maximum of 36 characters."
}
},
"properties": {
"isMandatory": true,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
{
"fieldType": "ROC",
"validation": {
"rules": [
{
"type": "DISABLES",
"fields": ["REGION"],
"condition": { "values": ["SARAWAK", "SABAH"] },
"message": "ROC is not applicable when REGION is SARAWAK or SABAH."
},
{
"type": "DISABLES",
"fields": ["CITIES"],
"condition": { "values": ["SARAWAK", "SABAH"] },
"message": "ROC is not applicable when REGION is SARAWAK or SABAH."
}
],
"formatCheck": {
"pattern": "^[0-9]{12}$",
"description": "For Malaysia, Register Of Company (ROC) must be 12 numeric digits."
}
},
"properties": {
"isMandatory": true,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
{
"fieldType": "COR",
"validation": {
"rules": [
{
"type": "MANDATORY_IF",
"condition": { "field": "REGION", "values": ["SARAWAK", "SABAH"] },
"message": "COR is mandatory when REGION is SARAWAK or SABAH."
}
],
"formatCheck": {
"pattern": "^[0-9]{1,10}[-]{1}[A-Z]{1}$|^[A-Z]{2}[0-9]{7}[-]{1}[A-Z]{1}$|^ZZ$",
"description": "For Malaysia, COR must follow one of the formats: N(1-10)-L, LLNNNNNNN-L, or 'ZZ'."
}
},
"properties": {
"isMandatory": false,
"isDependent": false,
"isApplicable": true,
"isExternalCheckApplicable": false
}
},
{
"fieldType": "BR2",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["BR1"],
"message": "Either BR1 or BR2 must be provided."
},
{
"type": "MANDATORY_IF",
"condition": { "field": "BR2", "valueExists": true },
"fields": ["BR3", "BR4"],
"message": "If BR2 is provided, BR3 and BR4 must also be provided."
},
{
"type": "OPTIONAL_IF",
"condition": { "field": "BR2", "valueExists": true },
"fields": ["BR5"],
"message": "If BR2 is provided, BR5 is optional."
},
{
"type": "DISABLES",
"fields": ["BR6", "BR7"],
"condition": { "field": "BR2", "valueExists": true },
"message": "If BR2 is provided, BR6 and BR7 cannot be entered."
}
],
"formatCheck": {
"pattern": "^[0-9]{14}$",
"description": "For Country Brazil, Tax Reference field (CNPJ) must be 14 numeric digits (NNNNNNNNNNNNNN)."
}
},
"properties": {
"isMandatory": false,
"isApplicable": true,
"isDependent": false,
"isExternalCheckApplicable": true
}
},
{
"fieldType": "BR2",
"validation": {
"rules": [
{
"type": "ANY_OF",
"fields": ["BR1"],
"message": "Either BR1 or BR2 must be provided."
}
],
"formatCheck": {
"pattern": "^[0-9]{11}$",
"description": "For Country Brazil, Tax Number 2 (CPF) must be 11 numeric digits (NNNNNNNNNNN)."
}
},
"properties": {
"isMandatory": false,
"isApplicable": true,
"isDependent": false,
"isExternalCheckApplicable": true
}
},
{
"fieldType": "BR3",
"validation": {
"formatCheck": {
"pattern": "^ISENTO$|^[0-9]{1,14}$",
"description": "For Country Brazil, Tax Number 3 (State Tax) must not exceed 14 digits or the value 'ISENTO'."
},
"rules": [
{
"type": "MANDATORY_IF",
"condition": { "field": "BR1", "valueExists": true },
"message": "Tax Number 3 is mandatory when BR1 is provided."
}
]
},
"properties": {
"isMandatory": true,
"isApplicable": true,
"isDependent": true,
"isExternalCheckApplicable": true
}
},
{
"fieldType": "BR4",
"validation": {
"formatCheck": {
"pattern": "^[0-9]{0,18}$",
"description": "For Country Brazil, Tax Number 4 (Municipal Tax) must not exceed 18 digits."
},
"rules": [
{
"type": "OPTIONAL_IF",
"condition": { "field": "BR1", "valueExists": true },
"message": "Tax Number 4 is optional when BR1 is provided."
}
]
},
"properties": {
"isMandatory": false,
"isApplicable": true,
"isDependent": true,
"isExternalCheckApplicable": true
}
}
]
// Example rule enums
- ANY_OF
- ALL_OF
- DISABLES
- ENABLES
- VALUE
- IS_MANDATORY
- IS_NOT_MANDATORY
- FIELDS
- ANY_OF_FIELDS
- ALL_OF_FIELDS
- ANY_OF_VALUES