001package org.hl7.fhir.convertors.conv10_50.resources10_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_50;
004import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Reference10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Ratio10_50;
008import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Timing10_50;
009import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Boolean10_50;
010import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
011import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50;
012import org.hl7.fhir.exceptions.FHIRException;
013import org.hl7.fhir.r5.model.Dosage.DosageDoseAndRateComponent;
014
015public class MedicationStatement10_50 {
016
017  public static org.hl7.fhir.dstu2.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.r5.model.MedicationStatement src) throws FHIRException {
018    if (src == null || src.isEmpty())
019      return null;
020    org.hl7.fhir.dstu2.model.MedicationStatement tgt = new org.hl7.fhir.dstu2.model.MedicationStatement();
021    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
022    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
023      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
024    if (src.hasStatus())
025      tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement()));
026    if (src.getMedication().hasConcept()) {
027      tgt.setMedication(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getMedication().getConcept()));
028    }
029    if (src.getMedication().hasReference()) {
030      tgt.setMedication(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getMedication().getReference()));
031    }
032    if (src.hasSubject())
033      tgt.setPatient(Reference10_50.convertReference(src.getSubject()));
034    if (src.hasEffective())
035      tgt.setEffective(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getEffective()));
036    if (src.hasInformationSource())
037      tgt.setInformationSource(Reference10_50.convertReference(src.getInformationSourceFirstRep()));
038    for (org.hl7.fhir.r5.model.Reference t : src.getDerivedFrom())
039      tgt.addSupportingInformation(Reference10_50.convertReference(t));
040    if (src.hasDateAsserted())
041      tgt.setDateAssertedElement(DateTime10_50.convertDateTime(src.getDateAssertedElement()));
042    for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.setNote(t.getText());
043    for (org.hl7.fhir.r5.model.Dosage t : src.getDosage()) tgt.addDosage(convertMedicationStatementDosageComponent(t));
044    return tgt;
045  }
046
047  public static org.hl7.fhir.r5.model.MedicationStatement convertMedicationStatement(org.hl7.fhir.dstu2.model.MedicationStatement src) throws FHIRException {
048    if (src == null || src.isEmpty())
049      return null;
050    org.hl7.fhir.r5.model.MedicationStatement tgt = new org.hl7.fhir.r5.model.MedicationStatement();
051    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
052    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
053      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
054    if (src.hasStatus())
055      tgt.setStatusElement(convertMedicationStatementStatus(src.getStatusElement()));
056    if (src.hasMedicationCodeableConcept()) {
057      tgt.getMedication().setConcept(CodeableConcept10_50.convertCodeableConcept(src.getMedicationCodeableConcept()));
058    }
059    if (src.hasMedicationReference()) {
060      tgt.getMedication().setReference(Reference10_50.convertReference(src.getMedicationReference()));
061    }
062    if (src.hasPatient())
063      tgt.setSubject(Reference10_50.convertReference(src.getPatient()));
064    if (src.hasEffective())
065      tgt.setEffective(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getEffective()));
066    if (src.hasInformationSource())
067      tgt.addInformationSource(Reference10_50.convertReference(src.getInformationSource()));
068    for (org.hl7.fhir.dstu2.model.Reference t : src.getSupportingInformation())
069      tgt.addDerivedFrom(Reference10_50.convertReference(t));
070    if (src.hasDateAsserted())
071      tgt.setDateAssertedElement(DateTime10_50.convertDateTime(src.getDateAssertedElement()));
072    if (src.hasNote())
073      tgt.addNote().setText(src.getNote());
074    for (org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent t : src.getDosage())
075      tgt.addDosage(convertMedicationStatementDosageComponent(t));
076    return tgt;
077  }
078
079  public static org.hl7.fhir.r5.model.Dosage convertMedicationStatementDosageComponent(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent src) throws FHIRException {
080    if (src == null || src.isEmpty())
081      return null;
082    org.hl7.fhir.r5.model.Dosage tgt = new org.hl7.fhir.r5.model.Dosage();
083    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
084    if (src.hasTextElement())
085      tgt.setTextElement(String10_50.convertString(src.getTextElement()));
086    if (src.hasTiming())
087      tgt.setTiming(Timing10_50.convertTiming(src.getTiming()));
088    if (src.hasAsNeededBooleanType())
089      tgt.setAsNeededElement(Boolean10_50.convertBoolean(src.getAsNeededBooleanType()));
090    if (src.hasSiteCodeableConcept())
091      tgt.setSite(CodeableConcept10_50.convertCodeableConcept(src.getSiteCodeableConcept()));
092    if (src.hasRoute())
093      tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute()));
094    if (src.hasMethod())
095      tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod()));
096    if (src.hasRate()) {
097      DosageDoseAndRateComponent dr = tgt.addDoseAndRate();
098      if (src.hasRate())
099        dr.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getRate()));
100    }
101    if (src.hasMaxDosePerPeriod())
102      tgt.addMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriod()));
103    return tgt;
104  }
105
106  public static org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent convertMedicationStatementDosageComponent(org.hl7.fhir.r5.model.Dosage src) throws FHIRException {
107    if (src == null || src.isEmpty())
108      return null;
109    org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent tgt = new org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementDosageComponent();
110    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
111    if (src.hasTextElement())
112      tgt.setTextElement(String10_50.convertString(src.getTextElement()));
113    if (src.hasTiming())
114      tgt.setTiming(Timing10_50.convertTiming(src.getTiming()));
115    if (src.hasAsNeeded())
116      tgt.setAsNeeded(Boolean10_50.convertBoolean(src.getAsNeededElement()));
117    if (src.hasSite())
118      tgt.setSite(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getSite()));
119    if (src.hasRoute())
120      tgt.setRoute(CodeableConcept10_50.convertCodeableConcept(src.getRoute()));
121    if (src.hasMethod())
122      tgt.setMethod(CodeableConcept10_50.convertCodeableConcept(src.getMethod()));
123    if (src.hasDoseAndRate() && src.getDoseAndRate().get(0).hasRate())
124      tgt.setRate(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getDoseAndRate().get(0).getRate()));
125    if (src.hasMaxDosePerPeriod())
126      tgt.setMaxDosePerPeriod(Ratio10_50.convertRatio(src.getMaxDosePerPeriodFirstRep()));
127    return tgt;
128  }
129
130  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> convertMedicationStatementStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> src) throws FHIRException {
131    if (src == null || src.isEmpty())
132      return null;
133    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodesEnumFactory());
134    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
135    switch (src.getValue()) {
136      case ACTIVE:
137        tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED);
138        break;
139      case COMPLETED:
140        tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED);
141        break;
142      case ENTEREDINERROR:
143        tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.ENTEREDINERROR);
144        break;
145      case INTENDED:
146        tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.RECORDED);
147        break;
148      default:
149        tgt.setValue(org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes.NULL);
150        break;
151    }
152    return tgt;
153  }
154
155  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> convertMedicationStatementStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.MedicationStatement.MedicationStatementStatusCodes> src) throws FHIRException {
156    if (src == null || src.isEmpty())
157      return null;
158    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatusEnumFactory());
159    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
160    switch (src.getValue()) {
161//            case ACTIVE:
162//                tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ACTIVE);
163//                break;
164      case RECORDED:
165        tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.COMPLETED);
166        break;
167      case ENTEREDINERROR:
168        tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ENTEREDINERROR);
169        break;
170      case DRAFT:
171        tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.ACTIVE);
172        break;
173      default:
174        tgt.setValue(org.hl7.fhir.dstu2.model.MedicationStatement.MedicationStatementStatus.NULL);
175        break;
176    }
177    return tgt;
178  }
179}