001package org.hl7.fhir.r4.model;
002
003import org.hl7.fhir.r4.model.Enumerations.FHIRVersion;
004
005/**
006 * This enumreation is special, and hand crafted. It only supports a subset of the actual published FHIR versions, those that are still supported.
007 * @author graha
008 *
009 */
010public enum FhirPublication {
011  NULL,
012  DSTU1,
013  DSTU2,
014  DSTU2016May,
015  STU3,
016  R4;
017
018  public static FhirPublication fromCode(String v) {
019    if ("1.0.2".equals(v))
020      return FhirPublication.DSTU2;
021    if ("1.0".equals(v))
022      return FhirPublication.DSTU2;
023    if ("1.4.0".equals(v))
024      return FhirPublication.DSTU2016May;
025    if ("1.4".equals(v))
026      return FhirPublication.DSTU2016May;
027    if ("3.0.1".equals(v))
028      return FhirPublication.STU3;
029    if ("3.0".equals(v))
030      return FhirPublication.STU3;
031    if ("3.5.0".equals(v))
032      return FhirPublication.R4;
033    if ("4.0.0".equals(v))
034      return FhirPublication.R4;
035    if ("3.5".equals(v))
036      return FhirPublication.R4;
037    if ("4.0".equals(v))
038      return FhirPublication.R4;
039    if ("1.0.0".equals(v))
040      return FhirPublication.R4; // hack workaround build problem
041    return null;
042  }
043
044  public String toCode() {
045    switch (this) {
046    case DSTU1: return "0.01";
047    case DSTU2: return "1.0.2";
048    case DSTU2016May: return "1.4.0";
049    case STU3: return "3.0.1";
050    case R4: return Constants.VERSION;
051    default:
052      return "??";
053    }
054  }
055
056  public static FhirPublication fromVersion(FHIRVersion v) {
057    return fromCode(v.toCode());
058  }
059
060
061}