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