001package org.hl7.fhir.convertors.conv30_50.resources30_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_50;
004import org.hl7.fhir.convertors.conv30_50.datatypes30_50.Reference30_50;
005import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_50;
006import org.hl7.fhir.exceptions.FHIRException;
007
008public class Linkage30_50 {
009
010  public static org.hl7.fhir.r5.model.Linkage convertLinkage(org.hl7.fhir.dstu3.model.Linkage src) throws FHIRException {
011    if (src == null)
012      return null;
013    org.hl7.fhir.r5.model.Linkage tgt = new org.hl7.fhir.r5.model.Linkage();
014    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
015    if (src.hasActive())
016      tgt.setActiveElement(Boolean30_50.convertBoolean(src.getActiveElement()));
017    if (src.hasAuthor())
018      tgt.setAuthor(Reference30_50.convertReference(src.getAuthor()));
019    for (org.hl7.fhir.dstu3.model.Linkage.LinkageItemComponent t : src.getItem())
020      tgt.addItem(convertLinkageItemComponent(t));
021    return tgt;
022  }
023
024  public static org.hl7.fhir.dstu3.model.Linkage convertLinkage(org.hl7.fhir.r5.model.Linkage src) throws FHIRException {
025    if (src == null)
026      return null;
027    org.hl7.fhir.dstu3.model.Linkage tgt = new org.hl7.fhir.dstu3.model.Linkage();
028    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
029    if (src.hasActive())
030      tgt.setActiveElement(Boolean30_50.convertBoolean(src.getActiveElement()));
031    if (src.hasAuthor())
032      tgt.setAuthor(Reference30_50.convertReference(src.getAuthor()));
033    for (org.hl7.fhir.r5.model.Linkage.LinkageItemComponent t : src.getItem())
034      tgt.addItem(convertLinkageItemComponent(t));
035    return tgt;
036  }
037
038  public static org.hl7.fhir.dstu3.model.Linkage.LinkageItemComponent convertLinkageItemComponent(org.hl7.fhir.r5.model.Linkage.LinkageItemComponent src) throws FHIRException {
039    if (src == null)
040      return null;
041    org.hl7.fhir.dstu3.model.Linkage.LinkageItemComponent tgt = new org.hl7.fhir.dstu3.model.Linkage.LinkageItemComponent();
042    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
043    if (src.hasType())
044      tgt.setTypeElement(convertLinkageType(src.getTypeElement()));
045    if (src.hasResource())
046      tgt.setResource(Reference30_50.convertReference(src.getResource()));
047    return tgt;
048  }
049
050  public static org.hl7.fhir.r5.model.Linkage.LinkageItemComponent convertLinkageItemComponent(org.hl7.fhir.dstu3.model.Linkage.LinkageItemComponent src) throws FHIRException {
051    if (src == null)
052      return null;
053    org.hl7.fhir.r5.model.Linkage.LinkageItemComponent tgt = new org.hl7.fhir.r5.model.Linkage.LinkageItemComponent();
054    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
055    if (src.hasType())
056      tgt.setTypeElement(convertLinkageType(src.getTypeElement()));
057    if (src.hasResource())
058      tgt.setResource(Reference30_50.convertReference(src.getResource()));
059    return tgt;
060  }
061
062  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Linkage.LinkageType> convertLinkageType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Linkage.LinkageType> src) throws FHIRException {
063    if (src == null || src.isEmpty())
064      return null;
065    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Linkage.LinkageType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Linkage.LinkageTypeEnumFactory());
066    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
067    switch (src.getValue()) {
068      case SOURCE:
069        tgt.setValue(org.hl7.fhir.r5.model.Linkage.LinkageType.SOURCE);
070        break;
071      case ALTERNATE:
072        tgt.setValue(org.hl7.fhir.r5.model.Linkage.LinkageType.ALTERNATE);
073        break;
074      case HISTORICAL:
075        tgt.setValue(org.hl7.fhir.r5.model.Linkage.LinkageType.HISTORICAL);
076        break;
077      default:
078        tgt.setValue(org.hl7.fhir.r5.model.Linkage.LinkageType.NULL);
079        break;
080    }
081    return tgt;
082  }
083
084  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Linkage.LinkageType> convertLinkageType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Linkage.LinkageType> src) throws FHIRException {
085    if (src == null || src.isEmpty())
086      return null;
087    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Linkage.LinkageType> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Linkage.LinkageTypeEnumFactory());
088    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
089    switch (src.getValue()) {
090      case SOURCE:
091        tgt.setValue(org.hl7.fhir.dstu3.model.Linkage.LinkageType.SOURCE);
092        break;
093      case ALTERNATE:
094        tgt.setValue(org.hl7.fhir.dstu3.model.Linkage.LinkageType.ALTERNATE);
095        break;
096      case HISTORICAL:
097        tgt.setValue(org.hl7.fhir.dstu3.model.Linkage.LinkageType.HISTORICAL);
098        break;
099      default:
100        tgt.setValue(org.hl7.fhir.dstu3.model.Linkage.LinkageType.NULL);
101        break;
102    }
103    return tgt;
104  }
105}