@Override
  public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(
      UriDt theValueSetIdentifier,
      IIdType theId,
      CodeDt theCode,
      UriDt theSystem,
      StringDt theDisplay,
      CodingDt theCoding,
      CodeableConceptDt theCodeableConcept) {
    List<IIdType> valueSetIds;

    boolean haveCodeableConcept =
        theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
    boolean haveCoding = theCoding != null && theCoding.isEmpty() == false;
    boolean haveCode = theCode != null && theCode.isEmpty() == false;

    if (!haveCodeableConcept && !haveCoding && !haveCode) {
      throw new InvalidRequestException("No code, coding, or codeableConcept provided to validate");
    }
    if (!(haveCodeableConcept ^ haveCoding ^ haveCode)) {
      throw new InvalidRequestException(
          "$validate-code can only validate (system AND code) OR (coding) OR (codeableConcept)");
    }

    boolean haveIdentifierParam =
        theValueSetIdentifier != null && theValueSetIdentifier.isEmpty() == false;
    if (theId != null) {
      valueSetIds = Collections.singletonList(theId);
    } else if (haveIdentifierParam) {
      Set<Long> ids =
          searchForIds(
              ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue()));
      valueSetIds = new ArrayList<IIdType>();
      for (Long next : ids) {
        valueSetIds.add(new IdDt("ValueSet", next));
      }
    } else {
      if (theCode == null || theCode.isEmpty()) {
        throw new InvalidRequestException(
            "Either ValueSet ID or ValueSet identifier or system and code must be provided. Unable to validate.");
      }
      Set<Long> ids =
          searchForIds(
              ValueSet.SP_CODE, new TokenParam(toStringOrNull(theSystem), theCode.getValue()));
      valueSetIds = new ArrayList<IIdType>();
      for (Long next : ids) {
        valueSetIds.add(new IdDt("ValueSet", next));
      }
    }

    for (IIdType nextId : valueSetIds) {
      ValueSet expansion = expand(nextId, null);
      List<ExpansionContains> contains = expansion.getExpansion().getContains();
      ValidateCodeResult result =
          validateCodeIsInContains(
              contains,
              toStringOrNull(theSystem),
              toStringOrNull(theCode),
              theCoding,
              theCodeableConcept);
      if (result != null) {
        if (theDisplay != null
            && isNotBlank(theDisplay.getValue())
            && isNotBlank(result.getDisplay())) {
          if (!theDisplay.getValue().equals(result.getDisplay())) {
            return new ValidateCodeResult(
                false, "Display for code does not match", result.getDisplay());
          }
        }
        return result;
      }
    }

    return new ValidateCodeResult(false, "Code not found", null);
  }
  @Override
  public ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult validateCode(
      IPrimitiveType<String> theValueSetIdentifier,
      IIdType theId,
      IPrimitiveType<String> theCode,
      IPrimitiveType<String> theSystem,
      IPrimitiveType<String> theDisplay,
      Coding theCoding,
      CodeableConcept theCodeableConcept,
      RequestDetails theRequestDetails) {

    List<IIdType> valueSetIds = Collections.emptyList();

    boolean haveCodeableConcept =
        theCodeableConcept != null && theCodeableConcept.getCoding().size() > 0;
    boolean haveCoding = theCoding != null && theCoding.isEmpty() == false;
    boolean haveCode = theCode != null && theCode.isEmpty() == false;

    if (!haveCodeableConcept && !haveCoding && !haveCode) {
      throw new InvalidRequestException("No code, coding, or codeableConcept provided to validate");
    }
    if (!LogicUtil.multiXor(haveCodeableConcept, haveCoding, haveCode)) {
      throw new InvalidRequestException(
          "$validate-code can only validate (system AND code) OR (coding) OR (codeableConcept)");
    }

    boolean haveIdentifierParam =
        theValueSetIdentifier != null && theValueSetIdentifier.isEmpty() == false;
    if (theId != null) {
      valueSetIds = Collections.singletonList(theId);
    } else if (haveIdentifierParam) {
      Set<Long> ids =
          searchForIds(
              ValueSet.SP_IDENTIFIER, new TokenParam(null, theValueSetIdentifier.getValue()));
      valueSetIds = new ArrayList<IIdType>();
      for (Long next : ids) {
        valueSetIds.add(new IdType("ValueSet", next));
      }
    } else {
      if (theCode == null || theCode.isEmpty()) {
        throw new InvalidRequestException(
            "Either ValueSet ID or ValueSet identifier or system and code must be provided. Unable to validate.");
      }
      // String code = theCode.getValue();
      // String system = toStringOrNull(theSystem);
      LookupCodeResult result = myCodeSystemDao.lookupCode(theCode, theSystem, null, null);
      if (result.isFound()) {
        ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult retVal =
            new ValidateCodeResult(true, "Found code", result.getCodeDisplay());
        return retVal;
      }
    }

    //		if (valueSetIds.isEmpty()) {
    //			if (haveIdentifierParam) {
    //				myValidationSupport.expandValueSet(getContext(), include);
    //				if (myValidationSupport.isCodeSystemSupported(getContext(),
    // theValueSetIdentifier.getValue())) {
    //					String system = toStringOrNull(theSystem);
    //					String code = toStringOrNull(theCode);
    //					String display = toStringOrNull(theDisplay);
    //					CodeValidationResult result = myValidationSupport.validateCode(getContext(), system,
    // code, display);
    //					if (result != null) {
    //						if (theDisplay != null && isNotBlank(theDisplay.getValue()) &&
    // isNotBlank(result.getDisplay())) {
    //							if (!theDisplay.getValue().equals(result.getDisplay())) {
    //								return new ValidateCodeResult(false, "Display for code does not match",
    // result.getDisplay());
    //							}
    //						}
    //						return new ValidateCodeResult(true, "Code validates", result.getDisplay());
    //					}
    //				}
    //			}
    //		}

    for (IIdType nextId : valueSetIds) {
      ValueSet expansion = expand(nextId, null, theRequestDetails);
      List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains();
      ValidateCodeResult result =
          validateCodeIsInContains(
              contains,
              toStringOrNull(theSystem),
              toStringOrNull(theCode),
              theCoding,
              theCodeableConcept);
      if (result != null) {
        if (theDisplay != null
            && isNotBlank(theDisplay.getValue())
            && isNotBlank(result.getDisplay())) {
          if (!theDisplay.getValue().equals(result.getDisplay())) {
            return new ValidateCodeResult(
                false, "Display for code does not match", result.getDisplay());
          }
        }
        return result;
      }
    }

    return new ValidateCodeResult(false, "Code not found", null);
  }