@Override
 public boolean supportsSystem(String system) throws TerminologyServiceException {
   if (codeSystems.containsKey(system)) return true;
   else if (nonSupportedCodeSystems.contains(system)) return false;
   else if (system.startsWith("http://example.org")
       || system.startsWith("http://acme.com")
       || system.startsWith("http://hl7.org/fhir/valueset-")
       || system.startsWith("urn:oid:")) return false;
   else {
     if (noTerminologyServer) return false;
     if (bndCodeSystems == null) {
       try {
         log("Terminology server: Check for supported code systems for " + system);
         bndCodeSystems =
             txServer.fetchFeed(
                 txServer.getAddress()
                     + "/CodeSystem?content=not-present&_summary=true&_count=1000");
       } catch (Exception e) {
         if (canRunWithoutTerminology) {
           noTerminologyServer = true;
           log("==============!! Running without terminology server !!==============");
           return false;
         } else throw new TerminologyServiceException(e);
       }
     }
     if (bndCodeSystems != null) {
       for (BundleEntryComponent be : bndCodeSystems.getEntry()) {
         CodeSystem cs = (CodeSystem) be.getResource();
         if (!codeSystems.containsKey(cs.getUrl())) {
           codeSystems.put(cs.getUrl(), null);
         }
       }
     }
     if (codeSystems.containsKey(system)) return true;
   }
   nonSupportedCodeSystems.add(system);
   return false;
 }
  public ValueSetExpansionOutcome expandOnServer(ValueSet vs, String fn) throws Exception {
    if (noTerminologyServer)
      return new ValueSetExpansionOutcome(
          "Error expanding ValueSet: running without terminology services",
          TerminologyServiceErrorClass.NOSERVICE);
    if (expProfile == null) throw new Exception("No ExpansionProfile provided");

    try {
      Map<String, String> params = new HashMap<String, String>();
      params.put("_limit", Integer.toString(expandCodesLimit));
      params.put("_incomplete", "true");
      log("Terminology Server: $expand on " + getVSSummary(vs));
      ValueSet result = txServer.expandValueset(vs, expProfile.setIncludeDefinition(false), params);
      return new ValueSetExpansionOutcome(result);
    } catch (Exception e) {
      return new ValueSetExpansionOutcome(
          "Error expanding ValueSet \"" + vs.getUrl() + ": " + e.getMessage(),
          TerminologyServiceErrorClass.UNKNOWN);
    }
  }
  private ValidationResult serverValidateCode(Parameters pin, boolean doCache) throws Exception {
    if (noTerminologyServer)
      return new ValidationResult(null, null, TerminologyServiceErrorClass.NOSERVICE);
    String cacheName = doCache ? generateCacheName(pin) : null;
    ValidationResult res = loadFromCache(cacheName);
    if (res != null) return res;
    log("Terminology Server: $validate-code " + describeValidationParameters(pin));
    for (ParametersParameterComponent pp : pin.getParameter())
      if (pp.getName().equals("profile"))
        throw new Error("Can only specify profile in the context");
    if (expProfile == null) throw new Exception("No ExpansionProfile provided");
    pin.addParameter().setName("profile").setResource(expProfile);

    Parameters pout = txServer.operateType(ValueSet.class, "validate-code", pin);
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    for (ParametersParameterComponent p : pout.getParameter()) {
      if (p.getName().equals("result")) ok = ((BooleanType) p.getValue()).getValue().booleanValue();
      else if (p.getName().equals("message")) message = ((StringType) p.getValue()).getValue();
      else if (p.getName().equals("display")) display = ((StringType) p.getValue()).getValue();
      else if (p.getName().equals("cause")) {
        try {
          IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
          if (it == IssueType.UNKNOWN) err = TerminologyServiceErrorClass.UNKNOWN;
          else if (it == IssueType.NOTSUPPORTED)
            err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
        } catch (FHIRException e) {
        }
      }
    }
    if (!ok) res = new ValidationResult(IssueSeverity.ERROR, message, err);
    else if (display != null)
      res = new ValidationResult(new ConceptDefinitionComponent().setDisplay(display));
    else res = new ValidationResult(null);
    saveToCache(res, cacheName);
    return res;
  }