This document describes the primitive DSL commands that can be used to transform a REDCap‐style data dictionary into a fully compliant REDCap dictionary. Each command is written in a function-call style and operates on a specific row or column.
-
EnsureColumn(columnName) Add a new (empty) column named
columnNameif it does not already exist. New cells will contain the empty string (""). -
RenameColumn(oldName, newName) If a column header exactly matches
oldNameandnewNameis not already in use, renameoldNametonewName. -
SetFormName(row, formName) Overwrite the “Form Name” cell in the given 1-based
rowwith the stringformName. If the “Form Name” column does not exist, it is created first. -
SetVariableName(row, newName) Overwrite the “Variable / Field Name” cell in the given 1-based
rowwithnewName. IfnewNamealready appears elsewhere in that column, append an underscore and a numeric suffix (_2,_3, …) until a unique name is found. -
LowercaseVariableName(row) Convert the existing “Variable / Field Name” in the given 1-based
rowto all lowercase, ensuring the result stays unique by adding a numeric suffix when needed. Raises an error if the lowercase value still violates REDCap variable name rules. -
SetFieldType(row, fieldType) Overwrite the “Field Type” cell in the given 1-based
rowwithfieldType, which must be one of:text, notes, radio, checkbox, dropdown, calc, file, yesno, truefalse, slider, descriptive, date, datetime -
ClearCell(row, columnName) Overwrite the cell at 1-based
rowin columncolumnNamewith the empty string (""). IfcolumnNamedoes not exist yet, it is first created as an empty column, and then the cell is set to"". -
SetChoices(row, [ (code,label), … ]) Overwrite the “Choices, Calculations, OR Slider Labels” cell in the given 1-based
rowwith a string of the form:code1,label1 | code2,label2 | …Each pair
(code,label)is formatted ascode,labeland joined with" | ". -
SetSlider(row, minValue, "minLabel", maxValue, "maxLabel") Overwrite the “Choices, Calculations, OR Slider Labels” cell in the given
rowwith:minValue,minLabel | maxValue,maxLabel -
SetFormula(row, "formulaString") Overwrite the “Choices, Calculations, OR Slider Labels” cell in the given
rowwith the literal string
formulaString
(usually prefixed by calc: if desired, but the DSL does not enforce
a specific prefix).
-
SetFormat(row, "formatString") Overwrite the “Text Validation Type OR Show Slider Number” cell in the given
rowwithformatString(e.g.date_ymdor a datetime pattern). If the column does not exist, it is first created. -
SetValidation(row, "validationType", "minValue", "maxValue") Populate three cells in the given
row:- “Text Validation Type OR Show Slider Number” ←
validationType - “Text Validation Min” ←
minValue - “Text Validation Max” ←
maxValueIf any of these columns does not exist, it is first created.
- “Text Validation Type OR Show Slider Number” ←
-
CreateOutputSheet(sheetName) Initialize or clear the single destination sheet (
sheetName) that will collect all processed rows. Called exactly once at script start. Name must be a valid sheet name -
ProcessSheet(sheetName, startRow) Switch context to the source sheet
sheetNameand begin processing at the specified 1‑based header row (startRow). All subsequent commands apply to each data row and append directly to the output sheet. -
MapColumn(fromName, toName) Record a mapping from a raw header
fromNameto a canonical headertoName. This replaces the oldRenameColumnto emphasize that mappings are not in‑place renames but logical associations used during processing. -
DeleteRowsIfEmpty([columnName1, columnName2, …]) Delete any row where any of the listed canonical columns is blank or consists only of whitespace. Use this to remove rows lacking a variable name and/or a field label.
-
SetCell(row, columnName, value) A catch‑all primitive for writing a constant
valueinto the cell at 1‑basedrowandcolumnName. Creates the column if needed.
# Setting the output sheet name
CreateOutputSheet("REDCap")
# Ensure all required columns exist
EnsureColumn("Variable / Field Name")
EnsureColumn("Form Name")
EnsureColumn("Field Type")
EnsureColumn("Field Label")
EnsureColumn("Choices, Calculations, OR Slider Labels")
EnsureColumn("Text Validation Type OR Show Slider Number")
EnsureColumn("Text Validation Min")
EnsureColumn("Text Validation Max")
# Rename a raw header
RenameColumn("VarNameRaw", "Variable / Field Name")
# Map a column during output generation
ProcessSheet("Demographics", 3)
DeleteRowsIfEmpty(["Variable / Field Name", "Field Label"])
MapColumn("VarRaw", "Variable / Field Name")
EnsureColumn("Field Type")
# Set a custom form name on every row
SetFormName(2, "baseline_survey")
SetFormName(3, "baseline_survey")
# Ensure uniqueness of variable names
SetVariableName(5, "age")
SetVariableName(6, "age") # becomes "age_2" if "age" already exists
# Change a field type to yesno and populate default choices
SetFieldType(8, yesno)
SetChoices(8, [("1","Yes"),("0","No")])
# Change a field type to radio with three options
SetFieldType(10, radio)
SetChoices(10, [("A","Option A"),("B","Option B"),("C","Option C")])
# Change a field to slider
SetFieldType(12, slider)
SetSlider(12, 0, "None", 10, "Extreme")
# Remove any residual choices when converting to text
SetFieldType(15, text)
ClearCell(15, "Choices, Calculations, OR Slider Labels")
# Set a calculation formula
SetFieldType(18, calc)
SetFormula(18, "[var1] + [var2]")
# Set date format hint
SetFieldType(21, date)
SetFormat(21, "YYYY-MM-DD")
# Set text validation range
SetFieldType(25, text)
SetValidation(25, "integer", "18", "99")