001package org.hl7.fhir.r4.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.instance.model.api.*;
029import org.hl7.fhir.r4.hapi.fluentpath.FluentPathR4;
030import org.hl7.fhir.r4.hapi.rest.server.R4BundleFactory;
031import org.hl7.fhir.r4.model.*;
032
033import ca.uhn.fhir.context.*;
034import ca.uhn.fhir.context.support.IContextValidationSupport;
035import ca.uhn.fhir.fluentpath.IFluentPath;
036import ca.uhn.fhir.model.api.IFhirVersion;
037import ca.uhn.fhir.model.primitive.IdDt;
038import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
039import ca.uhn.fhir.util.ReflectionUtil;
040
041public class FhirR4 implements IFhirVersion {
042
043        private String myId;
044
045        @Override
046        public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
047                return new FluentPathR4(theFhirContext);
048        }
049
050        @Override
051        public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
052                return ReflectionUtil.newInstanceOfFhirProfileValidationSupport("org.hl7.fhir.r4.hapi.ctx.DefaultProfileValidationSupport");
053        }
054
055        @Override
056        public IBaseResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
057                StructureDefinition retVal = new StructureDefinition();
058
059                RuntimeResourceDefinition def = theRuntimeResourceDefinition;
060
061                myId = def.getId();
062                if (StringUtils.isBlank(myId)) {
063                        myId = theRuntimeResourceDefinition.getName().toLowerCase();
064                }
065
066                retVal.setId(new IdDt(myId));
067                return retVal;
068        }
069
070        @SuppressWarnings("rawtypes")
071        @Override
072        public Class<List> getContainedType() {
073                return List.class;
074        }
075
076        @Override
077        public InputStream getFhirVersionPropertiesFile() {
078                String path = "org/hl7/fhir/r4/model/fhirversion.properties";
079                InputStream str = FhirR4.class.getResourceAsStream("/" + path);
080                if (str == null) {
081                        str = FhirR4.class.getResourceAsStream(path);
082                }
083                if (str == null) {
084                        throw new ConfigurationException("Can not find model property file on classpath: " + path);
085                }
086                return str;
087        }
088
089        @Override
090        public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
091                return ((Resource) theResource).getMeta().getLastUpdatedElement();
092        }
093
094        @Override
095        public String getPathToSchemaDefinitions() {
096                return "/org/hl7/fhir/r4/model/schema";
097        }
098
099        @Override
100        public Class<? extends IBaseReference> getResourceReferenceType() {
101                return Reference.class;
102        }
103
104        @Override
105        public Object getServerVersion() {
106                return ReflectionUtil.newInstanceOfFhirServerType("org.hl7.fhir.r4.hapi.ctx.FhirServerR4");
107        }
108
109        @Override
110        public FhirVersionEnum getVersion() {
111                return FhirVersionEnum.R4;
112        }
113
114        @Override
115        public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
116                return new R4BundleFactory(theContext);
117        }
118
119        @Override
120        public IBaseCoding newCodingDt() {
121                return new Coding();
122        }
123
124        @Override
125        public IIdType newIdType() {
126                return new IdType();
127        }
128
129}