コード例 #1
0
  @Override
  public MessageModel parse(TestContext context, MessageParserCommand command)
      throws MessageParserException {
    try {
      if (context instanceof HL7V2TestContext) {
        HL7V2TestContext testContext = (HL7V2TestContext) context;
        String er7Message = command.getContent();
        String profileXml = testContext.getConformanceProfile().getIntegrationProfile().getXml();
        if (profileXml == null) {
          throw new MessageParserException("No Conformance Profile Provided to Parse the Message");
        }
        String conformanceProfileId = testContext.getConformanceProfile().getSourceId();
        if (!"".equals(er7Message) && er7Message != null && !"".equals(conformanceProfileId)) {
          InputStream profileStream = IOUtils.toInputStream(profileXml);
          Profile profile = XMLDeserializer.deserialize(profileStream).get();
          JParser p = new JParser();
          Message message = p.jparse(er7Message, profile.messages().apply(conformanceProfileId));
          return parse(message, er7Message);
        }
      } else {
        throw new MessageParserException(
            "Invalid Context Provided. Expected Context is HL7V2TestContext but found "
                + context.getClass().getSimpleName());
      }

    } catch (RuntimeException e) {
      throw new MessageParserException(e.getMessage());
    } catch (Exception e) {
      throw new MessageParserException(e.getMessage());
    }
    return new MessageModel();
  }
コード例 #2
0
 @Override
 public MessageValidationResult validate(TestContext testContext, MessageValidationCommand command)
     throws MessageValidationException {
   try {
     if (testContext instanceof HL7V2TestContext) {
       HL7V2TestContext v2TestContext = (HL7V2TestContext) testContext;
       String title = command.getName();
       String contextType = command.getContextType();
       String message = getMessageContent(command);
       String conformanceProfielId = v2TestContext.getConformanceProfile().getSourceId();
       String integrationProfileXml =
           v2TestContext.getConformanceProfile().getIntegrationProfile().getXml();
       String valueSets = v2TestContext.getVocabularyLibrary().getXml();
       String c1 = v2TestContext.getConstraints().getXml();
       String c2 =
           v2TestContext.getAddditionalConstraints() != null
               ? v2TestContext.getAddditionalConstraints().getXml()
               : null;
       InputStream c1Stream = c1 != null ? IOUtils.toInputStream(c1) : null;
       InputStream c2Stream = c2 != null ? IOUtils.toInputStream(c2) : null;
       List<InputStream> cStreams = new ArrayList<InputStream>();
       if (c1Stream != null) cStreams.add(c1Stream);
       if (c2Stream != null) cStreams.add(c2Stream);
       ConformanceContext c = getConformanceContext(cStreams);
       ValueSetLibrary vsLib =
           valueSets != null ? getValueSetLibrary(IOUtils.toInputStream(valueSets)) : null;
       ValidationProxy vp = new ValidationProxy(title, "NIST", "1.0");
       EnhancedReport report =
           vp.validate(
               message,
               integrationProfileXml,
               c,
               vsLib,
               conformanceProfielId,
               Context.valueOf(contextType));
       return new MessageValidationResult(
           report.to("json").toString(), report.render("iz-report", null));
     } else {
       throw new MessageValidationException(
           "Invalid Context Provided. Expected Context is HL7V2TestContext but found "
               + testContext.getClass().getSimpleName());
     }
   } catch (RuntimeException e) {
     throw new MessageValidationException(e);
   } catch (Exception e) {
     throw new MessageValidationException(e);
   }
 }