in ctakes-smoking-status/src/main/java/org/apache/ctakes/smokingstatus/patientLevel/PatientLevelSmokingStatus.java [66:224]
public static void collectCounts(String delim){
try {
FileReader fr = new FileReader(inputFile);
BufferedReader reader = new BufferedReader(fr);
String line = null;
try {
//Format of the input information to be processed:
//Example: docSet35_0106487312_12_200812_12_2008701
//docSet35 - is something that retrieval api assigns by default to output to a subset (in this case I think that is doc_link_id)
//01064873 - is the MCN
//12_12_2008 - this should have been the start date range(which it is not in this case because of programming error)
//12_12_2008 - this should have been the end date range (which is is not in this case because of programming error)
//The last n-digits is a sequential numbers.
boolean currentSmoker = false;
boolean nonSmoker = false;
boolean pastSmoker = false;
boolean smoker = false;
//collect the counts and fill the hash map
while ( (line = reader.readLine()) != null) {
if(line.length()<1) continue;
line = line.trim();
System.out.println("Line: " + line);
String[] parts = line.split(delim);
String[] parts1 = parts[0].split("_"); //0106487312
String clinicNumber = parts1[1].substring(0, 8);
System.out.println(parts[1]); //class label
if (parts[1].equals("PAST_SMOKER")){
pastSmoker = true;
System.out.println("past smoker doc");
}
if (parts[1].equals("NON_SMOKER")){
nonSmoker = true;
System.out.println("non smoker doc");
}
if (parts[1].equals("CURRENT_SMOKER")){
currentSmoker = true;
System.out.println("current smoker doc");
}
if (parts[1].equals("SMOKER")){
smoker = true;
System.out.println("smoker doc");
}
//if a new clinic number
if (!patientsStatuses.containsKey(clinicNumber)){
//create a vector for currentSmoker, nonSmoker, pastSmoker, and smoker values
Vector<Integer> smokingStatusElements = new Vector<Integer>(4);
if (currentSmoker == true){
//smokingStatusElements
smokingStatusElements.insertElementAt(1, 0);
smokingStatusElements.insertElementAt(0, 1);
smokingStatusElements.insertElementAt(0, 2);
smokingStatusElements.insertElementAt(0, 3);
System.out.println("incrementing current");
}
else if (nonSmoker == true){
smokingStatusElements.insertElementAt(0, 0);
smokingStatusElements.insertElementAt(1, 1);
smokingStatusElements.insertElementAt(0, 2);
smokingStatusElements.insertElementAt(0, 3);
System.out.println("incrementing non");
}
else if (pastSmoker == true){
//smokingStatusElements[0] = 0;
smokingStatusElements.insertElementAt(0, 0);
smokingStatusElements.insertElementAt(0, 1);
smokingStatusElements.insertElementAt(1, 2);
smokingStatusElements.insertElementAt(0, 3);
System.out.println("incrementing past");
//System.out.println("past smoker");
}
else if (smoker == true){
//smokingStatusElements[0] = 0;
smokingStatusElements.insertElementAt(0, 0);
smokingStatusElements.insertElementAt(0, 1);
smokingStatusElements.insertElementAt(0, 2);
smokingStatusElements.insertElementAt(1, 3);
System.out.println("incrementing past");
//System.out.println("past smoker");
}
//account for the UNKNOWN category
else {
smokingStatusElements.insertElementAt(0, 0);
smokingStatusElements.insertElementAt(0, 1);
smokingStatusElements.insertElementAt(0, 2);
smokingStatusElements.insertElementAt(0, 3);
}
//clinicNumber = parts1[0] + "_" + clinicNumber;
patientsStatuses.put(clinicNumber, smokingStatusElements);
}
//if an existing clinic number
else {
Vector<Integer> smokingStatusElements = (Vector<Integer>) patientsStatuses.get(clinicNumber);
//increment the respective smoking status
if (currentSmoker == true){
int currentValue = ((Integer) smokingStatusElements.elementAt(0)).intValue();
currentValue = currentValue + 1;
smokingStatusElements.setElementAt(currentValue, 0);
System.out.println("incrementing current: " + currentValue);
patientsStatuses.put(clinicNumber, smokingStatusElements);
}
else if (nonSmoker == true){
int currentValue = ((Integer) smokingStatusElements.elementAt(1)).intValue();
currentValue = currentValue + 1;
smokingStatusElements.setElementAt(currentValue, 1);
System.out.println("incrementing non: " + currentValue);
patientsStatuses.put(clinicNumber, smokingStatusElements);
}
else if (pastSmoker == true){
int currentValue = ((Integer) smokingStatusElements.elementAt(2)).intValue();
currentValue = currentValue + 1;
smokingStatusElements.setElementAt(currentValue, 2);
System.out.println("incrementing past: " + currentValue);
patientsStatuses.put(clinicNumber, smokingStatusElements);
}
else if (smoker == true){
int currentValue = ((Integer) smokingStatusElements.elementAt(3)).intValue();
currentValue = currentValue + 1;
smokingStatusElements.setElementAt(currentValue, 3);
System.out.println("incrementing smoker: " + currentValue);
patientsStatuses.put(clinicNumber, smokingStatusElements);
}
//account for the UNKNOWN category
else {
//do nothing
}
//patientsStatuses.put(clinicNumber, smokingStatusElements);
}
currentSmoker = false;
nonSmoker = false;
pastSmoker = false;
smoker = false;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
reader.close();
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}