Skip to content

Generic Module Framework: Logic

dehall edited this page Sep 22, 2016 · 25 revisions

The Guard state and Conditional transition use conditional (boolean) logic. The following condition types are currently supported: Gender, Age, Date, Socioeconomic Status, Attribute And, Or, Not, True, and False.

The following condition types should be considered for future versions:

  • PriorEvent: check if a patient event occurred
  • PriorState: check if a specific state is in the module's state history

Gender

The Gender condition type tests the patient's gender.

Supported Properties

  • condition_type: must be "Gender" (required)
  • gender: the gender to test for. Synthea currently defines the following gender values: M: male, and F: female (required)

Example

The following Gender condition will return true if the patient is male; false otherwise.

{
  "condition_type": "Gender",
  "gender": "M" 
}

Age

The Age condition type tests the patient's age. The following units are supported: years, months, weeks, days, hours, minutes, and seconds.

Supported Properties

  • condition_type: must be "Age" (required)
  • operator: indicates how to compare the actual age against the quantity. Valid operator values are: <, <=, ==, >=, >, and !=. (required)
  • quantity: the number, corresponding to the unit, to indicate the age to test against (required)
  • unit: the unit corresponding to the quantity. Valid unit values are: years, months, weeks, days, hours, minutes, and seconds. (required)

Example

The following Age condition will return true if the patient is 40 years old or more.

{
  "condition_type": "Age",
  "operator": ">=",
  "quantity": 40,
  "unit": "years"
}

Date

The Date condition type tests the current year being simulated. For example, this may be used to drive different logic depending on the suggested medications or procedures of different time periods, or model different frequency of conditions.

Supported Properties

  • condition_type: must be "Date" (required)
  • operator: indicates how to compare the current year of simulation against the year. Valid operator values are: <, <=, ==, >=, >, and !=. (required)
  • year: the year to test the current year of simulation againt against (required)

Example

The following Date condition will return true if the year is 1990 or later.

{
  "condition_type": "Year",
  "operator": ">=",
  "year": 1990
}

Socioeconomic Status

The Socioeconomic Status condition type tests the patient's socioeconomic status. Socioeconomic status is based on income, education, and occupation, and is categorized in Synthea as "High", "Medium", or "Low".

Supported Properties

  • condition_type: must be "Socioeconomic Status" (required)
  • category: the gender to test for. Synthea currently defines the following categories: High, Middle, or Low. (required)

Example

The following Socioeconomic Status condition will return true if the patient is "Middle" Socioeconomic Status; false otherwise.

{
  "condition_type" : "Socioeconomic Status",
  "category" : "Middle"
}

Attribute

The Attribute condition type tests a named attribute on the patient entity.

Supported Properties

  • condition_type: must be "Attribute" (required)
  • attribute: the name of the attribute to test against (required)
  • operator: indicates how to compare the actual attribute value against the value. Valid operator values are: <, <=, ==, >=, >, !=, is nil, and is not nil. (required)
  • value: the value to test the attribute value against (required, unless operator is is nil or is not nil)

Example

The following Attribute condition will return true if attribute 'Opioid Prescription' on the patient is set to 'Vicodin'.

{
  "condition_type": "Attribute",
  "attribute": "Opioid Prescription",
  "operator": "==",
  "value": "Vicodin"
}

The following Attribute condition will return true if attribute 'Opioid Prescription' on the patient has any value that is not nil.

{
  "condition_type": "Attribute",
  "attribute": "Opioid Prescription",
  "operator": "is not nil"
}

And

The And condition type tests that a set of sub-conditions are all true. If all sub-conditions are true, it will return true, but if any are false, it will return false.

Supported Properties

  • condition_type: must be "And" (required)
  • conditions[]: an array of sub-conditions to test (required)

Example

The following And condition will return true if the patient is male and at least 40 years old; false otherwise.

{
  "condition_type": "And",
  "conditions": [
    {
      "condition_type": "Gender",
      "gender": "M" 
    },
    {
      "condition_type": "Age",
      "operator": ">=",
      "quantity": 40,
      "unit": "years"
    }
  ]
}

Or

The Or condition type tests that at least one of its sub-conditions is true. If any sub-condition is true, it will return true, but if all sub-conditions are false, it will return false.

Supported Properties

  • condition_type: must be "Or" (required)
  • conditions[]: an array of sub-conditions to test (required)

Example

The following Or condition will return true if the patient is male or the patient is at least 40 years old; false otherwise.

{
  "condition_type": "Or",
  "conditions": [
    {
      "condition_type": "Gender",
      "gender": "M" 
    },
    {
      "condition_type": "Age",
      "operator": ">=",
      "quantity": 40,
      "unit": "years"
    }
  ]
}

Not

The Not condition type negates its sub-condition. If the sub-condition is true, it will return false; if the sub-condition is false, it will return true.

Supported Properties

  • condition_type: must be "Not" (required)
  • condition: the sub-condition to test (required)

Example

The following Not condition will return true if the patient is not male; false otherwise.

{
  "condition_type": "Not",
  "condition": {
    "condition_type": "Gender",
    "gender": "M" 
  }
}

True

The True condition always returns true. This condition is mainly used for testing purposes and is not expected to be used in any real module.

Supported Properties

  • condition_type: must be "True" (required)

Example

The following True condition always returns true.

{
  "condition_type": "True"
}

False

The False condition always returns false. This condition is mainly used for testing purposes and is not expected to be used in any real module.

Supported Properties

  • condition_type: must be "False" (required)

Example

The following False condition always returns false.

{
  "condition_type": "False"
}

Clone this wiki locally