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