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.Extension10_40; 005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Reference10_40; 006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Annotation10_40; 007import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.CodeableConcept10_40; 008import org.hl7.fhir.convertors.conv10_40.datatypes10_40.complextypes10_40.Identifier10_40; 009import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.DateTime10_40; 010import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40; 011import org.hl7.fhir.dstu2.model.AllergyIntolerance; 012import org.hl7.fhir.exceptions.FHIRException; 013 014public class AllergyIntolerance10_40 { 015 public static org.hl7.fhir.r4.model.AllergyIntolerance convertAllergyIntolerance(org.hl7.fhir.dstu2.model.AllergyIntolerance src) throws FHIRException { 016 if (src == null) 017 return null; 018 org.hl7.fhir.r4.model.AllergyIntolerance tgt = new org.hl7.fhir.r4.model.AllergyIntolerance(); 019 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt); 020 for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier()) 021 tgt.addIdentifier(Identifier10_40.convertIdentifier(t)); 022 if (src.hasOnset()) 023 tgt.setOnset(ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getOnsetElement())); 024 if (src.hasRecordedDate()) 025 tgt.setRecordedDateElement(DateTime10_40.convertDateTime(src.getRecordedDateElement())); 026 if (src.hasRecorder()) 027 tgt.setRecorder(Reference10_40.convertReference(src.getRecorder())); 028 if (src.hasPatient()) 029 tgt.setPatient(Reference10_40.convertReference(src.getPatient())); 030 if (src.hasReporter()) 031 tgt.setAsserter(Reference10_40.convertReference(src.getReporter())); 032 if (src.hasSubstance()) 033 tgt.setCode(CodeableConcept10_40.convertCodeableConcept(src.getSubstance())); 034 if (src.hasStatus()) { 035 if (src.getStatus() != org.hl7.fhir.dstu2.model.AllergyIntolerance.AllergyIntoleranceStatus.REFUTED 036 && src.getStatus() != org.hl7.fhir.dstu2.model.AllergyIntolerance.AllergyIntoleranceStatus.ENTEREDINERROR) { 037 org.hl7.fhir.r4.model.Coding code = new org.hl7.fhir.r4.model.Coding(); 038 code.setSystem("http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"); 039 code.setCode(src.getStatus().toCode()); 040 tgt.setClinicalStatus(new org.hl7.fhir.r4.model.CodeableConcept(code)); 041 } 042 if (src.getStatus() != org.hl7.fhir.dstu2.model.AllergyIntolerance.AllergyIntoleranceStatus.ACTIVE 043 && src.getStatus() != org.hl7.fhir.dstu2.model.AllergyIntolerance.AllergyIntoleranceStatus.RESOLVED) { 044 org.hl7.fhir.r4.model.Coding code = new org.hl7.fhir.r4.model.Coding(); 045 code.setSystem("http://terminology.hl7.org/CodeSystem/allergyintolerance-verification"); 046 code.setCode(src.getStatus().toCode()); 047 tgt.setVerificationStatus(new org.hl7.fhir.r4.model.CodeableConcept(code)); 048 } 049 } 050 if (src.hasCriticality()) 051 tgt.setCriticality(translateAllergyIntoleranceCriticality(src.getCriticality())); 052 if (src.hasType()) 053 tgt.setType(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceType.fromCode(src.getType().toCode())); 054 if (src.hasCategory()) 055 tgt.addCategory(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCategory.fromCode(src.getCategory().toCode())); 056 if (src.hasLastOccurenceElement()) 057 tgt.setLastOccurrenceElement(DateTime10_40.convertDateTime(src.getLastOccurenceElement())); 058 if (src.hasNote()) 059 tgt.addNote(Annotation10_40.convertAnnotation(src.getNote())); 060 for (org.hl7.fhir.dstu2.model.AllergyIntolerance.AllergyIntoleranceReactionComponent reaction : src.getReaction()) 061 tgt.addReaction(algReaction(reaction)); 062 return tgt; 063 } 064 065 private static org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent algReaction(AllergyIntolerance.AllergyIntoleranceReactionComponent src) { 066 if (src == null) 067 return null; 068 org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent tgt = new org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceReactionComponent(); 069 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 070 for (org.hl7.fhir.dstu2.model.Extension extension : src.getModifierExtension()) 071 tgt.addExtension(Extension10_40.convertExtension(extension)); 072 if (src.hasSubstance()) 073 tgt.setSubstance(CodeableConcept10_40.convertCodeableConcept(src.getSubstance())); 074 if (src.hasCertainty()) 075 tgt.addExtension(new org.hl7.fhir.r4.model.Extension( 076 "http://hl7.org/fhir/AllergyIntolerance-r2-certainty", 077 new org.hl7.fhir.r4.model.StringType(src.getCertainty().toCode()) 078 )); 079 for (org.hl7.fhir.dstu2.model.CodeableConcept concept : src.getManifestation()) 080 tgt.addManifestation(CodeableConcept10_40.convertCodeableConcept(concept)); 081 if (src.hasDescription()) 082 tgt.setDescriptionElement(String10_40.convertString(src.getDescriptionElement())); 083 if (src.hasOnset()) 084 tgt.setOnsetElement(DateTime10_40.convertDateTime(src.getOnsetElement())); 085 if (src.hasSeverity()) 086 tgt.setSeverity(org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceSeverity.fromCode(src.getSeverity().toCode())); 087 if (src.hasExposureRoute()) 088 tgt.setExposureRoute(CodeableConcept10_40.convertCodeableConcept(src.getExposureRoute())); 089 if (src.hasNote()) 090 tgt.addNote(Annotation10_40.convertAnnotation(src.getNote())); 091 return tgt; 092 } 093 094 public static org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality translateAllergyIntoleranceCriticality(org.hl7.fhir.dstu2.model.AllergyIntolerance.AllergyIntoleranceCriticality src) { 095 switch (src) { 096 case CRITL: 097 return org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.LOW; 098 case CRITH: 099 return org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.HIGH; 100 case CRITU: 101 return org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.UNABLETOASSESS; 102 default: 103 return org.hl7.fhir.r4.model.AllergyIntolerance.AllergyIntoleranceCriticality.NULL; 104 } 105 } 106}