简体   繁体   English

nhapi-修改段值

[英]nhapi - Modifiy a segment value

Env : 信封:

Visual Studio 2013, Winform / C# / Framework 4.5, nHapi DLL 2.4.0.9, HL7 Version 2.3 Visual Studio 2013,Winform / C#/ Framework 4.5,nHapi DLL 2.4.0.9,HL7版本2.3

I'm building a little windows application that read HL7 messages and send them to an Interface system. 我正在构建一个小的Windows应用程序,该应用程序读取HL7消息并将其发送到Interface系统。 Everything is working just fine but I would like to know if it's possible to replace/add/modify a segment value : EVN 5.2 (Operator ID / Family name). 一切正常,但我想知道是否可以替换/添加/修改段值:EVN 5.2(操作员ID /姓氏)。

At the moment, I'm reading the content of the HL7 file on the computer, put the content in a string, parse the message, encode the message and return it. 目前,我正在读取计算机上HL7文件的内容,将内容放入字符串中,解析消息,对消息进行编码并返回它。

    public static String ParseMessage(String message)
    {
        var parser = new NHapi.Base.Parser.PipeParser();
        var parsedMessage = parser.Parse(message);
        /* I guess it's here that I should do the change for the EVN 5.2 ? But How ;-) */
        var msgType = parsedMessage.GetStructureName();
        var pipeDelimitedMessage = parser.Encode(parsedMessage);

        return pipeDelimitedMessage;
    }

Thanks everyone for you help 谢谢大家的帮助

Richard 理查德

The way the nHapi would have you do this is cast the 'parsed' abstract message down to its concrete type so that you are able to walk the object model and set the properties you'd like. nHapi希望您执行此操作的方式是将“已解析”的抽象消息转换为具体类型,以便能够遍历对象模型并设置所需的属性。

As an example, take the case of an ADT A01 admit message: 例如,以ADT A01允许消息为例:

    [Test]
    public void TestPopulateEVNOperaterID()
    {
        string message = @"MSH|^~\&|SUNS1|OVI02|AZIS|CMD|200606221348||ADT^A01|1049691900|P|2.3
EVN|A01|200601060800
PID||8912716038^^^51276|0216128^^^51276||BARDOUN^LEA SACHA||19981201|F|||AVENUE FRANC GOLD 8^^LUXEMBOURGH^^6780^150||053/12456789||N|S|||99120162652||^^^|||||B
PV1||O|^^|U|||07632^MORTELO^POL^^^DR.|^^^^^|||||N||||||0200001198
PV2|||^^AZIS||N|||200601060800
IN1|0001|2|314000|||||||||19800101|||1|BARDOUN^LEA SACHA|1|19981201|AVENUE FRANC GOLD 8^^LUXEMBOURGH^^6780^150|||||||||||||||||ZIN|0164652011399|0164652011399|101|101|45789^Broken bone";

        var parser = new PipeParser();
        var abstractMessage = parser.Parse(message);

        // this is the normal / expected way of working with NHapi parsed messages
        var typedMessage = abstractMessage as ADT_A01;
        if (typedMessage != null)
        {
            typedMessage.EVN.OperatorID.FamilyName.Value = "Surname";
            typedMessage.EVN.OperatorID.GivenName.Value = "Firstname";
        }

        var pipeDelimitedMessage = parser.Encode(typedMessage);

        // alternatively, you can apply this modification to any HL7 2.3 message
        // with an EVN segment using this more generic method
        var genericMethod = abstractMessage as AbstractMessage;
        var evn = genericMethod.GetStructure("EVN") as EVN;
        if (evn != null)
        {
            evn.OperatorID.FamilyName.Value = "SurnameGeneric";
            evn.OperatorID.GivenName.Value = "FirstnameGeneric";
        }

        pipeDelimitedMessage = parser.Encode(typedMessage);
    }

I believe the second more generic way is probably what you'll be wanting for this case, however I thought I'd just show you as well how to get to parsed / concrete type so that you can work with it that way if you are dealing with a specific message type. 我相信第二种更通用的方式可能是您在这种情况下想要的,但是我想我也将向您展示如何获取解析的/具体的类型,以便您可以在这种情况下使用该方式。处理特定的消息类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM