Unit tests all pass again, elements in baseresouerce reordered

This commit is contained in:
jamesagnew 2014-12-19 09:14:40 -05:00
parent c5d014e9ee
commit 4ca405a8fc
12 changed files with 61 additions and 627 deletions

View File

@ -1,53 +0,0 @@
package ca.uhn.fhir.model.api;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.InputStream;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import javax.servlet.http.HttpServletRequest;
public interface IFhirVersion {
<<<<<<< HEAD
FhirVersionEnum getVersion();
IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition);
Object createServerConformanceProvider(RestfulServer theServer);
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
InputStream getFhirVersionPropertiesFile();
=======
IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase);
Object createServerConformanceProvider(RestfulServer theServer);
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
>>>>>>> origin/master
}

View File

@ -22,7 +22,6 @@ package ca.uhn.fhir.model.base.resource;
import ca.uhn.fhir.model.api.BaseResource;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import ca.uhn.fhir.model.primitive.StringDt;
//@ResourceDef(name="Conformance")

View File

@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -677,9 +678,31 @@ public class XmlParser extends BaseParser implements IParser {
private void encodeResourceToStreamWriterInDstu2Format(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter,
BaseRuntimeElementCompositeDefinition<?> resDef, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
/*
* DSTU2 requires extensions to come in a specific spot within the encoded content -
* This is a bit of a messy way to make that happen, but hopefully this won't
* matter as much once we use the HL7 structures
*/
List<BaseRuntimeChildDefinition> preExtensionChildren = new ArrayList<BaseRuntimeChildDefinition>();
List<BaseRuntimeChildDefinition> postExtensionChildren = new ArrayList<BaseRuntimeChildDefinition>();
List<BaseRuntimeChildDefinition> children = resDef.getChildren();
for (BaseRuntimeChildDefinition next : children) {
if (next.getElementName().equals("text")) {
preExtensionChildren.add(next);
} else if (next.getElementName().equals("contained")) {
preExtensionChildren.add(next);
} else {
postExtensionChildren.add(next);
}
}
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, preExtensionChildren, theIncludedResource);
encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, theElement, theIncludedResource);
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getExtensions(), theIncludedResource);
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren(), theIncludedResource);
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, postExtensionChildren, theIncludedResource);
}
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter,

View File

@ -15,7 +15,7 @@
<dependent-module archiveName="hapi-fhir-structures-dstu-0.9-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/hapi-fhir-structures-dstu/hapi-fhir-structures-dstu">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module deploy-path="/" handle="module:/overlay/prj/hapi-fhir-testpage-overlay?includes=**/**&amp;excludes=META-INF/MANIFEST.MF">
<dependent-module deploy-path="/" handle="module:/overlay/var/M2_REPO/ca/uhn/hapi/fhir/hapi-fhir-testpage-overlay/0.9-SNAPSHOT/hapi-fhir-testpage-overlay-0.9-SNAPSHOT.war?unpackFolder=target/m2e-wtp/overlays&amp;includes=**/**&amp;excludes=META-INF/MANIFEST.MF">
<dependency-type>consumes</dependency-type>
</dependent-module>
<dependent-module deploy-path="/" handle="module:/overlay/slf/?includes=**/**&amp;excludes=META-INF/MANIFEST.MF">

View File

@ -15,7 +15,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>

View File

@ -1,5 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding//target/generated-resources/tinder=UTF-8

View File

@ -13,14 +13,18 @@ import java.text.SimpleDateFormat;
import org.apache.commons.io.IOUtils;
import org.hamcrest.core.StringContains;
import org.hl7.fhir.instance.model.DeviceComponent.MeasurementPrinciple;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.dev.composite.TimingDt;
import ca.uhn.fhir.model.dev.resource.MedicationPrescription;
import ca.uhn.fhir.model.dev.resource.OperationOutcome;
import ca.uhn.fhir.model.dev.resource.Patient;
import ca.uhn.fhir.model.dev.valueset.ContactPointSystemEnum;
import ca.uhn.fhir.model.primitive.DateDt;
import ca.uhn.fhir.model.primitive.DateTimeDt;
public class ResourceValidatorTest {
@ -66,7 +70,7 @@ public class ResourceValidatorTest {
assertThat(encoded, StringContains.containsString("2000-15-31"));
p = ourCtx.newXmlParser().parseResource(Patient.class, encoded);
assertEquals("2000-15-31", p.getBirthDate());
assertEquals("2000-15-31", p.getBirthDateElement().getValueAsString());
assertEquals("2001-03-31", new SimpleDateFormat("yyyy-MM-dd").format(p.getBirthDate()));
ValidationResult result = ourCtx.newValidator().validateWithResult(p);
@ -74,7 +78,7 @@ public class ResourceValidatorTest {
ourLog.info(resultString);
assertEquals(2, result.getOperationOutcome().getIssue().size());
assertThat(resultString, StringContains.containsString("cvc-datatype-valid.1.2.3"));
assertThat(resultString, StringContains.containsString("cvc-pattern-valid: Value '2000-15-31'"));
}
@SuppressWarnings("deprecation")
@ -87,16 +91,19 @@ public class ResourceValidatorTest {
val.validate(b);
Patient p = (Patient) b.getEntries().get(0).getResource();
p.getTelecomFirstRep().setValue("123-4567");
MedicationPrescription p = (MedicationPrescription) b.getEntries().get(0).getResource();
TimingDt timing = new TimingDt();
timing.getRepeat().setCount(5);
timing.getRepeat().setEnd(DateTimeDt.withCurrentTime());
p.getDosageInstructionFirstRep().setScheduled(timing);
try {
val.validate(b);
fail();
} catch (ValidationFailureException e) {
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome()));
assertEquals(1, e.getOperationOutcome().getIssue().size());
assertThat(e.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue(), containsString("Inv-2: A system is required if a value is provided."));
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome());
ourLog.info(encoded);
assertThat(encoded, containsString("Inv-3: At most, only one of count or end can be present"));
}
}
@ -152,14 +159,18 @@ public class ResourceValidatorTest {
ValidationResult validationResult = val.validateWithResult(b);
assertTrue(validationResult.isSuccessful());
Patient p = (Patient) b.getEntries().get(0).getResource();
p.getTelecomFirstRep().setValue("123-4567");
MedicationPrescription p = (MedicationPrescription) b.getEntries().get(0).getResource();
TimingDt timing = new TimingDt();
timing.getRepeat().setCount(5);
timing.getRepeat().setEnd(DateTimeDt.withCurrentTime());
p.getDosageInstructionFirstRep().setScheduled(timing);
validationResult = val.validateWithResult(b);
assertFalse(validationResult.isSuccessful());
OperationOutcome operationOutcome = (OperationOutcome) validationResult.getOperationOutcome();
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome));
assertEquals(1, operationOutcome.getIssue().size());
assertThat(operationOutcome.getIssueFirstRep().getDetails(), containsString("Inv-2: A system is required if a value is provided."));
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome);
ourLog.info(encoded);
assertThat(encoded, containsString("Inv-3: At most, only one of count or end can be present"));
}
private FhirValidator createFhirValidator() {

View File

@ -1,369 +0,0 @@
package ca.uhn.fhir.model.dstu;
/*
* #%L
* HAPI FHIR Structures - DSTU (FHIR 0.80)
* %%
* Copyright (C) 2014 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import static org.apache.commons.lang3.StringUtils.*;
import java.io.InputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.WordUtils;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeDeclaredChildDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeChildChoiceDefinition;
import ca.uhn.fhir.context.RuntimeChildCompositeDatatypeDefinition;
import ca.uhn.fhir.context.RuntimeChildContainedResources;
import ca.uhn.fhir.context.RuntimeChildDeclaredExtensionDefinition;
import ca.uhn.fhir.context.RuntimeChildPrimitiveDatatypeDefinition;
import ca.uhn.fhir.context.RuntimeChildResourceBlockDefinition;
import ca.uhn.fhir.context.RuntimeChildResourceDefinition;
import ca.uhn.fhir.context.RuntimeChildUndeclaredExtensionDefinition;
import ca.uhn.fhir.context.RuntimeCompositeDatatypeDefinition;
import ca.uhn.fhir.context.RuntimePrimitiveDatatypeDefinition;
import ca.uhn.fhir.context.RuntimeResourceBlockDefinition;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeResourceReferenceDefinition;
import ca.uhn.fhir.model.api.ICompositeDatatype;
import ca.uhn.fhir.model.api.IFhirVersion;
import ca.uhn.fhir.model.api.IPrimitiveDatatype;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.dstu.resource.Profile;
import ca.uhn.fhir.model.dstu.resource.Profile.ExtensionDefn;
import ca.uhn.fhir.model.dstu.resource.Profile.Structure;
import ca.uhn.fhir.model.dstu.resource.Profile.StructureElement;
import ca.uhn.fhir.model.dstu.resource.Profile.StructureElementDefinitionType;
import ca.uhn.fhir.model.dstu.valueset.DataTypeEnum;
import ca.uhn.fhir.model.dstu.valueset.SlicingRulesEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.provider.ServerConformanceProvider;
import ca.uhn.fhir.rest.server.provider.ServerProfileProvider;
import javax.servlet.http.HttpServletRequest;
public class FhirDstu1 implements IFhirVersion {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirDstu1.class);
// private Map<RuntimeChildDeclaredExtensionDefinition, String> myExtensionDefToCode = new HashMap<RuntimeChildDeclaredExtensionDefinition, String>();
private String myId;
@Override
public Object createServerConformanceProvider(RestfulServer theServer) {
return new ServerConformanceProvider(theServer);
}
private void fillBasics(StructureElement theElement, BaseRuntimeElementDefinition<?> def, LinkedList<String> path, BaseRuntimeDeclaredChildDefinition theChild) {
if (path.isEmpty()) {
path.add(def.getName());
theElement.setName(def.getName());
} else {
path.add(WordUtils.uncapitalize(theChild.getElementName()));
theElement.setName(theChild.getElementName());
}
theElement.setPath(StringUtils.join(path, '.'));
}
private void fillExtensions(Structure theStruct, LinkedList<String> path, List<RuntimeChildDeclaredExtensionDefinition> extList, String elementName, boolean theIsModifier) {
if (extList.size() > 0) {
StructureElement extSlice = theStruct.addElement();
extSlice.setName(elementName);
extSlice.setPath(join(path, '.') + '.' + elementName);
extSlice.getSlicing().getDiscriminator().setValue("url");
extSlice.getSlicing().setOrdered(false);
extSlice.getSlicing().setRules(SlicingRulesEnum.OPEN);
extSlice.getDefinition().addType().setCode(DataTypeEnum.EXTENSION);
for (RuntimeChildDeclaredExtensionDefinition nextExt : extList) {
StructureElement nextProfileExt = theStruct.addElement();
nextProfileExt.getDefinition().setIsModifier(theIsModifier);
nextProfileExt.setName(extSlice.getName());
nextProfileExt.setPath(extSlice.getPath());
fillMinAndMaxAndDefinitions(nextExt, nextProfileExt);
StructureElementDefinitionType type = nextProfileExt.getDefinition().addType();
type.setCode(DataTypeEnum.EXTENSION);
if (nextExt.isDefinedLocally()) {
type.setProfile(nextExt.getExtensionUrl().substring(nextExt.getExtensionUrl().indexOf('#')));
} else {
type.setProfile(nextExt.getExtensionUrl());
}
}
} else {
StructureElement extSlice = theStruct.addElement();
extSlice.setName(elementName);
extSlice.setPath(join(path, '.') + '.' + elementName);
extSlice.getDefinition().setIsModifier(theIsModifier);
extSlice.getDefinition().addType().setCode(DataTypeEnum.EXTENSION);
extSlice.getDefinition().setMin(0);
extSlice.getDefinition().setMax("*");
}
}
private void fillMinAndMaxAndDefinitions(BaseRuntimeDeclaredChildDefinition child, StructureElement elem) {
elem.getDefinition().setMin(child.getMin());
if (child.getMax() == Child.MAX_UNLIMITED) {
elem.getDefinition().setMax("*");
} else {
elem.getDefinition().setMax(Integer.toString(child.getMax()));
}
if (isNotBlank(child.getShortDefinition())) {
elem.getDefinition().getShort().setValue(child.getShortDefinition());
}
if (isNotBlank(child.getFormalDefinition())) {
elem.getDefinition().getFormal().setValue(child.getFormalDefinition());
}
}
private void fillName(StructureElement elem, BaseRuntimeElementDefinition<?> nextDef, String theServerBase) {
if (nextDef instanceof RuntimeResourceReferenceDefinition) {
RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef;
for (Class<? extends IBaseResource> next : rr.getResourceTypes()) {
StructureElementDefinitionType type = elem.getDefinition().addType();
type.getCode().setValue("ResourceReference");
if (next != IResource.class) {
<<<<<<< HEAD
@SuppressWarnings("unchecked")
RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType((Class<? extends IResource>) next);
type.getProfile().setValueAsString(resDef.getResourceProfile());
=======
RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next);
type.getProfile().setValueAsString(resDef.getResourceProfile(theServerBase));
>>>>>>> origin/master
}
}
return;
}
StructureElementDefinitionType type = elem.getDefinition().addType();
String name = nextDef.getName();
DataTypeEnum fromCodeString = DataTypeEnum.VALUESET_BINDER.fromCodeString(name);
if (fromCodeString == null) {
throw new ConfigurationException("Unknown type: " + name);
}
type.setCode(fromCodeString);
}
private void fillProfile(Structure theStruct, StructureElement theElement, BaseRuntimeElementDefinition<?> def, LinkedList<String> path, BaseRuntimeDeclaredChildDefinition theChild, String theServerBase) {
fillBasics(theElement, def, path, theChild);
String expectedPath = StringUtils.join(path, '.');
ourLog.debug("Filling profile for: {} - Path: {}", expectedPath);
String name = def.getName();
if (!expectedPath.equals(name)) {
path.pollLast();
theElement.getDefinition().getNameReference().setValue(def.getName());
return;
}
fillExtensions(theStruct, path, def.getExtensionsNonModifier(), "extension", false);
fillExtensions(theStruct, path, def.getExtensionsModifier(), "modifierExtension", true);
if (def.getChildType() == ChildTypeEnum.RESOURCE) {
StructureElement narrative = theStruct.addElement();
narrative.setName("text");
narrative.setPath(join(path, '.') + ".text");
narrative.getDefinition().addType().setCode(DataTypeEnum.NARRATIVE);
narrative.getDefinition().setIsModifier(false);
narrative.getDefinition().setMin(0);
narrative.getDefinition().setMax("1");
StructureElement contained = theStruct.addElement();
contained.setName("contained");
contained.setPath(join(path, '.') + ".contained");
contained.getDefinition().addType().getCode().setValue("Resource");
contained.getDefinition().setIsModifier(false);
contained.getDefinition().setMin(0);
contained.getDefinition().setMax("1");
}
if (def instanceof BaseRuntimeElementCompositeDefinition) {
BaseRuntimeElementCompositeDefinition<?> cdef = ((BaseRuntimeElementCompositeDefinition<?>) def);
for (BaseRuntimeChildDefinition nextChild : cdef.getChildren()) {
if (nextChild instanceof RuntimeChildUndeclaredExtensionDefinition) {
continue;
}
BaseRuntimeDeclaredChildDefinition child = (BaseRuntimeDeclaredChildDefinition) nextChild;
StructureElement elem = theStruct.addElement();
fillMinAndMaxAndDefinitions(child, elem);
if (child instanceof RuntimeChildResourceBlockDefinition) {
RuntimeResourceBlockDefinition nextDef = (RuntimeResourceBlockDefinition) child.getSingleChildOrThrow();
fillProfile(theStruct, elem, nextDef, path, child, theServerBase);
} else if (child instanceof RuntimeChildContainedResources) {
// ignore
} else if (child instanceof RuntimeChildDeclaredExtensionDefinition) {
throw new IllegalStateException("Unexpected child type: " + child.getClass().getCanonicalName());
} else if (child instanceof RuntimeChildCompositeDatatypeDefinition || child instanceof RuntimeChildPrimitiveDatatypeDefinition || child instanceof RuntimeChildChoiceDefinition
|| child instanceof RuntimeChildResourceDefinition) {
Iterator<String> childNamesIter = child.getValidChildNames().iterator();
String nextName = childNamesIter.next();
BaseRuntimeElementDefinition<?> nextDef = child.getChildByName(nextName);
fillBasics(elem, nextDef, path, child);
fillName(elem, nextDef, theServerBase);
while (childNamesIter.hasNext()) {
nextDef = child.getChildByName(childNamesIter.next());
fillName(elem, nextDef, theServerBase);
}
path.pollLast();
} else {
throw new IllegalStateException("Unexpected child type: " + child.getClass().getCanonicalName());
}
}
} else {
throw new IllegalStateException("Unexpected child type: " + def.getClass().getCanonicalName());
}
path.pollLast();
}
@Override
public IResource generateProfile(RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
Profile retVal = new Profile();
RuntimeResourceDefinition def = theRuntimeResourceDefinition;
myId = def.getId();
if (StringUtils.isBlank(myId)) {
myId = theRuntimeResourceDefinition.getName().toLowerCase();
}
retVal.setId(new IdDt(myId));
// Scan for extensions
scanForExtensions(retVal, def, new HashMap<RuntimeChildDeclaredExtensionDefinition, String>());
Collections.sort(retVal.getExtensionDefn(), new Comparator<ExtensionDefn>() {
@Override
public int compare(ExtensionDefn theO1, ExtensionDefn theO2) {
return theO1.getCode().compareTo(theO2.getCode());
}
});
// Scan for children
retVal.setName(def.getName());
Structure struct = retVal.addStructure();
LinkedList<String> path = new LinkedList<String>();
StructureElement element = struct.addElement();
element.getDefinition().setMin(1);
element.getDefinition().setMax("1");
fillProfile(struct, element, def, path, null, theServerBase);
retVal.getStructure().get(0).getElement().get(0).getDefinition().addType().getCode().setValue("Resource");
return retVal;
}
private Map<RuntimeChildDeclaredExtensionDefinition, String> scanForExtensions(Profile theProfile, BaseRuntimeElementDefinition<?> def, Map<RuntimeChildDeclaredExtensionDefinition, String> theExtensionDefToCode) {
BaseRuntimeElementCompositeDefinition<?> cdef = ((BaseRuntimeElementCompositeDefinition<?>) def);
for (RuntimeChildDeclaredExtensionDefinition nextChild : cdef.getExtensions()) {
if (theExtensionDefToCode.containsKey(nextChild)) {
continue;
}
if (nextChild.isDefinedLocally() == false) {
continue;
}
ExtensionDefn defn = theProfile.addExtensionDefn();
String code = null;
if (nextChild.getExtensionUrl().contains("#") && !nextChild.getExtensionUrl().endsWith("#")) {
code = nextChild.getExtensionUrl().substring(nextChild.getExtensionUrl().indexOf('#') + 1);
} else {
throw new ConfigurationException("Locally defined extension has no '#[code]' part in extension URL: " + nextChild.getExtensionUrl());
}
defn.setCode(code);
if (theExtensionDefToCode.values().contains(code)) {
throw new IllegalStateException("Duplicate extension code: " + code);
}
theExtensionDefToCode.put(nextChild, code);
if (nextChild.getChildType() != null && IPrimitiveDatatype.class.isAssignableFrom(nextChild.getChildType())) {
RuntimePrimitiveDatatypeDefinition pdef = (RuntimePrimitiveDatatypeDefinition) nextChild.getSingleChildOrThrow();
defn.getDefinition().addType().setCode(DataTypeEnum.VALUESET_BINDER.fromCodeString(pdef.getName()));
} else if (nextChild.getChildType() != null && ICompositeDatatype.class.isAssignableFrom(nextChild.getChildType())) {
RuntimeCompositeDatatypeDefinition pdef = (RuntimeCompositeDatatypeDefinition) nextChild.getSingleChildOrThrow();
defn.getDefinition().addType().setCode(DataTypeEnum.VALUESET_BINDER.fromCodeString(pdef.getName()));
} else {
RuntimeResourceBlockDefinition pdef = (RuntimeResourceBlockDefinition) nextChild.getSingleChildOrThrow();
scanForExtensions(theProfile, pdef, theExtensionDefToCode);
for (RuntimeChildDeclaredExtensionDefinition nextChildExt : pdef.getExtensions()) {
StructureElementDefinitionType type = defn.getDefinition().addType();
type.setCode(DataTypeEnum.EXTENSION);
type.setProfile("#" + theExtensionDefToCode.get(nextChildExt));
}
}
}
return theExtensionDefToCode;
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
@Override
public FhirVersionEnum getVersion() {
return FhirVersionEnum.DSTU1;
}
@Override
public InputStream getFhirVersionPropertiesFile() {
InputStream str = FhirDstu1.class.getResourceAsStream("/ca/uhn/fhir/model/dstu/fhirversion.properties");
if (str == null) {
str = FhirDstu1.class.getResourceAsStream("ca/uhn/fhir/model/dstu/fhirversion.properties");
}
if (str == null) {
throw new ConfigurationException("Can not find model property file on classpath: " + "/ca/uhn/fhir/model/dstu/model.properties");
}
return str;
}
}

View File

@ -84,4 +84,10 @@ public class FhirDev implements IFhirVersion {
return str;
}
@Override
public String getPathToSchemaDefinitions() {
return "ca/uhn/fhir/model/dev/schema";
}
}

View File

@ -358,6 +358,11 @@ public class FhirDstu1 implements IFhirVersion {
return str;
}
@Override
public String getPathToSchemaDefinitions() {
return "ca/uhn/fhir/model/dstu/schema";
}

View File

@ -1,95 +0,0 @@
#parse ( "/vm/templates.vm" )
package ${packageBase}.resource;
import java.math.BigDecimal;
import java.net.URI;
import java.util.*;
import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.rest.gclient.*;
#foreach ( $import in $imports )
import ${import};
#end
##import ${packageBase}.composite.*;
##import ${packageBase}.valueset.*;
/**
* HAPI/FHIR <b>${elementName}</b> Resource
* (${shortName})
*
* <p>
* <b>Definition:</b>
* ${definition}
* </p>
*
* <p>
* <b>Requirements:</b>
* ${requirements}
* </p>
*
#if (${profile} != "")
* <p>
* <b>Profile Definition:</b>
* <a href="${profile}">${profile}</a>
* </p>
*
#end
*/
@ResourceDef(name="${elementName}", profile="${profile}", id="${id}")
public class ${className}
<<<<<<< HEAD
extends #{if}( ${className}=="OperationOutcome" || ${className}=="Conformance" ) ca.uhn.fhir.model.base.resource.Base${className} #{else} BaseResource #{end}
=======
extends #{if}( ${className}=="OperationOutcome" || ${className}=="Conformance" || ${className}=="SecurityEvent" ) ca.uhn.fhir.model.base.resource.Base${className} #{else} BaseResource #{end}
>>>>>>> d22a35788f57e9f7ce64bc8afc2ee7eaf29d94f2
implements IResource {
#foreach ( $param in $searchParams )
/**
* Search parameter constant for <b>${param.name}</b>
* <p>
* Description: <b>${param.description}</b><br/>
* Type: <b>${param.type}</b><br/>
* Path: <b>${param.path}</b><br/>
* </p>
*/
@SearchParamDefinition(name="${param.name}", path="${param.path}", description="${param.description}", type="${param.type}" #{if}($param.compositeOf.empty == false) , compositeOf={ #{foreach}($compositeOf in $param.compositeOf) "${compositeOf}"#{if}($foreach.hasNext), #{end}#{end} } #{end} )
public static final String $param.constantName = "${param.name}";
/**
* <b>Fluent Client</b> search parameter constant for <b>${param.name}</b>
* <p>
* Description: <b>${param.description}</b><br/>
* Type: <b>${param.type}</b><br/>
* Path: <b>${param.path}</b><br/>
* </p>
*/
#if( ${param.typeCapitalized} == 'Composite' )
public static final CompositeClientParam<${param.compositeTypes[0]}ClientParam, ${param.compositeTypes[1]}ClientParam> ${param.fluentConstantName} = new CompositeClientParam<${param.compositeTypes[0]}ClientParam, ${param.compositeTypes[1]}ClientParam>(${param.constantName});
#else
public static final ${param.typeCapitalized}ClientParam ${param.fluentConstantName} = new ${param.typeCapitalized}ClientParam(${param.constantName});
#end
#if( ${param.typeCapitalized} == 'Reference' )
#foreach ( $include in $param.paths )
/**
* Constant for fluent queries to be used to add include statements. Specifies
* the path value of "<b>${include.path}</b>".
*/
public static final Include INCLUDE_${include.includeName} = new Include("${include.path}");
#end
#end
#end
#childExtensionFields( $childExtensionTypes )
#childVars( $children )
#childAccessors( $children )
#childResourceBlocks($resourceBlockChildren)
#childExtensionTypes( $childExtensionTypes )
}

View File

@ -1,94 +0,0 @@
#parse ( "/vm/templates_dstu.vm" )
package ${packageBase}.resource;
import java.util.*;
import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.rest.gclient.*;
#foreach ( $import in $imports )
import ${import};
#end
##import ${packageBase}.composite.*;
##import ${packageBase}.valueset.*;
/**
* HAPI/FHIR <b>${elementName}</b> Resource
* (${shortName})
*
* <p>
* <b>Definition:</b>
* ${definition}
* </p>
*
* <p>
* <b>Requirements:</b>
* ${requirements}
* </p>
*
#if (${profile} != "")
* <p>
* <b>Profile Definition:</b>
* <a href="${profile}">${profile}</a>
* </p>
*
#end
*/
@ResourceDef(name="${elementName}", profile="${profile}", id="${id}")
public class ${className}
<<<<<<< HEAD
extends #{if}( ${className}=="OperationOutcome" || ${className}=="Conformance" ) ca.uhn.fhir.model.base.resource.Base${className} #{else} BaseResource #{end}
=======
extends #{if}( ${className}=="OperationOutcome" || ${className}=="Conformance" || ${className}=="SecurityEvent" ) ca.uhn.fhir.model.base.resource.Base${className} #{else} BaseResource #{end}
>>>>>>> d22a35788f57e9f7ce64bc8afc2ee7eaf29d94f2
implements IResource {
#foreach ( $param in $searchParams )
/**
* Search parameter constant for <b>${param.name}</b>
* <p>
* Description: <b>${param.description}</b><br/>
* Type: <b>${param.type}</b><br/>
* Path: <b>${param.path}</b><br/>
* </p>
*/
@SearchParamDefinition(name="${param.name}", path="${param.path}", description="${param.description}", type="${param.type}" #{if}($param.compositeOf.empty == false) , compositeOf={ #{foreach}($compositeOf in $param.compositeOf) "${compositeOf}"#{if}($foreach.hasNext), #{end}#{end} } #{end} )
public static final String $param.constantName = "${param.name}";
/**
* <b>Fluent Client</b> search parameter constant for <b>${param.name}</b>
* <p>
* Description: <b>${param.description}</b><br/>
* Type: <b>${param.type}</b><br/>
* Path: <b>${param.path}</b><br/>
* </p>
*/
#if( ${param.typeCapitalized} == 'Composite' )
public static final CompositeClientParam<${param.compositeTypes[0]}ClientParam, ${param.compositeTypes[1]}ClientParam> ${param.fluentConstantName} = new CompositeClientParam<${param.compositeTypes[0]}ClientParam, ${param.compositeTypes[1]}ClientParam>(${param.constantName});
#else
public static final ${param.typeCapitalized}ClientParam ${param.fluentConstantName} = new ${param.typeCapitalized}ClientParam(${param.constantName});
#end
#if( ${param.typeCapitalized} == 'Reference' )
#foreach ( $include in $param.paths )
/**
* Constant for fluent queries to be used to add include statements. Specifies
* the path value of "<b>${include.path}</b>".
*/
public static final Include INCLUDE_${include.includeName} = new Include("${include.path}");
#end
#end
#end
#childExtensionFields( $childExtensionTypes )
#childVars( $children )
#childAccessors( $children )
#childResourceBlocks($resourceBlockChildren)
#childExtensionTypes( $childExtensionTypes )
}