To load the CSV files into PostgreSQL, step 1:
Store this SQL as a file named 001.001.001.create_schema_and_basetables.sql:
DROP SCHEMA <schema> CASCADE;
CREATE SCHEMA <schema>;
SET SEARCH_PATH TO <schema>;
CREATE TABLE sta_icsr
(
elocnr character varying,
reporttype character varying,
evgatewayrecdate character varying,
primarysourcequalification character varying,
primarysourcecountryforregulatorypurposes character varying,
literaturereference character varying,
patientagegroup character varying,
patientagegroupperreporter character varying,
parentchildreport character varying,
patientsex character varying,
reactionlist character varying,
suspectdruglist character varying,
concomitant character varying
);
CREATE TABLE dwh_elocnrs
(
id serial,
elocnr character varying,
evdate date
);
CREATE INDEX ix_eloc_id on dwh_elocnrs using btree(id);
CREATE INDEX ix_eloc_elocnr on dwh_elocnrs using btree(elocnr);
CREATE TABLE dwh_primarysourcequalifications
(
id serial,
primarysourcequalification character varying
);
CREATE INDEX ix_psq_id on dwh_primarysourcequalifications using btree(id);
CREATE INDEX ix_psq_primarysourcequalification on dwh_primarysourcequalifications using btree(primarysourcequalification);
CREATE TABLE dwh_primarysourcecountryforregulatorypurposes
(
id serial,
primarysourcecountryforregulatorypurposes character varying
);
CREATE TABLE dwh_literaturereferences
(
id serial,
literaturereference character varying
);
CREATE TABLE dwh_patientagegroup
(
id serial,
patientagegroup character varying
);
CREATE TABLE dwh_patientagegroupperreporter
(
id serial,
patientagegroupperreporter character varying
);
CREATE TABLE dwh_parentchildreport
(
id serial,
parentchildreport character varying
);
CREATE TABLE dwh_patientsex
(
id serial,
patientsex character varying
);
CREATE TABLE dwh_reactionlists
(
id serial,
reactionlist character varying
);
CREATE INDEX ix_reactionlist_id on dwh_reactionlists using btree(id);
CREATE INDEX ix_reactionlist_reactionlist on dwh_reactionlists using btree(reactionlist);
CREATE TABLE dwh_reaction_outcomes
(
id serial,
outcome character varying
);
INSERT INTO dwh_reaction_outcomes(id, outcome) values (0, 'Unidentified Outcome');
CREATE INDEX ix_reaction_outcomes_id on dwh_reaction_outcomes using btree(id);
CREATE INDEX ix_reaction_outcomes_outcome on dwh_reaction_outcomes using btree(outcome);
CREATE TABLE dwh_reaction_seriousness
(
id serial,
seriousness character varying
);
INSERT INTO dwh_reaction_seriousness(id, seriousness) values (0, 'Unidentified Seriousness');
CREATE INDEX ix_reaction_seriousness_id on dwh_reaction_outcomes using btree(id);
CREATE INDEX ix_reaction_seriousness_seriousness on dwh_reaction_seriousness using btree(seriousness);
CREATE VIEW <schema>.v_reactiondetails as
(
SELECT elocnr,
TRIM(BOTH FROM regexp_replace(split_part(regexp_split_to_table(reactionlist, '<BR><BR>'), ' (', 1), '"', '')) AS llt,
split_part(split_part(regexp_split_to_table(reactionlist, '<BR><BR>'), ' (', 2), ' - ', 1) AS duration,
split_part(split_part(regexp_split_to_table(reactionlist, '<BR><BR>'), ' (', 2), ' - ', 2) AS outcome,
regexp_replace(split_part(split_part(regexp_split_to_table(reactionlist, '<BR><BR>'), ' (', 2), ' - ', 3), '[\)\"\,] $', '') AS seriousness
FROM <schema>.sta_icsr
);
CREATE TABLE dwh_suspectdruglists
(
id serial,
suspectdruglist character varying
);
CREATE VIEW <schema>.v_drugdetails AS
SELECT
elocnr,
split_part(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), '] (', 2), ' - ', 1) AS drugrole,
regexp_split_to_table(split_part(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), '] (', 2), ' - ', 2), ', ') AS drugindication,
split_part(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), '] (', 2), ' - ', 3) AS drugaction,
split_part(regexp_replace(regexp_replace(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), ' - [', 2), ' - More in ICSR', ''), '[\]\)\,\""] $', ''), ' - ', 1) AS drugduration,
split_part(regexp_replace(regexp_replace(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), ' - [', 2), ' - More in ICSR', ''), '[\]\)\,\""] $', ''), ' - ', 2) AS drugdose,
split_part(regexp_replace(regexp_replace(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), ' - [', 2), ' - More in ICSR', ''), '[\]\)\,\""] $', ''), ' - ', 3) AS drugroute,
TRIM(BOTH FROM regexp_replace(split_part(split_part(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), '] (', 1), '\[', 1), '[', 1), '\"', '')) AS drug1,
split_part(split_part(split_part(regexp_split_to_table(suspectdruglist, '<BR><BR>'), '] (', 1), '\[', 1), '[', 2) AS drug2
FROM
sta_icsr
;