001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus;
004import org.hl7.fhir.dstu3.model.ExpansionProfile.DesignationIncludeDesignationComponent;
005import org.hl7.fhir.dstu3.model.ExpansionProfile.SystemVersionProcessingMode;
006import org.hl7.fhir.exceptions.FHIRException;
007import org.hl7.fhir.r4.model.Type;
008
009public class ExpansionProfile30_40 {
010
011  public static org.hl7.fhir.r4.model.Parameters convertExpansionProfile(org.hl7.fhir.dstu3.model.ExpansionProfile src) throws FHIRException {
012    if (src == null)
013      return null;
014    org.hl7.fhir.r4.model.Parameters tgt = new org.hl7.fhir.r4.model.Parameters();
015    if (src.hasUrl())
016      tgt.addParameter("profile-url", src.getUrl());
017    if (src.hasVersion())
018      tgt.addParameter("profile-version", src.getVersion());
019    if (src.hasName())
020      tgt.addParameter("profile-name", src.getName());
021    if (src.hasStatus())
022      tgt.addParameter("profile-status", src.getStatus().toCode());
023    for (org.hl7.fhir.dstu3.model.ExpansionProfile.ExpansionProfileFixedVersionComponent t : src.getFixedVersion()) {
024      if (t.getMode() == SystemVersionProcessingMode.DEFAULT)
025        tgt.addParameter("system-version", t.getSystem() + "|" + t.getVersion());
026      else if (t.getMode() == SystemVersionProcessingMode.CHECK)
027        tgt.addParameter("check-system-version", t.getSystem() + "|" + t.getVersion());
028      else if (t.getMode() == SystemVersionProcessingMode.OVERRIDE)
029        tgt.addParameter("force-system-version", t.getSystem() + "|" + t.getVersion());
030    }
031    if (src.hasExcludedSystem()) {
032      tgt.addParameter("exclude-system", src.getExcludedSystem().getSystem() + "|" + src.getExcludedSystem().getVersion());
033    }
034    if (src.hasIncludeDesignations())
035      tgt.addParameter("includeDesignations", src.getIncludeDesignations());
036    for (DesignationIncludeDesignationComponent t : src.getDesignation().getInclude().getDesignation()) {
037      if (t.hasLanguage())
038        tgt.addParameter("designation", "urn:ietf:bcp:47|" + t.getLanguage());
039      if (t.hasUse())
040        tgt.addParameter("designation", t.getUse().getSystem() + "|" + t.getUse().getCode());
041    }
042    if (src.hasIncludeDefinition())
043      tgt.addParameter("includeDefinition", src.getIncludeDefinition());
044    if (src.hasActiveOnly())
045      tgt.addParameter("activeOnly", src.getActiveOnly());
046    if (src.hasExcludeNested())
047      tgt.addParameter("excludeNested", src.getExcludeNested());
048    if (src.hasExcludeNotForUI())
049      tgt.addParameter("excludeNotForUI", src.getExcludeNotForUI());
050    if (src.hasExcludePostCoordinated())
051      tgt.addParameter("excludePostCoordinated", src.getExcludePostCoordinated());
052    if (src.hasDisplayLanguage())
053      tgt.addParameter("excludePostCoordinated", src.getDisplayLanguage());
054    if (src.hasLimitedExpansion())
055      tgt.addParameter("limitedExpansion", src.getLimitedExpansion());
056    return tgt;
057  }
058
059  public static org.hl7.fhir.dstu3.model.ExpansionProfile convertExpansionProfile(org.hl7.fhir.r4.model.Parameters src) throws FHIRException {
060    if (src == null)
061      return null;
062    org.hl7.fhir.dstu3.model.ExpansionProfile tgt = new org.hl7.fhir.dstu3.model.ExpansionProfile();
063    if (src.hasParameterValue("profile-url"))
064      tgt.setUrl(src.getParameterValue("profile-url").primitiveValue());
065    if (src.hasParameterValue("profile-version"))
066      tgt.setVersion(src.getParameterValue("profile-version").primitiveValue());
067    if (src.hasParameterValue("profile-name"))
068      tgt.setName(src.getParameterValue("profile-name").primitiveValue());
069    if (src.hasParameterValue("profile-status"))
070      tgt.setStatus(PublicationStatus.fromCode(src.getParameterValue("profile-status").primitiveValue()));
071    for (Type t : src.getParameterValues("system-version")) {
072      String[] v = t.primitiveValue().split("\\|");
073      tgt.addFixedVersion().setSystem(v[0]).setVersion(v[1]).setMode(SystemVersionProcessingMode.DEFAULT);
074    }
075    for (Type t : src.getParameterValues("force-system-version")) {
076      String[] v = t.primitiveValue().split("\\|");
077      tgt.addFixedVersion().setSystem(v[0]).setVersion(v[1]).setMode(SystemVersionProcessingMode.OVERRIDE);
078    }
079    for (Type t : src.getParameterValues("check-system-version")) {
080      String[] v = t.primitiveValue().split("\\|");
081      tgt.addFixedVersion().setSystem(v[0]).setVersion(v[1]).setMode(SystemVersionProcessingMode.CHECK);
082    }
083    for (Type t : src.getParameterValues("exclude-system")) {
084      String[] v = t.primitiveValue().split("\\|");
085      tgt.getExcludedSystem().setSystem(v[0]).setVersion(v[1]);
086    }
087    if (src.hasParameterValue("includeDesignations"))
088      tgt.setIncludeDesignations(src.getParameterBool(""));
089    for (Type t : src.getParameterValues("designation")) {
090      String[] v = t.primitiveValue().split("\\|");
091      if ("urn:ietf:bcp:47".equals(v[0]))
092        tgt.getDesignation().getInclude().addDesignation().setLanguage(v[1]);
093      else
094        tgt.getDesignation().getInclude().addDesignation().getUse().setSystem(v[0]).setCode(v[1]);
095    }
096    if (src.hasParameterValue("includeDefinition"))
097      tgt.setIncludeDefinition(src.getParameterBool("includeDefinition"));
098    if (src.hasParameterValue("activeOnly"))
099      tgt.setActiveOnly(src.getParameterBool("activeOnly"));
100    if (src.hasParameterValue("excludeNested"))
101      tgt.setExcludeNested(src.getParameterBool("excludeNested"));
102    if (src.hasParameterValue("excludeNotForUI"))
103      tgt.setExcludeNotForUI(src.getParameterBool("excludeNotForUI"));
104    if (src.hasParameterValue("excludeNotForUI"))
105      tgt.setExcludePostCoordinated(src.getParameterBool("excludeNotForUI"));
106    if (src.hasParameterValue("displayLanguage"))
107      tgt.setDisplayLanguage(src.getParameterValue("displayLanguage").primitiveValue());
108    if (src.hasParameterValue("limitedExpansion"))
109      tgt.setLimitedExpansion(src.getParameterBool("getParameterBool"));
110    return tgt;
111  }
112}