diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CodeSystemValidator.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CodeSystemValidator.java new file mode 100644 index 00000000..d3552a9f --- /dev/null +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CodeSystemValidator.java @@ -0,0 +1,82 @@ +package org.hl7.fhir.igtools.publisher; + +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ + + + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.hl7.fhir.r5.context.IWorkerContext; +import org.hl7.fhir.r5.model.CodeSystem; +import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent; +import org.hl7.fhir.r5.utils.XVerExtensionManager; +import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; +import org.hl7.fhir.validation.BaseValidator; + +/** + * This is defunct, I think? All this checking happens in the main code system validator? + * + * @author grahamegrieve + * + */ +public class CodeSystemValidator extends BaseValidator { + + public CodeSystemValidator(IWorkerContext context, XVerExtensionManager xverManager) { + super(context, xverManager, false); + } + + public List validate(CodeSystem cs, boolean forBuild) { + List errors = new ArrayList(); + + // this is an invariant on CodeSystem, but the invariant is wrong in R3, and doesn't work + checkCodesUnique(cs, errors); + return errors; + } + + private void checkCodesUnique(CodeSystem cs, List errors) { + Set codes = new HashSet(); + checkCodes(codes, cs.getConcept(), "CodeSystem.where(id = '"+cs.getId()+"')", errors); + } + + private void checkCodes(Set codes, List list, String path, List errors) { + for (ConceptDefinitionComponent cc : list) { + String npath = path+".concept.where(code = '"+cc.getCode()+"')"; + if (codes.contains(cc.getCode())) { + rule(errors, NO_RULE_DATE, IssueType.BUSINESSRULE, npath, false, "Duplicate Code "+cc.getCode()); + } + codes.add(cc.getCode()); + checkCodes(codes, cc.getConcept(), npath, errors); + } + } +} \ No newline at end of file diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java index 8b7b9715..71e203b0 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java @@ -354,7 +354,6 @@ import org.hl7.fhir.utilities.xml.XMLUtil; import org.hl7.fhir.utilities.xml.XmlEscaper; import org.hl7.fhir.validation.ValidatorUtils; -import org.hl7.fhir.validation.codesystem.CodeSystemValidator; import org.hl7.fhir.validation.instance.InstanceValidator; import org.hl7.fhir.validation.instance.utils.ValidatorHostContext; import org.hl7.fhir.validation.profile.ProfileValidator; @@ -1059,6 +1058,16 @@ private void processTxLog(String path) throws FileNotFoundException, IOException PrintStream f = new PrintStream(new FileOutputStream(path)); String title = "Terminology Server Log"; f.println(""+title+"

"+title+"

");
+      for (String s : tx.split("\\r?\\n|\\r")) {
+        if (s.startsWith("---") && s.endsWith("---")) {
+          f.println("

"); + String id = s.replace("-", "").trim(); + f.println("

"+id+"

"); + f.println("
");
+        } else {
+          f.println(s);
+        }
+      }
       f.print(tx);
       f.println("
"); f.close(); @@ -11321,14 +11330,14 @@ public static void main(String[] args) throws Exception { NpmPackage npm = pcm.loadPackage(p); System.out.println("OK: "+npm.name()+"#"+npm.version()+" for FHIR version(s) "+npm.fhirVersionList()+" with canonical "+npm.canonical()); } - } else if (hasNamedParam(args, "-dicom-gen")) { - DicomPackageBuilder pgen = new DicomPackageBuilder(); - pgen.setSource(getNamedParam(args, "src")); - pgen.setDest(getNamedParam(args, "dst")); - if (hasNamedParam(args, "-pattern")) { - pgen.setPattern(getNamedParam(args, "-pattern")); - } - pgen.execute(); +// } else if (hasNamedParam(args, "-dicom-gen")) { +// DicomPackageBuilder pgen = new DicomPackageBuilder(); +// pgen.setSource(getNamedParam(args, "src")); +// pgen.setDest(getNamedParam(args, "dst")); +// if (hasNamedParam(args, "-pattern")) { +// pgen.setPattern(getNamedParam(args, "-pattern")); +// } +// pgen.execute(); } else if (hasNamedParam(args, "-help") || hasNamedParam(args, "-?") || hasNamedParam(args, "/?") || hasNamedParam(args, "?") || args.length == 0) { System.out.println(""); System.out.println("To use this publisher to publish a FHIR Implementation Guide, run "); @@ -11372,16 +11381,16 @@ public static void main(String[] args) throws Exception { System.out.println("or you can configure the proxy using -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort="); System.out.println(""); System.out.println("For additional information, see https://confluence.hl7.org/display/FHIR/IG+Publisher+Documentation"); - } else if (hasNamedParam(args, "-convert")) { - // convert a igpack.zip to a package.tgz - IGPack2NpmConvertor conv = new IGPack2NpmConvertor(); - conv.setSource(getNamedParam(args, "-source")); - conv.setDest(getNamedParam(args, "-dest")); - conv.setPackageId(getNamedParam(args, "-npm-name")); - conv.setVersionIg(getNamedParam(args, "-version")); - conv.setLicense(getNamedParam(args, "-license")); - conv.setWebsite(getNamedParam(args, "-website")); - conv.execute(); +// } else if (hasNamedParam(args, "-convert")) { +// // convert a igpack.zip to a package.tgz +// IGPack2NpmConvertor conv = new IGPack2NpmConvertor(); +// conv.setSource(getNamedParam(args, "-source")); +// conv.setDest(getNamedParam(args, "-dest")); +// conv.setPackageId(getNamedParam(args, "-npm-name")); +// conv.setVersionIg(getNamedParam(args, "-version")); +// conv.setLicense(getNamedParam(args, "-license")); +// conv.setWebsite(getNamedParam(args, "-website")); +// conv.execute(); } else if (hasNamedParam(args, "-delete-current")) { if (!args[0].equals("-delete-current")) { throw new Error("-delete-current must have the format -delete-current {root}/{realm}/{code} -history {history} (first argument is not -delete-current)"); @@ -11549,7 +11558,7 @@ public static void main(String[] args) throws Exception { self.setSourceDir(getNamedParam(args, "-source")); self.setDestDir(getNamedParam(args, "-destination")); self.specifiedVersion = getNamedParam(args, "-version"); - } else if(!hasNamedParam(args, "-ig") && args.length == 1 && new File(args[0]).exists()) { + } else if (!hasNamedParam(args, "-ig") && args.length == 1 && new File(args[0]).exists()) { self.setConfigFile(determineActualIG(args[0], IGBuildMode.MANUAL)); } else if (hasNamedParam(args, "-prompt")) { IniFile ini = new IniFile("publisher.ini"); diff --git a/pom.xml b/pom.xml index e9e9b9e2..8c7fb4e9 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 1.3.25-SNAPSHOT - 6.0.22 + 6.0.23-SNAPSHOT 3.0.0-M5 5.2.1 4.10.0