001package org.hl7.fhir.convertors.conv40_50;
002
003
004import org.hl7.fhir.convertors.VersionConvertor_40_50;
005import org.hl7.fhir.exceptions.FHIRException;
006
007import java.util.stream.Collectors;
008
009/*
010  Copyright (c) 2011+, HL7, Inc.
011  All rights reserved.
012  
013  Redistribution and use in source and binary forms, with or without modification, 
014  are permitted provided that the following conditions are met:
015  
016   * Redistributions of source code must retain the above copyright notice, this 
017     list of conditions and the following disclaimer.
018   * Redistributions in binary form must reproduce the above copyright notice, 
019     this list of conditions and the following disclaimer in the documentation 
020     and/or other materials provided with the distribution.
021   * Neither the name of HL7 nor the names of its contributors may be used to 
022     endorse or promote products derived from this software without specific 
023     prior written permission.
024  
025  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
026  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
027  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
028  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
029  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
030  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
031  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
032  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
033  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
034  POSSIBILITY OF SUCH DAMAGE.
035  
036*/
037// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
038public class AllergyIntolerance40_50 extends VersionConvertor_40_50 {
039
040    public static org.hl7.fhir.r5.model.AllergyIntolerance convertAllergyIntolerance(org.hl7.fhir.r4.model.AllergyIntolerance src) throws FHIRException {
041        if (src == null)
042            return null;
043        org.hl7.fhir.r5.model.AllergyIntolerance tgt = new org.hl7.fhir.r5.model.AllergyIntolerance();
044        copyDomainResource(src, tgt);
045        for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
046        if (src.hasClinicalStatus())
047            tgt.setClinicalStatus(convertCodeableConcept(src.getClinicalStatus()));
048        if (src.hasVerificationStatus())
049            tgt.setVerificationStatus(convertCodeableConcept(src.getVerificationStatus()));
050        if (src.hasType())
051            tgt.setTypeElement(convertAllergyIntoleranceType(src.getTypeElement()));
052        tgt.setCategory(src.getCategory().stream()
053                .map(AllergyIntolerance40_50::convertAllergyIntoleranceCategory)
054                .collect(Collectors.toList()));
055        if (src.hasCriticality())
056            tgt.setCriticalityElement(convertAllergyIntoleranceCriticality(src.getCriticalityElement()));
057        if (src.hasCode())
058            tgt.setCode(convertCodeableConcept(src.getCode()));
059        if (src.hasPatient())
060            tgt.setPatient(convertReference(src.getPatient()));
061        if (src.hasEncounter())
062            tgt.setEncounter(convertReference(src.getEncounter()));
063        if (src.hasOnset())
064            tgt.setOnset(convertType(src.getOnset()));
065        if (src.hasRecordedDate())
066            tgt.setRecordedDateElement(convertDateTime(src.getRecordedDateElement()));
067        if (src.hasRecorder())
068            tgt.setRecorder(convertReference(src.getRecorder()));
069        if (src.hasAsserter())
070            tgt.setAsserter(convertReference(src.getAsserter()));
071        if (src.hasLastOccurrence())
072            tgt.setLastOccurrenceElement(convertDateTime(src.getLastOccurrenceElement()));
073        for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(convertAnnotation(t));
074        for (org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent t : src.getReaction()) tgt.addReaction(convertAllergyIntoleranceReactionComponent(t));
075        return tgt;
076    }
077
078    public static org.hl7.fhir.r4.model.AllergyIntolerance convertAllergyIntolerance(org.hl7.fhir.r5.model.AllergyIntolerance src) throws FHIRException {
079        if (src == null)
080            return null;
081        org.hl7.fhir.r4.model.AllergyIntolerance tgt = new org.hl7.fhir.r4.model.AllergyIntolerance();
082        copyDomainResource(src, tgt);
083        for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(convertIdentifier(t));
084        if (src.hasClinicalStatus())
085            tgt.setClinicalStatus(convertCodeableConcept(src.getClinicalStatus()));
086        if (src.hasVerificationStatus())
087            tgt.setVerificationStatus(convertCodeableConcept(src.getVerificationStatus()));
088        if (src.hasType())
089            tgt.setTypeElement(convertAllergyIntoleranceType(src.getTypeElement()));
090        tgt.setCategory(src.getCategory().stream()
091                .map(AllergyIntolerance40_50::convertAllergyIntoleranceCategory)
092                .collect(Collectors.toList()));
093        if (src.hasCriticality())
094            tgt.setCriticalityElement(convertAllergyIntoleranceCriticality(src.getCriticalityElement()));
095        if (src.hasCode())
096            tgt.setCode(convertCodeableConcept(src.getCode()));
097        if (src.hasPatient())
098            tgt.setPatient(convertReference(src.getPatient()));
099        if (src.hasEncounter())
100            tgt.setEncounter(convertReference(src.getEncounter()));
101        if (src.hasOnset())
102            tgt.setOnset(convertType(src.getOnset()));
103        if (src.hasRecordedDate())
104            tgt.setRecordedDateElement(convertDateTime(src.getRecordedDateElement()));
105        if (src.hasRecorder())
106            tgt.setRecorder(convertReference(src.getRecorder()));
107        if (src.hasAsserter())
108            tgt.setAsserter(convertReference(src.getAsserter()));
109        if (src.hasLastOccurrence())
110            tgt.setLastOccurrenceElement(convertDateTime(src.getLastOccurrenceElement()));
111        for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(convertAnnotation(t));
112        for (org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceReactionComponent t : src.getReaction()) tgt.addReaction(convertAllergyIntoleranceReactionComponent(t));
113        return tgt;
114    }
115
116    static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceType> convertAllergyIntoleranceType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType> src) throws FHIRException {
117        if (src == null || src.isEmpty())
118            return null;
119        org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceTypeEnumFactory());
120        VersionConvertor_40_50.copyElement(src, tgt);
121        switch(src.getValue()) {
122            case ALLERGY:
123                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceType.ALLERGY);
124                break;
125            case INTOLERANCE:
126                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceType.INTOLERANCE);
127                break;
128            default:
129                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceType.NULL);
130                break;
131        }
132        return tgt;
133    }
134
135    static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType> convertAllergyIntoleranceType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceType> src) throws FHIRException {
136        if (src == null || src.isEmpty())
137            return null;
138        org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceTypeEnumFactory());
139        VersionConvertor_40_50.copyElement(src, tgt);
140        switch(src.getValue()) {
141            case ALLERGY:
142                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType.ALLERGY);
143                break;
144            case INTOLERANCE:
145                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType.INTOLERANCE);
146                break;
147            default:
148                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType.NULL);
149                break;
150        }
151        return tgt;
152    }
153
154    static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory> convertAllergyIntoleranceCategory(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory> src) throws FHIRException {
155        if (src == null || src.isEmpty())
156            return null;
157        org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategoryEnumFactory());
158        VersionConvertor_40_50.copyElement(src, tgt);
159        switch(src.getValue()) {
160            case FOOD:
161                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory.FOOD);
162                break;
163            case MEDICATION:
164                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory.MEDICATION);
165                break;
166            case ENVIRONMENT:
167                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT);
168                break;
169            case BIOLOGIC:
170                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory.BIOLOGIC);
171                break;
172            default:
173                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory.NULL);
174                break;
175        }
176        return tgt;
177    }
178
179    static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory> convertAllergyIntoleranceCategory(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCategory> src) throws FHIRException {
180        if (src == null || src.isEmpty())
181            return null;
182        org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategoryEnumFactory());
183        VersionConvertor_40_50.copyElement(src, tgt);
184        switch(src.getValue()) {
185            case FOOD:
186                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory.FOOD);
187                break;
188            case MEDICATION:
189                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory.MEDICATION);
190                break;
191            case ENVIRONMENT:
192                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT);
193                break;
194            case BIOLOGIC:
195                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory.BIOLOGIC);
196                break;
197            default:
198                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory.NULL);
199                break;
200        }
201        return tgt;
202    }
203
204    static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality> convertAllergyIntoleranceCriticality(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality> src) throws FHIRException {
205        if (src == null || src.isEmpty())
206            return null;
207        org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticalityEnumFactory());
208        VersionConvertor_40_50.copyElement(src, tgt);
209        switch(src.getValue()) {
210            case LOW:
211                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality.LOW);
212                break;
213            case HIGH:
214                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality.HIGH);
215                break;
216            case UNABLETOASSESS:
217                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality.UNABLETOASSESS);
218                break;
219            default:
220                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality.NULL);
221                break;
222        }
223        return tgt;
224    }
225
226    static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality> convertAllergyIntoleranceCriticality(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceCriticality> src) throws FHIRException {
227        if (src == null || src.isEmpty())
228            return null;
229        org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticalityEnumFactory());
230        VersionConvertor_40_50.copyElement(src, tgt);
231        switch(src.getValue()) {
232            case LOW:
233                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.LOW);
234                break;
235            case HIGH:
236                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.HIGH);
237                break;
238            case UNABLETOASSESS:
239                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.UNABLETOASSESS);
240                break;
241            default:
242                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.NULL);
243                break;
244        }
245        return tgt;
246    }
247
248    public static org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceReactionComponent convertAllergyIntoleranceReactionComponent(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent src) throws FHIRException {
249        if (src == null)
250            return null;
251        org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceReactionComponent tgt = new org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceReactionComponent();
252        copyElement(src, tgt);
253        if (src.hasSubstance())
254            tgt.setSubstance(convertCodeableConcept(src.getSubstance()));
255        for (org.hl7.fhir.r4.model.CodeableConcept t : src.getManifestation()) tgt.addManifestation(convertCodeableConcept(t));
256        if (src.hasDescription())
257            tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
258        if (src.hasOnset())
259            tgt.setOnsetElement(convertDateTime(src.getOnsetElement()));
260        if (src.hasSeverity())
261            tgt.setSeverityElement(convertAllergyIntoleranceSeverity(src.getSeverityElement()));
262        if (src.hasExposureRoute())
263            tgt.setExposureRoute(convertCodeableConcept(src.getExposureRoute()));
264        for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(convertAnnotation(t));
265        return tgt;
266    }
267
268    public static org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent convertAllergyIntoleranceReactionComponent(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceReactionComponent src) throws FHIRException {
269        if (src == null)
270            return null;
271        org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent tgt = new org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent();
272        copyElement(src, tgt);
273        if (src.hasSubstance())
274            tgt.setSubstance(convertCodeableConcept(src.getSubstance()));
275        for (org.hl7.fhir.r5.model.CodeableConcept t : src.getManifestation()) tgt.addManifestation(convertCodeableConcept(t));
276        if (src.hasDescription())
277            tgt.setDescriptionElement(convertString(src.getDescriptionElement()));
278        if (src.hasOnset())
279            tgt.setOnsetElement(convertDateTime(src.getOnsetElement()));
280        if (src.hasSeverity())
281            tgt.setSeverityElement(convertAllergyIntoleranceSeverity(src.getSeverityElement()));
282        if (src.hasExposureRoute())
283            tgt.setExposureRoute(convertCodeableConcept(src.getExposureRoute()));
284        for (org.hl7.fhir.r5.model.Annotation t : src.getNote()) tgt.addNote(convertAnnotation(t));
285        return tgt;
286    }
287
288    static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity> convertAllergyIntoleranceSeverity(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity> src) throws FHIRException {
289        if (src == null || src.isEmpty())
290            return null;
291        org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverityEnumFactory());
292        VersionConvertor_40_50.copyElement(src, tgt);
293        switch(src.getValue()) {
294            case MILD:
295                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity.MILD);
296                break;
297            case MODERATE:
298                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity.MODERATE);
299                break;
300            case SEVERE:
301                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity.SEVERE);
302                break;
303            default:
304                tgt.setValue(org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity.NULL);
305                break;
306        }
307        return tgt;
308    }
309
310    static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity> convertAllergyIntoleranceSeverity(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.AllergyIntolerance.AllergyIntoleranceSeverity> src) throws FHIRException {
311        if (src == null || src.isEmpty())
312            return null;
313        org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverityEnumFactory());
314        VersionConvertor_40_50.copyElement(src, tgt);
315        switch(src.getValue()) {
316            case MILD:
317                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity.MILD);
318                break;
319            case MODERATE:
320                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity.MODERATE);
321                break;
322            case SEVERE:
323                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity.SEVERE);
324                break;
325            default:
326                tgt.setValue(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity.NULL);
327                break;
328        }
329        return tgt;
330    }
331}