Fix issues with xhtml handling

This commit is contained in:
Grahame Grieve 2023-03-16 14:07:11 +11:00
parent 4a7abab5e8
commit 27598a382d
7 changed files with 36 additions and 20 deletions

View File

@ -249,10 +249,12 @@ public class Property {
* @param E.g. "integer"
*/
public boolean isPrimitive(String code) {
return TypesUtilities.isPrimitive(code);
// was this... but this can be very inefficient compared to hard coding the list
// StructureDefinition sd = context.fetchTypeDefinition(code);
// return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
if (Utilities.isAbsoluteUrl(code)) {
StructureDefinition sd = context.fetchTypeDefinition(code);
return sd != null && sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE;
} else {
return TypesUtilities.isPrimitive(code);
}
}
public boolean isPrimitive() {

View File

@ -303,7 +303,7 @@ public class Narrative extends BaseNarrative implements INarrative {
public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException {
switch (hash) {
case -892481550: /*status*/ return this.status == null ? new Base[0] : new Base[] {this.status}; // Enumeration<NarrativeStatus>
case 99473: /*div*/ return this.div == null ? new Base[0] : new Base[] {new StringType(new org.hl7.fhir.utilities.xhtml.XhtmlComposer(true).composeEx(this.div))}; // XhtmlNode
case 99473: /*div*/ return this.div == null ? new Base[0] : new Base[] {new XhtmlType(this)}; // XhtmlNode
default: return super.getProperty(hash, name, checkValid);
}
@ -318,6 +318,7 @@ public class Narrative extends BaseNarrative implements INarrative {
return value;
case 99473: // div
this.div = TypeConvertor.castToXhtml(value); // XhtmlNode
((XhtmlType) value).setPlace(this);
return value;
default: return super.setProperty(hash, name, value);
}

View File

@ -713,7 +713,11 @@ public class ResourceFactory extends Factory {
case 1218149947: return new VirtualServiceDetail();
default:
throw new FHIRException("Unknown Resource or Type Name '"+name+"'");
if (name.equals("xhtml")) {
return new XhtmlType();
} else {
throw new FHIRException("Unknown Resource or Type Name '"+name+"'");
}
}
}

View File

@ -134,5 +134,13 @@ public class XhtmlType extends PrimitiveType<String> {
return theValue;
}
public Narrative getPlace() {
return place;
}
public void setPlace(Narrative place) {
this.place = place;
}
}

View File

@ -2347,7 +2347,7 @@ public class FHIRPathEngine {
return makeBoolean(!res);
}
private final static String[] FHIR_TYPES_STRING = new String[] {"string", "uri", "code", "oid", "id", "uuid", "sid", "markdown", "base64Binary", "canonical", "url"};
private final static String[] FHIR_TYPES_STRING = new String[] {"string", "uri", "code", "oid", "id", "uuid", "sid", "markdown", "base64Binary", "canonical", "url", "xhtml"};
private List<Base> opLessThan(List<Base> left, List<Base> right, ExpressionNode expr) throws FHIRException {
if (left.size() == 0 || right.size() == 0)

View File

@ -508,15 +508,16 @@ public class XhtmlNode extends XhtmlFluent implements IBaseXhtml {
try {
XhtmlDocument fragment = new XhtmlParser().parse(val, "div");
this.attributes = fragment.attributes;
this.childNodes = fragment.childNodes;
XhtmlNode root = fragment.getChildNodes().get(0);
this.attributes = root.attributes;
this.childNodes = root.childNodes;
// Strip the <? .. ?> declaration if one was present
if (childNodes.size() > 0 && childNodes.get(0) != null && childNodes.get(0).getNodeType() == NodeType.Instruction) {
childNodes.remove(0);
}
this.content = fragment.getContent();
this.name = fragment.getName();
this.nodeType= fragment.getNodeType();
this.content = root.getContent();
this.name = root.getName();
this.nodeType= root.getNodeType();
} catch (Exception e) {
// TODO: composer shouldn't throw exception like this
throw new RuntimeException(e);

View File

@ -52,22 +52,22 @@ public class ValidatorUtils {
return null;
}
if (VersionUtilities.isR2Ver(version)) {
return new R2ToR5Loader(new String[]{"Conformance", "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5());
return new R2ToR5Loader(Utilities.strings("Conformance", "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5());
}
if (VersionUtilities.isR2BVer(version)) {
return new R2016MayToR5Loader(new String[]{"Conformance", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5()); // special case
return new R2016MayToR5Loader(Utilities.strings("Conformance", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5()); // special case
}
if (VersionUtilities.isR3Ver(version)) {
return new R3ToR5Loader(new String[]{"CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5());
return new R3ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5());
}
if (VersionUtilities.isR4Ver(version)) {
return new R4ToR5Loader(new String[]{"CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5(), version);
return new R4ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5(), version);
}
if (VersionUtilities.isR4BVer(version)) {
return new R4BToR5Loader(new String[]{"CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5(), version);
return new R4BToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5(), version);
}
if (VersionUtilities.isR5Ver(version)) {
return new R5ToR5Loader(new String[]{"CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProviderR5());
return new R5ToR5Loader(Utilities.strings("CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem"), new NullLoaderKnowledgeProviderR5());
}
return null;
}