-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new filter - splitDataBySegments (#344)
- Loading branch information
1 parent
2bb197d
commit fc949c7
Showing
5 changed files
with
157 additions
and
2 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
41 changes: 41 additions & 0 deletions
41
src/Microsoft.Health.Fhir.Liquid.Converter.UnitTests/Utilities/Hl7v2DataUtilityTests.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; | ||
using Microsoft.Health.Fhir.Liquid.Converter.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Liquid.Converter.UnitTests.Utilities | ||
{ | ||
public class Hl7v2DataUtilityTests | ||
{ | ||
[Fact] | ||
public void GivenValidMessage_WhenSplitMessageToSegments_CorrectResultShouldBeReturned() | ||
{ | ||
string[] testMessage = | ||
{ | ||
"\r\nMSH|^~\\&|test\r\nPID|test\r\n\r\nPD1|test\r\nPD1|test\r\n", | ||
"\rMSH|^~\\&|test\rPID|test\r\rPD1|test\rPD1|test\r", | ||
"\nMSH|^~\\&|test\nPID|test\n\nPD1|test\nPD1|test\n", | ||
"\nMSH|^~\\&|test\r\nPID|test\r\r\nPD1|test\r\n\nPD1|test\r\n", | ||
}; | ||
|
||
foreach (string message in testMessage) | ||
{ | ||
string[] segments = Hl7v2DataUtility.SplitMessageToSegments(message); | ||
Assert.Equal(4, segments.Length); | ||
Assert.Equal("MSH|^~\\&|test", segments[0]); | ||
Assert.Equal("PID|test", segments[1]); | ||
Assert.Equal("PD1|test", segments[2]); | ||
Assert.Equal("PD1|test", segments[3]); | ||
} | ||
|
||
Assert.Empty(Hl7v2DataUtility.SplitMessageToSegments(string.Empty)); | ||
|
||
// message could not be null | ||
Assert.Throws<NullReferenceException>(() => Hl7v2DataUtility.SplitMessageToSegments(null)); | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/Microsoft.Health.Fhir.Liquid.Converter/Utilities/Hl7v2DataUtility.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,22 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Microsoft.Health.Fhir.Liquid.Converter.Utilities | ||
{ | ||
public static class Hl7v2DataUtility | ||
{ | ||
private static readonly string[] SegmentSeparators = { "\r\n", "\r", "\n" }; | ||
|
||
public static string[] SplitMessageToSegments(string message) | ||
{ | ||
var segments = message.Split(SegmentSeparators, StringSplitOptions.RemoveEmptyEntries); | ||
return segments; | ||
} | ||
} | ||
} |