ohdsi-studies / LegendT2dm

9 stars 16 forks source link

SQL error while running `assessPropensityModels()` #17

Open aki-nishimura opened 2 years ago

aki-nishimura commented 2 years ago

We have successfully run the phenotype assessment at Johns Hopkins, but are having troubles with the propensity model part. We get an SQL error while retrieving cohorts. Below is the content of errorReportSql.txt --- do you have insights as to where the "NA" in cohort_definition_id IN (NA, NA) is coming from?

DBMS:
sql server

Error:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'NA'.

SQL:
SELECT ROW_NUMBER() OVER (ORDER BY person_id, cohort_start_date) AS row_id,
    subject_id,

    cohort_definition_id,

    cohort_start_date,
    DATEDIFF(DAY, observation_period_start_date, cohort_start_date) AS days_from_obs_start,

        DATEDIFF(DAY, cohort_start_date, cohort_end_date)
     AS days_to_cohort_end,

        DATEDIFF(DAY, cohort_start_date, observation_period_end_date)
     AS days_to_obs_end,
    cohort_end_date
INTO #cohort_person
FROM (

    SELECT exposure_table.subject_id,

        cohort_definition_id,

        cohort_start_date,
        cohort_end_date
    FROM JHM_OMOP_20220203.Results.legendt2dm_study_class_sample_cohort exposure_table

            WHERE

        cohort_definition_id IN (NA, NA)

    ) raw_cohorts

INNER JOIN JHM_OMOP_20220203.dbo.observation_period
    ON subject_id = person_id
WHERE cohort_start_date <= observation_period_end_date
    AND cohort_start_date >= observation_period_start_date

R version:
R version 4.0.5 (2021-03-31)

Platform:
x86_64-pc-linux-gnu

Attached base packages:
- stats
- graphics
- grDevices
- utils
- datasets
- methods
- base

Other attached packages:
- LegendT2dm (1.0.2)
- DatabaseConnector (4.0.2)
msuchard commented 2 years ago

@aki-nishimura -- interesting. Those NA are probably coming from the R (as opposed to SQL) side since this is a a rendered snippet. I suspect there are no cohorts that meet some minimum requirement. I'll double the code and your cohort diagnostics shortly.

msuchard commented 2 years ago

JHM appears to only have one class of drugs with > 1,000 patients, so no comparisons are allowed here. I need to patch the code in assessPropensityModels to make this check as well.