我正在编写一个服务器应用程序,它将接收带有添加的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实例的原因。
如果你对我如何在不使用通用片段实例的情况下实现这一点有一些见解,请帮助!
谢谢!
发布于 2018-06-13 05:32:37
我终于想通了。我使用HAPI站点上的消息工作台生成一个一致性配置文件XML文件(使用我们的应用程序中的示例消息作为基础),并使用maven插件生成消息和片段类。只有使用这些类,我才能正确地将消息解析到我的自定义类。需要注意的一件事是,如果我尝试使用HAPI提供的MSH、PID、PV1或FT1类并使用我的Z段类,它将不起作用。只有当所有段都是由一致性插件生成的类时,它才起作用。这结合了一个CustomModelClassFactory类(如HAPI网站所示)和正确的包结构,最终允许我访问我的Z段。
https://stackoverflow.com/questions/48361162
复制相似问题