|
|
|
|
@ -32,3 +32,91 @@ CREATE TABLE IF NOT EXISTS http.responses (
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Type: history_download_status
|
|
|
|
|
-- DROP TYPE IF EXISTS http.history_download_status;
|
|
|
|
|
|
|
|
|
|
CREATE TYPE http.history_download_status AS ENUM
|
|
|
|
|
('Ignored', 'Of Interest', 'Reserved', 'Downloaded', 'Incomplete');
|
|
|
|
|
|
|
|
|
|
ALTER TYPE http.history_download_status
|
|
|
|
|
OWNER TO root;
|
|
|
|
|
|
|
|
|
|
COMMENT ON TYPE http.history_download_status
|
|
|
|
|
IS 'Records the status of the downloaded history from clinicaltrials.gov';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Table: http.download_status
|
|
|
|
|
|
|
|
|
|
Creates and then initializes the table to record history download status.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
--DROP TABLE IF EXISTS http.download_status;
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS http.download_status
|
|
|
|
|
(
|
|
|
|
|
id SERIAL NOT NULL,
|
|
|
|
|
nct_id character varying(15) COLLATE pg_catalog."default" NOT NULL,
|
|
|
|
|
status http.history_download_status NOT NULL DEFAULT 'Ignored'::http.history_download_status,
|
|
|
|
|
update_timestamp timestamp with time zone DEFAULT now(),
|
|
|
|
|
CONSTRAINT download_status_pkey PRIMARY KEY (id),
|
|
|
|
|
CONSTRAINT "nct_id link" FOREIGN KEY (nct_id)
|
|
|
|
|
REFERENCES ctgov.studies (nct_id) MATCH SIMPLE
|
|
|
|
|
ON UPDATE NO ACTION
|
|
|
|
|
ON DELETE NO ACTION
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
TABLESPACE pg_default;
|
|
|
|
|
|
|
|
|
|
ALTER TABLE IF EXISTS http.download_status
|
|
|
|
|
OWNER to root;
|
|
|
|
|
|
|
|
|
|
COMMENT ON TABLE http.download_status
|
|
|
|
|
IS 'Records the download status for each trial''s history';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSERT INTO http.download_status (nct_id, status)
|
|
|
|
|
SELECT DISTINCT nct_id, 'Ignored'::http.history_download_status
|
|
|
|
|
FROM ctgov.studies;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Views to allow downloader programs to identify what to download.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
-- View: http.most_recent_download_status
|
|
|
|
|
|
|
|
|
|
-- DROP VIEW http.most_recent_download_status;
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE VIEW http.most_recent_download_status
|
|
|
|
|
AS
|
|
|
|
|
SELECT download_status.nct_id,
|
|
|
|
|
download_status.status,
|
|
|
|
|
max(download_status.update_timestamp) AS max
|
|
|
|
|
FROM http.download_status
|
|
|
|
|
GROUP BY download_status.nct_id, download_status.status;
|
|
|
|
|
|
|
|
|
|
ALTER TABLE http.most_recent_download_status
|
|
|
|
|
OWNER TO http_requestor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- View: http.trials_to_download
|
|
|
|
|
|
|
|
|
|
-- DROP VIEW http.trials_to_download;
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE VIEW http.trials_to_download
|
|
|
|
|
AS
|
|
|
|
|
SELECT most_recent_download_status.nct_id,
|
|
|
|
|
most_recent_download_status.status,
|
|
|
|
|
most_recent_download_status.max
|
|
|
|
|
FROM http.most_recent_download_status
|
|
|
|
|
WHERE most_recent_download_status.status = 'Of Interest'::http.history_download_status;
|
|
|
|
|
|
|
|
|
|
ALTER TABLE http.trials_to_download
|
|
|
|
|
OWNER TO http_requestor;
|
|
|
|
|
COMMENT ON VIEW http.trials_to_download
|
|
|
|
|
IS 'List of trials for which the history needs downloaded';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|