java - 如何使用 ZPM 段解析 DFT_P03 消息

标签 java parsing message segment hapi

我正在编写一个服务器应用程序,该应用程序将接收带有添加的 ZPM 段的 DFT_P03 消息(我已根据 HAPI 文档为其创建了一个类)。目前,在执行以下操作时,我可以将该字段作为通用段访问:

@Override
public Message processMessage(Message t, Map map) throws ReceivingApplicationException, HL7Exception 
{
    String encodedMessage = new DefaultHapiContext().getPipeParser().encode(t);

    logEntryService.logDebug(LogEntry.CONNECTIVITY, "Received message:\n" + encodedMessage + "\n\n");

    try 
    {
        InboundMessage inboundMessage = new InboundMessage();
        inboundMessage.setMessageTime(new Date());
        inboundMessage.setMessageType("Usage");

        DFT_P03 usageMessage = (DFT_P03) t;
        Segment ZPMSegment = (Segment)usageMessage.get("ZPM");

        inboundMessage.setMessage(usageMessage.toString());
        Facility facility = facilityService.findByCode(usageMessage.getMSH().getReceivingFacility().getNamespaceID().getValue());
        inboundMessage.setTargetFacility(facility);
        String controlID = usageMessage.getMSH().getMessageControlID().encode();
        controlID = controlID.substring(controlID.indexOf("^") + 1, controlID.length());
        inboundMessage.setControlId(controlID);

        Message response;

        try
        {
            inboundMessageService.save(inboundMessage);
            response = t.generateACK();
            logEntryService.logDebug(LogEntry.CONNECTIVITY, "Message ACKed");
        }
        catch (Exception ex)
        {
            response = t.generateACK(AcknowledgmentCode.AE, new HL7Exception(ex));
            logEntryService.logDebug(LogEntry.CONNECTIVITY, "Message NACKed");
        }

        return response;
    } 
    catch (IOException e) 
    {
        logEntryService.logDebug(LogEntry.CONNECTIVITY, "Message rejected");

        throw new HL7Exception(e);
    }
}

我创建了一个 DFT_P03_Custom 类,如下所示:

public class DFT_P03_Custom extends DFT_P03
{
    public DFT_P03_Custom() throws HL7Exception
    {
        this(new DefaultModelClassFactory());
    }

    public DFT_P03_Custom(ModelClassFactory factory) throws HL7Exception
    {
        super(factory);
        String[] segmentNames = getNames();
        int indexOfPid = Arrays.asList(segmentNames).indexOf("FT1");
        int index = indexOfPid + 1;
        Class<ZPM> type = ZPM.class;
        boolean required = true;
        boolean repeating = false;
        this.add(type, required, repeating, index);
    }

    public ZPM getZPM()
    {
        return getTyped("ZPM", ZPM.class);
    }
}

当尝试将消息类型转换为 DFT_P03_Custom 实例时,我收到 ClassCastException。根据他们的文档,我确实创建了 CustomModelClassFactory 类,但使用它我只是在 controlId 字段上收到大量验证错误。

我已经在使用相同的逻辑来发送带有添加的 ZFX 段的自定义 MFN_M01 消息,并且工作完美。我知道 HAPI 在收到 DFT_P03 消息时会进行一些自动类型转换,这可能是我需要以某种方式覆盖它才能给我一个 DFT_P03_Custom 实例。

如果您对如何在不使用通用分段实例的情况下实现此目标有一些见解,请提供帮助!

谢谢!

最佳答案

我终于明白了这一点。我实现此功能的唯一方法是使用 HAPI 站点上的消息传递工作台生成一致性配置文件 XML 文件(使用我们应用程序中的示例消息作为基础),并使用 Maven 插件生成消息和分段类。只有使用这些类,我才能正确解析发送给我的自定义类的消息。需要注意的一件事是,如果我尝试使用 HAPI 提供的 MSH、PID、PV1 或 FT1 类并使用我的 Z 段类,它不起作用。仅当所有段都是由一致性插件生成的类时它才有效。这与 CustomModelClassFactory 类(如 HAPI 网站上所示)和正确的包结构相结合最终允许我访问我的 Z 段。

关于java - 如何使用 ZPM 段解析 DFT_P03 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48361162/

相关文章:

c++ - 模拟窗口之间的鼠标选择消息

将字符串解析为 double 时出现 java.lang.NumberFormatException

java - 如何注解injector.getInstance?

python - 如何从 Python 请求中提取值

ios - SiriKit INSendMessageIntent 跳过确认委托(delegate)

java - 在 JSF 2 配置文件中将 Flash.keepMessage 设置为 true 可以吗?

java - 比较两个文件并删除重复部分以仅合并新内容

java - 创建 JAX-RS 提供程序以从 InputStream 创建 Java Image

html - XML 中的换行符?

JAVA如何查找和删除句子结构?