rtmill / Data-Quality-Analysis

The PEDSnet Data Quality Assessment Toolkit (OMOP CDM)
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

add check to see if column is present, if not then skip #7

Open rtmill opened 5 years ago

rtmill commented 5 years ago

If a PEDSnet-specific column is not present, an error can be thrown.

example:

Failed to generate PERSON report, see dqa.log for more details. : Error: <SQL> 'SELECT "language_source_value", COUNT(*) AS "freq"
FROM dbo."person"
GROUP BY "language_source_value"'
  nanodbc/nanodbc.cpp:1587: 42S22: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'language_source_value'.

It's not the cleanest solution but you could take the column names into a vector and then check inclusion, closing each piece into if statements:

see: https://stackoverflow.com/questions/1169248/test-if-a-vector-contains-a-given-element

from:

  data_tbl <- cdm_tbl(req_env$db_src, table_name)
  ...
  field_name="language_source_value"
  df_table<-retrieve_dataframe_group(data_tbl, field_name)
  fileContent <-c(fileContent,paste("## Barplot for",field_name,"","\n"))
  describeNominalField(df_table,table_name,field_name)
  fileContent<-c(fileContent,paste_image_name(table_name,field_name));

to:

data_tbl <- cdm_tbl(req_env$db_src, table_name)
**columns_present <- some_get_columns_function()**
...
 #language Source Value
  field_name="language_source_value"
  **if( field_name %in% columns_present){**
     df_table<-retrieve_dataframe_group(data_tbl, field_name)
     fileContent <-c(fileContent,paste("## Barplot for",field_name,"","\n"))
     describeNominalField(df_table,table_name,field_name)
     fileContent<-c(fileContent,paste_image_name(table_name,field_name));
   **}**