001package org.hl7.fhir.convertors.conv30_40.resources30_40;
002
003import org.hl7.fhir.convertors.context.ConversionContext30_40;
004import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Reference30_40;
005import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Annotation30_40;
006import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.CodeableConcept30_40;
007import org.hl7.fhir.convertors.conv30_40.datatypes30_40.complextypes30_40.Identifier30_40;
008import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40;
009import org.hl7.fhir.exceptions.FHIRException;
010
011public class Communication30_40 {
012
013  public static org.hl7.fhir.dstu3.model.Communication convertCommunication(org.hl7.fhir.r4.model.Communication src) throws FHIRException {
014    if (src == null)
015      return null;
016    org.hl7.fhir.dstu3.model.Communication tgt = new org.hl7.fhir.dstu3.model.Communication();
017    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
018    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
019      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
020    for (org.hl7.fhir.r4.model.UriType t : src.getInstantiatesCanonical())
021      tgt.addDefinition(new org.hl7.fhir.dstu3.model.Reference(t.getValue()));
022    for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_40.convertReference(t));
023    for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_40.convertReference(t));
024    if (src.hasStatus())
025      if (src.getStatus() == org.hl7.fhir.r4.model.Communication.CommunicationStatus.NOTDONE)
026        tgt.setNotDone(true);
027      else
028        tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
029    if (src.hasStatusReason())
030      tgt.setNotDoneReason(CodeableConcept30_40.convertCodeableConcept(src.getStatusReason()));
031    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getCategory())
032      tgt.addCategory(CodeableConcept30_40.convertCodeableConcept(t));
033    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getMedium())
034      tgt.addMedium(CodeableConcept30_40.convertCodeableConcept(t));
035    if (src.hasSubject())
036      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
037    for (org.hl7.fhir.r4.model.Reference t : src.getRecipient()) tgt.addRecipient(Reference30_40.convertReference(t));
038    if (src.hasEncounter())
039      tgt.setContext(Reference30_40.convertReference(src.getEncounter()));
040    if (src.hasSent())
041      tgt.setSentElement(DateTime30_40.convertDateTime(src.getSentElement()));
042    if (src.hasReceived())
043      tgt.setReceivedElement(DateTime30_40.convertDateTime(src.getReceivedElement()));
044    if (src.hasSender())
045      tgt.setSender(Reference30_40.convertReference(src.getSender()));
046    for (org.hl7.fhir.r4.model.CodeableConcept t : src.getReasonCode())
047      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
048    for (org.hl7.fhir.r4.model.Reference t : src.getReasonReference())
049      tgt.addReasonReference(Reference30_40.convertReference(t));
050    for (org.hl7.fhir.r4.model.Communication.CommunicationPayloadComponent t : src.getPayload())
051      tgt.addPayload(convertCommunicationPayloadComponent(t));
052    for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
053    return tgt;
054  }
055
056  public static org.hl7.fhir.r4.model.Communication convertCommunication(org.hl7.fhir.dstu3.model.Communication src) throws FHIRException {
057    if (src == null)
058      return null;
059    org.hl7.fhir.r4.model.Communication tgt = new org.hl7.fhir.r4.model.Communication();
060    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
061    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
062      tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
063    for (org.hl7.fhir.dstu3.model.Reference t : src.getDefinition()) tgt.addInstantiatesCanonical(t.getReference());
064    for (org.hl7.fhir.dstu3.model.Reference t : src.getBasedOn()) tgt.addBasedOn(Reference30_40.convertReference(t));
065    for (org.hl7.fhir.dstu3.model.Reference t : src.getPartOf()) tgt.addPartOf(Reference30_40.convertReference(t));
066    if (src.hasNotDone())
067      tgt.setStatus(org.hl7.fhir.r4.model.Communication.CommunicationStatus.NOTDONE);
068    else if (src.hasStatus())
069      tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
070    if (src.hasNotDoneReason())
071      tgt.setStatusReason(CodeableConcept30_40.convertCodeableConcept(src.getNotDoneReason()));
072    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getCategory())
073      tgt.addCategory(CodeableConcept30_40.convertCodeableConcept(t));
074    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getMedium())
075      tgt.addMedium(CodeableConcept30_40.convertCodeableConcept(t));
076    if (src.hasSubject())
077      tgt.setSubject(Reference30_40.convertReference(src.getSubject()));
078    for (org.hl7.fhir.dstu3.model.Reference t : src.getRecipient())
079      tgt.addRecipient(Reference30_40.convertReference(t));
080    if (src.hasContext())
081      tgt.setEncounter(Reference30_40.convertReference(src.getContext()));
082    if (src.hasSent())
083      tgt.setSentElement(DateTime30_40.convertDateTime(src.getSentElement()));
084    if (src.hasReceived())
085      tgt.setReceivedElement(DateTime30_40.convertDateTime(src.getReceivedElement()));
086    if (src.hasSender())
087      tgt.setSender(Reference30_40.convertReference(src.getSender()));
088    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode())
089      tgt.addReasonCode(CodeableConcept30_40.convertCodeableConcept(t));
090    for (org.hl7.fhir.dstu3.model.Reference t : src.getReasonReference())
091      tgt.addReasonReference(Reference30_40.convertReference(t));
092    for (org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent t : src.getPayload())
093      tgt.addPayload(convertCommunicationPayloadComponent(t));
094    for (org.hl7.fhir.dstu3.model.Annotation t : src.getNote()) tgt.addNote(Annotation30_40.convertAnnotation(t));
095    return tgt;
096  }
097
098  public static org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent convertCommunicationPayloadComponent(org.hl7.fhir.r4.model.Communication.CommunicationPayloadComponent src) throws FHIRException {
099    if (src == null)
100      return null;
101    org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent tgt = new org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent();
102    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
103    if (src.hasContent())
104      tgt.setContent(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getContent()));
105    return tgt;
106  }
107
108  public static org.hl7.fhir.r4.model.Communication.CommunicationPayloadComponent convertCommunicationPayloadComponent(org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent src) throws FHIRException {
109    if (src == null)
110      return null;
111    org.hl7.fhir.r4.model.Communication.CommunicationPayloadComponent tgt = new org.hl7.fhir.r4.model.Communication.CommunicationPayloadComponent();
112    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyBackboneElement(src,tgt);
113    if (src.hasContent())
114      tgt.setContent(ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getContent()));
115    return tgt;
116  }
117
118  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Communication.CommunicationStatus> convertCommunicationStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Communication.CommunicationStatus> src) throws FHIRException {
119    if (src == null || src.isEmpty())
120      return null;
121    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Communication.CommunicationStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Communication.CommunicationStatusEnumFactory());
122    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
123    switch (src.getValue()) {
124      case PREPARATION:
125        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.PREPARATION);
126        break;
127      case INPROGRESS:
128        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.INPROGRESS);
129        break;
130      case ONHOLD:
131        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.SUSPENDED);
132        break;
133      case STOPPED:
134        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.ABORTED);
135        break;
136      case COMPLETED:
137        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.COMPLETED);
138        break;
139      case ENTEREDINERROR:
140        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.ENTEREDINERROR);
141        break;
142      case UNKNOWN:
143        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.UNKNOWN);
144        break;
145      default:
146        tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.NULL);
147        break;
148    }
149    return tgt;
150  }
151
152  static public org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Communication.CommunicationStatus> convertCommunicationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Communication.CommunicationStatus> src) throws FHIRException {
153    if (src == null || src.isEmpty())
154      return null;
155    org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.Communication.CommunicationStatus> tgt = new org.hl7.fhir.r4.model.Enumeration<>(new org.hl7.fhir.r4.model.Communication.CommunicationStatusEnumFactory());
156    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
157    switch (src.getValue()) {
158      case PREPARATION:
159        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.PREPARATION);
160        break;
161      case INPROGRESS:
162        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.INPROGRESS);
163        break;
164      case SUSPENDED:
165        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.ONHOLD);
166        break;
167      case ABORTED:
168        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.STOPPED);
169        break;
170      case COMPLETED:
171        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.COMPLETED);
172        break;
173      case ENTEREDINERROR:
174        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.ENTEREDINERROR);
175        break;
176      case UNKNOWN:
177        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.UNKNOWN);
178        break;
179      default:
180        tgt.setValue(org.hl7.fhir.r4.model.Communication.CommunicationStatus.NULL);
181        break;
182    }
183    return tgt;
184  }
185}