nHapiNET / nHapi

nHapi is the .Net port of the original Java project HAPI.
Mozilla Public License 2.0
276 stars 156 forks source link

getting exceptions when trying to parse hl7 messages containing large data in obx-5 #594

Open AlexFJaxFL opened 1 month ago

AlexFJaxFL commented 1 month ago

getting the following exception when parsing files containing large embedded images:

Parse error in DoEDieIn: NHapi.Base.DataTypeException: Failed validation rule: Maxumim size <= 65536 characters at NHapi.Base.Model.Varies.fixOBX5(ISegment segment, IModelClassFactory factory) at NHapi.Base.Parser.PipeParser.Parse(ISegment destination, String segment, EncodingCharacters encodingChars) at NHapi.Base.Parser.PipeParser.DoParse(String message, String version) at NHapi.Base.Parser.ParserBase.Parse(String message, String version) at EPDHL7ListenerSvc2.EPDHL7ListenerSvc2.TryParseMessage(String HL7Message).

not sure if this limitation is to be expected or maybe it will be resolved in future versions

Regards, Alex

milkshakeuk commented 3 weeks ago

hi @AlexFJaxFL do you have any example code?

milkshakeuk commented 3 weeks ago

also @AlexFJaxFL might be worth checking #105 to see if this issue is similar or not?

AlexFJaxFL commented 3 weeks ago

hi @AlexFJaxFL do you have any example code?

Public Shared Function ParseHL7Messages(HL7Messages As String, FType As FeedType) As Boolean Dim MsgType As String = "" Dim SendingApp As String = "" Dim iEPDFacNo As Integer = 0

    Try
        FieldSeparator = HL7Messages(3)
        ComponentSeparator = HL7Messages(4)

        Dim HL7MessageName As String = ""

        If Not HL7Messages.StartsWith("MSH") Then
            If blnInService = True Then 'if running in the service
                WriteEventLog("Error in ParseHL7Messages: does not start with MSH " & vbCrLf & HL7Messages, EventLogEntryType.Error)
            Else
                Dim ex As New Exception("Error in ParseHL7Messages: does not start with MSH " & vbCrLf & HL7Messages)
                Throw ex
            End If
        End If

        Dim prsr As New Parser.PipeParser()
        Dim imsg As Model.IMessage = Nothing
        Dim trsr As Util.Terser
        Dim blnFilterOut As Boolean = False

        For Each strMsg In HL7Messages.Split(New String() {"MSH|"}, StringSplitOptions.RemoveEmptyEntries)
            strMsg = "MSH|" & strMsg 'add the split chars back on.

            'If prsr.GetMessageStructure(strMsg) = "ORU_R01" Then
            strMsg = SetOBX2DataType(strMsg) '
            'End If

            Try
                imsg = prsr.Parse(strMsg)
            Catch ex As Exception
                Try
                    EPDnHapi.SetPtrnFindReplace(strMsg)
                    imsg = prsr.Parse(strMsg)
                Catch ex1 As Exception
                    If strMsg.Contains("ORU^R01") OrElse strMsg.Contains("ORM^O01") Then ' for IB ORU/ORM clearing OBR-13 since not needed 
                        EPDnHapi.ClearField(strMsg, "OBR|", 13)  ' and causing problems for parser (AF)
                        Try
                            imsg = prsr.Parse(strMsg)
                        Catch ex2 As Exception
                            imsg = prsr.Parse(strMsg, "2.4")
                        End Try
                    End If
                End Try
            End Try
AlexFJaxFL commented 3 weeks ago

also @AlexFJaxFL might be worth checking #105 to see if this issue is similar or not?

i can see there is certain correlation between my issue and discussion that took place in #105, my data looks like this:

image

AlexFJaxFL commented 3 weeks ago

maybe this structure does not match what your engine parser is expecting ..

milkshakeuk commented 3 weeks ago

Hi @AlexFJaxFL we have some unit tests showing how it should look, https://github.com/nHapiNET/nHapi/blob/a9f42181815e035383120540160d470c03f60918/tests/NHapi.Benchmarks/LargeEmbeddedFileTest.cs#L23 There is also this blog which might help. http://healthbase.info/blog/?p=376

AlexFJaxFL commented 2 weeks ago

Ok, this information is very helpful indeed and will be used for .pdf related feeds which we have plenty. What approach should I use if incoming hl7 message contains .rtf content in obx-5 the way I demonstrated above ?

milkshakeuk commented 1 week ago

@AlexFJaxFL I think you can use a similar approach to the pdf for rtf files.