001package org.hl7.fhir.convertors.conv40_50.resources40_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext40_50;
004import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.*;
005import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40_50;
006import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Date40_50;
007import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
008import org.hl7.fhir.exceptions.FHIRException;
009
010/*
011  Copyright (c) 2011+, HL7, Inc.
012  All rights reserved.
013  
014  Redistribution and use in source and binary forms, with or without modification, 
015  are permitted provided that the following conditions are met:
016  
017   * Redistributions of source code must retain the above copyright notice, this 
018     list of conditions and the following disclaimer.
019   * Redistributions in binary form must reproduce the above copyright notice, 
020     this list of conditions and the following disclaimer in the documentation 
021     and/or other materials provided with the distribution.
022   * Neither the name of HL7 nor the names of its contributors may be used to 
023     endorse or promote products derived from this software without specific 
024     prior written permission.
025  
026  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
027  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
028  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
029  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
030  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
031  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
032  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
033  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
034  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
035  POSSIBILITY OF SUCH DAMAGE.
036  
037*/
038// Generated on Sun, Feb 24, 2019 11:37+1100 for FHIR v4.0.0
039public class Patient40_50 {
040
041  public static org.hl7.fhir.r5.model.Patient convertPatient(org.hl7.fhir.r4.model.Patient src) throws FHIRException {
042    if (src == null)
043      return null;
044    org.hl7.fhir.r5.model.Patient tgt = new org.hl7.fhir.r5.model.Patient();
045    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
046    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
047      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
048    if (src.hasActive())
049      tgt.setActiveElement(Boolean40_50.convertBoolean(src.getActiveElement()));
050    for (org.hl7.fhir.r4.model.HumanName t : src.getName()) tgt.addName(HumanName40_50.convertHumanName(t));
051    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
052      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
053    if (src.hasGender())
054      tgt.setGenderElement(Enumerations40_50.convertAdministrativeGender(src.getGenderElement()));
055    if (src.hasBirthDate())
056      tgt.setBirthDateElement(Date40_50.convertDate(src.getBirthDateElement()));
057    if (src.hasDeceased())
058      tgt.setDeceased(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getDeceased()));
059    for (org.hl7.fhir.r4.model.Address t : src.getAddress()) tgt.addAddress(Address40_50.convertAddress(t));
060    if (src.hasMaritalStatus())
061      tgt.setMaritalStatus(CodeableConcept40_50.convertCodeableConcept(src.getMaritalStatus()));
062    if (src.hasMultipleBirth())
063      tgt.setMultipleBirth(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getMultipleBirth()));
064    for (org.hl7.fhir.r4.model.Attachment t : src.getPhoto()) tgt.addPhoto(Attachment40_50.convertAttachment(t));
065    for (org.hl7.fhir.r4.model.Patient.ContactComponent t : src.getContact())
066      tgt.addContact(convertContactComponent(t));
067    for (org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent t : src.getCommunication())
068      tgt.addCommunication(convertPatientCommunicationComponent(t));
069    for (org.hl7.fhir.r4.model.Reference t : src.getGeneralPractitioner())
070      tgt.addGeneralPractitioner(Reference40_50.convertReference(t));
071    if (src.hasManagingOrganization())
072      tgt.setManagingOrganization(Reference40_50.convertReference(src.getManagingOrganization()));
073    for (org.hl7.fhir.r4.model.Patient.PatientLinkComponent t : src.getLink())
074      tgt.addLink(convertPatientLinkComponent(t));
075    return tgt;
076  }
077
078  public static org.hl7.fhir.r4.model.Patient convertPatient(org.hl7.fhir.r5.model.Patient src) throws FHIRException {
079    if (src == null)
080      return null;
081    org.hl7.fhir.r4.model.Patient tgt = new org.hl7.fhir.r4.model.Patient();
082    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
083    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
084      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
085    if (src.hasActive())
086      tgt.setActiveElement(Boolean40_50.convertBoolean(src.getActiveElement()));
087    for (org.hl7.fhir.r5.model.HumanName t : src.getName()) tgt.addName(HumanName40_50.convertHumanName(t));
088    for (org.hl7.fhir.r5.model.ContactPoint t : src.getTelecom())
089      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
090    if (src.hasGender())
091      tgt.setGenderElement(Enumerations40_50.convertAdministrativeGender(src.getGenderElement()));
092    if (src.hasBirthDate())
093      tgt.setBirthDateElement(Date40_50.convertDate(src.getBirthDateElement()));
094    if (src.hasDeceased())
095      tgt.setDeceased(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getDeceased()));
096    for (org.hl7.fhir.r5.model.Address t : src.getAddress()) tgt.addAddress(Address40_50.convertAddress(t));
097    if (src.hasMaritalStatus())
098      tgt.setMaritalStatus(CodeableConcept40_50.convertCodeableConcept(src.getMaritalStatus()));
099    if (src.hasMultipleBirth())
100      tgt.setMultipleBirth(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getMultipleBirth()));
101    for (org.hl7.fhir.r5.model.Attachment t : src.getPhoto()) tgt.addPhoto(Attachment40_50.convertAttachment(t));
102    for (org.hl7.fhir.r5.model.Patient.ContactComponent t : src.getContact())
103      tgt.addContact(convertContactComponent(t));
104    for (org.hl7.fhir.r5.model.Patient.PatientCommunicationComponent t : src.getCommunication())
105      tgt.addCommunication(convertPatientCommunicationComponent(t));
106    for (org.hl7.fhir.r5.model.Reference t : src.getGeneralPractitioner())
107      tgt.addGeneralPractitioner(Reference40_50.convertReference(t));
108    if (src.hasManagingOrganization())
109      tgt.setManagingOrganization(Reference40_50.convertReference(src.getManagingOrganization()));
110    for (org.hl7.fhir.r5.model.Patient.PatientLinkComponent t : src.getLink())
111      tgt.addLink(convertPatientLinkComponent(t));
112    return tgt;
113  }
114
115  public static org.hl7.fhir.r5.model.Patient.ContactComponent convertContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent src) throws FHIRException {
116    if (src == null)
117      return null;
118    org.hl7.fhir.r5.model.Patient.ContactComponent tgt = new org.hl7.fhir.r5.model.Patient.ContactComponent();
119    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
120    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getRelationship())
121      tgt.addRelationship(CodeableConcept40_50.convertCodeableConcept(t));
122    if (src.hasName())
123      tgt.setName(HumanName40_50.convertHumanName(src.getName()));
124    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
125      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
126    if (src.hasAddress())
127      tgt.setAddress(Address40_50.convertAddress(src.getAddress()));
128    if (src.hasGender())
129      tgt.setGenderElement(Enumerations40_50.convertAdministrativeGender(src.getGenderElement()));
130    if (src.hasOrganization())
131      tgt.setOrganization(Reference40_50.convertReference(src.getOrganization()));
132    if (src.hasPeriod())
133      tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod()));
134    return tgt;
135  }
136
137  public static org.hl7.fhir.r4.model.Patient.ContactComponent convertContactComponent(org.hl7.fhir.r5.model.Patient.ContactComponent src) throws FHIRException {
138    if (src == null)
139      return null;
140    org.hl7.fhir.r4.model.Patient.ContactComponent tgt = new org.hl7.fhir.r4.model.Patient.ContactComponent();
141    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
142    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getRelationship())
143      tgt.addRelationship(CodeableConcept40_50.convertCodeableConcept(t));
144    if (src.hasName())
145      tgt.setName(HumanName40_50.convertHumanName(src.getName()));
146    for (org.hl7.fhir.r5.model.ContactPoint t : src.getTelecom())
147      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
148    if (src.hasAddress())
149      tgt.setAddress(Address40_50.convertAddress(src.getAddress()));
150    if (src.hasGender())
151      tgt.setGenderElement(Enumerations40_50.convertAdministrativeGender(src.getGenderElement()));
152    if (src.hasOrganization())
153      tgt.setOrganization(Reference40_50.convertReference(src.getOrganization()));
154    if (src.hasPeriod())
155      tgt.setPeriod(Period40_50.convertPeriod(src.getPeriod()));
156    return tgt;
157  }
158
159  public static org.hl7.fhir.r5.model.Patient.PatientCommunicationComponent convertPatientCommunicationComponent(org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent src) throws FHIRException {
160    if (src == null)
161      return null;
162    org.hl7.fhir.r5.model.Patient.PatientCommunicationComponent tgt = new org.hl7.fhir.r5.model.Patient.PatientCommunicationComponent();
163    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
164    if (src.hasLanguage())
165      tgt.setLanguage(CodeableConcept40_50.convertCodeableConcept(src.getLanguage()));
166    if (src.hasPreferred())
167      tgt.setPreferredElement(Boolean40_50.convertBoolean(src.getPreferredElement()));
168    return tgt;
169  }
170
171  public static org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent convertPatientCommunicationComponent(org.hl7.fhir.r5.model.Patient.PatientCommunicationComponent src) throws FHIRException {
172    if (src == null)
173      return null;
174    org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent tgt = new org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent();
175    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
176    if (src.hasLanguage())
177      tgt.setLanguage(CodeableConcept40_50.convertCodeableConcept(src.getLanguage()));
178    if (src.hasPreferred())
179      tgt.setPreferredElement(Boolean40_50.convertBoolean(src.getPreferredElement()));
180    return tgt;
181  }
182
183  public static org.hl7.fhir.r5.model.Patient.PatientLinkComponent convertPatientLinkComponent(org.hl7.fhir.r4.model.Patient.PatientLinkComponent src) throws FHIRException {
184    if (src == null)
185      return null;
186    org.hl7.fhir.r5.model.Patient.PatientLinkComponent tgt = new org.hl7.fhir.r5.model.Patient.PatientLinkComponent();
187    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
188    if (src.hasOther())
189      tgt.setOther(Reference40_50.convertReference(src.getOther()));
190    if (src.hasType())
191      tgt.setTypeElement(convertLinkType(src.getTypeElement()));
192    return tgt;
193  }
194
195  public static org.hl7.fhir.r4.model.Patient.PatientLinkComponent convertPatientLinkComponent(org.hl7.fhir.r5.model.Patient.PatientLinkComponent src) throws FHIRException {
196    if (src == null)
197      return null;
198    org.hl7.fhir.r4.model.Patient.PatientLinkComponent tgt = new org.hl7.fhir.r4.model.Patient.PatientLinkComponent();
199    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
200    if (src.hasOther())
201      tgt.setOther(Reference40_50.convertReference(src.getOther()));
202    if (src.hasType())
203      tgt.setTypeElement(convertLinkType(src.getTypeElement()));
204    return tgt;
205  }
206
207  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Patient.LinkType> convertLinkType(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Patient.LinkType> src) throws FHIRException {
208    if (src == null || src.isEmpty())
209      return null;
210    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Patient.LinkType> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Patient.LinkTypeEnumFactory());
211    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
212    switch (src.getValue()) {
213      case REPLACEDBY:
214        tgt.setValue(org.hl7.fhir.r5.model.Patient.LinkType.REPLACEDBY);
215        break;
216      case REPLACES:
217        tgt.setValue(org.hl7.fhir.r5.model.Patient.LinkType.REPLACES);
218        break;
219      case REFER:
220        tgt.setValue(org.hl7.fhir.r5.model.Patient.LinkType.REFER);
221        break;
222      case SEEALSO:
223        tgt.setValue(org.hl7.fhir.r5.model.Patient.LinkType.SEEALSO);
224        break;
225      default:
226        tgt.setValue(org.hl7.fhir.r5.model.Patient.LinkType.NULL);
227        break;
228    }
229    return tgt;
230  }
231
232  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Patient.LinkType> convertLinkType(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Patient.LinkType> src) throws FHIRException {
233    if (src == null || src.isEmpty())
234      return null;
235    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());
236    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
237    switch (src.getValue()) {
238      case REPLACEDBY:
239        tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.REPLACEDBY);
240        break;
241      case REPLACES:
242        tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.REPLACES);
243        break;
244      case REFER:
245        tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.REFER);
246        break;
247      case SEEALSO:
248        tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.SEEALSO);
249        break;
250      default:
251        tgt.setValue(org.hl7.fhir.r4.model.Patient.LinkType.NULL);
252        break;
253    }
254    return tgt;
255  }
256}