@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);
   }
 }
Exemplo n.º 2
0
  public EnhancedReport validateContent(
      String content, String profile, String constraints, String vs, String id, Context context)
      throws Exception {

    Report r = Validation.validate(profile, constraints, vs, content, id);
    String pr = Util.streamAsString(profile);
    String ctx = "";
    if (context == Context.Free) ctx = "Context-Free";
    else ctx = "Context-Based";
    ArrayList<Section> mds = new ArrayList<Section>();
    mds.add(service);
    return EnhancedReport.fromValidation(r, content, pr, id, mds, ctx);
  }
Exemplo n.º 3
0
  /**
   * @param content Message content
   * @param profile Profile content
   * @param constraints Constraints Object
   * @param vs ValueSetsLibrary Object
   * @param id Message id
   * @param context Context Free or Context Based
   * @throws Exception
   */
  public EnhancedReport validate(
      String content,
      String profile,
      ConformanceContext constraints,
      ValueSetLibrary vs,
      String id,
      Context context)
      throws Exception {

    InputStream stream = new ByteArrayInputStream(profile.getBytes(StandardCharsets.UTF_8));
    Profile profileX = XMLDeserializer.deserialize(stream).get();

    Report r = Validation.validate(profileX, constraints, vs, content, id);
    String pr = profile;
    String ctx = "";
    if (context == Context.Free) ctx = "Context-Free";
    else ctx = "Context-Based";
    ArrayList<Section> mds = new ArrayList<Section>();
    mds.add(service);
    return EnhancedReport.fromValidation(r, content, pr, id, mds, ctx);
  }