001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.convertors.VersionConvertorConstants;
004import org.hl7.fhir.convertors.context.ConversionContext30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Address30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Attachment30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
009import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.ContactPoint30_40;
010import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.HumanName30_40;
011import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
012import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Period30_40;
013import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Boolean30_40;
014import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Date30_40;
015import org.hl7.fhir.dstu3.model.Enumeration;
016import org.hl7.fhir.dstu3.model.Patient;
017import org.hl7.fhir.exceptions.FHIRException;
018
019public class Patient30_40 {
020
021  public static org.hl7.fhir.dstu3.model.Patient.AnimalComponent convertAnimalComponent(org.hl7.fhir.r4.model.Extension src) throws FHIRException {
022    if (src == null || src.isEmpty())
023      return null;
024    org.hl7.fhir.dstu3.model.Patient.AnimalComponent tgt = new org.hl7.fhir.dstu3.model.Patient.AnimalComponent();
025    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
026    if (src.hasExtension("species"))
027      tgt.setSpecies(CodeableConcept30_40.convertCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) src.getExtensionByUrl("species").getValue()));
028    if (src.hasExtension("breed"))
029      tgt.setBreed(CodeableConcept30_40.convertCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) src.getExtensionByUrl("breed").getValue()));
030    if (src.hasExtension("genderStatus"))
031      tgt.setGenderStatus(CodeableConcept30_40.convertCodeableConcept((org.hl7.fhir.r4.model.CodeableConcept) src.getExtensionByUrl("genderStatus").getValue()));
032    return tgt;
033  }
034
035  public static org.hl7.fhir.r4.model.Extension convertAnimalComponent(org.hl7.fhir.dstu3.model.Patient.AnimalComponent src) throws FHIRException {
036    if (src == null)
037      return null;
038    org.hl7.fhir.r4.model.Extension tgt = new org.hl7.fhir.r4.model.Extension();
039    tgt.setUrl(VersionConvertorConstants.EXT_PAT_ANIMAL);
040    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
041    if (src.hasSpecies())
042      tgt.addExtension("species", CodeableConcept30_40.convertCodeableConcept(src.getSpecies()));
043    if (src.hasBreed())
044      tgt.addExtension("breed", CodeableConcept30_40.convertCodeableConcept(src.getBreed()));
045    if (src.hasGenderStatus())
046      tgt.addExtension("genderStatus", CodeableConcept30_40.convertCodeableConcept(src.getGenderStatus()));
047    return tgt;
048  }
049
050  public static org.hl7.fhir.r4.model.Patient.ContactComponent convertContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent src) throws FHIRException {
051    if (src == null)
052      return null;
053    org.hl7.fhir.r4.model.Patient.ContactComponent tgt = new org.hl7.fhir.r4.model.Patient.ContactComponent();
054    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
055    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getRelationship())
056      tgt.addRelationship(CodeableConcept30_40.convertCodeableConcept(t));
057    if (src.hasName())
058      tgt.setName(HumanName30_40.convertHumanName(src.getName()));
059    for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom())
060      tgt.addTelecom(ContactPoint30_40.convertContactPoint(t));
061    if (src.hasAddress())
062      tgt.setAddress(Address30_40.convertAddress(src.getAddress()));
063    if (src.hasGender())
064      tgt.setGenderElement(Enumerations30_40.convertAdministrativeGender(src.getGenderElement()));
065    if (src.hasOrganization())
066      tgt.setOrganization(Reference30_40.convertReference(src.getOrganization()));
067    if (src.hasPeriod())
068      tgt.setPeriod(Period30_40.convertPeriod(src.getPeriod()));
069    return tgt;
070  }
071
072  public static org.hl7.fhir.dstu3.model.Patient.ContactComponent convertContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent src) throws FHIRException {
073    if (src == null)
074      return null;
075    org.hl7.fhir.dstu3.model.Patient.ContactComponent tgt = new org.hl7.fhir.dstu3.model.Patient.ContactComponent();
076    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
077    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getRelationship())
078      tgt.addRelationship(CodeableConcept30_40.convertCodeableConcept(t));
079    if (src.hasName())
080      tgt.setName(HumanName30_40.convertHumanName(src.getName()));
081    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
082      tgt.addTelecom(ContactPoint30_40.convertContactPoint(t));
083    if (src.hasAddress())
084      tgt.setAddress(Address30_40.convertAddress(src.getAddress()));
085    if (src.hasGender())
086      tgt.setGenderElement(Enumerations30_40.convertAdministrativeGender(src.getGenderElement()));
087    if (src.hasOrganization())
088      tgt.setOrganization(Reference30_40.convertReference(src.getOrganization()));
089    if (src.hasPeriod())
090      tgt.setPeriod(Period30_40.convertPeriod(src.getPeriod()));
091    return tgt;
092  }
093
094  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Patient.LinkType> convertLinkType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Patient.LinkType> src) throws FHIRException {
095      if (src == null || src.isEmpty())
096          return null;
097      Enumeration<Patient.LinkType> tgt = new Enumeration<>(new Patient.LinkTypeEnumFactory());
098      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
099      if (src.getValue() == null) {
100          tgt.setValue(null);
101      } else {
102          switch (src.getValue()) {
103              case REPLACEDBY:
104                  tgt.setValue(Patient.LinkType.REPLACEDBY);
105                  break;
106              case REPLACES:
107                  tgt.setValue(Patient.LinkType.REPLACES);
108                  break;
109              case REFER:
110                  tgt.setValue(Patient.LinkType.REFER);
111                  break;
112              case SEEALSO:
113                  tgt.setValue(Patient.LinkType.SEEALSO);
114                  break;
115              default:
116                  tgt.setValue(Patient.LinkType.NULL);
117                  break;
118          }
119      }
120      return tgt;
121  }
122
123  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Patient.LinkType> convertLinkType(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Patient.LinkType> src) throws FHIRException {
124      if (src == null || src.isEmpty())
125          return null;
126      org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Patient.LinkType> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Patient.LinkTypeEnumFactory());
127      ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
128      if (src.getValue() == null) {
129          tgt.setValue(null);
130      } else {
131          switch (src.getValue()) {
132              case REPLACEDBY:
133                  tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.REPLACEDBY);
134                  break;
135              case REPLACES:
136                  tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.REPLACES);
137                  break;
138              case REFER:
139                  tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.REFER);
140                  break;
141              case SEEALSO:
142                  tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.SEEALSO);
143                  break;
144              default:
145                  tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.NULL);
146                  break;
147          }
148      }
149      return tgt;
150  }
151
152  public static org.hl7.fhir.dstu3.model.Patient convertPatient(org.hl7.fhir.r4.model.Patient src) throws FHIRException {
153    if (src == null)
154      return null;
155    org.hl7.fhir.dstu3.model.Patient tgt = new org.hl7.fhir.dstu3.model.Patient();
156    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
157    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
158      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
159    if (src.hasActive())
160      tgt.setActiveElement(Boolean30_40.convertBoolean(src.getActiveElement()));
161    for (org.hl7.fhir.r4.model.HumanName t : src.getName()) tgt.addName(HumanName30_40.convertHumanName(t));
162    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
163      tgt.addTelecom(ContactPoint30_40.convertContactPoint(t));
164    if (src.hasGender())
165      tgt.setGenderElement(Enumerations30_40.convertAdministrativeGender(src.getGenderElement()));
166    if (src.hasBirthDate())
167      tgt.setBirthDateElement(Date30_40.convertDate(src.getBirthDateElement()));
168    if (src.hasDeceased())
169      tgt.setDeceased(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getDeceased()));
170    for (org.hl7.fhir.r4.model.Address t : src.getAddress()) tgt.addAddress(Address30_40.convertAddress(t));
171    if (src.hasMaritalStatus())
172      tgt.setMaritalStatus(CodeableConcept30_40.convertCodeableConcept(src.getMaritalStatus()));
173    if (src.hasMultipleBirth())
174      tgt.setMultipleBirth(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getMultipleBirth()));
175    for (org.hl7.fhir.r4.model.Attachment t : src.getPhoto()) tgt.addPhoto(Attachment30_40.convertAttachment(t));
176    for (org.hl7.fhir.r4.model.Patient.ContactComponent t : src.getContact())
177      tgt.addContact(convertContactComponent(t));
178    if (src.hasExtension(VersionConvertorConstants.EXT_PAT_ANIMAL))
179      tgt.setAnimal(convertAnimalComponent(src.getExtensionByUrl(VersionConvertorConstants.EXT_PAT_ANIMAL)));
180    for (org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent t : src.getCommunication())
181      tgt.addCommunication(convertPatientCommunicationComponent(t));
182    for (org.hl7.fhir.r4.model.Reference t : src.getGeneralPractitioner())
183      tgt.addGeneralPractitioner(Reference30_40.convertReference(t));
184    if (src.hasManagingOrganization())
185      tgt.setManagingOrganization(Reference30_40.convertReference(src.getManagingOrganization()));
186    for (org.hl7.fhir.r4.model.Patient.PatientLinkComponent t : src.getLink())
187      tgt.addLink(convertPatientLinkComponent(t));
188    return tgt;
189  }
190
191  public static org.hl7.fhir.r4.model.Patient convertPatient(org.hl7.fhir.dstu3.model.Patient src) throws FHIRException {
192    if (src == null)
193      return null;
194    org.hl7.fhir.r4.model.Patient tgt = new org.hl7.fhir.r4.model.Patient();
195    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
196    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
197      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
198    if (src.hasActive())
199      tgt.setActiveElement(Boolean30_40.convertBoolean(src.getActiveElement()));
200    for (org.hl7.fhir.dstu3.model.HumanName t : src.getName()) tgt.addName(HumanName30_40.convertHumanName(t));
201    for (org.hl7.fhir.dstu3.model.ContactPoint t : src.getTelecom())
202      tgt.addTelecom(ContactPoint30_40.convertContactPoint(t));
203    if (src.hasGender())
204      tgt.setGenderElement(Enumerations30_40.convertAdministrativeGender(src.getGenderElement()));
205    if (src.hasBirthDate())
206      tgt.setBirthDateElement(Date30_40.convertDate(src.getBirthDateElement()));
207    if (src.hasDeceased())
208      tgt.setDeceased(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getDeceased()));
209    for (org.hl7.fhir.dstu3.model.Address t : src.getAddress()) tgt.addAddress(Address30_40.convertAddress(t));
210    if (src.hasMaritalStatus())
211      tgt.setMaritalStatus(CodeableConcept30_40.convertCodeableConcept(src.getMaritalStatus()));
212    if (src.hasMultipleBirth())
213      tgt.setMultipleBirth(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getMultipleBirth()));
214    for (org.hl7.fhir.dstu3.model.Attachment t : src.getPhoto()) tgt.addPhoto(Attachment30_40.convertAttachment(t));
215    for (org.hl7.fhir.dstu3.model.Patient.ContactComponent t : src.getContact())
216      tgt.addContact(convertContactComponent(t));
217    if (src.hasAnimal())
218      tgt.addExtension(convertAnimalComponent(src.getAnimal()));
219    for (org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent t : src.getCommunication())
220      tgt.addCommunication(convertPatientCommunicationComponent(t));
221    for (org.hl7.fhir.dstu3.model.Reference t : src.getGeneralPractitioner())
222      tgt.addGeneralPractitioner(Reference30_40.convertReference(t));
223    if (src.hasManagingOrganization())
224      tgt.setManagingOrganization(Reference30_40.convertReference(src.getManagingOrganization()));
225    for (org.hl7.fhir.dstu3.model.Patient.PatientLinkComponent t : src.getLink())
226      tgt.addLink(convertPatientLinkComponent(t));
227    return tgt;
228  }
229
230  public static org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent convertPatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent src) throws FHIRException {
231    if (src == null)
232      return null;
233    org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent tgt = new org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent();
234    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
235    if (src.hasLanguage())
236      tgt.setLanguage(CodeableConcept30_40.convertCodeableConcept(src.getLanguage()));
237    if (src.hasPreferred())
238      tgt.setPreferredElement(Boolean30_40.convertBoolean(src.getPreferredElement()));
239    return tgt;
240  }
241
242  public static org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent convertPatientCommunicationComponent(org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent src) throws FHIRException {
243    if (src == null)
244      return null;
245    org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent tgt = new org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent();
246    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
247    if (src.hasLanguage())
248      tgt.setLanguage(CodeableConcept30_40.convertCodeableConcept(src.getLanguage()));
249    if (src.hasPreferred())
250      tgt.setPreferredElement(Boolean30_40.convertBoolean(src.getPreferredElement()));
251    return tgt;
252  }
253
254  public static org.hl7.fhir.dstu3.model.Patient.PatientLinkComponent convertPatientLinkComponent(org.hl7.fhir.r4.model.Patient.PatientLinkComponent src) throws FHIRException {
255    if (src == null)
256      return null;
257    org.hl7.fhir.dstu3.model.Patient.PatientLinkComponent tgt = new org.hl7.fhir.dstu3.model.Patient.PatientLinkComponent();
258    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
259    if (src.hasOther())
260      tgt.setOther(Reference30_40.convertReference(src.getOther()));
261    if (src.hasType())
262      tgt.setTypeElement(convertLinkType(src.getTypeElement()));
263    return tgt;
264  }
265
266  public static org.hl7.fhir.r4.model.Patient.PatientLinkComponent convertPatientLinkComponent(org.hl7.fhir.dstu3.model.Patient.PatientLinkComponent src) throws FHIRException {
267    if (src == null)
268      return null;
269    org.hl7.fhir.r4.model.Patient.PatientLinkComponent tgt = new org.hl7.fhir.r4.model.Patient.PatientLinkComponent();
270    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
271    if (src.hasOther())
272      tgt.setOther(Reference30_40.convertReference(src.getOther()));
273    if (src.hasType())
274      tgt.setTypeElement(convertLinkType(src.getTypeElement()));
275    return tgt;
276  }
277}