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