001package org.hl7.fhir.convertors.conv14_40.datatypes14_40.complextypes14_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext14_40;
004import org.hl7.fhir.convertors.conv14_40.datatypes14_40.primitivetypes14_40.String14_40;
005import org.hl7.fhir.exceptions.FHIRException;
006import org.hl7.fhir.r4.model.HumanName;
007
008public class HumanName14_40 {
009  public static org.hl7.fhir.r4.model.HumanName convertHumanName(org.hl7.fhir.dstu2016may.model.HumanName src) throws FHIRException {
010    if (src == null || src.isEmpty()) return null;
011    org.hl7.fhir.r4.model.HumanName tgt = new org.hl7.fhir.r4.model.HumanName();
012    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
013    if (src.hasUse()) tgt.setUseElement(convertNameUse(src.getUseElement()));
014    if (src.hasText()) tgt.setTextElement(String14_40.convertString(src.getTextElement()));
015    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getFamily()) tgt.setFamilyElement(String14_40.convertString(t));
016    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getGiven()) tgt.getGiven().add(String14_40.convertString(t));
017    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getPrefix()) tgt.getPrefix().add(String14_40.convertString(t));
018    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getSuffix()) tgt.getSuffix().add(String14_40.convertString(t));
019    if (src.hasPeriod()) tgt.setPeriod(Period14_40.convertPeriod(src.getPeriod()));
020    return tgt;
021  }
022
023  public static org.hl7.fhir.dstu2016may.model.HumanName convertHumanName(org.hl7.fhir.r4.model.HumanName src) throws FHIRException {
024    if (src == null || src.isEmpty()) return null;
025    org.hl7.fhir.dstu2016may.model.HumanName tgt = new org.hl7.fhir.dstu2016may.model.HumanName();
026    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
027    if (src.hasUse()) tgt.setUseElement(convertNameUse(src.getUseElement()));
028    if (src.hasText()) tgt.setTextElement(String14_40.convertString(src.getTextElement()));
029    if (src.hasFamily()) tgt.getFamily().add(String14_40.convertString(src.getFamilyElement()));
030    for (org.hl7.fhir.r4.model.StringType t : src.getGiven()) tgt.getGiven().add(String14_40.convertString(t));
031    for (org.hl7.fhir.r4.model.StringType t : src.getPrefix()) tgt.getPrefix().add(String14_40.convertString(t));
032    for (org.hl7.fhir.r4.model.StringType t : src.getSuffix()) tgt.getSuffix().add(String14_40.convertString(t));
033    if (src.hasPeriod()) tgt.setPeriod(Period14_40.convertPeriod(src.getPeriod()));
034    return tgt;
035  }
036
037  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.HumanName.NameUse> convertNameUse(org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.HumanName.NameUse> src) throws FHIRException {
038    if (src == null || src.isEmpty()) return null;
039    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.HumanName.NameUse> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.HumanName.NameUseEnumFactory());
040    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
041    if (src.getValue() == null) {
042    tgt.setValue(null);
043} else {
044      switch(src.getValue()) {
045        case USUAL:
046            tgt.setValue(HumanName.NameUse.USUAL);
047            break;
048          case OFFICIAL:
049            tgt.setValue(HumanName.NameUse.OFFICIAL);
050            break;
051          case TEMP:
052            tgt.setValue(HumanName.NameUse.TEMP);
053            break;
054          case NICKNAME:
055            tgt.setValue(HumanName.NameUse.NICKNAME);
056            break;
057          case ANONYMOUS:
058            tgt.setValue(HumanName.NameUse.ANONYMOUS);
059            break;
060          case OLD:
061            tgt.setValue(HumanName.NameUse.OLD);
062            break;
063          case MAIDEN:
064            tgt.setValue(HumanName.NameUse.MAIDEN);
065            break;
066          default:
067            tgt.setValue(HumanName.NameUse.NULL);
068            break;
069       }
070}
071    return tgt;
072  }
073
074  static public org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.HumanName.NameUse> convertNameUse(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.HumanName.NameUse> src) throws FHIRException {
075    if (src == null || src.isEmpty()) return null;
076    org.hl7.fhir.dstu2016may.model.Enumeration<org.hl7.fhir.dstu2016may.model.HumanName.NameUse> tgt = new org.hl7.fhir.dstu2016may.model.Enumeration<>(new org.hl7.fhir.dstu2016may.model.HumanName.NameUseEnumFactory());
077    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
078    if (src.getValue() == null) {
079    tgt.setValue(null);
080} else {
081      switch(src.getValue()) {
082        case USUAL:
083            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.USUAL);
084            break;
085          case OFFICIAL:
086            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.OFFICIAL);
087            break;
088          case TEMP:
089            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.TEMP);
090            break;
091          case NICKNAME:
092            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.NICKNAME);
093            break;
094          case ANONYMOUS:
095            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.ANONYMOUS);
096            break;
097          case OLD:
098            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.OLD);
099            break;
100          case MAIDEN:
101            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.MAIDEN);
102            break;
103          default:
104            tgt.setValue(org.hl7.fhir.dstu2016may.model.HumanName.NameUse.NULL);
105            break;
106       }
107}
108    return tgt;
109  }
110}