/**
   * Validates that a given identifier string is valid for a given {@link PatientIdentifierType}
   * Checks for things like blank identifiers, invalid check digits, and invalid format.
   *
   * @param pit - the {@link PatientIdentifierType} to validate against
   * @param identifier - the identifier to check against the passed {@link PatientIdentifierType}
   * @throws PatientIdentifierException if the identifier is invalid
   * @should fail validation if PatientIdentifierType is null
   * @should fail validation if identifier is blank
   * @see #checkIdentifierAgainstFormat(String, String, String)
   * @see #checkIdentifierAgainstValidator(String, IdentifierValidator)
   */
  public static void validateIdentifier(String identifier, PatientIdentifierType pit)
      throws PatientIdentifierException {

    log.debug("Checking identifier: " + identifier + " for type: " + pit);

    // Validate input parameters
    if (pit == null) {
      throw new BlankIdentifierException("PatientIdentifierType.null");
    }
    if (StringUtils.isBlank(identifier)) {
      throw new BlankIdentifierException("PatientIdentifier.error.nullOrBlank");
    }

    checkIdentifierAgainstFormat(identifier, pit.getFormat(), pit.getFormatDescription());

    // Check identifier against IdentifierValidator
    if (pit.hasValidator()) {
      IdentifierValidator validator =
          Context.getPatientService().getIdentifierValidator(pit.getValidator());
      checkIdentifierAgainstValidator(identifier, validator);
    }
    log.debug("The identifier check was successful");
  }