Skip to content

Commit

Permalink
Added new param to force a specs version (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
depryf committed Feb 9, 2024
1 parent c9ca011 commit 63137c6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/sas/macro/write_naaccr_xml_macro.sas
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%MACRO writeNaaccrXml(libpath, targetfile, naaccrversion="", recordtype="", dataset=alldata, items="", dictfile="", dictUri="", writenum="no", cleanuptempfiles="yes", grouptumors="yes");
%MACRO writeNaaccrXml(libpath, targetfile, naaccrversion="", recordtype="", dataset=alldata, items="", dictfile="", dictUri="", writenum="no", cleanuptempfiles="yes", grouptumors="yes", specs="");

/************************************************************************************************************;
This macro writes a given data fileset into a NAACCR XML data file.
Expand Down Expand Up @@ -43,6 +43,8 @@
- grouptumors should be "yes" or "no" (defaults to "yes"); if "yes" then the tumors that have the same
patient ID number (and appearing together in the observations) will be grouped under one Patient tag;
if "no", each tumor will appear under its own Patient tag (and every Patient will contain exactly one Tumor).
- specs is the specifications version to write to the data file (typically something like X.X); it's optional
and the library default value is used if not provided.
Note that the macro creates a temp fixed-column and input SAS format file in the same folder as the target file;
Expand Down Expand Up @@ -75,6 +77,7 @@
12/14/2021 - Fabian Depry - Added new optional grouptumors parameter to allow not grouping the tumors.
06/04/2023 - Fabian Depry - Re-wrote the macro to use a temp fixed-column file instead of a temp CSV file.
06/22/2023 - Fabian Depry - Renamed cleanupcsv parameter to cleanuptempfiles
08/09/2024 - Fabian Depry - Added new optional specs parameter to allow forcing a specific version to be written.
************************************************************************************************************/;

/*
Expand Down Expand Up @@ -131,6 +134,7 @@ data _null_;
j1.callVoidMethod('setDictionary', &dictfile, &dicturi);
j1.callVoidMethod('setWriteNumbers', &writenum);
j1.callVoidMethod('setGroupTumors', &grouptumors);
j1.callVoidMethod('setSpecificationsVersion', &specs);
j1.callVoidMethod('convert', &items);
j1.callVoidMethod('cleanup', &cleanuptempfiles);
j1.delete();
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/imsweb/naaccrxml/sas/SasCsvToXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class SasCsvToXml {

private boolean _groupTumors;

private String _specificationsVersion;

public SasCsvToXml(String xmlPath, String naaccrVersion, String recordType) {
this(SasUtils.computeCsvPathFromXmlPath(xmlPath), xmlPath, naaccrVersion, recordType);
}
Expand Down Expand Up @@ -116,6 +118,14 @@ public void setDictionary(String dictionaryPath, String dictionaryUri) {
}
}

/**
* The specificatoins version to use when writting the XML data.
*/
public void setSpecificationsVersion(String specificationsVersion) {
if (specificationsVersion != null && !specificationsVersion.trim().isEmpty())
_specificationsVersion = specificationsVersion;
}

public String getCsvPath() {
return _csvFile.getAbsolutePath();
}
Expand Down Expand Up @@ -231,7 +241,10 @@ else if ("Tumor".equals(field.getParentTag()))
if (!_dictionaryFiles.isEmpty() && _dictionaryUris != null && !_dictionaryUris.trim().isEmpty())
writer.write("\n userDictionaryUri=\"" + _dictionaryUris + "\"");
writer.write("\n recordType=\"" + _recordType + "\"");
writer.write("\n specificationVersion=\"1.7\"");
if (_specificationsVersion != null)
writer.write("\n specificationVersion=\"" + _specificationsVersion + "\"");
else
writer.write("\n specificationVersion=\"1.7\"");
writer.write("\n xmlns=\"http://naaccr.org/naaccrxml\"");
writer.write(">\n");
for (Entry<String, String> entry : rootFields.entrySet()) {
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/imsweb/naaccrxml/sas/SasFlatToXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class SasFlatToXml {
// the CSV list of fields contained in the data set
private String _dataSetFields;

// the (optional) specifications verison to use (uses the default library one if not provided)
private String _specificationsVersion;

/**
* Constructor.
*/
Expand Down Expand Up @@ -164,6 +167,14 @@ public void setDictionary(String dictionaryPath, String dictionaryUri) {
}
}

/**
* The specificatoins version to use when writting the XML data.
*/
public void setSpecificationsVersion(String specificationsVersion) {
if (specificationsVersion != null && !specificationsVersion.trim().isEmpty())
_specificationsVersion = specificationsVersion;
}

/**
* Returns the user-defined dictionaries.
*/
Expand Down Expand Up @@ -415,7 +426,10 @@ else if (line.length() < expectedLineLength) {
if (!_dictionaryFiles.isEmpty() && _dictionaryUris != null && !_dictionaryUris.trim().isEmpty())
writer.write("\n userDictionaryUri=\"" + _dictionaryUris + "\"");
writer.write("\n recordType=\"" + _recordType + "\"");
writer.write("\n specificationVersion=\"1.7\"");
if (_specificationsVersion != null)
writer.write("\n specificationVersion=\"" + _specificationsVersion + "\"");
else
writer.write("\n specificationVersion=\"1.7\"");
writer.write("\n xmlns=\"http://naaccr.org/naaccrxml\"");
writer.write(">\n");
for (Entry<String, SasFieldInfo> entry : rootFields.entrySet()) {
Expand Down

0 comments on commit 63137c6

Please sign in to comment.