Skip to content

Commit

Permalink
Started to work on N24 documentation (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
depryf committed Oct 13, 2023
1 parent 5014969 commit aee197f
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 66 deletions.
72 changes: 72 additions & 0 deletions src/main/resources/layout/fixed/naaccr/doc/naaccr24/race1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<table class="naaccr-summary-table naaccr-borders">
<tr>
<th class="naaccr-summary-header naaccr-borders">Item #</th>
<th class="naaccr-summary-header naaccr-borders">Length</th>
<th class="naaccr-summary-header naaccr-borders">Source of Standard</th>
<th class="naaccr-summary-header naaccr-borders">Year Implemented</th>
<th class="naaccr-summary-header naaccr-borders">Version Implemented</th>
<th class="naaccr-summary-header naaccr-borders">Year Retired</th>
<th class="naaccr-summary-header naaccr-borders">Version Retired</th>
</tr>
<tr>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered">160</td>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered">2</td>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered">SEER/CoC</td>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered"></td>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered"></td>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered"></td>
<td class="naaccr-summary-cell naaccr-borders naaccr-summary-centered"></td>
</tr>
</table>

<br/><strong>NAACCR XML</strong>: Patient.race1<br/><br/>
<strong>Alternate Names</strong>
<br/>
<br/>&nbsp;&nbsp;&nbsp;Race

<div class='content chap10-para-head'><strong>Description</strong></div>
<div class='content chap10-para'>
<p>Code the patient’s race. Race is coded separately from Spanish/Hispanic Origin [190]. All tumors for the same patient should have the same race codes. If the patient is multiracial, code all races using RACE 2 through RACE 5 [161-164]. For coding instructions and race code history see the current <em>SEER Program Coding and Staging Manual</em><sup>3</sup>.</p>
<p>Reference to Census 2000 definitions for ethnicity and race: <a href="http://www.census.gov/prod/cen2000/doc/sf2.pdf">http://www.census.gov/prod/cen2000/doc/sf2.pdf</a> (Appendix G).</p>

</div>

<div class='content chap10-para-head'><strong>Rationale</strong></div>
<div class='content chap10-para'>
<p>Because race has a significant association with cancer rates and outcomes, a comparison between areas with different racial distributions may require an analysis of race to interpret the findings. The race codes listed correspond closely to race categories used by the U.S. Census Bureau to allow calculation of race-specific incidence rates. The full coding system should be used to allow accurate national comparison and collaboration, even if the state population does not include many of the race categories.</p>

</div>

<div class='content chap10-para'><strong>Codes</strong></div>
<table>
<tr class='code-row'><td class='code-nbr'>01</td><td class='code-desc'>White</td></tr>
<tr class='code-row'><td class='code-nbr'>02</td><td class='code-desc'>Black or African American</td></tr>
<tr class='code-row'><td class='code-nbr'>03</td><td class='code-desc'>American Indian or Alaska Native</td></tr>
<tr class='code-row'><td class='code-nbr'>04</td><td class='code-desc'>Chinese</td></tr>
<tr class='code-row'><td class='code-nbr'>05</td><td class='code-desc'>Japanese</td></tr>
<tr class='code-row'><td class='code-nbr'>06</td><td class='code-desc'>Filipino</td></tr>
<tr class='code-row'><td class='code-nbr'>07</td><td class='code-desc'>Native Hawaiian</td></tr>
<tr class='code-row'><td class='code-nbr'>08</td><td class='code-desc'>Korean</td></tr>
<tr class='code-row'><td class='code-nbr'>10</td><td class='code-desc'>Vietnamese</td></tr>
<tr class='code-row'><td class='code-nbr'>11</td><td class='code-desc'>Laotian</td></tr>
<tr class='code-row'><td class='code-nbr'>12</td><td class='code-desc'>Hmong</td></tr>
<tr class='code-row'><td class='code-nbr'>13</td><td class='code-desc'>Cambodian</td></tr>
<tr class='code-row'><td class='code-nbr'>14</td><td class='code-desc'>Thai</td></tr>
<tr class='code-row'><td class='code-nbr'>15</td><td class='code-desc'>Asian Indian, NOS or Pakistani, NOS (code 09 prior to Version 12)</td></tr>
<tr class='code-row'><td class='code-nbr'>16</td><td class='code-desc'>Asian Indian</td></tr>
<tr class='code-row'><td class='code-nbr'>17</td><td class='code-desc'>Pakistani</td></tr>
<tr class='code-row'><td class='code-nbr'>20</td><td class='code-desc'>Micronesian, NOS</td></tr>
<tr class='code-row'><td class='code-nbr'>21</td><td class='code-desc'>Chamorro</td></tr>
<tr class='code-row'><td class='code-nbr'>22</td><td class='code-desc'>Guamanian, NOS</td></tr>
<tr class='code-row'><td class='code-nbr'>25</td><td class='code-desc'>Polynesian, NOS</td></tr>
<tr class='code-row'><td class='code-nbr'>26</td><td class='code-desc'>Tahitian</td></tr>
<tr class='code-row'><td class='code-nbr'>27</td><td class='code-desc'>Samoan</td></tr>
<tr class='code-row'><td class='code-nbr'>28</td><td class='code-desc'>Tongan</td></tr>
<tr class='code-row'><td class='code-nbr'>30</td><td class='code-desc'>Melanesian, NOS</td></tr>
<tr class='code-row'><td class='code-nbr'>31</td><td class='code-desc'>Fiji Islander</td></tr>
<tr class='code-row'><td class='code-nbr'>32</td><td class='code-desc'>Papua New Guinean</td></tr>
<tr class='code-row'><td class='code-nbr'>96</td><td class='code-desc'>Other Asian, including Asian, NOS and Oriental, NOS</td></tr>
<tr class='code-row'><td class='code-nbr'>97</td><td class='code-desc'>Pacific Islander, NOS</td></tr>
<tr class='code-row'><td class='code-nbr'>98</td><td class='code-desc'>Some other race</td></tr>
<tr class='code-row'><td class='code-nbr'>99</td><td class='code-desc'>Unknown by patient</td></tr>
</table>
126 changes: 71 additions & 55 deletions src/test/java/lab/NaaccrDocGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Pattern;
Expand All @@ -15,6 +16,7 @@
import freemarker.template.Template;
import freemarker.template.TemplateException;

import com.imsweb.layout.TestingUtils;
import com.imsweb.naaccr.api.client.NaaccrApiClient;
import com.imsweb.naaccr.api.client.entity.NaaccrAllowedCode;
import com.imsweb.naaccr.api.client.entity.NaaccrDataItem;
Expand All @@ -25,69 +27,83 @@ public class NaaccrDocGenerator {
public static void main(String[] args) throws IOException, TemplateException {
NaaccrApiClient client = NaaccrApiClient.getInstance();

NaaccrDataItem item = client.getDataItem("24", "race1");

Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();

String content = SeerUtils.readFile(new File(System.getProperty("user.dir") + "/src/test/resources/doc/naaccr-doc-template.txt"));
String style = SeerUtils.readFile(new File(System.getProperty("user.dir") + "/src/test/resources/doc/naaccr-doc-style.css"));

File outputFile = new File(System.getProperty("user.dir") + "/build/test.html");

try (FileReader reader = new FileReader(new File(System.getProperty("user.dir") + "/src/test/resources/doc/naaccr-doc-template.txt"));
FileWriter writer = new FileWriter(outputFile)) {
Template template = new Template(item.getXmlNaaccrId(), reader, null);

Map<String, Object> data = new HashMap<>();
data.put("ITEM_LENGTH", item.getItemNumber());
data.put("ITEM_NUMBER", item.getItemLength());
data.put("SOURCE_OF_STANDARD", Objects.toString(item.getSourceOfStandard(), ""));
data.put("YEAR_IMPLEMENTED", Objects.toString(item.getYearImplemented(), ""));
data.put("VERSION_IMPLEMENTED", Objects.toString(item.getVersionImplemented(), ""));
data.put("YEAR_RETIRED", Objects.toString(item.getYearRetired(), ""));
data.put("VERSION_RETIRED", Objects.toString(item.getVersionRetired(), ""));
data.put("DATA_LEVEL", item.getXmlParentId());
data.put("XML_ID", item.getXmlNaaccrId());
data.put("ALTERNATE_NAMES", item.getAlternateNames());
data.put("DESCRIPTION", cleanHtml(renderer.render(parser.parse(item.getDescription()))));
data.put("RATIONALE", cleanHtml(renderer.render(parser.parse(item.getRationale()))));
data.put("ALLOWED_CODES", item.getAllowedCodes());

template.process(data, writer);
// String test = "This is a \n \ntest...";
// System.out.println(test);
// System.out.println(renderer.render(parser.parse(test)));
// System.out.println(cleanHtml(renderer.render(parser.parse(test))));

File outputDir = new File(TestingUtils.getWorkingDirectory() + "\\src\\main\\resources\\layout\\fixed\\naaccr\\doc\\naaccr24");

for (String id : List.of("race1", "nameLast", "primarySite", "classOfCase")) {
try (FileReader reader = new FileReader(System.getProperty("user.dir") + "/src/test/resources/doc/naaccr-doc-template.txt");
FileWriter writer = new FileWriter(new File(outputDir, id + ".html"))) { // TODO FD deal with retired items

NaaccrDataItem item = client.getDataItem("24", id);

Template template = new Template(item.getXmlNaaccrId(), reader, null);

Map<String, Object> data = new HashMap<>();
data.put("ITEM_LENGTH", item.getItemLength());
data.put("ITEM_NUMBER", item.getItemNumber());
data.put("SOURCE_OF_STANDARD", Objects.toString(item.getSourceOfStandard(), ""));
data.put("YEAR_IMPLEMENTED", Objects.toString(item.getYearImplemented(), ""));
data.put("VERSION_IMPLEMENTED", Objects.toString(item.getVersionImplemented(), ""));
data.put("YEAR_RETIRED", Objects.toString(item.getYearRetired(), ""));
data.put("VERSION_RETIRED", Objects.toString(item.getVersionRetired(), ""));
data.put("DATA_LEVEL", item.getXmlParentId());
data.put("XML_ID", item.getXmlNaaccrId());
data.put("ALTERNATE_NAMES", item.getAlternateNames());
data.put("DESCRIPTION", cleanHtml(renderer.render(parser.parse(item.getDescription()))));
if (item.getRationale() != null)
data.put("RATIONALE", cleanHtml(renderer.render(parser.parse(item.getRationale()))));
if (item.getAllowedCodes() != null) {
for (NaaccrAllowedCode code : item.getAllowedCodes()) {
if (code.getCode() == null)
code.setCode("");
if (code.getDescription() == null)
code.setDescription("");
}
data.put("ALLOWED_CODES", item.getAllowedCodes());
}

template.process(data, writer);
}
}

// // TODO FD deal with replacing special characters in HTML... (see race1 for an example of a quote)

// StringBuilder buf = new StringBuilder();
// buf.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
// buf.append("\n");
// buf.append("<html>\n");
// buf.append("\n");
// buf.append("<head>\n");
// buf.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n");
// buf.append("<title>").append(item.getItemName().replace("&", "&amp;")).append("</title>\n");
// buf.append("<style>\n");
// buf.append("body { padding:5px; font-family:Tahoma; font-size: 14px; }\n");
// buf.append("h1 { font-size:14px; margin-top:0px; }\n");
// buf.append(style);
// buf.append("</style>\n");
// buf.append("</head>\n");
// buf.append("\n");
// buf.append("<body>\n");
// buf.append("\n");
// buf.append("<h1>").append(item.getItemName().replace("&", "&amp;")).append("</h1>\n");
// buf.append("\n");
// buf.append(content);
// buf.append("</body>\n");
// buf.append("</html>\n");
//
// SeerUtils.writeFile(buf.toString(), new File(System.getProperty("user.dir") + "/build/test.html"));
// // TODO FD deal with replacing special characters in HTML... (see race1 for an example of a quote)

// StringBuilder buf = new StringBuilder();
// buf.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n");
// buf.append("\n");
// buf.append("<html>\n");
// buf.append("\n");
// buf.append("<head>\n");
// buf.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n");
// buf.append("<title>").append(item.getItemName().replace("&", "&amp;")).append("</title>\n");
// buf.append("<style>\n");
// buf.append("body { padding:5px; font-family:Tahoma; font-size: 14px; }\n");
// buf.append("h1 { font-size:14px; margin-top:0px; }\n");
// buf.append(style);
// buf.append("</style>\n");
// buf.append("</head>\n");
// buf.append("\n");
// buf.append("<body>\n");
// buf.append("\n");
// buf.append("<h1>").append(item.getItemName().replace("&", "&amp;")).append("</h1>\n");
// buf.append("\n");
// buf.append(content);
// buf.append("</body>\n");
// buf.append("</html>\n");
//
// SeerUtils.writeFile(buf.toString(), new File(System.getProperty("user.dir") + "/build/test.html"));
}

private static String cleanHtml(String html) {
html = Pattern.compile("^<p>").matcher(html).replaceAll("");
html = Pattern.compile("</p>$").matcher(html).replaceAll("");
//html = Pattern.compile("^<p>").matcher(html).replaceAll("");
//html = Pattern.compile("</p>$").matcher(html).replaceAll("");

html = Pattern.compile("\\^(\\d+)\\^").matcher(html).replaceAll("<sup>$1</sup>");

Expand Down
7 changes: 4 additions & 3 deletions src/test/java/lab/NaaccrDocViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@
@SuppressWarnings({"ConstantConditions", "FieldCanBeLocal", "SameParameterValue"})
public class NaaccrDocViewer extends JFrame {

private static final File _DIR = new File(TestingUtils.getWorkingDirectory() + "\\src\\main\\resources\\layout\\fixed\\naaccr\\doc\\naaccr23");
private static final File _DIR = new File(TestingUtils.getWorkingDirectory() + "\\src\\main\\resources\\layout\\fixed\\naaccr\\doc\\naaccr24");

private static final List<Layout> _LAYOUTS = new ArrayList<>();

static {
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_24));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_23));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_22));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_21));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_18));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_16));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_15));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_XML_14));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_13));
_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_12));
//_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_13));
//_LAYOUTS.add(LayoutFactory.getLayout(LayoutFactory.LAYOUT_ID_NAACCR_12));
}

private static final Boolean _SORT_BY_ITEM_NUMBER = false;
Expand Down
18 changes: 10 additions & 8 deletions src/test/resources/doc/naaccr-doc-template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@
</table>

<br/><strong>NAACCR XML</strong>: ${DATA_LEVEL}.${XML_ID}<br/><br/>

<#if (ALTERNATE_NAMES??)>
<strong>Alternate Names</strong>
<br/>
<#list ALTERNATE_NAMES as name >
<br/>&nbsp;&nbsp;&nbsp;${name}
<br/>&nbsp;&nbsp;&nbsp;${name}
</#list>
</#if>

<br/>
<br/>
<div class='content chap10-para-head'><strong>Description</strong></div>
<div class='content chap10-para'>${DESCRIPTION}</div>
<div class='content chap10-para'>
${DESCRIPTION}
</div>

<#if (RATIONALE??)>
<div class='content chap10-para-head'><strong>Rationale</strong></div>
<div class='content chap10-para'>${RATIONALE}</div>
<div class='content chap10-para'>
${RATIONALE}
</div>
</#if>

<#if (ALLOWED_CODES??)>
<br/>
<br/>
<div class='content chap10-para'><strong>Codes</strong></div>
<table>
<#list ALLOWED_CODES as code >
Expand Down

0 comments on commit aee197f

Please sign in to comment.