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