Updates for clinical note

Added clinical notes check for pampi
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/GenerateCDADataHandler.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/GenerateCDADataHandler.java
index a4308d8..3d09c21 100644
--- a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/GenerateCDADataHandler.java
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/GenerateCDADataHandler.java
@@ -405,10 +405,7 @@
 
 		public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
 			try {
-				// @SuppressWarnings("unchecked")
-				// Iterator<Object> iter = iss.iterator();
-				// while (iter.hasNext() && !monitor.isCanceled()) {
-				// Object o = iter.next();
+
 				if (object instanceof IFolder) {
 					IFolder folder = (IFolder) object;
 					codeMetricsFile = folder.getFile("codemetrics.cfg");
@@ -417,50 +414,13 @@
 								? folder.members().length
 								: 1));
 
-					// int worksheetCache = 1000;
-					// if (System.getProperty("org.eclipse.mdht.cda.xls.worksheetcache") != null) {
-					// worksheetCache = Integer.valueOf(System.getProperty("org.eclipse.mdht.cda.xls.worksheetcache"));
-					// }
+					processSelection(folder, null, null, monitor, splitOption, theSections, theSectionCache);
 
-					final SXSSFWorkbook rollupStats = new SXSSFWorkbook(worksheetCache);
-					processSelection(
-						folder, null, null, monitor, splitOption, theSections, theSectionCache, rollupStats);
-
-					final StringBuffer fileLocation = new StringBuffer();
-					fileLocation.append(
-						folder.getParent().getLocation().toOSString() + System.getProperty("file.separator") +
-								CDAValueUtil.DATE_FORMAT3.format(new Date()) + "_" + folder.getName() + "_" +
-								"RollupStatistics.xlsx");
-
-					try (OutputStream fileOut = Files.newOutputStream(Paths.get(fileLocation.toString()))) {
-						rollupStats.write(fileOut);
-						fileOut.close();
-						rollupStats.close();
-						rollupStats.dispose();
-					}
 				}
 
 				if (object instanceof IFile) {
 					IFile zipFile = (IFile) object;
-
-					final SXSSFWorkbook rollupStats = new SXSSFWorkbook(10);
-					processSelection(
-						null, zipFile, null, monitor, splitOption, theSections, theSectionCache, rollupStats);
-
-					final StringBuffer fileLocation = new StringBuffer();
-					fileLocation.append(
-						zipFile.getParent().getLocation().toOSString() + System.getProperty("file.separator") +
-								CDAValueUtil.DATE_FORMAT3.format(new Date()) + "_" +
-								FilenameUtils.getBaseName(zipFile.getName()).toUpperCase() + "_" +
-								"RollupStatistics.xlsx");
-
-					try (OutputStream fileOut = Files.newOutputStream(Paths.get(fileLocation.toString()))) {
-						rollupStats.write(fileOut);
-						fileOut.close();
-						rollupStats.close();
-						rollupStats.dispose();
-					}
-
+					processSelection(null, zipFile, null, monitor, splitOption, theSections, theSectionCache);
 				}
 			} catch (Exception e) {
 				ILog log = Activator.getDefault().getLog();
@@ -699,8 +659,6 @@
 
 				final IStructuredSelection iss = (IStructuredSelection) selection;
 
-				final SXSSFWorkbook rollupStats = new SXSSFWorkbook(worksheetCache);
-
 				try {
 					pd.run(true, true, new IRunnableWithProgress() {
 
@@ -728,34 +686,17 @@
 										}
 
 										processSelection(
-											folder, null, null, monitor, splitOption, theSections, theSectionCache,
-											rollupStats);
+											folder, null, null, monitor, splitOption, theSections, theSectionCache);
 									}
 
 									if (o instanceof IFile) {
 										IFile zipFile = (IFile) o;
 
-										if (fileLocation.length() == 0) {
-											fileLocation.append(
-												zipFile.getParent().getLocation().toOSString() +
-														System.getProperty("file.separator") +
-														CDAValueUtil.DATE_FORMAT3.format(new Date()) + "_" +
-														zipFile.getName() + "RollupStatistics.xlsx");
-										}
-
 										processSelection(
-											null, zipFile, null, monitor, splitOption, theSections, theSectionCache,
-											rollupStats);
+											null, zipFile, null, monitor, splitOption, theSections, theSectionCache);
 
 									}
 
-									try (OutputStream fileOut = Files.newOutputStream(
-										Paths.get(fileLocation.toString()))) {
-										rollupStats.write(fileOut);
-										fileOut.close();
-										rollupStats.close();
-										rollupStats.dispose();
-									}
 								}
 							} catch (Throwable e) {
 								ILog log = Activator.getDefault().getLog();
@@ -1431,14 +1372,13 @@
 
 		omitValidation = true;
 		processSelection(
-			null, null, selectedFile2, new NullProgressMonitor(), CONSOLIDATED, sectionFilter, theSectionCache,
-			rollupStats);
+			null, null, selectedFile2, new NullProgressMonitor(), CONSOLIDATED, sectionFilter, theSectionCache);
 
 	}
 
 	void processSelection(IFolder selectedFolder, IFile selectedFile, String selectedFile2, IProgressMonitor monitor,
-			String splitOption, HashSet<EClass> sectionFilter, HashMap<EClass, HashSet<EClass>> theSectionCache,
-			SXSSFWorkbook rollupStats) throws Exception {
+			String splitOption, HashSet<EClass> sectionFilter, HashMap<EClass, HashSet<EClass>> theSectionCache)
+			throws Exception {
 
 		// MessageConsole mdhtConsole = findConsole(MDHTCONSOLE);
 		// mdhtConsole.setWaterMarks(1000, 18000);
@@ -1547,53 +1487,19 @@
 		String fileLocation3 = folderTarget + CDAValueUtil.DATE_FORMAT3.format(new Date()) + "_" + folderName +
 				"validatation.csv";
 
-		BufferedWriter performance = Files.newBufferedWriter(Paths.get(fileLocation2));
+		BufferedWriter performance = null;
+		boolean omitPerformance = true;
+		if (!omitPerformance) {
+			performance = Files.newBufferedWriter(Paths.get(fileLocation2));
+		}
 
-		BufferedWriter validation = Files.newBufferedWriter(Paths.get(fileLocation3));
+		BufferedWriter validation = null;
 
-		validation.write("File,Rule,XPath");
-		validation.newLine();
-
-		final int STATSFILENAME = 0;
-		final int STATSTOTAL = 1;
-		final int STATSCONSOLIDATED = 2;
-		final int STATSCONTINUITYOFCARE = 3;
-		final int STATSPROGRESSNOTE = 4;
-		final int STATSDISCHARGESUMMARY = 5;
-		final int STATSOTHER = 6;
-		final int STATSC32 = 7;
-		final int STATSNONXML = 8;
-		final int STATSERRORS = 9;
-
-		// SXSSFSheet statsheeta = rollupStats.getSheet("File Statistics");
-		// // if (statsheet == null) {
-		// // statsheet = rollupStats.createSheet("File Statistics");
-		// // Row hrow = statsheet.createRow(statsheet.getPhysicalNumberOfRows());
-		// // hrow.createCell(STATSFILENAME).setCellValue("File Name");
-		// // hrow.createCell(STATSTOTAL).setCellValue("Totals");
-		// // hrow.createCell(STATSCONSOLIDATED).setCellValue("Consolidated");
-		// // hrow.createCell(STATSCONTINUITYOFCARE).setCellValue("Summarization of episode note");
-		// // hrow.createCell(STATSPROGRESSNOTE).setCellValue("Outpatient Progress note");
-		// // hrow.createCell(STATSDISCHARGESUMMARY).setCellValue("Discharge Summary");
-		// // hrow.createCell(STATSOTHER).setCellValue("Other");
-		// // hrow.createCell(STATSC32).setCellValue("C32");
-		// // hrow.createCell(STATSNONXML).setCellValue("NonXML");
-		// // hrow.createCell(STATSERRORS).setCellValue("Errors");
-		// // ;
-		// //
-		// // }
-		//
-		// // statsheet.set
-		//
-		// Row statrowb = statsheet.createRow(statsheet.getPhysicalNumberOfRows());
-		//
-		// if (selectedFile != null) {
-		// statrow.createCell(0).setCellValue(selectedFile.getName());
-		// }
-		//
-		// if (selectedFolder != null) {
-		// statrow.createCell(0).setCellValue(selectedFolder.getName());
-		// }
+		if (!omitValidation) {
+			validation = Files.newBufferedWriter(Paths.get(fileLocation3));
+			validation.write("File,Rule,XPath");
+			validation.newLine();
+		}
 
 		boolean skipProcessing = false;
 
@@ -1746,9 +1652,12 @@
 								String.format("%.2f MB/S", (fileSize / (1024 * 1024)) / (t / 1000.0));
 						monitor.subTask(s);
 
-						performance.write(s);
-						performance.newLine();
-						performance.flush();
+						if (performance != null) {
+							performance.write(s);
+							performance.newLine();
+							performance.flush();
+
+						}
 
 						continue;
 					}
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SectionSwitch.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SectionSwitch.java
index f9b7130..7eab864 100644
--- a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SectionSwitch.java
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SectionSwitch.java
@@ -58,6 +58,7 @@
 import org.openhealthtools.mdht.uml.cda.consol.InstructionsSection;
 import org.openhealthtools.mdht.uml.cda.consol.MedicationsAdministeredSection;
 import org.openhealthtools.mdht.uml.cda.consol.MedicationsSectionEntriesOptional;
+import org.openhealthtools.mdht.uml.cda.consol.NoteActivity;
 import org.openhealthtools.mdht.uml.cda.consol.OutcomeObservation;
 import org.openhealthtools.mdht.uml.cda.consol.PayersSection;
 import org.openhealthtools.mdht.uml.cda.consol.PostprocedureDiagnosisSection;
@@ -1131,7 +1132,7 @@
 
 			offset = SpreadsheetSerializer.serializeEnounterID(row, offset, sa, encounters);
 
-			offset = SpreadsheetSerializer.serializeProblemObservationClinicalStatement(row, offset, sa);
+			offset = SpreadsheetSerializer.serializeProblemObservationClinicalStatement(row, offset, sa, true);
 
 			SpreadsheetSerializer.serializeSectionAndFileName(row, offset, sa.getSection(), fileName);
 
@@ -1180,7 +1181,7 @@
 
 		for (ProblemObservation problemObservation : problemConcernAct.getProblemObservations()) {
 			offset = SpreadsheetSerializer.serializeProblemObservationClinicalStatement(
-				row, offset, problemObservation);
+				row, offset, problemObservation, true);
 			break;
 		}
 
@@ -1202,7 +1203,7 @@
 
 			offset = SpreadsheetSerializer.serializeEnounterID(row, offset, sa, encounters);
 
-			offset = serializeAllergyProblemAct(row, offset, sa);
+			offset = serializeAllergyProblemAct(row, offset, sa, true);
 
 			SpreadsheetSerializer.serializeSectionAndFileName(row, offset, sa.getSection(), fileName);
 
@@ -1215,7 +1216,8 @@
 	 * @param sa
 	 * @return
 	 */
-	static int serializeAllergyProblemAct(Row row, int offset, AllergyProblemAct allergyProblemAct) {
+	static int serializeAllergyProblemAct(Row row, int offset, AllergyProblemAct allergyProblemAct,
+			boolean checkForNotes) {
 
 		StringBuffer sb = new StringBuffer();
 
@@ -1315,6 +1317,27 @@
 			} else {
 				offset = SpreadsheetSerializer.appendCode(row, offset, allergyProblemAct.getSection(), null, null);
 			}
+
+			if (checkForNotes) {
+				boolean hasNotes = false;
+				Act note = null;
+				for (Act act : allergyObservation.getActs()) {
+					if (act instanceof NoteActivity) {
+						hasNotes = true;
+						note = act;
+					}
+				}
+
+				if (hasNotes) {
+					row.createCell(offset++).setCellValue(hasNotes);
+					row.createCell(offset++).setCellValue(CDAUtil.getDomainPath(note));
+				} else {
+					row.createCell(offset++).setCellValue(false);
+					row.createCell(offset++).setCellValue("");
+				}
+
+			}
+
 			offset = SpreadsheetSerializer.appendOrganizationAndAuthor(row, offset, allergyObservation.getAuthors());
 
 			break;
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SheetHeaderUtil.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SheetHeaderUtil.java
index 2cda844..d286794 100644
--- a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SheetHeaderUtil.java
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SheetHeaderUtil.java
@@ -35,6 +35,9 @@
 
 		offset = addCodeHeader(row2, offset, "Reaction");
 		offset = addCodeHeader(row2, offset, "Severity");
+		row2.createCell(offset++).setCellValue(replaceSpace("Clinical Notes"));
+		row2.createCell(offset++).setCellValue(replaceSpace("Location"));
+		row2.getSheet().setColumnHidden(offset - 1, hideColumns);
 		row2.createCell(offset++).setCellValue(replaceSpace("Organization"));
 		row2.createCell(offset++).setCellValue(replaceSpace("Author"));
 		offset = addSectionHeader(row2, offset);
@@ -185,6 +188,11 @@
 		} else {
 			offset = addCodeHeader(row2, offset, "Problem");
 		}
+
+		row2.createCell(offset++).setCellValue(replaceSpace("Clinical Notes"));
+		row2.createCell(offset++).setCellValue(replaceSpace("Location"));
+		row2.getSheet().setColumnHidden(offset - 1, hideColumns);
+
 		row2.createCell(offset++).setCellValue(replaceSpace("Problem Organization"));
 		row2.createCell(offset++).setCellValue(replaceSpace("Problem Author"));
 		offset = addSectionHeader(row2, offset);
@@ -211,6 +219,9 @@
 		} else {
 			offset = addCodeHeader(row2, offset, "Procedure");
 		}
+		row2.createCell(offset++).setCellValue(replaceSpace("Clinical Notes"));
+		row2.createCell(offset++).setCellValue(replaceSpace("Location"));
+		row2.getSheet().setColumnHidden(offset - 1, hideColumns);
 		row2.createCell(offset++).setCellValue(replaceSpace("Performer"));
 		row2.createCell(offset++).setCellValue(replaceSpace("Location"));
 		row2.getSheet().setColumnHidden(offset - 1, hideColumns);
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SpreadsheetSerializer.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SpreadsheetSerializer.java
index 818c18e..8a5c0da 100644
--- a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SpreadsheetSerializer.java
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/SpreadsheetSerializer.java
@@ -585,8 +585,8 @@
 		return offset++;
 	}
 
-	public static int serializeProblemObservationClinicalStatement(Row row, int offset,
-			Observation problemObservation) {
+	public static int serializeProblemObservationClinicalStatement(Row row, int offset, Observation problemObservation,
+			boolean checkForNotes) {
 		Cell cell = row.createCell(offset++);
 
 		StringBuffer sb = new StringBuffer();
@@ -667,6 +667,26 @@
 				row, offset, problemObservation.getSection(), problemCode, problemObservation.getText());
 		}
 
+		if (checkForNotes) {
+			boolean hasNotes = false;
+			Act note = null;
+			for (Act act : problemObservation.getActs()) {
+				if (act instanceof NoteActivity) {
+					hasNotes = true;
+					note = act;
+				}
+			}
+
+			if (hasNotes) {
+				row.createCell(offset++).setCellValue(hasNotes);
+				row.createCell(offset++).setCellValue(CDAUtil.getDomainPath(note));
+			} else {
+				row.createCell(offset++).setCellValue(false);
+				row.createCell(offset++).setCellValue("");
+			}
+
+		}
+
 		offset = SpreadsheetSerializer.appendOrganizationAndAuthor(row, offset, problemObservation.getAuthors());
 
 		return offset;
@@ -1310,7 +1330,8 @@
 		for (Act act : encounter.getActs()) {
 			for (Observation observation : act.getObservations()) {
 
-				offset = SpreadsheetSerializer.serializeProblemObservationClinicalStatement(row, offset, observation);
+				offset = SpreadsheetSerializer.serializeProblemObservationClinicalStatement(
+					row, offset, observation, true);
 				hasDiagnosis = true;
 				break;
 			}