Menu

MSH version number

2010-04-21
2013-05-13
  • Steve Short

    Steve Short - 2010-04-21

    I have a problem that I suspect is a data source error but I'm not sure and I'm hoping that someone here might be able to confirm it…

    The HL7 data files that I'm trying to parse are v2.x ER7 data. Typically, they contain ADT A28 and ADT A31 messages. The version id in the MSH is "2.4".

    When I use the PipeParser to parse the data (e.g. ADT A31) I get a NHapi.Base.Model.GenericMessage.V24 returned. If I try to cast this to an ADT_A31 (defined in the v2.3.1 assembly) then I get an exception with the message "Unable to cast object of type 'V24' to type 'NHapi.Model.V231.Message.ADT_A31'."

    If I edit the data file in Notepad and change the version from "2.4" to "2.3.1" and run my code again, the PipeParser returns a NHapi.Model.V231.Message.ADT_A31 object.

    So, the question is, does the version number in the MSH have to specify the exact version that the event type/message type was last defined in the HL7 standard (and therefore implemented in the corresponding v2.x assembly) ?

    The team responsible for creating the data files say that they specify "2.4" in the files because that is the version that their data is compliant with (i.e. v2.4 and earlier versions). They don't think that they should be inserting a version number that changes from "2.4" to "2.3.1" (or earlier) depending on what the particular event type / message type is.

    I hope I've explained this clearly and would be grateful for any comments/guidance on this issue.

     
  • ChadC

    ChadC - 2010-04-21

    Whatever MSH version number is specified, NHapi uses to try to parse the message to that version of messages.  So in your example, MSH 2.4 will use the NHapi.Model.v24 library as the model.  Changing the MSH to 2.3.1 will make NHapi use the NHapi.Model.v231 library. 

    It could be that the 2.4 model differs in some way, and that is why it is returning you a NHapi.Base.Model.GenericMessage.V24.  When the parsing happens, if NHapi can't figure out how to take your message and spin up the correct model message, it will convert it to that GenericMessage.  Since it converted fine in the 2.3.1 space, I'm guessing something in the message is funky or the 2.4 model is broken.   

    Can you post a sample of the message back here?  You can de-identify the data. 

     
  • Steve Short

    Steve Short - 2010-04-21

    Thanks for the response.

    To be clear - I think nHAPI is doing the right thing because ADT A31 is not defined in the v24 library, it's defined in the v231 library. So, presumably if the MSH says 2.4 then the parser cannot parse this into a valid v24 message and falls back to returning a GenericMessage ?

    I don't think there's anything 'funky' about the message itself. This anonymised cut-down version exhibits the same behaviour:

    MSH|^~\&|XXXXXXXX(YYY) ZZZZZZ|TEST||TEST|20100401131052||ADT^A31|00005212|T|2.4
    EVN|A31|201004011310|||XXXXXXXX(YYY) ZZZZZZ

    If I run the PipeParser against this it returns a NHapi.Base.Model.GenericMessage.V24 object.

    If I change the version in the MSH to 2.3.1 like this:

    MSH|^~\&|XXXXXXXX(YYY) ZZZZZZ|TEST||TEST|20100401131052||ADT^A31|00005212|T|2.3.1
    EVN|A31|201004011310|||XXXXXXXX(YYY) ZZZZZZ

    then it returns a NHapi.Model.V231.Message.ADT object.

    Is this correct behaviour ? I.E. the MSH should specify 2.3.1 because this is the latest version (up to 2.4) in which the A31 is defined ?

    (Thanks for your help - much appreciated.)

     
  • Steve Short

    Steve Short - 2010-04-28

    Any further thoughts on this ?

     
  • ChadC

    ChadC - 2010-04-28

    Ok, I think the message is bad because in 2.4, the MSH.9 (Message Type) needs to send the message structure as well.  The message you have is valid for 2.3.1, because 2.3.1 didn't require the extra message structure piece like 2.4 does.  The below message should parse properly. 

    string hl7message =
                    @"MSH|^~\&|XXXXXXXX(YYY) ZZZZZZ|TEST||TEST|20100401131052||ADT^A31^ADT_A01|00005212|T|2.4
    EVN|A31|201004011310|||XXXXXXXX(YYY) ZZZZZZ";

                PipeParser parser = new PipeParser();

                //Parses the Hl7 message into a IMessage obj
                IMessage message = parser.Parse(hl7message);

                ADT_A01 a01 = message as ADT_A01;

                Console.WriteLine(a01.MSH.SendingFacility.UniversalID.Value);

     
  • Steve Short

    Steve Short - 2010-04-28

    Ah, that explains it. So it is a data source error but not the one I suspected.

    Thanks very much for looking into this and explaining the problem.

    And keep up the good work with nHAPI!

    Best regards.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.