예제 #1
0
  @Test
  public void testTerserGetPrimitive_VariesCompositeFirstComponent() throws HL7Exception {
    final Varies variesField = new Varies(mshOnly);
    final Primitive comp1Sub1 = Terser.getPrimitive(variesField, 1, 1);
    comp1Sub1.setValue("comp1Sub1");
    final Primitive comp1Sub2 = Terser.getPrimitive(variesField, 1, 2);
    comp1Sub2.setValue("comp1Sub2");
    final Primitive comp2Sub1 = Terser.getPrimitive(variesField, 2, 1);
    comp2Sub1.setValue("comp2Sub1");

    assertEquals(GenericComposite.class, variesField.getData().getClass());

    final GenericComposite field = (GenericComposite) variesField.getData();
    final Type typeComp1 = field.getComponent(0);
    assertEquals(typeComp1.getClass(), Varies.class);

    final Varies variesComp1 = (Varies) typeComp1;
    assertEquals(GenericComposite.class, variesComp1.getData().getClass());

    final GenericComposite comp1 = (GenericComposite) variesComp1.getData();
    final Type typeSub1 = comp1.getComponent(1);
    assertEquals(typeSub1.getClass(), Varies.class);

    final Varies variesSub1 = (Varies) typeSub1;
    assertEquals(GenericPrimitive.class, variesSub1.getData().getClass());

    assertEquals("comp1Sub1&comp1Sub2^comp2Sub1", PipeParser.encode(variesField, encoders));
  }
예제 #2
0
 /**
  * Returns the datatype and attempts to pipe-encode it. For example, a string implementation might
  * return "ST[Value^Value2]". This is only intended for logging/debugging purposes.
  */
 static String toString(Type theType) {
   StringBuilder b = new StringBuilder();
   b.append(theType.getClass().getSimpleName());
   b.append("[");
   b.append(PipeParser.encode(theType, EncodingCharacters.defaultInstance()));
   b.append("]");
   return b.toString();
 }
예제 #3
0
  protected List<ValidationException> testField(
      Type type, SegmentType.Field profile, boolean escape) {
    List<ValidationException> exList = new ArrayList<>();

    UsageInfo usage = new UsageInfo(profile);

    // account for MSH 1 & 2 which aren't escaped
    String encoded = null;
    if (!escape && Primitive.class.isAssignableFrom(type.getClass()))
      encoded = ((Primitive) type).getValue();

    exList.addAll(testType(type, profile.getDatatype(), usage, encoded, false));

    // test children
    if (validateChildren) {
      if (profile.getComponents().size() > 0 && !usage.disallowed()) {
        if (Composite.class.isAssignableFrom(type.getClass())) {
          Composite comp = (Composite) type;
          int i = 1;
          boolean nullContext = false;
          for (SegmentType.Field.Component component : profile.getComponents()) {
            try {
              SegmentType.Field.Component component2;
              if (nullContext) {
                component2 = new SegmentType.Field.Component();
                try {
                  BeanUtils.copyProperties(component2, component);
                } catch (InvocationTargetException | IllegalAccessException e) {
                  // nop
                }
                component2.setUsage("NULL");
              } else {
                component2 = component;
                if ((i == 1)
                    && profile.isNullable()
                    && PipeParser.encode(comp.getComponent(0), this.enc).equals("\"\"")) {
                  nullContext = true;
                }
              }

              exList.addAll(testComponent(comp.getComponent(i - 1), component2));
            } catch (DataTypeException de) {
              profileNotHL7Compliant(exList, COMPONENT_TYPE_MISMATCH, type.getName(), i);
            }
            ++i;
          }
          exList.addAll(checkUndefinedComponents(comp, profile.getComponents().size()));
        } else {
          profileNotHL7Compliant(exList, WRONG_FIELD_TYPE, type.getClass().getName());
        }
      }
    }
    return exList;
  }
예제 #4
0
  @Test
  public void testParser_VariesCompositeSecondField() throws HL7Exception {
    final Varies variesField = new Varies(mshOnly);
    final Parser parser = mshOnly.getParser();
    final String hl7Text = "^A3456&2Rozwick&don&FURTHER&JR&MR&DR^200701010933^200702031022";
    parser.parse(variesField, hl7Text, encoders);
    final Composite data = (Composite) variesField.getData();
    assertEquals(4, data.getComponents().length);

    final Varies component = (Varies) data.getComponent(1);
    assertEquals(GenericComposite.class, component.getData().getClass());
    assertEquals(7, ((Composite) component.getData()).getComponents().length);
    assertEquals(hl7Text, PipeParser.encode(variesField, encoders));
  }
예제 #5
0
  /**
   * Tests a Type against the corresponding section of a profile.
   *
   * @param encoded optional encoded form of type (if you want to specify this -- if null, default
   *     pipe-encoded form is used to check length and constant val)
   */
  protected List<ValidationException> testType(
      Type type, String dataType, UsageInfo usage, String encoded, boolean testUsage) {
    ArrayList<ValidationException> exList = new ArrayList<>();
    if (encoded == null) encoded = PipeParser.encode(type, this.enc);

    if (testUsage) {
      testUsage(exList, encoded, usage);
    }

    if (!usage.disallowed() && !encoded.isEmpty()) {
      // check datatype
      if ((type instanceof ca.uhn.hl7v2.model.v231.datatype.TSComponentOne
              || type instanceof ca.uhn.hl7v2.model.v24.datatype.TSComponentOne)
          && !dataType.equals("ST")) {
        profileNotHL7Compliant(exList, HL7_DATATYPE_MISMATCH, type.getName(), dataType);
      } else if (!(type instanceof TSComponentOne) && !type.getName().contains(dataType)) {
        profileViolatedWhen(
            !(type.getClass().getSimpleName().equals("Varies")
                || type.getClass().getSimpleName().equals("QIP")),
            exList,
            HL7_DATATYPE_MISMATCH,
            type.getName(),
            dataType);
      }

      // check length
      profileViolatedWhen(
          encoded.length() > usage.length,
          exList,
          LENGTH_EXCEEDED,
          usage.name,
          encoded.length(),
          usage.length);

      // check constant value
      if (usage.constantValue != null && usage.constantValue.length() > 0) {
        profileViolatedWhen(
            !encoded.equals(usage.constantValue),
            exList,
            WRONG_CONSTANT_VALUE,
            encoded,
            usage.constantValue);
      }

      // TODO : check against table, or do we need this check?
      // Gazelle checks code system and issues a WARNING if a check fails
    }

    return exList;
  }