// Path: src/org/drugepi/PharmacoepiTool.java
// public abstract class PharmacoepiTool {
// 	public static String description = "Pharamcoepi Toolbox";
// 	public static String version = "2.4.18";
// 	
// 	private long startTime;
// 	
// 	public PharmacoepiTool()
// 	{
// 		// not implemented
// 	}
// 		
// 	/**
// 	 * Add patient information, with patient data stored in a tab-delimited file.
// 	 * 
// 	 * @param filePath		Path of the patient data file.  See the documentation on each
// 	 * 						subclass for the expected order of patient columns.
// 	 * @throws Exception	
// 	 */
// 	public void addPatients(String filePath)
// 	throws Exception
// 	{		
// 		RowReader reader = new TabDelimitedFileReader(filePath);
// 		this.addPatients(reader);
// 
// 		// note: the implementing tool must close the reader
// 	}
// 	
// 	/**
// 	 * Add patient information, with patient data stored in a string buffer.
// 	 * 
// 	 * @param buf			Patient data.  See the documentation on each
// 	 * 						subclass for the expected order of patient columns.
// 	 * @throws Exception	
// 	 */
// 	public void addPatientsFromBuffer(String buf)
// 	throws Exception
// 	{		
// 		RowReader reader = new StringBufferRowReader(buf);
// 		this.addPatients(reader);
// 
// 		// note: the implementing tool must close the reader
// 	}
// 	
// 	/**
// 	 * Add patient information, with patient data stored in a database.
// 	 * 
// 	 * @param dbDriverClass	Name of the database driver.
// 	 * @param dbURL			JDBC URL of the database
// 	 * @param dbUser		Database user name.
// 	 * @param dbPassword	Database user's password.
// 	 * @param dbQuery		The query that will result in the patient data.  See the documentation on each
// 	 * 						subclass for the expected order of patient columns.
// 	 * @throws Exception
// 	 */
// 	public void addPatients(String dbDriverClass, String dbURL, String dbUser, String dbPassword,
// 			String dbQuery)
// 	throws Exception
// 	{
// 		RowReader reader = new DatabaseRowReader(dbDriverClass, dbURL, dbUser, dbPassword, dbQuery);
// 		this.addPatients(reader);
// 		
// 		// note: the implementing tool must close the reader
// 	}
// 	
// 	/**
// 	 * Add patient information from specified row reader object.
// 	 * 
// 	 * @param reader  The row reader object.
// 	 * @throws Exception
// 	 */
// 	public void addPatients(RowReader reader)
// 	throws Exception 
// 	{
// 		// do nothing.  override by subclass if desired.
// 	}
// 	 
// 	protected void startTool()
// 	{
//         System.out.printf("NOTE: %s version %s starting at %s.\n", 
//         		description, version, new Date().toString());
// 		this.startTime = System.currentTimeMillis();
// 	}
// 	
// 	protected void endTool()
// 	{
//         long eTime = System.currentTimeMillis() - startTime;
//         double minutes = Math.floor(eTime / (60 * 1000F));
//         eTime -= minutes * 60 * 1000F;
//         double seconds = eTime / 1000F;
//         System.out.printf("NOTE: %s finished at %s.  Run time: %02d:%02.3f.\n", 
//         		description, new Date().toString(), (int) minutes, seconds);
// 	}
// 
// 	/**
// 	 * @return the version
// 	 */
// 	public String getVersion() {
// 		return version;
// 	}
// 
// 	/**
// 	 * @return the description
// 	 */
// 	public String getDescription() {
// 		return description;
// 	}
// }
// 
// Path: src/org/drugepi/table/TableRowCol.java
// public enum RowColTypes { NORMAL, HEADER };


import java.io.*;
import java.util.*;
import org.apache.poi.ss.usermodel.*;
import org.drugepi.PharmacoepiTool;
import org.drugepi.table.TableRowCol.RowColTypes;
/* 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 
 */

package org.drugepi.table;



/**
 * Creation of basic tables for epidemiology.
 * 
 * Tables are added using the {@link #addTable(String, String)} method.  Rows and columns are then defined,
 * and values added to cells.  Tables are then rendered to HTML using {@link #writeHtmlToFile(String, String)}.
 * 
 * @author Jeremy A. Rassen
 * @version 1.0.0
 *
 */
/**
 * @author jeremy
 *
 */
public class TableCreator extends PharmacoepiTool {
	Map<String, Table> tables;
	
	/**
	 * Constructor for TableCreator.
	 */
	public TableCreator()
	{
		super();
		this.tables = new HashMap<String, Table>();
	}
	
	/**
	 * Add a table definition.
	 * 
	 * @param tableId		Unique ID of this table.
	 * @param description	Description of this table, to print as the table header.
	 */
	public void addTable(String tableId, String description)
	{
		tableId = TableElement.makeId(tableId);

		Table t = new Table(tableId, description);
		tables.put(tableId, t);
	}

	/**
	 * Add a header-style row to a table.
	 * 
	 * @param tableId	ID of the table.
	 * @param parentId	ID of the row's parent.
	 * @param id		Unique ID of the row.
	 * @param description	Description of the row, to print as the row's text in the table output.
	 */
	public void addHeaderRowToTable(String tableId, String parentId, String id, String description) {
// Path: src/org/drugepi/PharmacoepiTool.java
// public abstract class PharmacoepiTool {
// 	public static String description = "Pharamcoepi Toolbox";
// 	public static String version = "2.4.18";
// 	
// 	private long startTime;
// 	
// 	public PharmacoepiTool()
// 	{
// 		// not implemented
// 	}
// 		
// 	/**
// 	 * Add patient information, with patient data stored in a tab-delimited file.
// 	 * 
// 	 * @param filePath		Path of the patient data file.  See the documentation on each
// 	 * 						subclass for the expected order of patient columns.
// 	 * @throws Exception	
// 	 */
// 	public void addPatients(String filePath)
// 	throws Exception
// 	{		
// 		RowReader reader = new TabDelimitedFileReader(filePath);
// 		this.addPatients(reader);
// 
// 		// note: the implementing tool must close the reader
// 	}
// 	
// 	/**
// 	 * Add patient information, with patient data stored in a string buffer.
// 	 * 
// 	 * @param buf			Patient data.  See the documentation on each
// 	 * 						subclass for the expected order of patient columns.
// 	 * @throws Exception	
// 	 */
// 	public void addPatientsFromBuffer(String buf)
// 	throws Exception
// 	{		
// 		RowReader reader = new StringBufferRowReader(buf);
// 		this.addPatients(reader);
// 
// 		// note: the implementing tool must close the reader
// 	}
// 	
// 	/**
// 	 * Add patient information, with patient data stored in a database.
// 	 * 
// 	 * @param dbDriverClass	Name of the database driver.
// 	 * @param dbURL			JDBC URL of the database
// 	 * @param dbUser		Database user name.
// 	 * @param dbPassword	Database user's password.
// 	 * @param dbQuery		The query that will result in the patient data.  See the documentation on each
// 	 * 						subclass for the expected order of patient columns.
// 	 * @throws Exception
// 	 */
// 	public void addPatients(String dbDriverClass, String dbURL, String dbUser, String dbPassword,
// 			String dbQuery)
// 	throws Exception
// 	{
// 		RowReader reader = new DatabaseRowReader(dbDriverClass, dbURL, dbUser, dbPassword, dbQuery);
// 		this.addPatients(reader);
// 		
// 		// note: the implementing tool must close the reader
// 	}
// 	
// 	/**
// 	 * Add patient information from specified row reader object.
// 	 * 
// 	 * @param reader  The row reader object.
// 	 * @throws Exception
// 	 */
// 	public void addPatients(RowReader reader)
// 	throws Exception 
// 	{
// 		// do nothing.  override by subclass if desired.
// 	}
// 	 
// 	protected void startTool()
// 	{
//         System.out.printf("NOTE: %s version %s starting at %s.\n", 
//         		description, version, new Date().toString());
// 		this.startTime = System.currentTimeMillis();
// 	}
// 	
// 	protected void endTool()
// 	{
//         long eTime = System.currentTimeMillis() - startTime;
//         double minutes = Math.floor(eTime / (60 * 1000F));
//         eTime -= minutes * 60 * 1000F;
//         double seconds = eTime / 1000F;
//         System.out.printf("NOTE: %s finished at %s.  Run time: %02d:%02.3f.\n", 
//         		description, new Date().toString(), (int) minutes, seconds);
// 	}
// 
// 	/**
// 	 * @return the version
// 	 */
// 	public String getVersion() {
// 		return version;
// 	}
// 
// 	/**
// 	 * @return the description
// 	 */
// 	public String getDescription() {
// 		return description;
// 	}
// }
// 
// Path: src/org/drugepi/table/TableRowCol.java
// public enum RowColTypes { NORMAL, HEADER };


// Path: src/org/drugepi/table/TableCreator.java
import java.io.*;
import java.util.*;
import org.apache.poi.ss.usermodel.*;
import org.drugepi.PharmacoepiTool;
import org.drugepi.table.TableRowCol.RowColTypes;

/* 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 
 */

package org.drugepi.table;



/**
 * Creation of basic tables for epidemiology.
 * 
 * Tables are added using the {@link #addTable(String, String)} method.  Rows and columns are then defined,
 * and values added to cells.  Tables are then rendered to HTML using {@link #writeHtmlToFile(String, String)}.
 * 
 * @author Jeremy A. Rassen
 * @version 1.0.0
 *
 */
/**
 * @author jeremy
 *
 */
public class TableCreator extends PharmacoepiTool {
	Map<String, Table> tables;
	
	/**
	 * Constructor for TableCreator.
	 */
	public TableCreator()
	{
		super();
		this.tables = new HashMap<String, Table>();
	}
	
	/**
	 * Add a table definition.
	 * 
	 * @param tableId		Unique ID of this table.
	 * @param description	Description of this table, to print as the table header.
	 */
	public void addTable(String tableId, String description)
	{
		tableId = TableElement.makeId(tableId);

		Table t = new Table(tableId, description);
		tables.put(tableId, t);
	}

	/**
	 * Add a header-style row to a table.
	 * 
	 * @param tableId	ID of the table.
	 * @param parentId	ID of the row's parent.
	 * @param id		Unique ID of the row.
	 * @param description	Description of the row, to print as the row's text in the table output.
	 */
	public void addHeaderRowToTable(String tableId, String parentId, String id, String description) {
		this.addRowToTable(tableId, parentId, id, description, RowColTypes.HEADER);