001package org.hl7.fhir.r4.terminologies;
002
003import org.hl7.fhir.r4.model.Parameters;
004import org.hl7.fhir.r4.model.ValueSet;
005
006import java.io.FileNotFoundException;
007import java.io.IOException;
008
009public interface ValueSetExpander {
010  /**
011   * @param source  the value set definition to expand
012   * @param profile a profile affecting the outcome. If you don't supply a profile, the default internal expansion profile will be used.
013   * @return
014   * @throws ETooCostly
015   * @throws FileNotFoundException
016   * @throws IOException
017   */
018  ValueSetExpansionOutcome expand(ValueSet source, Parameters parameters) throws ETooCostly, FileNotFoundException, IOException;
019
020  enum TerminologyServiceErrorClass {
021    UNKNOWN, NOSERVICE, SERVER_ERROR, VALUESET_UNSUPPORTED;
022
023    public boolean isInfrastructure() {
024      return this == NOSERVICE || this == SERVER_ERROR || this == VALUESET_UNSUPPORTED;
025    }
026  }
027
028  class ETooCostly extends Exception {
029
030    public ETooCostly(String msg) {
031      super(msg);
032    }
033
034  }
035
036  /**
037   * Some value sets are just too big to expand. Instead of an expanded value set,
038   * you get back an interface that can test membership - usually on a server somewhere
039   *
040   * @author Grahame
041   */
042  class ValueSetExpansionOutcome {
043    private ValueSet valueset;
044    private String error;
045    private TerminologyServiceErrorClass errorClass;
046
047    public ValueSetExpansionOutcome(ValueSet valueset) {
048      super();
049      this.valueset = valueset;
050      this.error = null;
051    }
052
053    public ValueSetExpansionOutcome(ValueSet valueset, String error, TerminologyServiceErrorClass errorClass) {
054      super();
055      this.valueset = valueset;
056      this.error = error;
057      this.errorClass = errorClass;
058    }
059
060    public ValueSetExpansionOutcome(ValueSetChecker service, String error, TerminologyServiceErrorClass errorClass) {
061      super();
062      this.valueset = null;
063      this.error = error;
064      this.errorClass = errorClass;
065    }
066
067    public ValueSetExpansionOutcome(String error, TerminologyServiceErrorClass errorClass) {
068      this.valueset = null;
069      this.error = error;
070      this.errorClass = errorClass;
071    }
072
073    public ValueSet getValueset() {
074      return valueset;
075    }
076
077    public String getError() {
078      return error;
079    }
080
081    public TerminologyServiceErrorClass getErrorClass() {
082      return errorClass;
083    }
084
085
086  }
087}