Skip to content

florianschoffke/fhir-for-implementers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FHIR Validator JAR Setup Scripts

This repository contains setup scripts to automatically download the latest validator JAR file from the HAPI FHIR Core releases.

Files

Setup Scripts

  • setup.sh - Bash script for Unix/Linux/macOS systems to download validator JAR
  • setup.bat - Batch script for Windows systems to download validator JAR

Validation Scripts

  • validate.sh - Bash script to validate all FHIR files in the resources directory
  • validate.bat - Windows batch script for validation with colorized output

Features

  • Automatically fetches the latest release from GitHub API
  • Downloads the validator JAR file to a ./validator directory
  • 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

Usage

Setup (Download Validator)

On Unix/Linux/macOS

# Make the script executable (if not already)
chmod +x setup.sh

# Run the script
./setup.sh

On Windows

# Run the batch script

# Allow unknown extensions via validate.bat
validate.bat -extension any

setup.bat

Or double-click the setup.bat file in Windows Explorer.

Validation (Validate FHIR Files)

First, place your FHIR JSON or XML files in the ./resources directory.

On Unix/Linux/macOS

# 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

On Windows

# 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.json

Requirements

Setup Scripts

Bash Script (setup.sh)

  • curl - for downloading files
  • jq (optional) - for better JSON parsing. If not available, the script will use a fallback method

Batch Script (setup.bat)

  • PowerShell - for API calls and JSON parsing (usually pre-installed on Windows 7+ and Windows Server 2008 R2+)

Validation Scripts

All Platforms

  • Java Runtime Environment (JRE) 8 or higher
  • Downloaded validator JAR (run setup script first)
  • FHIR files (JSON or XML) in the ./resources directory

Windows Validation Script (validate.bat)

  • PowerShell (used for streaming line-by-line colorized output)

Output

Setup Scripts

Both setup scripts will:

  1. Create a ./validator directory if it doesn't exist
  2. Download the latest validator JAR file with its original name (e.g., validator_cli-6.0.22.jar)
  3. Create a symbolic link (Unix) or copy (Windows) named validator-latest.jar for easier reference

Validation Scripts

Both validation scripts will:

  1. Check for Java installation and validator JAR
  2. Find all JSON and XML files in the ./resources directory
  3. Run the FHIR validator on all found files in a single command
  4. Display validation results with severity-based color coding

Validation Output Colors

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.sh disables colors automatically when output is not a terminal, or when NO_COLOR is set.
  • validate.bat uses PowerShell host coloring, so colors are visible when run in standard Windows terminals.

Example Output

Setup Script Output

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

Validation Script Output

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

Error Handling

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.

Notes

  • The scripts will prompt before overwriting existing files
  • Downloaded validator JARs are stored in the ./validator directory 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)

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors