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.complextypes30_50.Annotation30_50;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50;
007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Identifier30_50;
008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.SimpleQuantity30_50;
009import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_50;
010import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Date30_50;
011import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50;
012import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50;
013import org.hl7.fhir.exceptions.FHIRException;
014import org.hl7.fhir.r5.model.CodeableReference;
015
016public class Immunization30_50 {
017
018  public static org.hl7.fhir.r5.model.Immunization convertImmunization(org.hl7.fhir.dstu3.model.Immunization src) throws FHIRException {
019    if (src == null)
020      return null;
021    org.hl7.fhir.r5.model.Immunization tgt = new org.hl7.fhir.r5.model.Immunization();
022    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
023    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
024      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
025    if (src.hasStatus())
026      tgt.setStatusElement(convertImmunizationStatus(src.getStatusElement()));
027    if (src.hasVaccineCode())
028      tgt.setVaccineCode(CodeableConcept30_50.convertCodeableConcept(src.getVaccineCode()));
029    if (src.hasPatient())
030      tgt.setPatient(Reference30_50.convertReference(src.getPatient()));
031    if (src.hasEncounter())
032      tgt.setEncounter(Reference30_50.convertReference(src.getEncounter()));
033    if (src.hasDate())
034      tgt.setOccurrence(DateTime30_50.convertDateTime(src.getDateElement()));
035    if (src.hasPrimarySource())
036      tgt.setPrimarySourceElement(Boolean30_50.convertBoolean(src.getPrimarySourceElement()));
037    if (src.hasReportOrigin())
038      tgt.setInformationSource(CodeableConcept30_50.convertCodeableConcept(src.getReportOrigin()));
039    if (src.hasLocation())
040      tgt.setLocation(Reference30_50.convertReference(src.getLocation()));
041    if (src.hasManufacturer())
042      tgt.setManufacturer(Reference30_50.convertReference(src.getManufacturer()));
043    if (src.hasLotNumber())
044      tgt.setLotNumberElement(String30_50.convertString(src.getLotNumberElement()));
045    if (src.hasExpirationDate())
046      tgt.setExpirationDateElement(Date30_50.convertDate(src.getExpirationDateElement()));
047    if (src.hasSite())
048      tgt.setSite(CodeableConcept30_50.convertCodeableConcept(src.getSite()));
049    if (src.hasRoute())
050      tgt.setRoute(CodeableConcept30_50.convertCodeableConcept(src.getRoute()));
051    if (src.hasDoseQuantity())
052      tgt.setDoseQuantity(SimpleQuantity30_50.convertSimpleQuantity(src.getDoseQuantity()));
053    for (org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent t : src.getPractitioner())
054      tgt.addPerformer(convertImmunizationPractitionerComponent(t));
055    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
056    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getExplanation().getReason())
057      tgt.addReason(Reference30_50.convertCodeableConceptToCodableReference(t));
058    return tgt;
059  }
060
061  public static org.hl7.fhir.dstu3.model.Immunization convertImmunization(org.hl7.fhir.r5.model.Immunization src) throws FHIRException {
062    if (src == null)
063      return null;
064    org.hl7.fhir.dstu3.model.Immunization tgt = new org.hl7.fhir.dstu3.model.Immunization();
065    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
066    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
067      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
068    if (src.hasStatus())
069      tgt.setStatusElement(convertImmunizationStatus(src.getStatusElement()));
070    if (src.hasVaccineCode())
071      tgt.setVaccineCode(CodeableConcept30_50.convertCodeableConcept(src.getVaccineCode()));
072    if (src.hasPatient())
073      tgt.setPatient(Reference30_50.convertReference(src.getPatient()));
074    if (src.hasEncounter())
075      tgt.setEncounter(Reference30_50.convertReference(src.getEncounter()));
076    if (src.hasOccurrenceDateTimeType())
077      tgt.setDateElement(DateTime30_50.convertDateTime(src.getOccurrenceDateTimeType()));
078    if (src.hasPrimarySource())
079      tgt.setPrimarySourceElement(Boolean30_50.convertBoolean(src.getPrimarySourceElement()));
080    if (src.hasInformationSourceCodeableConcept())
081      tgt.setReportOrigin(CodeableConcept30_50.convertCodeableConcept(src.getInformationSourceCodeableConcept()));
082    if (src.hasLocation())
083      tgt.setLocation(Reference30_50.convertReference(src.getLocation()));
084    if (src.hasManufacturer())
085      tgt.setManufacturer(Reference30_50.convertReference(src.getManufacturer()));
086    if (src.hasLotNumber())
087      tgt.setLotNumberElement(String30_50.convertString(src.getLotNumberElement()));
088    if (src.hasExpirationDate())
089      tgt.setExpirationDateElement(Date30_50.convertDate(src.getExpirationDateElement()));
090    if (src.hasSite())
091      tgt.setSite(CodeableConcept30_50.convertCodeableConcept(src.getSite()));
092    if (src.hasRoute())
093      tgt.setRoute(CodeableConcept30_50.convertCodeableConcept(src.getRoute()));
094    if (src.hasDoseQuantity())
095      tgt.setDoseQuantity(SimpleQuantity30_50.convertSimpleQuantity(src.getDoseQuantity()));
096    for (org.hl7.fhir.r5.model.Immunization.ImmunizationPerformerComponent t : src.getPerformer())
097      tgt.addPractitioner(convertImmunizationPractitionerComponent(t));
098    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
099    for (CodeableReference t : src.getReason())
100      if (t.hasConcept())
101        tgt.getExplanation().addReason(CodeableConcept30_50.convertCodeableConcept(t.getConcept()));
102    return tgt;
103  }
104
105  public static org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent convertImmunizationPractitionerComponent(org.hl7.fhir.r5.model.Immunization.ImmunizationPerformerComponent src) throws FHIRException {
106    if (src == null)
107      return null;
108    org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent tgt = new org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent();
109    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
110    if (src.hasFunction())
111      tgt.setRole(CodeableConcept30_50.convertCodeableConcept(src.getFunction()));
112    if (src.hasActor())
113      tgt.setActor(Reference30_50.convertReference(src.getActor()));
114    return tgt;
115  }
116
117  public static org.hl7.fhir.r5.model.Immunization.ImmunizationPerformerComponent convertImmunizationPractitionerComponent(org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent src) throws FHIRException {
118    if (src == null)
119      return null;
120    org.hl7.fhir.r5.model.Immunization.ImmunizationPerformerComponent tgt = new org.hl7.fhir.r5.model.Immunization.ImmunizationPerformerComponent();
121    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
122    if (src.hasRole())
123      tgt.setFunction(CodeableConcept30_50.convertCodeableConcept(src.getRole()));
124    if (src.hasActor())
125      tgt.setActor(Reference30_50.convertReference(src.getActor()));
126    return tgt;
127  }
128
129  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus> convertImmunizationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodes> src) throws FHIRException {
130    if (src == null || src.isEmpty())
131      return null;
132    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatusEnumFactory());
133    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
134    switch (src.getValue()) {
135      case COMPLETED:
136        tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.COMPLETED);
137        break;
138      case ENTEREDINERROR:
139        tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.ENTEREDINERROR);
140        break;
141      default:
142        tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.NULL);
143        break;
144    }
145    return tgt;
146  }
147
148  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodes> convertImmunizationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus> src) throws FHIRException {
149    if (src == null || src.isEmpty())
150      return null;
151    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodesEnumFactory());
152    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
153    switch (src.getValue()) {
154      case COMPLETED:
155        tgt.setValue(org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodes.COMPLETED);
156        break;
157      case ENTEREDINERROR:
158        tgt.setValue(org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodes.ENTEREDINERROR);
159        break;
160      default:
161        tgt.setValue(org.hl7.fhir.r5.model.Immunization.ImmunizationStatusCodes.NULL);
162        break;
163    }
164    return tgt;
165  }
166}