-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory-upload.sh
executable file
·74 lines (64 loc) · 1.64 KB
/
directory-upload.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
usage="
usage: $(basename "$0") command [-h] [-s] [-d] arguments...
Uploads supported resources to the bulk-export-server
Options:
-h
Displays help menu.
-s [server baseUrl]
Specifies the base URL of the FHIR server to access.
-d [path]
Provides directory or file path to parse for upload.
"
while getopts ':hs:d:' option;
do
case "$option" in
h)
echo -e "$usage"
exit 0
;;
s)
server=$OPTARG
;;
d)
directory_path=$OPTARG
;;
\?) printf "illegal option: -%s\n" "$OPTARG" 1>&2
echo "$usage" 1>&2
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument" 1>&2
;;
esac
done
if [[ $directory_path == "" ]] ; then
echo No directory path provided. Provide directory path via the '-d' flag.
exit 1
fi
if [[ $server == "" ]] ; then
echo No server URL provided. Provide server URL via the '-s' flag.
exit 1
fi
echo Using Server URL: $server and directory path: $directory_path
upload_bundle() {
echo "Uploading resources for bundle $1"
curl_command="curl -X POST -H 'Content-Type: application/json+fhir' -d @\"$1\" $server -o /dev/null"
# execute the curl command
eval "$curl_command"
echo "Finished bundle upload."
echo ""
}
# loop over FHIR bundles in specified directory
for file_path in "$directory_path" ; do
if [[ -d $file_path ]] ; then
# recurse on directory
for f in $(find $file_path -name "*.json") ; do
upload_bundle $f
done
elif [[ -f $file_path ]] ; then
if [[ ${file_path: -5} == ".json" ]] ; then
upload_bundle $file_path
fi
fi
done