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