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