diff --git a/Version4 To Version5 Conversion/Convert-OHDSI-Sql-To-Dialect-Local.R b/Version4 To Version5 Conversion/Convert-OHDSI-Sql-To-Dialect-Local.R deleted file mode 100644 index edf4613..0000000 --- a/Version4 To Version5 Conversion/Convert-OHDSI-Sql-To-Dialect-Local.R +++ /dev/null @@ -1,38 +0,0 @@ -# Load Libraries -install.packages(devtools) -library(devtools) -install_github("OHDSI/SqlRender") -library(SqlRender) -# Variables -ohdsiSqlFile <- "C:/Git/CommonDataModel/Version4 To Version5 Conversion/OMOP CDMv4 to CDMv5 - OHDSI-SQL.sql" -targetSqlServerFile <- "C:/Git/CommonDataModel/Version4 To Version5 Conversion/Sql Server/OMOP CDMv4 to CDMv5 - SQL Server.sql" -targetPostgreSqlFile <- "C:/Git/CommonDataModel/Version4 To Version5 Conversion/PostgreSQL/OMOP CDMv4 to CDMv5 - PostgreSQL.sql" -targetOracleFile <- "C:/Git/CommonDataModel/Version4 To Version5 Conversion/Oracle/OMOP CDMv4 to CDMv5 - Oracle.sql" -targetSqlServerPDWFile <- "C:/Git/CommonDataModel/Version4 To Version5 Conversion/Sql Server PDW/OMOP CDMv4 to CDMv5 - Sql Server PDW.dsql" -targetRedshiftFile <- "C:/Git/CommonDataModel/Version4 To Version5 Conversion/Redshift/OMOP CDMv4 to CDMv5 - Redshift.sql" - -##### LOCAL - SQL Server Testing -#renderSqlFile(ohdsiSqlFile, targetSqlServerFile, SOURCE_CDMV4 = "[CDMV4]", SOURCE_CDMV4_SCHEMA = "[CDMV4].[dbo]", TARGET_CDMV5 = "[CDMV5]", TARGET_CDMV5_SCHEMA = "[CDMV5].[dbo]") - -##### SQL Server Testing -#renderSqlFile(ohdsiSqlFile, targetSqlServerFile, SOURCE_CDMV4 = "[CDM_TRUVEN_CCAE_6k]", SOURCE_CDMV4_SCHEMA = "[CDM_TRUVEN_CCAE_6k].[dbo]", TARGET_CDMV5 = "[CDMV5_Conversion_Target]", TARGET_CDMV5_SCHEMA = "[CDMV5_Conversion_Target].[dbo]") - -##### PostgreSql Testing -#renderSqlFile(ohdsiSqlFile, targetSqlServerFile, SOURCE_CDMV4 = "sandbox", SOURCE_CDMV4_SCHEMA = "sandbox.cdmv4", TARGET_CDMV5 = "sandbox", TARGET_CDMV5_SCHEMA = "sandbox.cdmv5") -#translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetPostgreSqlFile, targetDialect = "postgresql") - -##### Oracle Testing -#renderSqlFile(ohdsiSqlFile, targetSqlServerFile, SOURCE_CDMV4 = "CDMV4", SOURCE_CDMV4_SCHEMA = "CDMV4", TARGET_CDMV5 = "CDMV5", TARGET_CDMV5_SCHEMA = "CDMV5") -#translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetOracleFile, targetDialect = "oracle") - -##### APS Testing -#renderSqlFile(ohdsiSqlFile, targetSqlServerFile, SOURCE_CDMV4 = "[CDM_THIN]", SOURCE_CDMV4_SCHEMA = "[CDM_THIN].[dbo]", TARGET_CDMV5 = "[CDM_THIN_V5_asena5]", TARGET_CDMV5_SCHEMA = "[CDM_THIN_V5_asena5].[dbo]") -#translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetSqlServerPDWFile, targetDialect = "pdw") - -##### Push to GitHub -renderSqlFile(ohdsiSqlFile, targetSqlServerFile) -translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetPostgreSqlFile, targetDialect = "postgresql") -translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetOracleFile, targetDialect = "oracle") -translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetSqlServerPDWFile, targetDialect = "pdw") -translateSqlFile(sourceFile = targetSqlServerFile, targetFile = targetRedshiftFile, targetDialect = "redshift") - diff --git a/Version4 To Version5 Conversion/OMOP CDMv4 to CDMv5 - OHDSI-SQL.sql b/Version4 To Version5 Conversion/OMOP CDMv4 to CDMv5 - OHDSI-SQL.sql index 7ebe47a..743316e 100644 --- a/Version4 To Version5 Conversion/OMOP CDMv4 to CDMv5 - OHDSI-SQL.sql +++ b/Version4 To Version5 Conversion/OMOP CDMv4 to CDMv5 - OHDSI-SQL.sql @@ -479,7 +479,7 @@ SELECT person_id ,CAST(NULL AS INT) AS cause_source_concept_id FROM @SOURCE_CDMV4_SCHEMA.DEATH LEFT JOIN #concept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID - AND LOWER(DOMAIN_ID) IN ('death type'); + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept'); INSERT INTO @TARGET_CDMV5_SCHEMA.ETL_WARNINGS (WARNING_MESSAGE) SELECT 'DEATH: ' + CAST(NUM_INVALID_RECORDS AS VARCHAR) + ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' @@ -492,7 +492,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('death type') + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -589,7 +589,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') LEFT JOIN #concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -632,7 +632,7 @@ SELECT procedure_occurrence_id FROM @SOURCE_CDMV4_SCHEMA.PROCEDURE_OCCURRENCE LEFT JOIN #concept_map cm1 ON procedure_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON procedure_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') WHERE procedure_concept_id <> 0 AND cm1.domain_id IS NULL @@ -680,7 +680,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') UNION ALL @@ -801,7 +801,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('procedure type') + AND LOWER(DOMAIN_ID) IN ('procedure type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -877,7 +877,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') INNER JOIN #concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -939,7 +939,7 @@ SELECT drug_exposure_id FROM @SOURCE_CDMV4_SCHEMA.DRUG_EXPOSURE LEFT JOIN #concept_map cm1 ON drug_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') WHERE drug_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1004,7 +1004,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') UNION ALL @@ -1170,7 +1170,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('drug type') + AND LOWER(DOMAIN_ID) IN ('drug type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1201,7 +1201,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1238,7 +1238,7 @@ SELECT condition_occurrence_id FROM @SOURCE_CDMV4_SCHEMA.CONDITION_OCCURRENCE LEFT JOIN #concept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1281,7 +1281,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1369,7 +1369,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('condition type') + AND LOWER(DOMAIN_ID) IN ('condition type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1522,7 +1522,7 @@ FROM ( INNER JOIN #concept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') LEFT JOIN #concept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id - AND LOWER(cm1.domain_id) IN ('unit') + AND LOWER(cm2.domain_id) IN ('unit') UNION ALL diff --git a/Version4 To Version5 Conversion/Oracle/OMOP CDMv4 to CDMv5 - Oracle.sql b/Version4 To Version5 Conversion/Oracle/OMOP CDMv4 to CDMv5 - Oracle.sql index f143127..4825f69 100644 --- a/Version4 To Version5 Conversion/Oracle/OMOP CDMv4 to CDMv5 - Oracle.sql +++ b/Version4 To Version5 Conversion/Oracle/OMOP CDMv4 to CDMv5 - Oracle.sql @@ -109,8 +109,8 @@ ALTER SESSION SET current_schema = [TARGET_CDMV5]; * Also, as of the date which this script was authored, no source_concept_ids map to multiple domains */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78aconcept_map'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78aconcept_map'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmconcept_map'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmconcept_map'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -120,23 +120,22 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78aconcept_map - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmconcept_map + AS SELECT - concept_id AS source_concept_id + concept_id AS source_concept_id ,concept_id AS target_concept_id ,domain_id AS domain_id FROM - [TARGET_CDMV5].[SCHEMA].concept - WHERE 1 = 0; + [TARGET_CDMV5].[SCHEMA].concept + WHERE 1 = 0 ; /* / */ -INSERT INTO ra2pz78aconcept_map +INSERT INTO g8iauhqmconcept_map --standard concepts -SELECT concept_id AS source_concept_id +SELECT concept_id AS source_concept_id ,concept_id AS target_concept_id ,domain_id FROM [TARGET_CDMV5].[SCHEMA].concept @@ -146,20 +145,19 @@ SELECT concept_id AS source_concept_id UNION --concepts with 'map to' standard -SELECT DISTINCT c1.concept_id AS source_concept_id +SELECT DISTINCT c1.concept_id AS source_concept_id ,c2.concept_id AS target_concept_id ,c2.domain_id - FROM ( - SELECT concept_id - FROM [TARGET_CDMV5].[SCHEMA].concept - WHERE ( + FROM (SELECT concept_id + FROM [TARGET_CDMV5].[SCHEMA].concept + WHERE ( ( standard_concept <> 'S' OR standard_concept IS NULL ) OR invalid_reason IS NOT NULL ) - ) c1 + ) c1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept_relationship cr1 ON c1.concept_id = cr1.concept_id_1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_id WHERE c2.standard_concept = 'S' @@ -170,33 +168,30 @@ INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_i UNION --concepts without 'map to' standard with another non 'is a' relation to standard -SELECT DISTINCT c1.concept_id AS source_concept_id +SELECT DISTINCT c1.concept_id AS source_concept_id ,c2.concept_id AS target_concept_id ,c2.domain_id - FROM ( - SELECT A.concept_id - FROM [TARGET_CDMV5].[SCHEMA].concept A - LEFT JOIN ( - SELECT DISTINCT c1.concept_id - FROM ( - SELECT concept_id - FROM [TARGET_CDMV5].[SCHEMA].concept - WHERE ( + FROM (SELECT A.concept_id + FROM [TARGET_CDMV5].[SCHEMA].concept A + LEFT JOIN (SELECT DISTINCT c1.concept_id + FROM (SELECT concept_id + FROM [TARGET_CDMV5].[SCHEMA].concept + WHERE ( ( standard_concept <> 'S' OR standard_concept IS NULL ) OR invalid_reason IS NOT NULL ) - ) c1 + ) c1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept_relationship cr1 ON c1.concept_id = cr1.concept_id_1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_id - WHERE c2.standard_concept = 'S' + WHERE c2.standard_concept = 'S' AND c2.invalid_reason IS NULL AND cr1.relationship_id IN ('Maps to') AND cr1.invalid_reason IS NULL - ) B ON A.concept_id = B.concept_id - WHERE ( + ) B ON A.concept_id = B.concept_id + WHERE ( ( A.standard_concept <> 'S' OR A.standard_concept IS NULL @@ -204,7 +199,7 @@ SELECT DISTINCT c1.concept_id AS source_concept_id OR A.invalid_reason IS NOT NULL ) AND B.concept_id IS NULL - ) c1 + ) c1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept_relationship cr1 ON c1.concept_id = cr1.concept_id_1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_id WHERE c2.standard_concept = 'S' @@ -225,28 +220,25 @@ INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_i UNION --concepts without 'map to' standard with 'is a' relation to standard -SELECT DISTINCT c1.concept_id AS source_concept_id +SELECT DISTINCT c1.concept_id AS source_concept_id ,c2.concept_id AS target_concept_id ,c2.domain_id - FROM ( - SELECT A.concept_id - FROM [TARGET_CDMV5].[SCHEMA].concept A - LEFT JOIN ( - SELECT DISTINCT c1.concept_id - FROM ( - SELECT concept_id - FROM [TARGET_CDMV5].[SCHEMA].concept - WHERE ( + FROM (SELECT A.concept_id + FROM [TARGET_CDMV5].[SCHEMA].concept A + LEFT JOIN (SELECT DISTINCT c1.concept_id + FROM (SELECT concept_id + FROM [TARGET_CDMV5].[SCHEMA].concept + WHERE ( ( standard_concept <> 'S' OR standard_concept IS NULL ) OR invalid_reason IS NOT NULL ) - ) c1 + ) c1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept_relationship cr1 ON c1.concept_id = cr1.concept_id_1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_id - WHERE c2.standard_concept = 'S' + WHERE c2.standard_concept = 'S' AND c2.invalid_reason IS NULL AND cr1.relationship_id IN ( 'Maps to' @@ -261,8 +253,8 @@ SELECT DISTINCT c1.concept_id AS source_concept_id ,'Concept alt_to to' ) AND cr1.invalid_reason IS NULL - ) B ON A.concept_id = B.concept_id - WHERE ( + ) B ON A.concept_id = B.concept_id + WHERE ( ( standard_concept <> 'S' OR standard_concept IS NULL @@ -270,17 +262,17 @@ SELECT DISTINCT c1.concept_id AS source_concept_id OR invalid_reason IS NOT NULL ) AND B.concept_id IS NULL - ) c1 + ) c1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept_relationship cr1 ON c1.concept_id = cr1.concept_id_1 INNER JOIN [TARGET_CDMV5].[SCHEMA].concept c2 ON cr1.concept_id_2 = c2.concept_id WHERE c2.standard_concept = 'S' AND c2.invalid_reason IS NULL AND cr1.relationship_id IN ('Is a') - AND cr1.invalid_reason IS NULL; + AND cr1.invalid_reason IS NULL ; BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78aconcept_map_distinct'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78aconcept_map_distinct'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmconcept_map_distinct'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmconcept_map_distinct'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -290,29 +282,28 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78aconcept_map_distinct - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmconcept_map_distinct + AS SELECT - source_concept_id + source_concept_id ,domain_id ,COUNT(*) AS targetConceptCount FROM - ra2pz78aconcept_map + g8iauhqmconcept_map WHERE 1 = 0 GROUP BY source_concept_id - ,domain_id; + ,domain_id ; /* / */ -INSERT INTO ra2pz78aconcept_map_distinct -SELECT source_concept_id +INSERT INTO g8iauhqmconcept_map_distinct +SELECT source_concept_id ,domain_id ,COUNT(*) -FROM ra2pz78aconcept_map + FROM g8iauhqmconcept_map GROUP BY source_concept_id - ,domain_id; + ,domain_id ; BEGIN EXECUTE IMMEDIATE 'TRUNCATE TABLE [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS'; @@ -340,12 +331,12 @@ INSERT INTO [TARGET_CDMV5].[SCHEMA].cdm_source ( ,vocabulary_version ,cdm_release_date ) -SELECT '[TARGET_CDMV5]' +SELECT '[TARGET_CDMV5]' ,'V5' ,v.vocabulary_version ,SYSDATE - FROM [TARGET_CDMV5].[SCHEMA].vocabulary v - WHERE vocabulary_id = 'Vocabulary'; + FROM [TARGET_CDMV5].[SCHEMA].vocabulary v + WHERE vocabulary_id = 'Vocabulary' ; /**** @@ -353,7 +344,7 @@ LOCATION ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].location -SELECT location_id +SELECT location_id ,address_1 ,address_2 ,city @@ -361,7 +352,7 @@ SELECT location_id ,zip ,county ,location_source_value -FROM [SOURCE_CDMV4].[SCHEMA].LOCATION; + FROM [SOURCE_CDMV4].[SCHEMA].LOCATION ; /**** @@ -369,13 +360,13 @@ CARE_SITE ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].care_site -SELECT care_site_id +SELECT care_site_id ,TO_CHAR(NULL ) AS care_site_name ,place_of_service_concept_id ,location_id ,care_site_source_value ,place_of_service_source_value -FROM [SOURCE_CDMV4].[SCHEMA].CARE_SITE; + FROM [SOURCE_CDMV4].[SCHEMA].CARE_SITE ; /**** @@ -383,7 +374,7 @@ Provider ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].provider -SELECT provider_id +SELECT provider_id ,TO_CHAR(NULL ) AS provider_name ,NPI ,DEA @@ -396,7 +387,7 @@ SELECT provider_id ,0 AS specialty_source_concept_id ,TO_CHAR(NULL ) AS gender_source_value ,cast(NULL AS INT) AS gender_source_concept_id -FROM [SOURCE_CDMV4].[SCHEMA].provider; + FROM [SOURCE_CDMV4].[SCHEMA].provider ; /**** @@ -404,7 +395,7 @@ FROM [SOURCE_CDMV4].[SCHEMA].provider; ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].person -SELECT person_id +SELECT person_id ,coalesce(gender.target_concept_id, 0) AS gender_concept_id ,year_of_birth ,month_of_birth @@ -422,66 +413,60 @@ SELECT person_id ,CAST(NULL AS INT) race_source_concept_id ,ethnicity_source_value ,CAST(NULL AS INT) ethnicity_source_concept_id -FROM [SOURCE_CDMV4].[SCHEMA].PERSON p -LEFT JOIN ra2pz78aconcept_map gender ON LOWER(gender.DOMAIN_ID) IN ('gender') + FROM [SOURCE_CDMV4].[SCHEMA].PERSON p +LEFT JOIN g8iauhqmconcept_map gender ON LOWER(gender.DOMAIN_ID) IN ('gender') AND p.gender_concept_id = gender.source_concept_id -LEFT JOIN ra2pz78aconcept_map race ON LOWER(race.DOMAIN_ID) IN ('race') +LEFT JOIN g8iauhqmconcept_map race ON LOWER(race.DOMAIN_ID) IN ('race') AND p.race_concept_id = race.source_concept_id -LEFT JOIN ra2pz78aconcept_map ethnicity ON LOWER(ethnicity.DOMAIN_ID) IN ('ethnicity') - AND p.ETHNICITY_CONCEPT_ID = ethnicity.source_concept_id; +LEFT JOIN g8iauhqmconcept_map ethnicity ON LOWER(ethnicity.DOMAIN_ID) IN ('ethnicity') + AND p.ETHNICITY_CONCEPT_ID = ethnicity.source_concept_id ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'PERSON: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid GENDER_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].PERSON - WHERE GENDER_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'PERSON: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid GENDER_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].PERSON + WHERE GENDER_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' AND LOWER(DOMAIN_ID) IN ('gender') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'PERSON: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid RACE_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].PERSON - WHERE RACE_CONCEPT_ID IS NOT NULL - AND RACE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'PERSON: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid RACE_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].PERSON + WHERE RACE_CONCEPT_ID IS NOT NULL + AND RACE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' AND LOWER(DOMAIN_ID) IN ('race') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'PERSON: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid ETHNICITY_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].PERSON - WHERE ETHNICITY_CONCEPT_ID IS NOT NULL - AND ETHNICITY_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'PERSON: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid ETHNICITY_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].PERSON + WHERE ETHNICITY_CONCEPT_ID IS NOT NULL + AND ETHNICITY_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' AND LOWER(DOMAIN_ID) IN ('ethnicity') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; /**** @@ -489,12 +474,12 @@ FROM ( ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].observation_period -SELECT observation_period_id +SELECT observation_period_id ,person_id ,observation_period_start_date ,observation_period_end_date ,44814722 AS period_type_concept_id -FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION_PERIOD; + FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION_PERIOD ; /**** @@ -502,32 +487,30 @@ FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION_PERIOD; ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].death -SELECT person_id +SELECT person_id ,death_date ,COALESCE(death_type_concept_id, 0) AS death_type_concept_id ,cause_of_death_concept_id AS cause_concept_id ,cause_of_death_source_value AS cause_source_value ,CAST(NULL AS INT) AS cause_source_concept_id -FROM [SOURCE_CDMV4].[SCHEMA].DEATH -LEFT JOIN ra2pz78aconcept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID - AND LOWER(DOMAIN_ID) IN ('death type'); + FROM [SOURCE_CDMV4].[SCHEMA].DEATH +LEFT JOIN g8iauhqmconcept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'DEATH: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].DEATH - WHERE DEATH_TYPE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'DEATH: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].DEATH + WHERE DEATH_TYPE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('death type') + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; /**** @@ -535,7 +518,7 @@ FROM ( ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].visit_occurrence -SELECT visit_occurrence_id +SELECT visit_occurrence_id ,person_id ,COALESCE(cm1.target_concept_id, 0) AS visit_concept_id ,visit_start_date @@ -547,26 +530,24 @@ SELECT visit_occurrence_id ,care_site_id ,place_of_service_source_value AS visit_source_value ,CAST(NULL AS INT) visit_source_concept_id -FROM [SOURCE_CDMV4].[SCHEMA].VISIT_OCCURRENCE -LEFT JOIN ra2pz78aconcept_map cm1 ON VISIT_OCCURRENCE.PLACE_OF_SERVICE_CONCEPT_ID = cm1.source_concept_id - AND LOWER(cm1.domain_id) IN ('visit'); + FROM [SOURCE_CDMV4].[SCHEMA].VISIT_OCCURRENCE +LEFT JOIN g8iauhqmconcept_map cm1 ON VISIT_OCCURRENCE.PLACE_OF_SERVICE_CONCEPT_ID = cm1.source_concept_id + AND LOWER(cm1.domain_id) IN ('visit') ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'VISIT_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid VISIT_CONCEPT_ID (from the CDMv4 PLACE_OF_SERVICE_CONCEPT_ID field)' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].VISIT_OCCURRENCE - WHERE PLACE_OF_SERVICE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'VISIT_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid VISIT_CONCEPT_ID (from the CDMv4 PLACE_OF_SERVICE_CONCEPT_ID field)' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].VISIT_OCCURRENCE + WHERE PLACE_OF_SERVICE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' AND LOWER(DOMAIN_ID) IN ('visit') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; /**** @@ -574,8 +555,8 @@ FROM ( ****/ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78apo_map'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78apo_map'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmpo_map'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmpo_map'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -585,11 +566,10 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78apo_map - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmpo_map + AS SELECT - po.procedure_occurrence_id + po.procedure_occurrence_id ,po.person_id ,po.procedure_concept_id ,po.procedure_date @@ -604,15 +584,15 @@ SELECT ,de.drug_exposure_id AS origional_drug_id FROM - [TARGET_CDMV5].[SCHEMA].procedure_occurrence po + [TARGET_CDMV5].[SCHEMA].procedure_occurrence po LEFT JOIN [TARGET_CDMV5].[SCHEMA].drug_exposure de ON 1 = 0 - WHERE 0 = 1; + WHERE 0 = 1 ; /* / */ --find valid procedures from procedure table -INSERT INTO ra2pz78apo_map -SELECT procedure_occurrence_id +INSERT INTO g8iauhqmpo_map +SELECT procedure_occurrence_id ,person_id ,COALESCE(cm1.target_concept_id, 0) AS procedure_concept_id ,procedure_date @@ -626,21 +606,21 @@ SELECT procedure_occurrence_id ,NULL AS qualifier_source_value ,CAST(NULL AS INT) AS origional_drug_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE -INNER JOIN ra2pz78aconcept_map cm1 ON PROCEDURE_OCCURRENCE.PROCEDURE_CONCEPT_ID = cm1.source_concept_id +INNER JOIN g8iauhqmconcept_map cm1 ON PROCEDURE_OCCURRENCE.PROCEDURE_CONCEPT_ID = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('procedure') -INNER JOIN ra2pz78aconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id +INNER JOIN g8iauhqmconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 -LEFT JOIN ra2pz78aconcept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') -LEFT JOIN ra2pz78aconcept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id +LEFT JOIN g8iauhqmconcept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') +LEFT JOIN g8iauhqmconcept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 UNION ALL -- All procedures that did not map to a standard concept in V4 should also carry over to V5 -SELECT procedure_occurrence_id +SELECT procedure_occurrence_id ,person_id ,procedure_concept_id ,procedure_date @@ -653,17 +633,13 @@ SELECT procedure_occurrence_id ,CAST(NULL AS INT) procedure_source_concept_id ,NULL qualifier_source_value ,CAST(NULL AS INT) AS origional_drug_id -FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - FROM - DUAL - FROM - DUAL -WHERE procedure_concept_id = 0 + FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE + WHERE procedure_concept_id = 0 UNION ALL -- All PROCEDURE_OCCURRENCE that do not map to a standard concept in V5 should also carry over with procedure_concept_id = 0 -SELECT procedure_occurrence_id +SELECT procedure_occurrence_id ,person_id ,0 AS procedure_concept_id ,procedure_date @@ -677,15 +653,15 @@ SELECT procedure_occurrence_id ,NULL qualifier_source_value ,CAST(NULL AS INT) AS origional_drug_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE -LEFT JOIN ra2pz78aconcept_map cm1 ON procedure_concept_id = cm1.source_concept_id -LEFT JOIN ra2pz78aconcept_map cm2 ON procedure_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') +LEFT JOIN g8iauhqmconcept_map cm1 ON procedure_concept_id = cm1.source_concept_id +LEFT JOIN g8iauhqmconcept_map cm2 ON procedure_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') WHERE procedure_concept_id <> 0 AND cm1.domain_id IS NULL UNION ALL -SELECT CASE +SELECT CASE WHEN MAXROW.MAXROWID IS NULL THEN 0 ELSE MAXROW.MAXROWID @@ -704,10 +680,7 @@ SELECT CASE ,procedure_source_concept_id ,qualifier_source_value ,origional_drug_id -FROM ( - --find valid procedures from procedure table that map to more than 1 - --target concept in V5 - SELECT person_id + FROM (SELECT person_id ,COALESCE(cm1.target_concept_id, 0) AS procedure_concept_id ,procedure_date ,COALESCE(cm2.target_concept_id, 0) AS procedure_type_concept_id @@ -721,13 +694,13 @@ FROM ( ,CAST(NULL AS INT) AS origional_drug_id ,CAST(NULL AS INT) AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON PROCEDURE_OCCURRENCE.PROCEDURE_CONCEPT_ID = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON PROCEDURE_OCCURRENCE.PROCEDURE_CONCEPT_ID = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('procedure') - INNER JOIN ra2pz78aconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id + INNER JOIN g8iauhqmconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 - LEFT JOIN ra2pz78aconcept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + LEFT JOIN g8iauhqmconcept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') UNION ALL @@ -746,7 +719,7 @@ FROM ( ,CAST(NULL AS INT) AS origional_drug_id ,condition_occurrence_id AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('procedure') UNION ALL @@ -766,13 +739,13 @@ FROM ( ,drug_exposure_id AS origional_drug_id ,drug_exposure_id AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('procedure') --find procedures that were previously classified as observation UNION ALL - SELECT person_id + SELECT person_id ,cm1.target_concept_id AS procedure_concept_id ,observation_date AS procedure_date ,0 AS procedure_type_concept_id @@ -785,14 +758,13 @@ FROM ( ,NULL AS qualifier_source_value ,CAST(NULL AS INT) AS origional_drug_id ,OBSERVATION_ID AS OCCURRENCE_ID - FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - INNER JOIN ra2pz78aconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION + INNER JOIN g8iauhqmconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('procedure') - ) OTHERS - ,( - SELECT MAX(PROCEDURE_OCCURRENCE_ID) AS MAXROWID - FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - ) MAXROW; + ) OTHERS + ,(SELECT MAX(PROCEDURE_OCCURRENCE_ID) AS MAXROWID + FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE + ) MAXROW ; INSERT INTO [TARGET_CDMV5].[SCHEMA].procedure_occurrence ( procedure_occurrence_id @@ -808,7 +780,7 @@ INSERT INTO [TARGET_CDMV5].[SCHEMA].procedure_occurrence ( ,procedure_source_concept_id ,qualifier_source_value ) -SELECT procedure_occurrence_id +SELECT procedure_occurrence_id ,person_id ,procedure_concept_id ,procedure_date @@ -820,39 +792,35 @@ SELECT procedure_occurrence_id ,procedure_source_value ,procedure_source_concept_id ,qualifier_source_value -FROM ra2pz78apo_map; + FROM g8iauhqmpo_map ; --warnings of invalid records INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'PROCEDURE_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid PROCOEDURE_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - WHERE PROCEDURE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'PROCEDURE_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid PROCOEDURE_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE + WHERE PROCEDURE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR STANDARD_CONCEPT = 'S' - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'PROCEDURE_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid PROCOEDURE_TYPE_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - WHERE PROCEDURE_TYPE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'PROCEDURE_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid PROCOEDURE_TYPE_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE + WHERE PROCEDURE_TYPE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('procedure type') + AND LOWER(DOMAIN_ID) IN ('procedure type', 'Type Concept') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; /**** @@ -861,8 +829,8 @@ FROM ( ****/ --find valid drugs from drug_exposure table BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78adrgexp_map'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78adrgexp_map'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmdrgexp_map'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmdrgexp_map'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -872,11 +840,10 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78adrgexp_map - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmdrgexp_map + AS SELECT - de.drug_exposure_id + de.drug_exposure_id ,de.person_id ,de.drug_concept_id ,de.drug_exposure_start_date @@ -900,14 +867,14 @@ SELECT ,po.procedure_occurrence_id AS origional_procedure_id FROM - [TARGET_CDMV5].[SCHEMA].drug_exposure de + [TARGET_CDMV5].[SCHEMA].drug_exposure de LEFT JOIN [TARGET_CDMV5].[SCHEMA].procedure_occurrence po ON 1 = 0 - WHERE 0 = 1; + WHERE 0 = 1 ; /* / */ -INSERT INTO ra2pz78adrgexp_map -SELECT drug_exposure_id +INSERT INTO g8iauhqmdrgexp_map +SELECT drug_exposure_id ,person_id ,COALESCE(cm1.target_concept_id, 0) AS drug_concept_id ,drug_exposure_start_date @@ -930,14 +897,14 @@ SELECT drug_exposure_id ,NULL AS dose_unit_source_value ,CAST(NULL AS INT) AS origional_procedure_id FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE -INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id +INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('drug') -INNER JOIN ra2pz78aconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id +INNER JOIN g8iauhqmconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 -LEFT JOIN ra2pz78aconcept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') -INNER JOIN ra2pz78aconcept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id +LEFT JOIN g8iauhqmconcept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') +INNER JOIN g8iauhqmconcept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 WHERE drug_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 @@ -945,7 +912,7 @@ INNER JOIN ra2pz78aconcept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2 UNION ALL -- All drug exposures that did not map to a standard concept in V4 should also carry over to V5 -SELECT drug_exposure_id +SELECT drug_exposure_id ,person_id ,drug_concept_id ,drug_exposure_start_date @@ -973,7 +940,7 @@ SELECT drug_exposure_id UNION ALL -- All drug exposures that do not map to a standard concept in V5 should also carry over with condition_concept_id = 0 -SELECT drug_exposure_id +SELECT drug_exposure_id ,person_id ,0 ,drug_exposure_start_date @@ -996,15 +963,15 @@ SELECT drug_exposure_id ,NULL AS dose_unit_source_value ,CAST(NULL AS INT) AS origional_procedure_id FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE -LEFT JOIN ra2pz78aconcept_map cm1 ON drug_concept_id = cm1.source_concept_id -LEFT JOIN ra2pz78aconcept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') +LEFT JOIN g8iauhqmconcept_map cm1 ON drug_concept_id = cm1.source_concept_id +LEFT JOIN g8iauhqmconcept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') WHERE drug_concept_id <> 0 AND cm1.domain_id IS NULL UNION ALL -SELECT CASE +SELECT CASE WHEN MAXROW.MAXROWID IS NULL THEN 0 ELSE MAXROW.MAXROWID @@ -1032,9 +999,7 @@ SELECT CASE ,route_source_value ,dose_unit_source_value ,origional_procedure_id -FROM ( - --find valid drugs from drug_exposure table that map to > 1 target concept - SELECT person_id + FROM (SELECT person_id ,COALESCE(cm1.target_concept_id, 0) AS drug_concept_id ,drug_exposure_start_date ,drug_exposure_end_date @@ -1057,13 +1022,13 @@ FROM ( ,CAST(NULL AS INT) AS origional_procedure_id ,CAST(NULL AS INT) AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('drug') - INNER JOIN ra2pz78aconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id + INNER JOIN g8iauhqmconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 - LEFT JOIN ra2pz78aconcept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + LEFT JOIN g8iauhqmconcept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') UNION ALL @@ -1091,7 +1056,7 @@ FROM ( ,CAST(NULL AS INT) AS origional_procedure_id ,condition_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('drug') --find drugs that were previously classified as procedure @@ -1120,13 +1085,13 @@ FROM ( ,procedure_occurrence_id AS origional_procedure_id ,procedure_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('drug') --find drugs that were previously classified as observation UNION ALL - SELECT person_id + SELECT person_id ,cm1.target_concept_id AS drug_concept_id ,observation_date AS drug_exposure_start_date ,TO_DATE(NULL , 'yyyymmdd') AS drug_exposure_end_date @@ -1148,14 +1113,13 @@ FROM ( ,NULL AS dose_unit_source_value ,CAST(NULL AS INT) AS origional_procedure_id ,observation_id AS occurrence_id - FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - INNER JOIN ra2pz78aconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION + INNER JOIN g8iauhqmconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('drug') - ) OTHERS - ,( - SELECT MAX(DRUG_EXPOSURE_ID) AS MAXROWID - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - ) MAXROW; + ) OTHERS + ,(SELECT MAX(DRUG_EXPOSURE_ID) AS MAXROWID + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE + ) MAXROW ; INSERT INTO [TARGET_CDMV5].[SCHEMA].drug_exposure ( drug_exposure_id @@ -1180,7 +1144,7 @@ INSERT INTO [TARGET_CDMV5].[SCHEMA].drug_exposure ( ,route_source_value ,dose_unit_source_value ) -SELECT drug_exposure_id +SELECT drug_exposure_id ,person_id ,drug_concept_id ,drug_exposure_start_date @@ -1201,39 +1165,35 @@ SELECT drug_exposure_id ,drug_source_concept_id ,route_source_value ,dose_unit_source_value -FROM ra2pz78adrgexp_map; + FROM g8iauhqmdrgexp_map ; --warnings of invalid records INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'DRUG_EXPOSURE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid DRUG_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - WHERE DRUG_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'DRUG_EXPOSURE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid DRUG_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE + WHERE DRUG_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR STANDARD_CONCEPT = 'S' - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'DRUG_EXPOSURE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid DRUG_TYPE_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - WHERE DRUG_TYPE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'DRUG_EXPOSURE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid DRUG_TYPE_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE + WHERE DRUG_TYPE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('drug type') + AND LOWER(DOMAIN_ID) IN ('drug type', 'Type Concept') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; /**** @@ -1242,7 +1202,7 @@ FROM ( ****/ --find valid conditions from condition_occurrence table INSERT INTO [TARGET_CDMV5].[SCHEMA].condition_occurrence -SELECT condition_occurrence_id +SELECT condition_occurrence_id ,person_id ,COALESCE(cm1.target_concept_id, 0) AS condition_concept_id ,condition_start_date @@ -1254,19 +1214,19 @@ SELECT condition_occurrence_id ,condition_source_value ,CAST(NULL AS INT) condition_source_concept_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE -INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id +INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('condition') -INNER JOIN ra2pz78aconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id +INNER JOIN g8iauhqmconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 -LEFT JOIN ra2pz78aconcept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') +LEFT JOIN g8iauhqmconcept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL -- All conditions that did not map to a standard concept in V4 should also carry over to V5 -SELECT condition_occurrence_id +SELECT condition_occurrence_id ,person_id ,condition_concept_id ,condition_start_date @@ -1283,7 +1243,7 @@ SELECT condition_occurrence_id UNION ALL -- All conditions that do not map to a standard concept in V5 should also carry over with condition_concept_id = 0 -SELECT condition_occurrence_id +SELECT condition_occurrence_id ,person_id ,0 AS condition_concept_id ,condition_start_date @@ -1295,15 +1255,15 @@ SELECT condition_occurrence_id ,condition_source_value ,CAST(NULL AS INT) condition_source_concept_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE -LEFT JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id -LEFT JOIN ra2pz78aconcept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') +LEFT JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id +LEFT JOIN g8iauhqmconcept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id <> 0 AND cm1.domain_id IS NULL UNION ALL -SELECT CASE +SELECT CASE WHEN MAXROW.MAXROWID IS NULL THEN 0 ELSE MAXROW.MAXROWID @@ -1320,9 +1280,7 @@ SELECT CASE ,visit_occurrence_id ,condition_source_value ,condition_source_concept_id -FROM ( - --find valid conditions from condition_occurrence table that map to > 1 target concept - SELECT person_id + FROM (SELECT person_id ,COALESCE(cm1.target_concept_id, 0) AS condition_concept_id ,condition_start_date ,condition_end_date @@ -1333,15 +1291,15 @@ FROM ( ,condition_source_value ,CAST(NULL AS INT) condition_source_concept_id ,NULL AS OCCURRENCE_ID - FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE + INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('condition') - INNER JOIN ra2pz78aconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id + INNER JOIN g8iauhqmconcept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_concept_id AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 - LEFT JOIN ra2pz78aconcept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') - WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 + LEFT JOIN g8iauhqmconcept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') + WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1358,7 +1316,7 @@ FROM ( ,CAST(NULL AS INT) condition_source_concept_id ,procedure_occurrence_id AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('condition') --find conditions that were previously classified as drug @@ -1376,13 +1334,13 @@ FROM ( ,CAST(NULL AS INT) condition_source_concept_id ,drug_exposure_id AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('condition') --find conditions that were previously classified as observation UNION ALL - SELECT person_id + SELECT person_id ,cm1.target_concept_id AS condition_concept_id ,observation_date AS condition_start_date ,NULL AS condition_end_date @@ -1393,46 +1351,41 @@ FROM ( ,observation_source_value AS condition_source_value ,CAST(NULL AS INT) condition_source_concept_id ,observation_id AS OCCURRENCE_ID - FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - INNER JOIN ra2pz78aconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION + INNER JOIN g8iauhqmconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('condition') - ) OTHERS - ,( - SELECT MAX(condition_occurrence_id) AS MAXROWID - FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - ) MAXROW; + ) OTHERS + ,(SELECT MAX(condition_occurrence_id) AS MAXROWID + FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE + ) MAXROW ; --warnings of invalid records INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'CONDITION_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid CONDITION_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - WHERE CONDITION_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'CONDITION_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid CONDITION_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE + WHERE CONDITION_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR STANDARD_CONCEPT = 'S' - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) -SELECT 'CONDIITON_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid CONDITION_TYPE_CONCEPT_ID' -FROM ( - SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS - FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - WHERE CONDITION_TYPE_CONCEPT_ID NOT IN ( - SELECT CONCEPT_ID - FROM [TARGET_CDMV5].[SCHEMA].CONCEPT - WHERE CONCEPT_ID = 0 +SELECT 'CONDIITON_OCCURRENCE: ' || TO_CHAR(NUM_INVALID_RECORDS ) || ' records in the source CDMv4 database have invalid CONDITION_TYPE_CONCEPT_ID' + FROM (SELECT COUNT(PERSON_ID) AS NUM_INVALID_RECORDS + FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE + WHERE CONDITION_TYPE_CONCEPT_ID NOT IN (SELECT CONCEPT_ID + FROM [TARGET_CDMV5].[SCHEMA].CONCEPT + WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('condition type') + AND LOWER(DOMAIN_ID) IN ('condition type', 'Type Concept') ) - ) + ) HAVING COUNT(PERSON_ID) > 0 - ) warn; + ) warn ; /**** @@ -1440,7 +1393,7 @@ FROM ( ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].device_exposure -SELECT row_number() OVER ( +SELECT row_number() OVER ( ORDER BY OCCURRENCE_ID ) AS device_exposure_id ,person_id @@ -1454,9 +1407,7 @@ SELECT row_number() OVER ( ,visit_occurrence_id ,device_source_value ,device_source_concept_id -FROM ( - --find devices that were previously classified as procedures - SELECT PERSON_ID + FROM (SELECT PERSON_ID ,cm1.target_concept_id AS DEVICE_CONCEPT_ID ,PROCEDURE_DATE AS DEVICE_EXPOSURE_START_DATE ,TO_DATE(NULL , 'yyyymmdd') AS DEVICE_EXPOSURE_END_DATE @@ -1469,7 +1420,7 @@ FROM ( ,0 AS device_source_concept_id ,PROCEDURE_OCCURRENCE_ID AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('device') --find devices that were previously classified as drug exposure @@ -1488,7 +1439,7 @@ FROM ( ,0 AS device_source_concept_id ,DRUG_EXPOSURE_ID AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('device') --find devices that were previously classified as conditions @@ -1507,13 +1458,13 @@ FROM ( ,0 AS device_source_concept_id ,CONDITION_OCCURRENCE_ID AS OCCURRENCE_ID FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('device') --find devices that were previously classified as observations UNION ALL - SELECT PERSON_ID + SELECT PERSON_ID ,cm1.target_concept_id AS DEVICE_CONCEPT_ID ,OBSERVATION_DATE AS DEVICE_EXPOSURE_START_DATE ,TO_DATE(NULL , 'yyyymmdd') AS DEVICE_EXPOSURE_END_DATE @@ -1525,10 +1476,10 @@ FROM ( ,OBSERVATION_SOURCE_VALUE AS DEVICE_SOURCE_VALUE ,0 AS device_source_concept_id ,OBSERVATION_ID AS OCCURRENCE_ID - FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - INNER JOIN ra2pz78aconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION + INNER JOIN g8iauhqmconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('device') - ) OTHERS; + ) OTHERS ; /**** @@ -1537,7 +1488,7 @@ FROM ( ****/ --find valid measurements from observation table INSERT INTO [TARGET_CDMV5].[SCHEMA].measurement -SELECT row_number() OVER ( +SELECT row_number() OVER ( ORDER BY occurrence_id ) AS measurement_id ,person_id @@ -1557,9 +1508,7 @@ SELECT row_number() OVER ( ,measurement_source_concept_id ,unit_source_value ,value_source_value -FROM ( - --find mesaurements that were previously classified as observations - SELECT person_id + FROM (SELECT person_id ,cm1.target_concept_id AS measurement_concept_id ,OBSERVATION_DATE AS measurement_date ,TO_CHAR(OBSERVATION_TIME ) AS measurement_time @@ -1578,10 +1527,10 @@ FROM ( ,TO_CHAR(NULL ) AS value_source_value ,observation_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - INNER JOIN ra2pz78aconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') - LEFT JOIN ra2pz78aconcept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id - AND LOWER(cm1.domain_id) IN ('unit') + LEFT JOIN g8iauhqmconcept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id + AND LOWER(cm2.domain_id) IN ('unit') UNION ALL @@ -1604,7 +1553,7 @@ FROM ( ,TO_CHAR(NULL ) AS value_source_value ,procedure_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') UNION ALL @@ -1628,12 +1577,12 @@ FROM ( ,TO_CHAR(NULL ) AS value_source_value ,condition_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') UNION ALL - SELECT person_id + SELECT person_id ,cm1.target_concept_id AS measurement_concept_id ,drug_exposure_start_date AS measurement_date ,TO_CHAR(NULL ) AS measurement_time @@ -1651,10 +1600,10 @@ FROM ( ,TO_CHAR(NULL ) AS unit_source_value ,TO_CHAR(NULL ) AS value_source_value ,drug_exposure_id AS occurrence_id - FROM [SOURCE_CDMV4].[SCHEMA].drug_exposure - INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].drug_exposure + INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') - ) OTHERS; + ) OTHERS ; /**** @@ -1663,7 +1612,7 @@ FROM ( ****/ --find valid observation from observation table INSERT INTO [TARGET_CDMV5].[SCHEMA].observation -SELECT observation_id +SELECT observation_id ,person_id ,observation_concept_id ,observation_date @@ -1681,22 +1630,21 @@ SELECT observation_id ,unit_source_value ,TO_CHAR(NULL ) qualifier_source_value FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - WHERE observation_concept_id NOT IN ( - SELECT source_concept_id - FROM ra2pz78aconcept_map_distinct - WHERE LOWER(domain_id) IN ( + WHERE observation_concept_id NOT IN (SELECT source_concept_id + FROM g8iauhqmconcept_map_distinct + WHERE LOWER(domain_id) IN ( 'condition' ,'drug' ,'procedure' ,'device' ,'measurement' ) - ) + ) --find observations that were previously classified as procedure UNION ALL -SELECT CASE +SELECT CASE WHEN MAXROW.MAXROWID IS NULL THEN 0 ELSE MAXROW.MAXROWID @@ -1719,8 +1667,7 @@ SELECT CASE ,observation_source_concept_id ,unit_source_value ,qualifier_source_value -FROM ( - SELECT person_id + FROM (SELECT person_id ,cm1.target_concept_id AS observation_concept_id ,procedure_date AS observation_date ,TO_CHAR(NULL ) AS observation_time @@ -1738,7 +1685,7 @@ FROM ( ,TO_CHAR(NULL ) qualifier_source_value ,procedure_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON procedure_occurrence.procedure_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('observation') --find observations that were previously classified as condition @@ -1762,7 +1709,7 @@ FROM ( ,TO_CHAR(NULL ) qualifier_source_value ,condition_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE - INNER JOIN ra2pz78aconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('observation') UNION ALL @@ -1787,13 +1734,13 @@ FROM ( ,po.procedure_occurrence_id AS occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_COST pc INNER JOIN [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE po ON pc.PROCEDURE_OCCURRENCE_ID = po.PROCEDURE_OCCURRENCE_ID - INNER JOIN ra2pz78aconcept_map cm1 ON pc.disease_class_concept_id = cm1.source_concept_id + INNER JOIN g8iauhqmconcept_map cm1 ON pc.disease_class_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('observation') UNION ALL --find observations that were previously classified as drug exposure - SELECT person_id + SELECT person_id ,cm1.target_concept_id AS observation_concept_id ,drug_exposure_start_date AS observation_date ,TO_CHAR(NULL ) AS observation_time @@ -1810,14 +1757,13 @@ FROM ( ,NULL AS unit_source_value ,TO_CHAR(NULL ) qualifier_source_value ,drug_exposure_id AS occurrence_id - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE - INNER JOIN ra2pz78aconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE + INNER JOIN g8iauhqmconcept_map cm1 ON drug_exposure.drug_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('observation') - ) OTHERS - ,( - SELECT MAX(OBSERVATION_ID) AS MAXROWID - FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION - ) MAXROW; + ) OTHERS + ,(SELECT MAX(OBSERVATION_ID) AS MAXROWID + FROM [SOURCE_CDMV4].[SCHEMA].OBSERVATION + ) MAXROW ; /**** @@ -1825,14 +1771,14 @@ FROM ( ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].payer_plan_period -SELECT payer_plan_period_id +SELECT payer_plan_period_id ,person_id ,payer_plan_period_start_date ,payer_plan_period_end_date ,payer_source_value ,plan_source_value ,family_source_value -FROM [SOURCE_CDMV4].[SCHEMA].PAYER_PLAN_PERIOD; + FROM [SOURCE_CDMV4].[SCHEMA].PAYER_PLAN_PERIOD ; /**** @@ -1842,7 +1788,7 @@ FROM [SOURCE_CDMV4].[SCHEMA].PAYER_PLAN_PERIOD; ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].drug_cost -SELECT drug_cost_id +SELECT drug_cost_id ,dc.drug_exposure_id ,cast(NULL AS INT) currency_concept_id ,paid_copay @@ -1856,11 +1802,11 @@ SELECT drug_cost_id ,dispensing_fee ,average_wholesale_price ,payer_plan_period_id -FROM [SOURCE_CDMV4].[SCHEMA].DRUG_COST dc; + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_COST dc ; -- insert procedure costs for procedures that were inserted into the drug_exposure table INSERT INTO [TARGET_CDMV5].[SCHEMA].drug_cost -SELECT CASE +SELECT CASE WHEN MAXROW.MAXROWID IS NULL THEN 0 ELSE MAXROW.MAXROWID @@ -1880,8 +1826,7 @@ SELECT CASE ,dispensing_fee ,average_wholesale_price ,payer_plan_period_id -FROM ( - SELECT drug_exposure_id + FROM (SELECT drug_exposure_id ,po.person_id ,paid_copay ,paid_coinsurance @@ -1895,16 +1840,15 @@ FROM ( ,CAST(NULL AS FLOAT) AS average_wholesale_price ,payer_plan_period_id ,procedure_cost_id AS OCCURRENCE_ID - FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE po + FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE po INNER JOIN [SOURCE_CDMV4].[SCHEMA].PROCEDURE_COST pc ON po.procedure_occurrence_id = pc.procedure_occurrence_id --JOIN dbo.drug_exposure de on de.person_id = po.person_id and pc.procedure_occurrence_id = de.origional_procedure_id - INNER JOIN ra2pz78adrgexp_map de ON de.person_id = po.person_id + INNER JOIN g8iauhqmdrgexp_map de ON de.person_id = po.person_id AND pc.procedure_occurrence_id = de.origional_procedure_id - ) OTHERS - ,( - SELECT MAX(drug_cost_id) AS MAXROWID - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_COST - ) MAXROW; + ) OTHERS + ,(SELECT MAX(drug_cost_id) AS MAXROWID + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_COST + ) MAXROW ; /**** @@ -1915,7 +1859,7 @@ FROM ( ****/ INSERT INTO [TARGET_CDMV5].[SCHEMA].procedure_cost -SELECT procedure_cost_id +SELECT procedure_cost_id ,procedure_occurrence_id ,cast(NULL AS INT) currency_concept_id ,paid_copay @@ -1928,11 +1872,11 @@ SELECT procedure_cost_id ,payer_plan_period_id ,revenue_code_concept_id ,revenue_code_source_value -FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_COST; + FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_COST ; -- insert drug costs for drugs that were inserted into the procedure_occurrence table INSERT INTO [TARGET_CDMV5].[SCHEMA].procedure_cost -SELECT CASE +SELECT CASE WHEN MAXROW.MAXROWID IS NULL THEN 0 ELSE MAXROW.MAXROWID @@ -1951,8 +1895,7 @@ SELECT CASE ,payer_plan_period_id ,revenue_code_concept_id ,revenue_code_source_value -FROM ( - SELECT po.procedure_occurrence_id + FROM (SELECT po.procedure_occurrence_id ,po.person_id ,paid_copay ,paid_coinsurance @@ -1968,16 +1911,15 @@ FROM ( ,CAST(NULL AS INT) AS revenue_code_concept_id ,CAST(NULL AS INT) AS revenue_code_source_value ,drug_cost_id AS OCCURRENCE_ID - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE de + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE de INNER JOIN [SOURCE_CDMV4].[SCHEMA].DRUG_COST dc ON de.drug_exposure_id = dc.drug_exposure_id --JOIN dbo.procedure_occurrence po on de.person_id = po.person_id and de.drug_exposure_id = po.origional_drug_id - INNER JOIN ra2pz78apo_map po ON de.person_id = po.person_id + INNER JOIN g8iauhqmpo_map po ON de.person_id = po.person_id AND de.drug_exposure_id = po.origional_drug_id - ) OTHERS - ,( - SELECT MAX(drug_cost_id) AS MAXROWID - FROM [SOURCE_CDMV4].[SCHEMA].DRUG_COST - ) MAXROW; + ) OTHERS + ,(SELECT MAX(drug_cost_id) AS MAXROWID + FROM [SOURCE_CDMV4].[SCHEMA].DRUG_COST + ) MAXROW ; /**** @@ -1986,8 +1928,8 @@ Note: Eras derived from DRUG_EXPOSURE table, using 30d gap ****/ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acteDrugTarget'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acteDrugTarget'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcteDrugTarget'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcteDrugTarget'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -1998,11 +1940,10 @@ END; /* / */ -- Normalize DRUG_EXPOSURE_END_DATE to either the existing drug exposure end date, or add days supply, or add 1 day to the start date -CREATE GLOBAL TEMPORARY TABLE ra2pz78acteDrugTarget - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmcteDrugTarget + AS SELECT - d.DRUG_EXPOSURE_ID + d.DRUG_EXPOSURE_ID ,d.PERSON_ID ,c.CONCEPT_ID ,d.DRUG_TYPE_CONCEPT_ID @@ -2011,17 +1952,17 @@ SELECT ,c.CONCEPT_ID AS INGREDIENT_CONCEPT_ID FROM - [TARGET_CDMV5].[SCHEMA].DRUG_EXPOSURE d + [TARGET_CDMV5].[SCHEMA].DRUG_EXPOSURE d INNER JOIN [TARGET_CDMV5].[SCHEMA].CONCEPT_ANCESTOR ca ON ca.DESCENDANT_CONCEPT_ID = d.DRUG_CONCEPT_ID INNER JOIN [TARGET_CDMV5].[SCHEMA].CONCEPT c ON ca.ANCESTOR_CONCEPT_ID = c.CONCEPT_ID WHERE c.VOCABULARY_ID = 'RxNorm' - AND c.CONCEPT_CLASS_ID = 'Ingredient'; + AND c.CONCEPT_CLASS_ID = 'Ingredient' ; /* / */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acteEndDates'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acteEndDates'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcteEndDates'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcteEndDates'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2031,23 +1972,20 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78acteEndDates - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmcteEndDates + AS SELECT - PERSON_ID + PERSON_ID ,INGREDIENT_CONCEPT_ID ,( EVENT_DATE + - 30) AS END_DATE -- unpad the end date FROM - ( - SELECT E1.PERSON_ID + (SELECT E1.PERSON_ID ,E1.INGREDIENT_CONCEPT_ID ,E1.EVENT_DATE ,COALESCE(E1.START_ORDINAL, MAX(E2.START_ORDINAL)) START_ORDINAL ,E1.OVERALL_ORD - FROM ( - SELECT PERSON_ID + FROM (SELECT PERSON_ID ,INGREDIENT_CONCEPT_ID ,EVENT_DATE ,EVENT_TYPE @@ -2057,9 +1995,7 @@ FROM ,INGREDIENT_CONCEPT_ID ORDER BY EVENT_DATE ,EVENT_TYPE ) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date - FROM ( - -- select the start dates, assigning a row number to each - SELECT PERSON_ID + FROM (SELECT PERSON_ID ,INGREDIENT_CONCEPT_ID ,DRUG_EXPOSURE_START_DATE AS EVENT_DATE ,0 AS EVENT_TYPE @@ -2067,29 +2003,28 @@ FROM PARTITION BY PERSON_ID ,INGREDIENT_CONCEPT_ID ORDER BY DRUG_EXPOSURE_START_DATE ) AS START_ORDINAL - FROM ra2pz78acteDrugTarget + FROM g8iauhqmcteDrugTarget UNION ALL -- add the end dates with NULL as the row number, padding the end dates by 30 to allow a grace period for overlapping ranges. - SELECT PERSON_ID + SELECT PERSON_ID ,INGREDIENT_CONCEPT_ID ,( DRUG_EXPOSURE_END_DATE + 30) ,1 AS EVENT_TYPE ,NULL - FROM ra2pz78acteDrugTarget - ) RAWDATA - ) E1 - INNER JOIN ( - SELECT PERSON_ID + FROM g8iauhqmcteDrugTarget + ) RAWDATA + ) E1 + INNER JOIN (SELECT PERSON_ID ,INGREDIENT_CONCEPT_ID ,DRUG_EXPOSURE_START_DATE AS EVENT_DATE ,ROW_NUMBER() OVER ( PARTITION BY PERSON_ID ,INGREDIENT_CONCEPT_ID ORDER BY DRUG_EXPOSURE_START_DATE ) AS START_ORDINAL - FROM ra2pz78acteDrugTarget - ) E2 ON E1.PERSON_ID = E2.PERSON_ID + FROM g8iauhqmcteDrugTarget + ) E2 ON E1.PERSON_ID = E2.PERSON_ID AND E1.INGREDIENT_CONCEPT_ID = E2.INGREDIENT_CONCEPT_ID AND E2.EVENT_DATE <= E1.EVENT_DATE GROUP BY E1.PERSON_ID @@ -2097,14 +2032,14 @@ FROM ,E1.EVENT_DATE ,E1.START_ORDINAL ,E1.OVERALL_ORD - ) E - WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0; + ) E + WHERE 2 * E.START_ORDINAL - E.OVERALL_ORD = 0 ; /* / */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acteDrugExpEnds'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acteDrugExpEnds'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcteDrugExpEnds'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcteDrugExpEnds'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2114,30 +2049,29 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78acteDrugExpEnds - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmcteDrugExpEnds + AS SELECT - d.PERSON_ID + d.PERSON_ID ,d.INGREDIENT_CONCEPT_ID ,d.DRUG_TYPE_CONCEPT_ID ,d.DRUG_EXPOSURE_START_DATE ,MIN(e.END_DATE) AS ERA_END_DATE FROM - ra2pz78acteDrugTarget d -INNER JOIN ra2pz78acteEndDates e ON d.PERSON_ID = e.PERSON_ID + g8iauhqmcteDrugTarget d +INNER JOIN g8iauhqmcteEndDates e ON d.PERSON_ID = e.PERSON_ID AND d.INGREDIENT_CONCEPT_ID = e.INGREDIENT_CONCEPT_ID AND e.END_DATE >= d.DRUG_EXPOSURE_START_DATE GROUP BY d.PERSON_ID ,d.INGREDIENT_CONCEPT_ID ,d.DRUG_TYPE_CONCEPT_ID - ,d.DRUG_EXPOSURE_START_DATE; + ,d.DRUG_EXPOSURE_START_DATE ; /* / */ INSERT INTO [TARGET_CDMV5].[SCHEMA].drug_era -SELECT row_number() OVER ( +SELECT row_number() OVER ( ORDER BY person_id ) AS drug_era_id ,person_id @@ -2146,11 +2080,11 @@ SELECT row_number() OVER ( ,ERA_END_DATE ,COUNT(*) AS DRUG_EXPOSURE_COUNT ,30 AS gap_days -FROM ra2pz78acteDrugExpEnds + FROM g8iauhqmcteDrugExpEnds GROUP BY person_id ,INGREDIENT_CONCEPT_ID ,drug_type_concept_id - ,ERA_END_DATE; + ,ERA_END_DATE ; /**** @@ -2159,8 +2093,8 @@ Note: Eras derived from CONDITION_OCCURRENCE table, using 30d gap ****/ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acondition_era_phase_1'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acondition_era_phase_1'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcondition_era_phase_1'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcondition_era_phase_1'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2171,8 +2105,8 @@ END; /* / */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acteConditionTarget'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acteConditionTarget'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcteConditionTarget'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcteConditionTarget'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2183,23 +2117,22 @@ END; /* / */ -- create base eras from the concepts found in condition_occurrence -CREATE GLOBAL TEMPORARY TABLE ra2pz78acteConditionTarget - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmcteConditionTarget + AS SELECT - co.PERSON_ID + co.PERSON_ID ,co.condition_concept_id ,co.CONDITION_START_DATE ,COALESCE(co.CONDITION_END_DATE, ( CONDITION_START_DATE + 1)) AS CONDITION_END_DATE FROM - [TARGET_CDMV5].[SCHEMA].CONDITION_OCCURRENCE co; + [TARGET_CDMV5].[SCHEMA].CONDITION_OCCURRENCE co ; /* / */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acteCondEndDates'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acteCondEndDates'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcteCondEndDates'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcteCondEndDates'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2209,23 +2142,20 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78acteCondEndDates - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmcteCondEndDates + AS SELECT - PERSON_ID + PERSON_ID ,CONDITION_CONCEPT_ID ,( EVENT_DATE + - 30) AS END_DATE -- unpad the end date FROM - ( - SELECT E1.PERSON_ID + (SELECT E1.PERSON_ID ,E1.CONDITION_CONCEPT_ID ,E1.EVENT_DATE ,COALESCE(E1.START_ORDINAL, MAX(E2.START_ORDINAL)) START_ORDINAL ,E1.OVERALL_ORD - FROM ( - SELECT PERSON_ID + FROM (SELECT PERSON_ID ,CONDITION_CONCEPT_ID ,EVENT_DATE ,EVENT_TYPE @@ -2235,9 +2165,7 @@ FROM ,CONDITION_CONCEPT_ID ORDER BY EVENT_DATE ,EVENT_TYPE ) AS OVERALL_ORD -- this re-numbers the inner UNION so all rows are numbered ordered by the event date - FROM ( - -- select the start dates, assigning a row number to each - SELECT PERSON_ID + FROM (SELECT PERSON_ID ,CONDITION_CONCEPT_ID ,CONDITION_START_DATE AS EVENT_DATE ,- 1 AS EVENT_TYPE @@ -2245,29 +2173,28 @@ FROM PARTITION BY PERSON_ID ,CONDITION_CONCEPT_ID ORDER BY CONDITION_START_DATE ) AS START_ORDINAL - FROM ra2pz78acteConditionTarget + FROM g8iauhqmcteConditionTarget UNION ALL -- pad the end dates by 30 to allow a grace period for overlapping ranges. - SELECT PERSON_ID + SELECT PERSON_ID ,CONDITION_CONCEPT_ID ,( CONDITION_END_DATE + 30) ,1 AS EVENT_TYPE ,NULL - FROM ra2pz78acteConditionTarget - ) RAWDATA - ) E1 - INNER JOIN ( - SELECT PERSON_ID + FROM g8iauhqmcteConditionTarget + ) RAWDATA + ) E1 + INNER JOIN (SELECT PERSON_ID ,CONDITION_CONCEPT_ID ,CONDITION_START_DATE AS EVENT_DATE ,ROW_NUMBER() OVER ( PARTITION BY PERSON_ID ,CONDITION_CONCEPT_ID ORDER BY CONDITION_START_DATE ) AS START_ORDINAL - FROM ra2pz78acteConditionTarget - ) E2 ON E1.PERSON_ID = E2.PERSON_ID + FROM g8iauhqmcteConditionTarget + ) E2 ON E1.PERSON_ID = E2.PERSON_ID AND E1.CONDITION_CONCEPT_ID = E2.CONDITION_CONCEPT_ID AND E2.EVENT_DATE <= E1.EVENT_DATE GROUP BY E1.PERSON_ID @@ -2275,14 +2202,14 @@ FROM ,E1.EVENT_DATE ,E1.START_ORDINAL ,E1.OVERALL_ORD - ) E - WHERE (2 * E.START_ORDINAL) - E.OVERALL_ORD = 0; + ) E + WHERE (2 * E.START_ORDINAL) - E.OVERALL_ORD = 0 ; /* / */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78acteConditionEnds'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78acteConditionEnds'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmcteConditionEnds'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmcteConditionEnds'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2292,23 +2219,22 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78acteConditionEnds - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmcteConditionEnds + AS SELECT - c.PERSON_ID + c.PERSON_ID ,c.CONDITION_CONCEPT_ID ,c.CONDITION_START_DATE ,MIN(e.END_DATE) AS ERA_END_DATE FROM - ra2pz78acteConditionTarget c -INNER JOIN ra2pz78acteCondEndDates e ON c.PERSON_ID = e.PERSON_ID + g8iauhqmcteConditionTarget c +INNER JOIN g8iauhqmcteCondEndDates e ON c.PERSON_ID = e.PERSON_ID AND c.CONDITION_CONCEPT_ID = e.CONDITION_CONCEPT_ID AND e.END_DATE >= c.CONDITION_START_DATE GROUP BY c.PERSON_ID ,c.CONDITION_CONCEPT_ID - ,c.CONDITION_START_DATE; + ,c.CONDITION_START_DATE ; /* / */ @@ -2320,7 +2246,7 @@ INSERT INTO [TARGET_CDMV5].[SCHEMA].condition_era ( ,condition_era_end_date ,condition_occurrence_count ) -SELECT row_number() OVER ( +SELECT row_number() OVER ( ORDER BY person_id ) AS condition_era_id ,person_id @@ -2328,10 +2254,10 @@ SELECT row_number() OVER ( ,min(CONDITION_START_DATE) AS CONDITION_ERA_START_DATE ,ERA_END_DATE AS CONDITION_ERA_END_DATE ,COUNT(*) AS CONDITION_OCCURRENCE_COUNT -FROM ra2pz78acteConditionEnds + FROM g8iauhqmcteConditionEnds GROUP BY person_id ,CONDITION_CONCEPT_ID - ,ERA_END_DATE; + ,ERA_END_DATE ; /**** @@ -2343,8 +2269,8 @@ Note: These queries are used to provide some basic stats around row counts betwe ****/ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78av5_stats'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78av5_stats'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmv5_stats'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmv5_stats'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2355,8 +2281,8 @@ END; /* / */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78av4_stats'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78av4_stats'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmv4_stats'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmv4_stats'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2367,16 +2293,14 @@ END; /* / */ -- Get the row counts for each table that is in scope for the migration -CREATE GLOBAL TEMPORARY TABLE ra2pz78av4_stats - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmv4_stats + AS SELECT - * + * FROM - -( - SELECT '[SOURCE_CDMV4]' AS DBName, 'care_site' AS TableName, COUNT(*) as row_count FROM [SOURCE_CDMV4].[SCHEMA].care_site + +(SELECT '[SOURCE_CDMV4]' AS DBName, 'care_site' AS TableName, COUNT(*) as row_count FROM [SOURCE_CDMV4].[SCHEMA].care_site UNION SELECT '[SOURCE_CDMV4]' AS DBName, 'condition_era' AS TableName, COUNT(*) as row_count FROM [SOURCE_CDMV4].[SCHEMA].condition_era UNION @@ -2406,21 +2330,19 @@ FROM UNION SELECT '[SOURCE_CDMV4]' AS DBName, 'provider' AS TableName, COUNT(*) as row_count FROM [SOURCE_CDMV4].[SCHEMA].provider UNION - SELECT '[SOURCE_CDMV4]' AS DBName, 'visit_occurrence' AS TableName, COUNT(*) as row_count FROM [SOURCE_CDMV4].[SCHEMA].visit_occurrence -) v4_stats; + SELECT '[SOURCE_CDMV4]' AS DBName, 'visit_occurrence' AS TableName, COUNT(*) as row_count FROM [SOURCE_CDMV4].[SCHEMA].visit_occurrence + ) v4_stats ; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78av5_stats - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmv5_stats + AS SELECT - * + * FROM - -( - SELECT '[TARGET_CDMV5]' AS DBName, 'care_site' AS TableName, COUNT(*) as row_count FROM [TARGET_CDMV5].[SCHEMA].care_site + +(SELECT '[TARGET_CDMV5]' AS DBName, 'care_site' AS TableName, COUNT(*) as row_count FROM [TARGET_CDMV5].[SCHEMA].care_site UNION SELECT '[TARGET_CDMV5]' AS DBName, 'condition_era' AS TableName, COUNT(*) as row_count FROM [TARGET_CDMV5].[SCHEMA].condition_era UNION @@ -2454,13 +2376,13 @@ FROM UNION SELECT '[TARGET_CDMV5]' AS DBName, 'provider' AS TableName, COUNT(*) as row_count FROM [TARGET_CDMV5].[SCHEMA].provider UNION - SELECT '[TARGET_CDMV5]' AS DBName, 'visit_occurrence' AS TableName, COUNT(*) as row_count FROM [TARGET_CDMV5].[SCHEMA].visit_occurrence -) v5_stats; + SELECT '[TARGET_CDMV5]' AS DBName, 'visit_occurrence' AS TableName, COUNT(*) as row_count FROM [TARGET_CDMV5].[SCHEMA].visit_occurrence + ) v5_stats ; /* / */ -- Show the results -select +SELECT 'Rowcounts for each database and table', NVL(V4.DBName, 'None') v4_database_name, v4.TableName v4_table_name, @@ -2469,17 +2391,17 @@ select v5.TableName v5_table_name, v5.row_count v5_row_count, NVL(v5.row_count, 0) - NVL(v4.row_count, 0) row_count_change -from ra2pz78av4_stats v4 -full outer join ra2pz78av5_stats v5 ON v4.TableName = v5.TableName -order by v5.TableName; + FROM g8iauhqmv4_stats v4 +full outer join g8iauhqmv5_stats v5 ON v4.TableName = v5.TableName +order by v5.TableName ; /* * Determine how the vocabulary/domains helped to map from the V4 source * tables to the V5 destinations */ BEGIN - EXECUTE IMMEDIATE 'TRUNCATE TABLE ra2pz78aclassification_map'; - EXECUTE IMMEDIATE 'DROP TABLE ra2pz78aclassification_map'; + EXECUTE IMMEDIATE 'TRUNCATE TABLE g8iauhqmclassification_map'; + EXECUTE IMMEDIATE 'DROP TABLE g8iauhqmclassification_map'; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN @@ -2489,44 +2411,42 @@ END; /* / */ -CREATE GLOBAL TEMPORARY TABLE ra2pz78aclassification_map - ON COMMIT PRESERVE ROWS -AS +CREATE TABLE g8iauhqmclassification_map + AS SELECT - * + * FROM - -( - SELECT 'Condition_Occurrence' TableName, NVL(LOWER(cm.domain_id), 'condition') domain_id, COUNT(*) row_count + +(SELECT 'Condition_Occurrence' TableName, NVL(LOWER(cm.domain_id), 'condition') domain_id, COUNT(*) row_count FROM [SOURCE_CDMV4].[SCHEMA].Condition_Occurrence CO - LEFT JOIN ra2pz78aconcept_map CM ON co.condition_concept_id = cm.source_concept_id + LEFT JOIN g8iauhqmconcept_map CM ON co.condition_concept_id = cm.source_concept_id GROUP BY NVL(LOWER(cm.domain_id), 'condition') UNION SELECT 'Drug_Exposure' TableName, NVL(LOWER(cm.domain_id), 'drug') domain_id, COUNT(*) row_count FROM [SOURCE_CDMV4].[SCHEMA].Drug_Exposure de - LEFT JOIN ra2pz78aconcept_map CM ON de.drug_concept_id = cm.source_concept_id + LEFT JOIN g8iauhqmconcept_map CM ON de.drug_concept_id = cm.source_concept_id GROUP BY NVL(LOWER(cm.domain_id), 'drug') UNION SELECT 'Observation' TableName, NVL(LOWER(cm.domain_id), 'observation') domain_id, COUNT(*) row_count FROM [SOURCE_CDMV4].[SCHEMA].Observation o - LEFT JOIN ra2pz78aconcept_map CM ON o.observation_concept_id = cm.source_concept_id + LEFT JOIN g8iauhqmconcept_map CM ON o.observation_concept_id = cm.source_concept_id GROUP BY NVL(LOWER(cm.domain_id), 'observation') UNION - SELECT 'Procedure_Occurrence' TableName, NVL(LOWER(cm.domain_id), 'procedure') domain_id, COUNT(*) row_count - FROM [SOURCE_CDMV4].[SCHEMA].Procedure_Occurrence po - LEFT JOIN ra2pz78aconcept_map CM ON po.PROCEDURE_CONCEPT_ID = cm.source_concept_id + SELECT 'Procedure_Occurrence' TableName, NVL(LOWER(cm.domain_id), 'procedure') domain_id, COUNT(*) row_count + FROM [SOURCE_CDMV4].[SCHEMA].Procedure_Occurrence po + LEFT JOIN g8iauhqmconcept_map CM ON po.PROCEDURE_CONCEPT_ID = cm.source_concept_id GROUP BY NVL(LOWER(cm.domain_id), 'procedure') -) A -ORDER by A.TableName, A.domain_id; + ) A +ORDER by A.TableName, A.domain_id ; /* / */ -select * -from ra2pz78aclassification_map -order by tablename, domain_id; +SELECT * + FROM g8iauhqmclassification_map +order by tablename, domain_id ; -select domain_id, SUM(row_count) -from ra2pz78aclassification_map +SELECT domain_id, SUM(row_count) + FROM g8iauhqmclassification_map group by domain_id -order by domain_id; \ No newline at end of file +order by domain_id ; \ No newline at end of file diff --git a/Version4 To Version5 Conversion/PostgreSQL/OMOP CDMv4 to CDMv5 - PostgreSQL.sql b/Version4 To Version5 Conversion/PostgreSQL/OMOP CDMv4 to CDMv5 - PostgreSQL.sql index 51198d5..db54431 100644 --- a/Version4 To Version5 Conversion/PostgreSQL/OMOP CDMv4 to CDMv5 - PostgreSQL.sql +++ b/Version4 To Version5 Conversion/PostgreSQL/OMOP CDMv4 to CDMv5 - PostgreSQL.sql @@ -486,7 +486,7 @@ SELECT person_id ,CAST(NULL AS INT) AS cause_source_concept_id FROM [SOURCE_CDMV4].[SCHEMA].DEATH LEFT JOIN concept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID - AND LOWER(DOMAIN_ID) IN ('death type'); + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept'); INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) SELECT 'DEATH: ' || CAST(NUM_INVALID_RECORDS AS VARCHAR) || ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' @@ -499,7 +499,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('death type') + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -600,7 +600,7 @@ INNER JOIN concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_co AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') LEFT JOIN concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -643,7 +643,7 @@ SELECT procedure_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE LEFT JOIN concept_map cm1 ON procedure_concept_id = cm1.source_concept_id LEFT JOIN concept_map cm2 ON procedure_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') WHERE procedure_concept_id <> 0 AND cm1.domain_id IS NULL @@ -691,7 +691,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') UNION ALL @@ -812,7 +812,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('procedure type') + AND LOWER(DOMAIN_ID) IN ('procedure type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -892,7 +892,7 @@ INNER JOIN concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_co AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') INNER JOIN concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -954,7 +954,7 @@ SELECT drug_exposure_id FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE LEFT JOIN concept_map cm1 ON drug_concept_id = cm1.source_concept_id LEFT JOIN concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') WHERE drug_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1019,7 +1019,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') UNION ALL @@ -1185,7 +1185,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('drug type') + AND LOWER(DOMAIN_ID) IN ('drug type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1216,7 +1216,7 @@ INNER JOIN concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_co AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1253,7 +1253,7 @@ SELECT condition_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE LEFT JOIN concept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id LEFT JOIN concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1296,7 +1296,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1384,7 +1384,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('condition type') + AND LOWER(DOMAIN_ID) IN ('condition type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1537,7 +1537,7 @@ FROM ( INNER JOIN concept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') LEFT JOIN concept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id - AND LOWER(cm1.domain_id) IN ('unit') + AND LOWER(cm2.domain_id) IN ('unit') UNION ALL diff --git a/Version4 To Version5 Conversion/Redshift/OMOP CDMv4 to CDMv5 - Redshift.sql b/Version4 To Version5 Conversion/Redshift/OMOP CDMv4 to CDMv5 - Redshift.sql index 6395c26..b132f2e 100644 --- a/Version4 To Version5 Conversion/Redshift/OMOP CDMv4 to CDMv5 - Redshift.sql +++ b/Version4 To Version5 Conversion/Redshift/OMOP CDMv4 to CDMv5 - Redshift.sql @@ -486,7 +486,7 @@ SELECT person_id ,CAST(NULL AS INT) AS cause_source_concept_id FROM [SOURCE_CDMV4].[SCHEMA].DEATH LEFT JOIN concept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID - AND LOWER(DOMAIN_ID) IN ('death type'); + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept'); INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) SELECT 'DEATH: ' || CAST(NUM_INVALID_RECORDS AS VARCHAR) || ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' @@ -499,7 +499,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('death type') + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -600,7 +600,7 @@ INNER JOIN concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_co AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') LEFT JOIN concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -643,7 +643,7 @@ SELECT procedure_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE LEFT JOIN concept_map cm1 ON procedure_concept_id = cm1.source_concept_id LEFT JOIN concept_map cm2 ON procedure_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') WHERE procedure_concept_id <> 0 AND cm1.domain_id IS NULL @@ -691,7 +691,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') UNION ALL @@ -812,7 +812,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('procedure type') + AND LOWER(DOMAIN_ID) IN ('procedure type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -892,7 +892,7 @@ INNER JOIN concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_co AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') INNER JOIN concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -954,7 +954,7 @@ SELECT drug_exposure_id FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE LEFT JOIN concept_map cm1 ON drug_concept_id = cm1.source_concept_id LEFT JOIN concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') WHERE drug_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1019,7 +1019,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') UNION ALL @@ -1185,7 +1185,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('drug type') + AND LOWER(DOMAIN_ID) IN ('drug type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1216,7 +1216,7 @@ INNER JOIN concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_co AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1253,7 +1253,7 @@ SELECT condition_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE LEFT JOIN concept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id LEFT JOIN concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1296,7 +1296,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1384,7 +1384,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('condition type') + AND LOWER(DOMAIN_ID) IN ('condition type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1537,7 +1537,7 @@ FROM ( INNER JOIN concept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') LEFT JOIN concept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id - AND LOWER(cm1.domain_id) IN ('unit') + AND LOWER(cm2.domain_id) IN ('unit') UNION ALL diff --git a/Version4 To Version5 Conversion/Sql Server PDW/OMOP CDMv4 to CDMv5 - Sql Server PDW.dsql b/Version4 To Version5 Conversion/Sql Server PDW/OMOP CDMv4 to CDMv5 - Sql Server PDW.dsql index cbe26c2..f351b4f 100644 --- a/Version4 To Version5 Conversion/Sql Server PDW/OMOP CDMv4 to CDMv5 - Sql Server PDW.dsql +++ b/Version4 To Version5 Conversion/Sql Server PDW/OMOP CDMv4 to CDMv5 - Sql Server PDW.dsql @@ -485,7 +485,7 @@ SELECT person_id ,CAST(NULL AS INT) AS cause_source_concept_id FROM [SOURCE_CDMV4].[SCHEMA].DEATH LEFT JOIN #concept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID - AND LOWER(DOMAIN_ID) IN ('death type'); + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept'); INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) SELECT 'DEATH: ' + CAST(NUM_INVALID_RECORDS AS VARCHAR) + ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' @@ -498,7 +498,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('death type') + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -597,7 +597,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') LEFT JOIN #concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -640,7 +640,7 @@ SELECT procedure_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE LEFT JOIN #concept_map cm1 ON procedure_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON procedure_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') WHERE procedure_concept_id <> 0 AND cm1.domain_id IS NULL @@ -688,7 +688,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') UNION ALL @@ -809,7 +809,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('procedure type') + AND LOWER(DOMAIN_ID) IN ('procedure type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -887,7 +887,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') INNER JOIN #concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -949,7 +949,7 @@ SELECT drug_exposure_id FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE LEFT JOIN #concept_map cm1 ON drug_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') WHERE drug_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1014,7 +1014,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') UNION ALL @@ -1180,7 +1180,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('drug type') + AND LOWER(DOMAIN_ID) IN ('drug type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1211,7 +1211,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1248,7 +1248,7 @@ SELECT condition_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE LEFT JOIN #concept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1291,7 +1291,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1379,7 +1379,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('condition type') + AND LOWER(DOMAIN_ID) IN ('condition type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1532,7 +1532,7 @@ FROM ( INNER JOIN #concept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') LEFT JOIN #concept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id - AND LOWER(cm1.domain_id) IN ('unit') + AND LOWER(cm2.domain_id) IN ('unit') UNION ALL diff --git a/Version4 To Version5 Conversion/Sql Server/OMOP CDMv4 to CDMv5 - SQL Server.sql b/Version4 To Version5 Conversion/Sql Server/OMOP CDMv4 to CDMv5 - SQL Server.sql index 3757a6e..31c4076 100644 --- a/Version4 To Version5 Conversion/Sql Server/OMOP CDMv4 to CDMv5 - SQL Server.sql +++ b/Version4 To Version5 Conversion/Sql Server/OMOP CDMv4 to CDMv5 - SQL Server.sql @@ -479,7 +479,7 @@ SELECT person_id ,CAST(NULL AS INT) AS cause_source_concept_id FROM [SOURCE_CDMV4].[SCHEMA].DEATH LEFT JOIN #concept_map_distinct cm1 ON DEATH.DEATH_TYPE_CONCEPT_ID = CM1.SOURCE_CONCEPT_ID - AND LOWER(DOMAIN_ID) IN ('death type'); + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept'); INSERT INTO [TARGET_CDMV5].[SCHEMA].ETL_WARNINGS (WARNING_MESSAGE) SELECT 'DEATH: ' + CAST(NUM_INVALID_RECORDS AS VARCHAR) + ' records in the source CDMv4 database have invalid DEATH_TYPE_CONCEPT_ID' @@ -492,7 +492,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('death type') + AND LOWER(DOMAIN_ID) IN ('death type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -589,7 +589,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') LEFT JOIN #concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -632,7 +632,7 @@ SELECT procedure_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].PROCEDURE_OCCURRENCE LEFT JOIN #concept_map cm1 ON procedure_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON procedure_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') WHERE procedure_concept_id <> 0 AND cm1.domain_id IS NULL @@ -680,7 +680,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON PROCEDURE_OCCURRENCE.PROCEDURE_TYPE_CONCEPT_ID = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('procedure type') + AND LOWER(cm2.domain_id) IN ('procedure type', 'Type Concept') UNION ALL @@ -801,7 +801,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('procedure type') + AND LOWER(DOMAIN_ID) IN ('procedure type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -877,7 +877,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') INNER JOIN #concept_map_distinct cmdis2 ON cm2.source_concept_id = cmdis2.source_concept_id AND cm2.domain_id = cmdis2.domain_id AND cmdis2.targetConceptCount = 1 @@ -939,7 +939,7 @@ SELECT drug_exposure_id FROM [SOURCE_CDMV4].[SCHEMA].DRUG_EXPOSURE LEFT JOIN #concept_map cm1 ON drug_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') WHERE drug_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1004,7 +1004,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON drug_exposure.drug_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('drug type') + AND LOWER(cm2.domain_id) IN ('drug type', 'Type Concept') UNION ALL @@ -1170,7 +1170,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('drug type') + AND LOWER(DOMAIN_ID) IN ('drug type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1201,7 +1201,7 @@ INNER JOIN #concept_map_distinct cmdis ON cm1.source_concept_id = cmdis.source_c AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount = 1 LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1238,7 +1238,7 @@ SELECT condition_occurrence_id FROM [SOURCE_CDMV4].[SCHEMA].CONDITION_OCCURRENCE LEFT JOIN #concept_map cm1 ON condition_occurrence.condition_concept_id = cm1.source_concept_id LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id <> 0 AND cm1.domain_id IS NULL @@ -1281,7 +1281,7 @@ FROM ( AND cm1.domain_id = cmdis.domain_id AND cmdis.targetConceptCount > 1 LEFT JOIN #concept_map cm2 ON condition_occurrence.condition_type_concept_id = cm2.source_concept_id - AND LOWER(cm2.domain_id) IN ('condition type') + AND LOWER(cm2.domain_id) IN ('condition type', 'Type Concept') WHERE condition_concept_id > 0 -- This condition will map those concepts that were mapped to valid concepts in V4 UNION ALL @@ -1369,7 +1369,7 @@ FROM ( WHERE CONCEPT_ID = 0 OR ( STANDARD_CONCEPT = 'S' - AND LOWER(DOMAIN_ID) IN ('condition type') + AND LOWER(DOMAIN_ID) IN ('condition type', 'Type Concept') ) ) HAVING COUNT(PERSON_ID) > 0 @@ -1522,7 +1522,7 @@ FROM ( INNER JOIN #concept_map cm1 ON observation.observation_concept_id = cm1.source_concept_id AND LOWER(cm1.domain_id) IN ('measurement') LEFT JOIN #concept_map cm2 ON observation.unit_concept_id = cm2.source_concept_id - AND LOWER(cm1.domain_id) IN ('unit') + AND LOWER(cm2.domain_id) IN ('unit') UNION ALL