Form Builder

The Form Builder module allows maintainers to programmatically define visual Form layouts and submit them to the legacy iMedNet Form Designer. This bypasses manual drag-and-drop operations when automating legacy layout updates.

Warning

Legacy Browser Session Boundary: imednet.form_designer targets only visual page layout submission to the legacy internal Form Designer endpoint (formdez_save.php) and requires scraped browser session cookies (PHPSESSID and CSRFKey)—standard REST credentials (IMEDNET_API_KEY and IMEDNET_SECURITY_KEY) are not accepted. It is not part of the official iMednet REST API and does not load Study Data Dictionaries, convert CDISC ODM XML, or validate Record edit check rules.

For canonical Study metadata conversion, CDISC ODM / REDCap / CSV loading, BusinessLogicRule evaluation, and UAT verification, see Data Dictionary Workflows and Rule Validation and UAT Workflow Guide.

Core Concepts

The module mimics the “State Dump” architecture of the Form Designer and uses a Composite Design Pattern to represent the visual Form layout.

Models and Architecture

The core building block is the Entity. An Entity can be a visual container (such as a Table or Row) or a data capture control mapped to a Variable (such as a TextField or DateTimeField).

  • TableProps: Represents a visual section or table on a Form.

  • RowProps: A horizontal arrangement of layout columns.

  • ColumnProps: A vertical container for layout controls.

  • EntityProps: A discriminated union of control properties.

This abstract structure is serialized into the hierarchical JSON payload expected by formdez_save.php.

Process

  1. Layout Definition: Define the Form layout programmatically using FormBuilder.

  2. Serialization: Call builder.build() to serialize the layout hierarchy into the formdez_save.php JSON payload.

  3. Submission: POST the payload through FormDesignerClient using an active PHPSESSID cookie and CSRFKey token.

Note

formdez_save.php overwrites the entire current layout state on save. Always verify the target --form-id, --comm-id, and next --revision number before submitting.

Usage

The primary headless entry point for FormBuilder is examples/build_form_payload.py.

Hybrid Script (Headless)

All 7 session and target flags are required when running in headless mode (--base-url may also fall back to IMEDNET_BASE_URL):

uv run --with "imednet[cli]" python examples/build_form_payload.py --preset "Demo Form" \
    --base-url "https://your.imednet.com" \
    --phpsessid "YOUR_SESSION_ID" \
    --csrf "YOUR_CSRF_KEY" \
    --form-id 12345 \
    --comm-id 999 \
    --revision 5

Presets

Reusable Form layouts are defined as presets in imednet.form_designer.presets. A preset is a function that accepts a FormBuilder instance and populates its pages:

from imednet.form_designer import FormBuilder


def build_my_form(builder: FormBuilder) -> None:
    builder.add_section_header("Subject Identification")
    builder.add_field(
        type="text",
        label="Subject Initials",
        question_name="INIT",
        required=True,
    )


builder = FormBuilder()
build_my_form(builder)
layout = builder.build()
assert len(layout.pages) == 1
print(len(layout.pages))

See imednet.form_designer.presets for additional layout examples.

API Reference