Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Category data to Conditions table #88

2 changes: 2 additions & 0 deletions query-connector/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:
interval: 2s
timeout: 5s
retries: 20
volumes:
- ./data/Conditions_and_Categories_20241024.csv:/tmp/Conditions_and_Categories_20241024.csv

# Next.js app with Flyway
tefca-viewer:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO conditions VALUES('1','DIBBs Local Code System','Newborn Screening','20240909');
INSERT INTO conditions VALUES('2','DIBBs Local Code System','Cancer (Leukemia)','20240909');
INSERT INTO conditions VALUES('3','DIBBs Local Code System','Social Determinants of Health','20240909'); -- has no valuesets
-- INSERT INTO conditions VALUES('3','DIBBs Local Code System','Social Determinants of Health','20240909'); -- has no valuesets

-- Newborn Screening valueset(s)
INSERT INTO valuesets VALUES('1_20240909','1','20240909','Newborn Screening','DIBBs','lotc');
Expand Down
34 changes: 34 additions & 0 deletions query-connector/flyway/sql/V01_07__add_conditions_category.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- 1. Add the new 'category' column to the condition table
ALTER TABLE conditions
ADD COLUMN category TEXT;

-- 2. Create a staging table to hold the CSV data
CREATE TABLE IF NOT EXISTS category_data (
condition_name TEXT,
condition_code TEXT,
category TEXT
);

-- 3. Load the CSV data into the staging table
COPY category_data (condition_name, condition_code, category)
FROM '/tmp/Conditions_and_Categories_20241024.csv'
DELIMITER ','
CSV HEADER;

-- 4. Update the condition table with the category from the staging table
UPDATE conditions
SET category = category_data.category
FROM category_data
WHERE conditions.id = category_data.condition_code;

-- 5. Add hardcoded categories from DIBBs-specific additions
UPDATE conditions
SET category = 'Birth Defects and Infant Disorders'
WHERE conditions.name = 'Newborn Screening';

UPDATE conditions
SET category = 'Cancer'
WHERE conditions.name = 'Cancer (Leukemia)';

-- 6. Drop the staging table after the join
DROP TABLE category_data;
Loading