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.Dosage30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Annotation30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
010import org.hl7.fhir.dstu3.model.Enumeration;
011import org.hl7.fhir.dstu3.model.MedicationStatement;
012import org.hl7.fhir.exceptions.FHIRException;
013
014public class MedicationStatement30_40 {
015
016  public static org.hl7.fhir.dstu3.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r4.model.MedicationStatement src) throws FHIRException {
017    if (src == null)
018      return null;
019    org.hl7.fhir.dstu3.model.MedicationStatement tgt = new org.hl7.fhir.dstu3.model.MedicationStatement();
020    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
021    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
022      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
023    for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_40.convertReference(t));
024    for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_40.convertReference(t));
025    if (src.hasContext())
026      tgt.setContext(Reference30_40.convertReference(src.getContext()));
027    if (src.hasStatus())
028      tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement()));
029    if (src.hasCategory())
030      tgt.setCategory(CodeableConcept30_40.convertCodeableConcept(src.getCategory()));
031    if (src.hasMedication())
032      tgt.setMedication(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getMedication()));
033    if (src.hasEffective())
034      tgt.setEffective(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getEffective()));
035    if (src.hasDateAsserted())
036      tgt.setDateAssertedElement(DateTime30_40.convertDateTime(src.getDateAssertedElement()));
037    if (src.hasInformationSource())
038      tgt.setInformationSource(Reference30_40.convertReference(src.getInformationSource()));
039    if (src.hasSubject())
040      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
041    for (org.hl7.fhir.r4.model.Reference t : src.getDerivedFrom())
042      tgt.addDerivedFrom(Reference30_40.convertReference(t));
043    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode())
044      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
045    for (org.hl7.fhir.r4.model.Reference t : src.getReasonReference())
046      tgt.addReasonReference(Reference30_40.convertReference(t));
047    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
048    for (org.hl7.fhir.r4.model.Dosage t : src.getDosage()) tgt.addDosage(Dosage30_40.convertDosage(t));
049    return tgt;
050  }
051
052  public static org.hl7.fhir.r4.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.dstu3.model.MedicationStatement src) throws FHIRException {
053    if (src == null)
054      return null;
055    org.hl7.fhir.r4.model.MedicationStatement tgt = new org.hl7.fhir.r4.model.MedicationStatement();
056    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
057    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
058      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
059    for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_40.convertReference(t));
060    for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_40.convertReference(t));
061    if (src.hasContext())
062      tgt.setContext(Reference30_40.convertReference(src.getContext()));
063    if (src.hasStatus())
064      tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement()));
065    if (src.hasCategory())
066      tgt.setCategory(CodeableConcept30_40.convertCodeableConcept(src.getCategory()));
067    if (src.hasMedication())
068      tgt.setMedication(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getMedication()));
069    if (src.hasEffective())
070      tgt.setEffective(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getEffective()));
071    if (src.hasDateAsserted())
072      tgt.setDateAssertedElement(DateTime30_40.convertDateTime(src.getDateAssertedElement()));
073    if (src.hasInformationSource())
074      tgt.setInformationSource(Reference30_40.convertReference(src.getInformationSource()));
075    if (src.hasSubject())
076      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
077    for (org.hl7.fhir.dstu3.model.Reference t : src.getDerivedFrom())
078      tgt.addDerivedFrom(Reference30_40.convertReference(t));
079    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode())
080      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
081    for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference())
082      tgt.addReasonReference(Reference30_40.convertReference(t));
083    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
084    for (org.hl7.fhir.dstu3.model.Dosage t : src.getDosage()) tgt.addDosage(Dosage30_40.convertDosage(t));
085    return tgt;
086  }
087
088  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException {
089      if (src == null || src.isEmpty())
090          return null;
091      Enumeration<MedicationStatement.MedicationStatementStatus> tgt = new Enumeration<>(new MedicationStatement.MedicationStatementStatusEnumFactory());
092      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
093      if (src.getValue() == null) {
094          tgt.setValue(null);
095      } else {
096          switch (src.getValue()) {
097              case ACTIVE:
098                  tgt.setValue(MedicationStatement.MedicationStatementStatus.ACTIVE);
099                  break;
100              case COMPLETED:
101                  tgt.setValue(MedicationStatement.MedicationStatementStatus.COMPLETED);
102                  break;
103              case ENTEREDINERROR:
104                  tgt.setValue(MedicationStatement.MedicationStatementStatus.ENTEREDINERROR);
105                  break;
106              case INTENDED:
107                  tgt.setValue(MedicationStatement.MedicationStatementStatus.INTENDED);
108                  break;
109              case STOPPED:
110                  tgt.setValue(MedicationStatement.MedicationStatementStatus.STOPPED);
111                  break;
112              case ONHOLD:
113                  tgt.setValue(MedicationStatement.MedicationStatementStatus.ONHOLD);
114                  break;
115              default:
116                  tgt.setValue(MedicationStatement.MedicationStatementStatus.NULL);
117                  break;
118          }
119      }
120      return tgt;
121  }
122
123  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException {
124      if (src == null || src.isEmpty())
125          return null;
126      org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatusEnumFactory());
127      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
128      if (src.getValue() == null) {
129          tgt.setValue(null);
130      } else {
131          switch (src.getValue()) {
132              case ACTIVE:
133                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.ACTIVE);
134                  break;
135              case COMPLETED:
136                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.COMPLETED);
137                  break;
138              case ENTEREDINERROR:
139                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.ENTEREDINERROR);
140                  break;
141              case INTENDED:
142                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.INTENDED);
143                  break;
144              case STOPPED:
145                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.STOPPED);
146                  break;
147              case ONHOLD:
148                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.ONHOLD);
149                  break;
150              default:
151                  tgt.setValue(org.hl7.fhir.r4.model.MedicationStatement.MedicationStatementStatus.NULL);
152                  break;
153          }
154      }
155      return tgt;
156  }
157}