* mucus category 5 - mucus description 6 - is bleeding 7 - is disturbed
*/
public void exportToCSV(OutputStream stream, NFPControler controler) throws IOException, RecordStoreException {
PrintStream writer = new PrintStream(stream);
PeriodDAO periodDAO = controler.getPeriodDAO();
ObservationDAO observationDAO = controler.getObservationDAO();
try {
String[] header = {
"${csv.period}",
"${csv.observation}",
"${csv.date}",
"${csv.temperature}",
"${csv.mucus.id}",
"${csv.mucus.category}",
"${csv.mucus.description}",
"${csv.bleeding}",
"${csv.disturbed}"
};
for(int i=0;i<header.length;++i) {
writer.print('"');
writer.print(header[i]);
writer.print('"');
if(i < header.length - 1)
writer.print(',');
}
writer.println();
Vector periods = periodDAO.findAll();
controler.progressListner.setMaxValue(periods.size() * 100);
for (int i = 0; i < periods.size(); ++i) {
Period period = (Period) periods.elementAt(i);
Vector ids = periodDAO.getObservationIds(period);
for (int j = 0; j < ids.size(); ++j) {
controler.progressListner.setValue(i * 100 + (j * 100 / ids.size()));
Integer id = (Integer) ids.elementAt(j);
Observation ob = observationDAO.find(id.intValue());
if (ob == null)
continue;
writer.print(i + 1);
writer.print(',');
writer.print(j + 1);