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.String30_50;
010import org.hl7.fhir.exceptions.FHIRException;
011import org.hl7.fhir.r5.model.CodeableReference;
012import org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodesEnumFactory;
013
014public class MedicationAdministration30_50 {
015
016  public static org.hl7.fhir.dstu3.model.MedicationAdministration convertMedicationAdministration(org.hl7.fhir.r5.model.MedicationAdministration src) throws FHIRException {
017    if (src == null)
018      return null;
019    org.hl7.fhir.dstu3.model.MedicationAdministration tgt = new org.hl7.fhir.dstu3.model.MedicationAdministration();
020    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
021    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
022      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
023    for (org.hl7.fhir.r5.model.UriType t : src.getInstantiatesUri()) tgt.addDefinition().setReference(t.getValue());
024    for (org.hl7.fhir.r5.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_50.convertReference(t));
025    if (src.hasStatus())
026      tgt.setStatusElement(convertMedicationAdministrationStatus(src.getStatusElement()));
027    if (src.hasCategory())
028      tgt.setCategory(CodeableConcept30_50.convertCodeableConcept(src.getCategoryFirstRep()));
029    if (src.getMedication().hasConcept())
030      tgt.setMedication(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getMedication().getConcept()));
031    if (src.getMedication().hasReference())
032      tgt.setMedication(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getMedication().getReference()));
033    if (src.hasSubject())
034      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
035    if (src.hasEncounter())
036      tgt.setContext(Reference30_50.convertReference(src.getEncounter()));
037    for (org.hl7.fhir.r5.model.Reference t : src.getSupportingInformation())
038      tgt.addSupportingInformation(Reference30_50.convertReference(t));
039    if (src.hasOccurence())
040      tgt.setEffective(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getOccurence()));
041    for (org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent t : src.getPerformer())
042      tgt.addPerformer(convertMedicationAdministrationPerformerComponent(t));
043    for (CodeableReference t : src.getReason())
044      if (t.hasConcept())
045        tgt.addReasonCode(CodeableConcept30_50.convertCodeableConcept(t.getConcept()));
046    for (CodeableReference t : src.getReason())
047      if (t.hasReference())
048        tgt.addReasonReference(Reference30_50.convertReference(t.getReference()));
049    if (src.hasRequest())
050      tgt.setPrescription(Reference30_50.convertReference(src.getRequest()));
051    for (org.hl7.fhir.r5.model.Reference t : src.getDevice()) tgt.addDevice(Reference30_50.convertReference(t));
052    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
053    if (src.hasDosage())
054      tgt.setDosage(convertMedicationAdministrationDosageComponent(src.getDosage()));
055    for (org.hl7.fhir.r5.model.Reference t : src.getEventHistory())
056      tgt.addEventHistory(Reference30_50.convertReference(t));
057    return tgt;
058  }
059
060  public static org.hl7.fhir.r5.model.MedicationAdministration convertMedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration src) throws FHIRException {
061    if (src == null)
062      return null;
063    org.hl7.fhir.r5.model.MedicationAdministration tgt = new org.hl7.fhir.r5.model.MedicationAdministration();
064    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
065    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
066      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
067    for (org.hl7.fhir.dstu3.model.Reference t : src.getDefinition()) tgt.addInstantiatesUri(t.getReference());
068    for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_50.convertReference(t));
069    if (src.hasStatus())
070      tgt.setStatusElement(convertMedicationAdministrationStatus(src.getStatusElement()));
071    if (src.hasCategory())
072      tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(src.getCategory()));
073    if (src.hasMedicationCodeableConcept())
074      tgt.getMedication().setConcept(CodeableConcept30_50.convertCodeableConcept(src.getMedicationCodeableConcept()));
075    if (src.hasMedicationReference())
076      tgt.getMedication().setReference(Reference30_50.convertReference(src.getMedicationReference()));
077    if (src.hasSubject())
078      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
079    if (src.hasContext())
080      tgt.setEncounter(Reference30_50.convertReference(src.getContext()));
081    for (org.hl7.fhir.dstu3.model.Reference t : src.getSupportingInformation())
082      tgt.addSupportingInformation(Reference30_50.convertReference(t));
083    if (src.hasEffective())
084      tgt.setOccurence(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getEffective()));
085    for (org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent t : src.getPerformer())
086      tgt.addPerformer(convertMedicationAdministrationPerformerComponent(t));
087    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode())
088      tgt.addReason(Reference30_50.convertCodeableConceptToCodableReference(t));
089    for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference())
090      tgt.addReason(Reference30_50.convertReferenceToCodableReference(t));
091    if (src.hasPrescription())
092      tgt.setRequest(Reference30_50.convertReference(src.getPrescription()));
093    for (org.hl7.fhir.dstu3.model.Reference t : src.getDevice()) tgt.addDevice(Reference30_50.convertReference(t));
094    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
095    if (src.hasDosage())
096      tgt.setDosage(convertMedicationAdministrationDosageComponent(src.getDosage()));
097    for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory())
098      tgt.addEventHistory(Reference30_50.convertReference(t));
099    return tgt;
100  }
101
102  public static org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent convertMedicationAdministrationDosageComponent(org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent src) throws FHIRException {
103    if (src == null)
104      return null;
105    org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent tgt = new org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent();
106    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
107    if (src.hasText())
108      tgt.setTextElement(String30_50.convertString(src.getTextElement()));
109    if (src.hasSite())
110      tgt.setSite(CodeableConcept30_50.convertCodeableConcept(src.getSite()));
111    if (src.hasRoute())
112      tgt.setRoute(CodeableConcept30_50.convertCodeableConcept(src.getRoute()));
113    if (src.hasMethod())
114      tgt.setMethod(CodeableConcept30_50.convertCodeableConcept(src.getMethod()));
115    if (src.hasDose())
116      tgt.setDose(SimpleQuantity30_50.convertSimpleQuantity(src.getDose()));
117    if (src.hasRate())
118      tgt.setRate(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getRate()));
119    return tgt;
120  }
121
122  public static org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent convertMedicationAdministrationDosageComponent(org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent src) throws FHIRException {
123    if (src == null)
124      return null;
125    org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent tgt = new org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent();
126    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
127    if (src.hasText())
128      tgt.setTextElement(String30_50.convertString(src.getTextElement()));
129    if (src.hasSite())
130      tgt.setSite(CodeableConcept30_50.convertCodeableConcept(src.getSite()));
131    if (src.hasRoute())
132      tgt.setRoute(CodeableConcept30_50.convertCodeableConcept(src.getRoute()));
133    if (src.hasMethod())
134      tgt.setMethod(CodeableConcept30_50.convertCodeableConcept(src.getMethod()));
135    if (src.hasDose())
136      tgt.setDose(SimpleQuantity30_50.convertSimpleQuantity(src.getDose()));
137    if (src.hasRate())
138      tgt.setRate(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getRate()));
139    return tgt;
140  }
141
142  public static org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent convertMedicationAdministrationPerformerComponent(org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent src) throws FHIRException {
143    if (src == null)
144      return null;
145    org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent tgt = new org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent();
146    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
147    if (src.hasActor())
148      tgt.setActor(Reference30_50.convertReference(src.getActor()));
149    return tgt;
150  }
151
152  public static org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent convertMedicationAdministrationPerformerComponent(org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent src) throws FHIRException {
153    if (src == null)
154      return null;
155    org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent tgt = new org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent();
156    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
157    if (src.hasActor())
158      tgt.setActor(Reference30_50.convertReference(src.getActor()));
159    return tgt;
160  }
161
162  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodes> convertMedicationAdministrationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus> src) {
163    if (src == null)
164      return null;
165    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new MedicationAdministrationStatusCodesEnumFactory());
166    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
167    tgt.setValue(org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodes.fromCode(src.getValueAsString()));
168    return tgt;
169  }
170
171  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus> convertMedicationAdministrationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodes> src) {
172    if (src == null)
173      return null;
174    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus>();
175    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
176    tgt.setValue(org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(src.getValueAsString()));
177    return tgt;
178  }
179}