Updates to xsl generation

modified filtering to leverage section by code
drop document and encoutner from filtered generation
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/FooBar.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/FooBar.java
new file mode 100644
index 0000000..d915a34
--- /dev/null
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/FooBar.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2020 seanmuir.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     seanmuir - initial API and implementation
+ *
+ *******************************************************************************/
+package org.eclipse.mdht.cda.xml;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @author seanmuir
+ *
+ */
+public class FooBar {
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		// fail("Not yet implemented");
+
+		ArrayList<String> aaaa = new ArrayList<String>();
+		// aaaa.add("aaaa");
+		// aaaa.add("bbbb");
+		// aaaa.add("cccc");
+		//
+		// String foo2 = convertWithStream(aaaa);
+		// System.out.println(foo2);
+
+		Map<String, List<String>> wordsByKey = new HashMap<String, List<String>>();
+		wordsByKey.put("1", new ArrayList<String>());
+		wordsByKey.put("2", new ArrayList<String>());
+		wordsByKey.put("3", new ArrayList<String>());
+		wordsByKey.put("4", new ArrayList<String>());
+
+		wordsByKey.get("1").add("aaaaaaa");
+		wordsByKey.get("2").add("aaaaaaa");
+		wordsByKey.get("3").add("aaaaaaa");
+		wordsByKey.get("4").add("aaaaaaa");
+
+		wordsByKey.get("1").add("bbb");
+		wordsByKey.get("2").add("bbb");
+		wordsByKey.get("3").add("bb");
+		wordsByKey.get("4").add("bbb");
+
+		String foo = convertWithStream(wordsByKey);
+		System.out.println(foo);
+
+		Map<String, List<String>> t = convertWithStream(foo);
+
+		for (String k : t.keySet()) {
+			System.out.println(k + "  >> " + t.get(k));
+		}
+
+	}
+
+	public static String convertWithStream(List<String> list) {
+		String mapAsString = " " + String.join(" ", list) + " ";
+		return mapAsString;
+	}
+
+	public static String convertWithStream(Map<String, List<String>> map) {
+		String mapAsString = map.keySet().stream().map(key -> key + "=" + convertWithStream(map.get(key))).collect(
+			Collectors.joining(", ", " ", " "));
+		return mapAsString;
+	}
+
+	public static Map<String, List<String>> convertWithStream(String mapAsString) {
+		Map<String, String> map1 = Arrays.stream(mapAsString.split(",")).map(entry -> entry.split("=")).collect(
+			Collectors.toMap(entry -> entry[0], entry -> entry[1]));
+
+		Map<String, List<String>> map2 = new HashMap<String, List<String>>();
+		for (String k : map1.keySet()) {
+			map2.put(k, new ArrayList<String>());
+			map2.get(k).addAll(Arrays.asList(map1.get(k).split(" ")));
+		}
+
+		return map2;
+	}
+
+}
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/SWTComboExample.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/SWTComboExample.java
new file mode 100644
index 0000000..3007fbd
--- /dev/null
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/SWTComboExample.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2020 seanmuir.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     seanmuir - initial API and implementation
+ *
+ *******************************************************************************/
+package org.eclipse.mdht.cda.xml;
+
+import java.util.Arrays;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class SWTComboExample {
+	Display d;
+
+	Shell s;
+
+	SWTComboExample() {
+		d = new Display();
+		s = new Shell(d);
+		s.setSize(250, 250);
+		s.setText("A Combo Example");
+		final CCombo c = new CCombo(s, SWT.READ_ONLY);
+		c.setBounds(50, 50, 150, 65);
+		c.setEditable(true);
+		String items[] = { "aaItem One", "Item Two", "Item Three", "Item Four", "Item Five" };
+		c.setItems(items);
+
+		// ControlListener new ControlListener () {} ;
+
+		// ModifyListener new ModifyListener () {};
+		// c.addModifyListener(new ModifyListener() {
+		//
+		// @Override
+		// public void modifyText(ModifyEvent arg0) {
+		// // TODO Auto-generated method stub
+		// System.out.println(arg0.toString());
+		//
+		// }
+		// });
+
+		c.addKeyListener(new KeyListener() {
+
+			@Override
+			public void keyPressed(KeyEvent arg0) {
+				System.out.println(arg0.toString());
+			}
+
+			@Override
+			public void keyReleased(KeyEvent arg0) {
+
+				if (arg0.keyCode == 0xd) {
+					System.out.println(arg0.toString());
+
+					System.out.println(c.getText());
+
+					boolean result = Arrays.stream(c.getItems()).anyMatch(c.getText()::equals);
+					if (!result) {
+						c.add(c.getText());
+						c.select(c.getItemCount());
+					}
+				}
+
+			}
+		});
+
+		s.open();
+		while (!s.isDisposed()) {
+			if (!d.readAndDispatch())
+				d.sleep();
+		}
+		d.dispose();
+	}
+
+	public static void main(String[] argv) {
+		new SWTComboExample();
+	}
+}
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 1da3c5e..929180b 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
@@ -112,6 +112,7 @@
 import org.eclipse.mdht.cda.xml.ui.handlers.CDAValueUtil.DocumentMetadata;
 import org.eclipse.mdht.uml.cda.AssignedAuthor;
 import org.eclipse.mdht.uml.cda.Author;
+import org.eclipse.mdht.uml.cda.CDAPackage;
 import org.eclipse.mdht.uml.cda.ClinicalDocument;
 import org.eclipse.mdht.uml.cda.DocumentRoot;
 import org.eclipse.mdht.uml.cda.Encounter;
@@ -1693,20 +1694,46 @@
 
 						for (Section section : clinicalDocument.getSections()) {
 
-							if (!sectionFilter.isEmpty() && !sectionFilter.contains(section.eClass())) {
+							// This is when a section template is not found
+							if (!sectionFilter.isEmpty()) {
 
-								boolean found = false;
-								for (EClass sectionClass : sectionFilter) {
-									if (theSectionCache.get(sectionClass).contains(section.eClass())) {
-										// theSectionEClass = sectionClass;
-										found = true;
-										break;
+								if (CDAPackage.eINSTANCE.getSection().isInstance(section)) {
+
+									String code = section.getCode().getCode();
+
+									if (ProcessSectionSwitch.getCodeToSection().containsKey(code)) {
+										EClass targetSectionEclass = ProcessSectionSwitch.getCodeToSection().get(code);
+
+										boolean found = false;
+										for (EClass sectionClass : sectionFilter) {
+											if (theSectionCache.get(sectionClass).contains(targetSectionEclass)) {
+												found = true;
+												break;
+											}
+										}
+										if (!found) {
+											continue;
+
+										}
+
 									}
-								}
-								if (!found) {
-									continue;
 
 								}
+
+								if (!sectionFilter.contains(section.eClass())) {
+
+									boolean found = false;
+									for (EClass sectionClass : sectionFilter) {
+										if (theSectionCache.get(sectionClass).contains(section.eClass())) {
+											found = true;
+											break;
+										}
+									}
+									if (!found) {
+										continue;
+
+									}
+								}
 							}
 
 							console.println("Start Section " + section.eClass().getName());
@@ -1957,9 +1984,12 @@
 				 * It was simpler to remove after tracking then modifying logic to process
 				 *
 				 */
+
 				wb.removeSheetAt(wb.getSheetIndex("Demographics"));
 				wb.removeSheetAt(wb.getSheetIndex("Metrics"));
 				wb.removeSheetAt(wb.getSheetIndex("Sections"));
+				wb.removeSheetAt(wb.getSheetIndex("Documents"));
+				wb.removeSheetAt(wb.getSheetIndex("Encounters"));
 
 			}
 			console.println("Start Saving " + currentProcessingTime);
diff --git a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/ProcessSectionSwitch.java b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/ProcessSectionSwitch.java
index 875c7f5..c674864 100644
--- a/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/ProcessSectionSwitch.java
+++ b/cda/plugins/org.eclipse.mdht.cda.xml.ui/src/org/eclipse/mdht/cda/xml/ui/handlers/ProcessSectionSwitch.java
@@ -810,7 +810,7 @@
 	// return super.casePlanOfTreatmentSection2(section);
 	// }
 
-	HashMap<String, EClass> codeToSection = new HashMap<String, EClass>();
+	static HashMap<String, EClass> codeToSection = new HashMap<String, EClass>();
 
 	/*
 	 * (non-Javadoc)
@@ -854,19 +854,19 @@
 		// If not found - try using code
 		Section section = (Section) object;
 
-		if (codeToSection.isEmpty()) {
-			for (EClassifier consolPackageClassifier : ConsolPackage.eINSTANCE.getEClassifiers()) {
-				if (CDAPackage.eINSTANCE.getSection().isSuperTypeOf(CDAPackage.eINSTANCE.getSection())) {
-					EAnnotation annotation = consolPackageClassifier.getEAnnotation(CDA_ANNOTATION_SOURCE);
-					String code = annotation.getDetails().get("code.code");
-					if (!codeToSection.containsKey(code)) {
-						codeToSection.put(code, (EClass) consolPackageClassifier);
-					}
-
-				}
-
-			}
-		}
+		// if (codeToSection.isEmpty()) {
+		// for (EClassifier consolPackageClassifier : ConsolPackage.eINSTANCE.getEClassifiers()) {
+		// if (CDAPackage.eINSTANCE.getSection().isSuperTypeOf(CDAPackage.eINSTANCE.getSection())) {
+		// EAnnotation annotation = consolPackageClassifier.getEAnnotation(CDA_ANNOTATION_SOURCE);
+		// String code = annotation.getDetails().get("code.code");
+		// if (!codeToSection.containsKey(code)) {
+		// codeToSection.put(code, (EClass) consolPackageClassifier);
+		// }
+		//
+		// }
+		//
+		// }
+		// }
 
 		StringBuffer sb = new StringBuffer();
 		sb.append("UnIdentified Section  in " + this.file.getName());
@@ -885,8 +885,8 @@
 
 			String code = section.getCode().getCode();
 
-			if (codeToSection.containsKey(code)) {
-				Section newSection = (Section) EcoreUtil.create(codeToSection.get(code));
+			if (getCodeToSection().containsKey(code)) {
+				Section newSection = (Section) EcoreUtil.create(getCodeToSection().get(code));
 				newSection.setText(section.getText());
 				newSection.getEntries().addAll(section.getEntries());
 
@@ -936,4 +936,25 @@
 		return Boolean.FALSE;
 	}
 
+	/**
+	 * @return the codeToSection
+	 */
+	public static HashMap<String, EClass> getCodeToSection() {
+
+		if (codeToSection.isEmpty()) {
+			for (EClassifier consolPackageClassifier : ConsolPackage.eINSTANCE.getEClassifiers()) {
+				if (CDAPackage.eINSTANCE.getSection().isSuperTypeOf(CDAPackage.eINSTANCE.getSection())) {
+					EAnnotation annotation = consolPackageClassifier.getEAnnotation(CDA_ANNOTATION_SOURCE);
+					String code = annotation.getDetails().get("code.code");
+					if (!codeToSection.containsKey(code)) {
+						codeToSection.put(code, (EClass) consolPackageClassifier);
+					}
+
+				}
+
+			}
+		}
+		return codeToSection;
+	}
+
 }