Export Validation Flags to MongoDB
export_validation_flags.RdExports validation flags directly to MongoDB without updating KoboToolbox validation
statuses. This function replaces the workflow of sync_validation_submissions() to
avoid slow API updates to KoboToolbox. Instead, it uses KoboToolbox validation status
queries only to identify manually edited validations by human reviewers.
Usage
export_validation_flags(
conf = NULL,
asset_id = c("adnap", "lurio"),
all_flags = NULL,
validation_statuses = NULL
)Arguments
- conf
Configuration object from
read_config()containing MongoDB connection parameters and survey-specific settings- asset_id
Character string specifying which survey to process. Must be one of "adnap" or "lurio". Determines which configuration to use from
conf$ingestion$kobo-{asset_id}. Default is "adnap".- all_flags
Data frame containing all validation flags with columns:
submission_id,submitted_by,submission_date,alert_flag- validation_statuses
Data frame from
get_validation_status()with columns:submission_id,validation_status,validated_by,validation_date
Details
The function performs the following steps:
Joins validation flags with KoboToolbox validation statuses
Identifies manual human approvals (excluding system username)
Preserves manual human decisions while updating system-generated statuses
Creates both wide and long format datasets for different reporting needs
Pushes results directly to MongoDB collections
Key Differences from sync_validation_submissions():
Does NOT update validation statuses in KoboToolbox (avoids slow API calls)
Uses
validation_statusesparameter obtained viaget_validation_status()Stores final validation state only in MongoDB
Respects manual human approvals by preserving their validation status
System-generated validations are updated based on current flags
Validation Status Logic:
If submission has flags AND validated_by is system username: set to "not_approved"
If submission has no flags AND validated_by is system username: set to "approved"
If validated_by is NOT system username: preserve existing status (manual approval)
Note
This function is called internally by validate_surveys_adnap() and should not
typically be called directly. It requires:
Valid configuration with MongoDB connection string
Survey-specific configuration under
conf$ingestion$kobo-{asset_id}System username configured to identify automated vs. manual validations
MongoDB Collections
The function pushes to two MongoDB collections:
- flags-asset_id
Wide format with one row per submission including validation status and flags
- enumerators_stats-asset_id
Long format with one row per flag per submission for enumerator statistics
See also
validate_surveys_adnap()for the main validation workflowget_validation_status()for fetching KoboToolbox validation statussync_validation_submissions()for the deprecated approach that updates KoboToolboxmdb_collection_push()for MongoDB operations