001/* 002 * #%L 003 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) 004 * %% 005 * Copyright (C) 2014 - 2015 University Health Network 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package org.hl7.fhir.dstu2016may.hapi.ctx; 021 022import ca.uhn.fhir.context.ConfigurationException; 023import ca.uhn.fhir.context.FhirContext; 024import ca.uhn.fhir.context.FhirVersionEnum; 025import ca.uhn.fhir.context.RuntimeResourceDefinition; 026import ca.uhn.fhir.fhirpath.IFhirPath; 027import ca.uhn.fhir.i18n.Msg; 028import ca.uhn.fhir.model.api.IFhirVersion; 029import ca.uhn.fhir.model.primitive.IdDt; 030import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory; 031import ca.uhn.fhir.util.ReflectionUtil; 032import org.apache.commons.lang3.StringUtils; 033import org.hl7.fhir.dstu2016may.hapi.rest.server.Dstu2_1BundleFactory; 034import org.hl7.fhir.dstu2016may.model.*; 035import org.hl7.fhir.instance.model.api.*; 036 037import java.io.InputStream; 038import java.util.Date; 039import java.util.List; 040 041public class FhirDstu2_1 implements IFhirVersion { 042 043 private String myId; 044 045 @Override 046 public IFhirPath createFhirPathExecutor(FhirContext theFhirContext) { 047 throw new UnsupportedOperationException(Msg.code(466) + "FluentPath is not supported in DSTU2 contexts"); 048 } 049 050 @Override 051 public IBaseResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) { 052 StructureDefinition retVal = new StructureDefinition(); 053 054 RuntimeResourceDefinition def = theRuntimeResourceDefinition; 055 056 myId = def.getId(); 057 if (StringUtils.isBlank(myId)) { 058 myId = theRuntimeResourceDefinition.getName().toLowerCase(); 059 } 060 061 retVal.setId(new IdDt(myId)); 062 return retVal; 063 } 064 065 @SuppressWarnings("rawtypes") 066 @Override 067 public Class<List> getContainedType() { 068 return List.class; 069 } 070 071 @Override 072 public InputStream getFhirVersionPropertiesFile() { 073 InputStream str = 074 FhirDstu2_1.class.getResourceAsStream("/org/hl7/fhir/dstu2016may/hapi/model/fhirversion.properties"); 075 if (str == null) { 076 str = FhirDstu2_1.class.getResourceAsStream("/org/hl7/fhir/dstu2016may/hapi/model/fhirversion.properties"); 077 } 078 if (str == null) { 079 throw new ConfigurationException(Msg.code(467) + "Can not find model property file on classpath: " 080 + "/org/hl7/fhir/dstu2016may/hapi/model/fhirversion.properties"); 081 } 082 return str; 083 } 084 085 @Override 086 public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) { 087 return ((Resource) theResource).getMeta().getLastUpdatedElement(); 088 } 089 090 @Override 091 public String getPathToSchemaDefinitions() { 092 return "/org/hl7/fhir/dstu2016may/model/schema"; 093 } 094 095 @Override 096 public Class<? extends IBaseReference> getResourceReferenceType() { 097 return Reference.class; 098 } 099 100 @Override 101 public FhirVersionEnum getVersion() { 102 return FhirVersionEnum.DSTU2_1; 103 } 104 105 @Override 106 public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) { 107 return new Dstu2_1BundleFactory(theContext); 108 } 109 110 @Override 111 public IBaseCoding newCodingDt() { 112 return new Coding(); 113 } 114 115 @Override 116 public IIdType newIdType() { 117 return new IdType(); 118 } 119 120 @Override 121 public Object getServerVersion() { 122 return ReflectionUtil.newInstanceOfFhirServerType("org.hl7.fhir.dstu2016may.hapi.ctx.FhirServerDstu2_1"); 123 } 124}