Bulk Submission Guide¶
The Bulk Record Submission Workflow manages the complexity of uploading large volumes of data by orchestrating a two-phase ingestion process. It ensures that required subject registrations complete before any subsequent data is uploaded.
Two-Phase Process¶
When submitting records in bulk, the operations are automatically separated into two phases:
Registration Phase: All
REGISTER_SUBJECTtest types are batched and submitted. The orchestrator polls until these registrations complete successfully.Data Phase: All other record types (e.g.,
CREATE_NEW_RECORD,UPDATE_SCHEDULED_RECORD) are subsequently submitted, preventing missing subject errors.
Visual Workflow¶
The following diagram illustrates the internal two-phase orchestration:
Usage Example¶
The following script sets up a bulk submission instance and illustrates the two-phase workflow:
"""Demonstrate running BulkRecordSubmissionWorkflow with GeneratedRecordSet payloads."""
import os
from imednet import ImednetSDK, load_config
from imednet_workflows.uat import BulkRecordSubmissionWorkflow, GeneratedRecordSet, RecordTestType
def main() -> None:
"""Configure and submit bulk Subject registration and Study Record sets."""
try:
cfg = load_config()
except ValueError:
cfg = load_config(simulation_mode=True)
study_key = os.environ.get("IMEDNET_STUDY_KEY", "STUDY")
with ImednetSDK(
api_key=cfg.api_key,
security_key=cfg.security_key,
base_url=cfg.base_url,
simulation_mode=cfg.simulation_mode,
) as sdk:
workflow = BulkRecordSubmissionWorkflow(
sdk,
batch_size=500,
skip_existing_subjects=True,
await_registration=True,
registration_poll_interval=0.05,
)
registration_set = GeneratedRecordSet(
form_key="F_DM",
form_name="Demographics",
test_type=RecordTestType.REGISTER_SUBJECT,
payloads=[
{
"formKey": "F_DM",
"siteName": "SITE",
"subjectKey": "SUBJ-BULK-001",
"data": {"V_AGE": 45, "V_GENDER": "M"},
}
],
subject_keys=["SUBJ-BULK-001"],
)
data_set = GeneratedRecordSet(
form_key="F_VS",
form_name="Vital Signs",
test_type=RecordTestType.CREATE_NEW_RECORD,
payloads=[
{
"formKey": "F_VS",
"siteName": "SITE",
"subjectKey": "SUBJ-BULK-001",
"intervalName": "Baseline",
"data": {"V_WEIGHT": 72.5},
}
],
subject_keys=["SUBJ-BULK-001"],
)
# Submit in two phases: Subject registration first, then Study Form data
result = workflow.submit(study_key, [registration_set, data_set])
print(
f"Submitted {result.total_records_submitted} Records across "
f"{len(result.all_batches)} Job batches for Study {result.study_key}."
)
if __name__ == "__main__":
main()
Error Handling¶
If the registration phase fails (i.e. one or more Job items return a FAILED state or record-level errors), the orchestrator raises a BulkSubmissionError immediately, avoiding cascading failures on the dependent Record data phase.
Direct Chunked Writes with create_or_update_records_batch¶
When Subject enrollment is already complete and you want schema-validated, chunked Record writes without GeneratedRecordSet wrappers, use create_or_update_records_batch() (or create_or_update_records_batch() for AsyncImednetSDK) via sdk.workflows.record_update:
from typing import Any, cast
from imednet import ImednetSDK
from imednet.simulation import reset_default_simulation_state
from imednet_workflows.record_update import RecordUpdateWorkflow
chunk_sdk = ImednetSDK(simulation_mode=True)
chunk_updater = RecordUpdateWorkflow(cast(Any, chunk_sdk), batch_size=100)
chunk_summary = chunk_updater.create_or_update_records_batch(
study_key="STUDY",
records_data=[
{
"formKey": "F_VS",
"siteName": "SITE",
"subjectKey": "SUB1",
"intervalName": "Baseline",
"data": {"V_WEIGHT": 71.0},
}
],
wait_for_completion=True,
poll_interval=1,
chunk_size=50,
)
assert chunk_summary.total_records == 1
assert chunk_summary.all_successful is True
print(chunk_summary.batch_ids, chunk_summary.all_successful)
reset_default_simulation_state()
See Record Update Workflow and Job Polling Mechanism for BatchSubmissionSummary and partial JobStatus failure triage details.
Pre-Submission Data Dictionary Validation¶
Before uploading large Record batches, pass schema=data_dictionary to
RecordUpdateWorkflow (or per call on
create_or_update_records_batch, create_or_update_records, and
sdk.records.create_batch) to validate every chunk locally against Form
required policies, Choice codelists, numeric/length bounds, and conditional XML
edit checks without extra /forms or /variables API round-trips:
from imednet import ImednetSDK
from imednet.datadict import DataDictionary, Form, Metadata, Variable
from imednet.errors import ValidationError
from imednet.simulation import SimulationState, SimulationTransport
from imednet_workflows.record_update import RecordUpdateWorkflow
vitals_dd = DataDictionary(
metadata=Metadata.create(study_key="STUDY"),
forms=[
Form(
formKey="F_VS",
formName="Vital Signs",
variables=[
Variable(
variableName="V_WEIGHT",
variableType="Float",
required="Yes",
extraAttributes={"minValue": 35.0, "maxValue": 200.0},
)
],
)
],
)
with ImednetSDK(
simulation_mode=True,
transport=SimulationTransport(SimulationState()),
) as sdk:
updater = RecordUpdateWorkflow(sdk, batch_size=50, schema=vitals_dd)
batch_summary = updater.create_or_update_records_batch(
"STUDY",
[
{
"formKey": "F_VS",
"subjectKey": "SUB1",
"intervalName": "Baseline",
"data": {"V_WEIGHT": 71.4},
}
],
)
assert batch_summary.total_records == 1
direct_summary = sdk.records.create_batch(
"STUDY",
[
{
"formKey": "F_VS",
"subjectKey": "SUB1",
"intervalName": "Baseline",
"data": {"V_WEIGHT": 72.0},
}
],
chunk_size=50,
schema=vitals_dd,
)
assert direct_summary.total_records == 1
try:
updater.create_or_update_records_batch(
"STUDY",
[
{
"formKey": "F_VS",
"subjectKey": "SUB1",
"intervalName": "Baseline",
"data": {"V_WEIGHT": 10.0},
}
],
)
except ValidationError as exc:
assert "V_WEIGHT" in str(exc)
See Data Dictionary Workflows and Rule Validation for loading a DataDictionary from CSV
exports, CDISC ODM 1.3 XML, REDCap CSV, or the REST API.