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