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