mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-09 14:31:17 +00:00
more work on PE
This commit is contained in:
parent
ead7eadfc0
commit
50bc157ab9
@ -105,6 +105,7 @@ import org.hl7.fhir.r5.model.Bundle.HTTPVerb;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent;
|
||||
import org.hl7.fhir.r5.profilemodel.PEDefinition;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder;
|
||||
import org.hl7.fhir.r5.renderers.OperationOutcomeRenderer;
|
||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities;
|
||||
@ -2391,7 +2392,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
|
||||
|
||||
|
||||
@Override
|
||||
public PEBuilder getProfiledElementBuilder(boolean elementProps) {
|
||||
public PEBuilder getProfiledElementBuilder(PEElementPropertiesPolicy elementProps) {
|
||||
// TODO Auto-generated method stub
|
||||
return new PEBuilder(this, elementProps);
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ import org.hl7.fhir.r5.model.StructureMap;
|
||||
import org.hl7.fhir.r5.model.ValueSet;
|
||||
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
|
||||
import org.hl7.fhir.r5.profilemodel.PEDefinition;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder;
|
||||
import org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass;
|
||||
import org.hl7.fhir.r5.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
|
||||
@ -803,6 +804,6 @@ public interface IWorkerContext {
|
||||
|
||||
public String getSpecUrl();
|
||||
|
||||
public PEBuilder getProfiledElementBuilder(boolean elementProps);
|
||||
public PEBuilder getProfiledElementBuilder(PEElementPropertiesPolicy elementProps);
|
||||
|
||||
}
|
@ -9,12 +9,15 @@ import org.hl7.fhir.r5.conformance.profile.ProfileUtilities;
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.DiscriminatorType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.SlicingRules;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
import org.hl7.fhir.r5.model.ResourceFactory;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
/**
|
||||
@ -70,15 +73,20 @@ import org.hl7.fhir.utilities.Utilities;
|
||||
*/
|
||||
public class PEBuilder {
|
||||
|
||||
|
||||
public enum PEElementPropertiesPolicy {
|
||||
NONE, EXTENSION, EXTENSION_ID
|
||||
}
|
||||
|
||||
private IWorkerContext context;
|
||||
private ProfileUtilities pu;
|
||||
private boolean elementProps;
|
||||
private PEElementPropertiesPolicy elementProps;
|
||||
|
||||
/**
|
||||
* @param context - must be loaded with R5 definitions
|
||||
* @param elementProps - whether to include Element.id and Element.extension in the tree
|
||||
* @param elementProps - whether to include Element.id and Element.extension in the tree. Recommended choice: Extension
|
||||
*/
|
||||
public PEBuilder(IWorkerContext context, boolean elementProps) {
|
||||
public PEBuilder(IWorkerContext context, PEElementPropertiesPolicy elementProps) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.elementProps = elementProps;
|
||||
@ -104,6 +112,9 @@ public class PEBuilder {
|
||||
if (profile == null) {
|
||||
throw new DefinitionException("Unable to find profile for URL '"+url+"'");
|
||||
}
|
||||
if (!profile.hasSnapshot()) {
|
||||
throw new DefinitionException("Profile '"+url+"' does not have a snapshot");
|
||||
}
|
||||
StructureDefinition base = context.fetchTypeDefinition(profile.getType());
|
||||
if (base == null) {
|
||||
throw new DefinitionException("Unable to find base type '"+profile.getType()+"' for URL '"+url+"'");
|
||||
@ -130,6 +141,9 @@ public class PEBuilder {
|
||||
if (profile == null) {
|
||||
throw new DefinitionException("Unable to find profile for URL '"+url+"'");
|
||||
}
|
||||
if (!profile.hasSnapshot()) {
|
||||
throw new DefinitionException("Profile '"+url+"' does not have a snapshot");
|
||||
}
|
||||
StructureDefinition base = context.fetchTypeDefinition(profile.getType());
|
||||
if (base == null) {
|
||||
throw new DefinitionException("Unable to find base type '"+profile.getType()+"' for URL '"+url+"'");
|
||||
@ -203,7 +217,7 @@ public class PEBuilder {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<PEDefinition> listChildren(StructureDefinition baseStructure, ElementDefinition baseDefinition, StructureDefinition profileStructure, ElementDefinition profileDefinition, String url) {
|
||||
protected List<PEDefinition> listChildren(StructureDefinition baseStructure, ElementDefinition baseDefinition, StructureDefinition profileStructure, ElementDefinition profileDefinition, String url, String... omitList) {
|
||||
StructureDefinition profile = profileStructure;
|
||||
List<ElementDefinition> list = pu.getChildList(profile, profileDefinition);
|
||||
if (profileDefinition.getType().size() == 1 || (!profileDefinition.getPath().contains(".")) || list.isEmpty()) {
|
||||
@ -223,31 +237,37 @@ public class PEBuilder {
|
||||
int i = 0;
|
||||
while (i < list.size()) {
|
||||
ElementDefinition defn = list.get(i);
|
||||
ElementDefinition bdefn = getByName(blist, defn);
|
||||
if (bdefn == null) {
|
||||
throw new Error("no base definition for "+defn.getId());
|
||||
}
|
||||
if (elementProps || (!Utilities.existsInList(bdefn.getBase().getPath(), "Element.id", "Element.extension"))) {
|
||||
PEDefinitionElement pe = new PEDefinitionElement(this, base, bdefn, profileStructure, defn);
|
||||
pe.setRecursing(profileDefinition == defn || (profile.getDerivation() == TypeDerivationRule.SPECIALIZATION && profile.getType().equals("Extension")));
|
||||
if (defn.hasSlicing()) {
|
||||
if (defn.getSlicing().getRules() != SlicingRules.CLOSED) {
|
||||
res.add(pe);
|
||||
}
|
||||
i++;
|
||||
while (i < list.size() && list.get(i).getPath().equals(defn.getPath())) {
|
||||
StructureDefinition ext = getExtensionDefinition(list.get(i));
|
||||
if (ext != null) {
|
||||
res.add(new PEDefinitionExtension(this, list.get(i).getSliceName(), baseStructure, getByName(blist, defn), profileStructure, list.get(i), defn, ext));
|
||||
} else {
|
||||
res.add(new PEDefinitionSlice(this, list.get(i).getSliceName(), baseStructure, getByName(blist, defn), profileStructure, list.get(i), defn));
|
||||
if (include(defn)) {
|
||||
ElementDefinition bdefn = getByName(blist, defn);
|
||||
if (bdefn == null) {
|
||||
throw new Error("no base definition for "+defn.getId());
|
||||
}
|
||||
if (passElementPropsCheck(bdefn) && !Utilities.existsInList(bdefn.getName(), omitList)) {
|
||||
PEDefinitionElement pe = new PEDefinitionElement(this, base, bdefn, profileStructure, defn);
|
||||
pe.setRecursing(profileDefinition == defn || (profile.getDerivation() == TypeDerivationRule.SPECIALIZATION && profile.getType().equals("Extension")));
|
||||
if (defn.hasSlicing()) {
|
||||
if (defn.getSlicing().getRules() != SlicingRules.CLOSED) {
|
||||
res.add(pe);
|
||||
}
|
||||
i++;
|
||||
while (i < list.size() && list.get(i).getPath().equals(defn.getPath())) {
|
||||
StructureDefinition ext = getExtensionDefinition(list.get(i));
|
||||
if (ext != null) {
|
||||
res.add(new PEDefinitionExtension(this, list.get(i).getSliceName(), baseStructure, getByName(blist, defn), profileStructure, list.get(i), defn, ext));
|
||||
} else if (isTypeSlicing(defn)) {
|
||||
res.add(new PEDefinitionTypeSlice(this, list.get(i).getSliceName(), baseStructure, getByName(blist, defn), profileStructure, list.get(i), defn));
|
||||
} else {
|
||||
res.add(new PEDefinitionSlice(this, list.get(i).getSliceName(), baseStructure, getByName(blist, defn), profileStructure, list.get(i), defn));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
res.add(pe);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
res.add(pe);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
@ -262,6 +282,34 @@ public class PEBuilder {
|
||||
}
|
||||
|
||||
|
||||
private boolean passElementPropsCheck(ElementDefinition bdefn) {
|
||||
switch (elementProps) {
|
||||
case EXTENSION:
|
||||
return !Utilities.existsInList(bdefn.getBase().getPath(), "Element.id");
|
||||
case NONE:
|
||||
return !Utilities.existsInList(bdefn.getBase().getPath(), "Element.id", "Element.extension");
|
||||
case EXTENSION_ID:
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTypeSlicing(ElementDefinition defn) {
|
||||
ElementDefinitionSlicingComponent sl = defn.getSlicing();
|
||||
return sl.getRules() == SlicingRules.CLOSED && sl.getDiscriminator().size() == 1 &&
|
||||
sl.getDiscriminatorFirstRep().getType() == DiscriminatorType.TYPE && "$this".equals(sl.getDiscriminatorFirstRep().getPath());
|
||||
}
|
||||
|
||||
private boolean include(ElementDefinition defn) {
|
||||
if (defn.getMax().equals("0")) {
|
||||
return false;
|
||||
}
|
||||
if (defn.hasFixed() || defn.hasPattern()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected List<PEDefinition> listSlices(StructureDefinition baseStructure, ElementDefinition baseDefinition, StructureDefinition profileStructure, ElementDefinition profileDefinition) {
|
||||
List<ElementDefinition> list = pu.getSliceList(profileStructure, profileDefinition);
|
||||
List<PEDefinition> res = new ArrayList<>();
|
||||
|
@ -91,7 +91,7 @@ public abstract class PEDefinition {
|
||||
* @return the maximum number of repeats allowed
|
||||
*/
|
||||
public int max() {
|
||||
return "*".equals(profiledDefinition.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(profiledDefinition.getMax());
|
||||
return profiledDefinition.getMax() == null || "*".equals(profiledDefinition.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(profiledDefinition.getMax());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,6 +171,12 @@ public abstract class PEDefinition {
|
||||
this.recursing = recursing;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return used in the instance processor to differentiate slices
|
||||
*/
|
||||
public abstract String fhirpath();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,4 +33,9 @@ public class PEDefinitionElement extends PEDefinition {
|
||||
children.addAll(builder.listChildren(baseStructure, baseDefinition, profileStructure, profiledDefinition, typeUrl));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fhirpath() {
|
||||
return baseDefinition.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.SlicingRules;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
|
||||
@ -11,6 +12,8 @@ public class PEDefinitionExtension extends PEDefinition {
|
||||
|
||||
private StructureDefinition extension;
|
||||
private ElementDefinition sliceDefinition;
|
||||
private ElementDefinition eed;
|
||||
private ElementDefinition ved;
|
||||
|
||||
public PEDefinitionExtension(PEBuilder builder, String name,
|
||||
StructureDefinition baseStructure, ElementDefinition baseDefinition,
|
||||
@ -19,12 +22,12 @@ public class PEDefinitionExtension extends PEDefinition {
|
||||
super(builder, name, baseStructure, baseDefinition, profileStructure, profileDefinition);
|
||||
this.sliceDefinition = sliceDefinition;
|
||||
this.extension= extension;
|
||||
eed = extension.getSnapshot().getElementByPath("Extension.extension");
|
||||
ved = extension.getSnapshot().getElementByPath("Extension.value[x]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listTypes(List<PEType> types) {
|
||||
ElementDefinition eed = extension.getSnapshot().getElementByPath("Extension.extension");
|
||||
ElementDefinition ved = extension.getSnapshot().getElementByPath("Extension.value[x]");
|
||||
if (ved.isRequired() || eed.isProhibited()) {
|
||||
for (TypeRefComponent t : ved.getType()) {
|
||||
if (t.hasProfile()) {
|
||||
@ -42,13 +45,23 @@ public class PEDefinitionExtension extends PEDefinition {
|
||||
|
||||
@Override
|
||||
protected void makeChildren(String typeUrl, List<PEDefinition> children) {
|
||||
ElementDefinition eed = extension.getSnapshot().getElementByPath("Extension.extension");
|
||||
ElementDefinition ved = extension.getSnapshot().getElementByPath("Extension.value[x]");
|
||||
if (ved.isRequired() || eed.isProhibited()) {
|
||||
children.addAll(builder.listChildren(extension, ved, extension, ved, typeUrl));
|
||||
} else {
|
||||
if (eed.getSlicing().getRules() != SlicingRules.CLOSED) {
|
||||
children.addAll(builder.listChildren(extension, eed, extension, eed, "http://hl7.org/fhir/StructureDefinition/Extension", "value[x]", "url"));
|
||||
}
|
||||
children.addAll(builder.listSlices(extension, eed, extension, eed));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fhirpath() {
|
||||
if (ved.isRequired() || eed.isProhibited()) {
|
||||
return "extension('"+extension.getUrl()+"').value";
|
||||
} else {
|
||||
return "extension('"+extension.getUrl()+"').extension";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,4 +20,10 @@ public class PEDefinitionResource extends PEDefinition {
|
||||
children.addAll(builder.listChildren(baseStructure, baseDefinition, profileStructure, profiledDefinition, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fhirpath() {
|
||||
return profileStructure.getType();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,10 @@ package org.hl7.fhir.r5.profilemodel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
|
||||
public class PEDefinitionSlice extends PEDefinition {
|
||||
|
||||
@ -18,7 +20,15 @@ public class PEDefinitionSlice extends PEDefinition {
|
||||
|
||||
@Override
|
||||
public void listTypes(List<PEType> types) {
|
||||
throw new Error("Not done yet");
|
||||
for (TypeRefComponent t : profiledDefinition.getType()) {
|
||||
if (t.hasProfile()) {
|
||||
for (CanonicalType u : t.getProfile()) {
|
||||
types.add(builder.makeType(t, u));
|
||||
}
|
||||
} else if (!t.getCode().startsWith("http://hl7.org/fhirpath/")) {
|
||||
types.add(new PEType(t.getWorkingCode(), t.getWorkingCode(), "http://hl7.org/fhir/StructureDefinition/"+t.getWorkingCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,4 +36,9 @@ public class PEDefinitionSlice extends PEDefinition {
|
||||
throw new Error("Not done yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fhirpath() {
|
||||
throw new Error("Not done yet");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,20 +4,26 @@ import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.SlicingRules;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
|
||||
public class PEDefinitionSubExtension extends PEDefinition {
|
||||
|
||||
private ElementDefinition eed;
|
||||
private ElementDefinition ved;
|
||||
private ElementDefinition ued;
|
||||
|
||||
public PEDefinitionSubExtension(PEBuilder builder, StructureDefinition baseStructure, ElementDefinition baseDefinition, StructureDefinition profileStructure, ElementDefinition profileDefinition) {
|
||||
super(builder, profileDefinition.getSliceName(), baseStructure, baseDefinition, profileStructure, profileDefinition);
|
||||
List<ElementDefinition> childDefs = builder.getChildren(profileStructure, profiledDefinition);
|
||||
eed = getElementByName(childDefs, "extension");
|
||||
ved = getElementByName(childDefs, "value[x]");
|
||||
ued = getElementByName(childDefs, "url");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listTypes(List<PEType> types) {
|
||||
List<ElementDefinition> childDefs = builder.getChildren(profileStructure, profiledDefinition);
|
||||
ElementDefinition eed = getElementByName(childDefs, "extension");
|
||||
ElementDefinition ved = getElementByName(childDefs, "value[x]");
|
||||
if (ved.isRequired() || eed.isProhibited()) {
|
||||
for (TypeRefComponent t : ved.getType()) {
|
||||
if (t.hasProfile()) {
|
||||
@ -44,14 +50,23 @@ public class PEDefinitionSubExtension extends PEDefinition {
|
||||
|
||||
@Override
|
||||
protected void makeChildren(String typeUrl, List<PEDefinition> children) {
|
||||
List<ElementDefinition> childDefs = builder.getChildren(profileStructure, profiledDefinition);
|
||||
ElementDefinition eed = getElementByName(childDefs, "extension");
|
||||
ElementDefinition ved = getElementByName(childDefs, "value[x]");
|
||||
if (ved.isRequired() || eed.isProhibited()) {
|
||||
children.addAll(builder.listChildren(baseStructure, baseDefinition, profileStructure, ved, typeUrl));
|
||||
} else {
|
||||
if (eed.getSlicing().getRules() != SlicingRules.CLOSED) {
|
||||
children.addAll(builder.listChildren(baseStructure, baseDefinition, profileStructure, eed, "http://hl7.org/fhir/StructureDefinition/Extension", "value[x]", "url"));
|
||||
}
|
||||
children.addAll(builder.listSlices(baseStructure, baseDefinition, profileStructure, eed));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fhirpath() {
|
||||
if (ved.isRequired() || eed.isProhibited()) {
|
||||
return "extension('"+ued.getFixed().primitiveValue()+"').value";
|
||||
} else {
|
||||
return "extension('"+ued.getFixed().primitiveValue()+"').extension";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package org.hl7.fhir.r5.profilemodel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r5.model.CanonicalType;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition;
|
||||
import org.hl7.fhir.r5.model.StructureDefinition;
|
||||
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
|
||||
|
||||
public class PEDefinitionTypeSlice extends PEDefinition {
|
||||
|
||||
protected ElementDefinition sliceDefinition;
|
||||
|
||||
public PEDefinitionTypeSlice(PEBuilder builder, String name, StructureDefinition baseStructure,
|
||||
ElementDefinition baseDefinition, StructureDefinition profileStructure, ElementDefinition profileDefinition,
|
||||
ElementDefinition sliceDefinition) {
|
||||
super(builder, name, baseStructure, baseDefinition, profileStructure, profileDefinition);
|
||||
this.sliceDefinition = sliceDefinition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listTypes(List<PEType> types) {
|
||||
for (TypeRefComponent t : profiledDefinition.getType()) {
|
||||
if (t.hasProfile()) {
|
||||
for (CanonicalType u : t.getProfile()) {
|
||||
types.add(builder.makeType(t, u));
|
||||
}
|
||||
} else if (!t.getCode().startsWith("http://hl7.org/fhirpath/")) {
|
||||
types.add(new PEType(t.getWorkingCode(), t.getWorkingCode(), "http://hl7.org/fhir/StructureDefinition/"+t.getWorkingCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void makeChildren(String typeUrl, List<PEDefinition> children) {
|
||||
children.addAll(builder.listChildren(baseStructure, baseDefinition, profileStructure, profiledDefinition, typeUrl));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fhirpath() {
|
||||
throw new Error("Not done yet");
|
||||
}
|
||||
|
||||
}
|
@ -4,9 +4,12 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.formats.JsonParser;
|
||||
import org.hl7.fhir.r5.model.Resource;
|
||||
import org.hl7.fhir.r5.profilemodel.PEDefinition;
|
||||
import org.hl7.fhir.r5.profilemodel.PEType;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder;
|
||||
import org.hl7.fhir.r5.profilemodel.PEBuilder.PEElementPropertiesPolicy;
|
||||
import org.hl7.fhir.r5.test.utils.TestPackageLoader;
|
||||
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
|
||||
@ -14,7 +17,7 @@ import org.hl7.fhir.utilities.npm.NpmPackage;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ProfiledElementTests {
|
||||
public class PETests {
|
||||
|
||||
|
||||
private IWorkerContext ctxt;
|
||||
@ -26,15 +29,83 @@ public class ProfiledElementTests {
|
||||
FilesystemPackageCacheManager pc = new FilesystemPackageCacheManager(true);
|
||||
NpmPackage npm = pc.loadPackage("hl7.fhir.us.core", "5.0.0");
|
||||
ctxt.loadFromPackage(npm, new TestPackageLoader(new String[] { "StructureDefinition" }));
|
||||
|
||||
ctxt.cacheResource(new JsonParser().parse(TestingUtilities.loadTestResource("R5", "profiles", "pe-extension-simple.json")));
|
||||
ctxt.cacheResource(new JsonParser().parse(TestingUtilities.loadTestResource("R5", "profiles", "pe-extension-complex.json")));
|
||||
// ctxt.cacheResource(new JsonParser().parse(TestingUtilities.loadTestResource("R5", "profiles", "pe-profile2.json")));
|
||||
ctxt.cacheResource(new JsonParser().parse(TestingUtilities.loadTestResource("R5", "profiles", "pe-profile1.json")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testProfile() throws IOException {
|
||||
load();
|
||||
PEDefinition pe = new PEBuilder(ctxt, PEElementPropertiesPolicy.EXTENSION).buildPEDefinition("http://hl7.org/fhir/test/StructureDefinition/pe-profile1");
|
||||
|
||||
Assertions.assertEquals("TestProfile", pe.name());
|
||||
Assertions.assertEquals("Observation", pe.schemaName());
|
||||
Assertions.assertEquals(0, pe.min());
|
||||
Assertions.assertEquals(Integer.MAX_VALUE, pe.max());
|
||||
Assertions.assertEquals("Observation", pe.types().get(0).getType());
|
||||
Assertions.assertEquals("TestProfile", pe.types().get(0).getName());
|
||||
Assertions.assertNotNull(pe.definition());
|
||||
Assertions.assertNotNull(pe.baseDefinition());
|
||||
Assertions.assertEquals("Test Observation Profile", pe.shortDocumentation());
|
||||
Assertions.assertEquals("Test Observation Profile.", pe.documentation());
|
||||
|
||||
|
||||
List<PEDefinition> children = pe.children("Observation");
|
||||
|
||||
checkElement(pe, "Observation", "TestProfile", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/test/StructureDefinition/pe-profile1", 16);
|
||||
checkElement(children.get(0), "id", "id", 0, 1, null, 0);
|
||||
checkElement(children.get(1), "meta", "meta", 0, 1, "http://hl7.org/fhir/StructureDefinition/Meta", 7);
|
||||
checkElement(children.get(2), "language", "language", 0, 1, "http://hl7.org/fhir/StructureDefinition/code", 2);
|
||||
checkElement(children.get(3), "text", "text", 0, 1, "http://hl7.org/fhir/StructureDefinition/Narrative", 3);
|
||||
checkElement(children.get(4), "contained", "contained", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/Resource", 4);
|
||||
checkElement(children.get(5), "extension", "extension", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/Extension", 3);
|
||||
checkElement(children.get(6), "extension", "simple", 0, 1, "http://hl7.org/fhir/StructureDefinition/code", 2);
|
||||
checkElement(children.get(7), "extension", "complex", 0, 1, "http://hl7.org/fhir/StructureDefinition/Extension", 4);
|
||||
checkElement(children.get(8), "identifier", "identifier", 0, 1, "http://hl7.org/fhir/StructureDefinition/Identifier", 7);
|
||||
checkElement(children.get(9), "category", "category", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/CodeableConcept", 3);
|
||||
checkElement(children.get(10), "subject", "subject", 1, 1, "http://hl7.org/fhir/StructureDefinition/Reference", 5);
|
||||
checkElement(children.get(11), "encounter", "encounter", 0, 1, "http://hl7.org/fhir/StructureDefinition/Reference", 5);
|
||||
checkElement(children.get(12), "effective[x]", "effective[x]", 1, 1, "http://hl7.org/fhir/StructureDefinition/dateTime", 2);
|
||||
checkElement(children.get(13), "issued", "issued", 0, 1, "http://hl7.org/fhir/StructureDefinition/instant", 2);
|
||||
checkElement(children.get(14), "performer", "performer", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/Reference", 5);
|
||||
checkElement(children.get(15), "value[x]", "valueCodeableConcept", 0, 1, "http://hl7.org/fhir/StructureDefinition/CodeableConcept", 3);
|
||||
|
||||
List<PEDefinition> gchildren = children.get(7).children("http://hl7.org/fhir/StructureDefinition/Extension");
|
||||
checkElement(gchildren.get(0), "extension", "extension", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/Extension", 3);
|
||||
checkElement(gchildren.get(1), "extension", "slice1", 0, 2, "http://hl7.org/fhir/StructureDefinition/Coding", 6);
|
||||
checkElement(gchildren.get(2), "extension", "slice2", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/string", 2);
|
||||
checkElement(gchildren.get(3), "extension", "slice3", 1, 1, "http://hl7.org/fhir/StructureDefinition/Extension", 3);
|
||||
|
||||
List<PEDefinition> ggchildren = gchildren.get(3).children("http://hl7.org/fhir/StructureDefinition/Extension");
|
||||
checkElement(ggchildren.get(0), "extension", "extension", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/Extension", 3);
|
||||
checkElement(ggchildren.get(1), "extension", "slice3a", 0, 2, "http://hl7.org/fhir/StructureDefinition/Coding", 6);
|
||||
checkElement(ggchildren.get(2), "extension", "slice3b", 0, Integer.MAX_VALUE, "http://hl7.org/fhir/StructureDefinition/string", 2);
|
||||
}
|
||||
|
||||
private void checkElement(PEDefinition pe, String schemaName, String name, int min, int max, String type, int children) {
|
||||
Assertions.assertEquals(name, pe.name());
|
||||
Assertions.assertEquals(schemaName, pe.schemaName());
|
||||
Assertions.assertEquals(min, pe.min());
|
||||
Assertions.assertEquals(max, pe.max());
|
||||
if (type != null) {
|
||||
Assertions.assertEquals(1, pe.types().size());
|
||||
Assertions.assertEquals(type, pe.types().get(0).getUrl());
|
||||
List<PEDefinition> children2 = pe.children(type);
|
||||
Assertions.assertEquals(children, children2.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUSPatientCore() throws IOException {
|
||||
load();
|
||||
|
||||
PEDefinition pe = new PEBuilder(ctxt, true).buildPEDefinition("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");
|
||||
PEDefinition pe = new PEBuilder(ctxt, PEElementPropertiesPolicy.EXTENSION_ID).buildPEDefinition("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");
|
||||
|
||||
Assertions.assertEquals("USCorePatientProfile", pe.name());
|
||||
Assertions.assertEquals("Patient", pe.schemaName());
|
||||
@ -172,7 +243,7 @@ public class ProfiledElementTests {
|
||||
public void dumpUSPatientCore() throws IOException {
|
||||
load();
|
||||
|
||||
PEDefinition pe = new PEBuilder(ctxt, false).buildPEDefinition("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");
|
||||
PEDefinition pe = new PEBuilder(ctxt, PEElementPropertiesPolicy.NONE).buildPEDefinition("http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient");
|
||||
dump(pe, "");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user