refactor loader for easier loading of old versions

This commit is contained in:
Grahame Grieve 2023-03-25 18:58:22 +11:00
parent b273d3f730
commit 8e9b96b4b7
2 changed files with 31 additions and 11 deletions

View File

@ -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<String> 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) {

View File

@ -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;
}