Skip to content

Commit

Permalink
Better handling of a template data mismatch error case (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
psapozh82 authored Dec 6, 2024
1 parent 88a84ed commit 066edf0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Health.Fhir.Liquid.Converter.Exceptions;
using Microsoft.Health.Fhir.Liquid.Converter.Models.Hl7v2;
using Microsoft.Health.Fhir.Liquid.Converter.Parsers;
using Xunit;
Expand Down Expand Up @@ -45,7 +46,7 @@ public void GivenAnHl7v2Data_WhenGetFirstSegments_CorrectResultShouldBeReturned(
Assert.True(!segments.ContainsKey("PV1"));

// Hl7v2Data and segment id content could not be null
Assert.Throws<NullReferenceException>(() => Filters.GetFirstSegments(null, "PID"));
Assert.Throws<TemplateLoadException>(() => Filters.GetFirstSegments(null, "PID"));
Assert.Throws<NullReferenceException>(() => Filters.GetFirstSegments(new Hl7v2Data(), null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Health.Fhir.Liquid.Converter.Exceptions;
using Microsoft.Health.Fhir.Liquid.Converter.Models;
using Microsoft.Health.Fhir.Liquid.Converter.Models.Hl7v2;

namespace Microsoft.Health.Fhir.Liquid.Converter
Expand All @@ -17,6 +19,11 @@ public partial class Filters
{
public static Dictionary<string, Hl7v2Segment> GetFirstSegments(Hl7v2Data hl7v2Data, string segmentIdContent)
{
if (hl7v2Data == null)
{
throw new TemplateLoadException(FhirConverterErrorCode.TemplateDataMismatch, "Incorrect template was passed in for the input data format.");
}

var result = new Dictionary<string, Hl7v2Segment>();
var segmentIds = segmentIdContent.Split(@"|");
for (var i = 0; i < hl7v2Data.Meta.Count; ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum FhirConverterErrorCode
InvalidCodeMapping = 1103,
TemplateSyntaxError = 1104,
InvalidJsonSchema = 1105,
TemplateDataMismatch = 1106,

// DataParseException
InputParsingError = 1201,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ protected string RenderTemplates(Template template, Context context)
{
throw;
}
catch (TemplateLoadException)
{
throw;
}
catch (Exception ex)
{
throw new RenderException(FhirConverterErrorCode.TemplateRenderingError, string.Format(Resources.TemplateRenderingError, ex.Message), ex);
Expand Down

0 comments on commit 066edf0

Please sign in to comment.