HAPI - 也是规范的自定义模型类?

我有一个应用程序当前使用带有自定义消息类型和 Z 段类的自定义模型。例如,我的 v25 包中有一个 DFT_P03 类,它扩展了 AbstractMessage 并声明了段,也在同一个包中,如下所示:


private void init(ModelClassFactory factory) 

{

    try 

    {

        this.add(MSH.class, true, false);

        this.add(PID.class, false, false);

        this.add(PV1.class, false, false);

        this.add(FT1.class, false, false);

        this.add(ZPM.class, false, false);

    } 

    catch (HL7Exception e) 

    {}

}

这就是我创建 HapiContext 的方式,它指向同一个包:


public void initializeHAPI()

{

    try

    {

        ModelClassFactory cmf = new CustomModelClassFactory("com.somepackage.somelibraryname.hl7.custommodel");


        MinLowerLayerProtocol mllp = new MinLowerLayerProtocol();

        mllp.setCharset(StandardCharsets.ISO_8859_1.name());


        hapiContext = new DefaultHapiContext();

        hapiContext.setValidationContext(ValidationContextFactory.noValidation());

        hapiContext.getPipeParser().getParserConfiguration().setUnexpectedSegmentBehaviour(UnexpectedSegmentBehaviourEnum.ADD_INLINE);

        hapiContext.setModelClassFactory(cmf);

        hapiContext.setLowerLayerProtocol(mllp);


        logEntryService.logInfo(LogEntrySource.SERVICE, LogEntryType.CORE, "Successfully initialized HAPI framework", logger);

    }

    catch (Exception ex)

    {

        logEntryService.logError(LogEntrySource.SERVICE, LogEntryType.CORE, "Error initializing HAPI framework : " 

            + ex.getMessage(), logger);

    }

}

只要我在 MSH.12 中使用 2.5 发送消息,一切都会完美无缺。我想将 CanonicalModelClassFactory 集成到其中,以便它可以将较低版本解析为 v2.5 消息,而不会在我尝试将消息解析为我的 v2.5 DFT_P03 类时抛出 ClassCastException。我已经阅读了我能找到的关于此的所有信息,不幸的是,没有一个将它与 CustomModelClassFactory 结合使用。


我实际上创建了自己的 CustomModelClassFactory 类,它扩展了 CanonicalClassModelFactory 并修改了构造函数链:


public CustomModelClassFactory() 

{

    this((Map<String, String[]>)null);

}


请注意委托模型被设置为 CanonicalModelClassFactory 和 super("2.5") 调用。遗憾的是,在尝试解析除 v2.5 DFT 消息之外的任何其他内容时,这仍然会抛出 ClassCastException。


关于如何将这两种行为整合在一起的任何想法?


红糖糍粑
浏览 65回答 1
1回答

慕尼黑8549860

我们找到了一种结合这两种行为的方法。public class CustomModelCanonicalClassFactory extends CustomModelClassFactory {private String customVersion;&nbsp; &nbsp;public CustomModelCanonicalClassFactory(String packageName, String version){&nbsp; &nbsp; &nbsp; &nbsp; super(packageName);&nbsp; &nbsp; &nbsp; &nbsp; if (version == null || !Version.supportsVersion(version)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new IllegalArgumentException("Unknown version: " + version);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; this.customVersion = version;&nbsp; &nbsp; }}然后覆盖你需要的所有方法,将显式版本提供给 super#method&nbsp; &nbsp; @Override&nbsp; &nbsp; public Class<? extends Message> getMessageClass(String name, String version, boolean isExplicit) throws HL7Exception {&nbsp; &nbsp; &nbsp; &nbsp; return super.getMessageClass(name, this.customVersion, isExplicit);&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; public Class<? extends Group> getGroupClass(String name, String version) throws HL7Exception {&nbsp; &nbsp; &nbsp; &nbsp; return super.getGroupClass(name, this.customVersion);&nbsp; &nbsp; }最好的问候,帕特里克
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java