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, WITHDRAWN; 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 case WITHDRAWN: 055 return "Withdrawn"; 056 } 057 return "?"; 058 } 059 060 public String toCode() { 061 switch (this) { 062 case DRAFT : 063 return "draft"; 064 case NORMATIVE : 065 return "normative"; 066 case TRIAL_USE : 067 return "trial-use"; 068 case INFORMATIVE: 069 return "informative"; 070 case DEPRECATED: 071 return "deprecated"; 072 case EXTERNAL: 073 return "external"; 074 case WITHDRAWN: 075 return "Withdrawn"; 076 } 077 return "?"; 078 } 079 080 081 public static StandardsStatus fromCode(String value) throws FHIRException { 082 if (Utilities.noString(value)) 083 return null; 084 if (value.equalsIgnoreCase("draft")) 085 return DRAFT; 086 if (value.equalsIgnoreCase("NORMATIVE")) 087 return NORMATIVE; 088 if (value.equalsIgnoreCase("TRIAL_USE")) 089 return TRIAL_USE; 090 if (value.equalsIgnoreCase("TRIAL-USE")) 091 return TRIAL_USE; 092 if (value.equalsIgnoreCase("TRIAL USE")) 093 return TRIAL_USE; 094 if (value.equalsIgnoreCase("INFORMATIVE")) 095 return INFORMATIVE; 096 if (value.equalsIgnoreCase("EXTERNAL")) 097 return EXTERNAL; 098 if (value.equalsIgnoreCase("DEPRECATED")) 099 return DEPRECATED; 100 if (value.equalsIgnoreCase("WITHDRAWN")) 101 return WITHDRAWN; 102 throw new FHIRException("Incorrect Standards Status '"+value+"'"); 103 } 104 105 public String getAbbrev() { 106 switch (this) { 107 case DRAFT : 108 return "D"; 109 case NORMATIVE : 110 return "N"; 111 case TRIAL_USE : 112 return "TU"; 113 case INFORMATIVE: 114 return "I"; 115 case DEPRECATED: 116 return "XD"; 117 case EXTERNAL: 118 return "X"; 119 case WITHDRAWN: 120 return "W"; 121 } 122 return "?"; 123 } 124 125 public String getColor() { 126 switch (this) { 127 case DRAFT : 128 return "#efefef"; 129 case NORMATIVE : 130 return "#e6ffe6"; 131 case TRIAL_USE : 132 return "#fff5e6"; 133 case INFORMATIVE: 134 return "#ffffe6"; 135 case DEPRECATED: 136 case WITHDRAWN: 137 return "#ffcccc"; 138 case EXTERNAL: 139 return "#e6ffff"; 140 } 141 return "?"; 142 } 143 144 public String getColorSvg() { 145 switch (this) { 146 case DRAFT : 147 return "#f6f6f6"; 148 case NORMATIVE : 149 return "#ecffec"; 150 case TRIAL_USE : 151 return "#fff9ec"; 152 case INFORMATIVE: 153 return "#ffffec"; 154 case DEPRECATED: 155 case WITHDRAWN: 156 return "#ffcccc"; 157 case EXTERNAL: 158 return "#ecffff"; 159 } 160 return "?"; 161 } 162 163 public boolean canDependOn(StandardsStatus tgtSS) { 164 if (this == DRAFT || this == INFORMATIVE || this == EXTERNAL) 165 return true; 166 if (this == TRIAL_USE) 167 return (tgtSS != DRAFT); 168 if (this == NORMATIVE) 169 return (tgtSS == NORMATIVE || tgtSS == EXTERNAL ); 170 if (this == DEPRECATED) 171 return (tgtSS == DEPRECATED ); 172 if (this == WITHDRAWN) 173 return (tgtSS == WITHDRAWN ); 174 return false; 175 } 176 177 public boolean isLowerThan(StandardsStatus status) { 178 return this.compareTo(status) <0; 179 } 180}