National-COVID-Cohort-Collaborative / Phenotype_Data_Acquisition

The repository for code and documentation produced by the N3C Phenotype and Data Acquisition workstream
60 stars 35 forks source link

Oracle OMOP Phenotype script - Change #4 DATEPART error #190

Closed kirenotneb closed 3 years ago

kirenotneb commented 3 years ago

The latest code is failing on the use of DATEPART in the following query, which seems related to change #4 listed above:

--PERSON
--OUTPUT_FILE: PERSON.csv
SELECT p.PERSON_ID,
   GENDER_CONCEPT_ID,
   NVL(YEAR_OF_BIRTH,DATEPART(year, birth_datetime )) as YEAR_OF_BIRTH,
   NVL(MONTH_OF_BIRTH,DATEPART(month, birth_datetime)) as MONTH_OF_BIRTH,
   RACE_CONCEPT_ID,
   ETHNICITY_CONCEPT_ID,
   LOCATION_ID,
   PROVIDER_ID,
   CARE_SITE_ID,
   PERSON_SOURCE_VALUE,
   GENDER_SOURCE_VALUE,
   RACE_SOURCE_VALUE,
   RACE_SOURCE_CONCEPT_ID,
   ETHNICITY_SOURCE_VALUE,
   ETHNICITY_SOURCE_CONCEPT_ID
  FROM RDW_OMOP.PERSON p
  JOIN RDW_OMOP_RESULTS.N3C_COHORT n
    ON p.PERSON_ID = n.PERSON_ID ;

The error is java.sql.SQLSyntaxErrorException: ORA-00904: "DATEPART": invalid identifier.

AdamLeeIT commented 3 years ago

Code corrected and committed, thank you for the report.

The code NVL(YEAR_OF_BIRTH,DATEPART(year, birth_datetime )) as YEAR_OF_BIRTH, NVL(MONTH_OF_BIRTH,DATEPART(month, birth_datetime)) as MONTH_OF_BIRTH, was changed to NVL(YEAR_OF_BIRTH,EXTRACT(year from birth_datetime )) as YEAR_OF_BIRTH, NVL(MONTH_OF_BIRTH,EXTRACT(month from birth_datetime)) as MONTH_OF_BIRTH,

Tested in Oracle 19c