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