001package org.hl7.fhir.r4.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 java.io.InputStream; 025import java.util.Date; 026import java.util.List; 027 028import org.apache.commons.lang3.StringUtils; 029import org.hl7.fhir.instance.model.api.*; 030import org.hl7.fhir.r4.hapi.fluentpath.FhirPathR4; 031import org.hl7.fhir.r4.hapi.rest.server.R4BundleFactory; 032import org.hl7.fhir.r4.model.*; 033 034import ca.uhn.fhir.context.*; 035import ca.uhn.fhir.fhirpath.IFhirPath; 036import ca.uhn.fhir.model.api.IFhirVersion; 037import ca.uhn.fhir.model.primitive.IdDt; 038import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory; 039import ca.uhn.fhir.util.ReflectionUtil; 040 041public class FhirR4 implements IFhirVersion { 042 043 private String myId; 044 045 @Override 046 public IFhirPath createFhirPathExecutor(FhirContext theFhirContext) { 047 return new FhirPathR4(theFhirContext); 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 String path = "org/hl7/fhir/r4/model/fhirversion.properties"; 074 InputStream str = FhirR4.class.getResourceAsStream("/" + path); 075 if (str == null) { 076 str = FhirR4.class.getResourceAsStream(path); 077 } 078 if (str == null) { 079 throw new ConfigurationException(Msg.code(257) + "Can not find model property file on classpath: " + path); 080 } 081 return str; 082 } 083 084 @Override 085 public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) { 086 return ((Resource) theResource).getMeta().getLastUpdatedElement(); 087 } 088 089 @Override 090 public String getPathToSchemaDefinitions() { 091 return "/org/hl7/fhir/r4/model/schema"; 092 } 093 094 @Override 095 public Class<? extends IBaseReference> getResourceReferenceType() { 096 return Reference.class; 097 } 098 099 @Override 100 public Object getServerVersion() { 101 return ReflectionUtil.newInstanceOfFhirServerType("org.hl7.fhir.r4.hapi.ctx.FhirServerR4"); 102 } 103 104 @Override 105 public FhirVersionEnum getVersion() { 106 return FhirVersionEnum.R4; 107 } 108 109 @Override 110 public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) { 111 return new R4BundleFactory(theContext); 112 } 113 114 @Override 115 public IBaseCoding newCodingDt() { 116 return new Coding(); 117 } 118 119 @Override 120 public IIdType newIdType() { 121 return new IdType(); 122 } 123 124}