* Populate maps from db
*/
public void populate() {
try {
DbHandler db = createDbHandler();
//Count nr of available languages
String query = "select ID, NAME from language";
ResultSet rs = db.executeQuery(query);
int lang = -1;
String langName = "";
while(rs.next()) {
lang = rs.getInt("ID");
langName = rs.getString("NAME");
languages.put(""+lang, new TreeMap());
if(debug) {
System.out.println("Populating DiagnoseHandler with language: "+langName+"("+lang+")");
}
}
int currentLanguage = -1;
for (Iterator it = languages.keySet().iterator() ; it.hasNext() ;) {
try {
String currentKey = (String)it.next();
currentLanguage = Integer.parseInt(currentKey);
} catch (NumberFormatException nfe) {
System.out.println("DiagnoseHandler: Can't use the found language id as an int"+nfe);
}
TreeMap languageGroups = (TreeMap)languages.get(""+currentLanguage);
if(debug) {
System.out.println("\tLooping for language: "+currentLanguage);
}
//Loop out all diagnosegroups for this language
Integer id = new Integer(-1);
query = "select ID, NAME, LANGUAGE, SORTORDER from diagnose_group WHERE STATUS=1 AND LANGUAGE="+currentLanguage+" ORDER BY SORTORDER";
rs = db.executeQuery(query);
while(rs.next()) {
id = new Integer(rs.getInt("ID"));
if(debug) {
System.out.println("Adding DiagnoseGroup: "+id+" ("+rs.getString("NAME")+")");
}
languageGroups.put(id, new DiagnoseGroup(id.intValue(), rs.getString("NAME"), rs.getInt("LANGUAGE"), rs.getInt("SORTORDER")));
}
//Get all diagnoses
query = "select DIAGNOSE.ID, DIAGNOSE.CODE, DIAGNOSE.NAME, DIAGNOSE.CODE, DIAGNOSE.LANGUAGE, DIAGNOSE.SORTORDER,DIAGNOSE_REL.DIAGNOSE_GROUP from diagnose, diagnose_rel where diagnose.ID=diagnose_rel.DIAGNOSE and diagnose.STATUS=1 and diagnose_rel.STATUS=1 AND diagnose.LANGUAGE="+currentLanguage+" ORDER BY diagnose.SORTORDER";
rs = db.executeQuery(query);
Integer groupId = new Integer(-1);
while(rs.next()) {
groupId = new Integer(rs.getInt("DIAGNOSE_REL.DIAGNOSE_GROUP"));
if(debug) {
System.out.println("\t\tAdding Diagnose to group: "+groupId);
}
((DiagnoseGroup)languageGroups.get(groupId)).addDiagnose(new Diagnose(rs.getInt("SORTORDER"), rs.getString("NAME")+(diagnoseCodeInName?" ["+rs.getString("CODE").trim()+"]":""), rs.getString("CODE").trim(), rs.getInt("LANGUAGE"), rs.getInt("SORTORDER")));
}
}
db.close();
} catch (DbHandlerException dbe) {
System.out.println("Can't load diagnosegroups because of: \n"+dbe.toString());
} catch (SQLException sqle) {
System.out.println("Can't load diagnosegroups because of: \n"+sqle.toString());
}