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.Reference30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Range30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.SimpleQuantity30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Instant30_40;
010import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40;
011import org.hl7.fhir.exceptions.FHIRException;
012
013public class Observation30_40 {
014
015  public static org.hl7.fhir.r4.model.Observation convertObservation(org.hl7.fhir.dstu3.model.Observation src) throws FHIRException {
016    if (src == null)
017      return null;
018    org.hl7.fhir.r4.model.Observation tgt = new org.hl7.fhir.r4.model.Observation();
019    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
020    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
021      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
022    for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_40.convertReference(t));
023    if (src.hasStatus())
024      tgt.setStatusElement(convertObservationStatus(src.getStatusElement()));
025    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getCategory())
026      tgt.addCategory(CodeableConcept30_40.convertCodeableConcept(t));
027    if (src.hasCode())
028      tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
029    if (src.hasSubject())
030      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
031    if (src.hasContext())
032      tgt.setEncounter(Reference30_40.convertReference(src.getContext()));
033    if (src.hasEffective())
034      tgt.setEffective(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getEffective()));
035    if (src.hasIssued())
036      tgt.setIssuedElement(Instant30_40.convertInstant(src.getIssuedElement()));
037    for (org.hl7.fhir.dstu3.model.Reference t : src.getPerformer())
038      tgt.addPerformer(Reference30_40.convertReference(t));
039    if (src.hasValue())
040      tgt.setValue(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getValue()));
041    if (src.hasDataAbsentReason())
042      tgt.setDataAbsentReason(CodeableConcept30_40.convertCodeableConcept(src.getDataAbsentReason()));
043    if (src.hasInterpretation())
044      tgt.addInterpretation(CodeableConcept30_40.convertCodeableConcept(src.getInterpretation()));
045    if (src.hasComment())
046      tgt.addNote().setText(src.getComment());
047    if (src.hasBodySite())
048      tgt.setBodySite(CodeableConcept30_40.convertCodeableConcept(src.getBodySite()));
049    if (src.hasMethod())
050      tgt.setMethod(CodeableConcept30_40.convertCodeableConcept(src.getMethod()));
051    if (src.hasSpecimen())
052      tgt.setSpecimen(Reference30_40.convertReference(src.getSpecimen()));
053    if (src.hasDevice())
054      tgt.setDevice(Reference30_40.convertReference(src.getDevice()));
055    for (org.hl7.fhir.dstu3.model.Observation.ObservationReferenceRangeComponent t : src.getReferenceRange())
056      tgt.addReferenceRange(convertObservationReferenceRangeComponent(t));
057    for (org.hl7.fhir.dstu3.model.Observation.ObservationRelatedComponent t : src.getRelated())
058      if (t.getType() == org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType.HASMEMBER)
059        tgt.addHasMember(Reference30_40.convertReference(t.getTarget()));
060      else if (t.getType() == org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType.DERIVEDFROM)
061        tgt.addDerivedFrom(Reference30_40.convertReference(t.getTarget()));
062    for (org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent t : src.getComponent())
063      tgt.addComponent(convertObservationComponentComponent(t));
064    return tgt;
065  }
066
067  public static org.hl7.fhir.dstu3.model.Observation convertObservation(org.hl7.fhir.r4.model.Observation src) throws FHIRException {
068    if (src == null)
069      return null;
070    org.hl7.fhir.dstu3.model.Observation tgt = new org.hl7.fhir.dstu3.model.Observation();
071    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
072    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
073      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
074    for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_40.convertReference(t));
075    if (src.hasStatus())
076      tgt.setStatusElement(convertObservationStatus(src.getStatusElement()));
077    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory())
078      tgt.addCategory(CodeableConcept30_40.convertCodeableConcept(t));
079    if (src.hasCode())
080      tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
081    if (src.hasSubject())
082      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
083    if (src.hasEncounter())
084      tgt.setContext(Reference30_40.convertReference(src.getEncounter()));
085    if (src.hasEffective())
086      tgt.setEffective(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getEffective()));
087    if (src.hasIssued())
088      tgt.setIssuedElement(Instant30_40.convertInstant(src.getIssuedElement()));
089    for (org.hl7.fhir.r4.model.Reference t : src.getPerformer()) tgt.addPerformer(Reference30_40.convertReference(t));
090    if (src.hasValue())
091      tgt.setValue(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getValue()));
092    if (src.hasDataAbsentReason())
093      tgt.setDataAbsentReason(CodeableConcept30_40.convertCodeableConcept(src.getDataAbsentReason()));
094    if (src.hasInterpretation())
095      tgt.setInterpretation(CodeableConcept30_40.convertCodeableConcept(src.getInterpretationFirstRep()));
096    if (src.hasNote())
097      tgt.setComment(src.getNoteFirstRep().getText());
098    if (src.hasBodySite())
099      tgt.setBodySite(CodeableConcept30_40.convertCodeableConcept(src.getBodySite()));
100    if (src.hasMethod())
101      tgt.setMethod(CodeableConcept30_40.convertCodeableConcept(src.getMethod()));
102    if (src.hasSpecimen())
103      tgt.setSpecimen(Reference30_40.convertReference(src.getSpecimen()));
104    if (src.hasDevice())
105      tgt.setDevice(Reference30_40.convertReference(src.getDevice()));
106    for (org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent t : src.getReferenceRange())
107      tgt.addReferenceRange(convertObservationReferenceRangeComponent(t));
108    for (org.hl7.fhir.r4.model.Reference t : src.getHasMember())
109      tgt.addRelated(convertObservationRelatedComponent(t, org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType.HASMEMBER));
110    for (org.hl7.fhir.r4.model.Reference t : src.getDerivedFrom())
111      tgt.addRelated(convertObservationRelatedComponent(t, org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType.DERIVEDFROM));
112    for (org.hl7.fhir.r4.model.Observation.ObservationComponentComponent t : src.getComponent())
113      tgt.addComponent(convertObservationComponentComponent(t));
114    return tgt;
115  }
116
117  public static org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent convertObservationComponentComponent(org.hl7.fhir.r4.model.Observation.ObservationComponentComponent src) throws FHIRException {
118    if (src == null)
119      return null;
120    org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent tgt = new org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent();
121    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
122    if (src.hasCode())
123      tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
124    if (src.hasValue())
125      tgt.setValue(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getValue()));
126    if (src.hasDataAbsentReason())
127      tgt.setDataAbsentReason(CodeableConcept30_40.convertCodeableConcept(src.getDataAbsentReason()));
128    if (src.hasInterpretation())
129      tgt.setInterpretation(CodeableConcept30_40.convertCodeableConcept(src.getInterpretationFirstRep()));
130    for (org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent t : src.getReferenceRange())
131      tgt.addReferenceRange(convertObservationReferenceRangeComponent(t));
132    return tgt;
133  }
134
135  public static org.hl7.fhir.r4.model.Observation.ObservationComponentComponent convertObservationComponentComponent(org.hl7.fhir.dstu3.model.Observation.ObservationComponentComponent src) throws FHIRException {
136    if (src == null)
137      return null;
138    org.hl7.fhir.r4.model.Observation.ObservationComponentComponent tgt = new org.hl7.fhir.r4.model.Observation.ObservationComponentComponent();
139    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
140    if (src.hasCode())
141      tgt.setCode(CodeableConcept30_40.convertCodeableConcept(src.getCode()));
142    if (src.hasValue())
143      tgt.setValue(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getValue()));
144    if (src.hasDataAbsentReason())
145      tgt.setDataAbsentReason(CodeableConcept30_40.convertCodeableConcept(src.getDataAbsentReason()));
146    if (src.hasInterpretation())
147      tgt.addInterpretation(CodeableConcept30_40.convertCodeableConcept(src.getInterpretation()));
148    for (org.hl7.fhir.dstu3.model.Observation.ObservationReferenceRangeComponent t : src.getReferenceRange())
149      tgt.addReferenceRange(convertObservationReferenceRangeComponent(t));
150    return tgt;
151  }
152
153  public static org.hl7.fhir.dstu3.model.Observation.ObservationReferenceRangeComponent convertObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent src) throws FHIRException {
154    if (src == null)
155      return null;
156    org.hl7.fhir.dstu3.model.Observation.ObservationReferenceRangeComponent tgt = new org.hl7.fhir.dstu3.model.Observation.ObservationReferenceRangeComponent();
157    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
158    if (src.hasLow())
159      tgt.setLow(SimpleQuantity30_40.convertSimpleQuantity(src.getLow()));
160    if (src.hasHigh())
161      tgt.setHigh(SimpleQuantity30_40.convertSimpleQuantity(src.getHigh()));
162    if (src.hasType())
163      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
164    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getAppliesTo())
165      tgt.addAppliesTo(CodeableConcept30_40.convertCodeableConcept(t));
166    if (src.hasAge())
167      tgt.setAge(Range30_40.convertRange(src.getAge()));
168    if (src.hasText())
169      tgt.setTextElement(String30_40.convertString(src.getTextElement()));
170    return tgt;
171  }
172
173  public static org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent convertObservationReferenceRangeComponent(org.hl7.fhir.dstu3.model.Observation.ObservationReferenceRangeComponent src) throws FHIRException {
174    if (src == null)
175      return null;
176    org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent tgt = new org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent();
177    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
178    if (src.hasLow())
179      tgt.setLow(SimpleQuantity30_40.convertSimpleQuantity(src.getLow()));
180    if (src.hasHigh())
181      tgt.setHigh(SimpleQuantity30_40.convertSimpleQuantity(src.getHigh()));
182    if (src.hasType())
183      tgt.setType(CodeableConcept30_40.convertCodeableConcept(src.getType()));
184    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getAppliesTo())
185      tgt.addAppliesTo(CodeableConcept30_40.convertCodeableConcept(t));
186    if (src.hasAge())
187      tgt.setAge(Range30_40.convertRange(src.getAge()));
188    if (src.hasText())
189      tgt.setTextElement(String30_40.convertString(src.getTextElement()));
190    return tgt;
191  }
192
193  public static org.hl7.fhir.dstu3.model.Observation.ObservationRelatedComponent convertObservationRelatedComponent(org.hl7.fhir.r4.model.Reference src, org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType type) throws FHIRException {
194    if (src == null)
195      return null;
196    org.hl7.fhir.dstu3.model.Observation.ObservationRelatedComponent tgt = new org.hl7.fhir.dstu3.model.Observation.ObservationRelatedComponent();
197    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
198    tgt.setType(type);
199    tgt.setTarget(Reference30_40.convertReference(src));
200    return tgt;
201  }
202
203  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Observation.ObservationStatus> convertObservationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Observation.ObservationStatus> src) throws FHIRException {
204    if (src == null || src.isEmpty())
205      return null;
206    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Observation.ObservationStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Observation.ObservationStatusEnumFactory());
207    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
208    switch (src.getValue()) {
209      case REGISTERED:
210        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.REGISTERED);
211        break;
212      case PRELIMINARY:
213        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.PRELIMINARY);
214        break;
215      case FINAL:
216        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.FINAL);
217        break;
218      case AMENDED:
219        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.AMENDED);
220        break;
221      case CORRECTED:
222        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.CORRECTED);
223        break;
224      case CANCELLED:
225        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.CANCELLED);
226        break;
227      case ENTEREDINERROR:
228        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.ENTEREDINERROR);
229        break;
230      case UNKNOWN:
231        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.UNKNOWN);
232        break;
233      default:
234        tgt.setValue(org.hl7.fhir.dstu3.model.Observation.ObservationStatus.NULL);
235        break;
236    }
237    return tgt;
238  }
239
240  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Observation.ObservationStatus> convertObservationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Observation.ObservationStatus> src) throws FHIRException {
241    if (src == null || src.isEmpty())
242      return null;
243    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Observation.ObservationStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Observation.ObservationStatusEnumFactory());
244    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
245    switch (src.getValue()) {
246      case REGISTERED:
247        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.REGISTERED);
248        break;
249      case PRELIMINARY:
250        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.PRELIMINARY);
251        break;
252      case FINAL:
253        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.FINAL);
254        break;
255      case AMENDED:
256        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.AMENDED);
257        break;
258      case CORRECTED:
259        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.CORRECTED);
260        break;
261      case CANCELLED:
262        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.CANCELLED);
263        break;
264      case ENTEREDINERROR:
265        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.ENTEREDINERROR);
266        break;
267      case UNKNOWN:
268        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.UNKNOWN);
269        break;
270      default:
271        tgt.setValue(org.hl7.fhir.r4.model.Observation.ObservationStatus.NULL);
272        break;
273    }
274    return tgt;
275  }
276}