001package org.hl7.fhir.dstu3.hapi.ctx;
002
003/*
004 * #%L
005 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
006 * %%
007 * Copyright (C) 2014 - 2015 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;
025import java.util.List;
026
027import org.apache.commons.lang3.StringUtils;
028import org.hl7.fhir.dstu3.hapi.fluentpath.FluentPathDstu3;
029import org.hl7.fhir.dstu3.hapi.rest.server.Dstu3BundleFactory;
030import org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider;
031import org.hl7.fhir.dstu3.hapi.rest.server.ServerProfileProvider;
032import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport;
033import org.hl7.fhir.dstu3.model.Coding;
034import org.hl7.fhir.dstu3.model.Constants;
035import org.hl7.fhir.dstu3.model.IdType;
036import org.hl7.fhir.dstu3.model.Reference;
037import org.hl7.fhir.dstu3.model.Resource;
038import org.hl7.fhir.dstu3.model.StructureDefinition;
039import org.hl7.fhir.instance.model.api.IBaseCoding;
040import org.hl7.fhir.instance.model.api.IBaseReference;
041import org.hl7.fhir.instance.model.api.IBaseResource;
042import org.hl7.fhir.instance.model.api.IIdType;
043import org.hl7.fhir.instance.model.api.IPrimitiveType;
044
045import ca.uhn.fhir.context.ConfigurationException;
046import ca.uhn.fhir.context.FhirContext;
047import ca.uhn.fhir.context.FhirVersionEnum;
048import ca.uhn.fhir.context.RuntimeResourceDefinition;
049import ca.uhn.fhir.context.support.IContextValidationSupport;
050import ca.uhn.fhir.fluentpath.IFluentPath;
051import ca.uhn.fhir.model.api.IFhirVersion;
052import ca.uhn.fhir.model.primitive.IdDt;
053import ca.uhn.fhir.rest.server.IResourceProvider;
054import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory;
055import ca.uhn.fhir.rest.server.RestfulServer;
056
057public class FhirDstu3 implements IFhirVersion {
058
059        private String myId;
060
061        @Override
062        public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
063                return new FluentPathDstu3(theFhirContext);
064        }
065
066        @Override
067        public ServerCapabilityStatementProvider createServerConformanceProvider(RestfulServer theServer) {
068                return new ServerCapabilityStatementProvider(theServer);
069        }
070
071        @Override
072        public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
073                return new ServerProfileProvider(theRestfulServer);
074        }
075
076        @Override
077        public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
078                return new DefaultProfileValidationSupport();
079        }
080
081        @Override
082        public IBaseResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
083                StructureDefinition retVal = new StructureDefinition();
084
085                RuntimeResourceDefinition def = theRuntimeResourceDefinition;
086
087                myId = def.getId();
088                if (StringUtils.isBlank(myId)) {
089                        myId = theRuntimeResourceDefinition.getName().toLowerCase();
090                }
091
092                retVal.setId(new IdDt(myId));
093                return retVal;
094        }
095
096        @SuppressWarnings("rawtypes")
097        @Override
098        public Class<List> getContainedType() {
099                return List.class;
100        }
101
102        @Override
103        public InputStream getFhirVersionPropertiesFile() {
104                InputStream str = FhirDstu3.class.getResourceAsStream("/org/hl7/fhir/dstu3/model/fhirversion.properties");
105                if (str == null) {
106                        str = FhirDstu3.class.getResourceAsStream("/org/hl7/fhir/dstu3/model/fhirversion.properties");
107                }
108                if (str == null) {
109                        throw new ConfigurationException("Can not find model property file on classpath: " + "/ca/uhn/fhir/model/dstu3/fhirversion.properties");
110                }
111                return str;
112        }
113
114        @Override
115        public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
116                return ((Resource) theResource).getMeta().getLastUpdatedElement();
117        }
118        
119        @Override
120        public String getPathToSchemaDefinitions() {
121                return "/org/hl7/fhir/instance/model/dstu3/schema";
122        }
123
124        @Override
125        public Class<? extends IBaseReference> getResourceReferenceType() {
126                return Reference.class;
127        }
128
129        @Override
130        public FhirVersionEnum getVersion() {
131                return FhirVersionEnum.DSTU3;
132        }
133
134        @Override
135        public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
136                return new Dstu3BundleFactory(theContext);
137        }
138
139        @Override
140        public IBaseCoding newCodingDt() {
141                return new Coding();
142        }
143
144        @Override
145        public IIdType newIdType() {
146                return new IdType();
147        }
148
149}