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 Person40_50 {
040
041  public static org.hl7.fhir.r5.model.Person convertPerson(org.hl7.fhir.r4.model.Person src) throws FHIRException {
042    if (src == null)
043      return null;
044    org.hl7.fhir.r5.model.Person tgt = new org.hl7.fhir.r5.model.Person();
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    for (org.hl7.fhir.r4.model.HumanName t : src.getName()) tgt.addName(HumanName40_50.convertHumanName(t));
049    for (org.hl7.fhir.r4.model.ContactPoint t : src.getTelecom())
050      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
051    if (src.hasGender())
052      tgt.setGenderElement(Enumerations40_50.convertAdministrativeGender(src.getGenderElement()));
053    if (src.hasBirthDate())
054      tgt.setBirthDateElement(Date40_50.convertDate(src.getBirthDateElement()));
055    for (org.hl7.fhir.r4.model.Address t : src.getAddress()) tgt.addAddress(Address40_50.convertAddress(t));
056    if (src.hasPhoto())
057      tgt.addPhoto(Attachment40_50.convertAttachment(src.getPhoto()));
058    if (src.hasManagingOrganization())
059      tgt.setManagingOrganization(Reference40_50.convertReference(src.getManagingOrganization()));
060    if (src.hasActive())
061      tgt.setActiveElement(Boolean40_50.convertBoolean(src.getActiveElement()));
062    for (org.hl7.fhir.r4.model.Person.PersonLinkComponent t : src.getLink()) tgt.addLink(convertPersonLinkComponent(t));
063    return tgt;
064  }
065
066  public static org.hl7.fhir.r4.model.Person convertPerson(org.hl7.fhir.r5.model.Person src) throws FHIRException {
067    if (src == null)
068      return null;
069    org.hl7.fhir.r4.model.Person tgt = new org.hl7.fhir.r4.model.Person();
070    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt);
071    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
072      tgt.addIdentifier(Identifier40_50.convertIdentifier(t));
073    for (org.hl7.fhir.r5.model.HumanName t : src.getName()) tgt.addName(HumanName40_50.convertHumanName(t));
074    for (org.hl7.fhir.r5.model.ContactPoint t : src.getTelecom())
075      tgt.addTelecom(ContactPoint40_50.convertContactPoint(t));
076    if (src.hasGender())
077      tgt.setGenderElement(Enumerations40_50.convertAdministrativeGender(src.getGenderElement()));
078    if (src.hasBirthDate())
079      tgt.setBirthDateElement(Date40_50.convertDate(src.getBirthDateElement()));
080    for (org.hl7.fhir.r5.model.Address t : src.getAddress()) tgt.addAddress(Address40_50.convertAddress(t));
081    if (src.hasPhoto())
082      tgt.setPhoto(Attachment40_50.convertAttachment(src.getPhotoFirstRep()));
083    if (src.hasManagingOrganization())
084      tgt.setManagingOrganization(Reference40_50.convertReference(src.getManagingOrganization()));
085    if (src.hasActive())
086      tgt.setActiveElement(Boolean40_50.convertBoolean(src.getActiveElement()));
087    for (org.hl7.fhir.r5.model.Person.PersonLinkComponent t : src.getLink()) tgt.addLink(convertPersonLinkComponent(t));
088    return tgt;
089  }
090
091  public static org.hl7.fhir.r5.model.Person.PersonLinkComponent convertPersonLinkComponent(org.hl7.fhir.r4.model.Person.PersonLinkComponent src) throws FHIRException {
092    if (src == null)
093      return null;
094    org.hl7.fhir.r5.model.Person.PersonLinkComponent tgt = new org.hl7.fhir.r5.model.Person.PersonLinkComponent();
095    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
096    if (src.hasTarget())
097      tgt.setTarget(Reference40_50.convertReference(src.getTarget()));
098    if (src.hasAssurance())
099      tgt.setAssuranceElement(convertIdentityAssuranceLevel(src.getAssuranceElement()));
100    return tgt;
101  }
102
103  public static org.hl7.fhir.r4.model.Person.PersonLinkComponent convertPersonLinkComponent(org.hl7.fhir.r5.model.Person.PersonLinkComponent src) throws FHIRException {
104    if (src == null)
105      return null;
106    org.hl7.fhir.r4.model.Person.PersonLinkComponent tgt = new org.hl7.fhir.r4.model.Person.PersonLinkComponent();
107    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
108    if (src.hasTarget())
109      tgt.setTarget(Reference40_50.convertReference(src.getTarget()));
110    if (src.hasAssurance())
111      tgt.setAssuranceElement(convertIdentityAssuranceLevel(src.getAssuranceElement()));
112    return tgt;
113  }
114
115  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel> convertIdentityAssuranceLevel(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel> src) throws FHIRException {
116    if (src == null || src.isEmpty())
117      return null;
118    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Person.IdentityAssuranceLevelEnumFactory());
119    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
120    switch (src.getValue()) {
121      case LEVEL1:
122        tgt.setValue(org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel.LEVEL1);
123        break;
124      case LEVEL2:
125        tgt.setValue(org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel.LEVEL2);
126        break;
127      case LEVEL3:
128        tgt.setValue(org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel.LEVEL3);
129        break;
130      case LEVEL4:
131        tgt.setValue(org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel.LEVEL4);
132        break;
133      default:
134        tgt.setValue(org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel.NULL);
135        break;
136    }
137    return tgt;
138  }
139
140  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel> convertIdentityAssuranceLevel(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Person.IdentityAssuranceLevel> src) throws FHIRException {
141    if (src == null || src.isEmpty())
142      return null;
143    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Person.IdentityAssuranceLevelEnumFactory());
144    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
145    switch (src.getValue()) {
146      case LEVEL1:
147        tgt.setValue(org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel.LEVEL1);
148        break;
149      case LEVEL2:
150        tgt.setValue(org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel.LEVEL2);
151        break;
152      case LEVEL3:
153        tgt.setValue(org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel.LEVEL3);
154        break;
155      case LEVEL4:
156        tgt.setValue(org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel.LEVEL4);
157        break;
158      default:
159        tgt.setValue(org.hl7.fhir.r4.model.Person.IdentityAssuranceLevel.NULL);
160        break;
161    }
162    return tgt;
163  }
164}