Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: ayushgarg0694 <ayushgarg0694@gmail.com>
  • Loading branch information
ayushgarg0694 authored and LisaWellman committed Jan 14, 2022
1 parent 4339970 commit ab6f3cf
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/main/java/io/github/linuxforhealth/hl7/HL7ToFHIRConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,10 @@ public String convert(String hl7MessageData) {
* @throws UnsupportedOperationException - if message type is not supported
*/
public String convert(String hl7MessageData, ConverterOptions options) {
Preconditions.checkArgument(StringUtils.isNotBlank(hl7MessageData),
"Input HL7 message cannot be blank");
Preconditions.checkArgument(options != null, "options cannot be null.");
FHIRContext context = new FHIRContext(options.isPrettyPrint(), options.isValidateResource());
HL7MessageEngine engine = new HL7MessageEngine(context, options.getBundleType());

Message hl7message = getHl7Message(hl7MessageData);
if (hl7message != null) {
String messageType = HL7DataExtractor.getMessageType(hl7message);
HL7MessageModel hl7MessageTemplateModel = messagetemplates.get(messageType);
if (hl7MessageTemplateModel != null) {
Bundle bundle = hl7MessageTemplateModel.convert(hl7message, engine);
return engine.getFHIRContext().encodeResourceToString(bundle);
} else {
throw new UnsupportedOperationException("Message type not yet supported " + messageType);
}
} else {
throw new IllegalArgumentException("Parsed HL7 message was null.");
}
HL7MessageEngine engine = getMessageEngine(options);
Bundle bundle = convertToBundle(hl7MessageData, options);
return engine.getFHIRContext().encodeResourceToString(bundle);
}

/**
Expand All @@ -149,9 +134,7 @@ public String convert(String hl7MessageData, ConverterOptions options) {
public Bundle convertToBundle(String hl7MessageData, ConverterOptions options) {
Preconditions.checkArgument(StringUtils.isNotBlank(hl7MessageData),
"Input HL7 message cannot be blank");
Preconditions.checkArgument(options != null, "options cannot be null.");
FHIRContext context = new FHIRContext(options.isPrettyPrint(), options.isValidateResource());
HL7MessageEngine engine = new HL7MessageEngine(context, options.getBundleType());
HL7MessageEngine engine = getMessageEngine(options);

Message hl7message = getHl7Message(hl7MessageData);
if (hl7message != null) {
Expand All @@ -167,6 +150,13 @@ public Bundle convertToBundle(String hl7MessageData, ConverterOptions options) {
}
}

private HL7MessageEngine getMessageEngine(ConverterOptions options){
Preconditions.checkArgument(options != null, "options cannot be null.");
FHIRContext context = new FHIRContext(options.isPrettyPrint(), options.isValidateResource());

return new HL7MessageEngine(context, options.getBundleType());
}

private static Message getHl7Message(String data) {
Message hl7message = null;
try (InputStream ins = IOUtils.toInputStream(data, StandardCharsets.UTF_8)) {
Expand Down

0 comments on commit ab6f3cf

Please sign in to comment.