From f9e11e22c13cae80803c314a98c3a0647bddf4ba Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 12 Dec 2023 15:56:23 +1300 Subject: [PATCH 1/4] fix problem with version dependencies when loading npm packages directly in validator --- .../src/main/java/org/hl7/fhir/validation/IgLoader.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java index 13333a1ab..5736eb67b 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/IgLoader.java @@ -105,6 +105,14 @@ public class IgLoader implements IValidationEngineLoader { } NpmPackage npm = srcPackage.matches(FilesystemPackageCacheManager.PACKAGE_VERSION_REGEX_OPT) && !new File(srcPackage).exists() ? getPackageCacheManager().loadPackage(srcPackage, null) : null; + if (npm == null && new File(srcPackage).exists()) { + // try treating the file as an npm + try { + npm = NpmPackage.fromPackage(new FileInputStream(srcPackage)); + } catch (Exception e) { + // nothing - any errors will be properly handled later in the process + } + } if (npm != null) { for (String s : npm.dependencies()) { if (!getContext().getLoadedPackages().contains(s)) { From cc424a04e1396cc59f447ebb97722d0e011b2029 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 12 Dec 2023 16:52:11 +1300 Subject: [PATCH 2/4] fix problems setting owning committee consistently --- .../r5/terminologies/CodeSystemUtilities.java | 3 +- .../r5/terminologies/ValueSetUtilities.java | 3 +- .../r5/utils/CanonicalResourceUtilities.java | 35 ++++++++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java index aa5074afc..3ff4c0560 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/CodeSystemUtilities.java @@ -64,6 +64,7 @@ import org.hl7.fhir.r5.model.IntegerType; import org.hl7.fhir.r5.model.Meta; import org.hl7.fhir.r5.model.StringType; import org.hl7.fhir.r5.model.UriType; +import org.hl7.fhir.r5.utils.CanonicalResourceUtilities; import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.MarkDownProcessor; @@ -504,7 +505,7 @@ public class CodeSystemUtilities extends TerminologyUtilities { if (wg != null) { if (!ToolingExtensions.hasExtension(cs, ToolingExtensions.EXT_WORKGROUP) || (Utilities.existsInList(ToolingExtensions.readStringExtension(cs, ToolingExtensions.EXT_WORKGROUP), "fhir", "vocab") && !Utilities.existsInList(wg, "fhir", "vocab"))) { - ToolingExtensions.setCodeExtension(cs, ToolingExtensions.EXT_WORKGROUP, wg); + CanonicalResourceUtilities.setHl7WG(cs, wg); } } if (status != null) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetUtilities.java index 87511c494..da3236f95 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetUtilities.java @@ -64,6 +64,7 @@ import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionPropertyComponent; import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptDefinitionComponentSorter; import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptStatus; +import org.hl7.fhir.r5.utils.CanonicalResourceUtilities; import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.utilities.StandardsStatus; import org.hl7.fhir.utilities.Utilities; @@ -139,7 +140,7 @@ public class ValueSetUtilities extends TerminologyUtilities { if (wg != null) { if (!ToolingExtensions.hasExtension(vs, ToolingExtensions.EXT_WORKGROUP) || (!Utilities.existsInList(ToolingExtensions.readStringExtension(vs, ToolingExtensions.EXT_WORKGROUP), "fhir", "vocab") && Utilities.existsInList(wg, "fhir", "vocab"))) { - ToolingExtensions.setCodeExtension(vs, ToolingExtensions.EXT_WORKGROUP, wg); + CanonicalResourceUtilities.setHl7WG(vs, wg); } } if (status != null) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/CanonicalResourceUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/CanonicalResourceUtilities.java index 91d924f7b..df1f3b44a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/CanonicalResourceUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/CanonicalResourceUtilities.java @@ -6,6 +6,8 @@ import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.CompartmentDefinition; import org.hl7.fhir.r5.model.Constants; +import org.hl7.fhir.r5.model.ContactDetail; +import org.hl7.fhir.r5.model.ContactPoint; import org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem; import org.hl7.fhir.utilities.HL7WorkGroups; import org.hl7.fhir.utilities.VersionUtilities; @@ -14,17 +16,33 @@ import org.hl7.fhir.utilities.xml.XMLUtil; public class CanonicalResourceUtilities { public static void setHl7WG(CanonicalResource cr, String wgc) { + if ("http://hl7.org/fhir/days-of-week".equals(cr.getUrl())) { + System.out.println("!"); + } var wg = HL7WorkGroups.find(wgc); if (wg == null) { throw new Error("Unknown WG "+wgc); } ToolingExtensions.setCodeExtension(cr, ToolingExtensions.EXT_WORKGROUP, wg.getCode()); cr.setPublisher("HL7 International / "+wg.getName()); - cr.getContact().clear(); - cr.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue(wg.getLink()); + boolean found = false; + for (ContactDetail c : cr.getContact()) { + for (ContactPoint t : c.getTelecom()) { + if ((t.getSystem() == ContactPointSystem.URL) && wg.getLink().equals(t.getValue())) { + found = true; + } + } + } + if (!found) { + cr.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue(wg.getLink()); + } } public static void setHl7WG(CanonicalResource cr) { + if ("http://hl7.org/fhir/days-of-week".equals(cr.getUrl())) { + System.out.println("!"); + } + String wgc = ToolingExtensions.readStringExtension(cr, ToolingExtensions.EXT_WORKGROUP); if (wgc == null) { wgc = "fhir"; @@ -35,8 +53,17 @@ public class CanonicalResourceUtilities { } ToolingExtensions.setCodeExtension(cr, ToolingExtensions.EXT_WORKGROUP, wg.getCode()); cr.setPublisher("HL7 International / "+wg.getName()); - cr.getContact().clear(); - cr.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue(wg.getLink()); + boolean found = false; + for (ContactDetail c : cr.getContact()) { + for (ContactPoint t : c.getTelecom()) { + if ((t.getSystem() == ContactPointSystem.URL) && wg.getLink().equals(t.getValue())) { + found = true; + } + } + } + if (!found) { + cr.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue(wg.getLink()); + } } public static void setHl7WG(Element res, String code) { From 289a74301d70928982afd44d208dff7bc89000b6 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 12 Dec 2023 20:32:19 +1300 Subject: [PATCH 3/4] work around R6 validation issue validating search parameters --- .../validation/instance/type/SearchParameterValidator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java index 63fd850a5..a0f504d6b 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java @@ -47,7 +47,9 @@ public class SearchParameterValidator extends BaseValidator { for (Element b : cs.getChildrenByName("base")) { bases.add(b.primitiveValue()); } - ok = checkExpression(errors, stack.push(cs.getNamedChild("expression", false), -1, null, null), cs.getNamedChildValue("expression", false), bases) && ok; + if (!bases.isEmpty()) { + ok = checkExpression(errors, stack.push(cs.getNamedChild("expression", false), -1, null, null), cs.getNamedChildValue("expression", false), bases) && ok; + } } String master = cs.getNamedChildValue("derivedFrom", false); if (!Utilities.noString(master)) { From 166cb445f8ced32ba87d86cc44652f82a98b3743 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 12 Dec 2023 21:00:31 +1300 Subject: [PATCH 4/4] More fixes for SearchParameter validation --- .../java/org/hl7/fhir/r5/utils/ToolingExtensions.java | 1 + .../instance/type/SearchParameterValidator.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java index d60f239e5..d9bf4f934 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/ToolingExtensions.java @@ -264,6 +264,7 @@ public class ToolingExtensions { public static final String EXT_ARTIFACT_NAME = "http://hl7.org/fhir/StructureDefinition/artifact-name"; public static final String EXT_ARTIFACT_DESC = "http://hl7.org/fhir/StructureDefinition/artifact-description"; public static final String EXT_ED_SUPPRESS = "http://hl7.org/fhir/StructureDefinition/elementdefinition-suppress"; + public static final String EXT_SEARCH_PARAMETER_BASE = "http://hl7.org/fhir/tools/StructureDefinition/searchparameter-base-type";; // specific extension helpers diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java index a0f504d6b..f1ef96b09 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java @@ -12,6 +12,7 @@ import org.hl7.fhir.r5.fhirpath.ExpressionNode.Kind; import org.hl7.fhir.r5.fhirpath.ExpressionNode.Operation; import org.hl7.fhir.r5.fhirpath.FHIRPathEngine.IssueMessage; import org.hl7.fhir.r5.model.SearchParameter; +import org.hl7.fhir.r5.utils.ToolingExtensions; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -45,9 +46,13 @@ public class SearchParameterValidator extends BaseValidator { if (cs.hasChild("expression", false)) { List bases = new ArrayList<>(); for (Element b : cs.getChildrenByName("base")) { - bases.add(b.primitiveValue()); + if (b.hasExtension(ToolingExtensions.EXT_SEARCH_PARAMETER_BASE)) { + bases.add(b.getExtensionValue(ToolingExtensions.EXT_SEARCH_PARAMETER_BASE).primitiveValue()); + } else { + bases.add(b.primitiveValue()); + } } - if (!bases.isEmpty()) { + if (!bases.isEmpty()) { // that'd be an error somewhere else ok = checkExpression(errors, stack.push(cs.getNamedChild("expression", false), -1, null, null), cs.getNamedChildValue("expression", false), bases) && ok; } }