-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DotLiquid] Add TraceInfo for HL7 v2 conversion (#123)
* Add unused segments as the one in Handlebars * Merge and solve conflict * Add index in output and refine code * Simplify output trace info * Add end index and make them readonly Co-authored-by: Qiwei Jin <qiwjin@microsoft.com>
- Loading branch information
Showing
27 changed files
with
409 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Extensions/StringExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Health.Fhir.Liquid.Converter.Extensions; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests.Extensions | ||
{ | ||
public class StringExtensionsTests | ||
{ | ||
public static IEnumerable<object[]> GetIndexOfNthOccurrenceData() | ||
{ | ||
// Null or empty string or char | ||
yield return new object[] { null, null, 1, -1 }; | ||
yield return new object[] { string.Empty, null, 1, -1 }; | ||
yield return new object[] { "abc|abc", null, 1, -1 }; | ||
|
||
// Nth occurrence smaller than one | ||
yield return new object[] { "abc|abc", '|', 0, -1 }; | ||
yield return new object[] { "abc|abc", '|', -1, -1 }; | ||
|
||
// Nth occurrence hit | ||
yield return new object[] { "abc|abc", '|', 1, 3 }; | ||
yield return new object[] { "abc|abc|abc", '|', 2, 7 }; | ||
|
||
// Nth occurrence not hit | ||
yield return new object[] { "abc|abc", '|', 3, -1 }; | ||
yield return new object[] { "abc|abc", '^', 1, -1 }; | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(GetIndexOfNthOccurrenceData))] | ||
public void IndexOfNthOccurrenceTests(string s, char c, int n, int expected) | ||
{ | ||
Assert.Equal(expected, s.IndexOfNthOccurrence(c, n)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Hl7v2/Models/Hl7v2TraceInfoTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Health.Fhir.Liquid.Converter.Hl7v2; | ||
using Microsoft.Health.Fhir.Liquid.Converter.Hl7v2.Models; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests.Hl7v2.Models | ||
{ | ||
public class Hl7v2TraceInfoTests | ||
{ | ||
[Fact] | ||
public void GivenHl7v2Data_WhenCreate_CorrectHl7v2TraceInfoShouldBeReturned() | ||
{ | ||
// Null Hl7v2Data | ||
var traceInfo = Hl7v2TraceInfo.CreateTraceInfo(null); | ||
Assert.Empty(traceInfo.UnusedSegments); | ||
|
||
// Empty Hl7v2Data | ||
var data = new Hl7v2Data(); | ||
traceInfo = Hl7v2TraceInfo.CreateTraceInfo(data); | ||
Assert.Empty(traceInfo.UnusedSegments); | ||
|
||
// Null data | ||
data = new Hl7v2Data() | ||
{ | ||
Meta = null, | ||
Data = null, | ||
}; | ||
traceInfo = Hl7v2TraceInfo.CreateTraceInfo(data); | ||
Assert.Empty(traceInfo.UnusedSegments); | ||
|
||
// Null segment | ||
data = new Hl7v2Data() | ||
{ | ||
Meta = new List<string>() { null }, | ||
Data = new List<Hl7v2Segment>() { null }, | ||
}; | ||
traceInfo = Hl7v2TraceInfo.CreateTraceInfo(data); | ||
Assert.Empty(traceInfo.UnusedSegments); | ||
|
||
// Valid Hl7v2Data before render | ||
var content = @"MSH|^~\&|AccMgr|1|||20050110045504||ADT^A01|599102|P|2.3||| | ||
PID|1||10006579^^^1^MR^1||DUCK^DONALD^D||19241010|M||1|111 DUCK ST^^FOWL^CA^999990000^^M|1|8885551212|8885551212|1|2||40007716^^^AccMgr^VN^1|123121234|||||||||||NO "; | ||
var parser = new Hl7v2DataParser(); | ||
data = parser.Parse(content); | ||
traceInfo = Hl7v2TraceInfo.CreateTraceInfo(data); | ||
Assert.Equal(2, traceInfo.UnusedSegments.Count); | ||
Assert.Equal(27, traceInfo.UnusedSegments[1].Components.Count); | ||
|
||
// Valid Hl7v2Data after render | ||
var processor = new Hl7v2Processor(); | ||
var templateProvider = new Hl7v2TemplateProvider(Constants.Hl7v2TemplateDirectory); | ||
_ = processor.Convert(content, "ADT_A01", templateProvider, traceInfo); | ||
Assert.Equal(2, traceInfo.UnusedSegments.Count); | ||
|
||
var unusedPid = traceInfo.UnusedSegments[1]; | ||
Assert.Equal("PID", unusedPid.Type); | ||
Assert.Equal(1, unusedPid.Line); | ||
Assert.Equal(6, unusedPid.Components.Count); | ||
Assert.Equal(118, unusedPid.Components[2].Start); | ||
Assert.Equal(126, unusedPid.Components[2].End); | ||
Assert.Equal("40007716", unusedPid.Components[2].Value); | ||
} | ||
} | ||
} |
Oops, something went wrong.