From 6fb61b75f0b7aeb819531cf235cdfd50d7d25e37 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 12 Aug 2022 21:24:14 +1000 Subject: [PATCH] R5 related fixes --- .../fhir/r5/conformance/ProfileUtilities.java | 15 ++-- .../r5/context/CanonicalResourceManager.java | 1 + .../r5/renderers/utils/RenderingContext.java | 12 ++-- .../r5/test/NarrativeGenerationTests.java | 68 ++++++++++++++++++- .../hl7/fhir/utilities/VersionUtilities.java | 7 ++ 5 files changed, 92 insertions(+), 11 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java index 178ee5601..d420be9d2 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ProfileUtilities.java @@ -3721,14 +3721,19 @@ public class ProfileUtilities extends TranslatingUtilities { if (ref != null) { String[] parts = ref.split("\\|"); if (parts[0].startsWith("http:") || parts[0].startsWith("https:")) { - // c.addPiece(checkForNoChange(t, gen.new Piece(parts[0], "<" + parts[1] + ">", t.getCode()))); Lloyd - c.addPiece(checkForNoChange(t, gen.new Piece(parts[0], parts[1], t.getWorkingCode()))); + if (p.hasExtension(ToolingExtensions.EXT_PROFILE_ELEMENT)) { + String pp = p.getExtensionString(ToolingExtensions.EXT_PROFILE_ELEMENT); + pp = pp.substring(pp.indexOf(".")); + c.addPiece(checkForNoChange(t, gen.new Piece(parts[0], parts[1]+pp, t.getWorkingCode()))); + } else { + c.addPiece(checkForNoChange(t, gen.new Piece(parts[0], parts[1], t.getWorkingCode()))); + } } else { - // c.addPiece(checkForNoChange(t, gen.new Piece((t.getProfile().startsWith(corePath)? corePath: "")+parts[0], "<" + parts[1] + ">", t.getCode()))); c.addPiece(checkForNoChange(t, gen.new Piece((p.getValue().startsWith(corePath+"StructureDefinition")? corePath: "")+parts[0], parts[1], t.getWorkingCode()))); } - } else + } else { c.addPiece(checkForNoChange(t, gen.new Piece((p.getValue().startsWith(corePath)? corePath: "")+ref, t.getWorkingCode(), null))); + } if (!mustSupportMode && isMustSupport(p) && e.getMustSupport()) { c.addPiece(gen.new Piece(null, " ", null)); c.addStyledText(translate("sd.table", "This profile must be supported"), "S", "white", "red", null, false); @@ -5026,7 +5031,7 @@ public class ProfileUtilities extends TranslatingUtilities { Cell c = gen.new Cell(); row.getCells().add(c); - c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref+ed.getPath() : (VersionUtilities.isThisOrLater("4.1", context.getVersion()) ? corePath+"types-definitions.html#"+ed.getBase().getPath() : corePath+"element-definitions.html#"+ed.getBase().getPath())), t.getName(), null)); + c.addPiece(gen.new Piece((ed.getBase().getPath().equals(ed.getPath()) ? ref+ed.getPath() : (VersionUtilities.isR5Ver(context.getVersion()) ? corePath+"types-definitions.html#"+ed.getBase().getPath() : corePath+"element-definitions.html#"+ed.getBase().getPath())), t.getName(), null)); c = gen.new Cell(); row.getCells().add(c); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java index 6ab1b474c..039edd105 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java @@ -21,6 +21,7 @@ public class CanonicalResourceManager { private final String[] INVALID_TERMINOLOGY_URLS = { "http://snomed.info/sct", + "http://dicom.nema.org/resources/ontology/DCM", "http://nucc.org/provider-taxonomy" }; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java index 9d0f99ceb..e81bb81d6 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/RenderingContext.java @@ -115,7 +115,7 @@ public class RenderingContext { private String tooCostlyNoteNotEmptyDependent; private List codeSystemPropList = new ArrayList<>(); - private ProfileUtilities profileUtilities; + private ProfileUtilities profileUtilitiesR; private String definitionsTarget; private String destDir; private boolean inlineGraphics; @@ -152,7 +152,6 @@ public class RenderingContext { } // default to US locale - discussion here: https://github.com/hapifhir/org.hl7.fhir.core/issues/666 this.locale = new Locale.Builder().setLanguageTag("en-US").build(); - profileUtilities = new ProfileUtilities(worker, null, null); } public RenderingContext copy() { RenderingContext res = new RenderingContext(worker, markdown, terminologyServiceOptions, specificationLink, localPrefix, lang, mode); @@ -174,7 +173,7 @@ public class RenderingContext { res.tooCostlyNoteNotEmptyDependent = tooCostlyNoteNotEmptyDependent; res.codeSystemPropList.addAll(codeSystemPropList); - res.profileUtilities = profileUtilities; + res.profileUtilitiesR = profileUtilitiesR; res.definitionsTarget = definitionsTarget; res.destDir = destDir; res.addGeneratedNarrativeHeader = addGeneratedNarrativeHeader; @@ -204,7 +203,10 @@ public class RenderingContext { // -- 2. Markdown support ------------------------------------------------------- public ProfileUtilities getProfileUtilities() { - return profileUtilities; + if (profileUtilitiesR == null) { + profileUtilitiesR = new ProfileUtilities(worker, null, null); + } + return profileUtilitiesR; } public IWorkerContext getWorker() { @@ -331,7 +333,7 @@ public class RenderingContext { } public RenderingContext setProfileUtilities(ProfileUtilities profileUtilities) { - this.profileUtilities = profileUtilities; + this.profileUtilitiesR = profileUtilities; return this; } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java index d31bfae21..483041201 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/NarrativeGenerationTests.java @@ -8,24 +8,31 @@ import java.util.stream.Stream; import javax.xml.parsers.ParserConfigurationException; +import org.apache.commons.lang3.NotImplementedException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.r5.conformance.ProfileUtilities; +import org.hl7.fhir.r5.conformance.ProfileUtilities.ProfileKnowledgeProvider; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.elementmodel.Manager; import org.hl7.fhir.r5.elementmodel.Manager.FhirFormat; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.XmlParser; import org.hl7.fhir.r5.model.Base; +import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent; import org.hl7.fhir.r5.model.Resource; +import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.renderers.RendererFactory; import org.hl7.fhir.r5.renderers.utils.ElementWrappers; import org.hl7.fhir.r5.renderers.utils.RenderingContext; import org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser; import org.hl7.fhir.r5.renderers.utils.RenderingContext.ResourceRendererMode; +import org.hl7.fhir.r5.test.NarrativeGenerationTests.TestProfileKnowledgeProvider; import org.hl7.fhir.r5.test.utils.CompareUtilities; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.utilities.TerminologyServiceOptions; import org.hl7.fhir.utilities.TextFile; +import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.xhtml.XhtmlComposer; import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.hl7.fhir.utilities.xml.XMLUtil; @@ -40,6 +47,64 @@ import org.xml.sax.SAXException; public class NarrativeGenerationTests { + public class TestProfileKnowledgeProvider implements ProfileKnowledgeProvider { + + private IWorkerContext context; + + public TestProfileKnowledgeProvider(IWorkerContext context) { + this.context = context; + } + + @Override + public boolean isDatatype(String typeSimple) { + throw new NotImplementedException(); + } + + @Override + public boolean isResource(String typeSimple) { + throw new NotImplementedException(); + } + + @Override + public boolean hasLinkFor(String typeSimple) { + throw new NotImplementedException(); + } + + @Override + public String getLinkFor(String corePath, String typeSimple) { + throw new NotImplementedException(); + } + + @Override + public BindingResolution resolveBinding(StructureDefinition def, ElementDefinitionBindingComponent binding, String path) throws FHIRException { + throw new NotImplementedException(); + } + + @Override + public BindingResolution resolveBinding(StructureDefinition def, String url, String path) throws FHIRException { + throw new NotImplementedException(); + } + + @Override + public String getLinkForProfile(StructureDefinition profile, String url) { + if ("http://hl7.org/fhir/StructureDefinition/Composition".equals(url)) { + return "http://hl7.org/fhir/composition.html|TestComposition"; + } + throw new NotImplementedException(); + } + + @Override + public boolean prependLinks() { + throw new NotImplementedException(); + } + + @Override + public String getLinkForUrl(String corePath, String s) { + throw new NotImplementedException(); + } + + } + public class TestTypeParser implements ITypeParser { @Override @@ -111,7 +176,7 @@ public class NarrativeGenerationTests { @MethodSource("data") public void test(String id, TestDetails test) throws Exception { RenderingContext rc = new RenderingContext(context, null, null, "http://hl7.org/fhir", "", null, ResourceRendererMode.END_USER); - rc.setDestDir(""); + rc.setDestDir(Utilities.path("[tmp]", "narrative")); rc.setHeader(test.isHeader()); rc.setDefinitionsTarget("test.html"); rc.setTerminologyServiceOptions(TerminologyServiceOptions.defaults()); @@ -123,6 +188,7 @@ public class NarrativeGenerationTests { rc.setDateTimeFormatString("yyyy-MM-dd'T'HH:mm:ssZZZZZ"); rc.setDateFormatString("yyyy-MM-dd"); rc.setMode(test.technical ? ResourceRendererMode.TECHNICAL : ResourceRendererMode.END_USER); + rc.setProfileUtilities(new ProfileUtilities(rc.getContext(), null, new TestProfileKnowledgeProvider(rc.getContext()))); Resource source; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java index 6842dc95e..6c2c02c5b 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java @@ -558,5 +558,12 @@ public class VersionUtilities { return version != null && (version.startsWith("4.") || version.startsWith("5.") || "current".equals(version)); } + public static boolean refersTo(String refVer, String v) { + if (v.length() > refVer.length()) { + v = v.substring(0, refVer.length()); + } + return refVer.equals(v); + } + } \ No newline at end of file