> ## Documentation Index
> Fetch the complete documentation index at: https://developer.eka.care/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a rule



## OpenAPI

````yaml api-reference/doc-tool/ipd-api/protocol-openapi.json post /protocol/workflow/rules
openapi: 3.1.0
info:
  title: Eka Protocol API
  version: '1.0'
  description: >-
    Hospital workflows for IPD: rules, the tasks they create, and the forms
    filled on an admission.
servers:
  - description: Production
    url: https://api.eka.care
  - description: Stage/Sandbox
    url: https://api.dev.eka.care
security: []
tags:
  - name: Tasks
    description: >-
      Workflow tasks at a hospital. Rules create them; users claim, release,
      complete and cancel them here. Task documents are also readable live from
      Firestore (`protocol/{bid}/tasks`) through `@orbi/protocol-sdk`; every
      change goes through this API.
  - name: Forms
    description: >-
      Forms filled on an entity (today: an admission, the IPD Forms tab) and
      what happened to each.
  - name: Rules
    description: >-
      Hospital workflow rules: events → conditions → tasks. Each save is a new
      version, compiled to a workflow.
  - name: Catalog
    description: The events and fields rules are written against.
  - name: Events
    description: 'Fire an event for a scope: every active rule on it starts a run.'
  - name: SA forms
    description: >-
      The hospital's SA forms (its own and the system ones), with versions and
      archiving.
  - name: SA form drafts
    description: SA forms saved before they are ready. Not offered in IPD until published.
  - name: AI drafts
    description: Draft an SA form from a prompt or a file with AI.
paths:
  /protocol/workflow/rules:
    post:
      tags:
        - Rules
      summary: Create a rule
      operationId: postRules
      parameters:
        - name: auth
          in: header
          required: true
          description: >-
            The access token. The gateway verifies it and passes the user and
            the business on.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                scope_type:
                  type: string
                  enum:
                    - ADMISSION
                    - DISCHARGE
                    - APPOINTMENT
                    - PRESCRIPTION
                    - PATIENT
                events:
                  type: array
                  items:
                    type: string
                    minLength: 1
                  minItems: 1
                  maxItems: 10
                name:
                  type: string
                  minLength: 1
                  maxLength: 120
                description:
                  anyOf:
                    - type: string
                      maxLength: 500
                    - type: 'null'
                conditions:
                  anyOf:
                    - anyOf:
                        - type: object
                          properties:
                            field:
                              type: string
                              minLength: 1
                            op:
                              type: string
                              enum:
                                - equal
                                - notEqual
                                - lessThan
                                - lessThanInclusive
                                - greaterThan
                                - greaterThanInclusive
                                - in
                                - notIn
                                - contains
                            value:
                              anyOf:
                                - type:
                                    - string
                                    - number
                                    - boolean
                                    - 'null'
                                - type: array
                                  items:
                                    type:
                                      - string
                                      - number
                          required:
                            - field
                            - op
                            - value
                          additionalProperties: false
                        - type: object
                          properties:
                            all:
                              type: array
                              items: {}
                          required:
                            - all
                          additionalProperties: false
                        - type: object
                          properties:
                            any:
                              type: array
                              items: {}
                          required:
                            - any
                          additionalProperties: false
                    - type: 'null'
                tasks:
                  type: array
                  items:
                    type: object
                    properties:
                      task_type:
                        type: string
                        enum:
                          - VITALS
                          - DOCTOR_NOTES
                          - NURSING_NOTES
                          - MEDICAL_HISTORY
                          - EMAR_MEDICATION_DOSE
                          - FORM
                      form_kind:
                        type: string
                        enum:
                          - SA
                          - CONSENT
                          - MCERT
                      sa_id:
                        type: string
                        pattern: ^\d+$
                      template_id:
                        type: string
                        minLength: 1
                        maxLength: 200
                      title:
                        type: string
                        minLength: 1
                      description:
                        type: string
                        maxLength: 1000
                      payload:
                        type: object
                        additionalProperties:
                          anyOf:
                            - type:
                                - string
                                - number
                                - boolean
                                - 'null'
                            - type: array
                              items: {}
                            - type: object
                              additionalProperties: {}
                      requiredness:
                        type: string
                        enum:
                          - MANDATORY
                          - OPTIONAL
                      blocking:
                        type: boolean
                      audience_keys:
                        anyOf:
                          - type: array
                            items:
                              type: string
                              pattern: ^(PERSONA:(D|S|AD)|USER:\S+)$
                          - type: 'null'
                      estimate:
                        anyOf:
                          - type: string
                            pattern: >-
                              ^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$
                          - type: 'null'
                      delay:
                        anyOf:
                          - type: string
                            pattern: >-
                              ^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$
                          - type: 'null'
                      every:
                        anyOf:
                          - type: string
                            pattern: >-
                              ^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$
                          - type: 'null'
                      due_in:
                        anyOf:
                          - type: string
                            pattern: >-
                              ^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$
                          - type: 'null'
                      escalation:
                        anyOf:
                          - type: object
                            properties:
                              after:
                                type: string
                                pattern: >-
                                  ^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$
                              audience_keys:
                                type: array
                                items:
                                  type: string
                                  pattern: ^(PERSONA:(D|S|AD)|USER:\S+)$
                                minItems: 1
                              title:
                                type: string
                            required:
                              - after
                              - audience_keys
                            additionalProperties: false
                          - type: 'null'
                    required:
                      - task_type
                    additionalProperties: false
                  minItems: 1
                  maxItems: 20
              required:
                - scope_type
                - events
                - name
                - conditions
                - tasks
              additionalProperties: false
      responses:
        '201':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    const: success
                  data:
                    $ref: '#/components/schemas/SavedRule'
                required:
                  - status
                  - data
        '401':
          description: No signed-in user, or no business on the session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Not in a state for this.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: The request failed validation; `details` names each invalid path.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    SavedRule:
      type: object
      properties:
        id:
          type: string
        workflow_name:
          type: string
        version:
          type: number
        active:
          type: boolean
      required:
        - id
        - workflow_name
        - version
        - active
    Error:
      type: object
      properties:
        status:
          type: string
          const: error
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            details:
              type: array
              items:
                type: object
                properties:
                  path:
                    type: string
                  message:
                    type: string
                required:
                  - path
                  - message
          required:
            - code
            - message
      required:
        - status
        - error

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.