Skip to content

Commit

Permalink
Add support for basic validation when reading files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinJSoles committed Jan 12, 2022
1 parent 3a1acd3 commit 25e99eb
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Madjic.Edi.Dom.Tests/Madjic.Edi.Dom.Tests.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<None Update="samples\Test270.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="samples\Test271.BadTS.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="samples\test271.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
24 changes: 24 additions & 0 deletions Madjic.Edi.Dom.Tests/TestBasicFileParsing.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ Public Class TestBasicFileParsing
".\samples\Test837P.txt",
".\samples\Test999.txt"}

<TestMethod()> Async Function TestBadTransactionSet() As Task
Dim Doc As Document

Using stream As New IO.FileStream(".\Samples\Test271.BadTS.txt", IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
Doc = Await Document.FromStreamAsync(stream)
End Using

Assert.AreEqual(1, Doc.Envelopes.Count)
Assert.AreEqual(1, Doc.Envelopes(0).FunctionalGroups.Count)
Assert.AreEqual(3, Doc.Envelopes(0).FunctionalGroups(0).Transactions.Count)

For Each ts In Doc.Envelopes(0).FunctionalGroups(0).Transactions
Assert.IsInstanceOfType(ts, GetType(Transactions.Transaction271.Transaction271_B1.TransactionSet))
Next

Dim ShouldBeBad() = {True, False, False}

For i = 0 To 2
Dim ts = Doc.Envelopes(0).FunctionalGroups(0).Transactions(i)

Assert.AreEqual(ShouldBeBad(i), ts.HasReaderErrors, $"Transaction set #{i + 1}.")
Next
End Function

<TestMethod()> Async Function TestAllFileImplementations() As Task
Dim Doc As Document
Dim ExpectedTypes() As Type = {
Expand Down
57 changes: 57 additions & 0 deletions Madjic.Edi.Dom.Tests/samples/Test271.BadTS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ISA*00* *00* *ZZ*263086998 *ZZ*93323767 *220107*0600*^*00501*000032146*0*P*:~
GS*HB*263086998*93323767*20220107*0600*32146*X*005010X279A1~
ST*271*0001*005010X279A1~
BHT*0022*11*32146.0001*20220107*050035~
HL*1**20*1~
NM1*PR*2*MEDICARE CGS - REGION C*****PI*MEDX~
HL*2*1*21*1~
NM1*1P*2*MY PROVIDER COMPANY*****XX*1234567890~
HL*3*2*22*0~
TRN*1*123456789*CLEARINGHOUSE~
TRN*2*PATIENTID*1234567890~
NM1*IL*1*LAST*FIRST****MI*123456~
DMG*D8*19810102~
DTP*291*D8*20220101~
AAA*Y**72*C~
SE*14*0001~
ST*271*0001*005010X279A1~
BHT*0022*11*32146.0001*20220107*050419~
HL*1**20*1~
NM1*PR*2*CMS*****PI*MEDX~
HL*2*1*21*1~
NM1*1P*2*MY PROVIDER COMPANY*****XX*1234567890~
HL*3*2*22*0~
TRN*1*12345678A*CLGHOUSE~
TRN*2*PATIENT2*0123456789~
NM1*IL*1*LAST*FIRST*J***MI*MEM001~
N3*123 MAIN ST~
N4*TAMPA*FL*336198300~
DMG*D8*19500101*F~
DTP*307*D8*20220102~
EB*I**41^54~
EB*1**88~
EB*1**30^10^42^45^48^49^69^76^83^A5^A7^AG^BT^BU^BV*MA~
DTP*291*D8*20150401~
MSG*0-Beneficiary insured due to age OASI~
LS*2120~
NM1*PR*2*BLUE CROSS AND BLUE SHIELD OF FLORIDA, INC.~
N3*4800 Deerwood Campus Parkway~
N4*Jacksonville*FL*32246~
PER*IC**TE*8009266565*UR*www.floridablue.com/medicare~
LE*2120~
SE*26*0001~
ST*271*0001*005010X279A1~
BHT*0022*11*32146.0001*20220107*050035~
HL*1**20*1~
NM1*PR*2*MEDICARE CGS - REGION C*****PI*MEDX~
HL*2*1*21*1~
NM1*1P*2*MY PROVIDER COMPANY*****XX*1234567890~
HL*3*2*22*0~
TRN*1*123456789*CLEARINGHOUSE~
TRN*2*PATIENTID*1234567890~
NM1*IL*1*LAST*FIRST****MI*123456~
DMG*D8*19810102~
DTP*291*D8*20220101~
SE*13*0001~
GE*3*32146~
IEA*1*000032146~
2 changes: 2 additions & 0 deletions Madjic.Edi.Dom/Document.vb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
.Implementation = ReaderFactory.GetImplementationKey(rval.VersionCode, rval.TransactionSetIdCode, grp.FunctionalIdCode)
}
Await rval.ReadAsync(args).ConfigureAwait(False)

CType(rval, TransactionSet).HasReaderErrors = args.DataSegment IsNot Nothing AndAlso String.Compare(args.DataSegment.SegmentID, "SE", StringComparison.OrdinalIgnoreCase) <> 0
End If

Return rval
Expand Down
9 changes: 6 additions & 3 deletions Madjic.Edi.Dom/Madjic.Edi.Dom.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/MartinJSoles/Madjic.Edi</RepositoryUrl>
<PackageTags>HIPAA, EDI, ANSI X12</PackageTags>
<PackageReleaseNotes>This is a servicing release. The only change made is a recompilation for .NET 6.0.</PackageReleaseNotes>
<PackageReleaseNotes>This version is adding minimal support to indicate when a transaction set failed to parse correctly. To do this, an extra readonly property `HasReaderErrors` has been added to the base TransactionSet object.</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>2.0.1</Version>
<Version>2.1.0-alpha</Version>
<AssemblyVersion>2.0.1.0</AssemblyVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -26,5 +27,7 @@
<ItemGroup>
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>

<ItemGroup>
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions Madjic.Edi.Dom/Reader Support/EdiGroupReader.vb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
Await Reader.ReadAsync().ConfigureAwait(False)

If Reader.CurrentSegment IsNot Nothing Then
Do While Not IsValueInGroup(Reader.CurrentSegment.SegmentID, {"ST", "GE", "IEA"}, StringComparison.OrdinalIgnoreCase)
Await Reader.ReadAsync().ConfigureAwait(False)
Loop

If String.Compare(Reader.CurrentSegment.SegmentID, "ST", StringComparison.OrdinalIgnoreCase) = 0 Then
Reader.ResetCountTransaction()
Return New EdiTransactionSetReader(Me, Reader.CurrentSegment, Reader)
Expand All @@ -77,6 +81,16 @@
atEOF = True
Return Nothing
End Function

Private Shared Function IsValueInGroup(value As String, groupToTestMembership() As String, comparison As StringComparison) As Boolean
For Each v In groupToTestMembership
If String.Compare(value, v, comparison) = 0 Then
Return True
End If
Next

Return False
End Function
End Class

End Namespace
14 changes: 14 additions & 0 deletions Madjic.Edi.Dom/TransactionSet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,18 @@ Public MustInherit Class TransactionSet
Return i > 0 AndAlso i < allowedOptions.Length - 1 AndAlso allowedOptions(i - 1) = ";"c AndAlso allowedOptions(i + instance.Length) = ";"c
End If
End Function

Private _HasError As Boolean
''' <summary>
''' Gets a value indicating that there were errors while reading this transaction set (the results should not be considered valid).
''' </summary>
''' <returns>True, to indicate there was an error while reading. False, otherwise.</returns>
Public Property HasReaderErrors As Boolean
Get
Return _HasError
End Get
Friend Set(value As Boolean)
_HasError = value
End Set
End Property
End Class
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ I need to add conveniences that set required fields when instantiating segments

## History

#### V2.1.0-alpha
* This release includes very basic validation when reading a transaction set. After parsing is complete, the `HasReaderErrors` property on the base `TransactionSet` object.

#### V1.0.6
* This release includes a test case for writing a file from scratch.
* A bug has been fixed for adding segments that can repeat as well as child loops that can repeat
Expand Down

0 comments on commit 25e99eb

Please sign in to comment.