From 4ca405a8fcb7abc4c1d109dd50894e1d234e2487 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 19 Dec 2014 09:14:40 -0500 Subject: [PATCH] Unit tests all pass again, elements in baseresouerce reordered --- .../uhn/fhir/model/api/IFhirVersion.java.orig | 53 --- .../model/base/resource/BaseConformance.java | 1 - .../java/ca/uhn/fhir/parser/XmlParser.java | 25 +- .../org.eclipse.wst.common.component | 2 +- hapi-fhir-structures-dev/.classpath | 2 +- .../org.eclipse.core.resources.prefs | 1 + .../validation/ResourceValidatorTest.java | 35 +- .../uhn/fhir/model/dstu/FhirDstu1.java.orig | 369 ------------------ .../java/ca/uhn/fhir/model/dev/FhirDev.java | 6 + .../ca/uhn/fhir/model/dstu/FhirDstu1.java | 5 + .../src/main/resources/vm/resource.vm.orig | 95 ----- .../main/resources/vm/resource_dstu.vm.orig | 94 ----- 12 files changed, 61 insertions(+), 627 deletions(-) delete mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java.orig delete mode 100644 hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java.orig delete mode 100644 hapi-tinder-plugin/src/main/resources/vm/resource.vm.orig delete mode 100644 hapi-tinder-plugin/src/main/resources/vm/resource_dstu.vm.orig diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java.orig b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java.orig deleted file mode 100644 index 8074b931420..00000000000 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IFhirVersion.java.orig +++ /dev/null @@ -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 -} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/resource/BaseConformance.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/resource/BaseConformance.java index 1ee8a06faa2..223deb11f01 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/resource/BaseConformance.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/base/resource/BaseConformance.java @@ -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") diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java index 143ac05abb1..3acd1668a2c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java @@ -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 preExtensionChildren = new ArrayList(); + List postExtensionChildren = new ArrayList(); + List 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, diff --git a/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component b/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component index 7de896f5cce..1121f094025 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component +++ b/hapi-fhir-jpaserver-uhnfhirtest/.settings/org.eclipse.wst.common.component @@ -15,7 +15,7 @@ uses - + consumes diff --git a/hapi-fhir-structures-dev/.classpath b/hapi-fhir-structures-dev/.classpath index 6ab4f68bc72..d2749946b4c 100644 --- a/hapi-fhir-structures-dev/.classpath +++ b/hapi-fhir-structures-dev/.classpath @@ -15,7 +15,7 @@ - + diff --git a/hapi-fhir-structures-dev/.settings/org.eclipse.core.resources.prefs b/hapi-fhir-structures-dev/.settings/org.eclipse.core.resources.prefs index a16325fe5a1..e35473ebaf9 100644 --- a/hapi-fhir-structures-dev/.settings/org.eclipse.core.resources.prefs +++ b/hapi-fhir-structures-dev/.settings/org.eclipse.core.resources.prefs @@ -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 diff --git a/hapi-fhir-structures-dev/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java b/hapi-fhir-structures-dev/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java index c01572e5c2c..a73cacbfbbf 100644 --- a/hapi-fhir-structures-dev/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java +++ b/hapi-fhir-structures-dev/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java @@ -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() { diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java.orig b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java.orig deleted file mode 100644 index f2b8c6e1042..00000000000 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java.orig +++ /dev/null @@ -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 myExtensionDefToCode = new HashMap(); - private String myId; - - @Override - public Object createServerConformanceProvider(RestfulServer theServer) { - return new ServerConformanceProvider(theServer); - } - - private void fillBasics(StructureElement theElement, BaseRuntimeElementDefinition def, LinkedList 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 path, List 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 next : rr.getResourceTypes()) { - StructureElementDefinitionType type = elem.getDefinition().addType(); - type.getCode().setValue("ResourceReference"); - - if (next != IResource.class) { -<<<<<<< HEAD - @SuppressWarnings("unchecked") - RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType((Class) 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 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 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()); - Collections.sort(retVal.getExtensionDefn(), new Comparator() { - @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 path = new LinkedList(); - - 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 scanForExtensions(Profile theProfile, BaseRuntimeElementDefinition def, Map 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; - } - - - - -} diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java index da728c77000..199a5e98748 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dev/FhirDev.java @@ -84,4 +84,10 @@ public class FhirDev implements IFhirVersion { return str; } + @Override + public String getPathToSchemaDefinitions() { + return "ca/uhn/fhir/model/dev/schema"; + } + + } diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index ae122eb1c1b..1c379803917 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -358,6 +358,11 @@ public class FhirDstu1 implements IFhirVersion { return str; } + @Override + public String getPathToSchemaDefinitions() { + return "ca/uhn/fhir/model/dstu/schema"; + } + diff --git a/hapi-tinder-plugin/src/main/resources/vm/resource.vm.orig b/hapi-tinder-plugin/src/main/resources/vm/resource.vm.orig deleted file mode 100644 index b269955bab7..00000000000 --- a/hapi-tinder-plugin/src/main/resources/vm/resource.vm.orig +++ /dev/null @@ -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 ${elementName} Resource - * (${shortName}) - * - *

- * Definition: - * ${definition} - *

- * - *

- * Requirements: - * ${requirements} - *

- * -#if (${profile} != "") - *

- * Profile Definition: - * ${profile} - *

- * -#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 ${param.name} - *

- * Description: ${param.description}
- * Type: ${param.type}
- * Path: ${param.path}
- *

- */ - @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}"; - - /** - * Fluent Client search parameter constant for ${param.name} - *

- * Description: ${param.description}
- * Type: ${param.type}
- * Path: ${param.path}
- *

- */ -#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 "${include.path}". - */ - public static final Include INCLUDE_${include.includeName} = new Include("${include.path}"); - -#end -#end -#end - -#childExtensionFields( $childExtensionTypes ) -#childVars( $children ) -#childAccessors( $children ) -#childResourceBlocks($resourceBlockChildren) - -#childExtensionTypes( $childExtensionTypes ) - -} \ No newline at end of file diff --git a/hapi-tinder-plugin/src/main/resources/vm/resource_dstu.vm.orig b/hapi-tinder-plugin/src/main/resources/vm/resource_dstu.vm.orig deleted file mode 100644 index c701fbf0c13..00000000000 --- a/hapi-tinder-plugin/src/main/resources/vm/resource_dstu.vm.orig +++ /dev/null @@ -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 ${elementName} Resource - * (${shortName}) - * - *

- * Definition: - * ${definition} - *

- * - *

- * Requirements: - * ${requirements} - *

- * -#if (${profile} != "") - *

- * Profile Definition: - * ${profile} - *

- * -#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 ${param.name} - *

- * Description: ${param.description}
- * Type: ${param.type}
- * Path: ${param.path}
- *

- */ - @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}"; - - /** - * Fluent Client search parameter constant for ${param.name} - *

- * Description: ${param.description}
- * Type: ${param.type}
- * Path: ${param.path}
- *

- */ -#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 "${include.path}". - */ - public static final Include INCLUDE_${include.includeName} = new Include("${include.path}"); - -#end -#end -#end - -#childExtensionFields( $childExtensionTypes ) -#childVars( $children ) -#childAccessors( $children ) -#childResourceBlocks($resourceBlockChildren) - -#childExtensionTypes( $childExtensionTypes ) - -} \ No newline at end of file