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