001package org.hl7.fhir.convertors.conv10_40.resources10_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_40;
004import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Reference10_40;
005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40;
006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40;
007import org.hl7.fhir.dstu2.model.Enumeration;
008import org.hl7.fhir.dstu2.model.SupplyDelivery;
009import org.hl7.fhir.exceptions.FHIRException;
010
011public class SupplyDelivery10_40 {
012
013  public static org.hl7.fhir.dstu2.model.SupplyDelivery convertSupplyDelivery(org.hl7.fhir.r4.model.SupplyDelivery src) throws FHIRException {
014    if (src == null || src.isEmpty())
015      return null;
016    org.hl7.fhir.dstu2.model.SupplyDelivery tgt = new org.hl7.fhir.dstu2.model.SupplyDelivery();
017    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
018    if (src.hasIdentifier())
019      tgt.setIdentifier(Identifier10_40.convertIdentifier(src.getIdentifierFirstRep()));
020    if (src.hasStatus())
021      tgt.setStatusElement(convertSupplyDeliveryStatus(src.getStatusElement()));
022    if (src.hasPatient())
023      tgt.setPatient(Reference10_40.convertReference(src.getPatient()));
024    if (src.hasType())
025      tgt.setType(CodeableConcept10_40.convertCodeableConcept(src.getType()));
026    if (src.hasSupplier())
027      tgt.setSupplier(Reference10_40.convertReference(src.getSupplier()));
028    if (src.hasDestination())
029      tgt.setDestination(Reference10_40.convertReference(src.getDestination()));
030    for (org.hl7.fhir.r4.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference10_40.convertReference(t));
031    return tgt;
032  }
033
034  public static org.hl7.fhir.r4.model.SupplyDelivery convertSupplyDelivery(org.hl7.fhir.dstu2.model.SupplyDelivery src) throws FHIRException {
035    if (src == null || src.isEmpty())
036      return null;
037    org.hl7.fhir.r4.model.SupplyDelivery tgt = new org.hl7.fhir.r4.model.SupplyDelivery();
038    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
039    if (src.hasIdentifier())
040      tgt.addIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
041    if (src.hasStatus())
042      tgt.setStatusElement(convertSupplyDeliveryStatus(src.getStatusElement()));
043    if (src.hasPatient())
044      tgt.setPatient(Reference10_40.convertReference(src.getPatient()));
045    if (src.hasType())
046      tgt.setType(CodeableConcept10_40.convertCodeableConcept(src.getType()));
047    if (src.hasSupplier())
048      tgt.setSupplier(Reference10_40.convertReference(src.getSupplier()));
049    if (src.hasDestination())
050      tgt.setDestination(Reference10_40.convertReference(src.getDestination()));
051    for (org.hl7.fhir.dstu2.model.Reference t : src.getReceiver()) tgt.addReceiver(Reference10_40.convertReference(t));
052    return tgt;
053  }
054
055  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.SupplyDelivery.SupplyDeliveryStatus> convertSupplyDeliveryStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus> src) throws FHIRException {
056      if (src == null || src.isEmpty())
057          return null;
058      Enumeration<SupplyDelivery.SupplyDeliveryStatus> tgt = new Enumeration<>(new SupplyDelivery.SupplyDeliveryStatusEnumFactory());
059      ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
060      if (src.getValue() == null) {
061          tgt.setValue(null);
062      } else {
063          switch (src.getValue()) {
064              case INPROGRESS:
065                  tgt.setValue(SupplyDelivery.SupplyDeliveryStatus.INPROGRESS);
066                  break;
067              case COMPLETED:
068                  tgt.setValue(SupplyDelivery.SupplyDeliveryStatus.COMPLETED);
069                  break;
070              case ABANDONED:
071                  tgt.setValue(SupplyDelivery.SupplyDeliveryStatus.ABANDONED);
072                  break;
073              default:
074                  tgt.setValue(SupplyDelivery.SupplyDeliveryStatus.NULL);
075                  break;
076          }
077      }
078      return tgt;
079  }
080
081  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus> convertSupplyDeliveryStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.SupplyDelivery.SupplyDeliveryStatus> src) throws FHIRException {
082      if (src == null || src.isEmpty())
083          return null;
084      org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatusEnumFactory());
085      ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
086      if (src.getValue() == null) {
087          tgt.setValue(null);
088      } else {
089          switch (src.getValue()) {
090              case INPROGRESS:
091                  tgt.setValue(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus.INPROGRESS);
092                  break;
093              case COMPLETED:
094                  tgt.setValue(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus.COMPLETED);
095                  break;
096              case ABANDONED:
097                  tgt.setValue(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus.ABANDONED);
098                  break;
099              default:
100                  tgt.setValue(org.hl7.fhir.r4.model.SupplyDelivery.SupplyDeliveryStatus.NULL);
101                  break;
102          }
103      }
104      return tgt;
105  }
106}