001package org.hl7.fhir.convertors.conv10_30.resources10_30;
002
003import org.hl7.fhir.convertors.context.ConversionContext10_30;
004import org.hl7.fhir.convertors.conv10_30.datatypes10_30.Reference10_30;
005import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.CodeableConcept10_30;
006import org.hl7.fhir.convertors.conv10_30.datatypes10_30.complextypes10_30.Identifier10_30;
007import org.hl7.fhir.convertors.conv10_30.datatypes10_30.primitivetypes10_30.DateTime10_30;
008import org.hl7.fhir.exceptions.FHIRException;
009
010public class CommunicationRequest10_30 {
011
012  public static org.hl7.fhir.dstu2.model.CommunicationRequest convertCommunicationRequest(org.hl7.fhir.dstu3.model.CommunicationRequest src) throws FHIRException {
013    if (src == null || src.isEmpty())
014      return null;
015    org.hl7.fhir.dstu2.model.CommunicationRequest tgt = new org.hl7.fhir.dstu2.model.CommunicationRequest();
016    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
017    for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier())
018      tgt.addIdentifier(Identifier10_30.convertIdentifier(t));
019    if (src.hasCategory())
020      tgt.setCategory(CodeableConcept10_30.convertCodeableConcept(src.getCategoryFirstRep()));
021    if (src.hasSender())
022      tgt.setSender(Reference10_30.convertReference(src.getSender()));
023    for (org.hl7.fhir.dstu3.model.Reference t : src.getRecipient())
024      tgt.addRecipient(Reference10_30.convertReference(t));
025    for (org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestPayloadComponent t : src.getPayload())
026      tgt.addPayload(convertCommunicationRequestPayloadComponent(t));
027    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getMedium())
028      tgt.addMedium(CodeableConcept10_30.convertCodeableConcept(t));
029    tgt.setRequester(Reference10_30.convertReference(src.getRequester().getAgent()));
030    if (src.hasStatus())
031      tgt.setStatusElement(convertCommunicationRequestStatus(src.getStatusElement()));
032    if (src.hasContext())
033      tgt.setEncounter(Reference10_30.convertReference(src.getContext()));
034    if (src.hasOccurrence())
035      tgt.setScheduled(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getOccurrence()));
036    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode())
037      tgt.addReason(CodeableConcept10_30.convertCodeableConcept(t));
038    if (src.hasAuthoredOnElement())
039      tgt.setRequestedOnElement(DateTime10_30.convertDateTime(src.getAuthoredOnElement()));
040    if (src.hasSubject())
041      tgt.setSubject(Reference10_30.convertReference(src.getSubject()));
042    if (src.hasPriority())
043      tgt.setPriority(convertPriorityCode(src.getPriority()));
044    return tgt;
045  }
046
047  public static org.hl7.fhir.dstu3.model.CommunicationRequest convertCommunicationRequest(org.hl7.fhir.dstu2.model.CommunicationRequest src) throws FHIRException {
048    if (src == null || src.isEmpty())
049      return null;
050    org.hl7.fhir.dstu3.model.CommunicationRequest tgt = new org.hl7.fhir.dstu3.model.CommunicationRequest();
051    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyDomainResource(src, tgt);
052    for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier())
053      tgt.addIdentifier(Identifier10_30.convertIdentifier(t));
054    if (src.hasCategory())
055      tgt.addCategory(CodeableConcept10_30.convertCodeableConcept(src.getCategory()));
056    if (src.hasSender())
057      tgt.setSender(Reference10_30.convertReference(src.getSender()));
058    for (org.hl7.fhir.dstu2.model.Reference t : src.getRecipient())
059      tgt.addRecipient(Reference10_30.convertReference(t));
060    for (org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestPayloadComponent t : src.getPayload())
061      tgt.addPayload(convertCommunicationRequestPayloadComponent(t));
062    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getMedium())
063      tgt.addMedium(CodeableConcept10_30.convertCodeableConcept(t));
064    tgt.getRequester().setAgent(Reference10_30.convertReference(src.getRequester()));
065    if (src.hasStatus())
066      tgt.setStatusElement(convertCommunicationRequestStatus(src.getStatusElement()));
067    if (src.hasEncounter())
068      tgt.setContext(Reference10_30.convertReference(src.getEncounter()));
069    if (src.hasScheduled())
070      tgt.setOccurrence(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getScheduled()));
071    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReason())
072      tgt.addReasonCode(CodeableConcept10_30.convertCodeableConcept(t));
073    if (src.hasRequestedOnElement())
074      tgt.setAuthoredOnElement(DateTime10_30.convertDateTime(src.getRequestedOnElement()));
075    if (src.hasSubject())
076      tgt.setSubject(Reference10_30.convertReference(src.getSubject()));
077    if (src.hasPriority())
078      tgt.setPriority(convertPriorityCode(src.getPriority()));
079    return tgt;
080  }
081
082  public static org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestPayloadComponent convertCommunicationRequestPayloadComponent(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestPayloadComponent src) throws FHIRException {
083    if (src == null || src.isEmpty())
084      return null;
085    org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestPayloadComponent tgt = new org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestPayloadComponent();
086    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
087    if (src.hasContent())
088      tgt.setContent(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getContent()));
089    return tgt;
090  }
091
092  public static org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestPayloadComponent convertCommunicationRequestPayloadComponent(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestPayloadComponent src) throws FHIRException {
093    if (src == null || src.isEmpty())
094      return null;
095    org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestPayloadComponent tgt = new org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestPayloadComponent();
096    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyBackboneElement(src,tgt);
097    if (src.hasContent())
098      tgt.setContent(ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().convertType(src.getContent()));
099    return tgt;
100  }
101
102  static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus> convertCommunicationRequestStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus> src) throws FHIRException {
103    if (src == null || src.isEmpty())
104      return null;
105    org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatusEnumFactory());
106    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
107    switch (src.getValue()) {
108      case PROPOSED:
109        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.DRAFT);
110        break;
111      case PLANNED:
112        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.ACTIVE);
113        break;
114      case REQUESTED:
115        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.ACTIVE);
116        break;
117      case RECEIVED:
118        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.ACTIVE);
119        break;
120      case ACCEPTED:
121        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.ACTIVE);
122        break;
123      case INPROGRESS:
124        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.ACTIVE);
125        break;
126      case COMPLETED:
127        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.COMPLETED);
128        break;
129      case SUSPENDED:
130        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.SUSPENDED);
131        break;
132      case REJECTED:
133        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.ENTEREDINERROR);
134        break;
135      default:
136        tgt.setValue(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus.NULL);
137        break;
138    }
139    return tgt;
140  }
141
142  static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus> convertCommunicationRequestStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationRequestStatus> src) throws FHIRException {
143    if (src == null || src.isEmpty())
144      return null;
145    org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatusEnumFactory());
146    ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
147    switch (src.getValue()) {
148      case DRAFT:
149        tgt.setValue(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus.PROPOSED);
150        break;
151      case ACTIVE:
152        tgt.setValue(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus.INPROGRESS);
153        break;
154      case COMPLETED:
155        tgt.setValue(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus.COMPLETED);
156        break;
157      case SUSPENDED:
158        tgt.setValue(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus.SUSPENDED);
159        break;
160      case ENTEREDINERROR:
161        tgt.setValue(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus.REJECTED);
162        break;
163      default:
164        tgt.setValue(org.hl7.fhir.dstu2.model.CommunicationRequest.CommunicationRequestStatus.NULL);
165        break;
166    }
167    return tgt;
168  }
169
170  static public org.hl7.fhir.dstu2.model.CodeableConcept convertPriorityCode(org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority priority) {
171    org.hl7.fhir.dstu2.model.CodeableConcept cc = new org.hl7.fhir.dstu2.model.CodeableConcept();
172    switch (priority) {
173      case ROUTINE:
174        cc.addCoding().setSystem("http://hl7.org/fhir/diagnostic-order-priority").setCode("routine");
175        break;
176      case URGENT:
177        cc.addCoding().setSystem("http://hl7.org/fhir/diagnostic-order-priority").setCode("urgent");
178        break;
179      case STAT:
180        cc.addCoding().setSystem("http://hl7.org/fhir/diagnostic-order-priority").setCode("stat");
181        break;
182      case ASAP:
183        cc.addCoding().setSystem("http://hl7.org/fhir/diagnostic-order-priority").setCode("asap");
184        break;
185      default:
186        return null;
187    }
188    return cc;
189  }
190
191  static public org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority convertPriorityCode(org.hl7.fhir.dstu2.model.CodeableConcept priority) {
192    for (org.hl7.fhir.dstu2.model.Coding c : priority.getCoding()) {
193      if ("http://hl7.org/fhir/diagnostic-order-priority".equals(c.getSystem()) && "routine".equals(c.getCode()))
194        return org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority.ROUTINE;
195      if ("http://hl7.org/fhir/diagnostic-order-priority".equals(c.getSystem()) && "urgent".equals(c.getCode()))
196        return org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority.URGENT;
197      if ("http://hl7.org/fhir/diagnostic-order-priority".equals(c.getSystem()) && "stat".equals(c.getCode()))
198        return org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority.STAT;
199      if ("http://hl7.org/fhir/diagnostic-order-priority".equals(c.getSystem()) && "asap".equals(c.getCode()))
200        return org.hl7.fhir.dstu3.model.CommunicationRequest.CommunicationPriority.ASAP;
201    }
202    return null;
203  }
204}