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