<commit_before>/*******************************************************************************
 * Copyright (c) 2009 <NAME>.
 * 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:
 *     <NAME> (XMLmodeling.com) - initial API and implementation
 *     <NAME> - Fixed a problem related to generating the DITA for value sets
 *                    that were not contained in the vocab project and that are in 
 *                    models which are not based on CDA
 *                   
 *     
 * $Id$
 *******************************************************************************/
package org.openhealthtools.mdht.uml.cda.dita;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import org.eclipse.core.runtime.IPath;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
import org.openhealthtools.mdht.uml.cda.core.util.CDAModelUtil;
import org.openhealthtools.mdht.uml.cda.dita.internal.Logger;
import org.openhealthtools.mdht.uml.term.core.profile.ValueSetCode;
import org.openhealthtools.mdht.uml.term.core.profile.ValueSetVersion;
import org.openhealthtools.mdht.uml.term.core.util.TermProfileUtil;

public class TransformValueSet extends TransformAbstract {

	public TransformValueSet(DitaTransformerOptions options) {
		super(options);
	}

	public String getDefinition(Enumeration enumeration) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);

		pw.println("<section id=\"definition\">");

		appendDefinition(pw, enumeration);
		appendConcepts(pw, enumeration);

		pw.println("</section>");
		return sw.toString();
	}

	private void appendBody(PrintWriter writer, Enumeration umlEnumeration) {
		writer.println("<body>");
		writer.println("<!-- THIS IS GENERATED CONTENT, DO NOT EDIT -->");
		writer.println("<section id=\"definition\">");

		appendDefinition(writer, umlEnumeration);
		appendConcepts(writer, umlEnumeration);

		writer.println("</section>");
		writer.println("</body>");
		writer.println("</topic>");
	}

	private void appendConcepts(PrintWriter writer, Enumeration umlEnumeration) {
		String codeSystemName = null;
		ValueSetVersion valueSetVersion = TermProfileUtil.getValueSetVersion(umlEnumeration);
		if (valueSetVersion != null && valueSetVersion.getCodeSystem() != null &&
				!valueSetVersion.getCodeSystem().eIsProxy()) {
			codeSystemName = valueSetVersion.getCodeSystem().getBase_Enumeration().getName();
		}

		if (!umlEnumeration.getOwnedLiterals().isEmpty()) {

			if (transformerOptions.isIncludeUsageNotes()) {
				writer.println("<table><tgroup cols=\"4\">");
				writer.println("<colspec colname=\"col1\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col2\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col3\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col4\" colwidth=\"2*\"/>");
				writer.println("<thead><row>");
				writer.println("<entry>Code</entry><entry>Code System</entry><entry>Print Name</entry><entry>Usage Note</entry>");
				writer.println("</row></thead><tbody>");
			} else {
				writer.println("<table><tgroup cols=\"3\">");
				writer.println("<colspec colname=\"col1\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col2\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col3\" colwidth=\"2*\"/>");
				writer.println("<thead><row>");
				writer.println("<entry>Code</entry><entry>Code System</entry><entry>Print Name</entry>");
				writer.println("</row></thead><tbody>");
			}

			for (EnumerationLiteral literal : umlEnumeration.getOwnedLiterals()) {
				ValueSetCode valueSetCode = TermProfileUtil.getValueSetCode(literal);
				writer.print("<row>");
				// Concept Code
				writer.print("<entry>" + literal.getName() + "</entry>");

				// Code System
				writer.print("<entry>");
				if (valueSetCode != null && valueSetCode.getCodeSystem() != null) {
					writer.print(valueSetCode.getCodeSystem().getBase_Enumeration().getName());
				} else if (codeSystemName != null) {
					writer.print(codeSystemName);
				}
				writer.print("</entry>");

				// Print Name
				writer.print("<entry>");
				if (valueSetCode != null && valueSetCode.getConceptName() != null) {
					writer.print(CDAModelUtil.fixNonXMLCharacters(valueSetCode.getConceptName()));
				}
				writer.print("</entry>");

				if (transformerOptions.isIncludeUsageNotes()) {
					writer.print("<entry>");
					if (valueSetCode != null && valueSetCode.getUsageNote() != null) {
						writer.print(CDAModelUtil.fixNonXMLCharacters(valueSetCode.getUsageNote()));
					}
					writer.print("</entry>");
				}

				writer.println("</row>");
			}

			writer.println("</tbody></tgroup></table>");
		}
	}

	private static void appendDefinition(PrintWriter writer, Enumeration umlEnumeration) {
		writer.println("<table><tgroup cols=\"2\">");
		writer.println("<colspec colname=\"col1\" colwidth=\"1*\"/>");
		writer.println("<colspec colname=\"col2\" colwidth=\"4*\"/>");
		writer.println("<tbody>");

		ValueSetVersion valueSetVersion = TermProfileUtil.getValueSetVersion(umlEnumeration);
		if (valueSetVersion != null) {
			String valueSetId = valueSetVersion.getIdentifier() != null
					? valueSetVersion.getIdentifier()
					: "(OID not specified)";<commit_msg>Row separators are added to Value Sets<commit_after>/*******************************************************************************
 * Copyright (c) 2009 <NAME>.
 * 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:
 *     <NAME> (XMLmodeling.com) - initial API and implementation
 *     <NAME> - Fixed a problem related to generating the DITA for value sets
 *                    that were not contained in the vocab project and that are in 
 *                    models which are not based on CDA
 *                   
 *     
 * $Id$
 *******************************************************************************/
package org.openhealthtools.mdht.uml.cda.dita;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

import org.eclipse.core.runtime.IPath;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
import org.openhealthtools.mdht.uml.cda.core.util.CDAModelUtil;
import org.openhealthtools.mdht.uml.cda.dita.internal.Logger;
import org.openhealthtools.mdht.uml.term.core.profile.ValueSetCode;
import org.openhealthtools.mdht.uml.term.core.profile.ValueSetVersion;
import org.openhealthtools.mdht.uml.term.core.util.TermProfileUtil;

public class TransformValueSet extends TransformAbstract {

	public TransformValueSet(DitaTransformerOptions options) {
		super(options);
	}

	public String getDefinition(Enumeration enumeration) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);

		pw.println("<section id=\"definition\">");

		appendDefinition(pw, enumeration);
		appendConcepts(pw, enumeration);

		pw.println("</section>");
		return sw.toString();
	}

	private void appendBody(PrintWriter writer, Enumeration umlEnumeration) {
		writer.println("<body>");
		writer.println("<!-- THIS IS GENERATED CONTENT, DO NOT EDIT -->");
		writer.println("<section id=\"definition\">");

		appendDefinition(writer, umlEnumeration);
		appendConcepts(writer, umlEnumeration);

		writer.println("</section>");
		writer.println("</body>");
		writer.println("</topic>");
	}

	private void appendConcepts(PrintWriter writer, Enumeration umlEnumeration) {
		String codeSystemName = null;
		ValueSetVersion valueSetVersion = TermProfileUtil.getValueSetVersion(umlEnumeration);
		if (valueSetVersion != null && valueSetVersion.getCodeSystem() != null &&
				!valueSetVersion.getCodeSystem().eIsProxy()) {
			codeSystemName = valueSetVersion.getCodeSystem().getBase_Enumeration().getName();
		}

		if (!umlEnumeration.getOwnedLiterals().isEmpty()) {

			if (transformerOptions.isIncludeUsageNotes()) {
				writer.println("<table frame=\"all\" rowsep=\"1\" colsep=\"1\"><tgroup cols=\"4\">");
				writer.println("<colspec colname=\"col1\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col2\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col3\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col4\" colwidth=\"2*\"/>");
				writer.println("<thead><row>");
				writer.println("<entry>Code</entry><entry>Code System</entry><entry>Print Name</entry><entry>Usage Note</entry>");
				writer.println("</row></thead><tbody>");
			} else {
				writer.println("<table frame=\"all\" rowsep=\"1\" colsep=\"1\"><tgroup cols=\"3\">");
				writer.println("<colspec colname=\"col1\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col2\" colwidth=\"1*\"/>");
				writer.println("<colspec colname=\"col3\" colwidth=\"2*\"/>");
				writer.println("<thead><row>");
				writer.println("<entry>Code</entry><entry>Code System</entry><entry>Print Name</entry>");
				writer.println("</row></thead><tbody>");
			}

			for (EnumerationLiteral literal : umlEnumeration.getOwnedLiterals()) {
				ValueSetCode valueSetCode = TermProfileUtil.getValueSetCode(literal);
				writer.print("<row>");
				// Concept Code
				writer.print("<entry>" + literal.getName() + "</entry>");

				// Code System
				writer.print("<entry>");
				if (valueSetCode != null && valueSetCode.getCodeSystem() != null) {
					writer.print(valueSetCode.getCodeSystem().getBase_Enumeration().getName());
				} else if (codeSystemName != null) {
					writer.print(codeSystemName);
				}
				writer.print("</entry>");

				// Print Name
				writer.print("<entry>");
				if (valueSetCode != null && valueSetCode.getConceptName() != null) {
					writer.print(CDAModelUtil.fixNonXMLCharacters(valueSetCode.getConceptName()));
				}
				writer.print("</entry>");

				if (transformerOptions.isIncludeUsageNotes()) {
					writer.print("<entry>");
					if (valueSetCode != null && valueSetCode.getUsageNote() != null) {
						writer.print(CDAModelUtil.fixNonXMLCharacters(valueSetCode.getUsageNote()));
					}
					writer.print("</entry>");
				}

				writer.println("</row>");
			}

			writer.println("</tbody></tgroup></table>");
		}
	}

	private static void appendDefinition(PrintWriter writer, Enumeration umlEnumeration) {
		writer.println("<table frame=\"all\" rowsep=\"1\" colsep=\"1\"><tgroup cols=\"2\">");
		writer.println("<colspec colname=\"col1\" colwidth=\"1*\"/>");
		writer.println("<colspec colname=\"col2\" colwidth=\"4*\"/>");
		writer.println("<tbody>");

		ValueSetVersion valueSetVersion = TermProfileUtil.getValueSetVersion(umlEnumeration);
		if (valueSetVersion != null) {
			String valueSetId = valueSetVersion.getIdentifier() != null
					? valueSetVersion.getIdentifier()
					: "(OID not specified)";
{'fraction_non_alphanumeric': 0.18948579520311531, 'fraction_numerical': 0.006195238516682892, 'mean_word_length': 4.53921568627451, 'pattern_counts': {'":': 0, '<': 131, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2899235', 'n_tokens_mistral': 3778, 'n_tokens_neox': 3313, 'n_words': 612}