diff --git a/CHANGELOG.md b/CHANGELOG.md index f1806c4..89b93d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ **Version 10.2** - Changed data level errors from an exception to a validation error reported on the item. +- Fixed behavior of the reading SAS macro when it deals with fields that have a value too long in the XML file. **Version 10.1** diff --git a/src/main/java/com/imsweb/naaccrxml/sas/SasXmlToFlat.java b/src/main/java/com/imsweb/naaccrxml/sas/SasXmlToFlat.java index e5dcd4e..fd3805f 100644 --- a/src/main/java/com/imsweb/naaccrxml/sas/SasXmlToFlat.java +++ b/src/main/java/com/imsweb/naaccrxml/sas/SasXmlToFlat.java @@ -395,17 +395,23 @@ protected boolean removeEldestEntry(Map.Entry eldest) { buf.append(paddedValue); } else { - int remainingLength = entry.getValue().getLength() - val.length(); - if (remainingLength > 0) { - String remainingValue = cache2.get(remainingLength); - if (remainingValue == null) { - remainingValue = SasUtils.rightPadWithSpaces("", remainingLength); - cache2.put(remainingLength, remainingValue); + int defLength = entry.getValue().getLength(); + + if (val.length() > defLength) + buf.append(val.substring(0, defLength)); + else { + int remainingLength = defLength - val.length(); + if (remainingLength > 0) { + String remainingValue = cache2.get(remainingLength); + if (remainingValue == null) { + remainingValue = SasUtils.rightPadWithSpaces("", remainingLength); + cache2.put(remainingLength, remainingValue); + } + buf.append(val).append(remainingValue); } - buf.append(val).append(remainingValue); + else + buf.append(val); } - else - buf.append(val); } } writer.write(buf.toString());