001package org.hl7.fhir.r4.terminologies;
002
003/*-
004 * #%L
005 * org.hl7.fhir.r4
006 * %%
007 * Copyright (C) 2014 - 2019 Health Level 7
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023
024import java.io.FileNotFoundException;
025import java.io.IOException;
026
027import org.hl7.fhir.r4.model.Parameters;
028import org.hl7.fhir.r4.model.ValueSet;
029
030public interface ValueSetExpander {
031  public enum TerminologyServiceErrorClass {
032    UNKNOWN, NOSERVICE, SERVER_ERROR, VALUESET_UNSUPPORTED;
033
034    public boolean isInfrastructure() {
035      return this == NOSERVICE || this == SERVER_ERROR || this == VALUESET_UNSUPPORTED;
036    }
037  }
038  
039  public class ETooCostly extends Exception {
040
041    public ETooCostly(String msg) {
042      super(msg);
043    }
044
045  }
046
047  /**
048   * Some value sets are just too big to expand. Instead of an expanded value set, 
049   * you get back an interface that can test membership - usually on a server somewhere
050   * 
051   * @author Grahame
052   */
053  public class ValueSetExpansionOutcome {
054    private ValueSet valueset;
055    private String error;
056    private TerminologyServiceErrorClass errorClass;
057    private String txLink;
058    
059    public ValueSetExpansionOutcome(ValueSet valueset) {
060      super();
061      this.valueset = valueset;
062      this.error = null;
063    }
064    public ValueSetExpansionOutcome(ValueSet valueset, String error, TerminologyServiceErrorClass errorClass) {
065      super();
066      this.valueset = valueset;
067      this.error = error;
068      this.errorClass = errorClass;
069    }
070    public ValueSetExpansionOutcome(ValueSetChecker service, String error, TerminologyServiceErrorClass errorClass) {
071      super();
072      this.valueset = null;
073      this.error = error;
074      this.errorClass = errorClass;
075    }
076    public ValueSetExpansionOutcome(String error, TerminologyServiceErrorClass errorClass) {
077      this.valueset = null;
078      this.error = error;
079      this.errorClass = errorClass;
080    }
081    public ValueSet getValueset() {
082      return valueset;
083    }
084    public String getError() {
085      return error;
086    }
087    public TerminologyServiceErrorClass getErrorClass() {
088      return errorClass;
089    }
090    public String getTxLink() {
091      return txLink;
092    }
093    public ValueSetExpansionOutcome setTxLink(String txLink) {
094      this.txLink = txLink;
095      return this;
096    }
097
098
099  }
100/**
101 * 
102 * @param source the value set definition to expand
103 * @param profile a profile affecting the outcome. If you don't supply a profile, the default internal expansion profile will be used.
104 *  
105 * @return
106 * @throws ETooCostly
107 * @throws FileNotFoundException
108 * @throws IOException
109 */
110  public ValueSetExpansionOutcome expand(ValueSet source, Parameters parameters) throws ETooCostly, FileNotFoundException, IOException;
111}