This repository contains setup scripts to automatically download the latest validator JAR file from the HAPI FHIR Core releases.
setup.sh- Bash script for Unix/Linux/macOS systems to download validator JARsetup.bat- Batch script for Windows systems to download validator JAR
validate.sh- Bash script to validate all FHIR files in the resources directoryvalidate.bat- Windows batch script for validation with colorized output
- Automatically fetches the latest release from GitHub API
- Downloads the validator JAR file to a
./validatordirectory - Checks for existing files and prompts for overwrite
- Creates a symbolic link/copy with a generic name (
validator-latest.jar) - Provides colored output and clear status messages
- Error handling and dependency checking
# Make the script executable (if not already)
chmod +x setup.sh
# Run the script
./setup.sh# Run the batch script
# Allow unknown extensions via validate.bat
validate.bat -extension any
setup.batOr double-click the setup.bat file in Windows Explorer.
First, place your FHIR JSON or XML files in the ./resources directory.
# Make the script executable (if not already)
chmod +x validate.sh
# Run validation with default settings (FHIR R4)
./validate.sh
# Run validation with custom FHIR version
./validate.sh -v 5.0.0
# Run validation in quiet mode
./validate.sh --quiet
# Allow unknown extensions (quick demo mode)
./validate.sh -extension any
# Allow unknown extensions for one file in watch mode
./validate.sh -watch-mode single -extension any ./resources/test-patient.json
# Show help
./validate.sh --help# Validate all files in .\resources
validate.bat
# Allow unknown extensions via validate.bat
validate.bat -extension any
# Watch one specific file
validate.bat -watch-mode single .\resources\test-patient.json
# Direct validator CLI example (allow unknown extensions)
java -jar .\validator\validator-latest.jar -extension any .\resources\test-patient.jsoncurl- for downloading filesjq(optional) - for better JSON parsing. If not available, the script will use a fallback method
- PowerShell - for API calls and JSON parsing (usually pre-installed on Windows 7+ and Windows Server 2008 R2+)
- Java Runtime Environment (JRE) 8 or higher
- Downloaded validator JAR (run setup script first)
- FHIR files (JSON or XML) in the
./resourcesdirectory
- PowerShell (used for streaming line-by-line colorized output)
Both setup scripts will:
- Create a
./validatordirectory if it doesn't exist - Download the latest validator JAR file with its original name (e.g.,
validator_cli-6.0.22.jar) - Create a symbolic link (Unix) or copy (Windows) named
validator-latest.jarfor easier reference
Both validation scripts will:
- Check for Java installation and validator JAR
- Find all JSON and XML files in the
./resourcesdirectory - Run the FHIR validator on all found files in a single command
- Display validation results with severity-based color coding
Both validate.sh and validate.bat highlight validator output by severity to make console output easier to scan:
- Red: errors, fatal messages, exceptions
- Yellow: warnings
- Green: success summaries (for example
0 errors) - Cyan: validator metadata/status lines (for example
Loading,Params,Paths)
Notes:
validate.shdisables colors automatically when output is not a terminal, or whenNO_COLORis set.validate.batuses PowerShell host coloring, so colors are visible when run in standard Windows terminals.
FHIR Validator JAR Download Script
===================================
[INFO] Checking dependencies...
[INFO] Creating download directory: ./validator
[INFO] Fetching latest release information...
[INFO] Found latest release: 6.0.22-SNAPSHOT
[INFO] Validator JAR file: validator_cli-6.0.22-SNAPSHOT.jar
[INFO] Downloading validator_cli-6.0.22-SNAPSHOT.jar...
[INFO] Successfully downloaded: ./validator/validator_cli-6.0.22-SNAPSHOT.jar
[INFO] File size: 15M
[INFO] Creating symbolic link: ./validator/validator-latest.jar -> validator_cli-6.0.22-SNAPSHOT.jar
[INFO] Symbolic link created successfully
[INFO] Setup completed successfully!
[INFO] Validator JAR location: ./validator/validator_cli-6.0.22-SNAPSHOT.jar
[INFO] You can also use the symbolic link: ./validator/validator-latest.jar
FHIR Validator Script
=====================
[INFO] Checking prerequisites...
[INFO] Found Java version: 17.0.2
[INFO] Found 2 FHIR files to validate
[INFO] Starting FHIR validation...
[VALIDATION] File: test-patient.json
[VALIDATION] File: test-observation.xml
[INFO] Running validator command...
[INFO] Command: java -jar "./validator/validator-latest.jar" -version 4.0.1 -output-style compact "./resources/test-patient.json" "./resources/test-observation.xml"
Success: 0 errors, 0 warnings, 0 informational messages
[INFO] Validation completed successfully!
[INFO] Validator JAR: ./validator/validator-latest.jar
[INFO] You can also use the symbolic link: ./validator/validator-latest.jar
Both scripts include comprehensive error handling:
- Network connectivity issues
- Missing dependencies
- API rate limiting
- File permission problems
- Corrupted downloads
If an error occurs, the scripts will display detailed error messages in the console.
- The scripts will prompt before overwriting existing files
- Downloaded validator JARs are stored in the
./validatordirectory relative to the script location - The scripts use the GitHub API to fetch release information, which has rate limiting for unauthenticated requests (60 requests per hour per IP address)