Skip to content

Instantly share code, notes, and snippets.

@ppazos
Last active December 19, 2019 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppazos/d9478bff574ef7064f3d882a6337baaa to your computer and use it in GitHub Desktop.
Save ppazos/d9478bff574ef7064f3d882a6337baaa to your computer and use it in GitHub Desktop.
Ideas for UI rules
  1. Default visibility (ACTION)

    "ff0001": {
      "visible": false
    }
    
    
    "ff0001": {
       "visible": true
    }
    
  2. Visibility based on other field value, when value is set or is changed (show ff0001 when ff0008 value changes to true), the value or values depend on the type assigned to the field ff0008 (RULE):

    "ff0001": {
       "when": {
         "code": "ff0008",
         "is": true,
         "apply": {    <<<< set of actions
            "visible": true
         }
      }
    }
    

2.1. Similar, but checking against many values:

   "ff0001": {
      "when": {
         "code": "ff0008",
         "in": ["a", "b", "c"],
         "apply": {    <<<< set of actions
            "visible": true
         }
      }
   }

2.2. Similar, but the when.code field could contain many values:

"ff0001": {
   "when": {
      "code": "ff0008",
      "contains": 123,
      "apply": {    <<<< set of actions
         "visible": true
      }
   }
}

2.3. Constraints depending on rules / conditional constraints (applies a CONSTRAINT instead of an ACTION)

This could be applied to a field or an attribute of a field, and follows this logic, the list of rules are applied in order and the first match is the only match:

 field: [
    if (condition1(other_field, params)) then apply_constraint(field, constraint1),
    if (condition2(other_field, params)) then apply_constraint(field, constraint2),
    ...
 ]
 
  "ff0019": {         // quantity field
     "/units": [      // constraint over units attribute
        {             // first IF
           "when": "ff0018",   // other field
           "in": [             // condition 1
              "cv0001",
              "cv0002",
              "cv0003",
              "cv0004",
              "cv0005",
              "cv0006",
              "cv0007",
              "cv0008"
           ],
           "then": {
              "in_list": [     // conditional constraint
                 "ml/h"
              ]
           }
        },
        {                      // second IF
           "when": "ff0018",   // other field
           "in": [             // condition 2
              "cv0009",
              "cv0010",
              "cv0011"
           ],
           "then": {
              "in_list": [     // conditional constraint
                 "U"
              ]
           }
        }
     ]
  }

Instead of applying those rules to the /units field only, those could be applied to the whole quantity:

  "ff0019": {              // quantity field
       "when": "ff0018",   // other field
       "in": [             // condition 1
          "cv0001",
          "cv0002",
          "cv0003",
          "cv0004",
          "cv0005",
          "cv0006",
          "cv0007",
          "cv0008"
       ],
       "then": {
          "in_list": [
             {
                "/units": "ml/h"   // this object can constraint also the magnitude
             }
          ]
       },
       "else": {           // introducing the "else" for the "when"
          "when": "ff0018",
           "in": [
              "cv0009",
              "cv0010",
              "cv0011"
           ],
           "then": {
              "in_list": [
                 {
                    "/units": "U"
                 }
              ]
           }
       }
   }
  1. Occurrences of field or group, no mention of max or min means 1, max = -1 means unbounded, max = 0 means prohibited (SCHEMA/CONSTRAINT)

    "ff0001": {
       "occurrences": {
          "min": 1,
          "max": 1
       }
    }
    
  2. Cleaning field values (ACTION)

    "ff0001": {
       "clean": true
    }
    

4.1. Conditional cleaning: clean ff0001 value when ff0008 multiple values contain 123 (ACTION in RULE)

"ff0001": {
   "when": {
      "code": "ff0008",
      "contains": 123,
      "apply": {    <<<< set of actions
         "clean": true
      }
   }
}
  1. Set / change value: default value, the value will depend on the type declared for the field (ACTION)

    "ff0001": {
       "assign": true
    }
    

5.1. Conditional set: set ff0001 value when ff0008 multiple values contain 123 (ACTION in RULE)

"ff0001": {
   "when": {
      "code": "ff0008",
      "contains": 123,
      "apply": {    <<<< set of actions
         "assign": true
      }
   }
}

5.1 Assign using functions (FUNCTION / ACTION)

   "ff0001": {
      "assign": "now()"
   }
   
   "ff0001": {
      "assign": "random()"
   }
   
   "ff0001": {
      "assign": "random(0,1000)"
   }
  1. Data constraints for coded data: source terminology (CONSTRAINT)

    "ff0001": {    // this is a code
       "/terminology_id": {
          "data_source": "SNOMED CT" // data_source is an external terminology ID
       }
    }
    

6.1. Data constraints for coded data: codes desfined in the def (the coded values names are defined in the terminology section) (CONSTRAINT)

  "ff0002": {
     "in_list": [
        "cv0001",
        "cv0002",
        "cv0003"
     ]
  }
  1. Data constraints for strings: local list (CONSTRAINT)

    "ff0001": {
       "in_list": [
          "a",
          "b",
          "c"
       ]
    }
    

7.1. Data constraints list for numbers: local list (CONSTRAINT)

   "ff0001": {
      "in_list": [
         1,
         2,
         3
      ]
   }

7.2. Data constraint list for numbers: boundaries, no constraint means unbounded (CONSTRAINT)

"ff0001": {
   "min": 0,
   "max": 1000
}
  1. Data constraints list on a field of a structure datatype (CONSTRAINT)

    "ff0001": {      <<< quantity
       "/units": {   <<< starts with / is a field
          "in_list": [  <<< same constraints as above in_list, this case is for a string
            "mm[Hg]",
            "mm[H2O]"
          ]
       }
    }
    
    "ff0001": {      // code
       "/code": {    // constraint on one field
          "in_list": [
            "fv0001",
            "fv0002"
          ]
       }
    }
    
  2. Data constraint list for complex types (code, ordinal, ...) (CONSTRAINT)

    "ff0001": {        // code
       "in_list": [    // list of complex objects, another way of writing constraint 2 in point 8.
          {
             "/code": "fv0001"
          },
          {
             "/code": "fv0002"
          }
       ]
    }
    
    "ff0001": {        // ordinal
       "in_list": [    // list of complex objects
          {
             "/ordinal": 1,
             "/code": "fv0001"
          },
          {
             "/ordinal": 2,
             "/code": "fv0002"
          }
       ]
    }
    
    "ff0001": {        // quantity
       "in_list": [    // list of complex objects, another way of writing constraint 1 in point 8.
          {
             "/units": "ml"
          },
          {
             "/units": "cc"
          }
       ]
    }
    
  3. Calculated data, only for numeric fields (for instance for Glasgow coma scale and body mass index)

    "ff0004": {
       "calc": {
          "using": [
             "ff0001", "ff0002", "ff0003"   // these other fields should have values set to be able to calculate
          ],
          "formula": "ff0001 + ff0002 + ff0003"   // only simple arithmetic operations are allowed + - * /
       }
    }
    
    "ff0003": {
       "calc": {
          "using": [
             "ff0001", "ff0002"
          ],
          "formula": "ff0001 / ff0002 * ff0002"   // ff0001 is weight in Kg, ff0002 is height in m
       }
    }
    

10.1. Calculated, using constants and fields

    "ff0004": {
       "calc": {
          "using": [
             "ff0002", "ff0003"   // these other fields should have values set to be able to calculate
          ],
          "formula": "1.5 * ff0002 + ff0003"
       }
    }
  1. Complex constraint: in_list and boundary on complex types (quantity)

    "ff0001": {          // quantity
       "constraints": [  // comnplex constraint
          {
             "/units": "ml",
             "/magnitude": {
                "min": 0,
                "max": 100
             }
          },
          {
             "/units": "cc",
             "/magnitude": {
                "min": 0,
                "max": 100
             }
          }
       ]
    }
    

TODO: mandatory data constraint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment