2015-11-03 27 views
0

在這裏我附上我的代碼。當stateVector包含狀態名時,我需要檢查整個行,而不是所有的icd和dicd向量值。我需要怎麼做?如果結果集與整個行值匹配,如何獲取值?

在我的代碼中,它檢查所有向量,一旦statename與任何其他或icdid匹配顯示它可用。

public class LCDEdits 
{ 

@SuppressWarnings("unchecked") 
public String validateICD_CPT(String cptCode, String stateName, String icdCode) throws Exception 
{ 

    /**** Variable Initialization ***/ 
    String lcdRes = null; 
    StringBuffer lcdSql = null; 
// String error = null; 

    java.sql.Connection con = null; 
    java.sql.PreparedStatement poStmt1 = null;  
    DBConfig db1 = null; 
    ResultSet rs = null; 

    JSONObject JObj = new JSONObject(); 

    try 
    { 
     lcdSql = new StringBuffer(" SELECT cpt.hcpc_code, cpt.lcd_id, statepri.state_abbr, icd.icd10_id, "); 
     lcdSql.append(" dicd.icd10_id_dont FROM lcd_cpt cpt "); 
     lcdSql.append(" LEFT JOIN lcd_statepri statepri ON(cpt.lcd_id = statepri.lcd_id) ");    
     //lcdSql.append(" LEFT JOIN lcd_statesec statesec ON(cpt.lcd_id = statesec.lcd_id) "); 
     lcdSql.append(" LEFT JOIN lcd_icd_support icd ON(cpt.lcd_id = icd.lcd_id) "); 
     lcdSql.append(" LEFT JOIN lcd_icd_dont_support dicd ON(cpt.lcd_id = dicd.lcd_id) "); 
     lcdSql.append(" WHERE hcpc_code = ? "); 

     db1 = new DBConfig(); 
     con = db1.openConn(); 
     poStmt1 = con.prepareStatement(lcdSql.toString()); 

     poStmt1.setString(1, cptCode); 
     rs = poStmt1.executeQuery();     

     Vector<String> stateVector = new Vector<String>(); 
     Vector<String> icdVector = new Vector<String>(); 
     Vector<String> dicdVector = new Vector<String>(); 

     while(rs.next()) 
     {     
      stateVector.add(rs.getString("state_abbr")); 
     // icdVector.add(rs.getString("icd10_id")); 
     // dicdVector.add(rs.getString("icd10_id_dont")); 
      //stateVector.add(rs.getString("sec_state_abbr")); 


     } 


      if(stateVector.contains(stateName)) 
      { 
       if(icdVector.contains(icdCode)) 
       { 
       // String lcd_icd = lcd_Id; 
        lcdRes = "CPT-Code is Available in LCD Database."; 
       // lcdRes1 = "As for the LCD-Code " +lcd_icd+ ", the CPT-Code " + cptCode + " is supported the Diagnosis " +icdCode+ " in the state of " +stateName+ "."; 
       } 
       else if(dicdVector.contains(icdCode)) 
       { 
        lcdRes = "Medicare is not interest to pay Amount for this CPT-Code."; 
       // lcdRes1 = "As for the LCD-Code " +lcd_Id+ ", the CPT-Code " +cptCode+ " is not supported the Diagnosis " +icdCode+ " in the state of " +stateName+ "."; 
       } 
       else 
       { 
        lcdRes = "CPT-Code is not available in the LCD-Database."; 
       // lcdRes1 = "As for the LCD-Code " +lcd_Id+ ", the CPT-Code " +cptCode+ " is not applicable for the Diagnosis " +icdCode+ " in the state of " +stateName+ "."; 
       } 
      } 
      else 
      { 
      // String lcd_state = lcd_Id; 
       lcdRes = "State not matched with LCD-Code."; 
      // lcdRes1 = "As for the LCD-Code " +lcd_state+ ", the CPT-Code " +cptCode+ " is not applicable in the state of " +stateName+ "."; 
      } 

     JObj.put("status", "success"); 
     JObj.put("res_msg", lcdRes); 
    // JObj.put("dis_msg", lcdRes1); 
    } 
    catch(Exception ex) { 
     ex.printStackTrace(); 
     JObj.put("status", "failed");   
    } 
    finally { 
     rs.close(); 
     poStmt1.close(); 
     db1.closeConnection(con);   
    } 
    return JObj.toString(); 
} 
} 

回答

0

首先,將讀數從數據庫中分離出來並處理數據。

Vector stateVector = null; 

try { 
    Reading data from database 
} catch (the problems) { 
    And handle them 
} finally { 
    close the connection 
} 

然後檢查,如果你有一些數據:

if (stateVector != null { 
    // get the data you want, probably with a loop construct 
}