
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.complextypes10_40.ContactPoint10_40; 005import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.Instant10_40; 006import org.hl7.fhir.convertors.conv10_40.datatypes10_40.primitivetypes10_40.String10_40; 007import org.hl7.fhir.dstu2.model.Enumeration; 008import org.hl7.fhir.dstu2.model.Subscription; 009import org.hl7.fhir.exceptions.FHIRException; 010 011public class Subscription10_40 { 012 013 public static org.hl7.fhir.r4.model.Subscription convertSubscription(org.hl7.fhir.dstu2.model.Subscription src) throws FHIRException { 014 if (src == null || src.isEmpty()) 015 return null; 016 org.hl7.fhir.r4.model.Subscription tgt = new org.hl7.fhir.r4.model.Subscription(); 017 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt); 018 if (src.hasCriteriaElement()) 019 tgt.setCriteriaElement(String10_40.convertString(src.getCriteriaElement())); 020 for (org.hl7.fhir.dstu2.model.ContactPoint t : src.getContact()) 021 tgt.addContact(ContactPoint10_40.convertContactPoint(t)); 022 if (src.hasReasonElement()) 023 tgt.setReasonElement(String10_40.convertString(src.getReasonElement())); 024 if (src.hasStatus()) 025 tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement())); 026 if (src.hasErrorElement()) 027 tgt.setErrorElement(String10_40.convertString(src.getErrorElement())); 028 if (src.hasChannel()) 029 tgt.setChannel(convertSubscriptionChannelComponent(src.getChannel())); 030 if (src.hasEndElement()) 031 tgt.setEndElement(Instant10_40.convertInstant(src.getEndElement())); 032 return tgt; 033 } 034 035 public static org.hl7.fhir.dstu2.model.Subscription convertSubscription(org.hl7.fhir.r4.model.Subscription src) throws FHIRException { 036 if (src == null || src.isEmpty()) 037 return null; 038 org.hl7.fhir.dstu2.model.Subscription tgt = new org.hl7.fhir.dstu2.model.Subscription(); 039 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt); 040 if (src.hasCriteriaElement()) 041 tgt.setCriteriaElement(String10_40.convertString(src.getCriteriaElement())); 042 for (org.hl7.fhir.r4.model.ContactPoint t : src.getContact()) 043 tgt.addContact(ContactPoint10_40.convertContactPoint(t)); 044 if (src.hasReasonElement()) 045 tgt.setReasonElement(String10_40.convertString(src.getReasonElement())); 046 if (src.hasStatus()) 047 tgt.setStatusElement(convertSubscriptionStatus(src.getStatusElement())); 048 if (src.hasErrorElement()) 049 tgt.setErrorElement(String10_40.convertString(src.getErrorElement())); 050 if (src.hasChannel()) 051 tgt.setChannel(convertSubscriptionChannelComponent(src.getChannel())); 052 if (src.hasEndElement()) 053 tgt.setEndElement(Instant10_40.convertInstant(src.getEndElement())); 054 return tgt; 055 } 056 057 public static org.hl7.fhir.r4.model.Subscription.SubscriptionChannelComponent convertSubscriptionChannelComponent(org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent src) throws FHIRException { 058 if (src == null || src.isEmpty()) 059 return null; 060 org.hl7.fhir.r4.model.Subscription.SubscriptionChannelComponent tgt = new org.hl7.fhir.r4.model.Subscription.SubscriptionChannelComponent(); 061 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt); 062 if (src.hasType()) 063 tgt.setTypeElement(convertSubscriptionChannelType(src.getTypeElement())); 064 if (src.hasEndpoint()) 065 tgt.setEndpoint(src.getEndpoint()); 066 if (src.hasPayload()) 067 tgt.setPayload(src.getPayload()); 068 tgt.addHeader(src.getHeader()); 069 return tgt; 070 } 071 072 public static org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent convertSubscriptionChannelComponent(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelComponent src) throws FHIRException { 073 if (src == null || src.isEmpty()) 074 return null; 075 org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent tgt = new org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelComponent(); 076 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyBackboneElement(src,tgt); 077 if (src.hasType()) 078 tgt.setTypeElement(convertSubscriptionChannelType(src.getTypeElement())); 079 if (src.hasEndpoint()) 080 tgt.setEndpoint(src.getEndpoint()); 081 if (src.hasPayload()) 082 tgt.setPayload(src.getPayload()); 083 if (src.hasHeader()) 084 tgt.setHeaderElement(String10_40.convertString(src.getHeader().get(0))); 085 return tgt; 086 } 087 088 static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType> convertSubscriptionChannelType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType> src) throws FHIRException { 089 if (src == null || src.isEmpty()) 090 return null; 091 Enumeration<Subscription.SubscriptionChannelType> tgt = new Enumeration<>(new Subscription.SubscriptionChannelTypeEnumFactory()); 092 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 093 if (src.getValue() == null) { 094 tgt.setValue(null); 095 } else { 096 switch (src.getValue()) { 097 case RESTHOOK: 098 tgt.setValue(Subscription.SubscriptionChannelType.RESTHOOK); 099 break; 100 case WEBSOCKET: 101 tgt.setValue(Subscription.SubscriptionChannelType.WEBSOCKET); 102 break; 103 case EMAIL: 104 tgt.setValue(Subscription.SubscriptionChannelType.EMAIL); 105 break; 106 case SMS: 107 tgt.setValue(Subscription.SubscriptionChannelType.SMS); 108 break; 109 case MESSAGE: 110 tgt.setValue(Subscription.SubscriptionChannelType.MESSAGE); 111 break; 112 default: 113 tgt.setValue(Subscription.SubscriptionChannelType.NULL); 114 break; 115 } 116 } 117 return tgt; 118 } 119 120 static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType> convertSubscriptionChannelType(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionChannelType> src) throws FHIRException { 121 if (src == null || src.isEmpty()) 122 return null; 123 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Subscription.SubscriptionChannelTypeEnumFactory()); 124 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 125 if (src.getValue() == null) { 126 tgt.setValue(null); 127 } else { 128 switch (src.getValue()) { 129 case RESTHOOK: 130 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.RESTHOOK); 131 break; 132 case WEBSOCKET: 133 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.WEBSOCKET); 134 break; 135 case EMAIL: 136 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.EMAIL); 137 break; 138 case SMS: 139 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.SMS); 140 break; 141 case MESSAGE: 142 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.MESSAGE); 143 break; 144 default: 145 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType.NULL); 146 break; 147 } 148 } 149 return tgt; 150 } 151 152 static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Subscription.SubscriptionStatus> convertSubscriptionStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus> src) throws FHIRException { 153 if (src == null || src.isEmpty()) 154 return null; 155 org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Subscription.SubscriptionStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Subscription.SubscriptionStatusEnumFactory()); 156 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 157 if (src.getValue() == null) { 158 tgt.setValue(null); 159 } else { 160 switch (src.getValue()) { 161 case REQUESTED: 162 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.REQUESTED); 163 break; 164 case ACTIVE: 165 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.ACTIVE); 166 break; 167 case ERROR: 168 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.ERROR); 169 break; 170 case OFF: 171 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.OFF); 172 break; 173 default: 174 tgt.setValue(org.hl7.fhir.r4.model.Subscription.SubscriptionStatus.NULL); 175 break; 176 } 177 } 178 return tgt; 179 } 180 181 static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Subscription.SubscriptionStatus> convertSubscriptionStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Subscription.SubscriptionStatus> src) throws FHIRException { 182 if (src == null || src.isEmpty()) 183 return null; 184 Enumeration<Subscription.SubscriptionStatus> tgt = new Enumeration<>(new Subscription.SubscriptionStatusEnumFactory()); 185 ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); 186 if (src.getValue() == null) { 187 tgt.setValue(null); 188 } else { 189 switch (src.getValue()) { 190 case REQUESTED: 191 tgt.setValue(Subscription.SubscriptionStatus.REQUESTED); 192 break; 193 case ACTIVE: 194 tgt.setValue(Subscription.SubscriptionStatus.ACTIVE); 195 break; 196 case ERROR: 197 tgt.setValue(Subscription.SubscriptionStatus.ERROR); 198 break; 199 case OFF: 200 tgt.setValue(Subscription.SubscriptionStatus.OFF); 201 break; 202 default: 203 tgt.setValue(Subscription.SubscriptionStatus.NULL); 204 break; 205 } 206 } 207 return tgt; 208 } 209}