001/* 002 * #%L 003 * HAPI FHIR Structures - DSTU2 (FHIR v1.0.0) 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 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 ca.uhn.fhir.model.dstu2; 021 022import ca.uhn.fhir.context.*; 023import ca.uhn.fhir.fhirpath.IFhirPath; 024import ca.uhn.fhir.i18n.Msg; 025import ca.uhn.fhir.model.api.*; 026import ca.uhn.fhir.model.base.composite.*; 027import ca.uhn.fhir.model.dstu2.composite.*; 028import ca.uhn.fhir.model.dstu2.resource.StructureDefinition; 029import ca.uhn.fhir.model.primitive.IdDt; 030import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory; 031import ca.uhn.fhir.rest.server.provider.dstu2.Dstu2BundleFactory; 032import ca.uhn.fhir.util.ReflectionUtil; 033import org.apache.commons.lang3.StringUtils; 034import org.hl7.fhir.instance.model.api.*; 035 036import java.io.InputStream; 037import java.util.Date; 038 039public class FhirDstu2 implements IFhirVersion { 040 041 private String myId; 042 043 @Override 044 public IFhirPath createFhirPathExecutor(FhirContext theFhirContext) { 045 throw new UnsupportedOperationException(Msg.code(578) + "FluentPath is not supported in DSTU2 contexts"); 046 } 047 048 @Override 049 public IResource 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 @Override 064 public Class<? extends BaseContainedDt> getContainedType() { 065 return ContainedDt.class; 066 } 067 068 @Override 069 public InputStream getFhirVersionPropertiesFile() { 070 InputStream str = FhirDstu2.class.getResourceAsStream("/ca/uhn/fhir/model/dstu2/fhirversion.properties"); 071 if (str == null) { 072 str = FhirDstu2.class.getResourceAsStream("ca/uhn/fhir/model/dstu2/fhirversion.properties"); 073 } 074 if (str == null) { 075 throw new ConfigurationException(Msg.code(579) + "Can not find model property file on classpath: " 076 + "/ca/uhn/fhir/model/dstu2/fhirversion.properties"); 077 } 078 return str; 079 } 080 081 @Override 082 public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) { 083 return ResourceMetadataKeyEnum.UPDATED.get((IResource) theResource); 084 } 085 086 @Override 087 public String getPathToSchemaDefinitions() { 088 return "/org/hl7/fhir/instance/model/schema"; 089 } 090 091 @Override 092 public Class<? extends BaseResourceReferenceDt> getResourceReferenceType() { 093 return ResourceReferenceDt.class; 094 } 095 096 @Override 097 public FhirVersionEnum getVersion() { 098 return FhirVersionEnum.DSTU2; 099 } 100 101 @Override 102 public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) { 103 return new Dstu2BundleFactory(theContext); 104 } 105 106 @Override 107 public BaseCodingDt newCodingDt() { 108 return new CodingDt(); 109 } 110 111 @Override 112 public IIdType newIdType() { 113 return new IdDt(); 114 } 115 116 @Override 117 public Object getServerVersion() { 118 return ReflectionUtil.newInstanceOfFhirServerType("ca.uhn.fhir.model.dstu2.FhirServerDstu2"); 119 } 120}