272 lines
6.7 KiB
Bash
Executable File
272 lines
6.7 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
# Saudi Healthcare Data Population Script
|
||
# This script runs all data generators in the correct dependency order
|
||
|
||
set -e # Exit on any error
|
||
|
||
# Colors for output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# Configuration
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
PYTHON_CMD="python3"
|
||
ORCHESTRATOR="${SCRIPT_DIR}/populate_all_data.py"
|
||
|
||
# Function to print colored output
|
||
print_info() {
|
||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||
}
|
||
|
||
print_success() {
|
||
echo -e "${GREEN}✅ $1${NC}"
|
||
}
|
||
|
||
print_warning() {
|
||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||
}
|
||
|
||
print_error() {
|
||
echo -e "${RED}❌ $1${NC}"
|
||
}
|
||
|
||
print_header() {
|
||
echo -e "${BLUE}🏥 $1${NC}"
|
||
echo -e "${BLUE}$(printf '%.0s=' {1..50})${NC}"
|
||
}
|
||
|
||
# Function to check if Python is available
|
||
check_python() {
|
||
if ! command -v $PYTHON_CMD &> /dev/null; then
|
||
print_error "Python3 is not installed or not in PATH"
|
||
exit 1
|
||
fi
|
||
|
||
# Check if Django is available
|
||
if ! $PYTHON_CMD -c "import django" &> /dev/null; then
|
||
print_error "Django is not installed. Please install requirements."
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
# Function to check if we're in the right directory
|
||
check_directory() {
|
||
if [[ ! -f "manage.py" ]]; then
|
||
print_error "manage.py not found. Please run this script from the Django project root."
|
||
exit 1
|
||
fi
|
||
|
||
if [[ ! -f "$ORCHESTRATOR" ]]; then
|
||
print_error "populate_all_data.py not found. Please ensure the script exists."
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
# Function to show usage
|
||
show_usage() {
|
||
cat << EOF
|
||
Saudi Healthcare Data Population Script
|
||
|
||
USAGE:
|
||
$0 [OPTIONS] [GENERATORS...]
|
||
|
||
OPTIONS:
|
||
-h, --help Show this help message
|
||
-l, --list List available generators
|
||
-p, --plan Show execution plan
|
||
-v, --validate Validate dependencies only
|
||
--tenant-id ID Generate data for specific tenant ID
|
||
--tenant-slug SLUG Generate data for specific tenant slug
|
||
--skip-validation Skip dependency validation
|
||
--dry-run Show what would be done without executing
|
||
|
||
GENERATORS:
|
||
Specify which generators to run. If none specified, runs all in dependency order:
|
||
core accounts hr patients emr lab radiology pharmacy appointments billing inpatients inventory facility_management
|
||
|
||
EXAMPLES:
|
||
$0 # Run all generators
|
||
$0 core accounts patients # Run specific generators
|
||
$0 --tenant-id 1 # Generate data for tenant ID 1
|
||
$0 --list # List available generators
|
||
$0 --plan # Show execution plan
|
||
$0 --validate # Validate dependencies only
|
||
|
||
DEPENDENCY ORDER:
|
||
1. core (tenants)
|
||
2. accounts (users)
|
||
3. hr (employees/departments)
|
||
4. patients (patients)
|
||
5. emr, lab, radiology, pharmacy (clinical data - parallel)
|
||
6. appointments (needs patients + providers)
|
||
7. billing (needs patients + encounters)
|
||
8. inpatients (needs patients + staff)
|
||
9. inventory (independent)
|
||
10. facility_management (management command)
|
||
|
||
EOF
|
||
}
|
||
|
||
# Function to run the orchestrator
|
||
run_orchestrator() {
|
||
local args=("$@")
|
||
|
||
print_info "Running data generation orchestrator..."
|
||
|
||
if [[ "${args[*]}" =~ "--dry-run" ]]; then
|
||
print_warning "DRY RUN MODE - No data will be created"
|
||
args=("${args[@]/--dry-run/}")
|
||
fi
|
||
|
||
# Run the Python orchestrator
|
||
if $PYTHON_CMD "$ORCHESTRATOR" "${args[@]}"; then
|
||
print_success "Data generation completed successfully!"
|
||
else
|
||
print_error "Data generation failed!"
|
||
exit 1
|
||
fi
|
||
}
|
||
|
||
# Function to run individual generators (legacy support)
|
||
run_individual() {
|
||
local generator="$1"
|
||
|
||
print_info "Running individual generator: $generator"
|
||
|
||
case $generator in
|
||
"core")
|
||
$PYTHON_CMD core_data.py
|
||
;;
|
||
"accounts")
|
||
$PYTHON_CMD accounts_data.py
|
||
;;
|
||
"hr")
|
||
$PYTHON_CMD hr_data.py
|
||
;;
|
||
"patients")
|
||
$PYTHON_CMD patients_data.py
|
||
;;
|
||
"emr")
|
||
$PYTHON_CMD emr_data.py
|
||
;;
|
||
"lab")
|
||
$PYTHON_CMD lab_data.py
|
||
;;
|
||
"radiology")
|
||
$PYTHON_CMD radiology_data.py
|
||
;;
|
||
"pharmacy")
|
||
$PYTHON_CMD pharmacy_data.py
|
||
;;
|
||
"appointments")
|
||
$PYTHON_CMD appointments_data.py
|
||
;;
|
||
"billing")
|
||
$PYTHON_CMD billing_data.py
|
||
;;
|
||
"inpatients")
|
||
$PYTHON_CMD inpatients_data.py
|
||
;;
|
||
"inventory")
|
||
$PYTHON_CMD inventory_data.py
|
||
;;
|
||
"facility_management")
|
||
$PYTHON_CMD manage.py seed_facility
|
||
;;
|
||
*)
|
||
print_error "Unknown generator: $generator"
|
||
exit 1
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# Parse command line arguments
|
||
ARGS=()
|
||
INDIVIDUAL_MODE=false
|
||
|
||
while [[ $# -gt 0 ]]; do
|
||
case $1 in
|
||
-h|--help)
|
||
show_usage
|
||
exit 0
|
||
;;
|
||
-l|--list)
|
||
ARGS+=("--list-generators")
|
||
shift
|
||
;;
|
||
-p|--plan)
|
||
ARGS+=("--show-plan")
|
||
shift
|
||
;;
|
||
-v|--validate)
|
||
ARGS+=("--validate-only")
|
||
shift
|
||
;;
|
||
--dry-run)
|
||
ARGS+=("--dry-run")
|
||
shift
|
||
;;
|
||
--tenant-id)
|
||
ARGS+=("--tenant-id" "$2")
|
||
shift 2
|
||
;;
|
||
--tenant-slug)
|
||
ARGS+=("--tenant-slug" "$2")
|
||
shift 2
|
||
;;
|
||
--skip-validation)
|
||
ARGS+=("--skip-validation")
|
||
shift
|
||
;;
|
||
--individual)
|
||
INDIVIDUAL_MODE=true
|
||
shift
|
||
;;
|
||
-*)
|
||
print_error "Unknown option: $1"
|
||
show_usage
|
||
exit 1
|
||
;;
|
||
*)
|
||
ARGS+=("$1")
|
||
shift
|
||
;;
|
||
esac
|
||
done
|
||
|
||
# Main execution
|
||
main() {
|
||
print_header "Saudi Healthcare Data Population Script"
|
||
|
||
# Pre-flight checks
|
||
check_python
|
||
check_directory
|
||
|
||
print_info "Python version: $($PYTHON_CMD --version)"
|
||
print_info "Django project root: $SCRIPT_DIR"
|
||
|
||
# Handle individual mode (legacy support)
|
||
if [[ "$INDIVIDUAL_MODE" == true ]]; then
|
||
print_warning "Individual mode is deprecated. Use the orchestrator instead."
|
||
if [[ ${#ARGS[@]} -eq 0 ]]; then
|
||
print_error "No generator specified for individual mode"
|
||
exit 1
|
||
fi
|
||
|
||
for generator in "${ARGS[@]}"; do
|
||
run_individual "$generator"
|
||
done
|
||
exit 0
|
||
fi
|
||
|
||
# Run orchestrator
|
||
run_orchestrator "${ARGS[@]}"
|
||
}
|
||
|
||
# Run main function
|
||
main "$@"
|