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 Provenance10_30 {
007
008    public static org.hl7.fhir.dstu2.model.Provenance convertProvenance(org.hl7.fhir.dstu3.model.Provenance src) throws FHIRException {
009        if (src == null || src.isEmpty())
010            return null;
011        org.hl7.fhir.dstu2.model.Provenance tgt = new org.hl7.fhir.dstu2.model.Provenance();
012        VersionConvertor_10_30.copyDomainResource(src, tgt);
013        for (org.hl7.fhir.dstu3.model.Reference t : src.getTarget()) tgt.addTarget(VersionConvertor_10_30.convertReference(t));
014        if (src.hasPeriod())
015            tgt.setPeriod(VersionConvertor_10_30.convertPeriod(src.getPeriod()));
016        if (src.hasRecordedElement())
017            tgt.setRecordedElement(VersionConvertor_10_30.convertInstant(src.getRecordedElement()));
018        for (org.hl7.fhir.dstu3.model.Coding t : src.getReason()) tgt.addReason().addCoding(VersionConvertor_10_30.convertCoding(t));
019        tgt.setActivity(new org.hl7.fhir.dstu2.model.CodeableConcept().addCoding(VersionConvertor_10_30.convertCoding(src.getActivity())));
020        if (src.hasLocation())
021            tgt.setLocation(VersionConvertor_10_30.convertReference(src.getLocation()));
022        for (org.hl7.fhir.dstu3.model.UriType t : src.getPolicy()) tgt.addPolicy(t.getValue());
023        for (org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent t : src.getAgent()) tgt.addAgent(convertProvenanceAgentComponent(t));
024        for (org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent t : src.getEntity()) tgt.addEntity(convertProvenanceEntityComponent(t));
025        for (org.hl7.fhir.dstu3.model.Signature t : src.getSignature()) tgt.addSignature(VersionConvertor_10_30.convertSignature(t));
026        return tgt;
027    }
028
029    public static org.hl7.fhir.dstu3.model.Provenance convertProvenance(org.hl7.fhir.dstu2.model.Provenance src) throws FHIRException {
030        if (src == null || src.isEmpty())
031            return null;
032        org.hl7.fhir.dstu3.model.Provenance tgt = new org.hl7.fhir.dstu3.model.Provenance();
033        VersionConvertor_10_30.copyDomainResource(src, tgt);
034        for (org.hl7.fhir.dstu2.model.Reference t : src.getTarget()) tgt.addTarget(VersionConvertor_10_30.convertReference(t));
035        if (src.hasPeriod())
036            tgt.setPeriod(VersionConvertor_10_30.convertPeriod(src.getPeriod()));
037        if (src.hasRecordedElement())
038            tgt.setRecordedElement(VersionConvertor_10_30.convertInstant(src.getRecordedElement()));
039        for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getReason()) for (org.hl7.fhir.dstu2.model.Coding tc : t.getCoding()) tgt.addReason(VersionConvertor_10_30.convertCoding(tc));
040        for (org.hl7.fhir.dstu2.model.Coding t : src.getActivity().getCoding()) tgt.setActivity(VersionConvertor_10_30.convertCoding(t));
041        if (src.hasLocation())
042            tgt.setLocation(VersionConvertor_10_30.convertReference(src.getLocation()));
043        for (org.hl7.fhir.dstu2.model.UriType t : src.getPolicy()) tgt.addPolicy(t.getValue());
044        for (org.hl7.fhir.dstu2.model.Provenance.ProvenanceAgentComponent t : src.getAgent()) tgt.addAgent(convertProvenanceAgentComponent(t));
045        for (org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityComponent t : src.getEntity()) tgt.addEntity(convertProvenanceEntityComponent(t));
046        for (org.hl7.fhir.dstu2.model.Signature t : src.getSignature()) tgt.addSignature(VersionConvertor_10_30.convertSignature(t));
047        return tgt;
048    }
049
050    public static org.hl7.fhir.dstu2.model.Provenance.ProvenanceAgentComponent convertProvenanceAgentComponent(org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent src) throws FHIRException {
051        if (src == null || src.isEmpty())
052            return null;
053        org.hl7.fhir.dstu2.model.Provenance.ProvenanceAgentComponent tgt = new org.hl7.fhir.dstu2.model.Provenance.ProvenanceAgentComponent();
054        VersionConvertor_10_30.copyElement(src, tgt);
055        if (src.hasWhoReference())
056            tgt.setActor(VersionConvertor_10_30.convertReference(src.getWhoReference()));
057        return tgt;
058    }
059
060    public static org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent convertProvenanceAgentComponent(org.hl7.fhir.dstu2.model.Provenance.ProvenanceAgentComponent src) throws FHIRException {
061        if (src == null || src.isEmpty())
062            return null;
063        org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent tgt = new org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent();
064        VersionConvertor_10_30.copyElement(src, tgt);
065        if (src.hasActor())
066            tgt.setWho(VersionConvertor_10_30.convertReference(src.getActor()));
067        return tgt;
068    }
069
070    public static org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityComponent convertProvenanceEntityComponent(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent src) throws FHIRException {
071        if (src == null || src.isEmpty())
072            return null;
073        org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityComponent tgt = new org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityComponent();
074        VersionConvertor_10_30.copyElement(src, tgt);
075        if (src.hasRole())
076            tgt.setRoleElement(convertProvenanceEntityRole(src.getRoleElement()));
077        if (src.hasWhatReference() && src.getWhatReference().hasReference())
078            tgt.setReference(src.getWhatReference().getReference());
079        for (org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent t : src.getAgent()) tgt.setAgent(convertProvenanceAgentComponent(t));
080        return tgt;
081    }
082
083    public static org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent convertProvenanceEntityComponent(org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityComponent src) throws FHIRException {
084        if (src == null || src.isEmpty())
085            return null;
086        org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent tgt = new org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityComponent();
087        VersionConvertor_10_30.copyElement(src, tgt);
088        if (src.hasRole())
089            tgt.setRoleElement(convertProvenanceEntityRole(src.getRoleElement()));
090        if (src.hasReference())
091            tgt.setWhat(new org.hl7.fhir.dstu3.model.Reference().setReference(src.getReference()));
092        if (src.hasAgent())
093            tgt.addAgent(convertProvenanceAgentComponent(src.getAgent()));
094        return tgt;
095    }
096
097    static public org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole> convertProvenanceEntityRole(org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole> src) throws FHIRException {
098        if (src == null || src.isEmpty())
099            return null;
100        org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole> tgt = new org.hl7.fhir.dstu3.model.Enumeration<>(new org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRoleEnumFactory());
101        VersionConvertor_10_30.copyElement(src, tgt);
102        switch(src.getValue()) {
103            case DERIVATION:
104                tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.DERIVATION);
105                break;
106            case REVISION:
107                tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.REVISION);
108                break;
109            case QUOTATION:
110                tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.QUOTATION);
111                break;
112            case SOURCE:
113                tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.SOURCE);
114                break;
115            default:
116                tgt.setValue(org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole.NULL);
117                break;
118        }
119        return tgt;
120    }
121
122    static public org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole> convertProvenanceEntityRole(org.hl7.fhir.dstu3.model.Enumeration<org.hl7.fhir.dstu3.model.Provenance.ProvenanceEntityRole> src) throws FHIRException {
123        if (src == null || src.isEmpty())
124            return null;
125        org.hl7.fhir.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole> tgt = new org.hl7.fhir.dstu2.model.Enumeration<>(new org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRoleEnumFactory());
126        VersionConvertor_10_30.copyElement(src, tgt);
127        switch(src.getValue()) {
128            case DERIVATION:
129                tgt.setValue(org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole.DERIVATION);
130                break;
131            case REVISION:
132                tgt.setValue(org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole.REVISION);
133                break;
134            case QUOTATION:
135                tgt.setValue(org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole.QUOTATION);
136                break;
137            case SOURCE:
138                tgt.setValue(org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole.SOURCE);
139                break;
140            default:
141                tgt.setValue(org.hl7.fhir.dstu2.model.Provenance.ProvenanceEntityRole.NULL);
142                break;
143        }
144        return tgt;
145    }
146}