// Path: src/com/learningmodule/association/conceptdrug/ConceptDrugDatabaseInterface.java
// public interface ConceptDrugDatabaseInterface {
// 
// 	/*
// 	 * get name of file that will contain the prediction matrix generated by
// 	 * algorithm
// 	 */
// 	public String getMatrixFileName();
// 
// 	/*
// 	 * Method to get all the medical records containing encounterId(integer that
// 	 * represent an id for prescriptions written for a patient),
// 	 * ConceptId(integer that represent a diagnosis/diseases/observation for
// 	 * patient has been treated), DrugId(integer representing a drug that was
// 	 * written in the prescription)
// 	 */
// 	public LinkedList<EncounterIdConceptDrug> getData();
// 
// 	/*
// 	 * Method to get the medical records with given list of concepts Ids contaning encounterId, conceptId, DrugId,
// 	 * and feature related to medical records like age of patient, location of doctor/patient etc.
// 	 */
// 	
// 	public LinkedList<EncounterIdConceptFeaturesDrugModel> getDataByConceptIds(LinkedList<String> ids);
// 
// 	/*
// 	 * Method to get the list of conceptId and concept_name for given list of conceptId(integer)
// 	 */
// 	
// 	public LinkedList<ConceptNameModel> getConceptIdNameByConceptIds(LinkedList<String> conceptIds);
// 
// 	/*
// 	 * Method to get the list of Drugs for given drugIds(integers)
// 	 */
// 	public LinkedList<AbstractDrugModel> getDrugInfoByDrugIds(LinkedList<String> conceptIds);
// 
// 	/*
// 	 * Method to get the list of all conceptId and concept_words
// 	 */
// 	public LinkedList<ConceptWordModel> getConceptWords();
// }
// 
// Path: src/com/learningmodule/association/conceptdrug/model/EncounterIdConceptDrug.java
// public class EncounterIdConceptDrug {
// 	private int id;
// 	private String drug, conceptId;
// 	
// 	public EncounterIdConceptDrug(int id, String drug, String conceptId) {
// 		super();
// 		this.id = id;
// 		this.drug = drug;
// 		this.conceptId = conceptId;
// 	}
// 	
// 	public int getEncounterId() {
// 		return id;
// 	}
// 	public void setEncounterId(int id) {
// 		this.id = id;
// 	}
// 	
// 	public String getDrug() {
// 		return drug;
// 	}
// 	public void setDrug(String drug) {
// 		this.drug = drug;
// 	}
// 	public String getConceptId() {
// 		return conceptId;
// 	}
// 	public void setConceptId(String conceptId) {
// 		this.conceptId = conceptId;
// 	}
// }
// 
// Path: src/com/learningmodule/association/conceptdrug/model/PredictionMatrix.java
// public class PredictionMatrix implements Serializable {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	// Prediction matrix is a hastable with key as concept_id and value as
// 	// ConceptRow
// 	Hashtable<String, ConceptRow> rows;
// 
// 	public PredictionMatrix(int noOfConcepts) {
// 		rows = new Hashtable<String, ConceptRow>();
// 	}
// 
// 	/*
// 	 * method to get the list of drugs that are associated with a drugId
// 	 */
// 	public LinkedList<Cell> getDrugs(String conceptId) {
// 		// if conceptId is present in the hash table then get the list of drugs
// 		// related to it
// 		if (rows.containsKey(conceptId)) {
// 			return rows.get(conceptId).getDrugs();
// 		}
// 		return null;
// 	}
// 
// 	/*
// 	 * method to get all the concepts which are related to some drug
// 	 */
// 	public LinkedList<String> getNonEmptyConcepts() {
// 		Enumeration<String> temp = rows.keys();
// 		LinkedList<String> result = new LinkedList<String>();
// 		while (temp.hasMoreElements()) {
// 			String key = temp.nextElement();
// 			if (!getDrugs(key).isEmpty()) {
// 				result.add(key);
// 			}
// 		}
// 		return result;
// 	}
// 
// 	/*
// 	 * method to add a new cell to Prediction matrix
// 	 */
// 	public void addCell(String concept, String drug, double conf) {
// 		// if concept is already present in hast table put a new key value pair
// 		// with key as this concept
// 		if (!rows.containsKey(concept)) {
// 			rows.put(concept, new ConceptRow(concept));
// 		}
// 		// add the drug in conceptRow
// 		rows.get(concept).addCell(drug, conf);
// 	}
// 
// 	@Override
// 	public String toString() {
// 		String result = "";
// 		int count = 0;
// 		Enumeration<String> keys = rows.keys();
// 		while (keys.hasMoreElements()) {
// 			result = result + rows.get(keys.nextElement()).toString() + "\n";
// 			count++;
// 		}
// 		return result + count;
// 	}
// 
// }


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.LinkedList;
import org.apache.log4j.Logger;
import com.learningmodule.association.conceptdrug.ConceptDrugDatabaseInterface;
import com.learningmodule.association.conceptdrug.model.EncounterIdConceptDrug;
import com.learningmodule.association.conceptdrug.model.PredictionMatrix;

	/*
	 * method to save the results of association rules in a file
	 */
	public PredictionMatrix readResults() throws IOException {
		try {
			String path = PostProcessing.class.getResource("/").getFile();
			InputStream saveFile = new FileInputStream(path + "files/" + matrixFileName);
			ObjectInputStream restore = new ObjectInputStream(saveFile);
			resultMatrix = (PredictionMatrix) restore.readObject();
			restore.close();
			System.out.print("xxx");
			return resultMatrix;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.error(e);
		}
		return null;
	}

	/*
	 * method for learning from database
	 */
	public void learn(ConceptDrugDatabaseInterface learningInterface) {

		// get the pre-processed data
		// Instances instances =
		// PreProcessing.process(learningInterface.getData());
		LinkedList<EncounterIdConceptDrug> data = learningInterface.getData();
// Path: src/com/learningmodule/association/conceptdrug/ConceptDrugDatabaseInterface.java
// public interface ConceptDrugDatabaseInterface {
// 
// 	/*
// 	 * get name of file that will contain the prediction matrix generated by
// 	 * algorithm
// 	 */
// 	public String getMatrixFileName();
// 
// 	/*
// 	 * Method to get all the medical records containing encounterId(integer that
// 	 * represent an id for prescriptions written for a patient),
// 	 * ConceptId(integer that represent a diagnosis/diseases/observation for
// 	 * patient has been treated), DrugId(integer representing a drug that was
// 	 * written in the prescription)
// 	 */
// 	public LinkedList<EncounterIdConceptDrug> getData();
// 
// 	/*
// 	 * Method to get the medical records with given list of concepts Ids contaning encounterId, conceptId, DrugId,
// 	 * and feature related to medical records like age of patient, location of doctor/patient etc.
// 	 */
// 	
// 	public LinkedList<EncounterIdConceptFeaturesDrugModel> getDataByConceptIds(LinkedList<String> ids);
// 
// 	/*
// 	 * Method to get the list of conceptId and concept_name for given list of conceptId(integer)
// 	 */
// 	
// 	public LinkedList<ConceptNameModel> getConceptIdNameByConceptIds(LinkedList<String> conceptIds);
// 
// 	/*
// 	 * Method to get the list of Drugs for given drugIds(integers)
// 	 */
// 	public LinkedList<AbstractDrugModel> getDrugInfoByDrugIds(LinkedList<String> conceptIds);
// 
// 	/*
// 	 * Method to get the list of all conceptId and concept_words
// 	 */
// 	public LinkedList<ConceptWordModel> getConceptWords();
// }
// 
// Path: src/com/learningmodule/association/conceptdrug/model/EncounterIdConceptDrug.java
// public class EncounterIdConceptDrug {
// 	private int id;
// 	private String drug, conceptId;
// 	
// 	public EncounterIdConceptDrug(int id, String drug, String conceptId) {
// 		super();
// 		this.id = id;
// 		this.drug = drug;
// 		this.conceptId = conceptId;
// 	}
// 	
// 	public int getEncounterId() {
// 		return id;
// 	}
// 	public void setEncounterId(int id) {
// 		this.id = id;
// 	}
// 	
// 	public String getDrug() {
// 		return drug;
// 	}
// 	public void setDrug(String drug) {
// 		this.drug = drug;
// 	}
// 	public String getConceptId() {
// 		return conceptId;
// 	}
// 	public void setConceptId(String conceptId) {
// 		this.conceptId = conceptId;
// 	}
// }
// 
// Path: src/com/learningmodule/association/conceptdrug/model/PredictionMatrix.java
// public class PredictionMatrix implements Serializable {
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	// Prediction matrix is a hastable with key as concept_id and value as
// 	// ConceptRow
// 	Hashtable<String, ConceptRow> rows;
// 
// 	public PredictionMatrix(int noOfConcepts) {
// 		rows = new Hashtable<String, ConceptRow>();
// 	}
// 
// 	/*
// 	 * method to get the list of drugs that are associated with a drugId
// 	 */
// 	public LinkedList<Cell> getDrugs(String conceptId) {
// 		// if conceptId is present in the hash table then get the list of drugs
// 		// related to it
// 		if (rows.containsKey(conceptId)) {
// 			return rows.get(conceptId).getDrugs();
// 		}
// 		return null;
// 	}
// 
// 	/*
// 	 * method to get all the concepts which are related to some drug
// 	 */
// 	public LinkedList<String> getNonEmptyConcepts() {
// 		Enumeration<String> temp = rows.keys();
// 		LinkedList<String> result = new LinkedList<String>();
// 		while (temp.hasMoreElements()) {
// 			String key = temp.nextElement();
// 			if (!getDrugs(key).isEmpty()) {
// 				result.add(key);
// 			}
// 		}
// 		return result;
// 	}
// 
// 	/*
// 	 * method to add a new cell to Prediction matrix
// 	 */
// 	public void addCell(String concept, String drug, double conf) {
// 		// if concept is already present in hast table put a new key value pair
// 		// with key as this concept
// 		if (!rows.containsKey(concept)) {
// 			rows.put(concept, new ConceptRow(concept));
// 		}
// 		// add the drug in conceptRow
// 		rows.get(concept).addCell(drug, conf);
// 	}
// 
// 	@Override
// 	public String toString() {
// 		String result = "";
// 		int count = 0;
// 		Enumeration<String> keys = rows.keys();
// 		while (keys.hasMoreElements()) {
// 			result = result + rows.get(keys.nextElement()).toString() + "\n";
// 			count++;
// 		}
// 		return result + count;
// 	}
// 
// }


// Path: src/com/learningmodule/association/conceptdrug/learning/LearningMethod.java
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.util.LinkedList;
import org.apache.log4j.Logger;
import com.learningmodule.association.conceptdrug.ConceptDrugDatabaseInterface;
import com.learningmodule.association.conceptdrug.model.EncounterIdConceptDrug;
import com.learningmodule.association.conceptdrug.model.PredictionMatrix;


	/*
	 * method to save the results of association rules in a file
	 */
	public PredictionMatrix readResults() throws IOException {
		try {
			String path = PostProcessing.class.getResource("/").getFile();
			InputStream saveFile = new FileInputStream(path + "files/" + matrixFileName);
			ObjectInputStream restore = new ObjectInputStream(saveFile);
			resultMatrix = (PredictionMatrix) restore.readObject();
			restore.close();
			System.out.print("xxx");
			return resultMatrix;
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.error(e);
		}
		return null;
	}

	/*
	 * method for learning from database
	 */
	public void learn(ConceptDrugDatabaseInterface learningInterface) {

		// get the pre-processed data
		// Instances instances =
		// PreProcessing.process(learningInterface.getData());
		LinkedList<EncounterIdConceptDrug> data = learningInterface.getData();
		log.debug("Pre Processing Done");