-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetch-capability-statements.sh
More file actions
36 lines (28 loc) · 1.26 KB
/
fetch-capability-statements.sh
File metadata and controls
36 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
set -u
SERVICES=(careplan device document-query document-transformation library measurement organization plan questionnaire reporting task terminology)
SOURCE_ENVIRONMENT="${SOURCE_ENVIRONMENT:-devtest.systematic-ehealth.com}"
TIME_OUT=5
IG_PATH=$(pwd)
OUTPUT_DIR="${IG_PATH}/input/resources"
mkdir -p $OUTPUT_DIR
TMP_FILE=$(mktemp)
trap 'rm -f "$TMP_FILE"' EXIT
echo "Downloading capability statements from ${SOURCE_ENVIRONMENT} to ${IG_PATH}"
for service in "${SERVICES[@]}"; do
URL="https://${service}.${SOURCE_ENVIRONMENT}/fhir/metadata"
OUTPUT_FILE="${OUTPUT_DIR}/CapabilityStatement-${service}.json"
http_code=$(curl -kf -H 'Content-Type: application/fhir+json' --connect-timeout "$TIME_OUT" -w '%{http_code}' -o "$TMP_FILE" "${URL}")
curl_exit=$?
if [ "$curl_exit" -ne 0 ] || [ "$http_code" -ne 200 ]; then
echo "ERROR: Fetching from ${URL} terminated with curl exit-code: $curl_exit; http-code: $http_code"
exit 1
fi
if ! jq empty "$TMP_FILE" 2>/dev/null; then
echo "ERROR: Invalid JSON fetched from ${URL}: \"$(head -1 $TMP_FILE)...\""
exit 2
fi
# remove text element to be generated by IG publisher - using sed because jq is reformatting the JSON
sed -i '/"text": {/,/^[[:space:]]*},/d' "$TMP_FILE"
mv "$TMP_FILE" "$OUTPUT_FILE"
done