Skip to content

Instantly share code, notes, and snippets.

@KeironO
Created June 15, 2024 18:42
Show Gist options
  • Save KeironO/5942cc05aa70a0355b710b81d09b7cb7 to your computer and use it in GitHub Desktop.
Save KeironO/5942cc05aa70a0355b710b81d09b7cb7 to your computer and use it in GitHub Desktop.
Upload UK Core to HAPI FHIR hack script - run twice.
#!/bin/bash
# Define variables
ZIP_FILE="hl7fhirukcorer4.zip"
FHIR_SERVER_URL="http://localhost:8080/fhir"
# Create a temporary directory to extract the zip file
TEMP_DIR=$(mktemp -d)
# Unzip the file
unzip "$ZIP_FILE" -d "$TEMP_DIR"
# Find all JSON files and upload them to the FHIR server
find "$TEMP_DIR" -type f -name "*.json" | while read -r json_file; do
echo "Processing $json_file"
# Extract the resource type and id from the JSON file
RESOURCE_TYPE=$(jq -r .resourceType "$json_file")
RESOURCE_ID=$(jq -r .id "$json_file")
if [ -z "$RESOURCE_TYPE" ] || [ "$RESOURCE_TYPE" == "null" ]; then
echo "Resource type not found in $json_file, skipping..."
continue
fi
if [ -z "$RESOURCE_ID" ] || [ "$RESOURCE_ID" == "null" ]; then
echo "Resource ID not found in $json_file, skipping..."
continue
fi
# Construct the URL using the resource type and id
URL="${FHIR_SERVER_URL}/${RESOURCE_TYPE}/${RESOURCE_ID}"
echo "Uploading $json_file to $URL"
curl -X PUT -H "Content-Type: application/json" --data @"$json_file" "$URL"
done
# Clean up the temporary directory
rm -rf "$TEMP_DIR"
echo "All JSON files have been processed and uploaded to the FHIR server."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment