Skip to content

Commit 6a2b763

Browse files
ssharma5LisaWellman
authored andcommitted
Fix for #512 StringIndexOutOfBoundsException is thrown while converting NTE segments with additional dash.
Added fail-safe check for last index in substring method. Signed-off-by: Shubham Sharma <shubham.nksharma@gmail.com>
1 parent 66bd894 commit 6a2b763

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/io/github/linuxforhealth/hl7/HL7ToFHIRConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ private static Message getHl7Message(String data) {
185185
output.append(line);
186186
} else {
187187
int firstDash = line.indexOf("-");
188-
output.append(line.substring(0, firstDash + 5));
188+
// Added fail-safe check if the content after "-" is less than 5 characters
189+
int lastContentIndex = Math.min(firstDash + 5, line.length());
190+
output.append(line.substring(0, lastContentIndex));
189191
}
190192
output.append("\n");
191193
}

src/test/java/io/github/linuxforhealth/FHIRConverterTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,25 @@ void testCodingSystems() throws FHIRException {
324324
assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0163");
325325
}
326326

327+
@Test
328+
void test_nte_split_print_structure_on_dash(){
329+
String hl7message = "MSH|^~\\&|Lab|Lab|GeneralHosp|MySys|202408160605-1000||ORU^R01|218374717|P|2.3|\n" +
330+
"PID|1||||||||123|\n" +
331+
"ORC|RE||123|\n" +
332+
"OBR|1||123|456||||||||||||||||||202408160605-1000|||F|||||\n" +
333+
"OBX|1|NM|1894^Non-HDL Cholesterol, calc^43396-1^1894||180|mg/dL|<130 optimal|H|||F|||202408160605-1000|12D0620420^General's Hospital|%AUTO^%AUTO^2|\n" +
334+
"NTE|1|#9151E| |\n" +
335+
"NTE|2|#9151E|LDL and Non-HDL Cholesterol goals based on level of risk:|\n" +
336+
"NTE|3|#9151E| |\n" +
337+
"NTE|4|#9151E| LDL NON-HDL|\n" +
338+
"NTE|5|#9151E| ------------------------|\n" +
339+
"SPM|1|YF123321||123456^Specimen (specimen)^SCT|||||||||||||202408180502-1000|202408180531-1000|";
340+
341+
Bundle b = ftv.convertToBundle(hl7message, OPTIONS, null);
342+
343+
assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);
344+
}
345+
327346
private void verifyResult(String json, BundleType expectedBundleType) {
328347
verifyResult(json, expectedBundleType, true);
329348
}

0 commit comments

Comments
 (0)