001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_40;
004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Annotation30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.SimpleQuantity30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Boolean30_40;
010import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Date30_40;
011import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
012import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
013import org.hl7.fhir.exceptions.FHIRException;
014import org.hl7.fhir.r4.model.Extension;
015import org.hl7.fhir.r4.model.Immunization;
016
017
018
019public class Immunization30_40 {
020
021  public static final String NOT_GIVEN_EXTENSION_URL = "http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven";
022
023  private static final String[] IGNORED_EXTENSION_URLS = new String[]{
024    NOT_GIVEN_EXTENSION_URL
025  };
026
027  public static org.hl7.fhir.r4.model.Immunization convertImmunization(org.hl7.fhir.dstu3.model.Immunization src) throws FHIRException {
028    if (src == null)
029      return null;
030    org.hl7.fhir.r4.model.Immunization tgt = new org.hl7.fhir.r4.model.Immunization();
031    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
032    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
033      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
034    if (src.hasStatus())
035      tgt.setStatusElement(convertImmunizationStatus(src.getStatusElement()));
036    if (src.hasNotGiven()) {
037      if (src.getNotGiven()) {
038        org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Immunization.ImmunizationStatus> notDoneElement = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Immunization.ImmunizationStatusEnumFactory());
039        notDoneElement.setValue(Immunization.ImmunizationStatus.NOTDONE);
040        tgt.setStatusElement(notDoneElement);
041      }
042      tgt.addExtension(getExtensionForNotGiven(src.getNotGiven()));
043    }
044    if (src.hasVaccineCode())
045      tgt.setVaccineCode(CodeableConcept30_40.convertCodeableConcept(src.getVaccineCode()));
046    if (src.hasPatient())
047      tgt.setPatient(Reference30_40.convertReference(src.getPatient()));
048    if (src.hasEncounter())
049      tgt.setEncounter(Reference30_40.convertReference(src.getEncounter()));
050    if (src.hasDateElement())
051      tgt.setOccurrence(DateTime30_40.convertDateTime(src.getDateElement()));
052    if (src.hasPrimarySource())
053      tgt.setPrimarySourceElement(Boolean30_40.convertBoolean(src.getPrimarySourceElement()));
054    if (src.hasReportOrigin())
055      tgt.setReportOrigin(CodeableConcept30_40.convertCodeableConcept(src.getReportOrigin()));
056    if (src.hasLocation())
057      tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
058    if (src.hasManufacturer())
059      tgt.setManufacturer(Reference30_40.convertReference(src.getManufacturer()));
060    if (src.hasLotNumber())
061      tgt.setLotNumberElement(String30_40.convertString(src.getLotNumberElement()));
062    if (src.hasExpirationDate())
063      tgt.setExpirationDateElement(Date30_40.convertDate(src.getExpirationDateElement()));
064    if (src.hasSite())
065      tgt.setSite(CodeableConcept30_40.convertCodeableConcept(src.getSite()));
066    if (src.hasRoute())
067      tgt.setRoute(CodeableConcept30_40.convertCodeableConcept(src.getRoute()));
068    if (src.hasDoseQuantity())
069      tgt.setDoseQuantity(SimpleQuantity30_40.convertSimpleQuantity(src.getDoseQuantity()));
070    for (org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent t : src.getPractitioner())
071      tgt.addPerformer(convertImmunizationPractitionerComponent(t));
072    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
073    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getExplanation().getReason())
074      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
075    return tgt;
076  }
077
078  public static org.hl7.fhir.r4.model.Extension getExtensionForNotGiven(boolean notGiven) {
079    org.hl7.fhir.r4.model.Extension extension = new  org.hl7.fhir.r4.model.Extension();
080    extension.setUrl(NOT_GIVEN_EXTENSION_URL);
081    extension.setValue(new org.hl7.fhir.r4.model.BooleanType(notGiven));
082    return extension;
083  }
084
085  public static org.hl7.fhir.dstu3.model.Immunization convertImmunization(org.hl7.fhir.r4.model.Immunization src) throws FHIRException {
086    if (src == null)
087      return null;
088    org.hl7.fhir.dstu3.model.Immunization tgt = new org.hl7.fhir.dstu3.model.Immunization();
089
090    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS);
091    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
092      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
093    if (src.hasStatus()) {
094      tgt.setStatusElement(convertImmunizationStatus(src.getStatusElement()));
095       if (src.getStatusElement().getValue() == Immunization.ImmunizationStatus.NOTDONE)
096         tgt.setNotGivenElement(new org.hl7.fhir.dstu3.model.BooleanType(true));
097       else
098         tgt.setNotGivenElement(new org.hl7.fhir.dstu3.model.BooleanType(false));
099    }
100    if (src.hasExtension(NOT_GIVEN_EXTENSION_URL)) {
101      Extension notGivenExtension = src.getExtensionByUrl(NOT_GIVEN_EXTENSION_URL);
102      if (notGivenExtension.hasValue() && notGivenExtension.getValueAsPrimitive() instanceof org.hl7.fhir.r4.model.BooleanType)
103        tgt.setNotGivenElement(new org.hl7.fhir.dstu3.model.BooleanType(((org.hl7.fhir.r4.model.BooleanType)notGivenExtension.getValueAsPrimitive()).getValue()));
104    }
105    if (src.hasVaccineCode())
106      tgt.setVaccineCode(CodeableConcept30_40.convertCodeableConcept(src.getVaccineCode()));
107    if (src.hasPatient())
108      tgt.setPatient(Reference30_40.convertReference(src.getPatient()));
109    if (src.hasEncounter())
110      tgt.setEncounter(Reference30_40.convertReference(src.getEncounter()));
111    if (src.hasOccurrenceDateTimeType())
112      tgt.setDateElement(DateTime30_40.convertDateTime(src.getOccurrenceDateTimeType()));
113    if (src.hasPrimarySource())
114      tgt.setPrimarySourceElement(Boolean30_40.convertBoolean(src.getPrimarySourceElement()));
115    if (src.hasReportOrigin())
116      tgt.setReportOrigin(CodeableConcept30_40.convertCodeableConcept(src.getReportOrigin()));
117    if (src.hasLocation())
118      tgt.setLocation(Reference30_40.convertReference(src.getLocation()));
119    if (src.hasManufacturer())
120      tgt.setManufacturer(Reference30_40.convertReference(src.getManufacturer()));
121    if (src.hasLotNumber())
122      tgt.setLotNumberElement(String30_40.convertString(src.getLotNumberElement()));
123    if (src.hasExpirationDate())
124      tgt.setExpirationDateElement(Date30_40.convertDate(src.getExpirationDateElement()));
125    if (src.hasSite())
126      tgt.setSite(CodeableConcept30_40.convertCodeableConcept(src.getSite()));
127    if (src.hasRoute())
128      tgt.setRoute(CodeableConcept30_40.convertCodeableConcept(src.getRoute()));
129    if (src.hasDoseQuantity())
130      tgt.setDoseQuantity(SimpleQuantity30_40.convertSimpleQuantity(src.getDoseQuantity()));
131    for (org.hl7.fhir.r4.model.Immunization.ImmunizationPerformerComponent t : src.getPerformer())
132      tgt.addPractitioner(convertImmunizationPractitionerComponent(t));
133    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
134    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode())
135      tgt.getExplanation().addReason(CodeableConcept30_40.convertCodeableConcept(t));
136
137
138    return tgt;
139  }
140
141  public static org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent convertImmunizationPractitionerComponent(org.hl7.fhir.r4.model.Immunization.ImmunizationPerformerComponent src) throws FHIRException {
142    if (src == null)
143      return null;
144    org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent tgt = new org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent();
145    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
146    if (src.hasFunction())
147      tgt.setRole(CodeableConcept30_40.convertCodeableConcept(src.getFunction()));
148    if (src.hasActor())
149      tgt.setActor(Reference30_40.convertReference(src.getActor()));
150    return tgt;
151  }
152
153  public static org.hl7.fhir.r4.model.Immunization.ImmunizationPerformerComponent convertImmunizationPractitionerComponent(org.hl7.fhir.dstu3.model.Immunization.ImmunizationPractitionerComponent src) throws FHIRException {
154    if (src == null)
155      return null;
156    org.hl7.fhir.r4.model.Immunization.ImmunizationPerformerComponent tgt = new org.hl7.fhir.r4.model.Immunization.ImmunizationPerformerComponent();
157    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
158    if (src.hasRole())
159      tgt.setFunction(CodeableConcept30_40.convertCodeableConcept(src.getRole()));
160    if (src.hasActor())
161      tgt.setActor(Reference30_40.convertReference(src.getActor()));
162    return tgt;
163  }
164
165  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus> convertImmunizationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Immunization.ImmunizationStatus> src) throws FHIRException {
166    if (src == null || src.isEmpty())
167      return null;
168    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());
169    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
170    switch (src.getValue()) {
171      case COMPLETED:
172      case NOTDONE:
173        tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.COMPLETED);
174        break;
175      case ENTEREDINERROR:
176        tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.ENTEREDINERROR);
177        break;
178      default:
179        tgt.setValue(org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus.NULL);
180        break;
181    }
182    return tgt;
183  }
184
185  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Immunization.ImmunizationStatus> convertImmunizationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Immunization.ImmunizationStatus> src) throws FHIRException {
186    if (src == null || src.isEmpty())
187      return null;
188    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Immunization.ImmunizationStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Immunization.ImmunizationStatusEnumFactory());
189    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
190    switch (src.getValue()) {
191      case COMPLETED:
192        tgt.setValue(org.hl7.fhir.r4.model.Immunization.ImmunizationStatus.COMPLETED);
193        break;
194      case ENTEREDINERROR:
195        tgt.setValue(org.hl7.fhir.r4.model.Immunization.ImmunizationStatus.ENTEREDINERROR);
196        break;
197      default:
198        tgt.setValue(org.hl7.fhir.r4.model.Immunization.ImmunizationStatus.NULL);
199        break;
200    }
201    return tgt;
202  }
203}