我正在编写一个服务器应用程序,它将接收带有添加的 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 实例。
如果您对我如何在不必使用通用段实例的情况下实现这一点有一些见解,请提供帮助!
谢谢!