This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
aact.sh
executable file
·83 lines (72 loc) · 1.78 KB
/
aact.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
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
#
# Download a static copy of the AACT database and reconstruct it.
# Set the search path and run an evaluation query for the current year.
# The dump file is deleted at the end.
#
# DATE is YYYYMMDD.
#
# ./script/aact.sh <DATE>
set -eu
DATE=$1
DIR="data/aact"
DB=aact
ZIP_FILE="${DATE}_clinical_trials.zip"
mkdir -p "$DIR"
if ! wget -P "$DIR" "https://aact.ctti-clinicaltrials.org/static/static_db_copies/daily/$ZIP_FILE"
then
rm -f "$DIR/$ZIP_FILE"
echo "Download failed."
exit 1
fi
unzip -o -d "$DIR" "$DIR/$ZIP_FILE"
dropdb --if-exists "$DB"
createdb "$DB"
pg_restore -U "$USER" -e -v -O -x --dbname="$DB" "${DIR}/postgres_data.dmp"
psql -d "$DB" -c "ALTER ROLE $USER SET search_path TO ctgov,public;"
# Check the download:
YEAR=$(date +'%Y')
echo "Year: $YEAR"
QUERY="
SELECT
t1.overall_status status,
COUNT(1) study_count,
SUM(t1.enrollment) enrollment
FROM (
SELECT
nct_id,
date_part('year', start_date) AS start_year,
date_part('year', completion_date) AS completion_year,
enrollment,
overall_status,
study_type
FROM studies
WHERE
enrollment < 50000
) t1
JOIN calculated_values t2
ON t1.nct_id = t2.nct_id
WHERE
t2.has_us_facility
AND t1.start_year <= $YEAR
AND (
t1.completion_year >= $YEAR
OR t1.completion_year IS NULL
)
AND t1.overall_status = ANY (
ARRAY[
'Recruiting',
'Active, not recruiting',
'Not yet recruiting',
'Enrolling by invitation'
]
)
AND t1.study_type = 'Interventional'
GROUP BY
t1.overall_status
ORDER BY
3 DESC;
"
psql -U "$USER" -d "$DB" -c "$QUERY"
rm "$DIR/postgres_data.dmp"