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 Communication10_30 {
007
008    public static org.hl7.fhir.dstu3.model.Communication convertCommunication(org.hl7.fhir.dstu2.model.Communication src) throws FHIRException {
009        if (src == null || src.isEmpty())
010            return null;
011        org.hl7.fhir.dstu3.model.Communication tgt = new org.hl7.fhir.dstu3.model.Communication();
012        VersionConvertor_10_30.copyDomainResource(src, tgt);
013        for (org.hl7.fhir.dstu2.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(VersionConvertor_10_30.convertIdentifier(t));
014        if (src.hasCategory())
015            tgt.addCategory(VersionConvertor_10_30.convertCodeableConcept(src.getCategory()));
016        if (src.hasSender())
017            tgt.setSender(VersionConvertor_10_30.convertReference(src.getSender()));
018        for (org.hl7.fhir.dstu2.model.Reference t : src.getRecipient()) tgt.addRecipient(VersionConvertor_10_30.convertReference(t));
019        for (org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent t : src.getPayload()) tgt.addPayload(convertCommunicationPayloadComponent(t));
020        for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getMedium()) tgt.addMedium(VersionConvertor_10_30.convertCodeableConcept(t));
021        if (src.hasStatus())
022            tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
023        if (src.hasEncounter())
024            tgt.setContext(VersionConvertor_10_30.convertReference(src.getEncounter()));
025        if (src.hasSentElement())
026            tgt.setSentElement(VersionConvertor_10_30.convertDateTime(src.getSentElement()));
027        if (src.hasReceivedElement())
028            tgt.setReceivedElement(VersionConvertor_10_30.convertDateTime(src.getReceivedElement()));
029        for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReason()) tgt.addReasonCode(VersionConvertor_10_30.convertCodeableConcept(t));
030        if (src.hasSubject())
031            tgt.setSubject(VersionConvertor_10_30.convertReference(src.getSubject()));
032        return tgt;
033    }
034
035    public static org.hl7.fhir.dstu2.model.Communication convertCommunication(org.hl7.fhir.dstu3.model.Communication src) throws FHIRException {
036        if (src == null || src.isEmpty())
037            return null;
038        org.hl7.fhir.dstu2.model.Communication tgt = new org.hl7.fhir.dstu2.model.Communication();
039        VersionConvertor_10_30.copyDomainResource(src, tgt);
040        for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(VersionConvertor_10_30.convertIdentifier(t));
041        if (src.hasCategory())
042            tgt.setCategory(VersionConvertor_10_30.convertCodeableConcept(src.getCategoryFirstRep()));
043        if (src.hasSender())
044            tgt.setSender(VersionConvertor_10_30.convertReference(src.getSender()));
045        for (org.hl7.fhir.dstu3.model.Reference t : src.getRecipient()) tgt.addRecipient(VersionConvertor_10_30.convertReference(t));
046        for (org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent t : src.getPayload()) tgt.addPayload(convertCommunicationPayloadComponent(t));
047        for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getMedium()) tgt.addMedium(VersionConvertor_10_30.convertCodeableConcept(t));
048        if (src.hasStatus())
049            tgt.setStatusElement(convertCommunicationStatus(src.getStatusElement()));
050        if (src.hasContext())
051            tgt.setEncounter(VersionConvertor_10_30.convertReference(src.getContext()));
052        if (src.hasSentElement())
053            tgt.setSentElement(VersionConvertor_10_30.convertDateTime(src.getSentElement()));
054        if (src.hasReceivedElement())
055            tgt.setReceivedElement(VersionConvertor_10_30.convertDateTime(src.getReceivedElement()));
056        for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getReasonCode()) tgt.addReason(VersionConvertor_10_30.convertCodeableConcept(t));
057        if (src.hasSubject())
058            tgt.setSubject(VersionConvertor_10_30.convertReference(src.getSubject()));
059        return tgt;
060    }
061
062    public static org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent convertCommunicationPayloadComponent(org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent src) throws FHIRException {
063        if (src == null || src.isEmpty())
064            return null;
065        org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent tgt = new org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent();
066        VersionConvertor_10_30.copyElement(src, tgt);
067        if (src.hasContent())
068            tgt.setContent(VersionConvertor_10_30.convertType(src.getContent()));
069        return tgt;
070    }
071
072    public static org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent convertCommunicationPayloadComponent(org.hl7.fhir.dstu2.model.Communication.CommunicationPayloadComponent src) throws FHIRException {
073        if (src == null || src.isEmpty())
074            return null;
075        org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent tgt = new org.hl7.fhir.dstu3.model.Communication.CommunicationPayloadComponent();
076        VersionConvertor_10_30.copyElement(src, tgt);
077        if (src.hasContent())
078            tgt.setContent(VersionConvertor_10_30.convertType(src.getContent()));
079        return tgt;
080    }
081
082    static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Communication.CommunicationStatus> convertCommunicationStatus(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Communication.CommunicationStatus> src) throws FHIRException {
083        if (src == null || src.isEmpty())
084            return null;
085        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());
086        VersionConvertor_10_30.copyElement(src, tgt);
087        switch(src.getValue()) {
088            case INPROGRESS:
089                tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.INPROGRESS);
090                break;
091            case COMPLETED:
092                tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.COMPLETED);
093                break;
094            case SUSPENDED:
095                tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.SUSPENDED);
096                break;
097            case REJECTED:
098                tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.ENTEREDINERROR);
099                break;
100            case FAILED:
101                tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.ABORTED);
102                break;
103            default:
104                tgt.setValue(org.hl7.fhir.dstu3.model.Communication.CommunicationStatus.NULL);
105                break;
106        }
107        return tgt;
108    }
109
110    static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Communication.CommunicationStatus> convertCommunicationStatus(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Communication.CommunicationStatus> src) throws FHIRException {
111        if (src == null || src.isEmpty())
112            return null;
113        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());
114        VersionConvertor_10_30.copyElement(src, tgt);
115        switch(src.getValue()) {
116            case INPROGRESS:
117                tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.INPROGRESS);
118                break;
119            case COMPLETED:
120                tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.COMPLETED);
121                break;
122            case SUSPENDED:
123                tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.SUSPENDED);
124                break;
125            case ENTEREDINERROR:
126                tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.REJECTED);
127                break;
128            case ABORTED:
129                tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.FAILED);
130                break;
131            default:
132                tgt.setValue(org.hl7.fhir.dstu2.model.Communication.CommunicationStatus.NULL);
133                break;
134        }
135        return tgt;
136    }
137}