#!/usr/bin/env bash
# Verzi Healthcare Data API — curl examples.
#
# Six progressive commands that cover 90% of first integrations.
# Copy-paste and run after setting VERZI_API_KEY.
#
# Get a free API key: https://api.healthcaredata.io/signup
# Full API reference:  https://api.healthcaredata.io/docs

set -euo pipefail

: "${VERZI_API_KEY:?Set VERZI_API_KEY in your environment}"

BASE_URL="https://api.healthcaredata.io"
AUTH=(-H "X-API-Key: $VERZI_API_KEY")

# 1. Search California hospitals (top 5 by rating)
echo "=== 5 California hospitals ==="
curl -s "${AUTH[@]}" \
  "${BASE_URL}/hospitals?state=CA&min_rating=5&limit=5" | jq '.results[] | {ccn, name, overall_rating}'

# 2. Get one hospital in detail
echo -e "\n=== Intermountain Utah Valley Hospital (CCN 460001) ==="
curl -s "${AUTH[@]}" "${BASE_URL}/hospitals/460001" | jq '{ccn, name, overall_rating, beds, system_name}'

# 3. Full cross-source dossier for one NPI
echo -e "\n=== NPI dossier ==="
curl -s "${AUTH[@]}" "${BASE_URL}/provider/1245319599" | jq 'keys'

# 4. OIG federal exclusion screening
echo -e "\n=== Exclusion check ==="
curl -s "${AUTH[@]}" "${BASE_URL}/exclusions/check/1234567890" | jq

# 5. HCAHPS national percentile for one hospital's Nurse Communication score
echo -e "\n=== HCAHPS benchmark ==="
curl -s "${AUTH[@]}" \
  "${BASE_URL}/benchmarks/hcahps/percentile?ccn=460001&measure=H_NURSE_COMM_LINEAR" | jq

# 6. Check your rate-limit headroom
echo -e "\n=== Your remaining daily requests ==="
curl -s -D - -o /dev/null "${AUTH[@]}" "${BASE_URL}/hospitals?limit=1" \
  | grep -i "X-RateLimit-Remaining"
