#!/bin/bash set -euo pipefail case "${DISABLE_IMPORT:-false}" in false) ;; true|load) echo "DISABLE_IMPORT is ${DISABLE_IMPORT} - skipping ETL pipeline (neo4j handles the rest)" exit 0 ;; *) echo "Invalid DISABLE_IMPORT='${DISABLE_IMPORT}' - expected false, true or load" >&2 exit 1 ;; esac # Wait for a file to appear, with a timeout so the container can't hang forever. # Usage: wait_for_file [timeout_seconds] wait_for_file() { local file="$1" local timeout="${2:-300}" local waited=0 while [ ! -f "$file" ]; do if [ "$waited" -ge "$timeout" ]; then echo "Timed out after ${timeout}s waiting for $(basename "$file")" >&2 exit 1 fi echo "Waiting for $(basename "$file")..." sleep 5 waited=$((waited + 5)) done } # Start from an empty import dir: BioCypher appends new -partNNN files next to # old ones and the admin import globs all of them, so leftovers would be # imported again. Stale marker files would also break the handshake below. echo "Clearing /neo4j_import..." find /neo4j_import -mindepth 1 -delete # Make the import dir accessible to both the Python app and Neo4j chmod -R 777 /neo4j_import #echo "Waiting for Neo4j to be ready..." #python wait-for-neo4j.py echo "Running Python data processing script..." #python import_fhir_to_nx_diGraph.py python multiple_adapters.py echo "Running Neo4j import..." # Give downstream services a moment before touching the database sleep 5 # Wait for the shell script to finish writing its data wait_for_file /neo4j_import/shell-scipt-complete # Signal that data is prepared and ready to import touch /neo4j_import/ready-to-import chmod 777 /neo4j_import/ready-to-import # Wait for the import to complete echo "Waiting for Neo4j import to complete..." wait_for_file /neo4j_import/import-complete echo "Database setup complete!"