Skip to content

Commit

Permalink
Fix for LinuxForHealth#512 StringIndexOutOfBoundsException is thrown …
Browse files Browse the repository at this point in the history
…while converting NTE segments with additional dash.

Added fail-safe check for last index in substring method.

Added test.
  • Loading branch information
Sharma, Shubham {DIDE~Pune} committed Aug 22, 2024
1 parent edaefc2 commit e513b11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static Message getHl7Message(String data) {
} else {
int firstDash = line.indexOf("-");
// Added fail-safe check if the content after "-" is less than 5 characters
int lastContentIndex = Math.min(firstDash + 5, line.length() - 1);
int lastContentIndex = Math.min(firstDash + 5, line.length());
output.append(line.substring(0, lastContentIndex));
}
output.append("\n");
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/io/github/linuxforhealth/FHIRConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,26 @@ void testCodingSystems() throws FHIRException {
assertThat(coding.getSystem()).isEqualTo("http://terminology.hl7.org/CodeSystem/v2-0163");
}

@Test
void test_nte_split_print_structure_on_dash(){
String hl7message = "MSH|^~\\&|Lab|Lab|GeneralHosp|MySys|202408160605-1000||ORU^R01|218374717|P|2.3|\n" +
"PID|1||||||||123|\n" +
"ORC|RE||123|\n" +
"OBR|1||123|456||||||||||||||||||202408160605-1000|||F|||||\n" +
"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" +
"NTE|1|#9151E| |\n" +
"NTE|2|#9151E|LDL and Non-HDL Cholesterol goals based on level of risk:|\n" +
"NTE|3|#9151E| |\n" +
"NTE|4|#9151E| LDL NON-HDL|\n" +
"NTE|5|#9151E| ------------------------|\n" +
"SPM|1|YF123321||123456^Specimen (specimen)^SCT|||||||||||||202408180502-1000|202408180531-1000|";

Bundle b = ftv.convertToBundle(hl7message, OPTIONS, null);

assertThat(b.getType()).isEqualTo(BundleType.COLLECTION);

}

private void verifyResult(String json, BundleType expectedBundleType) {
verifyResult(json, expectedBundleType, true);
}
Expand Down

0 comments on commit e513b11

Please sign in to comment.