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