Skip to content

Commit

Permalink
Moved logic in HL7Parser.parsePath to HL7Path.parse to avoid circular…
Browse files Browse the repository at this point in the history
… dependency
  • Loading branch information
basiliskus committed Dec 23, 2024
1 parent e350ce1 commit 466c3f4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rs-e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Information on how to set up the sample files evaluated by the tests can be foun

- The output files generated by the framework are stored in an Azure blob storage container. Every time the tests are run, a cleanup task moves the files to a folder with the year/month/day format for better organization. The files are retained in the container for 90 days before being deleted
- The code that organizes the files is using EST time zone. This means that if you are in PST, you may run into an issue if you submit a run before 9 PM PST and then run the tests after 9pm. You'd need to make sure to run both tasks before or after 9pm so the files are where they are expected to be
- The HL7 parser and expression evaluator returns an empty string when the value is not found. It will only throw an exception if the path is not valid
- The HL7 parser and expression evaluator returns an empty string when the value is not found. It will only throw an exception if the path is not a valid HL7 notation

## Running the tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public HL7Segment getSegment(String name) throws HL7MessageException {
}

public String getValue(String path) throws HL7MessageException {
HL7Path hl7Path = HL7Parser.parsePath(path);
HL7Path hl7Path = HL7Path.parse(path);
int[] indices = hl7Path.indices();
List<String> fields = this.getSegment(hl7Path.segmentName()).fields();
char[] delimiters = this.getEncoding().getOrderedDelimiters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** The HL7Parser class is responsible for parsing HL7 messages and extracting values from them. */
public class HL7Parser {
static final String MSH_SEGMENT_NAME = "MSH";
static final String NEWLINE_REGEX = "\\r?\\n|\\r";
static final Pattern HL7_FIELD_NAME_PATTERN = Pattern.compile("(\\w+)-(\\d+(?:\\.\\d+)*)");

private HL7Parser() {}

Expand All @@ -37,19 +35,6 @@ public static HL7Message parseMessage(String content) {
return new HL7Message(segments, HL7Encoding.fromEncodingField(encodingCharactersField));
}

public static HL7Path parsePath(String path) {
Matcher matcher = HL7_FIELD_NAME_PATTERN.matcher(path);
if (!matcher.matches()) {
throw new HL7ParserException("Invalid HL7 path format: " + path);
}

String segmentName = matcher.group(1);
int[] indices =
Arrays.stream(matcher.group(2).split("\\.")).mapToInt(Integer::parseInt).toArray();

return new HL7Path(segmentName, indices);
}

public static String segmentToString(HL7Segment segment, HL7Encoding encoding) {
String fieldSeparator = String.valueOf(encoding.getFieldDelimiter());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

import java.util.Arrays;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** The HL7Path class represents a path to a specific field in an HL7 message. */
public record HL7Path(String segmentName, int[] indices) {
static final Pattern HL7_FIELD_NAME_PATTERN = Pattern.compile("(\\w+)-(\\d+(?:\\.\\d+)*)");

public static HL7Path parse(String path) {
Matcher matcher = HL7_FIELD_NAME_PATTERN.matcher(path);
if (!matcher.matches()) {
throw new HL7ParserException("Invalid HL7 path format: " + path);
}

String segmentName = matcher.group(1);
int[] indices =
Arrays.stream(matcher.group(2).split("\\.")).mapToInt(Integer::parseInt).toArray();

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.

return new HL7Path(segmentName, indices);
}

// Need to override equals, hashCode, and toString to handle array comparison
@Override
Expand Down

0 comments on commit 466c3f4

Please sign in to comment.