001package org.hl7.fhir.convertors.conv10_50.resources10_50;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_50;
004import org.hl7.fhir.convertors.conv10_50.datatypes10_50.Reference10_50;
005import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50;
006import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Identifier10_50;
007import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50;
008import org.hl7.fhir.exceptions.FHIRException;
009import org.hl7.fhir.r5.model.CodeableReference;
010
011public class Communication10_50 {
012
013  public static org.hl7.fhir.r5.model.Communication convertCommunication(org.hl7.fhir.dstu2.model.Communication src) throws FHIRException {
014    if (src == null || src.isEmpty())
015      return null;
016    org.hl7.fhir.r5.model.Communication tgt = new org.hl7.fhir.r5.model.Communication();
017    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
018    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
019      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
020    if (src.hasCategory())
021      tgt.addCategory(CodeableConcept10_50.convertCodeableConcept(src.getCategory()));
022    if (src.hasSender())
023      tgt.setSender(Reference10_50.convertReference(src.getSender()));
024    for (org.hl7.fhir.dstu2.model.Reference t : src.getRecipient())
025      tgt.addRecipient(Reference10_50.convertReference(t));
026    for (org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent t : src.getPayload())
027      tgt.addPayload(convertCommunicationPayloadComponent(t));
028    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getMedium())
029      tgt.addMedium(CodeableConcept10_50.convertCodeableConcept(t));
030    if (src.hasStatus())
031      tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
032    if (src.hasEncounter())
033      tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
034    if (src.hasSentElement())
035      tgt.setSentElement(DateTime10_50.convertDateTime(src.getSentElement()));
036    if (src.hasReceivedElement())
037      tgt.setReceivedElement(DateTime10_50.convertDateTime(src.getReceivedElement()));
038    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReason())
039      tgt.addReason(CodeableConcept10_50.convertCodeableConceptToCodableReference(t));
040    if (src.hasSubject())
041      tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
042    return tgt;
043  }
044
045  public static org.hl7.fhir.dstu2.model.Communication convertCommunication(org.hl7.fhir.r5.model.Communication src) throws FHIRException {
046    if (src == null || src.isEmpty())
047      return null;
048    org.hl7.fhir.dstu2.model.Communication tgt = new org.hl7.fhir.dstu2.model.Communication();
049    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt);
050    for (org.hl7.fhir.r5.model.Identifier t : src.getIdentifier())
051      tgt.addIdentifier(Identifier10_50.convertIdentifier(t));
052    if (src.hasCategory())
053      tgt.setCategory(CodeableConcept10_50.convertCodeableConcept(src.getCategoryFirstRep()));
054    if (src.hasSender())
055      tgt.setSender(Reference10_50.convertReference(src.getSender()));
056    for (org.hl7.fhir.r5.model.Reference t : src.getRecipient()) tgt.addRecipient(Reference10_50.convertReference(t));
057    for (org.hl7.fhir.r5.model.Communication.CommunicationPayloadComponent t : src.getPayload())
058      tgt.addPayload(convertCommunicationPayloadComponent(t));
059    for (org.hl7.fhir.r5.model.CodeableConcept t : src.getMedium())
060      tgt.addMedium(CodeableConcept10_50.convertCodeableConcept(t));
061    if (src.hasStatus())
062      tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
063    if (src.hasEncounter())
064      tgt.setEncounter(Reference10_50.convertReference(src.getEncounter()));
065    if (src.hasSentElement())
066      tgt.setSentElement(DateTime10_50.convertDateTime(src.getSentElement()));
067    if (src.hasReceivedElement())
068      tgt.setReceivedElement(DateTime10_50.convertDateTime(src.getReceivedElement()));
069    for (CodeableReference t : src.getReason())
070      if (t.hasConcept())
071        tgt.addReason(CodeableConcept10_50.convertCodeableConcept(t.getConcept()));
072    if (src.hasSubject())
073      tgt.setSubject(Reference10_50.convertReference(src.getSubject()));
074    return tgt;
075  }
076
077  public static org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent convertCommunicationPayloadComponent(org.hl7.fhir.r5.model.Communication.CommunicationPayloadComponent src) throws FHIRException {
078    if (src == null || src.isEmpty())
079      return null;
080    org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent tgt = new org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent();
081    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
082    if (src.hasContent())
083      tgt.setContent(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getContent()));
084    return tgt;
085  }
086
087  public static org.hl7.fhir.r5.model.Communication.CommunicationPayloadComponent convertCommunicationPayloadComponent(org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent src) throws FHIRException {
088    if (src == null || src.isEmpty())
089      return null;
090    org.hl7.fhir.r5.model.Communication.CommunicationPayloadComponent tgt = new org.hl7.fhir.r5.model.Communication.CommunicationPayloadComponent();
091    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyBackboneElement(src,tgt);
092    if (src.hasContent())
093      tgt.setContent(ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().convertType(src.getContent()));
094    return tgt;
095  }
096
097  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Communication.CommunicationStatus> convertCommunicationStatus(org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.EventStatus> src) throws FHIRException {
098    if (src == null || src.isEmpty())
099      return null;
100    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Communication.CommunicationStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Communication.CommunicationStatusEnumFactory());
101    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
102    switch (src.getValue()) {
103      case INPROGRESS:
104        tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.INPROGRESS);
105        break;
106      case COMPLETED:
107        tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.COMPLETED);
108        break;
109      case ONHOLD:
110        tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.SUSPENDED);
111        break;
112      case ENTEREDINERROR:
113        tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.REJECTED);
114        break;
115      case NOTDONE:
116        tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.FAILED);
117        break;
118      default:
119        tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.NULL);
120        break;
121    }
122    return tgt;
123  }
124
125  static public org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.EventStatus> convertCommunicationStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Communication.CommunicationStatus> src) throws FHIRException {
126    if (src == null || src.isEmpty())
127      return null;
128    org.hl7.fhir.r5.model.Enumeration<org.hl7.fhir.r5.model.Enumerations.EventStatus> tgt = new org.hl7.fhir.r5.model.Enumeration<>(new org.hl7.fhir.r5.model.Enumerations.EventStatusEnumFactory());
129    ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
130    switch (src.getValue()) {
131      case INPROGRESS:
132        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.EventStatus.INPROGRESS);
133        break;
134      case COMPLETED:
135        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.EventStatus.COMPLETED);
136        break;
137      case SUSPENDED:
138        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.EventStatus.ONHOLD);
139        break;
140      case REJECTED:
141        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.EventStatus.ENTEREDINERROR);
142        break;
143      case FAILED:
144        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.EventStatus.NOTDONE);
145        break;
146      default:
147        tgt.setValue(org.hl7.fhir.r5.model.Enumerations.EventStatus.NULL);
148        break;
149    }
150    return tgt;
151  }
152}