From 8cb7e038971434d41af619831b4988b226a62ef0 Mon Sep 17 00:00:00 2001 From: Raymond Rusk Date: Wed, 22 Mar 2017 06:40:35 -0700 Subject: [PATCH] Fix for NullPointerExceptin and org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying --- .../i2b2/crc/dao/pdo/PdoQueryEidDao.java | 20 +++++++++++++------ .../i2b2/crc/dao/pdo/PdoQueryPatientDao.java | 20 +++++++++++++------ .../i2b2/crc/dao/pdo/PdoQueryPidDao.java | 20 +++++++++++++------ .../i2b2/crc/dao/pdo/PdoQueryVisitDao.java | 20 +++++++++++++------ .../crc/dao/pdo/TablePdoQueryPatientDao.java | 20 +++++++++++++------ .../dao/pdo/input/PatientListTypeHandler.java | 8 ++++++-- .../SQLServerFactRelatedQueryHandler.java | 3 ++- 7 files changed, 78 insertions(+), 33 deletions(-) diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryEidDao.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryEidDao.java index 031631cf..9de55889 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryEidDao.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryEidDao.java @@ -116,9 +116,13 @@ public EidSet getEidByEncounterNum(List encounterNumList, String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "encounter_mapping em WHERE em.encounter_num IN (select distinct char_param1 FROM " - + SQLServerFactRelatedQueryHandler.TEMP_PDO_INPUTLIST_TABLE + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "encounter_mapping em WHERE em.encounter_num IN (select distinct CAST (char_param1 AS INTEGER) FROM "; + } else { + finalSql += "encounter_mapping em WHERE em.encounter_num IN (select distinct char_param1 FROM "; + } + finalSql += SQLServerFactRelatedQueryHandler.TEMP_PDO_INPUTLIST_TABLE + ") order by em_encounter_num"; log.debug("Size of the encounter list " + encounterNumList.size()); @@ -532,9 +536,13 @@ public EidSet getEidByFact(List panelSqlList, + selectClause + " FROM " + getDbSchemaName() - + "encounter_mapping em " - + " where encounter_num in (select distinct char_param1 from " - + tempTable + ") order by encounter_num"; + + "encounter_mapping em "; + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += " where encounter_num in (select distinct CAST (char_param1 AS INTEGER) from "; + } else { + finalSql += " where encounter_num in (select distinct char_param1 from "; + } + finalSql += tempTable + ") order by encounter_num"; log.debug("Executing SQL [" + finalSql + "]"); System.out.println("Final Sql " + finalSql); diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPatientDao.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPatientDao.java index c1a7077e..65c1d165 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPatientDao.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPatientDao.java @@ -144,9 +144,13 @@ else if (dataSourceLookup.getServerType().equalsIgnoreCase( String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "patient_dimension patient WHERE patient.patient_num IN (select distinct char_param1 FROM " - + tempTableName + ") order by patient_num"; + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "patient_dimension patient WHERE patient.patient_num IN (select distinct CAST (char_param1 AS INTEGER) FROM "; + } else { + finalSql += "patient_dimension patient WHERE patient.patient_num IN (select distinct char_param1 FROM "; + } + finalSql += tempTableName + ") order by patient_num"; log.debug("Executing [" + finalSql + "]"); query = conn.prepareStatement(finalSql); @@ -475,9 +479,13 @@ public PatientSet getPatientByFact(List panelSqlList, String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "patient_dimension patient where patient_num in (select distinct char_param1 from " - + factTempTable + ") order by patient_num"; + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "patient_dimension patient where patient_num in (select distinct CAST (char_param1 AS INTEGER) from "; + } else { + finalSql += "patient_dimension patient where patient_num in (select distinct char_param1 from "; + } + finalSql += factTempTable + ") order by patient_num"; log.debug("Executing SQL [" + finalSql + "]"); diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPidDao.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPidDao.java index 7060fd44..67446b46 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPidDao.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryPidDao.java @@ -114,9 +114,13 @@ public PidSet getPidByPatientNum(List patientNumList, String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "patient_mapping pm WHERE pm.patient_num IN (select distinct char_param1 FROM " - + SQLServerFactRelatedQueryHandler.TEMP_PDO_INPUTLIST_TABLE + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "patient_mapping pm WHERE pm.patient_num IN (select distinct CAST (char_param1 AS INTEGER) FROM "; + } else { + finalSql += "patient_mapping pm WHERE pm.patient_num IN (select distinct char_param1 FROM "; + } + finalSql += SQLServerFactRelatedQueryHandler.TEMP_PDO_INPUTLIST_TABLE + ") order by pm_patient_num"; log.debug("Executing [" + finalSql + "]"); @@ -136,9 +140,13 @@ public PidSet getPidByPatientNum(List patientNumList, String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "patient_mapping pm WHERE pm.patient_num IN (select distinct char_param1 FROM " - + SQLServerFactRelatedQueryHandler.TEMP_PDO_INPUTLIST_TABLE.substring(1) + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "patient_mapping pm WHERE pm.patient_num IN (select distinct CAST( char_param1 AS INTEGER) FROM "; + } else { + finalSql += "patient_mapping pm WHERE pm.patient_num IN (select distinct char_param1 FROM "; + } + finalSql += SQLServerFactRelatedQueryHandler.TEMP_PDO_INPUTLIST_TABLE.substring(1) + ") order by pm_patient_num"; log.debug("Executing [" + finalSql + "]"); diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryVisitDao.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryVisitDao.java index 6f6e7cba..5a7ef807 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryVisitDao.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/PdoQueryVisitDao.java @@ -118,9 +118,13 @@ public EventSet getVisitsByEncounterNum(List encounterNumList, String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "visit_dimension visit WHERE visit.encounter_num IN (select distinct char_param1 FROM " - + tempTableName + ") order by encounter_num"; + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "visit_dimension visit WHERE visit.encounter_num IN (select distinct CAST (char_param1 AS INTEGER) FROM "; + } else { + finalSql += "visit_dimension visit WHERE visit.encounter_num IN (select distinct char_param1 FROM "; + } + finalSql += tempTableName + ") order by encounter_num"; log.debug("Executing [" + finalSql + "]"); query = conn.prepareStatement(finalSql); @@ -420,9 +424,13 @@ public EventSet getVisitByFact(List panelSqlList, String finalSql = "SELECT " + selectClause + " FROM " - + getDbSchemaName() - + "visit_dimension visit where encounter_num in (select distinct char_param1 from " - + factTempTable + ") order by encounter_num"; + + getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += "visit_dimension visit where encounter_num in (select distinct CAST (char_param1 AS INTEGER) from "; + } else { + finalSql += "visit_dimension visit where encounter_num in (select distinct char_param1 from "; + } + finalSql += factTempTable + ") order by encounter_num"; log.debug("Executing SQL [" + finalSql + "]"); System.out.println("Final Sql " + finalSql); diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/TablePdoQueryPatientDao.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/TablePdoQueryPatientDao.java index dbaac693..45b250b1 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/TablePdoQueryPatientDao.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/TablePdoQueryPatientDao.java @@ -140,9 +140,13 @@ public PatientSet getPatientByPatientNum(List patientNumList, + " FROM " + getDbSchemaName() + "patient_dimension patient " - + joinClause - + " WHERE patient.patient_num IN (select distinct char_param1 FROM " - + tempTableName + ") order by patient_num"; + + joinClause; + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += " WHERE patient.patient_num IN (select distinct CAST (char_param1 AS INTEGER) FROM "; + } else { + finalSql += " WHERE patient.patient_num IN (select distinct char_param1 FROM "; + } + finalSql += tempTableName + ") order by patient_num"; log.debug("Executing [" + finalSql + "]"); query = conn.prepareStatement(finalSql); @@ -585,9 +589,13 @@ public PatientSet getPatientByFact(List panelSqlList, + " FROM " + getDbSchemaName() + "patient_dimension patient " - + joinClause - + " where patient_num in (select distinct char_param1 from " - + factTempTable + ") order by patient_num"; + + joinClause; + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + finalSql += " where patient_num in (select distinct CAST (char_param1 AS INTEGER) from "; + } else { + finalSql += " where patient_num in (select distinct char_param1 from "; + } + finalSql += factTempTable + ") order by patient_num"; log.debug("Executing SQL [" + finalSql + "]"); diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/PatientListTypeHandler.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/PatientListTypeHandler.java index 8f0b487e..e8d86b9d 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/PatientListTypeHandler.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/PatientListTypeHandler.java @@ -178,8 +178,12 @@ public String generateWhereClauseSql() { // set sql string sqlString = "select pset.patient_num from " - + this.getDbSchemaName() - + "qt_patient_set_collection pset where pset.result_instance_id = ? "; + + this.getDbSchemaName(); + if (dataSourceLookup.getServerType().equalsIgnoreCase(DAOFactoryHelper.POSTGRESQL)) { + sqlString += "qt_patient_set_collection pset where pset.result_instance_id = CAST ( ? AS INTEGER) "; + } else { + sqlString += "qt_patient_set_collection pset where pset.result_instance_id = ? "; + } if (minIndex <= maxIndex) { sqlString += (" and pset.set_index between " + minIndex diff --git a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/SQLServerFactRelatedQueryHandler.java b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/SQLServerFactRelatedQueryHandler.java index d904aa51..6b04f8fa 100755 --- a/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/SQLServerFactRelatedQueryHandler.java +++ b/edu.harvard.i2b2.crc/src/server/edu/harvard/i2b2/crc/dao/pdo/input/SQLServerFactRelatedQueryHandler.java @@ -584,7 +584,8 @@ private String buildQueryCommon(PanelType panel, String pdoType) } - if (this.outputOptionList.getObservationSet().getSelectionfilter()!= null) + if (this.outputOptionList!=null && this.outputOptionList.getObservationSet()!=null && + this.outputOptionList.getObservationSet().getSelectionfilter()!= null) { //mainQuerySql = "with main_query as (" + mainQuerySql + ") select * from (select f1.*, " + String newMainQuerySql = "select * from (select f1.*, " +