001package org.hl7.fhir.instance;
002
003/*
004 * #%L
005 * HAPI FHIR Structures - HL7.org DSTU2
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.ArrayList;
025import java.util.Date;
026
027import org.apache.commons.lang3.StringUtils;
028import org.hl7.fhir.instance.model.*;
029import org.hl7.fhir.instance.model.api.*;
030
031import ca.uhn.fhir.context.*;
032import ca.uhn.fhir.context.support.IContextValidationSupport;
033import ca.uhn.fhir.fluentpath.IFluentPath;
034import ca.uhn.fhir.model.api.IFhirVersion;
035import ca.uhn.fhir.model.base.composite.BaseCodingDt;
036import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
037import ca.uhn.fhir.rest.server.provider.dstu2hl7org.Dstu2Hl7OrgBundleFactory;
038import ca.uhn.fhir.util.ReflectionUtil;
039
040public class FhirDstu2Hl7Org implements IFhirVersion {
041
042  private String myId;
043
044  @Override
045  public IFluentPath createFluentPathExecutor(FhirContext theFhirContext) {
046    throw new UnsupportedOperationException("FluentPath is not supported in DSTU2 contexts");
047  }
048
049  @Override
050  public IContextValidationSupport<?, ?, ?, ?, ?, ?> createValidationSupport() {
051    throw new UnsupportedOperationException("Validation support is not supported in DSTU2 contexts");
052  }
053
054  @Override
055  public StructureDefinition generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
056    StructureDefinition retVal = new StructureDefinition();
057
058    RuntimeResourceDefinition def = theRuntimeResourceDefinition;
059
060    myId = def.getId();
061    if (StringUtils.isBlank(myId)) {
062      myId = theRuntimeResourceDefinition.getName().toLowerCase();
063    }
064
065    retVal.setId(myId);
066    return retVal;
067  }
068
069  @SuppressWarnings("rawtypes")
070  @Override
071  public Class<ArrayList> getContainedType() {
072    return ArrayList.class;
073  }
074
075  @Override
076  public InputStream getFhirVersionPropertiesFile() {
077    String path = "/org/hl7/fhir/instance/model/fhirversion.properties";
078    InputStream str = FhirDstu2Hl7Org.class.getResourceAsStream(path);
079    if (str == null) {
080      str = FhirDstu2Hl7Org.class.getResourceAsStream(path.substring(1));
081    }
082    if (str == null) {
083      throw new ConfigurationException("Can not find model property file on classpath: " + path);
084    }
085    return str;
086  }
087
088  @Override
089  public IPrimitiveType<Date> getLastUpdated(IBaseResource theResource) {
090    return ((Resource) theResource).getMeta().getLastUpdatedElement();
091  }
092
093  @Override
094  public String getPathToSchemaDefinitions() {
095    return "/org/hl7/fhir/instance/model/schema";
096  }
097
098  @Override
099  public Class<Reference> getResourceReferenceType() {
100    return Reference.class;
101  }
102
103  @Override
104  public Object getServerVersion() {
105    return ReflectionUtil.newInstanceOfFhirServerType("org.hl7.fhir.instance.FhirServerDstu2Hl7Org2");
106  }
107
108  @Override
109  public FhirVersionEnum getVersion() {
110    return FhirVersionEnum.DSTU2_HL7ORG;
111  }
112
113  @Override
114  public IVersionSpecificBundleFactory newBundleFactory(FhirContext theContext) {
115    return new Dstu2Hl7OrgBundleFactory(theContext);
116  }
117
118  @Override
119  public BaseCodingDt newCodingDt() {
120    throw new UnsupportedOperationException();
121  }
122
123  @Override
124  public IIdType newIdType() {
125    return new IdType();
126  }
127
128}