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.CodeableConcept30_50;
006import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.Identifier30_50;
007import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Decimal30_50;
008import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50;
009import org.hl7.fhir.exceptions.FHIRException;
010
011public class RiskAssessment30_50 {
012
013  public static org.hl7.fhir.r5.model.RiskAssessment convertRiskAssessment(org.hl7.fhir.dstu3.model.RiskAssessment src) throws FHIRException {
014    if (src == null)
015      return null;
016    org.hl7.fhir.r5.model.RiskAssessment tgt = new org.hl7.fhir.r5.model.RiskAssessment();
017    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
018    if (src.hasIdentifier())
019      tgt.addIdentifier(Identifier30_50.convertIdentifier(src.getIdentifier()));
020    if (src.hasBasedOn())
021      tgt.setBasedOn(Reference30_50.convertReference(src.getBasedOn()));
022    if (src.hasParent())
023      tgt.setParent(Reference30_50.convertReference(src.getParent()));
024    if (src.hasStatus())
025      tgt.setStatusElement(convertRiskAssessmentStatus(src.getStatusElement()));
026    if (src.hasMethod())
027      tgt.setMethod(CodeableConcept30_50.convertCodeableConcept(src.getMethod()));
028    if (src.hasCode())
029      tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode()));
030    if (src.hasSubject())
031      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
032    if (src.hasContext())
033      tgt.setEncounter(Reference30_50.convertReference(src.getContext()));
034    if (src.hasOccurrence())
035      tgt.setOccurrence(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getOccurrence()));
036    if (src.hasCondition())
037      tgt.setCondition(Reference30_50.convertReference(src.getCondition()));
038    if (src.hasPerformer())
039      tgt.setPerformer(Reference30_50.convertReference(src.getPerformer()));
040    if (src.hasReason()) {
041      if (src.getReason() instanceof org.hl7.fhir.dstu3.model.CodeableConcept)
042        tgt.addReason(Reference30_50.convertCodeableConceptToCodableReference((org.hl7.fhir.dstu3.model.CodeableConcept) src.getReason()));
043      else if (src.getReason() instanceof org.hl7.fhir.dstu3.model.Reference)
044        tgt.addReason(Reference30_50.convertReferenceToCodableReference((org.hl7.fhir.dstu3.model.Reference) src.getReason()));
045    }
046    for (org.hl7.fhir.dstu3.model.Reference t : src.getBasis()) tgt.addBasis(Reference30_50.convertReference(t));
047    for (org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentPredictionComponent t : src.getPrediction())
048      tgt.addPrediction(convertRiskAssessmentPredictionComponent(t));
049    if (src.hasMitigation())
050      tgt.setMitigationElement(String30_50.convertString(src.getMitigationElement()));
051    if (src.hasComment())
052      tgt.addNote().setText(src.getComment());
053    return tgt;
054  }
055
056  public static org.hl7.fhir.dstu3.model.RiskAssessment convertRiskAssessment(org.hl7.fhir.r5.model.RiskAssessment src) throws FHIRException {
057    if (src == null)
058      return null;
059    org.hl7.fhir.dstu3.model.RiskAssessment tgt = new org.hl7.fhir.dstu3.model.RiskAssessment();
060    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt);
061    if (src.hasIdentifier())
062      tgt.setIdentifier(Identifier30_50.convertIdentifier(src.getIdentifierFirstRep()));
063    if (src.hasBasedOn())
064      tgt.setBasedOn(Reference30_50.convertReference(src.getBasedOn()));
065    if (src.hasParent())
066      tgt.setParent(Reference30_50.convertReference(src.getParent()));
067    if (src.hasStatus())
068      tgt.setStatusElement(convertRiskAssessmentStatus(src.getStatusElement()));
069    if (src.hasMethod())
070      tgt.setMethod(CodeableConcept30_50.convertCodeableConcept(src.getMethod()));
071    if (src.hasCode())
072      tgt.setCode(CodeableConcept30_50.convertCodeableConcept(src.getCode()));
073    if (src.hasSubject())
074      tgt.setSubject(Reference30_50.convertReference(src.getSubject()));
075    if (src.hasEncounter())
076      tgt.setContext(Reference30_50.convertReference(src.getEncounter()));
077    if (src.hasOccurrence())
078      tgt.setOccurrence(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getOccurrence()));
079    if (src.hasCondition())
080      tgt.setCondition(Reference30_50.convertReference(src.getCondition()));
081    if (src.hasPerformer())
082      tgt.setPerformer(Reference30_50.convertReference(src.getPerformer()));
083    if (src.hasReason() && src.getReasonFirstRep().hasConcept())
084      tgt.setReason(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getReasonFirstRep().getConcept()));
085    if (src.hasReason() && src.getReasonFirstRep().hasReference())
086      tgt.setReason(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getReasonFirstRep().getReference()));
087    for (org.hl7.fhir.r5.model.Reference t : src.getBasis()) tgt.addBasis(Reference30_50.convertReference(t));
088    for (org.hl7.fhir.r5.model.RiskAssessment.RiskAssessmentPredictionComponent t : src.getPrediction())
089      tgt.addPrediction(convertRiskAssessmentPredictionComponent(t));
090    if (src.hasMitigation())
091      tgt.setMitigationElement(String30_50.convertString(src.getMitigationElement()));
092    if (src.hasNote())
093      tgt.setComment(src.getNoteFirstRep().getText());
094    return tgt;
095  }
096
097  public static org.hl7.fhir.r5.model.RiskAssessment.RiskAssessmentPredictionComponent convertRiskAssessmentPredictionComponent(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentPredictionComponent src) throws FHIRException {
098    if (src == null)
099      return null;
100    org.hl7.fhir.r5.model.RiskAssessment.RiskAssessmentPredictionComponent tgt = new org.hl7.fhir.r5.model.RiskAssessment.RiskAssessmentPredictionComponent();
101    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
102    if (src.hasOutcome())
103      tgt.setOutcome(CodeableConcept30_50.convertCodeableConcept(src.getOutcome()));
104    if (src.hasProbability())
105      tgt.setProbability(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getProbability()));
106    if (src.hasQualitativeRisk())
107      tgt.setQualitativeRisk(CodeableConcept30_50.convertCodeableConcept(src.getQualitativeRisk()));
108    if (src.hasRelativeRisk())
109      tgt.setRelativeRiskElement(Decimal30_50.convertDecimal(src.getRelativeRiskElement()));
110    if (src.hasWhen())
111      tgt.setWhen(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getWhen()));
112    if (src.hasRationale())
113      tgt.setRationaleElement(String30_50.convertString(src.getRationaleElement()));
114    return tgt;
115  }
116
117  public static org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentPredictionComponent convertRiskAssessmentPredictionComponent(org.hl7.fhir.r5.model.RiskAssessment.RiskAssessmentPredictionComponent src) throws FHIRException {
118    if (src == null)
119      return null;
120    org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentPredictionComponent tgt = new org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentPredictionComponent();
121    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
122    if (src.hasOutcome())
123      tgt.setOutcome(CodeableConcept30_50.convertCodeableConcept(src.getOutcome()));
124    if (src.hasProbability())
125      tgt.setProbability(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getProbability()));
126    if (src.hasQualitativeRisk())
127      tgt.setQualitativeRisk(CodeableConcept30_50.convertCodeableConcept(src.getQualitativeRisk()));
128    if (src.hasRelativeRisk())
129      tgt.setRelativeRiskElement(Decimal30_50.convertDecimal(src.getRelativeRiskElement()));
130    if (src.hasWhen())
131      tgt.setWhen(ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().convertType(src.getWhen()));
132    if (src.hasRationale())
133      tgt.setRationaleElement(String30_50.convertString(src.getRationaleElement()));
134    return tgt;
135  }
136
137  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.ObservationStatus> convertRiskAssessmentStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus> src) throws FHIRException {
138    if (src == null || src.isEmpty())
139      return null;
140    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.ObservationStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.ObservationStatusEnumFactory());
141    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
142    switch (src.getValue()) {
143      case REGISTERED:
144        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.REGISTERED);
145        break;
146      case PRELIMINARY:
147        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.PRELIMINARY);
148        break;
149      case FINAL:
150        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.FINAL);
151        break;
152      case AMENDED:
153        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.AMENDED);
154        break;
155      case CORRECTED:
156        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.CORRECTED);
157        break;
158      case CANCELLED:
159        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.CANCELLED);
160        break;
161      case ENTEREDINERROR:
162        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.ENTEREDINERROR);
163        break;
164      case UNKNOWN:
165        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.UNKNOWN);
166        break;
167      default:
168        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.ObservationStatus.NULL);
169        break;
170    }
171    return tgt;
172  }
173
174  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus> convertRiskAssessmentStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.ObservationStatus> src) throws FHIRException {
175    if (src == null || src.isEmpty())
176      return null;
177    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatusEnumFactory());
178    ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
179    switch (src.getValue()) {
180      case REGISTERED:
181        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.REGISTERED);
182        break;
183      case PRELIMINARY:
184        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.PRELIMINARY);
185        break;
186      case FINAL:
187        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.FINAL);
188        break;
189      case AMENDED:
190        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.AMENDED);
191        break;
192      case CORRECTED:
193        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.CORRECTED);
194        break;
195      case CANCELLED:
196        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.CANCELLED);
197        break;
198      case ENTEREDINERROR:
199        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.ENTEREDINERROR);
200        break;
201      case UNKNOWN:
202        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.UNKNOWN);
203        break;
204      default:
205        tgt.setValue(org.hl7.fhir.dstu3.model.RiskAssessment.RiskAssessmentStatus.NULL);
206        break;
207    }
208    return tgt;
209  }
210}