From 67aee59f0f3206e23997a9f74865a4d4d1323137 Mon Sep 17 00:00:00 2001 From: Bill Denton Date: Fri, 9 Dec 2016 17:04:01 -0800 Subject: [PATCH] allow templates access to resource-block referenced by a block-copy --- .../fhir/tinder/model/ResourceBlockCopy.java | 12 ++++++++++ .../BaseStructureSpreadsheetParser.java | 22 +++++++++++++++++++ hapi-tinder-test/pom.xml | 2 ++ .../test/resources/macros/dump_templates.vm | 1 + 4 files changed, 37 insertions(+) diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ResourceBlockCopy.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ResourceBlockCopy.java index d3eff544e12..c1fd2b4dc93 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ResourceBlockCopy.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/model/ResourceBlockCopy.java @@ -2,5 +2,17 @@ package ca.uhn.fhir.tinder.model; public class ResourceBlockCopy extends Child { + private ResourceBlock referencedBlock = null; + @Override + public boolean isBlockRef() { + return referencedBlock != null; + } + + public ResourceBlock getReferencedBlock () { + return this.referencedBlock; + } + public void setReferencedBlock (ResourceBlock referencedBlock) { + this.referencedBlock = referencedBlock; + } } diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java index b85c934df1a..331e6e53cf7 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java @@ -127,6 +127,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser // HashMap(); Map> pathToResourceTypes = new HashMap>(); + List blockCopies = new ArrayList(); for (int i = 2; i < rows.getLength(); i++) { Element nextRow = (Element) rows.item(i); String name = cellValue(nextRow, 0); @@ -152,6 +153,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser } else if (type.startsWith("@")) { // type = type.substring(type.lastIndexOf('.')+1); elem = new ResourceBlockCopy(); + blockCopies.add(elem); } else if (type.equals("*")) { elem = new AnyChild(); } else { @@ -198,6 +200,26 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser // } // } + // resolve BlockCopy elements so they can access + // the children of the referenced ResourceBlock + // from Velocity templates. + for (Child blockCopy : blockCopies) { + BaseElement element = blockCopy; + refLoop: + while (element.getElementParentName() != null) { + BaseElement parent = elements.get(element.getElementParentName()); + List children = parent.getChildren(); + for (BaseElement child : children) { + if (!child.equals(blockCopy) && child instanceof ResourceBlock + && child.getElementName().equals(blockCopy.getElementName())) { + ((ResourceBlockCopy)blockCopy).setReferencedBlock((ResourceBlock)child); + break refLoop; + } + } + element = parent; + } + } + index++; } diff --git a/hapi-tinder-test/pom.xml b/hapi-tinder-test/pom.xml index f7367e5410b..20234a35539 100644 --- a/hapi-tinder-test/pom.xml +++ b/hapi-tinder-test/pom.xml @@ -136,6 +136,8 @@ patient organization + bundle + composition diff --git a/hapi-tinder-test/src/test/resources/macros/dump_templates.vm b/hapi-tinder-test/src/test/resources/macros/dump_templates.vm index e924687c2d1..b282a0867d6 100644 --- a/hapi-tinder-test/src/test/resources/macros/dump_templates.vm +++ b/hapi-tinder-test/src/test/resources/macros/dump_templates.vm @@ -45,6 +45,7 @@ ${lead} referenceTypesForMultiple: $!{child.referenceTypesForMultiple} ${lead} singleType: $!{child.singleType} ${lead} variableName: $!{child.variableName} ${lead} isBlock: $!{child.block} +${lead} isBlockRef: $!{child.blockRef} ${lead} isPrimitive: $!{child.primitive} ${lead} primitiveType: #{if}(${child.primitive})$!{child.primitiveType}#{end} . ${lead} isBoundCode: $!{child.boundCode}