diff --git a/grails-app/services/PlinkService.groovy b/grails-app/services/PlinkService.groovy index 6e07bea11..595877c55 100644 --- a/grails-app/services/PlinkService.groovy +++ b/grails-app/services/PlinkService.groovy @@ -67,7 +67,7 @@ class PlinkService { select a.platform_name, a.trial_name from DE_SUBJECT_SNP_DATASET a INNER JOIN de_subject_sample_mapping c on c.omic_patient_id=a.patient_num - INNER JOIN (SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ? AND patient_num IN + INNER JOIN (SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric) AND patient_num IN (SELECT patient_num FROM patient_dimension WHERE sourcesystem_cd NOT LIKE '%:S:%')) b on c.patient_id=b.patient_num where rownum=1 and a.platform_name is not null diff --git a/grails-app/services/PostgresI2b2HelperService.groovy b/grails-app/services/PostgresI2b2HelperService.groovy index 2a46a4871..e97ddd0d3 100644 --- a/grails-app/services/PostgresI2b2HelperService.groovy +++ b/grails-app/services/PostgresI2b2HelperService.groovy @@ -301,7 +301,7 @@ class PostgresI2b2HelperService { String sqlt="SELECT NVAL_NUM FROM OBSERVATION_FACT f WHERE CONCEPT_CD = '" + concept_cd + "' AND PATIENT_NUM IN (select distinct patient_num " + - "from qt_patient_set_collection where result_instance_id = " + result_instance_id + ")"; + "from qt_patient_set_collection where result_instance_id = CAST(" + result_instance_id + " AS numeric))"; log.debug("executing query: sqlt=" + sqlt); try { @@ -904,10 +904,10 @@ class PostgresI2b2HelperService { from qt_patient_set_collection q inner join patient_trial p on q.patient_num=p.patient_num - where q.result_instance_id="""; + where q.result_instance_id=CAST("""; - String sqlTemplate2 = """ or result_instance_id="""; - String sqlTemplate3 = """) and x.parent_cd="""; + String sqlTemplate2 = """ AS numeric) or result_instance_id=CAST("""; + String sqlTemplate3 = """ AS numeric)) and x.parent_cd="""; diff --git a/grails-app/services/com/recomdata/transmart/data/export/AdditionalDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/AdditionalDataService.groovy index 7493b4cd9..87af14d64 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/AdditionalDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/AdditionalDataService.groovy @@ -44,7 +44,7 @@ class AdditionalDataService { select distinct s.sample_cd from de_subject_sample_mapping s where s.trial_name in ${studies} and patient_id in ( SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd - WHERE sc.result_instance_id = ? AND sc.patient_num = pd.patient_num + WHERE sc.result_instance_id = CAST(? AS numeric) AND sc.patient_num = pd.patient_num ) and s.sample_cd is not null and b.file_name like s.sample_cd||'%' ) """ diff --git a/grails-app/services/com/recomdata/transmart/data/export/ClinicalDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/ClinicalDataService.groovy index 530bb38f7..d07dbd2d9 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/ClinicalDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/ClinicalDataService.groovy @@ -113,7 +113,7 @@ class ClinicalDataService { sqlQuery <<= "LEFT JOIN DEAPP.DE_SUBJECT_SAMPLE_MAPPING ssm ON ssm.PATIENT_ID = ofa.PATIENT_NUM " } - sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = ? AND ofa.MODIFIER_CD = ?" + sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) AND ofa.MODIFIER_CD = ?" if (!retrievalTypeMRNAExists && parFilterHighLevelConcepts) { sqlQuery <<= " AND cd.concept_cd NOT IN (SELECT DISTINCT NVL(sample_type_cd,'-1') as gene_expr_concept" @@ -432,7 +432,7 @@ class ClinicalDataService { queryToReturn <<= "INNER JOIN DE_XTRIAL_CHILD_MAP XMAP ON XMAP.CONCEPT_CD = ofa.CONCEPT_CD " queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C1 ON C1.CONCEPT_CD = XMAP.CONCEPT_CD " queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C2 ON C2.CONCEPT_CD = XMAP.PARENT_CD " - queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = ? " + queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) " queryToReturn <<= "AND ofa.MODIFIER_CD = ? " queryToReturn <<= "AND ofa.CONCEPT_CD IN " queryToReturn <<= "( " diff --git a/grails-app/services/com/recomdata/transmart/data/export/DataCountService.groovy b/grails-app/services/com/recomdata/transmart/data/export/DataCountService.groovy index 2f1c43af0..c9e7ce5d7 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/DataCountService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/DataCountService.groovy @@ -47,7 +47,7 @@ class DataCountService { StringBuilder subjectsFromBothSubsetsQuery = new StringBuilder() StringBuilder gseaQuery = new StringBuilder() - subjectsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ?") + subjectsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric)") .append(" AND patient_num IN (select patient_num from patient_dimension where sourcesystem_cd not like '%:S:%')") subjectsFromBothSubsetsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id IN (") .append(resultInstanceIds).append(')') diff --git a/grails-app/services/com/recomdata/transmart/data/export/I2b2ExportHelperService.groovy b/grails-app/services/com/recomdata/transmart/data/export/I2b2ExportHelperService.groovy index b60786628..eb186025c 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/I2b2ExportHelperService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/I2b2ExportHelperService.groovy @@ -31,7 +31,7 @@ def findStudyAccessions( result_instance_ids){ def rids = [] for(r in result_instance_ids){ if(r?.trim()?.length()>0 ){ - rids.add(r); + rids.add('CAST('+ r + ' AS numeric)'); } } diff --git a/grails-app/services/com/recomdata/transmart/data/export/MetadataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/MetadataService.groovy index 08a2fed11..509f6bdac 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/MetadataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/MetadataService.groovy @@ -215,7 +215,7 @@ class MetadataService { select distinct s.sample_cd from de_subject_sample_mapping s where s.trial_name = ? and patient_id in ( SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd - WHERE sc.result_instance_id = ? AND sc.patient_num = pd.patient_num + WHERE sc.result_instance_id = CAST(? AS numeric) AND sc.patient_num = pd.patient_num ) and s.sample_cd is not null and b.file_name like s.sample_cd||'%' ) """ diff --git a/grails-app/services/com/recomdata/transmart/data/export/PostgresClinicalDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/PostgresClinicalDataService.groovy index 401ae9ca2..e7908e27d 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/PostgresClinicalDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/PostgresClinicalDataService.groovy @@ -113,7 +113,7 @@ class PostgresClinicalDataService { sqlQuery <<= "LEFT JOIN DE_SUBJECT_SAMPLE_MAPPING ssm ON ssm.PATIENT_ID = ofa.PATIENT_NUM " } - sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = ? AND ofa.MODIFIER_CD = ?" + sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) AND ofa.MODIFIER_CD = ?" if (!retrievalTypeMRNAExists && parFilterHighLevelConcepts) { sqlQuery <<= " AND cd.concept_cd NOT IN (SELECT DISTINCT coalesce(sample_type_cd,'-1') as gene_expr_concept" @@ -436,7 +436,7 @@ class PostgresClinicalDataService { queryToReturn <<= "INNER JOIN DE_XTRIAL_CHILD_MAP XMAP ON XMAP.CONCEPT_CD = ofa.CONCEPT_CD " queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C1 ON C1.CONCEPT_CD = XMAP.CONCEPT_CD " queryToReturn <<= "INNER JOIN CONCEPT_DIMENSION C2 ON C2.CONCEPT_CD = XMAP.PARENT_CD " - queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = ? " + queryToReturn <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) " queryToReturn <<= "AND ofa.MODIFIER_CD = ? " queryToReturn <<= "AND ofa.CONCEPT_CD IN " queryToReturn <<= "( " diff --git a/grails-app/services/com/recomdata/transmart/data/export/PostgresDataCountService.groovy b/grails-app/services/com/recomdata/transmart/data/export/PostgresDataCountService.groovy index f08f4eca5..109e54b56 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/PostgresDataCountService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/PostgresDataCountService.groovy @@ -48,7 +48,7 @@ class PostgresDataCountService { StringBuilder gseaQuery = new StringBuilder() subjectsQuery.append("select omic_patient_id from de_subject_sample_mapping where patient_id in ") - subjectsQuery.append("(SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ?") + subjectsQuery.append("(SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric)") .append(" AND patient_num IN (select patient_num from patient_dimension where sourcesystem_cd not like '%:S:%'))") subjectsFromBothSubsetsQuery.append("SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id IN (") diff --git a/grails-app/services/com/recomdata/transmart/data/export/PostgresExportService.groovy b/grails-app/services/com/recomdata/transmart/data/export/PostgresExportService.groovy index b67b3468d..a75211268 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/PostgresExportService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/PostgresExportService.groovy @@ -74,9 +74,9 @@ class PostgresExportService { def rID1 = RequestValidator.nullCheck(params.result_instance_id1) def rID2 = RequestValidator.nullCheck(params.result_instance_id2) def rIDs = null - if (rID1 && rID1?.trim() != '' && rID2 && rID2?.trim() != '') rIDs = rID1 + ',' + rID2 - else if (rID1 && rID1?.trim() != '') rIDs = rID1 - else if (rID2 && rID2?.trim() != '') rIDs = rID2 + if (rID1 && rID1?.trim() != '' && rID2 && rID2?.trim() != '') rIDs = 'CAST(' + rID1 + ' AS numeric), CAST(' + rID2 + 'AS numeric)' + else if (rID1 && rID1?.trim() != '') rIDs = 'CAST(' + rID1 + ' AS numeric)' + else if (rID2 && rID2?.trim() != '') rIDs = 'CAST(' + rID2 + ' AS numeric)' def subsetLen = (rID1 && rID2) ? 2 : (rID1 || rID2) ? 1 : 0 log.debug('rID1 :: ' + rID1 + ' :: rID2 :: ' + rID2) diff --git a/grails-app/services/com/recomdata/transmart/data/export/PostgresGeneExpressionDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/PostgresGeneExpressionDataService.groovy index b845e0753..a2e6c92ea 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/PostgresGeneExpressionDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/PostgresGeneExpressionDataService.groovy @@ -118,7 +118,7 @@ class PostgresGeneExpressionDataService { ssm.GPL_ID FROM de_subject_sample_mapping ssm - INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = ? AND ssm.patient_id = sc.patient_num + INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = CAST(? AS numeric) AND ssm.patient_id = sc.patient_num """); sQuery.append(" WHERE ssm.trial_name = '").append(study).append("' ") @@ -184,7 +184,7 @@ class PostgresGeneExpressionDataService { FROM de_subject_microarray_data a INNER JOIN de_mrna_annotation b ON a.probeset_id = b.probeset_id INNER JOIN de_subject_sample_mapping ssm ON ssm.assay_id = A.assay_id - INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = ? AND ssm.PATIENT_ID = sc.patient_num + INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id = CAST(? AS numeric) AND ssm.PATIENT_ID = sc.patient_num INNER JOIN PATIENT_DIMENSION pd on ssm.patient_id = pd.patient_num """) @@ -302,7 +302,7 @@ class PostgresGeneExpressionDataService { assayS.append(""" SELECT DISTINCT s.assay_id FROM de_subject_sample_mapping s, qt_patient_set_collection qt - WHERE qt.patient_num = s.patient_id AND qt.result_instance_id = ? """); + WHERE qt.patient_num = s.patient_id AND qt.result_instance_id = CAST(? AS numeric) """); //If we have a sample type, append it to the query. @@ -879,11 +879,11 @@ class PostgresGeneExpressionDataService { SELECT DISTINCT ssm.patient_id FROM de_subject_sample_mapping ssm INNER JOIN (SELECT DISTINCT patient_num FROM qt_patient_set_collection - WHERE result_instance_id = ? + WHERE result_instance_id = CAST(? AS numeric) INTERSECT SELECT DISTINCT patient_num FROM qt_patient_set_collection - WHERE result_instance_id = ?) sc ON ssm.patient_id = sc.patient_num + WHERE result_instance_id = CAST(? AS numeric)) sc ON ssm.patient_id = sc.patient_num """ groovy.sql.Sql sql = new groovy.sql.Sql(dataSource) def queryParams = [] @@ -1056,7 +1056,7 @@ class PostgresGeneExpressionDataService { def str = new StringBuffer() def mapValues = resultInstanceIdMap.values() mapValues.each { val -> - if (val && ((String)val)?.trim() != '') str.append(val).append(',') + if (val && ((String)val)?.trim() != '') str.append('CAST(').append(val).append(' AS numeric),') } str.delete(str.length()-1, str.length()) diff --git a/grails-app/services/com/recomdata/transmart/data/export/PostgresSnpDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/PostgresSnpDataService.groovy index 8dbb8368e..358f7c33c 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/PostgresSnpDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/PostgresSnpDataService.groovy @@ -83,7 +83,7 @@ class PostgresSnpDataService { WHERE platform = 'SNP' and patient_id in ( SELECT DISTINCT patient_num FROM qt_patient_set_collection - WHERE result_instance_id = ?) + WHERE result_instance_id = CAST(? AS numeric)) """ def patientDataMap = [:] sql.eachRow(query, [resultInstanceId]) { row -> @@ -194,7 +194,7 @@ class PostgresSnpDataService { INNER JOIN de_subject_sample_mapping dssm on ssd.patient_num=dssm.omic_patient_id WHERE dssm.patient_id IN (SELECT DISTINCT patient_num FROM qt_patient_set_collection - WHERE result_instance_id = ?)""" + WHERE result_instance_id = CAST(? AS numeric))""" def firstRow = sql.firstRow(platformQuery, [resultInstanceId]) def platformName = firstRow.title @@ -419,7 +419,7 @@ class PostgresSnpDataService { FROM bio_content b WHERE b.study_name in ${studies} AND b.file_name IN (SELECT DISTINCT sg.gsm_num FROM de_snp_calls_by_gsm sg WHERE sg.patient_num IN ( - SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ? + SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric) AND patient_num IN (SELECT patient_num FROM patient_dimension WHERE sourcesystem_cd NOT LIKE '%:S:%'))) """ @@ -473,7 +473,7 @@ class PostgresSnpDataService { //This from statement needs to be in all selects. sTables.append(""" FROM DE_SUBJECT_SAMPLE_MAPPING DSM INNER JOIN patient_dimension PD ON DSM.patient_id = PD.patient_num - INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = ? AND qt.PATIENT_NUM = DSM.PATIENT_ID + INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = CAST(? AS numeric) AND qt.PATIENT_NUM = DSM.PATIENT_ID LEFT JOIN DE_SNP_CALLS_BY_GSM SNP_GENO ON DSM.OMIC_PATIENT_ID = SNP_GENO.PATIENT_NUM AND DSM.SAMPLE_CD = SNP_GENO.GSM_NUM LEFT JOIN DE_SNP_COPY_NUMBER SNP_COPY ON DSM.OMIC_PATIENT_ID = SNP_COPY.PATIENT_NUM AND SNP_GENO.snp_name = SNP_COPY.snp_name INNER JOIN DE_SNP_GENE_MAP D2 ON D2.SNP_NAME = SNP_GENO.SNP_NAME diff --git a/grails-app/services/com/recomdata/transmart/data/export/SnpDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/SnpDataService.groovy index cb245bfb0..3ed65138b 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/SnpDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/SnpDataService.groovy @@ -83,7 +83,7 @@ class SnpDataService { WHERE platform = 'SNP' and patient_id in ( SELECT DISTINCT patient_num FROM qt_patient_set_collection - WHERE result_instance_id = ?) + WHERE result_instance_id = CAST(? AS numeric)) """ def patientDataMap = [:] sql.eachRow(query, [resultInstanceId]) { row -> @@ -194,7 +194,7 @@ class SnpDataService { INNER JOIN de_subject_sample_mapping dssm on ssd.patient_num=dssm.omic_patient_id WHERE dssm.patient_id IN (SELECT DISTINCT patient_num FROM qt_patient_set_collection - WHERE result_instance_id = ?)""" + WHERE result_instance_id = CAST(? AS numeric))""" def firstRow = sql.firstRow(platformQuery, [resultInstanceId]) def platformName = firstRow.title @@ -419,7 +419,7 @@ class SnpDataService { FROM bio_content b WHERE b.study_name in ${studies} AND b.file_name IN (SELECT DISTINCT sg.gsm_num FROM de_snp_calls_by_gsm sg WHERE sg.patient_num IN ( - SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = ? + SELECT DISTINCT patient_num FROM qt_patient_set_collection WHERE result_instance_id = CAST(? AS numeric) AND patient_num IN (SELECT patient_num FROM patient_dimension WHERE sourcesystem_cd NOT LIKE '%:S:%'))) """ @@ -473,7 +473,7 @@ class SnpDataService { //This from statement needs to be in all selects. sTables.append(""" FROM DE_SUBJECT_SAMPLE_MAPPING DSM INNER JOIN patient_dimension PD ON DSM.patient_id = PD.patient_num - INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = ? AND qt.PATIENT_NUM = DSM.PATIENT_ID + INNER JOIN qt_patient_set_collection qt ON qt.result_instance_id = CAST(? AS numeric) AND qt.PATIENT_NUM = DSM.PATIENT_ID INNER JOIN DE_SAMPLE_SNP_DATA SNP ON DSM.SAMPLE_CD = SNP.SAMPLE_ID INNER JOIN DE_SNP_GENE_MAP D2 ON D2.SNP_NAME = SNP.SNP_NAME INNER JOIN bio_marker bm ON bm.PRIMARY_EXTERNAL_ID = to_char(D2.ENTREZ_GENE_ID) diff --git a/grails-app/services/com/recomdata/transmart/data/export/VcfDataService.groovy b/grails-app/services/com/recomdata/transmart/data/export/VcfDataService.groovy index 61c854402..6d6ee1e6d 100644 --- a/grails-app/services/com/recomdata/transmart/data/export/VcfDataService.groovy +++ b/grails-app/services/com/recomdata/transmart/data/export/VcfDataService.groovy @@ -370,10 +370,10 @@ class VcfDataService { """; def param = [] if(resultInstanceId1!=null){ - param.add(resultInstanceId1) + param.add('CAST(' + resultInstanceId1 + '? AS numeric)') } if(resultInstanceId2!=null){ - param.add(resultInstanceId2) + param.add('CAST(' + resultInstanceId2 + '? AS numeric)') } groovy.sql.Sql sql = new groovy.sql.Sql(dataSource); @@ -399,7 +399,7 @@ class VcfDataService { def q = """ SELECT distinct a.DATASET_ID, a.SUBJECT_ID, a.POSITION from DE_VARIANT_SUBJECT_IDX a INNER JOIN de_subject_sample_mapping b on a.SUBJECT_ID = b.SUBJECT_ID - INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id in (?) AND b.patient_id = sc.patient_num + INNER JOIN qt_patient_set_collection sc ON sc.result_instance_id in (CAST(? AS numeric)) AND b.patient_id = sc.patient_num ORDER BY a.POSITION""" groovy.sql.Sql sql = new groovy.sql.Sql(dataSource); def datasetIdxMap =[:] diff --git a/src/groovy/com/recomdata/gex/GexDao.groovy b/src/groovy/com/recomdata/gex/GexDao.groovy index 3dd680160..fbc994217 100644 --- a/src/groovy/com/recomdata/gex/GexDao.groovy +++ b/src/groovy/com/recomdata/gex/GexDao.groovy @@ -135,7 +135,7 @@ public class GexDao { INNER JOIN search_keyword sk ON sk.bio_data_id = sbm.bio_marker_id INNER JOIN de_subject_sample_mapping ssm ON (ssm.trial_name = A.trial_name AND ssm.assay_id = A.assay_id) INNER JOIN (SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd - WHERE sc.result_instance_id = ? AND pd.sourcesystem_cd NOT LIKE '%:S:%' + WHERE sc.result_instance_id = CAST(? AS numeric) AND pd.sourcesystem_cd NOT LIKE '%:S:%' AND sc.patient_num = pd.patient_num) sub ON ssm.patient_id = sub.patient_num """); //TODO replace study within query as parameter to query @@ -190,7 +190,7 @@ public class GexDao { //SQL Query string. StringBuilder assayS = new StringBuilder("select distinct s.assay_id from de_subject_sample_mapping s"); assayS.append(", (SELECT DISTINCT sc.patient_num FROM qt_patient_set_collection sc, patient_dimension pd") - .append(" WHERE sc.result_instance_id = ? AND pd.sourcesystem_cd NOT LIKE '%:S:%'") + .append(" WHERE sc.result_instance_id = CAST(? AS numeric) AND pd.sourcesystem_cd NOT LIKE '%:S:%'") .append(" AND sc.patient_num = pd.patient_num) A where s.patient_id = A.patient_num"); //If we have a sample type, append it to the query. diff --git a/src/groovy/com/recomdata/i2b2/I2b2DAO.groovy b/src/groovy/com/recomdata/i2b2/I2b2DAO.groovy index e71252e0e..a0ad874fe 100644 --- a/src/groovy/com/recomdata/i2b2/I2b2DAO.groovy +++ b/src/groovy/com/recomdata/i2b2/I2b2DAO.groovy @@ -19,13 +19,13 @@ package com.recomdata.i2b2 - + import com.recomdata.dataexport.util.ExportUtil; import com.recomdata.transmart.data.export.util.FileWriterUtil; import com.sun.rowset.CachedRowSetImpl; -import java.sql.ResultSet -import java.sql.Statement +import java.sql.ResultSet +import java.sql.Statement import org.rosuda.REngine.REXP; import org.rosuda.REngine.Rserve.RConnection; @@ -34,45 +34,45 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger import org.codehaus.groovy.grails.commons.ApplicationHolder; import org.codehaus.groovy.grails.commons.ConfigurationHolder; - + /** * This class has been replaced with ClinicalDataService - */ -@Deprecated + */ +@Deprecated public class I2b2DAO { - ApplicationContext ctx = org.codehaus.groovy.grails.web.context.ServletContextHolder.getServletContext().getAttribute(org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes.APPLICATION_CONTEXT) - def dataSource = ctx.getBean('dataSource') - def i2b2HelperService = ctx.getBean('i2b2HelperService') + ApplicationContext ctx = org.codehaus.groovy.grails.web.context.ServletContextHolder.getServletContext().getAttribute(org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes.APPLICATION_CONTEXT) + def dataSource = ctx.getBean('dataSource') + def i2b2HelperService = ctx.getBean('i2b2HelperService') def springSecurityService = ctx.getBean('springSecurityService') Logger log = Logger.getLogger(getClass()) // log4j - - //This is the SQL query we use to get our data. - private StringBuilder sqlQuery = new StringBuilder(); - - //This is the list of parameters passed to the SQL statement. + + //This is the SQL query we use to get our data. + private StringBuilder sqlQuery = new StringBuilder(); + + //This is the list of parameters passed to the SQL statement. ArrayList parameterList = new ArrayList(); - def config = ConfigurationHolder.config - - boolean dataFound = false - - /** - * This method will gather data from the i2b2 database and write it to a file. The file will contain PATIENT_NUM,CONCEPT_PATH, The concept name and a subset. - * @param fileName Name of the data file. - * @param result_instance_ids A hashmap of the form ["subset1":result_instance_id] - * @param conceptCodeList An array of strings representing the concept codes to filter on. - * @return - */ + def config = ConfigurationHolder.config + + boolean dataFound = false + + /** + * This method will gather data from the i2b2 database and write it to a file. The file will contain PATIENT_NUM,CONCEPT_PATH, The concept name and a subset. + * @param fileName Name of the data file. + * @param result_instance_ids A hashmap of the form ["subset1":result_instance_id] + * @param conceptCodeList An array of strings representing the concept codes to filter on. + * @return + */ public void getData(String study, File studyDir, String fileName, String jobName, String resultInstanceId, String[] conceptCodeList, List retrievalTypes, boolean parPivotData, boolean parFilterHighLevelConcepts, Map snpFilesMap, String subset, Map filesDoneMap) { boolean retrievalTypeMRNAExists = retrievalTypeExists('MRNA', retrievalTypes) - boolean retrievalTypeSNPExists = retrievalTypeExists('SNP', retrievalTypes) - - if (null != resultInstanceId) { - //If the string isn't empty, we need a Union because we already have a subset in the query. - //Construct the SQL Query. + boolean retrievalTypeSNPExists = retrievalTypeExists('SNP', retrievalTypes) + + if (null != resultInstanceId) { + //If the string isn't empty, we need a Union because we already have a subset in the query. + //Construct the SQL Query. sqlQuery <<= "SELECT ofa.PATIENT_NUM, cd.CONCEPT_PATH, cd.CONCEPT_CD, cd.NAME_CHAR, " sqlQuery <<= "case ofa.VALTYPE_CD " sqlQuery <<= " WHEN 'T' THEN TVAL_CHAR " @@ -80,24 +80,24 @@ public class I2b2DAO { sqlQuery <<= "END VALUE, ? SUBSET " if (retrievalTypeMRNAExists && null != filesDoneMap['MRNA.TXT'] && filesDoneMap['MRNA.TXT']) { sqlQuery <<= ", ssm.assay_id, ssm.sample_type, ssm.timepoint, ssm.tissue_type " - } - sqlQuery <<= "FROM qt_patient_set_collection qt " - sqlQuery <<= "INNER JOIN OBSERVATION_FACT ofa ON qt.PATIENT_NUM = ofa.PATIENT_NUM " + } + sqlQuery <<= "FROM qt_patient_set_collection qt " + sqlQuery <<= "INNER JOIN OBSERVATION_FACT ofa ON qt.PATIENT_NUM = ofa.PATIENT_NUM " sqlQuery <<= "INNER JOIN CONCEPT_DIMENSION cd ON cd.CONCEPT_CD = ofa.CONCEPT_CD " if (retrievalTypeMRNAExists && null != filesDoneMap['MRNA.TXT'] && filesDoneMap['MRNA.TXT']) { sqlQuery <<= "INNER JOIN DE_SUBJECT_SAMPLE_MAPPING ssm ON ssm.PATIENT_ID = ofa.PATIENT_NUM " } - sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = ? AND ofa.MODIFIER_CD = ? " + sqlQuery <<= "WHERE qt.RESULT_INSTANCE_ID = CAST(? AS numeric) AND ofa.MODIFIER_CD = ? " if (!retrievalTypeMRNAExists && parFilterHighLevelConcepts) { sqlQuery <<= " AND cd.concept_cd NOT IN (SELECT DISTINCT sample_type_cd as gene_expr_concept FROM de_subject_sample_mapping WHERE trial_name = ?" sqlQuery <<= " UNION SELECT DISTINCT tissue_type_cd as gene_expr_concept FROM de_subject_sample_mapping WHERE trial_name = ?" sqlQuery <<= " UNION SELECT DISTINCT platform_cd as gene_expr_concept FROM de_subject_sample_mapping WHERE trial_name = ?)" } - - //Add the name of the subset to the parameter list. - parameterList.add(subset) - //Add the value of the result instance ID to the parameter list. + + //Add the name of the subset to the parameter list. + parameterList.add(subset) + //Add the value of the result instance ID to the parameter list. parameterList.add(resultInstanceId) //Add study to the parameter list. parameterList.add(study) @@ -105,33 +105,42 @@ public class I2b2DAO { parameterList.add(study) parameterList.add(study) parameterList.add(study) - } - - //If we have a list of concepts, add them to the query. - if(conceptCodeList.size() > 0) - { + } + + //If we have a list of concepts, add them to the query. + if(conceptCodeList.size() > 0) + { sqlQuery <<= " AND cd.CONCEPT_CD IN (" + quoteCSV(conceptCodeList.join(",")) + ") " //Add the concept list to the parameter list. - //parameterList.add(conceptCodeList.join(",")) - } + //parameterList.add(conceptCodeList.join(",")) + } } log.debug("Retrieving Clinical data : " + sqlQuery) log.debug("Retrieving Clinical data : " + parameterList) - //Only pivot the data if the parameter specifies it. if(parPivotData) { + //Only pivot the data if the parameter specifies it. + if(parPivotData) + { boolean mRNAExists = retrievalTypeMRNAExists && null != filesDoneMap['MRNA.TXT'] && filesDoneMap['MRNA.TXT'] - boolean snpExists = retrievalTypeSNPExists && null != filesDoneMap['SNP.PED, .MAP & .CNV'] && filesDoneMap['SNP.PED, .MAP & .CNV'] pivotData(writeData(studyDir, fileName, jobName, retrievalTypes, snpFilesMap), mRNAExists, snpExists) } else { writeData(studyDir, fileName, jobName, retrievalTypes) } } + boolean snpExists = retrievalTypeSNPExists && null != filesDoneMap['SNP.PED, .MAP & .CNV'] && filesDoneMap['SNP.PED, .MAP & .CNV'] + pivotData(writeData(studyDir, fileName, jobName, retrievalTypes, snpFilesMap), mRNAExists, snpExists) + } + else + { + writeData(studyDir, fileName, jobName, retrievalTypes) + } + } - private String writeData(File studyDir, String fileName, String jobName, List retrievalTypes, Map snpFilesMap = null) + private String writeData(File studyDir, String fileName, String jobName, List retrievalTypes, Map snpFilesMap = null) { //TODO Get the dataTypeName from the list of DataTypeNames either from DB or from config file def dataTypeName = "Clinical"; //TODO set this to either "Raw_Files/Findings" or NULL for processed_files - def dataTypeFolder = null; - //Build the query to get the clinical data. - groovy.sql.Sql sql = new groovy.sql.Sql(dataSource) + def dataTypeFolder = null; + //Build the query to get the clinical data. + groovy.sql.Sql sql = new groovy.sql.Sql(dataSource) def char separator = '\t'; def filePath = null FileWriterUtil writerUtil = null @@ -205,7 +214,7 @@ public class I2b2DAO { sql?.close() } - return filePath + return filePath } private void pivotData(String inputFileLoc, boolean mRNAExists, boolean snpExists) { @@ -255,7 +264,7 @@ public class I2b2DAO { return s.toString(); } - + def boolean retrievalTypeExists(String checkRetrievalType, List retrievalTypes) { boolean exists = false retrievalTypes.each { retrievalType -> @@ -294,10 +303,10 @@ public class I2b2DAO { if (null != snpFilesMap?.get('MAPFiles')) columnNames.add("SNP MAP File") } return columnNames - } - - def public boolean wasDataFound(){ - return dataFound - } - + } + + def public boolean wasDataFound(){ + return dataFound + } + } \ No newline at end of file