001package ca.uhn.fhir.model.dstu2;
002
003/*
004 * #%L
005 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
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 ca.uhn.fhir.i18n.Msg;
024import java.io.InputStream;
025import java.util.Date;
026
027import ca.uhn.fhir.fhirpath.IFhirPath;
028import org.apache.commons.lang3.StringUtils;
029import org.hl7.fhir.instance.model.api.*;
030
031import ca.uhn.fhir.context.*;
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 IFhirPath createFhirPathExecutor(FhirContext theFhirContext) {
047                throw new UnsupportedOperationException(Msg.code(578) + "FluentPath is not supported in DSTU2 contexts");
048        }
049
050
051        @Override
052        public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
053                StructureDefinition retVal = new StructureDefinition();
054
055                RuntimeResourceDefinition def = theRuntimeResourceDefinition;
056
057                myId = def.getId();
058                if (StringUtils.isBlank(myId)) {
059                        myId = theRuntimeResourceDefinition.getName().toLowerCase();
060                }
061
062                retVal.setId(new IdDt(myId));
063                return retVal;
064        }
065
066        @Override
067        public Class<? extends BaseContainedDt> getContainedType() {
068                return ContainedDt.class;
069        }
070
071        @Override
072        public InputStream getFhirVersionPropertiesFile() {
073                InputStream str = FhirDstu2.class.getResourceAsStream("/ca/uhn/fhir/model/dstu2/fhirversion.properties");
074                if (str == null) {
075                        str = FhirDstu2.class.getResourceAsStream("ca/uhn/fhir/model/dstu2/fhirversion.properties");
076                }
077                if (str == null) {
078                        throw new ConfigurationException(Msg.code(579) + "Can not find model property file on classpath: " + "/ca/uhn/fhir/model/dstu2/fhirversion.properties");
079                }
080                return str;
081        }
082
083        @Override
084        public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
085                return ResourceMetadataKeyEnum.UPDATED.get((IResource) theResource);
086        }
087
088        @Override
089        public String getPathToSchemaDefinitions() {
090                return "/org/hl7/fhir/instance/model/schema";
091        }
092
093        @Override
094        public Class<? extends BaseResourceReferenceDt> getResourceReferenceType() {
095                return ResourceReferenceDt.class;
096        }
097
098        @Override
099        public FhirVersionEnum getVersion() {
100                return FhirVersionEnum.DSTU2;
101        }
102
103        @Override
104        public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
105                return new Dstu2BundleFactory(theContext);
106        }
107
108        @Override
109        public BaseCodingDt newCodingDt() {
110                return new CodingDt();
111        }
112
113        @Override
114        public IIdType newIdType() {
115                return new IdDt();
116        }
117
118
119        
120
121        @Override
122        public Object getServerVersion() {
123                return ReflectionUtil.newInstanceOfFhirServerType("ca.uhn.fhir.model.dstu2.FhirServerDstu2");
124        }
125
126
127}