Work around issue with R5 path in extensions pack

This commit is contained in:
Grahame Grieve 2023-03-30 23:30:23 +11:00
parent 1b6137967f
commit 76c96a53d6
5 changed files with 154 additions and 1 deletions

View File

@ -0,0 +1,69 @@
package org.hl7.fhir.r4b.utils;
import org.hl7.fhir.r4b.model.Base;
import org.hl7.fhir.r4b.model.DataType;
import org.hl7.fhir.r4b.model.Property;
import org.hl7.fhir.r4b.model.Resource;
import org.hl7.fhir.utilities.Utilities;
public class DataTypeVisitor {
public interface IDatatypeVisitor<T extends DataType> {
Class<T> classT();
boolean visit(String path, T node);
}
private boolean anyFalse;
private boolean anyTrue;
private int nodeCount;
private int selectedCount;
public <T extends DataType> void visit(Resource resource, IDatatypeVisitor<T> visitor) {
visitNode(resource.fhirType(), resource, visitor);
}
@SuppressWarnings("unchecked")
private <T extends DataType> void visitNode(String path, Base node, IDatatypeVisitor<T> visitor) {
nodeCount++;
if (node instanceof DataType && visitor.classT().isInstance(node)) {
selectedCount++;
boolean ok = visitor.visit(path, (T) node);
if (ok) {
anyTrue = true;
} else {
anyFalse = true;
}
}
for (Property p : node.children()) {
if (p.isList()) {
int i = 0;
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName()+"["+i+"]", b, visitor);
i++;
}
} else {
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName(), b, visitor);
}
}
}
}
public boolean isAnyFalse() {
return anyFalse;
}
public boolean isAnyTrue() {
return anyTrue;
}
public int getNodeCount() {
return nodeCount;
}
public int getSelectedCount() {
return selectedCount;
}
}

View File

@ -68,6 +68,11 @@ public class Extension extends BaseExtension implements IBaseExtension<Extension
@Description(shortDefinition="Value of extension", formalDefinition="Value of extension - must be one of a constrained set of the data types (see [Extensibility](extensibility.html) for a list)." )
protected DataType value;
@Override
public String toString() {
return url + "=" + value.toString();
}
private static final long serialVersionUID = 465890108L;
/**

View File

@ -7159,6 +7159,12 @@ public class ImplementationGuide extends CanonicalResource {
@Description(shortDefinition="Location of the resource", formalDefinition="Where this resource is found." )
protected Reference reference;
@Override
public String toString() {
return "ImplementationGuideDefinitionResourceComponent [name=" + name + ", reference=" + reference
+ ", profile=" + profile + "]";
}
/**
* Indicates the FHIR Version(s) this artifact is intended to apply to. If no versions are specified, the resource is assumed to apply to all the versions stated in ImplementationGuide.fhirVersion.
*/

View File

@ -146,8 +146,13 @@ public class DataRenderer extends Renderer implements CodeResolver {
String left = text.substring(0, text.indexOf("[[["));
String link = text.substring(text.indexOf("[[[")+3, text.indexOf("]]]"));
String right = text.substring(text.indexOf("]]]")+3);
String path = null;
String url = link;
String[] parts = link.split("\\#");
if (parts[0].contains(".")) {
path = parts[0];
parts[0] = parts[0].substring(0, parts[0].indexOf("."));
}
StructureDefinition p = getContext().getWorker().fetchResource(StructureDefinition.class, parts[0]);
if (p == null)
p = getContext().getWorker().fetchTypeDefinition(parts[0]);
@ -160,7 +165,7 @@ public class DataRenderer extends Renderer implements CodeResolver {
} else
throw new DefinitionException("Unable to resolve markdown link "+link);
text = left+"["+link+"]("+url+")"+right;
text = left+"["+link+"]("+url+(path == null ? "" : "#"+path)+")"+right;
}
// 2. markdown

View File

@ -0,0 +1,68 @@
package org.hl7.fhir.r5.utils;
import org.hl7.fhir.r5.model.Base;
import org.hl7.fhir.r5.model.DataType;
import org.hl7.fhir.r5.model.Property;
import org.hl7.fhir.r5.model.Resource;
public class DataTypeVisitor {
public interface IDatatypeVisitor<T extends DataType> {
Class<T> classT();
boolean visit(String path, T node);
}
private boolean anyFalse;
private boolean anyTrue;
private int nodeCount;
private int selectedCount;
public <T extends DataType> void visit(Resource resource, IDatatypeVisitor<T> visitor) {
visitNode(resource.fhirType(), resource, visitor);
}
@SuppressWarnings("unchecked")
private <T extends DataType> void visitNode(String path, Base node, IDatatypeVisitor<T> visitor) {
nodeCount++;
if (node instanceof DataType && visitor.classT().isInstance(node)) {
selectedCount++;
boolean ok = visitor.visit(path, (T) node);
if (ok) {
anyTrue = true;
} else {
anyFalse = true;
}
}
for (Property p : node.children()) {
if (p.isList()) {
int i = 0;
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName()+"["+i+"]", b, visitor);
i++;
}
} else {
for (Base b : p.getValues()) {
visitNode(path+"."+p.getName(), b, visitor);
}
}
}
}
public boolean isAnyFalse() {
return anyFalse;
}
public boolean isAnyTrue() {
return anyTrue;
}
public int getNodeCount() {
return nodeCount;
}
public int getSelectedCount() {
return selectedCount;
}
}