Fix structuredefinition regression

This commit is contained in:
James 2016-11-14 12:04:56 -05:00
parent 8676489792
commit 6314f5efb3
9 changed files with 167 additions and 19 deletions

View File

@ -100,6 +100,7 @@ import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse; import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus;
@ -675,6 +676,23 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
} }
} }
@Test
public void testMetadataSuperParamsAreIncluded() throws IOException {
StructureDefinition p = new StructureDefinition();
p.setAbstract(true);
p.setUrl("http://example.com/foo");
IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless();
Bundle resp = ourClient
.search()
.forResource(StructureDefinition.class)
.where(StructureDefinition.URL.matches().value("http://example.com/foo"))
.returnBundle(Bundle.class)
.execute();
assertEquals(1, resp.getTotal());
}
@Test @Test
public void testDeleteResourceConditional1() throws IOException { public void testDeleteResourceConditional1() throws IOException {
String methodName = "testDeleteResourceConditional1"; String methodName = "testDeleteResourceConditional1";

View File

@ -31,32 +31,32 @@
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu</artifactId> <artifactId>hapi-fhir-structures-dstu</artifactId>
<version>1.5</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2</artifactId> <artifactId>hapi-fhir-structures-dstu2</artifactId>
<version>1.5</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu3</artifactId> <artifactId>hapi-fhir-structures-dstu3</artifactId>
<version>1.5</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId> <artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
<version>1.5</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu2</artifactId> <artifactId>hapi-fhir-validation-resources-dstu2</artifactId>
<version>1.5</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId> <artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
<version>2.2-SNAPSHOT</version> <version>2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.velocity</groupId> <groupId>org.apache.velocity</groupId>

View File

@ -7,6 +7,8 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.TreeSet; import java.util.TreeSet;
@ -29,6 +31,7 @@ import org.apache.velocity.tools.generic.EscapeTool;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser; import ca.uhn.fhir.tinder.parser.BaseStructureSpreadsheetParser;
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingModel;
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet; import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
@Mojo(name = "generate-jparest-server", defaultPhase = LifecyclePhase.GENERATE_SOURCES) @Mojo(name = "generate-jparest-server", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
@ -137,7 +140,7 @@ public class TinderJpaRestServerMojo extends AbstractMojo {
File packageDirectoryBase = new File(targetDirectory, packageBase.replace(".", File.separatorChar + "")); File packageDirectoryBase = new File(targetDirectory, packageBase.replace(".", File.separatorChar + ""));
packageDirectoryBase.mkdirs(); packageDirectoryBase.mkdirs();
ResourceGeneratorUsingSpreadsheet gen = new ResourceGeneratorUsingSpreadsheet(version, baseDir); ResourceGeneratorUsingModel gen = new ResourceGeneratorUsingModel(version, baseDir);
gen.setBaseResourceNames(baseResourceNames); gen.setBaseResourceNames(baseResourceNames);
try { try {
@ -236,7 +239,7 @@ public class TinderJpaRestServerMojo extends AbstractMojo {
mojo.version = "dstu3"; mojo.version = "dstu3";
mojo.packageBase = "ca.uhn.test"; mojo.packageBase = "ca.uhn.test";
mojo.configPackageBase = "ca.uhn.test"; mojo.configPackageBase = "ca.uhn.test";
// mojo.baseResourceNames = new ArrayList<String>(Collections.singletonList("observation")); mojo.baseResourceNames = new ArrayList<String>(Arrays.asList("structuredefinition", "observation"));
mojo.targetDirectory = new File("target/generated/valuesets"); mojo.targetDirectory = new File("target/generated/valuesets");
mojo.targetResourceDirectory = new File("target/generated/valuesets"); mojo.targetResourceDirectory = new File("target/generated/valuesets");
mojo.targetResourceSpringBeansFile = "tmp_beans.xml"; mojo.targetResourceSpringBeansFile = "tmp_beans.xml";

View File

@ -56,7 +56,7 @@ public abstract class BaseRootType extends BaseElement {
return retVal; return retVal;
} }
public void addSearchParameter(String theVersion, SearchParameter theParam) { public void addSearchParameter(SearchParameter theParam) {
getSearchParameters(); getSearchParameters();
mySearchParameters.add(theParam); mySearchParameters.add(theParam);

View File

@ -32,6 +32,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
@ -66,11 +67,24 @@ public abstract class BaseStructureParser {
protected List<BaseRootType> myResources = new ArrayList<BaseRootType>(); protected List<BaseRootType> myResources = new ArrayList<BaseRootType>();
private String myVersion; private String myVersion;
private boolean myIsRi; private boolean myIsRi;
private FhirContext myCtx;
public BaseStructureParser(String theVersion, String theBaseDir) { public BaseStructureParser(String theVersion, String theBaseDir) {
myVersion = theVersion; myVersion = theVersion;
myBaseDir = theBaseDir; myBaseDir = theBaseDir;
myIsRi = myVersion.equals("dstu3"); myIsRi = myVersion.equals("dstu3");
if (myVersion.equals("dstu3")) {
myCtx = FhirContext.forDstu3();
} else if (myVersion.equals("dstu2")) {
myCtx = FhirContext.forDstu2();
} else if (myVersion.equals("dstu")) {
myCtx = FhirContext.forDstu1();
}
}
public FhirContext getCtx() {
return myCtx;
} }
public String getVersion() { public String getVersion() {
@ -175,7 +189,7 @@ public abstract class BaseStructureParser {
} }
protected abstract String getTemplate(); protected abstract String getTemplate();
protected abstract File getTemplateFile(); protected abstract File getTemplateFile();
protected boolean isSpreadsheet(String theFileName) { protected boolean isSpreadsheet(String theFileName) {
@ -228,7 +242,7 @@ public abstract class BaseStructureParser {
// not found // not found
} }
} }
try { try {
return Class.forName("org.hl7.fhir.dstu3.model." + unqualifiedTypeName).getName(); return Class.forName("org.hl7.fhir.dstu3.model." + unqualifiedTypeName).getName();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
@ -447,7 +461,7 @@ public abstract class BaseStructureParser {
if (determineVersionEnum().isRi()) { if (determineVersionEnum().isRi()) {
packageSuffix = "." + myVersion; packageSuffix = "." + myVersion;
} }
VelocityContext ctx = new VelocityContext(); VelocityContext ctx = new VelocityContext();
ctx.put("includeDescriptionAnnotations", true); ctx.put("includeDescriptionAnnotations", true);
ctx.put("packageBase", thePackageBase); ctx.put("packageBase", thePackageBase);
@ -489,8 +503,7 @@ public abstract class BaseStructureParser {
v.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); v.setProperty("cp.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
v.setProperty("runtime.references.strict", Boolean.TRUE); v.setProperty("runtime.references.strict", Boolean.TRUE);
InputStream templateIs = InputStream templateIs = getTemplateFile() != null
getTemplateFile() != null
? new FileInputStream(getTemplateFile()) ? new FileInputStream(getTemplateFile())
: ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream(getTemplate()); : ResourceGeneratorUsingSpreadsheet.class.getResourceAsStream(getTemplate());
InputStreamReader templateReader = new InputStreamReader(templateIs); InputStreamReader templateReader = new InputStreamReader(templateIs);
@ -573,7 +586,7 @@ public abstract class BaseStructureParser {
myNameToDatatypeClass.put("boundCode", BoundCodeDt.class.getName()); myNameToDatatypeClass.put("boundCode", BoundCodeDt.class.getName());
myNameToDatatypeClass.put("boundCodeableConcept", ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt.class.getName()); myNameToDatatypeClass.put("boundCodeableConcept", ca.uhn.fhir.model.dstu2.composite.BoundCodeableConceptDt.class.getName());
} }
try { try {
File versionFile = new File(theResourceOutputDirectory, "fhirversion.properties"); File versionFile = new File(theResourceOutputDirectory, "fhirversion.properties");
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(versionFile, false), "UTF-8"); OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(versionFile, false), "UTF-8");
@ -584,7 +597,7 @@ public abstract class BaseStructureParser {
if (determineVersionEnum().isRi()) { if (determineVersionEnum().isRi()) {
packageSuffix = "." + myVersion; packageSuffix = "." + myVersion;
} }
VelocityContext ctx = new VelocityContext(); VelocityContext ctx = new VelocityContext();
ctx.put("nameToResourceClass", myNameToResourceClass); ctx.put("nameToResourceClass", myNameToResourceClass);
ctx.put("nameToDatatypeClass", myNameToDatatypeClass); ctx.put("nameToDatatypeClass", myNameToDatatypeClass);

View File

@ -317,7 +317,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
if (sp.getType().equals("composite")) { if (sp.getType().equals("composite")) {
compositeParams.add(sp); compositeParams.add(sp);
} else { } else {
theResource.addSearchParameter(getVersion(), sp); theResource.addSearchParameter(sp);
} }
} }
@ -397,7 +397,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
for (SearchParameter part1 : compositeOf.get(0)) { for (SearchParameter part1 : compositeOf.get(0)) {
for (SearchParameter part2 : compositeOf.get(1)) { for (SearchParameter part2 : compositeOf.get(1)) {
SearchParameter composite = new SearchParameter(getVersion(), theResource.getName()); SearchParameter composite = new SearchParameter(getVersion(), theResource.getName());
theResource.addSearchParameter(getVersion(), composite); theResource.addSearchParameter(composite);
composite.setName(part1.getName() + "-" + part2.getName()); composite.setName(part1.getName() + "-" + part2.getName());
composite.setDescription(nextCompositeParam.getDescription()); composite.setDescription(nextCompositeParam.getDescription());
composite.setPath(nextCompositeParam.getPath()); composite.setPath(nextCompositeParam.getPath());

View File

@ -159,7 +159,7 @@ public class ProfileParser extends BaseStructureParser {
param.setType(nextParam.getType().getValue()); param.setType(nextParam.getType().getValue());
param.setDescription(nextParam.getDocumentation().getValue()); param.setDescription(nextParam.getDocumentation().getValue());
retVal.addSearchParameter(getVersion(), param); retVal.addSearchParameter(param);
} }
addResource(retVal); addResource(retVal);

View File

@ -0,0 +1,107 @@
package ca.uhn.fhir.tinder.parser;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.WordUtils;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.tinder.model.Resource;
import ca.uhn.fhir.tinder.model.SearchParameter;
public class ResourceGeneratorUsingModel extends BaseStructureParser {
private String myFilenameSuffix;
private String myTemplate;
private File myTemplateFile;
private Collection<String> myResourceNames;
public ResourceGeneratorUsingModel(String theVersion, String theBaseDir) {
super(theVersion, theBaseDir);
}
@Override
protected String getFilenameSuffix() {
return myFilenameSuffix;
}
@Override
protected String getTemplate() {
return myTemplate;
}
@Override
protected File getTemplateFile() {
return myTemplateFile;
}
public void setFilenameSuffix(String theFilenameSuffix) {
myFilenameSuffix = theFilenameSuffix;
}
public void setTemplate(String theTemplate) {
myTemplate = theTemplate;
}
public void setTemplateFile(File theTemplateFile) {
myTemplateFile = theTemplateFile;
}
public void setBaseResourceNames(List<String> theBaseResourceNames) {
myResourceNames = theBaseResourceNames;
}
public void parse() {
for (String nextResourceName : myResourceNames) {
RuntimeResourceDefinition def = getCtx().getResourceDefinition(nextResourceName);
Resource resource = new Resource();
resource.setName(def.getName());
resource.setElementName(def.getName());
addResource(resource);
for (RuntimeSearchParam nextSearchParam : def.getSearchParams()) {
SearchParameter param = new SearchParameter(getVersion(), def.getName());
param.setName(nextSearchParam.getName());
param.setDescription(nextSearchParam.getDescription());
param.setCompositeOf(toCompositeOfStrings(nextSearchParam.getCompositeOf()));
param.setCompositeTypes(toCompositeOfTypes(nextSearchParam.getCompositeOf()));
param.setPath(nextSearchParam.getPath());
param.setType(nextSearchParam.getParamType().getCode());
resource.addSearchParameter(param);
}
}
}
private List<String> toCompositeOfStrings(List<RuntimeSearchParam> theCompositeOf) {
if (theCompositeOf == null) {
return null;
}
ArrayList<String> retVal = new ArrayList<String>();
for (RuntimeSearchParam next : theCompositeOf) {
retVal.add(next.getName());
}
return retVal;
}
private List<String> toCompositeOfTypes(List<RuntimeSearchParam> theCompositeOf) {
if (theCompositeOf == null) {
return null;
}
ArrayList<String> retVal = new ArrayList<String>();
for (RuntimeSearchParam next : theCompositeOf) {
String type = next.getParamType().getCode();
type = WordUtils.capitalize(type);
retVal.add(type);
}
return retVal;
}
}

View File

@ -12,6 +12,13 @@
transactions are blocked even when they transactions are blocked even when they
should not be should not be
</action> </action>
<action type="fix">
Fix regression in HAPI FHIR 2.1 JPA
server where some search parameters on
metadata resources did not appear
(e.g. "StructureDefinition.url"). Thanks
to David Hay for reporting!
</action>
<release version="2.1" date="2016-11-11"> <release version="2.1" date="2016-11-11">
<action type="add"> <action type="add">
STU3 structure definitions have been updated to the STU3 structure definitions have been updated to the