From 8e9b96b4b74e00e1011682ee057052703aedff87 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 25 Mar 2023 18:58:22 +1100 Subject: [PATCH] refactor loader for easier loading of old versions --- .../r5/renderers/StructureMapRenderer.java | 22 +++++++++++++++---- .../hl7/fhir/validation/ValidatorUtils.java | 20 +++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java index 2fc49420c..2332e94b3 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/StructureMapRenderer.java @@ -323,7 +323,12 @@ public class StructureMapRenderer extends TerminologyRenderer { x.color(COLOR_SYNTAX).tx(")"); if (g.hasExtends()) { x.b().tx(" extends "); - x.tx(g.getExtends()); + String ref = resolveRuleReference(g.getExtendsElement()); + if (ref != null) { + x.ah(ref).tx(g.getExtends()); + } else { + x.tx(g.getExtends()); + } } if (g.hasTypeMode()) { @@ -347,6 +352,10 @@ public class StructureMapRenderer extends TerminologyRenderer { x.color(COLOR_SYNTAX).tx("}\r\n\r\n"); } + private String resolveRuleReference(IdType idType) { + return null; + } + private void renderRule(XhtmlNode x, StructureMapGroupComponent g, StructureMapGroupRuleComponent r, int indent) { Collection tokens = scanVariables(g, r); if (r.hasFormatCommentPre()) { @@ -396,7 +405,7 @@ public class StructureMapRenderer extends TerminologyRenderer { x.tx(" "); x.color(COLOR_SYNTAX).tx("}"); } else { - if (r.hasDependent()) { + if (r.hasDependent() && !canBeAbbreviated) { x.b().tx(" then "); boolean first = true; for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) { @@ -404,7 +413,12 @@ public class StructureMapRenderer extends TerminologyRenderer { first = false; else x.color(COLOR_SYNTAX).tx(", "); - x.tx(rd.getName()); + String ref = resolveRuleReference(rd.getNameElement()); + if (ref != null) { + x.ah(ref).tx(rd.getName()); + } else { + x.tx(rd.getName()); + } x.color(COLOR_SYNTAX).tx("("); boolean ifirst = true; for (StructureMapGroupRuleTargetParameterComponent rdp : rd.getParameter()) { @@ -481,7 +495,7 @@ public class StructureMapRenderer extends TerminologyRenderer { return (r.getSource().size() == 1 && r.getSourceFirstRep().hasElement() && r.getSourceFirstRep().hasVariable()) && (r.getTarget().size() == 1 && r.getTargetFirstRep().hasVariable() && (r.getTargetFirstRep().getTransform() == null || r.getTargetFirstRep().getTransform() == StructureMapTransform.CREATE) && r.getTargetFirstRep().getParameter().size() == 0) && - (r.getDependent().size() == 0) && (r.getRule().size() == 0); + (r.getDependent().size() == 0 || (r.getDependent().size() == 1 && StructureMapUtilities.DEF_GROUP_NAME.equals(r.getDependentFirstRep().getName()))) && (r.getRule().size() == 0); } private void renderSource(XhtmlNode x,StructureMapGroupRuleSourceComponent rs, boolean abbreviate) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorUtils.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorUtils.java index 3e952d3d7..5693dd6b2 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorUtils.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidatorUtils.java @@ -11,6 +11,8 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.hl7.fhir.convertors.loaders.loaderR5.BaseLoaderR5; +import org.hl7.fhir.convertors.loaders.loaderR5.ILoaderKnowledgeProviderR5; import org.hl7.fhir.convertors.loaders.loaderR5.NullLoaderKnowledgeProviderR5; import org.hl7.fhir.convertors.loaders.loaderR5.R2016MayToR5Loader; import org.hl7.fhir.convertors.loaders.loaderR5.R2ToR5Loader; @@ -47,27 +49,31 @@ public class ValidatorUtils { } } - public static IWorkerContext.IContextResourceLoader loaderForVersion(String version) { + public static BaseLoaderR5 loaderForVersion(String version) { + return loaderForVersion(version, new NullLoaderKnowledgeProviderR5()); + } + + public static BaseLoaderR5 loaderForVersion(String version, ILoaderKnowledgeProviderR5 loader) { if (Utilities.noString(version)) { return null; } if (VersionUtilities.isR2Ver(version)) { - return new R2ToR5Loader(Utilities.strings("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"), loader); } if (VersionUtilities.isR2BVer(version)) { - return new R2016MayToR5Loader(Utilities.strings("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"), loader); // special case } if (VersionUtilities.isR3Ver(version)) { - return new R3ToR5Loader(Utilities.strings("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"), loader); } if (VersionUtilities.isR4Ver(version)) { - return new R4ToR5Loader(Utilities.strings("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"), loader, version); } if (VersionUtilities.isR4BVer(version)) { - return new R4BToR5Loader(Utilities.strings("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"), loader, version); } if (VersionUtilities.isR5Ver(version)) { - return new R5ToR5Loader(Utilities.strings("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"), loader); } return null; }