001package ca.uhn.fhir.model.dstu2;
002
003/*
004 * #%L
005 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
006 * %%
007 * Copyright (C) 2014 - 2020 University Health Network
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import java.io.InputStream;
024import java.util.Date;
025
026import org.apache.commons.lang3.StringUtils;
027import org.hl7.fhir.instance.model.api.*;
028
029import ca.uhn.fhir.context.*;
030import ca.uhn.fhir.context.support.IContextValidationSupport;
031import ca.uhn.fhir.fluentpath.IFluentPath;
032import ca.uhn.fhir.model.api.*;
033import ca.uhn.fhir.model.base.composite.*;
034import ca.uhn.fhir.model.dstu2.composite.*;
035import ca.uhn.fhir.model.dstu2.resource.StructureDefinition;
036import ca.uhn.fhir.model.primitive.IdDt;
037import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
038import ca.uhn.fhir.rest.server.provider.dstu2.Dstu2BundleFactory;
039import ca.uhn.fhir.util.ReflectionUtil;
040
041public class FhirDstu2 implements IFhirVersion {
042
043        private String myId;
044
045        @Override
046        public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
047                throw new UnsupportedOperationException("FluentPath is not supported in DSTU2 contexts");
048        }
049
050
051        @Override
052        public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
053                throw new UnsupportedOperationException("Validation support is not supported in DSTU2 contexts");
054        }
055
056        @Override
057        public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
058                StructureDefinition retVal = new StructureDefinition();
059
060                RuntimeResourceDefinition def = theRuntimeResourceDefinition;
061
062                myId = def.getId();
063                if (StringUtils.isBlank(myId)) {
064                        myId = theRuntimeResourceDefinition.getName().toLowerCase();
065                }
066
067                retVal.setId(new IdDt(myId));
068                return retVal;
069        }
070
071        @Override
072        public Class<? extends BaseContainedDt> getContainedType() {
073                return ContainedDt.class;
074        }
075
076        @Override
077        public InputStream getFhirVersionPropertiesFile() {
078                InputStream str = FhirDstu2.class.getResourceAsStream("/ca/uhn/fhir/model/dstu2/fhirversion.properties");
079                if (str == null) {
080                        str = FhirDstu2.class.getResourceAsStream("ca/uhn/fhir/model/dstu2/fhirversion.properties");
081                }
082                if (str == null) {
083                        throw new ConfigurationException("Can not find model property file on classpath: " + "/ca/uhn/fhir/model/dstu2/fhirversion.properties");
084                }
085                return str;
086        }
087
088        @Override
089        public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
090                return ResourceMetadataKeyEnum.UPDATED.get((IResource) theResource);
091        }
092
093        @Override
094        public String getPathToSchemaDefinitions() {
095                return "/org/hl7/fhir/instance/model/schema";
096        }
097
098        @Override
099        public Class<? extends BaseResourceReferenceDt> getResourceReferenceType() {
100                return ResourceReferenceDt.class;
101        }
102
103        @Override
104        public FhirVersionEnum getVersion() {
105                return FhirVersionEnum.DSTU2;
106        }
107
108        @Override
109        public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
110                return new Dstu2BundleFactory(theContext);
111        }
112
113        @Override
114        public BaseCodingDt newCodingDt() {
115                return new CodingDt();
116        }
117
118        @Override
119        public IIdType newIdType() {
120                return new IdDt();
121        }
122
123
124        
125
126        @Override
127        public Object getServerVersion() {
128                return ReflectionUtil.newInstanceOfFhirServerType("ca.uhn.fhir.model.dstu2.FhirServerDstu2");
129        }
130
131
132}