001package org.hl7.fhir.utilities;
002
003/*
004  Copyright (c) 2011+, HL7, Inc.
005  All rights reserved.
006  
007  Redistribution and use in source and binary forms, with or without modification, 
008  are permitted provided that the following conditions are met:
009    
010   * Redistributions of source code must retain the above copyright notice, this 
011     list of conditions and the following disclaimer.
012   * Redistributions in binary form must reproduce the above copyright notice, 
013     this list of conditions and the following disclaimer in the documentation 
014     and/or other materials provided with the distribution.
015   * Neither the name of HL7 nor the names of its contributors may be used to 
016     endorse or promote products derived from this software without specific 
017     prior written permission.
018  
019  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
020  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
021  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
022  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
023  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
024  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
025  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
027  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
028  POSSIBILITY OF SUCH DAMAGE.
029  
030 */
031
032
033
034import org.hl7.fhir.exceptions.FHIRException;
035
036public enum StandardsStatus {
037
038  EXTERNAL, INFORMATIVE, DRAFT, TRIAL_USE, DEPRECATED, NORMATIVE;
039
040  public String toDisplay() {
041    switch (this) {
042    case DRAFT : 
043      return "Draft";  
044    case NORMATIVE  : 
045      return "Normative";
046    case TRIAL_USE : 
047      return "Trial Use";  
048    case INFORMATIVE:
049      return "Informative";
050    case EXTERNAL:
051      return "External";
052    case DEPRECATED: 
053      return "Deprecated";
054    }
055    return "?";
056  }
057
058  public String toCode() {
059    switch (this) {
060    case DRAFT : 
061      return "draft";  
062    case NORMATIVE  : 
063      return "normative";
064    case TRIAL_USE : 
065      return "trial-use";  
066    case INFORMATIVE:
067      return "informative";
068    case DEPRECATED: 
069    return "deprecated";
070    case EXTERNAL:
071      return "external";
072    }
073    return "?";
074  }
075
076
077  public static StandardsStatus fromCode(String value) throws FHIRException {
078    if (Utilities.noString(value))
079      return null;
080    if (value.equalsIgnoreCase("draft"))
081      return DRAFT;
082    if (value.equalsIgnoreCase("NORMATIVE")) 
083      return NORMATIVE;
084    if (value.equalsIgnoreCase("TRIAL_USE")) 
085      return TRIAL_USE;  
086    if (value.equalsIgnoreCase("TRIAL-USE")) 
087      return TRIAL_USE;  
088    if (value.equalsIgnoreCase("TRIAL USE")) 
089      return TRIAL_USE;  
090    if (value.equalsIgnoreCase("INFORMATIVE"))
091      return INFORMATIVE;
092    if (value.equalsIgnoreCase("EXTERNAL"))
093      return EXTERNAL;
094    if (value.equalsIgnoreCase("DEPRECATED"))
095      return DEPRECATED;
096    throw new FHIRException("Incorrect Standards Status '"+value+"'");
097  }
098
099  public String getAbbrev() {
100    switch (this) {
101    case DRAFT : 
102      return "D";  
103    case NORMATIVE  : 
104      return "N";
105    case TRIAL_USE : 
106      return "TU";  
107    case INFORMATIVE:
108      return "I";
109    case DEPRECATED: 
110      return "XD";
111    case EXTERNAL:
112      return "X";
113    }
114    return "?";
115  }
116
117  public String getColor() {
118    switch (this) {
119    case DRAFT : 
120      return "#efefef";  
121    case NORMATIVE  : 
122      return "#e6ffe6";
123    case TRIAL_USE : 
124      return "#fff5e6";  
125    case INFORMATIVE:
126      return "#ffffe6";
127    case DEPRECATED: 
128      return "#ffcccc";
129    case EXTERNAL:
130      return "#e6ffff";
131    }
132    return "?";
133  }
134
135  public String getColorSvg() {
136    switch (this) {
137    case DRAFT : 
138      return "#f6f6f6";  
139    case NORMATIVE  : 
140      return "#ecffec";
141    case TRIAL_USE : 
142      return "#fff9ec";  
143    case INFORMATIVE:
144      return "#ffffec";
145    case DEPRECATED: 
146      return "#ffcccc";
147    case EXTERNAL:
148      return "#ecffff";
149    }
150    return "?";
151  }
152
153  public boolean canDependOn(StandardsStatus tgtSS) {
154    if (this == DRAFT || this == INFORMATIVE || this == EXTERNAL)
155      return true;
156    if (this == TRIAL_USE)
157      return (tgtSS != DRAFT);
158    if (this == NORMATIVE)
159      return (tgtSS == NORMATIVE || tgtSS == EXTERNAL );
160    if (this == DEPRECATED)
161      return (tgtSS == DEPRECATED );
162    return false;
163  }
164
165  public boolean isLowerThan(StandardsStatus status) {
166    return this.compareTo(status) <0;
167  }
168}