This script updates the external IDs of concepts in a given Open Concept Lab (OCL) source. It checks each concept's external ID against certain conditions and updates it if necessary. The updated external IDs are written to a CSV file.
It uses the OCL API to pull the details of each concept in the configured OCL source, check the external ID of each concept, and update it if necessary.
Here is an explanation/demo video
- If the external ID is empty
- If the external ID starts with "MSF-"
- If the external ID is not a valid 36-character UUID
- Python 3.x installed
requests
library installeduuid
library installed
- Clone this repository:
git clone https://github.com/michaelbontyes/OCL-Concept-External-ID-Updater.git
- Navigate to the project directory:
cd ocl-concept-updater
- Install the required libraries:
pip install requests uuid
- Create a
config.json
file in the project directory with the following structure:
{
"OCL_API_URL": "https://api.openconceptlab.org/",
"SOURCE_ID": "your-source-id",
"OCL_TOKEN": "your-api-token",
"ORG_ID": "your-organization-id"
}
- Replace "https://api.openconceptlab.org/", "your-source-id", "your-api-token", and "your-organization-id" with your actual OCL API URL, source ID, API token, and organization ID.
- Save the config.json file.
To run the script in dry run mode, add the --dry-run flag when executing the script.
Run the script:
python update_UUID.py --dry-run
Run the script:
python update_UUID.py
The script will update the external IDs of concepts in the specified OCL source and write the updated concepts to a CSV file named updated_concepts.csv
and updated_concepts_dry_run.csv
in Dry Run Mode.
The script creates two CSV files:
- updated_concepts.csv: Contains the details of all updated concepts, including the timestamp, concept ID, name, URL, current external ID, and new external ID.
- updated_concepts_dry_run.csv: Contains the details of all concepts that would have been updated if the script was run in dry run mode, including the timestamp, concept ID, name, URL, and current external ID.
The CSV file will have the following columns:
- ID: The ID of the concept.
- Status: If the concept was updated or not by the script.
- Valid External ID: If the external UUID is a 36-characters UUID.
- Name: The name of the concept.
- URL: The URL of the concept.
- Current External ID: The current external ID of the concept.
- New External ID: The new external ID generated for the concept.
- Original Response: A Json backup of the concept before the update.
- Update Payload: A Json that details what was sent back to the OCL API (ID, External ID, Names)
- The script uses pagination to retrieve all concepts from the specified OCL source.
- The script handles unexpected response formats and prints an error message if encountered.
- The script updates the external IDs in place, so make sure to back up your data before running the script.