RuleDef:
  type: object
  properties:
    RuleID:
      type: integer
    RuleCode:
      type: string
      example: AUTO_SET_RESULT
    RuleName:
      type: string
      example: Automatically Set Result
    Description:
      type: string
      nullable: true
    EventCode:
      type: string
      example: ORDER_CREATED
    ConditionExpr:
      type: string
      nullable: true
      description: Raw DSL expression (editable)
      example: "if(sex('M'); result_set(0.5); result_set(0.6))"
    ConditionExprCompiled:
      type: string
      nullable: true
      description: Compiled JSON structure (auto-generated from ConditionExpr)
      example: '{"conditionExpr":"patient[\"Sex\"] == \"M\"","valueExpr":"(patient[\"Sex\"] == \"M\") ? 0.5 : 0.6","then":[{"type":"RESULT_SET","value":0.5,"valueExpr":"0.5"}],"else":[{"type":"RESULT_SET","value":0.6,"valueExpr":"0.6"}]}'
    CreateDate:
      type: string
      format: date-time
      nullable: true
    StartDate:
      type: string
      format: date-time
      nullable: true
    EndDate:
      type: string
      format: date-time
      nullable: true

RuleWithDetails:
  allOf:
    - $ref: './rules.yaml#/RuleDef'
    - type: object
      properties:
        linkedTests:
          type: array
          items:
            type: integer
          description: Array of TestSiteIDs this rule is linked to. Rules are active only when attached to tests.

TestRule:
  type: object
  description: Mapping between a rule and a test site (testrule table). Rules are active when linked via this table.
  properties:
    TestRuleID:
      type: integer
    RuleID:
      type: integer
    TestSiteID:
      type: integer
    CreateDate:
      type: string
      format: date-time
      nullable: true
    EndDate:
      type: string
      format: date-time
      nullable: true
