XONValidator implements ValueValidator { @Override public void validate(String hl7XON) throws XDSMetaDataException { Organization organization = Hl7v2Based.parse(hl7XON, Organization.class); metaDataAssert(organization != null, ORGANIZATION_NAME_MISSING, hl7XON); XON xon = organization.getHapiObject(); metaDataAssert(isNotEmpty(xon.getXon1_OrganizationName().getValue()), ORGANIZATION_NAME_MISSING, hl7XON); HD hd = xon.getXon6_AssigningAuthority(); if (HD_VALIDATOR.isEmpty(hd)) { String idNumber = xon.getXon10_OrganizationIdentifier().getValue(); if (isNotEmpty(idNumber)) { OID_VALIDATOR.validate(idNumber); } } else { HD_VALIDATOR.validate(hd, hl7XON); } metaDataAssert(countMatches(hl7XON, "^") <= 9, ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(xon.getXon2_OrganizationNameTypeCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(xon.getXon3_IDNumber().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(xon.getXon4_CheckDigit().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(xon.getXon5_CheckDigitScheme().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(xon.getXon7_IdentifierTypeCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(HD_VALIDATOR.isEmpty(xon.getXon8_AssigningFacility()), ORGANIZATION_TOO_MANY_COMPONENTS); metaDataAssert(isEmpty(xon.getXon9_NameRepresentationCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS); }  @Override void validate(String hl7XON);  }
@Test public void testValidateGoodCases() throws XDSMetaDataException { validator.validate("Some Hospital^^^^^&1.2.3.4.5.6.7.8.9.1789&ISO^^^^45"); validator.validate("Some Hospital^^^^^^^^^1.2.3.4.5.6.7.8.9.1789.45"); validator.validate("Some Hospital"); }