001package org.hl7.fhir.r5.model; 002 003/*- 004 * #%L 005 * org.hl7.fhir.r5 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.r5.model.Enumerations.FHIRVersion; 025import org.hl7.fhir.utilities.VersionUtilities; 026 027/** 028 * This enumreation is special, and hand crafted. It only supports a subset of the actual published FHIR versions, those that are still supported. 029 * @author graha 030 * 031 */ 032public enum FhirPublication { 033 NULL, 034 DSTU1, 035 DSTU2, 036 DSTU2016May, 037 STU3, 038 R4, 039 R5; 040 041 public static FhirPublication fromCode(String v) { 042 if (VersionUtilities.isR2Ver(v)) 043 return FhirPublication.DSTU2; 044 if (VersionUtilities.isR2BVer(v)) 045 return FhirPublication.DSTU2016May; 046 if (VersionUtilities.isR3Ver(v)) 047 return FhirPublication.STU3; 048 if (VersionUtilities.isR4Ver(v)) 049 return FhirPublication.R4; 050 if (VersionUtilities.isR5Ver(v)) 051 return FhirPublication.R5; 052 if ("3.5.0".equals(v)) 053 return FhirPublication.R4; 054 if ("3.5".equals(v)) 055 return FhirPublication.R4; 056 return null; 057 } 058 059 public String toCode() { 060 switch (this) { 061 case DSTU1: return "0.01"; 062 case DSTU2: return "1.0.2"; 063 case DSTU2016May: return "1.4.0"; 064 case STU3: return "3.0.1"; 065 case R4: return Constants.VERSION; 066 default: 067 return "??"; 068 } 069 } 070 071 public static FhirPublication fromVersion(FHIRVersion v) { 072 return fromCode(v.toCode()); 073 } 074 075 076}