001package org.hl7.fhir.utilities;
002
003/*-
004 * #%L
005 * org.hl7.fhir.utilities
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 org.hl7.fhir.exceptions.FHIRException;
025
026public enum StandardsStatus {
027
028  EXTERNAL, INFORMATIVE, DRAFT, TRIAL_USE, DEPRECATED, NORMATIVE;
029
030  public String toDisplay() {
031    switch (this) {
032    case DRAFT : 
033      return "Draft";  
034    case NORMATIVE  : 
035      return "Normative";
036    case TRIAL_USE : 
037      return "Trial Use";  
038    case INFORMATIVE:
039      return "Informative";
040    case EXTERNAL:
041      return "External";
042    case DEPRECATED: 
043      return "Deprecated";
044    }
045    return "?";
046  }
047
048  public String toCode() {
049    switch (this) {
050    case DRAFT : 
051      return "draft";  
052    case NORMATIVE  : 
053      return "normative";
054    case TRIAL_USE : 
055      return "trial-use";  
056    case INFORMATIVE:
057      return "informative";
058    case DEPRECATED: 
059    return "deprecated";
060    case EXTERNAL:
061      return "external";
062    }
063    return "?";
064  }
065
066
067  public static StandardsStatus fromCode(String value) throws FHIRException {
068    if (Utilities.noString(value))
069      return null;
070    if (value.equalsIgnoreCase("draft"))
071      return DRAFT;
072    if (value.equalsIgnoreCase("NORMATIVE")) 
073      return NORMATIVE;
074    if (value.equalsIgnoreCase("TRIAL_USE")) 
075      return TRIAL_USE;  
076    if (value.equalsIgnoreCase("TRIAL-USE")) 
077      return TRIAL_USE;  
078    if (value.equalsIgnoreCase("TRIAL USE")) 
079      return TRIAL_USE;  
080    if (value.equalsIgnoreCase("INFORMATIVE"))
081      return INFORMATIVE;
082    if (value.equalsIgnoreCase("EXTERNAL"))
083      return EXTERNAL;
084    if (value.equalsIgnoreCase("DEPRECATED"))
085      return DEPRECATED;
086    throw new FHIRException("Incorrect Standards Status '"+value+"'");
087  }
088
089  public String getAbbrev() {
090    switch (this) {
091    case DRAFT : 
092      return "D";  
093    case NORMATIVE  : 
094      return "N";
095    case TRIAL_USE : 
096      return "TU";  
097    case INFORMATIVE:
098      return "I";
099    case DEPRECATED: 
100      return "XD";
101    case EXTERNAL:
102      return "X";
103    }
104    return "?";
105  }
106
107  public String getColor() {
108    switch (this) {
109    case DRAFT : 
110      return "#efefef";  
111    case NORMATIVE  : 
112      return "#e6ffe6";
113    case TRIAL_USE : 
114      return "#fff5e6";  
115    case INFORMATIVE:
116      return "#ffffe6";
117    case DEPRECATED: 
118      return "#ffcccc";
119    case EXTERNAL:
120      return "#e6ffff";
121    }
122    return "?";
123  }
124
125  public String getColorSvg() {
126    switch (this) {
127    case DRAFT : 
128      return "#f6f6f6";  
129    case NORMATIVE  : 
130      return "#ecffec";
131    case TRIAL_USE : 
132      return "#fff9ec";  
133    case INFORMATIVE:
134      return "#ffffec";
135    case DEPRECATED: 
136      return "#ffcccc";
137    case EXTERNAL:
138      return "#ecffff";
139    }
140    return "?";
141  }
142
143  public boolean canDependOn(StandardsStatus tgtSS) {
144    if (this == DRAFT || this == INFORMATIVE || this == EXTERNAL)
145      return true;
146    if (this == TRIAL_USE)
147      return (tgtSS != DRAFT);
148    if (this == NORMATIVE)
149      return (tgtSS == NORMATIVE || tgtSS == EXTERNAL );
150    if (this == DEPRECATED)
151      return (tgtSS == DEPRECATED );
152    return false;
153  }
154
155  public boolean isLowerThan(StandardsStatus status) {
156    return this.compareTo(status) <0;
157  }
158}