001package org.hl7.fhir.convertors.conv10_30;
002
003import org.hl7.fhir.convertors.VersionConvertor_10_30;
004import org.hl7.fhir.dstu3.model.Specimen;
005import org.hl7.fhir.exceptions.FHIRException;
006
007public class Specimen10_30 {
008
009    static public org.hl7.fhir.dstu2.model.Specimen convertSpecimen(Specimen src) {
010        if (src == null) {
011            return null;
012        }
013        org.hl7.fhir.dstu2.model.Specimen tgt = new org.hl7.fhir.dstu2.model.Specimen();
014        VersionConvertor_10_30.copyDomainResource(src, tgt);
015        for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(VersionConvertor_10_30.convertIdentifier(t));
016        if (src.hasAccessionIdentifier())
017            tgt.setAccessionIdentifier(VersionConvertor_10_30.convertIdentifier(src.getAccessionIdentifier()));
018        if (src.hasStatus())
019            tgt.setStatus(convertSpecimenStatus(src.getStatus()));
020        if (src.hasType())
021            tgt.setType(VersionConvertor_10_30.convertCodeableConcept(src.getType()));
022        if (src.hasSubject())
023            tgt.setSubject(VersionConvertor_10_30.convertReference(src.getSubject()));
024        if (src.hasReceivedTime())
025            tgt.setReceivedTime(src.getReceivedTime());
026        for (org.hl7.fhir.dstu3.model.Reference t : src.getParent()) tgt.addParent(VersionConvertor_10_30.convertReference(t));
027        if (src.hasCollection())
028            tgt.setCollection(convertSpecimenCollectionComponent(src.getCollection()));
029        for (org.hl7.fhir.dstu3.model.Specimen.SpecimenProcessingComponent t : src.getProcessing()) tgt.addTreatment(convertSpecimenProcessingComponent(t));
030        for (org.hl7.fhir.dstu3.model.Specimen.SpecimenContainerComponent t : src.getContainer()) tgt.addContainer(convertSpecimenContainerComponent(t));
031        return tgt;
032    }
033
034    public static org.hl7.fhir.dstu2.model.Specimen.SpecimenCollectionComponent convertSpecimenCollectionComponent(org.hl7.fhir.dstu3.model.Specimen.SpecimenCollectionComponent src) throws FHIRException {
035        if (src == null)
036            return null;
037        org.hl7.fhir.dstu2.model.Specimen.SpecimenCollectionComponent tgt = new org.hl7.fhir.dstu2.model.Specimen.SpecimenCollectionComponent();
038        VersionConvertor_10_30.copyElement(src, tgt);
039        if (src.hasCollector())
040            tgt.setCollector(VersionConvertor_10_30.convertReference(src.getCollector()));
041        if (src.hasCollected())
042            tgt.setCollected(VersionConvertor_10_30.convertType(src.getCollected()));
043        if (src.hasQuantity())
044            tgt.setQuantity(VersionConvertor_10_30.convertSimpleQuantity(src.getQuantity()));
045        if (src.hasMethod())
046            tgt.setMethod(VersionConvertor_10_30.convertCodeableConcept(src.getMethod()));
047        if (src.hasBodySite())
048            tgt.setBodySite(VersionConvertor_10_30.convertCodeableConcept(src.getBodySite()));
049        return tgt;
050    }
051
052    public static org.hl7.fhir.dstu2.model.Specimen.SpecimenContainerComponent convertSpecimenContainerComponent(org.hl7.fhir.dstu3.model.Specimen.SpecimenContainerComponent src) throws FHIRException {
053        if (src == null)
054            return null;
055        org.hl7.fhir.dstu2.model.Specimen.SpecimenContainerComponent tgt = new org.hl7.fhir.dstu2.model.Specimen.SpecimenContainerComponent();
056        VersionConvertor_10_30.copyElement(src, tgt);
057        for (org.hl7.fhir.dstu3.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(VersionConvertor_10_30.convertIdentifier(t));
058        if (src.hasDescription())
059            tgt.setDescriptionElement(VersionConvertor_10_30.convertString(src.getDescriptionElement()));
060        if (src.hasType())
061            tgt.setType(VersionConvertor_10_30.convertCodeableConcept(src.getType()));
062        if (src.hasCapacity())
063            tgt.setCapacity(VersionConvertor_10_30.convertSimpleQuantity(src.getCapacity()));
064        if (src.hasSpecimenQuantity())
065            tgt.setSpecimenQuantity(VersionConvertor_10_30.convertSimpleQuantity(src.getSpecimenQuantity()));
066        if (src.hasAdditive())
067            tgt.setAdditive(VersionConvertor_10_30.convertType(src.getAdditive()));
068        return tgt;
069    }
070
071    public static org.hl7.fhir.dstu2.model.Specimen.SpecimenTreatmentComponent convertSpecimenProcessingComponent(org.hl7.fhir.dstu3.model.Specimen.SpecimenProcessingComponent src) throws FHIRException {
072        if (src == null)
073            return null;
074        org.hl7.fhir.dstu2.model.Specimen.SpecimenTreatmentComponent tgt = new org.hl7.fhir.dstu2.model.Specimen.SpecimenTreatmentComponent();
075        VersionConvertor_10_30.copyElement(src, tgt);
076        if (src.hasDescription())
077            tgt.setDescriptionElement(VersionConvertor_10_30.convertString(src.getDescriptionElement()));
078        if (src.hasProcedure())
079            tgt.setProcedure(VersionConvertor_10_30.convertCodeableConcept(src.getProcedure()));
080        for (org.hl7.fhir.dstu3.model.Reference t : src.getAdditive()) tgt.addAdditive(VersionConvertor_10_30.convertReference(t));
081        return tgt;
082    }
083
084    static public org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus convertSpecimenStatus(Specimen.SpecimenStatus status) {
085        if (status == null) {
086            return null;
087        }
088        switch(status) {
089            case AVAILABLE:
090                return org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus.AVAILABLE;
091            case UNAVAILABLE:
092                return org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus.UNAVAILABLE;
093            case ENTEREDINERROR:
094                return org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus.ENTEREDINERROR;
095            case UNSATISFACTORY:
096                return org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus.UNSATISFACTORY;
097            case NULL:
098                return org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus.NULL;
099            default:
100                return org.hl7.fhir.dstu2.model.Specimen.SpecimenStatus.NULL;
101        }
102    }
103}