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