001package org.hl7.fhir.r5.terminologies.expansion;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import org.hl7.fhir.r5.model.ValueSet;
007import org.hl7.fhir.r5.terminologies.ValueSetUtilities;
008import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass;
009
010/**
011 * Some value sets are just too big to expand. Instead of an expanded value set, 
012 * you get back an interface that can test membership - usually on a server somewhere
013 * 
014 * @author Grahame
015 */
016public class ValueSetExpansionOutcome {
017  private ValueSet valueset;
018  private String error;
019  private TerminologyServiceErrorClass errorClass;
020  private String txLink;
021  private List<String> allErrors = new ArrayList<>();
022  private boolean fromServer;
023  
024  public ValueSetExpansionOutcome(ValueSet valueset) {
025    super();
026    this.valueset = valueset;
027    this.error = null;
028  }
029  public ValueSetExpansionOutcome(ValueSet valueset, String error, TerminologyServiceErrorClass errorClass, boolean fromServer) {
030    super();
031    this.valueset = valueset;
032    this.error = error;
033    this.errorClass = errorClass;
034    this.fromServer = fromServer;
035    allErrors.add(error);
036  }
037
038  public ValueSetExpansionOutcome(String error, TerminologyServiceErrorClass errorClass, boolean fromServer) {
039    this.valueset = null;
040    this.error = error;
041    this.errorClass = errorClass;
042    this.fromServer = fromServer;
043    allErrors.add(error);
044  }
045  public ValueSetExpansionOutcome(String error, TerminologyServiceErrorClass errorClass, List<String> errList, boolean fromServer) {
046    this.valueset = null;
047    this.error = error;
048    this.errorClass = errorClass;
049    this.fromServer = fromServer;
050    this.allErrors.addAll(errList);
051    if (!allErrors.contains(error)) {
052      allErrors.add(error);
053    }
054    if (!errList.contains(error)) {
055      errList.add(error);
056    }
057  }
058  
059  public ValueSet getValueset() {
060    return valueset;
061  }
062  public String getError() {
063    return error;
064  }
065  public TerminologyServiceErrorClass getErrorClass() {
066    return errorClass;
067  }
068  public String getTxLink() {
069    return txLink;
070  }
071  public ValueSetExpansionOutcome setTxLink(String txLink) {
072    this.txLink = txLink;
073    return this;
074  }
075  public List<String> getAllErrors() {
076    return allErrors;
077  }
078  
079  public boolean isFromServer() {
080    return fromServer;
081  }
082  public boolean isOk() {
083    return (allErrors.isEmpty() || (allErrors.size() == 1 && allErrors.get(0) == null)) && error == null;
084  }
085  public int count() {
086    if (valueset == null) {
087      return 0; 
088    }
089    return ValueSetUtilities.countExpansion(valueset);
090  }
091}