@Override public String toString() { if (isValid()) return "VALID"; StringBuilder sb = new StringBuilder(); if (notAllowedAttributes != null) errorComment(sb, "Not allowed Attribute", tagsOfNotAllowedAttributes()).append(StringUtils.LINE_SEPARATOR); if (missingAttributes != null) errorComment(sb, "Missing Attribute", tagsOfMissingAttributes()).append(StringUtils.LINE_SEPARATOR); if (missingAttributeValues != null) errorComment(sb, "Missing Value of Attribute", tagsOfMissingAttributeValues()).append(StringUtils.LINE_SEPARATOR); if (invalidAttributeValues != null) errorComment(sb, "Invalid Attribute", tagsOfInvalidAttributeValues()).append(StringUtils.LINE_SEPARATOR); return sb.substring(0, sb.length()-1); }
public ValidationResult validate(IOD iod) { ValidationResult result = new ValidationResult(); HashMap<String,Boolean> resolvedConditions = new HashMap<String,Boolean>(); for (IOD.DataElement el : iod) { validate(el, result, resolvedConditions); } return result; }
public boolean isValid() { return !hasMissingAttributes() && !hasMissingAttributeValues() && !hasInvalidAttributeValues() && !hasNotAllowedAttributes(); }
public int[] getOffendingElements() { return cat(tagsOfMissingAttributes(), tagsOfMissingAttributeValues(), tagsOfInvalidAttributeValues(), tagsOfNotAllowedAttributes()); }
public String asText(Attributes attrs) { if (isValid()) return "VALID"; StringBuilder sb = new StringBuilder(); appendTextTo(0, attrs, sb); return sb.substring(0, sb.length()-1); }
public static DicomServiceException valueOf(ValidationResult result, Attributes attrs) { if (result.hasNotAllowedAttributes()) return new DicomServiceException(Status.NoSuchAttribute) .setAttributeIdentifierList(result.tagsOfNotAllowedAttributes()); if (result.hasMissingAttributes()) return new DicomServiceException(Status.MissingAttribute) .setAttributeIdentifierList(result.tagsOfMissingAttributes()); if (result.hasMissingAttributeValues()) return new DicomServiceException(Status.MissingAttributeValue) .setDataset(new Attributes(attrs, result.tagsOfMissingAttributeValues())); if (result.hasInvalidAttributeValues()) return new DicomServiceException(Status.InvalidAttributeValue) .setDataset(new Attributes(attrs, result.tagsOfInvalidAttributeValues())); return null; } }
if (el.type == IOD.DataElementType.TYPE_1 || el.type == IOD.DataElementType.TYPE_2) { result.addMissingAttribute(el); if (isEmpty(value)) { if (el.type == IOD.DataElementType.TYPE_1) { result.addMissingAttributeValue(el); result.addNotAllowedAttribute(el); return; if (el.vr == VR.SQ) { if (!(value instanceof Sequence)) { result.addInvalidAttributeValue(el, ValidationResult.Invalid.VR); return; int seqSize = seq.size(); if (el.maxVM > 0 && seqSize > el.maxVM) { result.addInvalidAttributeValue(el, ValidationResult.Invalid.MultipleItems); return; ValidationResult itemValidationResult = validateCode(seq.get(i), (Code[]) validVals); invalidItem = invalidItem || !itemValidationResult.isValid(); itemValidationResults[i] = itemValidationResult; result.addInvalidAttributeValue(el, ValidationResult.Invalid.Code, itemValidationResults, null);
private void appendInvalidAttributeValues(int level, Attributes attrs, String title, StringBuilder sb) { appendPrefixTo(level, sb); sb.append(title); sb.append(StringUtils.LINE_SEPARATOR); for (InvalidAttributeValue iav : invalidAttributeValues) { int tag = iav.dataElement.tag; appendAttribute(level, tag, sb); VR.Holder vr = new VR.Holder(); Object value = attrs.getValue(tag, vr); if (iav.reason != Invalid.Item) { sb.append(" Invalid ").append(iav.reason); appendIODRef(iav.dataElement.getLineNumber(), sb); appendPrefixTo(level+1, sb); sb.append("Missing Item"); appendIODRef(iod.getLineNumber(), sb); sb.append(StringUtils.LINE_SEPARATOR); for (int i = 0; i < iav.itemValidationResults.length; i++) { ValidationResult itemResult = iav.itemValidationResults[i]; if (!itemResult.isValid()) { appendPrefixTo(level+1, sb); sb.append("Invalid Item ").append(i+1).append(':') .append(StringUtils.LINE_SEPARATOR); itemResult.appendTextTo(level+1, seq.get(i), sb);
private static void check(ValidationResult result) throws DicomServiceException { if (!result.isValid()) throw new DicomServiceException( Status.IdentifierDoesNotMatchSOPClass, result.getErrorComment()) .setOffendingElements(result.getOffendingElements()); } }
public void validate(File file) { if (iod == null) throw new IllegalStateException("IOD net initialized"); DicomInputStream dis = null; try { System.out.print("Validate: " + file + " ... "); dis = new DicomInputStream(file); Attributes attrs = dis.readDataset(-1, -1); ValidationResult result = attrs.validate(iod); if (result.isValid()) System.out.println("OK"); else { System.out.println("FAILED:"); System.out.println(result.asText(attrs)); } } catch (IOException e) { System.out.println("FAILED: " + e.getMessage()); } finally { SafeClose.close(dis); } }
private ValidationResult validateCode(Attributes item, Code[] validVals) { ValidationResult result = null; for (Code code : validVals) { result = item.validate(IOD.valueOf(code)); if (result.isValid()) break; } return result; }
public static DicomServiceException valueOf(ValidationResult result, Attributes attrs) { if (result.hasNotAllowedAttributes()) return new DicomServiceException(Status.NoSuchAttribute) .setAttributeIdentifierList(result.tagsOfNotAllowedAttributes()); if (result.hasMissingAttributes()) return new DicomServiceException(Status.MissingAttribute) .setAttributeIdentifierList(result.tagsOfMissingAttributes()); if (result.hasMissingAttributeValues()) return new DicomServiceException(Status.MissingAttributeValue) .setDataset(new Attributes(attrs, result.tagsOfMissingAttributeValues())); if (result.hasInvalidAttributeValues()) return new DicomServiceException(Status.InvalidAttributeValue) .setDataset(new Attributes(attrs, result.tagsOfInvalidAttributeValues())); return null; } }
public String getErrorComment() { StringBuilder sb = new StringBuilder(); if (notAllowedAttributes != null) return errorComment(sb, "Not allowed Attribute", tagsOfNotAllowedAttributes()).toString(); if (missingAttributes != null) return errorComment(sb, "Missing Attribute", tagsOfMissingAttributes()).toString(); if (missingAttributeValues != null) return errorComment(sb, "Missing Value of Attribute", tagsOfMissingAttributeValues()).toString(); if (invalidAttributeValues != null) return errorComment(sb, "Invalid Attribute", tagsOfInvalidAttributeValues()).toString(); return null; }
private static void check(ValidationResult result) throws DicomServiceException { if (!result.isValid()) throw new DicomServiceException( Status.IdentifierDoesNotMatchSOPClass, result.getErrorComment()) .setOffendingElements(result.getOffendingElements()); } }
public void validate(File file) { if (iod == null) throw new IllegalStateException("IOD net initialized"); DicomInputStream dis = null; try { System.out.print("Validate: " + file + " ... "); dis = new DicomInputStream(file); Attributes attrs = dis.readDataset(-1, -1); ValidationResult result = attrs.validate(iod); if (result.isValid()) System.out.println("OK"); else { System.out.println("FAILED:"); System.out.println(result.asText(attrs)); } } catch (IOException e) { System.out.println("FAILED: " + e.getMessage()); } finally { SafeClose.close(dis); } }
if (mppsNCreateIOD != null) { ValidationResult result = rqAttrs.validate(mppsNCreateIOD); if (!result.isValid()) throw DicomServiceException.valueOf(result, rqAttrs);
if (mppsNSetIOD != null) { ValidationResult result = rqAttrs.validate(mppsNSetIOD); if (!result.isValid()) throw DicomServiceException.valueOf(result, rqAttrs);
public static QueryRetrieveLevel valueOf(Attributes attrs, String[] qrLevels) throws DicomServiceException { ValidationResult result = new ValidationResult(); attrs.validate(new IOD.DataElement(Tag.QueryRetrieveLevel, VR.LO, IOD.DataElementType.TYPE_1, 1, 1, 0).setValues(qrLevels), result); check(result); return QueryRetrieveLevel.valueOf(attrs.getString(Tag.QueryRetrieveLevel)); }
public static QueryRetrieveLevel valueOf(Attributes attrs, String[] qrLevels) throws DicomServiceException { ValidationResult result = new ValidationResult(); attrs.validate(new IOD.DataElement(Tag.QueryRetrieveLevel, VR.LO, IOD.DataElementType.TYPE_1, 1, 1, 0).setValues(qrLevels), result); check(result); return QueryRetrieveLevel.valueOf(attrs.getString(Tag.QueryRetrieveLevel)); }