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 (CodeableReference t : src.getDevice())
052      if (t.hasReference())
053        tgt.addDevice(Reference30_50.convertReference(t.getReference()));
054    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
055    if (src.hasDosage())
056      tgt.setDosage(convertMedicationAdministrationDosageComponent(src.getDosage()));
057    for (org.hl7.fhir.r5.model.Reference t : src.getEventHistory())
058      tgt.addEventHistory(Reference30_50.convertReference(t));
059    return tgt;
060  }
061
062  public static org.hl7.fhir.r5.model.MedicationAdministration convertMedicationAdministration(org.hl7.fhir.dstu3.model.MedicationAdministration src) throws FHIRException {
063    if (src == null)
064      return null;
065    org.hl7.fhir.r5.model.MedicationAdministration tgt = new org.hl7.fhir.r5.model.MedicationAdministration();
066    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
067    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
068      tgt.addIdentifier(Identifier30_50.convertIdentifier(t));
069//    for (org.hl7.fhir.dstu3.model.Reference t : src.getDefinition()) tgt.addInstantiatesUri(t.getReference());
070    for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_50.convertReference(t));
071    if (src.hasStatus())
072      tgt.setStatusElement(convertMedicationAdministrationStatus(src.getStatusElement()));
073    if (src.hasCategory())
074      tgt.addCategory(CodeableConcept30_50.convertCodeableConcept(src.getCategory()));
075    if (src.hasMedicationCodeableConcept())
076      tgt.getMedication().setConcept(CodeableConcept30_50.convertCodeableConcept(src.getMedicationCodeableConcept()));
077    if (src.hasMedicationReference())
078      tgt.getMedication().setReference(Reference30_50.convertReference(src.getMedicationReference()));
079    if (src.hasSubject())
080      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
081    if (src.hasContext())
082      tgt.setEncounter(Reference30_50.convertReference(src.getContext()));
083    for (org.hl7.fhir.dstu3.model.Reference t : src.getSupportingInformation())
084      tgt.addSupportingInformation(Reference30_50.convertReference(t));
085    if (src.hasEffective())
086      tgt.setOccurence(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getEffective()));
087    for (org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent t : src.getPerformer())
088      tgt.addPerformer(convertMedicationAdministrationPerformerComponent(t));
089    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode())
090      tgt.addReason(Reference30_50.convertCodeableConceptToCodableReference(t));
091    for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference())
092      tgt.addReason(Reference30_50.convertReferenceToCodableReference(t));
093    if (src.hasPrescription())
094      tgt.setRequest(Reference30_50.convertReference(src.getPrescription()));
095    for (org.hl7.fhir.dstu3.model.Reference t : src.getDevice()) tgt.addDevice(Reference30_50.convertReferenceToCodableReference(t));
096    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_50.convertAnnotation(t));
097    if (src.hasDosage())
098      tgt.setDosage(convertMedicationAdministrationDosageComponent(src.getDosage()));
099    for (org.hl7.fhir.dstu3.model.Reference t : src.getEventHistory())
100      tgt.addEventHistory(Reference30_50.convertReference(t));
101    return tgt;
102  }
103
104  public static org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent convertMedicationAdministrationDosageComponent(org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent src) throws FHIRException {
105    if (src == null)
106      return null;
107    org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent tgt = new org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent();
108    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
109    if (src.hasText())
110      tgt.setTextElement(String30_50.convertString(src.getTextElement()));
111    if (src.hasSite())
112      tgt.setSite(CodeableConcept30_50.convertCodeableConcept(src.getSite()));
113    if (src.hasRoute())
114      tgt.setRoute(CodeableConcept30_50.convertCodeableConcept(src.getRoute()));
115    if (src.hasMethod())
116      tgt.setMethod(CodeableConcept30_50.convertCodeableConcept(src.getMethod()));
117    if (src.hasDose())
118      tgt.setDose(SimpleQuantity30_50.convertSimpleQuantity(src.getDose()));
119    if (src.hasRate())
120      tgt.setRate(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getRate()));
121    return tgt;
122  }
123
124  public static org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent convertMedicationAdministrationDosageComponent(org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent src) throws FHIRException {
125    if (src == null)
126      return null;
127    org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent tgt = new org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationDosageComponent();
128    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
129    if (src.hasText())
130      tgt.setTextElement(String30_50.convertString(src.getTextElement()));
131    if (src.hasSite())
132      tgt.setSite(CodeableConcept30_50.convertCodeableConcept(src.getSite()));
133    if (src.hasRoute())
134      tgt.setRoute(CodeableConcept30_50.convertCodeableConcept(src.getRoute()));
135    if (src.hasMethod())
136      tgt.setMethod(CodeableConcept30_50.convertCodeableConcept(src.getMethod()));
137    if (src.hasDose())
138      tgt.setDose(SimpleQuantity30_50.convertSimpleQuantity(src.getDose()));
139    if (src.hasRate())
140      tgt.setRate(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getRate()));
141    return tgt;
142  }
143
144  public static org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent convertMedicationAdministrationPerformerComponent(org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent src) throws FHIRException {
145    if (src == null)
146      return null;
147    org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent tgt = new org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent();
148    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
149    if (src.hasActor())
150      tgt.setActor(Reference30_50.convertReferenceToCodableReference(src.getActor()));
151    return tgt;
152  }
153
154  public static org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent convertMedicationAdministrationPerformerComponent(org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationPerformerComponent src) throws FHIRException {
155    if (src == null)
156      return null;
157    org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent tgt = new org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationPerformerComponent();
158    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
159    if (src.hasActor() && src.getActor().hasReference())
160      tgt.setActor(Reference30_50.convertReference(src.getActor().getReference()));
161    return tgt;
162  }
163
164  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) {
165    if (src == null)
166      return null;
167    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new MedicationAdministrationStatusCodesEnumFactory());
168    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
169    tgt.setValue(org.hl7.fhir.r5.model.MedicationAdministration.MedicationAdministrationStatusCodes.fromCode(src.getValueAsString()));
170    return tgt;
171  }
172
173  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) {
174    if (src == null)
175      return null;
176    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>();
177    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
178    tgt.setValue(org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus.fromCode(src.getValueAsString()));
179    return tgt;
180  }
181}