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